Skip to content

Commit 0e94297

Browse files
author
Enrique Gomez
committed
functionalities added
1 parent ac2a07a commit 0e94297

File tree

9 files changed

+1207
-11
lines changed

9 files changed

+1207
-11
lines changed

openapi-front-end/src/main/java/org/apiaddicts/apitools/dosonarapi/api/v31/OpenApi31Grammar.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ public static YamlGrammarBuilder create() {
9191
b.mandatoryProperty("info", INFO),
9292
b.property("servers", b.array(SERVER)),
9393
b.mandatoryProperty("paths", PATHS),
94+
b.property("webhooks", WEBHOOKS),
9495
b.property("components", COMPONENTS),
9596
b.property("security", b.array(SECURITY_REQUIREMENT)),
9697
b.property("tags", b.array(TAG)),
@@ -107,6 +108,7 @@ public static YamlGrammarBuilder create() {
107108
buildInfo(b);
108109
buildServer(b);
109110
buildPaths(b);
111+
buildWebhooks(b);
110112
buildComponents(b);
111113
buildSecurityDefinitions(b);
112114
buildTags(b);
@@ -311,7 +313,6 @@ private static void buildComponents(YamlGrammarBuilder b) {
311313
buildParameters(b);
312314
buildResponses(b);
313315
buildSchema(b);
314-
buildWebhooks(b);
315316
buildCallbacks(b);
316317
}
317318

@@ -343,15 +344,18 @@ private static void buildSchema(YamlGrammarBuilder b) {
343344
b.property("$schema", b.string()),
344345
b.property("additionalProperties", b.firstOf(b.bool(), REF, SCHEMA)),
345346
b.property("description", DESCRIPTION),
347+
b.property("unevaluatedProperties", b.bool()),
346348
b.property("format", b.string()),
347349
b.property("default", b.anything()),
348350
b.property("nullable", b.bool()),
349351
b.property("discriminator", DISCRIMINATOR),
352+
b.property("const", b.anything()),
350353
b.property("readOnly", b.bool()),
351354
b.property("writeOnly", b.bool()),
352355
b.property("xml", XML),
353356
b.property("externalDocs", EXTERNAL_DOC),
354357
b.property("examples", b.array(b.anything())),
358+
b.property("example", b.anything()),
355359
b.property("deprecated", b.bool()),
356360
b.patternProperty(EXTENSION_PATTERN, b.anything())));
357361
b.rule(SCHEMA_PROPERTIES).is(b.object(b.patternProperty(".*", b.firstOf(REF, SCHEMA))));
@@ -370,7 +374,7 @@ private static void buildSchema(YamlGrammarBuilder b) {
370374

371375
private static void buildWebhooks(YamlGrammarBuilder b) {
372376
b.rule(WEBHOOKS).is(b.object(
373-
b.property("webhooks", WEBHOOK), // Usar una propiedad simple en lugar de patternProperty
377+
b.patternProperty("^.*", WEBHOOK),
374378
b.patternProperty(EXTENSION_PATTERN, b.anything())));
375379
b.rule(WEBHOOK).is(b.object(
376380
b.property("$ref", b.string()),
@@ -477,6 +481,7 @@ private static void buildInfo(YamlGrammarBuilder b) {
477481
b.rule(LICENSE).is(b.object(
478482
b.mandatoryProperty("name", b.string()),
479483
b.property("url", b.string()),
484+
b.property("identifier", b.string()),
480485
b.patternProperty(EXTENSION_PATTERN, b.anything())));
481486
}
482487
}

openapi-front-end/src/main/java/org/apiaddicts/apitools/dosonarapi/openapi/parser/OpenApiParser.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import org.apiaddicts.apitools.dosonarapi.api.v2.OpenApi2Grammar;
2323
import org.apiaddicts.apitools.dosonarapi.api.v3.OpenApi3Grammar;
24+
import org.apiaddicts.apitools.dosonarapi.api.v31.OpenApi31Grammar;
2425
import org.apiaddicts.apitools.dosonarapi.openapi.OpenApiConfiguration;
2526
import org.apiaddicts.apitools.dosonarapi.sslr.yaml.grammar.YamlParser;
2627

@@ -37,6 +38,10 @@ public static YamlParser createV3(OpenApiConfiguration configuration) {
3738
return YamlParser.builder().withCharset(configuration.getCharset()).withGrammar(OpenApi3Grammar.create()).withStrictValidation(configuration.isStrict()).build();
3839
}
3940

41+
public static YamlParser createV31(OpenApiConfiguration configuration) {
42+
return YamlParser.builder().withCharset(configuration.getCharset()).withGrammar(OpenApi31Grammar.create()).withStrictValidation(configuration.isStrict()).build();
43+
}
44+
4045
public static YamlParser createGeneric(OpenApiConfiguration configuration) {
4146
return YamlParser.builder().withCharset(configuration.getCharset()).withStrictValidation(configuration.isStrict()).build();
4247
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package org.apiaddicts.apitools.dosonarapi.api.v31;
2+
3+
public class IdentifierTest {
4+
5+
}
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,19 @@
1717
* along with this program; if not, write to the Free Software Foundation,
1818
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
1919
*/
20-
package org.apiaddicts.apitools.dosonarapi.api.v3;
20+
package org.apiaddicts.apitools.dosonarapi.api.v31;
2121

2222
import org.apiaddicts.apitools.dosonarapi.openapi.BaseNodeTest;
2323
import org.junit.Test;
2424
import org.apiaddicts.apitools.dosonarapi.sslr.yaml.grammar.JsonNode;
2525

26-
public class LicenseTest extends BaseNodeTest<OpenApi3Grammar> {
27-
@Test
28-
public void can_parse_full_definition() {
29-
JsonNode node = parseResource(OpenApi3Grammar.LICENSE, "/models/shared/license.yaml");
26+
public class LicenseTest extends BaseNodeTest<OpenApi31Grammar>{
3027

31-
assertEquals("Apache 2.0", node, "/name");
32-
assertEquals("https://www.apache.org/licenses/LICENSE-2.0.html", node, "/url");
33-
}
28+
@Test
29+
public void license_identifier() {
30+
JsonNode node = parseResource(OpenApi31Grammar.COMPONENTS, "/models/v31/webhook.yaml");
3431

32+
assertPropertyKeys(node).containsOnly("webhooks");
33+
}
34+
3535
}

openapi-front-end/src/test/java/org/apiaddicts/apitools/dosonarapi/api/v31/WebhooksTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,11 @@ public void component_webhook() {
3030

3131
assertPropertyKeys(node).containsOnly("webhooks");
3232
}
33+
34+
@Test
35+
public void webhook_test() {
36+
JsonNode node = parseResource(OpenApi31Grammar.WEBHOOKS, "/models/v31/webhookfirstlevel.yaml");
37+
38+
assertPropertyKeys(node).containsOnly("newBooking");
39+
}
3340
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
newBooking:
2+
post:
3+
operationId: new-booking
4+
summary: New Booking
5+
description: |
6+
Subscribe to new bookings being created, to update integrations for your users. Related data is available via the links provided in the request.
7+
tags:
8+
- Bookings
9+
requestBody:
10+
content:
11+
application/json:
12+
schema:
13+
allOf:
14+
- $ref: "#/components/schemas/Booking"
15+
- properties:
16+
links:
17+
allOf:
18+
- $ref: "#/components/schemas/Links-Self"
19+
- $ref: "#/components/schemas/Links-Pagination"
20+
example:
21+
id: efdbb9d1-02c2-4bc3-afb7-6788d8782b1e
22+
trip_id: efdbb9d1-02c2-4bc3-afb7-6788d8782b1e
23+
passenger_name: John Doe
24+
has_bicycle: true
25+
has_dog: true
26+
links:
27+
self: https://api.example.com/bookings/1725ff48-ab45-4bb5-9d02-88745177dedb
28+
responses:
29+
"200":
30+
description: Return a 200 status to indicate that the data was received successfully.

sonar-openapi-plugin/src/main/java/org/apiaddicts/apitools/dosonarapi/plugin/OpenApiAnalyzer.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,20 @@ private void scanFile(InputFile inputFile) {
119119
if (!content.contains("swagger") && !content.contains("openapi")) return;
120120
JsonNode rootNode = OpenApiParser.createGeneric(configuration).parse(content);
121121
boolean isV2 = !rootNode.at("/swagger").isMissing();
122-
boolean isV3 = !rootNode.at("/openapi").isMissing();
122+
JsonNode openapiNode = rootNode.at("/openapi");
123+
boolean isV3 = !openapiNode.isMissing() && (
124+
openapiNode.getTokenValue().equals("3.0.0") ||
125+
openapiNode.getTokenValue().equals("3.0.1") ||
126+
openapiNode.getTokenValue().equals("3.0.2") ||
127+
openapiNode.getTokenValue().equals("3.0.3")
128+
);
129+
130+
// Verificar si el nodo "/openapi" está presente y su valor es 3.1.0 para isV31
131+
boolean isV31 = !openapiNode.isMissing() && openapiNode.getTokenValue().equals("3.1.0");
123132
YamlParser targetParser = null;
124133
if (isV2) targetParser = OpenApiParser.createV2(configuration);
125134
if (isV3) targetParser = OpenApiParser.createV3(configuration);
135+
if (isV31) targetParser = OpenApiParser.createV31(configuration);
126136
if (targetParser == null) return;
127137

128138
visitorContext = new OpenApiVisitorContext(targetParser.parse(content), targetParser.getIssues(), openApiFile);

sonar-openapi-plugin/src/test/java/org/apiaddicts/apitools/dosonarapi/plugin/OpenApiScannerSensorTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,18 @@ public void parse_yaml_tabs_ok() {
177177
assertThat(context.allIssues()).hasSize(0);
178178
assertThat(context.allAnalysisErrors()).hasSize(0);
179179
}
180+
181+
@Test
182+
public void parse_yaml_tabs_ok_31() {
183+
inputFile("file2.yaml");
184+
activeRules = (new ActiveRulesBuilder())
185+
.create(RuleKey.of(CheckList.REPOSITORY_KEY, ParsingErrorCheck.CHECK_KEY))
186+
.activate()
187+
.build();
188+
sensor().execute(context);
189+
assertThat(context.allIssues()).hasSize(0);
190+
assertThat(context.allAnalysisErrors()).hasSize(0);
191+
}
180192

181193
//@Test
182194
public void test_folder() {

0 commit comments

Comments
 (0)