Skip to content

Commit

Permalink
Comment corner case test
Browse files Browse the repository at this point in the history
  • Loading branch information
Yehor Kovalchuk committed Mar 16, 2023
1 parent fd923d3 commit 45e3f97
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 45e3f97

Please sign in to comment.