Skip to content

Commit 1513657

Browse files
gracekarinafrantuma
authored andcommitted
oas 3.1 - test ref siblings: const, contentEncoding, contentMediaType
1 parent 346f8ac commit 1513657

File tree

3 files changed

+50
-15
lines changed

3 files changed

+50
-15
lines changed

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

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4004,10 +4004,20 @@ public Schema getJsonSchema(ObjectNode node, String location, ParseResult result
40044004
}
40054005
}
40064006

4007-
//sets const value according to the schema type
4008-
// TODO check types
4009-
if (node.get("const") != null) {
4010-
schema.setConst(node.get("const"));
4007+
//const is a String
4008+
value = getString("const", node, false, location, result);
4009+
if (value != null) {
4010+
schema.setConst(value);
4011+
}
4012+
4013+
value = getString("contentEncoding", node, false, location, result);
4014+
if (value != null) {
4015+
schema.setContentEncoding(value);
4016+
}
4017+
4018+
value = getString("contentMediaType", node, false, location, result);
4019+
if (value != null) {
4020+
schema.setContentMediaType(value);
40114021
}
40124022

40134023
bool = getBoolean("readOnly", node, false, location, result);

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

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ public void testSiblingsReferenceJSONSchema2() {
280280
ParseOptions options = new ParseOptions();
281281
String refSibling = "openapi: 3.1.0\n" +
282282
"info:\n" +
283-
" title: siblings JSONschema\n" +
283+
" title: siblings JSONSchema\n" +
284284
" version: 1.0.0\n" +
285285
"servers:\n" +
286286
" - url: /\n" +
@@ -311,7 +311,7 @@ public void testSiblingsReferenceJSONSchema3() {
311311
ParseOptions options = new ParseOptions();
312312
String refSibling = "openapi: 3.1.0\n" +
313313
"info:\n" +
314-
" title: siblings JSONschema\n" +
314+
" title: siblings JSONSchema\n" +
315315
" version: 1.0.0\n" +
316316
"servers:\n" +
317317
" - url: /\n" +
@@ -339,5 +339,34 @@ public void testSiblingsReferenceJSONSchema3() {
339339
assertTrue(profile.getExclusiveMaximumValue().intValue()==12);
340340
assertTrue(profile.getExclusiveMinimumValue().intValue()==1);
341341
assertEquals(profile.get$comment(),"end user should not see this comment");
342+
assertTrue(profile.getTypes().contains("string"));
343+
assertTrue(profile.getTypes().contains("integer"));
344+
}
345+
346+
@Test(description = "Test siblings with $ref for const, contentEncoding, contentMediaType")
347+
public void testSiblingsReferenceJSONSchema4() {
348+
ParseOptions options = new ParseOptions();
349+
String refSibling = "openapi: 3.1.0\n" +
350+
"info:\n" +
351+
" title: siblings JSONSchema\n" +
352+
" version: 1.0.0\n" +
353+
"servers:\n" +
354+
" - url: /\n" +
355+
"paths: { }\n" +
356+
"components:\n" +
357+
" schemas:\n" +
358+
" profile:\n" +
359+
" const: sales\n" +
360+
" contentEncoding: base64\n" +
361+
" contentMediaType: text/html\n" +
362+
" $ref: ./ex.json#user-profile";
363+
SwaggerParseResult result = new OpenAPIV3Parser().readContents( refSibling , null, options);
364+
OpenAPI openAPI = result.getOpenAPI();
365+
assertNotNull(openAPI);
366+
Schema profile = openAPI.getComponents().getSchemas().get("profile");
367+
assertNotNull(profile.get$ref());
368+
assertEquals(profile.getConst(),"sales");
369+
assertEquals(profile.getContentEncoding(),"base64");
370+
assertEquals(profile.getContentMediaType(),"text/html");
342371
}
343372
}

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

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,9 @@ paths: { }
88
components:
99
schemas:
1010
profile:
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
11+
const: sales
12+
contentEncoding: base64
13+
contentMediaType: text/html
14+
contentSchema:
15+
type: string
2016
$ref: ./ex.json#user-profile

0 commit comments

Comments
 (0)