Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

$ref in external file in parameter with resolve option true #749

Closed
jmini opened this issue Jul 5, 2018 · 2 comments
Closed

$ref in external file in parameter with resolve option true #749

jmini opened this issue Jul 5, 2018 · 2 comments

Comments

@jmini
Copy link
Contributor

jmini commented Jul 5, 2018

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: 123

Run 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: 123

Tested with version 2.0.1

@ymohdriz
Copy link
Contributor

ymohdriz commented Jul 6, 2018

Hi team,

I have raised a PR (#752) to fix this issue.

Thanks,
Mohammed

@gracekarina
Copy link
Contributor

Fixed by #752

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants