Skip to content

Commit 346f8ac

Browse files
gracekarinafrantuma
authored andcommitted
oas 3.1 - test for exclusiveMaximum and ExclusiveMinimun
1 parent c026f57 commit 346f8ac

File tree

3 files changed

+97
-12
lines changed

3 files changed

+97
-12
lines changed

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4053,6 +4053,26 @@ public Schema getJsonSchema(ObjectNode node, String location, ParseResult result
40534053
schema.setDeprecated(bool);
40544054
}
40554055

4056+
value = getString("$anchor", node, false, location, result);
4057+
if (value != null) {
4058+
schema.set$anchor(value);
4059+
}
4060+
4061+
value = getString("$id", node, false, location, result);
4062+
if (value != null) {
4063+
schema.set$id(value);
4064+
}
4065+
4066+
value = getString("$schema", node, false, location, result);
4067+
if (value != null) {
4068+
schema.set$schema(value);
4069+
}
4070+
4071+
value = getString("$comment", node, false, location, result);
4072+
if (value != null) {
4073+
schema.set$comment(value);
4074+
}
4075+
40564076
Map<String, Object> extensions = getExtensions(node);
40574077
if (extensions != null && extensions.size() > 0) {
40584078
schema.setExtensions(extensions);

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

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ public void testSiblingsReferenceObjects() {
240240
}
241241

242242
@Test(description = "Test siblings with $ref for maxItems, properties, description, required")
243-
public void testSiblingsReferenceJSONSchema() {
243+
public void testSiblingsReferenceJSONSchema1() {
244244
ParseOptions options = new ParseOptions();
245245
String refSibling = "openapi: 3.1.0\n" +
246246
"info:\n" +
@@ -274,4 +274,70 @@ public void testSiblingsReferenceJSONSchema() {
274274
assertTrue(profile.getProperties().containsKey("login"));
275275
assertTrue(profile.getProperties().containsKey("password"));
276276
}
277+
278+
@Test(description = "Test siblings with $ref for patternProperties, pattern, additionalProperties")
279+
public void testSiblingsReferenceJSONSchema2() {
280+
ParseOptions options = new ParseOptions();
281+
String refSibling = "openapi: 3.1.0\n" +
282+
"info:\n" +
283+
" title: siblings JSONschema\n" +
284+
" version: 1.0.0\n" +
285+
"servers:\n" +
286+
" - url: /\n" +
287+
"paths: { }\n" +
288+
"components:\n" +
289+
" schemas:\n" +
290+
" profile:\n" +
291+
" $ref: ./ex.json#user-profile\n" +
292+
" pattern: \\d\\d\\d\\d-\\d\\d-\\d\\d\n" +
293+
" patternProperties:\n" +
294+
" \"^S_\":\n" +
295+
" type: string\n" +
296+
" \"^I_\":\n" +
297+
" type: integer\n" +
298+
" additionalProperties: false";
299+
SwaggerParseResult result = new OpenAPIV3Parser().readContents( refSibling , null, options);
300+
OpenAPI openAPI = result.getOpenAPI();
301+
assertNotNull(openAPI);
302+
Schema profile = openAPI.getComponents().getSchemas().get("profile");
303+
assertNotNull(profile.get$ref());
304+
assertEquals(profile.getPattern(),"\\d\\d\\d\\d-\\d\\d-\\d\\d");
305+
assertNotNull(profile.getAdditionalProperties());
306+
assertTrue(profile.getPatternProperties().containsKey("^S_"));
307+
}
308+
309+
@Test(description = "Test siblings with $ref for patternProperties, pattern, additionalProperties")
310+
public void testSiblingsReferenceJSONSchema3() {
311+
ParseOptions options = new ParseOptions();
312+
String refSibling = "openapi: 3.1.0\n" +
313+
"info:\n" +
314+
" title: siblings JSONschema\n" +
315+
" version: 1.0.0\n" +
316+
"servers:\n" +
317+
" - url: /\n" +
318+
"paths: { }\n" +
319+
"components:\n" +
320+
" schemas:\n" +
321+
" profile:\n" +
322+
" $id: profile-id\n" +
323+
" $anchor: foo\n" +
324+
" $schema: https://json-schema.org/draft/2020-12/schema\n" +
325+
" $comment: end user should not see this comment\n" +
326+
" type:\n" +
327+
" - string\n" +
328+
" - integer\n" +
329+
" exclusiveMaximum: 12\n" +
330+
" exclusiveMinimum: 1\n" +
331+
" $ref: ./ex.json#user-profile";
332+
SwaggerParseResult result = new OpenAPIV3Parser().readContents( refSibling , null, options);
333+
OpenAPI openAPI = result.getOpenAPI();
334+
assertNotNull(openAPI);
335+
Schema profile = openAPI.getComponents().getSchemas().get("profile");
336+
assertNotNull(profile.get$ref());
337+
assertEquals(profile.get$anchor(),"foo");
338+
assertEquals(profile.get$id(),"profile-id");
339+
assertTrue(profile.getExclusiveMaximumValue().intValue()==12);
340+
assertTrue(profile.getExclusiveMinimumValue().intValue()==1);
341+
assertEquals(profile.get$comment(),"end user should not see this comment");
342+
}
277343
}

modules/swagger-parser-v3/src/test/resources/3.1.0/schemaSiblings.yaml

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,13 @@ paths: { }
88
components:
99
schemas:
1010
profile:
11-
description: siblings refs
12-
required:
13-
- login
14-
- password
15-
maxItems: 2
16-
$ref: ./ex.json#user-profile
17-
properties:
18-
login:
19-
type: string
20-
password:
21-
type: string
11+
$id: profile-id
12+
$anchor: foo
13+
$schema: https://json-schema.org/draft/2020-12/schema
14+
$comment: end user should not see this comment
15+
type:
16+
- string
17+
- integer
18+
exclusiveMaximum: 12
19+
exclusiveMinimum: 1
20+
$ref: ./ex.json#user-profile

0 commit comments

Comments
 (0)