Skip to content

Use full schema (schema-base.yaml) for coverage #4701

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

Merged
merged 6 commits into from
Jun 13, 2025
Merged

Conversation

handrews
Copy link
Member

But don't count standard JSON Schema keywords.

We were not actually using the correct schema for our testing, which meant that we were not covering the Schema Object at all.

  • schema changes are included in this pull request
  • schema changes are needed for this pull request but not done yet
  • no schema changes are needed for this pull request

But don't count standard JSON Schema keywords.
@handrews handrews requested review from a team as code owners June 13, 2025 01:30
@handrews handrews added the script Pull requests that update Bash or JavaScript code label Jun 13, 2025
There needs to be a local `$dynamicAnchor`, but it is never
actually evaluated.
});

defineVocabulary(
"https://spec.openapis.org/oas/3.1/vocab/base",
Copy link
Contributor

@ralfhandl ralfhandl Jun 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This apparently needs to be parameterized with the OpenAPI version of the branch it is running on, because the script fails if run as-is on the v3.2-dev branch.

No spontanous idea on how to reliably do that, other than parsing dialect.yaml.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ralfhandl I was just going to modify the line on the 3.2 port

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which would end up in main (and then dev and v3.1-dev) after the release unless someone fiddles with the v3.2.0-rel branch.

Automatically detecting the release seems preferable.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ralfhandl Which is fine but let's fix it separately. I do not have the mental bandwidth today for that, and want to get the XML PR merged so I can unblock further work that depends on it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This apparently needs to be parameterized with the OpenAPI version of the branch it is running on

I didn't realize you were versioning the vocabulary now. So, ignore what I said about not needing defineVocabulary, but you still shouldn't need to implement the keywords as long as you use the correct import.

@ralfhandl
Copy link
Contributor

@handrews Thanks for taking this up, I was wondering how to test our Schema Object extensions without having to cover all standard JSON Schema keywords.

Copy link
Contributor

@ralfhandl ralfhandl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above

Comment on lines +122 to +164
addKeyword({
id: "https://spec.openapis.org/oas/schema/vocab/keyword/discriminator",
interpret: (discriminator, instance, context) => {
return true;
},
/* discriminator is not exactly an annotation, but it's not allowed
* to change the validation outcome (hence returing true from interopret())
* and for our purposes of testing, this is sufficient.
*/
annotation: (discriminator) => {
return discriminator;
},
});

addKeyword({
id: "https://spec.openapis.org/oas/schema/vocab/keyword/example",
interpret: (example, instance, context) => {
return true;
},
annotation: (example) => {
return example;
},
});

addKeyword({
id: "https://spec.openapis.org/oas/schema/vocab/keyword/externalDocs",
interpret: (externalDocs, instance, context) => {
return true;
},
annotation: (externalDocs) => {
return externalDocs;
},
});

addKeyword({
id: "https://spec.openapis.org/oas/schema/vocab/keyword/xml",
interpret: (xml, instance, context) => {
return true;
},
annotation: (xml) => {
return xml;
},
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These seem to be unnecessary, commenting them out does not change the test result.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ralfhandl they make the vocabulary be handled correctly if we want to further utilize those keywords in tests. I prefer to set up the vocabulary correctly rather than stub it out just because we're not using it right now.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would checks of the keyword's correct use go into the interpret stubs?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ralfhandl they're not stubs. Annotations are always valid, returning true is correct.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At least I think. That was as far as I got in the library's documentation. It's at least closer to correct than it was, and we can work on it more later.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These seem to be unnecessary, commenting them out does not change the test result.

It works because the vocabulary is set as optional. If there is no keyword implementation, it's treated like an unknown keyword, which is allowed, but not quite the same thing.

These keyword implementations are already provided, so you shouldn't need to define them here. Instead of importing @hyperjump/json-schema/draft-2020-12, use @hyperjump/json-schema/openapi-3-1. Then the keywords and vocabulary definitions will be loaded and you can skip this. However, you still need to register the local schemas because you're testing the local schemas, not the ones included with the @hyperjump/json-schema.

@handrews
Copy link
Member Author

@ralfhandl I have fixed the blocking things, I think.

I realize the 3.1 hardcoding is not ideal, and we can debate the addKeyword thing. Please let's get this merged so literally everything else can be unblocked. We can work on parametrizing or re-organizing but I'll just modify the PR on v3.2-dev to hardcode 3.2 instead so we can get the other PRs mergeable. We can keep improving this afterwards.

Among other things, it's extremely awkward that this script has to start on main but the non-coverage script that runs the fail tests has to start on dev. But let's get this going first.

Copy link
Contributor

@ralfhandl ralfhandl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to eliminate all uses of visitedLocations.size

@handrews
Copy link
Member Author

@ralfhandl merged your latest suggestion, thanks.

@ralfhandl ralfhandl merged commit b862c2e into OAI:main Jun 13, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
script Pull requests that update Bash or JavaScript code
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants