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

JSON Schema Validation struggles with circular references #789

Closed
philsturgeon opened this issue Nov 19, 2019 · 5 comments · Fixed by #974
Closed

JSON Schema Validation struggles with circular references #789

philsturgeon opened this issue Nov 19, 2019 · 5 comments · Fixed by #974
Labels
t/bug Something isn't working

Comments

@philsturgeon
Copy link
Contributor

I am building an AsyncAPI ruleset over here: apisyouwonthate/style-guide#4

The schema function should support Draft 4, 6 and 7, but when I run spectral lint -r asyncapi.yml examples/asyncapi.yml I get this error:

Encountered error when running rule 'asyncapi-schema' on node at path '$':
Error: id "http://json-schema.org/draft-07/schema" resolves to more than one schema

/Users/phil/src/style-guide/examples/asyncapi.yml
 1:1  warning  asyncapi-servers  Define at least one server.
 2:6  warning  info-contact      Info object should contain `contact` object.

I'm not sure what that means, but to be able to use the AsyncAPI v2.0.0 metaschema we need JSON Schema Draft 7.

@philsturgeon philsturgeon added the t/bug Something isn't working label Nov 19, 2019
@P0lip
Copy link
Contributor

P0lip commented Nov 19, 2019

schema function supports Draft 4, 6 and 7.
We have it covered here https://github.com/stoplightio/spectral/blob/develop/src/functions/__tests__/schema.test.ts#L241

It seems like there is some issue around schema ids, so perhaps it's our usage of Ajv. 🤔

@philsturgeon
Copy link
Contributor Author

I dunno, can you dig into this one? This is the first non-OAS ruleset I've tried to create which uses the schema function and all I know is it's not working. 😅

@P0lip
Copy link
Contributor

P0lip commented Nov 19, 2019

@P0lip
Copy link
Contributor

P0lip commented Nov 20, 2019

Okay, I think I got it.
The condition here https://github.com/epoberezkin/ajv/blob/master/lib/compile/resolve.js#L253 is met, because in this case schema function is given a resolved schema, since we resolve all $refs in rulesets. The JSON draft 4/6/7 schema we resolve will be without any refs unlike the one from Ajv that does have local refs unresolved.
The potential fix would be to disable resolving of local refs in rulesets. I will give it a try to see whether it resolves the issue.
Ah, we already have them disabled :/

@P0lip P0lip mentioned this issue Feb 26, 2020
10 tasks
@nulltoken
Copy link
Contributor

@philsturgeon @P0lip Currently hitting the same exact issue with #974

Working on it...

@P0lip P0lip changed the title JSON Schema Validation struggles with Draft 7 JSON Schema Validation struggles with circular references Apr 12, 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.

3 participants