Repository navigation
Closed
Description
When $ref references an external yaml file, Swagger-Parser can merge everything and produce an instance of OpenAPI where the references are local.
The key point is to use setResolve(true).
See more: https://j2r2b.github.io/2018/05/26/external-ref-openapi.html
It was reported that this does not work with $ref in parameter. It works well in request body
and response.
Test case, in the same folder, put two files:
Main OAS3 file: main.yaml
openapi: 3.0.1
info:
title: ping test
version: '1.0'
servers:
- url: 'http://localhost:8000/'
paths:
/some/ping:
get:
operationId: pingGet
parameters:
- name: i
in: query
description: Test
required: true
schema:
$ref: './external.yaml#/SomeId'
responses:
'201':
description: OK
components:
schemas: {}External file: other.yaml
SomeId:
type: integer
format: int32
description: My value 123
example: 123Run this code:
OpenAPIParser openApiParser = new OpenAPIParser();
ParseOptions options = new ParseOptions();
options.setResolve(true);
OpenAPI openAPI = openApiParser.readLocation(inputSpec, null, options).getOpenAPI();
String string = Yaml.mapper().writerWithDefaultPrettyPrinter().writeValueAsString(openAPI);
Current value:
openapi: 3.0.1
info:
title: ping test
version: "1.0"
servers:
- url: http://localhost:8000/
paths:
/some/ping:
get:
operationId: pingGet
parameters:
- name: i
in: query
description: Test
required: true
style: form
explode: true
schema:
$ref: ./external.yaml#/SomeId
responses:
201:
description: OK
components:
schemas: {}Expected value:
openapi: 3.0.1
info:
title: ping test
version: "1.0"
servers:
- url: http://localhost:8000/
paths:
/some/ping:
get:
operationId: pingGet
parameters:
- name: i
in: query
description: Test
required: true
style: form
explode: true
schema:
$ref: '#/components/schemas/SomeId'
responses:
201:
description: OK
components:
schemas:
SomeId:
type: integer
description: My value 123
format: int32
example: 123Tested with version 2.0.1
Metadata
Metadata
Assignees
Labels
No labels
Activity
ymohdriz commentedon Jul 6, 2018
Hi team,
I have raised a PR (#752) to fix this issue.
Thanks,
Mohammed
Add unit test for issue swagger-api#749
gracekarina commentedon Aug 10, 2018
Fixed by #752