JSON Reference \"#/definitions/ <...> \" cannot be resolved in RestAssured tests
I've encountered problem that one of my definitions is not resolved.
When I tried to debug it looks one definition is missing in new schema what is converted from swagger 2.0 to open api. Definition is missing in inventory instance (during debug).
class: io.swagger.v3.parser.converter.SwaggerConverter
method: public SwaggerParseResult convert(SwaggerDeserializationResult parse)
line: SwaggerInventory inventory = (new SwaggerInventory()).process(parse.getSwagger());
While I was debuggng, almost all definitions and references to them where updated from #/definitions/ to #/components/schemas/
But all references to one definition are not updated, when it was $ref in allOf. It is used in allOf.
I've tried to test in: com.atlassian.oai.validator.restassuredOpenApiValidationFilterTest, my method below:
@Test
public void filter_returnsResponse_ifValidationSucceeds_forGetWithLinkArrays() {
OpenApiInteractionValidator validator = OpenApiInteractionValidator
.createFor("api-with-linkArrays-swagger.yaml")
// .withLevelResolver(LevelResolverFactory.withAdditionalPropertiesIgnored())
.build();
classUnderTest = new OpenApiValidationFilter(validator);
assertThat(classUnderTest.filter(
requestSpec("GET", "/hello/John"), null,
response(200,
ClasspathHelper.loadFileFromClasspath("api-with-linkArrays-expected-response.json"))),
notNullValue());
}
See part of spec (below), full file in attachment.
definitions:
Message:
type: object
properties:
message:
type: string
links:
allOf:
- $ref: '#/definitions/Links'
Links:
discriminator: type
type: array
Error: com.atlassian.oai.validator.restassured.OpenApiValidationFilter$OpenApiValidationException: { "messages" : [ { "key" : "validation.response.body.schema.processingError", "level" : "ERROR", "message" : "JSON Reference \"#/definitions/Links\" cannot be resolved", "context" : { "requestPath" : "/hello/John", "responseStatus" : 200, "location" : "RESPONSE", "requestMethod" : "GET" } } ] }
Comments (4)
-
-
When I converted swagger 2.0 doc to open api 3.0.0 using https://mermade.org.uk/openapi-converter It works fine and all references to /components/schemas/* were updated.
Like
Links: allOf: - $ref: "#/components/schemas/Links"
That's why I think it can be a problem in SwaggerConverter.
-
- changed status to resolved
Closing due to inactivity. Please re-open if the problem still exists in the latest version.
-
I can confirm that upgrading to version
2.11.1
made the error go away. - Log in to comment
I was debugging for several hours and I haven't found solution, but I can help how to reproduce it. I hope this is a valid problem at all. I would need this solution to use your restassured.OpenApiValidationFilterfilter in a lot of tests for API project.