-
Notifications
You must be signed in to change notification settings - Fork 270
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
feat: add support for draft-04 (06, 2019 and 2020 included) json schemas while supporting draft-07 #1006
base: main
Are you sure you want to change the base?
feat: add support for draft-04 (06, 2019 and 2020 included) json schemas while supporting draft-07 #1006
Conversation
@@ -67,6 +67,50 @@ describe('YAML Schema Service', () => { | |||
expect(schema.schema.type).eqls('array'); | |||
}); | |||
|
|||
it('should handle schemas that use draft-04', async () => { | |||
const content = `openapi: "3.0.0" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I specifically wanted to test an openapi v3.0.0 schema because that's what is not working in my IDE.
service.registerCustomSchemaProvider(() => { | ||
return new Promise<string | string[]>((resolve) => { | ||
resolve('http://fakeschema.faketld'); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I came up with this to enforce the retrieval of the schema. Not sure if this is the best, feel free to suggest better ways.
@@ -0,0 +1,1662 @@ | |||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe having the entire openapi v3.0.0 spec is a bit too much. Let me know if you want me to just use a simple one that uses draft-04.
I used this because it's the use case I wanted to cover (and I think supporting openapi v3.0.0 is very important as there are tools that are unable to upgrade to 3.1).
…s a string instead of parsed json
What does this PR do?
Adds support for draft-04, draft-06, draft-2019-09 and draft-2020-12 json schemas. I first started adding support for draft-04 but some of the changes actually make the code validate the schemas more strictly so I felt the need to add the rest of the drafts. I am not entirely sure of the implications of adding the other drafts which are more complex so I would need some help there testing.
The use of avj-draft-04 is documented here: https://ajv.js.org/json-schema.html#draft-04 so it should not be deprecated or out of support.
According to https://ajv.js.org/api.html#ajv-validateschema-schema-object-boolean using that method should be preferred but I am not sure of the consequences of it.
Citing to avoid having to click there:
What issues does this PR fix or reference?
Is it tested? How?
I added a unit test but I would like to test it in my IDE. I have no idea how to do that so help is more than welcome.