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

Reference parsing doesn't work in the CLI tool using relative paths. #164

Open
shulard opened this issue Jun 24, 2022 · 3 comments
Open
Labels
bug Something isn't working

Comments

@shulard
Copy link

shulard commented Jun 24, 2022

Hello !

First, thank you for your awesome library, it helps us a lot manipulating our OpenAPI definitions.

We found a tiny issue about reference resolution in our local configuration.

I give you a tiny sample to describe our usage. We have a doc/api folder which contains an openapi.yaml file like this :

openapi: 3.0.3
paths:
  /api/files:
    $ref: upload/files.yaml

Then here is the doc/api/upload/files.yaml :

get:
  operationId: getUploadFiles
  summary: Get all the non deleted uploaded file batchs
  responses:
    '200':
      content:
        'application/json':
          schema:
            $ref: './../schema/file.yaml#/FileListResponse'

And finally the doc/api/schema/file.yaml which looks like :

File:
  type: object
  required:
    - id
    - type
    - attributes
  properties:
    type:
      type: string
      example: file
    id:
      type: string
      format: UUIDv4
      example: d6e6ad56-3874-48c7-9265-97f27808dac3
    attributes:
      type: object
    relationships:
      type: object

ArrayOfFile:
  type: array
  items:
    $ref: '#/File'

FileListResponse:
  type: object
  properties:
    data:
      $ref: '#/ArrayOfFile'

As you can see, we use relative paths in our $ref attributes. I simplified a bit the definition but the idea is here. Whenever a $ref contains .., there are skipped.

I checked in the library code and found that the cebe\openapi\ReferenceContext::reduceDots remove all the .. from the given paths. If I just skip this methods, my API doc is correctly imported and used.

I don't know what's the expected behavior here. If I can help (giving more details or contributing code), I'll be glad to do it ^^

@cebe
Copy link
Owner

cebe commented Jul 22, 2022

thanks for reporting this. reduceDots does not simply remove the dots, it should resolve cases like e.g. /some/path/to/subdir/../../openapi.yml to /some/path/openapi.yml. There might be a bug so that it does not do that correctly in your case.

cebe added a commit that referenced this issue Jul 22, 2022
@cebe
Copy link
Owner

cebe commented Jul 22, 2022

added a failing test for this case. You can work around it by removing the reference to the current directory: ./ this should work:

        $ref: '../schema/file.yaml#/FileListResponse'

@cebe cebe added the bug Something isn't working label Jul 22, 2022
@shulard
Copy link
Author

shulard commented Jul 25, 2022

Ok, thank you for the ./ fix, it works on my side ^^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants