Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.3.0-beta-2] - 2026-09-01

### Fixed

- An unsupported value in `openapi` / `swagger` no longer discards the whole file: the analysis reported success with zero issues from every rule. The document is now analysed with the closest known grammar.

## [1.3.0-beta-1] - 2026-08-18

### Added
Expand Down
2 changes: 1 addition & 1 deletion its/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.apiaddicts.apitools.dosonarapi</groupId>
<artifactId>dosonarapi</artifactId>
<version>1.3.0-beta-1</version>
<version>1.3.0-beta-2</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion openapi-checks/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.apiaddicts.apitools.dosonarapi</groupId>
<artifactId>dosonarapi</artifactId>
<version>1.3.0-beta-1</version>
<version>1.3.0-beta-2</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion openapi-front-end/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.apiaddicts.apitools.dosonarapi</groupId>
<artifactId>dosonarapi</artifactId>
<version>1.3.0-beta-1</version>
<version>1.3.0-beta-2</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public static YamlGrammarBuilder create() {
b.setRootRule(ROOT);

b.rule(ROOT).is(b.object(
b.mandatoryProperty("swagger", "2.0"),
b.mandatoryProperty("swagger", b.scalar()),
b.mandatoryProperty("info", INFO),
b.property("host", b.string()),
b.property("basePath", b.string()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public static YamlGrammarBuilder create() {
b.setRootRule(ROOT);

b.rule(ROOT).is(b.object(
b.mandatoryProperty("openapi", b.firstOf("3.0.0", "3.0.1", "3.0.2", "3.0.3", "3.0.4")),
b.mandatoryProperty("openapi", b.scalar()),
b.mandatoryProperty("info", INFO),
b.property("servers", b.array(SERVER)),
b.mandatoryProperty("paths", PATHS),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public static YamlGrammarBuilder create() {
b.setRootRule(ROOT);

b.rule(ROOT).is(b.object(
b.mandatoryProperty("openapi", b.firstOf("3.1.0", "3.1.1", "3.1.2")),
b.mandatoryProperty("openapi", b.scalar()),
b.mandatoryProperty("info", INFO),
b.property("jsonSchemaDialect", b.string()),
b.property("servers", b.array(SERVER)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public static YamlGrammarBuilder create() {
b.setRootRule(ROOT);

b.rule(ROOT).is(b.object(
b.mandatoryProperty("openapi", "3.2.0"),
b.mandatoryProperty("openapi", b.scalar()),
b.mandatoryProperty("info", INFO),
b.property("$self", b.string()),
b.property("jsonSchemaDialect", b.string()),
Expand Down
2 changes: 1 addition & 1 deletion openapi-test-tools/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.apiaddicts.apitools.dosonarapi</groupId>
<artifactId>dosonarapi</artifactId>
<version>1.3.0-beta-1</version>
<version>1.3.0-beta-2</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<groupId>org.apiaddicts.apitools.dosonarapi</groupId>
<artifactId>dosonarapi</artifactId>
<version>1.3.0-beta-1</version>
<version>1.3.0-beta-2</version>
<packaging>pom</packaging>

<name>SonarOpenAPI</name>
Expand Down
2 changes: 1 addition & 1 deletion sonar-openapi-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.apiaddicts.apitools.dosonarapi</groupId>
<artifactId>dosonarapi</artifactId>
<version>1.3.0-beta-1</version>
<version>1.3.0-beta-2</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,24 +109,14 @@ public void scanFiles() {
}
}

private static boolean isV3Version(JsonNode openapiNode) {
if (openapiNode.isMissing()) return false;
String v = openapiNode.getTokenValue();
return "3.0.0".equals(v) || "3.0.1".equals(v) || "3.0.2".equals(v) || "3.0.3".equals(v) || "3.0.4".equals(v);
}

private static boolean isV31Version(JsonNode openapiNode) {
if (openapiNode.isMissing()) return false;
String v = openapiNode.getTokenValue();
return "3.1.0".equals(v) || "3.1.1".equals(v) || "3.1.2".equals(v);
}
private YamlParser selectParser(JsonNode swaggerNode, JsonNode openapiNode) {
if (!swaggerNode.isMissing()) return OpenApiParser.createV2(configuration);

private YamlParser selectParser(boolean isV2, boolean isV3, boolean isV31, boolean isV32) {
if (isV2) return OpenApiParser.createV2(configuration);
if (isV32) return OpenApiParser.createV32(configuration);
if (isV31) return OpenApiParser.createV31(configuration);
if (isV3) return OpenApiParser.createV3(configuration);
return null;
String version = openapiNode.isMissing() ? null : openapiNode.getTokenValue();
if (version == null) return OpenApiParser.createV3(configuration);
if (version.startsWith("3.2")) return OpenApiParser.createV32(configuration);
if (version.startsWith("3.1")) return OpenApiParser.createV31(configuration);
return OpenApiParser.createV3(configuration);
}

private void scanFile(InputFile inputFile) {
Expand All @@ -136,13 +126,11 @@ private void scanFile(InputFile inputFile) {
String content = getContent(inputFile);
if (!content.contains("swagger") && !content.contains("openapi")) return;
JsonNode rootNode = OpenApiParser.createGeneric(configuration).parse(content);
boolean isV2 = !rootNode.at("/swagger").isMissing();
JsonNode swaggerNode = rootNode.at("/swagger");
JsonNode openapiNode = rootNode.at("/openapi");
boolean isV3 = isV3Version(openapiNode);
boolean isV31 = isV31Version(openapiNode);
boolean isV32 = !openapiNode.isMissing() && openapiNode.getTokenValue().equals("3.2.0");
YamlParser targetParser = selectParser(isV2, isV3, isV31, isV32);
if (targetParser == null) return;

if (swaggerNode.isMissing() && openapiNode.isMissing()) return;
YamlParser targetParser = selectParser(swaggerNode, openapiNode);

visitorContext = new OpenApiVisitorContext(targetParser.parse(content), targetParser.getIssues(), openApiFile);
saveMeasures(inputFile, visitorContext);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,32 @@ public void test_folder() {
System.out.println(errorFiles);
}

@Test
public void unsupported_openapi_version_still_runs_rules() {
activeRules = (new ActiveRulesBuilder())
.create(RuleKey.of(CheckList.YAML_REPOSITORY_KEY, "PathMaskerading"))
.activate()
.build();

inputFile("unsupported-openapi-version.yaml");
sensor().execute(context);

assertThat(context.allIssues()).hasSize(1);
}

@Test
public void unsupported_swagger_version_still_runs_rules() {
activeRules = (new ActiveRulesBuilder())
.create(RuleKey.of(CheckList.YAML_REPOSITORY_KEY, "PathMaskerading"))
.activate()
.build();

inputFile("unsupported-swagger-version.yaml");
sensor().execute(context);

assertThat(context.allIssues()).hasSize(1);
}

@Test
public void cancelled_analysis() {
InputFile inputFile = inputFile("file1.yaml");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
openapi: "1.1.3"
info:
version: 1.0.0
title: Swagger Petstore
paths:
/pets/{petId}:
get:
responses:
'200':
description: success
content:
'application/json':
schema:
type: array
items:
$ref: '#/components/schemas/Pet'
/pets/1234:
get:
responses:
'200':
description: success
content:
'application/json':
schema:
$ref: '#/components/schemas/Pet'
components:
schemas:
Pet:
type: object
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
swagger: "1.2"
info:
version: 1.0.0
title: Swagger Petstore
paths:
/pets/{petId}:
get:
responses:
'200':
description: success
schema:
type: array
items:
$ref: '#/definitions/Pet'
/pets/1234:
get:
responses:
'200':
description: success
schema:
$ref: '#/definitions/Pet'
definitions:
Pet:
type: object
Loading