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
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,8 @@ public class OpenAPIDeserializer {
"default", "discriminator", "readOnly", "writeOnly", "xml", "externalDocs", "example", "deprecated",
"const", "examples", "$id", "$comment", "if", "then", "else", "unevaluatedProperties","unevaluatedItems", "prefixItems",
"contains","contentEncoding","contentMediaType","$anchor","$schema","contentSchema","propertyNames",
"dependentSchemas","dependentRequired","minContains","maxContains","patternProperties", "$vocabulary", "$dynamicAnchor"));
"dependentSchemas","dependentRequired","minContains","maxContains","patternProperties", "$vocabulary",
"$dynamicAnchor", "$dynamicRef"));
protected static Set<String> EXAMPLE_KEYS_31 = new LinkedHashSet<>(Arrays.asList("$ref", "summary", "description",
"value", "externalValue"));
protected static Set<String> HEADER_KEYS_31 = new LinkedHashSet<>(Arrays.asList("$ref", "name", "in", "description",
Expand Down Expand Up @@ -4120,9 +4121,7 @@ public Schema getJsonSchema(JsonNode jsonNode, String location, ParseResult resu
dependentRequired.add(n.textValue());
}
}
if (dependentRequired != null) {
dependentRequiredList.put(name, dependentRequired);
}
dependentRequiredList.put(name, dependentRequired);
}
}
}
Expand All @@ -4143,14 +4142,12 @@ public Schema getJsonSchema(JsonNode jsonNode, String location, ParseResult resu
dependentSchemasList.put(name, dependentSchemas);
}
}
if (dependentSchemasObj != null) {
schema.setDependentSchemas(dependentSchemasList);
}
schema.setDependentSchemas(dependentSchemasList);
}

//prefixItems
ArrayNode prefixItemsArray = getArray("prefixItems", node, false, location, result);
if(prefixItemsArray != null) {
if (prefixItemsArray != null) {
Schema prefixItems = new JsonSchema();

List<Schema> prefixItemsList = new ArrayList<>();
Expand Down Expand Up @@ -4180,11 +4177,9 @@ public Schema getJsonSchema(JsonNode jsonNode, String location, ParseResult resu
Set<String> keys = getKeys(propertiesObj);
for (String name : keys) {
JsonNode propertyValue = propertiesObj.get(name);
if (propertiesObj != null) {
property = getJsonSchema(propertyValue, location, result);
if (property != null) {
properties.put(name, property);
}
property = getJsonSchema(propertyValue, location, result);
if (property != null) {
properties.put(name, property);
}
}
if (propertiesObj != null) {
Expand Down Expand Up @@ -4250,6 +4245,11 @@ public Schema getJsonSchema(JsonNode jsonNode, String location, ParseResult resu
schema.set$dynamicAnchor(value);
}

value = getString("$dynamicRef", node, false, location, result);
if (value != null) {
schema.set$dynamicRef(value);
}

value = getString("$id", node, false, location, result);
if (value != null) {
schema.set$id(value);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package io.swagger.v3.parser.test;

import io.swagger.v3.oas.models.media.Schema;
import io.swagger.v3.parser.OpenAPIV3Parser;
import io.swagger.v3.parser.core.models.SwaggerParseResult;
import org.testng.annotations.Test;

import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;

public class OpenAPIV3ParserDynamicRefTest {
@Test
public void testDynamicRefParsing() {
SwaggerParseResult result = new OpenAPIV3Parser()
.readLocation("dynamicRef/dynamicref-example.yaml", null, null);

assertNotNull(result.getOpenAPI(), "Parsed OpenAPI object should not be null");

Schema<?> rootSchema = result.getOpenAPI()
.getPaths().get("/tree").getGet()
.getResponses().get("200").getContent()
.get("application/json").getSchema();

assertEquals(rootSchema.get$ref(), "#/components/schemas/Node",
"Expected root schema to be a $ref to Node");

Schema<?> nodeSchema = result.getOpenAPI().getComponents()
.getSchemas().get("Node");

assertNotNull(nodeSchema, "Node schema should be parsed");

Schema<?> childrenSchema = (Schema<?>) nodeSchema.getProperties().get("children");
Schema<?> itemsSchema = childrenSchema.getItems();

// THIS is the actual test: you should have a get$dynamicRef() field
assertEquals("#node", itemsSchema.get$dynamicRef(), "Expected $dynamicRef to be preserved");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
openapi: 3.1.0
info:
title: Test DynamicRef
version: 1.0.0
paths:
/tree:
get:
responses:
'200':
description: OK
content:
application/json:
schema:
$ref: "#/components/schemas/Node"

components:
schemas:
Node:
$id: "https://example.com/schemas/node"
$dynamicAnchor: "node"
type: object
properties:
name:
type: string
children:
type: array
items:
$dynamicRef: "#node"
6 changes: 0 additions & 6 deletions modules/swagger-parser/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,6 @@
<version>${jmockit-version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit-version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,13 @@
import io.swagger.v3.core.util.Json;
import java.math.BigDecimal;
import java.math.MathContext;
import org.junit.Test;

import org.testng.annotations.Test;
import org.testng.Assert;

import java.util.Map;

import java.util.List;


import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;
Expand Down Expand Up @@ -772,5 +771,6 @@ public void testIssue1552AdditionalProps() throws Exception {
" x-original-swagger-version: \"2.0\"\n" +
"openapi31: false\n");
}

}

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
openapi: 3.1.0
info:
title: Test DynamicRef
version: 1.0.0
paths:
/tree:
get:
responses:
'200':
description: OK
content:
application/json:
schema:
$ref: "#/components/schemas/Node"

components:
schemas:
Node:
$id: "https://example.com/schemas/node"
$dynamicAnchor: "node"
type: object
properties:
name:
type: string
children:
type: array
items:
$dynamicRef: "#node"
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@
<swagger-parser-v2-version>1.0.73</swagger-parser-v2-version>
<commons-io-version>2.18.0</commons-io-version>
<slf4j-version>2.0.9</slf4j-version>
<swagger-core-version>2.2.29</swagger-core-version>
<swagger-core-version>2.2.32</swagger-core-version>
<swagger-core-v2-version>1.6.15</swagger-core-v2-version>
<junit-version>4.13.2</junit-version>
<testng-version>7.11.0</testng-version>
Expand Down
Loading