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

Loader fails to load file with no reason #759

Closed
akzincsystems opened this issue Feb 1, 2023 · 5 comments · Fixed by #761
Closed

Loader fails to load file with no reason #759

akzincsystems opened this issue Feb 1, 2023 · 5 comments · Fixed by #761

Comments

@akzincsystems
Copy link

I'm seeing an error:

bad data in "#/components/schemas/UserStruct"

when calling openapi3.NewLoader().LoadFromFile(path)

This is being emitted from openapi3/loader.go L358 which is the default case in a switch statement, and no reason is given.

Dumping the reflect values gives:
reflect.TypeOf(cursor).Kind().String == ptr
reflect.TypeOf(cursor).String() == *openapi3.SchemaRef

which I can see for all other schema components as well

The particular component is:

  schemas:
    UserStruct:
      title: "A User"
      type: object
      properties:
        struct:
          $ref: "#/components/schemas/StructVersionV1"
        data:
          $ref: "#/components/schemas/UserV1"

All referenced schemas are in the file and the entire yaml schema validates at https://app.swaggerhub.com

lib version is: github.com/getkin/kin-openapi v0.113.0

Any ideas why this might be happening?

@fenollp
Copy link
Collaborator

fenollp commented Feb 1, 2023

Hello! Can you provide a YML that reproduces the error with a call such as

go run github.com/getkin/kin-openapi/cmd/validate@latest -- file.yml

@akzincsystems
Copy link
Author

akzincsystems commented Feb 1, 2023

EDIT: got it, thanks!

I'd appreciate you deleting it once you have it locally.

Thanks

@fenollp fenollp linked a pull request Feb 1, 2023 that will close this issue
@akzincsystems
Copy link
Author

akzincsystems commented Feb 2, 2023

Not seeing this yet. Needs a new tag? v0.113.1 perhaps?

@fenollp
Copy link
Collaborator

fenollp commented Feb 2, 2023

Yes I haven't tagged yet. I'm looking to get another PR in first but it can probably wait. I'll tag later today.

This will just change the error message you are getting though. Your issue is that the ref points to a schema instead of a response object. I'm not sure why other tools did not point that out though.

@akzincsystems
Copy link
Author

Ah Ha! Found it - yes - correct. Thanks for that. Hopefully your new messaging will point the error at the wrong ref, not the ref definition itself. Look forward to seeing it. Thanks for your help.

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

Successfully merging a pull request may close this issue.

2 participants