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

apply default in objects and arrays #477

Merged
merged 7 commits into from
Dec 2, 2021
Merged

apply default in objects and arrays #477

merged 7 commits into from
Dec 2, 2021

Conversation

SiemelNaran
Copy link
Contributor

@SiemelNaran SiemelNaran commented Oct 30, 2021

At https://json-schema.org/understanding-json-schema/reference/generic.html they say of the default keyword

The default keyword specifies a default value. This value is not used to fill in missing values during the validation process. Non-validation tools such as documentation generators or form generators may use this value to give hints to users about how to use a value. However, default is typically used to express that if a value is missing, then the value is semantically the same as if the value was present with the default value. The value of default should validate against the schema in which it resides, but that isn’t required.

So before this PR, the 'default' keyword is ignored during both validation and walking. But this PR allow the user to apply defaults during walking. They still have to set a flag indicating that they want defaults to be applied (and they can apply defaults only if property is missing, or if it missing or is explicitly null).

If JSON blobs were saved to the database, and the JSON schema changed to add defaults, the db migration tool could use read the JSON blobs and walk them against the schema again to apply defaults.

@SiemelNaran
Copy link
Contributor Author

mvn test results in 4 errors

[ERROR] Failures: 
[ERROR]   OpenAPI30JsonSchemaTest.testDiscriminatorMapping:120->runTestFile:109 expected: <false> but was: <true>
[ERROR]   V4JsonSchemaTest.testNotValidator:155->BaseSuiteJsonSchemaTest.runTestFile:116 expected: <false> but was: <true>
[ERROR]   V7JsonSchemaTest.testNotValidator:272->BaseSuiteJsonSchemaTest.runTestFile:116 expected: <false> but was: <true>
[ERROR] Errors: 
[ERROR]   CollectorContextTest.testCollectorGetAll:109 » NullPointer
[INFO] 
[ERROR] Tests run: 310, Failures: 3, Errors: 1, Skipped: 46

@SiemelNaran
Copy link
Contributor Author

Reminder about this review in case you missed it @prashanthjos . @stevehu I did the performance tests and replied in the thread, and to my surprise found that the code is faster after my changes.

@stevehu
Copy link
Contributor

stevehu commented Nov 24, 2021

@SiemelNaran That is good news :) Let us know when you think the PR is completed so that we can start the review. Thanks a lot for the effort.

@SiemelNaran
Copy link
Contributor Author

@SiemelNaran That is good news :) Let us know when you think the PR is completed so that we can start the review. Thanks a lot for the effort.

It is ready.

@stevehu stevehu merged commit fad2a58 into master Dec 2, 2021
@stevehu stevehu deleted the snaran/default branch December 2, 2021 01:23
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.

2 participants