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

Can't make it work with OpenAPI #2347

Open
Garito opened this issue Nov 19, 2023 · 5 comments
Open

Can't make it work with OpenAPI #2347

Garito opened this issue Nov 19, 2023 · 5 comments

Comments

@Garito
Copy link

Garito commented Nov 19, 2023

Hi
I'm trying to validate data from an openapi schema but I do not understand the logic or I'm missing something
Sorry if this is a dumb question
This is my code:

const ajv = new Ajv({allErrors: true});
ajv.addSchema(openapi)
console.log(ajv.validate({ $ref: `#/components/schemas/${ schema }` }, JSON.parse(data)))

This is the error:

Uncaught Error: can't resolve reference #/components/schemas/Schema from id #

openapi is the json object version 3.0.2 generated by a fastapi backend
I want to validate data against the schema at #/components/schemas/Schema
What am I missing?
Thanks

@jeremyfiel
Copy link

@Garito
Copy link
Author

Garito commented Dec 4, 2023

Thanks for that @jeremyfiel
I'm following the example but raises:

Uncaught Error: reference "<schema>" resolves to more than one schema

when ajv.addSchema(openapi, 'openapi.json') but there are no duplicate schemas on that openapi (has been generated by fastapi)

@jeremyfiel
Copy link

post your code where it's having an error. including the import statements or variables you have defined for schema and openapi

@Garito
Copy link
Author

Garito commented Dec 4, 2023

I'm sorry, writing this response i have noticed that two schemas have the same id so I correct that and test the openapi file with the swagger editor
But now it raises Uncaught Error: reference "properties" resolves to more than one schema which seems a little weird

The problem is that the error doesn't help too much

The line that fails is:

ajv.addSchema(openapi, 'openapi.json')

so seems to be an openapi schema validation problem
Any clue as to how debug this issue besides the swagger editor? (the new version doesn't complain of any schema errors at all)

@jeremyfiel
Copy link

short of seeing the schemas, or your code, not much I can reference to help you

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

No branches or pull requests

2 participants