diff --git a/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/processors/SchemaProcessor.java b/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/processors/SchemaProcessor.java index c2001dcc1b..3fefd2ee1d 100644 --- a/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/processors/SchemaProcessor.java +++ b/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/processors/SchemaProcessor.java @@ -258,11 +258,11 @@ private void processReferenceSchemaForProperty(Schema schema) { String $ref = schema.get$ref(); final String newRef = externalRefProcessor.processRefToExternalSchema($ref, refFormat); - if (newRef != null && !newRef.startsWith("#/components") && refFormat.equals(RefFormat.RELATIVE)) { + if (newRef != null && !newRef.startsWith("#/components")) { schema.set$ref(RefType.SCHEMAS.getInternalPrefix() + newRef); } Schema internalSchema = schema.getItems(); - if (internalSchema != null && internalSchema.get$ref().startsWith("..")) { + if (internalSchema != null && !internalSchema.get$ref().startsWith("#/components")) { processReferenceSchemaForProperty(schema.getItems()); } } diff --git a/modules/swagger-parser-v3/src/test/java/io/swagger/v3/parser/test/OpenAPIV3ParserTest.java b/modules/swagger-parser-v3/src/test/java/io/swagger/v3/parser/test/OpenAPIV3ParserTest.java index d096201720..caffe41a7c 100644 --- a/modules/swagger-parser-v3/src/test/java/io/swagger/v3/parser/test/OpenAPIV3ParserTest.java +++ b/modules/swagger-parser-v3/src/test/java/io/swagger/v3/parser/test/OpenAPIV3ParserTest.java @@ -3386,26 +3386,25 @@ public void testValidateExternalRefsTrue() { } - @Ignore - @Test(description = "test that a model in a folder that has a ref to a model in the classpath is properly resolved.") - public void testIssue1891() { - ParseOptions options = new ParseOptions(); - options.setResolve(true); - options.setFlatten(true); - - SwaggerParseResult result = new OpenAPIV3Parser().readLocation("./issue-1891/openapi.yaml", null, options); - assertTrue(result.getMessages().isEmpty()); - - // Expect all references to be properly resolved to local references. - OpenAPI openAPI = result.getOpenAPI(); - Schema localModel = openAPI.getComponents().getSchemas().get("LocalModel"); - Schema typesModel = openAPI.getComponents().getSchemas().get("TypesModel"); - Schema sharedModel = openAPI.getComponents().getSchemas().get("SharedModel"); - - assertEquals("#/components/schemas/TypesModel", localModel.getProperties().get("sharedModelField").get$ref()); - assertEquals("#/components/schemas/SharedModel", typesModel.get$ref()); - assertNotNull(sharedModel); - } +// @Test(description = "test that a model in a folder that has a ref to a model in the classpath is properly resolved.") +// public void testIssue1891() { +// ParseOptions options = new ParseOptions(); +// options.setResolve(true); +// options.setFlatten(true); +// +// SwaggerParseResult result = new OpenAPIV3Parser().readLocation("./issue-1891/openapi.yaml", null, options); +// assertTrue(result.getMessages().isEmpty()); +// +// // Expect all references to be properly resolved to local references. +// OpenAPI openAPI = result.getOpenAPI(); +// Schema localModel = openAPI.getComponents().getSchemas().get("LocalModel"); +// Schema typesModel = openAPI.getComponents().getSchemas().get("TypesModel"); +// Schema sharedModel = openAPI.getComponents().getSchemas().get("SharedModel"); +// +// assertEquals("#/components/schemas/TypesModel", localModel.getProperties().get("sharedModelField").get$ref()); +// assertEquals("#/components/schemas/SharedModel", typesModel.get$ref()); +// assertNotNull(sharedModel); +// } @Test(description = "directly parsed definition, tested in previous method as reference relative/local ") public void testValidateDefinition() {