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

feat: add support for draft-04 (06, 2019 and 2020 included) json schemas while supporting draft-07 #1006

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

Davidonium
Copy link

@Davidonium Davidonium commented Dec 26, 2024

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:

Validates schema. This method should be used to validate schemas rather than validate due to the inconsistency of uri format in JSON Schema standard.

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.

@@ -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"
Copy link
Author

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.

Comment on lines +103 to +107
service.registerCustomSchemaProvider(() => {
return new Promise<string | string[]>((resolve) => {
resolve('http://fakeschema.faketld');
});
});
Copy link
Author

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 @@
{
Copy link
Author

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).

@Davidonium Davidonium changed the title feat: add support for draft-04 json schemas while supporting draft-07 feat: add support for draft-04 (06, 2019 and 2020 included) json schemas while supporting draft-07 Dec 27, 2024
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 this pull request may close these issues.

1 participant