Skip to content

Commit 898f7c3

Browse files
gracekarinafrantuma
authored andcommitted
oas 3.1 - adding tests for unevaluatedItems deprecated
1 parent cd0e2a8 commit 898f7c3

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/util/OpenAPIDeserializer.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3786,7 +3786,6 @@ public Schema getJsonSchema(ObjectNode node, String location, ParseResult result
37863786
}
37873787

37883788
if (node.get("default") != null) {
3789-
//TODO rename method
37903789
if(result.isDefaultSchemaTypeObject()) {
37913790
schema.setDefault(getAnyType("default", node, location, result));
37923791
}
@@ -3993,6 +3992,15 @@ public Schema getJsonSchema(ObjectNode node, String location, ParseResult result
39933992
}
39943993
}
39953994

3995+
ObjectNode unevaluatedItems = getObject("unevaluatedItems", node, false, location, result);
3996+
if (unevaluatedItems != null) {
3997+
Schema unevaluatedItemsSchema = getJsonSchema(unevaluatedItems, location, result);
3998+
if (unevaluatedItemsSchema != null) {
3999+
schema.setUnevaluatedItems(unevaluatedItemsSchema);
4000+
}
4001+
}
4002+
4003+
39964004
Map<String, List<String>> dependentRequiredList = new LinkedHashMap<>();
39974005
ObjectNode dependentRequiredObj = getObject("dependentRequired", node, false, location, result);
39984006
List<String> dependentRequired = new ArrayList<>();

modules/swagger-parser-v3/src/test/java/io/swagger/v3/parser/test/OAI31DeserializationTest.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ public void testSiblingsReferenceJSONSchema2() {
366366
assertTrue(profile.getPatternProperties().containsKey("^S_"));
367367
}
368368

369-
@Test(description = "Test siblings with $ref for patternProperties, pattern, additionalProperties,exclusiveMaximum,exclusiveMinimum")
369+
@Test(description = "Test siblings with $ref for patternProperties, pattern, additionalProperties,exclusiveMaximum,exclusiveMinimum, $schema")
370370
public void testSiblingsReferenceJSONSchema3() {
371371
ParseOptions options = new ParseOptions();
372372
String refSibling = "openapi: 3.1.0\n" +
@@ -394,6 +394,7 @@ public void testSiblingsReferenceJSONSchema3() {
394394
assertNotNull(openAPI);
395395
Schema profile = openAPI.getComponents().getSchemas().get("profile");
396396
assertNotNull(profile.get$ref());
397+
assertEquals(profile.get$schema(), "https://json-schema.org/draft/2020-12/schema");
397398
assertEquals(profile.get$anchor(),"foo");
398399
assertEquals(profile.get$id(),"profile-id");
399400
assertTrue(profile.getExclusiveMaximumValue().intValue()==12);
@@ -434,7 +435,7 @@ public void testSiblingsReferenceJSONSchema4() {
434435
assertTrue(profile.getContentSchema().getTypes().contains("string"));
435436
}
436437

437-
@Test(description = "Test siblings with $ref for contains, maxContains, minContains, prefixItems, uniqueItems, propertyNames, unevaluatedProperties")
438+
@Test(description = "Test siblings with $ref for contains, maxContains, minContains, prefixItems, uniqueItems, propertyNames, unevaluatedProperties, unevaluatedItems")
438439
public void testSiblingsReferenceJSONSchema5() {
439440
ParseOptions options = new ParseOptions();
440441
String refSibling = "openapi: 3.1.0\n" +
@@ -459,6 +460,8 @@ public void testSiblingsReferenceJSONSchema5() {
459460
" $ref: ./ex.json#user-profile\n" +
460461
" unevaluatedProperties:\n" +
461462
" type: object\n"+
463+
" unevaluatedItems:\n" +
464+
" type: object\n" +
462465
" Person:\n" +
463466
" type: array\n" +
464467
" prefixItems:\n" +
@@ -510,6 +513,9 @@ public void testSiblingsReferenceJSONSchema5() {
510513
assertNotNull(patientPersonSchema.getUnevaluatedProperties());
511514
assertTrue(patientPersonSchema.getUnevaluatedProperties() instanceof Boolean);
512515
assertFalse(((Boolean)patientPersonSchema.getUnevaluatedProperties()).booleanValue());
516+
517+
//unevaluatedItems
518+
assertNotNull(profile.getUnevaluatedItems());
513519
}
514520

515521
@Test(description = "Test siblings with $ref for if - then - else, dependentRequired, dependentSchemas")
@@ -672,6 +678,7 @@ public void testArbitraryKeywordsJSONSchema() {
672678
"components:\n" +
673679
" schemas:\n" +
674680
" Fruit:\n" +
681+
" deprecated: true\n"+
675682
" type: string\n" +
676683
" example: kiwi\n" +
677684
" examples:\n" +
@@ -684,6 +691,7 @@ public void testArbitraryKeywordsJSONSchema() {
684691
assertNotNull(openAPI);
685692
assertNotNull(openAPI.getComponents().getSchemas().get("Fruit").getExtensions().get("arbitraryKeyword"));
686693
assertNotNull(openAPI.getComponents().getSchemas().get("Fruit").getExtensions().get("x-normalExtension"));
694+
assertTrue(openAPI.getComponents().getSchemas().get("Fruit").getDeprecated());
687695
}
688696

689697
@Test(description = "Test for Tuple parsing")

0 commit comments

Comments
 (0)