-
Notifications
You must be signed in to change notification settings - Fork 536
Closed
Description
Issue found with swagger-parser version 2.0.12. This may also be related to swagger-api/swagger-ui#4442, as it seems content
is not well supported in some areas.
Given a common.yaml:
openapi: "3.0.0"
info:
version: 15.3.0
title: "Common Data Types"
paths: {}
components:
schemas:
PlmnId:
type: object
properties:
mcc:
type: string
mnc:
type: string
and a simple test1.yaml that references it from a content
parameter:
openapi: "3.0.0"
info:
version: 15.3.0
title: test
paths:
/my-app:
get:
parameters:
- name: target-plmn-list
in: query
content:
application/json:
schema:
type: array
items:
$ref: 'common.yaml#/components/schemas/PlmnId'
minItems: 1
responses:
'200':
description: Expected response to a valid request
schema:
type: string
The following test code shows the external reference is not resolved
ParseOptions options = new ParseOptions();
options.setResolve(true);
OpenAPIV3Parser parser = new OpenAPIV3Parser();
SwaggerParseResult result = parser.readLocation("test1.yaml", Collections.emptyList(), options);
OpenAPI test1 = result.getOpenAPI();
ArraySchema schema = (ArraySchema)test1.getPaths().get("/my-app").getGet().getParameters().get(0).getContent().get("application/json").getSchema();
System.out.println("items/$ref=" + schema.getItems().get$ref());
System.out.println("components=" + test1.getComponents());
Output:
items/$ref=./common.yaml#/components/schemas/PlmnId
components=null
If content
is not used (see test2.yaml below) with slightly tweaked test code, the external reference can be resolved:
openapi: "3.0.0"
info:
version: 15.3.0
title: test
paths:
/my-app:
get:
parameters:
- name: target-plmn-list
in: query
schema:
type: array
items:
$ref: 'common.yaml#/components/schemas/PlmnId'
minItems: 1
responses:
'200':
description: Expected response to a valid request
schema:
type: string
Test code:
ParseOptions options = new ParseOptions();
options.setResolve(true);
OpenAPIV3Parser parser = new OpenAPIV3Parser();
SwaggerParseResult result = parser.readLocation("test2.yaml", Collections.emptyList(), options);
OpenAPI test2 = result.getOpenAPI();
ArraySchema schema = (ArraySchema)test2.getPaths().get("/my-app").getGet().getParameters().get(0).getSchema();
System.out.println("items/$ref=" + schema.getItems().get$ref());
System.out.println("components=" + test2.getComponents().getSchemas().keySet());
Output:
items/$ref=#/components/schemas/PlmnId
components=[PlmnId]
A potential fix is to add support for Content
in io.swagger.v3.parser.processors.ParameterProcessor.processParameters(List<Parameter> parameters)
. By adding the new code block for Content
, then the original test code gives the expected output.
for (Parameter parameter : processedPathLevelParameters) {
Schema schema = parameter.getSchema();
if(schema != null){
schemaProcessor.processSchema(schema);
}
Content content = parameter.getContent();
if (content != null) {
for (MediaType mediaType : content.values()) {
schema = mediaType.getSchema();
schemaProcessor.processSchema(schema);
}
}
}
Metadata
Metadata
Assignees
Labels
No labels