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

I can't use $ref to pull in other yaml files #238

Closed
evhabs opened this issue Jul 13, 2021 · 5 comments
Closed

I can't use $ref to pull in other yaml files #238

evhabs opened this issue Jul 13, 2021 · 5 comments
Labels
bug Something isn't working

Comments

@evhabs
Copy link

evhabs commented Jul 13, 2021

Which package are you using?
chai-openapi-response-validator / jest-openapi

OpenAPI version
3

Describe the bug
In my response I try to use $ref to ask for a model and i consistantly get this error:
received did not satisfy it because: products[0] can't resolve reference ./models/Product.v1.yaml

I've tried moving it into the same folder and doing './Product.v1.yaml' but it still doesn't work.

Here is part of my reference file that is in question:

  /products:
    get:
      summary: List products
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  products:
                    type: array
                    items:
                      $ref: './Product.v1.yaml'

Is this type of notation supported? Or do I need to have items: point to something like $ref: '#/definitions/ComponentType/Product'

To Reproduce
Steps to reproduce the behavior:

  1. Create a yaml file
  2. create a yaml model in a different folder
  3. use $ref in response to reference it
  4. See error when you try doing:
    expect(res).toSatisfyApiSpec();

Expected behavior
I expected it to find the yaml file and do correct comparisons against my API doc

Are you going to resolve the issue?

If it something that needs to be added I don't mind taking a look

@evhabs evhabs added the bug Something isn't working label Jul 13, 2021
@evhabs evhabs closed this as completed Jul 13, 2021
@rwalle61
Copy link
Collaborator

Hey @evhabs, thanks for raising this, did you resolve the issue?

@evhabs
Copy link
Author

evhabs commented Jul 24, 2021

Hey @rwalle61, I wasn't able to resolve this I closed this because it seems there's already this same issue here: #229

@rwalle61
Copy link
Collaborator

rwalle61 commented Aug 15, 2021

Sorry for the delay! I think your issue is quite different to #229, which is about what to do when the request path matches multiple paths in the OpenAPI document. Your issue is that you want to reference other files via $ref: './Product.v1.yaml'. Unfortunately we don't currently support this - when we see $ref we just look at #/components/responses/ rather than other files.

If you'd like this enhancement (or bug fix, whatever you want to call it), a PR would be very welcome 😄

You could either expand that function to recognise file refs and look in those files, or ideally there'd be some npm package to manage that complexity for us. Here are some docs I found on how $ref should behave

@rwalle61
Copy link
Collaborator

Actually, is this a duplicate of #216 ? (perhaps you meant to link that instead of 229). Does the workaround in #216 solve this issue?

@evhabs
Copy link
Author

evhabs commented Aug 16, 2021

Oh I didn't see #216 i'll have to try this out when I get sometime later this week i'll try it out

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