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

definition schemas #466

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

JoshMcCullough
Copy link

@JoshMcCullough JoshMcCullough commented Aug 18, 2022

Adds the ability to configure definition schemas.

Copy link
Contributor

@erosb erosb left a comment

Choose a reason for hiding this comment

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

Thank you for raising the PR. Added a couple of notes.
One more question: do you think it is possible to change the SchemaLoader so that the subschemas appearing under "$defs" are added to Schema#definitionSchemas ? I know it won't be a trivial code change, but maybe it is feasible?

@@ -227,6 +227,13 @@ private void describePropertyDependencies(Map<String, Set<String>> propertyDepen
visit(propertyNameSchema);
}

@Override void visitDefinitionSchemas(Map<String, Schema> definitionSchemas) {
if (!definitionSchemas.isEmpty()) {
writer.key("definitions");
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe better to use $defs since that is the currently recommended keyword according to the spec?

@@ -177,6 +181,12 @@ void visitPatternProperties(Map<Regexp, Schema> patternProperties) {
}
}

void visitDefinitionSchemas(Map<String, Schema> definitionSchemas) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Are you sure this makes sense? It may trigger unnecessary validation. For example if the schema is

{
   "type": "object",
   "properties": {
      "A": { "type": "string" }
   },
   "required": ["A"']
   "$defs": {
      "A": { "type": "integer" }
   }
}

Then I suspect no instance would pass the validation (the "A" prop would be validated against both {"type":"string"} and { "type": "integer" }).

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.

None yet

2 participants