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

Fail to load external reference file because a '/' is prepend to the path #474

Closed
aleung opened this issue Aug 22, 2019 · 0 comments · Fixed by #477
Closed

Fail to load external reference file because a '/' is prepend to the path #474

aleung opened this issue Aug 22, 2019 · 0 comments · Fixed by #477
Assignees
Labels
t/bug Something isn't working

Comments

@aleung
Copy link

aleung commented Aug 22, 2019

Describe the bug
Spectral is unable to load external reference file because a / is prepend to the path.

To Reproduce

  1. Given this OpenAPI document and referenced document in same folder:

index.yaml

openapi: 3.0.0
info:
  title: Test
  version: 1.0.0
paths:
  '/':
    get:
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: 'common.yaml#/components/schemas/ResponseType'
                # Below doesn't work as well
                # $ref: './common.yaml#/components/schemas/ResponseType'

common.yaml

openapi: 3.0.0
info:
  title: Common schema definition
  version: 1.0.0
components:
  schema:
    ResponseType:
      type: string
  1. Run this CLI command
spectral lint index.yaml
  1. See error
Adding OpenAPI 3.x functions
OpenAPI 3.x detected

index.yaml
  1:1   warning  api-servers            OpenAPI `servers` must be present and non-empty array.
  2:6   warning  info-contact           Info object should contain `contact` object.
  2:6   warning  info-description       OpenAPI object info `description` must be present and non-empty string.
  7:9   warning  operation-description  Operation `description` must be present and non-empty string.
  7:9   warning  operation-operationId  Operation should have an `operationId`.
  7:9   warning  operation-tags         Operation should have non-empty `tags` array.
 14:23    error  invalid-ref            ENOENT: no such file or directory, open '/common.yaml'

✖ 7 problems (1 error, 6 warnings, 0 infos)

Expected behavior
There should not be an invalid-ref error. The reference file path should be ./common.yaml instead of /common.yaml

Environment (remove any that are not applicable):

@stoplight/spectral/4.0.2 darwin-x64 node-v12.8.0

@aleung aleung added the t/bug Something isn't working label Aug 22, 2019
@P0lip P0lip self-assigned this Aug 22, 2019
@P0lip P0lip modified the milestones: Aug '19, Sept '19 Aug 22, 2019
@P0lip P0lip removed this from the Sept '19 milestone May 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
t/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants