Skip to content

Commit b706d14

Browse files
committed
adding fix for 901 in 3.0
1 parent c9557d9 commit b706d14

File tree

4 files changed

+14
-5
lines changed

4 files changed

+14
-5
lines changed

modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/models/RefType.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
public enum RefType {
77
COMPONENTS("#/components/"),
8+
SCHEMAS("#/components/schemas/"),
89
PATH("#/paths/");
910

1011
private final String internalPrefix;

modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/processors/ExternalRefProcessor.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import io.swagger.v3.oas.models.security.SecurityScheme;
2020
import io.swagger.v3.parser.ResolverCache;
2121
import io.swagger.v3.parser.models.RefFormat;
22+
import io.swagger.v3.parser.models.RefType;
2223
import org.apache.commons.lang3.StringUtils;
2324
import org.slf4j.LoggerFactory;
2425

@@ -680,16 +681,17 @@ private void processRefSchema(Schema subRef, String externalFile) {
680681
RefFormat format = computeRefFormat(subRef.get$ref());
681682

682683
if (!isAnExternalRefFormat(format)) {
683-
subRef.set$ref(processRefToExternalSchema(externalFile + subRef.get$ref(), RefFormat.RELATIVE));
684+
subRef.set$ref(RefType.SCHEMAS.getInternalPrefix()+ processRefToExternalSchema(externalFile + subRef.get$ref(), RefFormat.RELATIVE));
684685
return;
685686
}
686687
String $ref = subRef.get$ref();
687688

688689
if (format.equals(RefFormat.RELATIVE)) {
689690
$ref = constructRef(subRef, externalFile);
690691
subRef.set$ref($ref);
692+
}else {
693+
processRefToExternalSchema($ref, format);
691694
}
692-
processRefToExternalSchema($ref, computeRefFormat(subRef.get$ref()));
693695
}
694696

695697

modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/processors/SchemaProcessor.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import io.swagger.v3.oas.models.media.Schema;
1010
import io.swagger.v3.parser.ResolverCache;
1111
import io.swagger.v3.parser.models.RefFormat;
12+
import io.swagger.v3.parser.models.RefType;
1213
import io.swagger.v3.parser.util.RefUtils;
1314

1415
import java.util.HashMap;
@@ -201,7 +202,7 @@ private void processReferenceSchema(Schema schema) {
201202
final String newRef = externalRefProcessor.processRefToExternalSchema($ref, refFormat);
202203

203204
if (newRef != null) {
204-
schema.set$ref(newRef);
205+
schema.set$ref(RefType.SCHEMAS.getInternalPrefix() + newRef);
205206
}
206207
}
207208
}

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,14 @@ public void testIssue901_2() {
7474
options.setResolve(true);
7575
OpenAPI openAPI = new OpenAPIV3Parser().readLocation("issue-901/spec2.yaml",null,options).getOpenAPI();
7676
assertNotNull(openAPI);
77-
String internalRef = openAPI.getPaths().get("/test").getPut().getResponses().get("200").getContent().get("application/json").getSchema().get$ref();
78-
assertEquals(internalRef,"#/components/schemas/Test.Definition");
7977
assertNotNull(openAPI.getComponents());
78+
ArraySchema arraySchema = (ArraySchema) openAPI.getComponents().getSchemas().get("Test.Definition").getProperties().get("stuff");
79+
String internalRef = arraySchema.getItems().get$ref();
80+
assertEquals(internalRef,"#/components/schemas/TEST.THING.OUT.Stuff");
81+
82+
83+
84+
8085

8186
}
8287

0 commit comments

Comments
 (0)