-
Notifications
You must be signed in to change notification settings - Fork 5
feat(parser,validator): support bare-boolean schemas for OAS 3.1+ #450
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
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b36ddc7
feat(parser,validator): support bare-boolean schemas for OAS 3.1+
erraggy 5f2fece
fix(schemautil,joiner): unify boolean-schema hashing and equivalence
erraggy 349ffb8
test(parser,validator): convert the conformance tests to testify
erraggy 387b9ea
fix(joiner): compare boolean schemas in nested and schema-or-bool pos…
erraggy c3adf38
fix(joiner): report boolean differences as values, and drop dead bran…
erraggy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| package schemautil | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
|
|
||
| "github.com/erraggy/oastools/parser" | ||
| ) | ||
|
|
||
| // A boolean schema has two representations in the parser model. In a | ||
| // schema-or-bool field such as Items it stays a raw bool, because the promotion | ||
| // step passes bools through untouched; in a *Schema-typed field it arrives as a | ||
| // Schema with BoolForm set. They mean the same thing, so they must hash the | ||
| // same — otherwise deduplication sorts equivalent schemas into different | ||
| // buckets and never compares them. | ||
| func TestHashBoolSchemaRepresentationsAgree(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| raw *parser.Schema | ||
| wrap *parser.Schema | ||
| }{ | ||
| { | ||
| name: "items true", | ||
| raw: &parser.Schema{Type: "array", Items: true}, | ||
| wrap: &parser.Schema{Type: "array", Items: parser.NewBoolSchema(true)}, | ||
| }, | ||
| { | ||
| name: "items false", | ||
| raw: &parser.Schema{Type: "array", Items: false}, | ||
| wrap: &parser.Schema{Type: "array", Items: parser.NewBoolSchema(false)}, | ||
| }, | ||
| { | ||
| name: "additionalProperties true", | ||
| raw: &parser.Schema{Type: "object", AdditionalProperties: true}, | ||
| wrap: &parser.Schema{Type: "object", AdditionalProperties: parser.NewBoolSchema(true)}, | ||
| }, | ||
| { | ||
| name: "additionalProperties false", | ||
| raw: &parser.Schema{Type: "object", AdditionalProperties: false}, | ||
| wrap: &parser.Schema{Type: "object", AdditionalProperties: parser.NewBoolSchema(false)}, | ||
| }, | ||
| { | ||
| name: "additionalItems true", | ||
| raw: &parser.Schema{Type: "array", AdditionalItems: true}, | ||
| wrap: &parser.Schema{Type: "array", AdditionalItems: parser.NewBoolSchema(true)}, | ||
| }, | ||
| { | ||
| name: "additionalItems false", | ||
| raw: &parser.Schema{Type: "array", AdditionalItems: false}, | ||
| wrap: &parser.Schema{Type: "array", AdditionalItems: parser.NewBoolSchema(false)}, | ||
| }, | ||
| { | ||
| name: "unevaluatedProperties true", | ||
| raw: &parser.Schema{Type: "object", UnevaluatedProperties: true}, | ||
| wrap: &parser.Schema{Type: "object", UnevaluatedProperties: parser.NewBoolSchema(true)}, | ||
| }, | ||
| { | ||
| name: "unevaluatedItems false", | ||
| raw: &parser.Schema{Type: "array", UnevaluatedItems: false}, | ||
| wrap: &parser.Schema{Type: "array", UnevaluatedItems: parser.NewBoolSchema(false)}, | ||
| }, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| assert.Equal(t, NewSchemaHasher().Hash(tt.raw), NewSchemaHasher().Hash(tt.wrap), | ||
| "the raw bool and BoolForm representations must hash alike") | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| // The two boolean values are opposite schemas, so they must not collide — in | ||
| // either representation, and at the top level as well as nested. | ||
| func TestHashBoolSchemaValuesDiffer(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| a, b *parser.Schema | ||
| }{ | ||
| { | ||
| name: "top-level true and false", | ||
| a: parser.NewBoolSchema(true), | ||
| b: parser.NewBoolSchema(false), | ||
| }, | ||
| { | ||
| name: "raw items true and false", | ||
| a: &parser.Schema{Type: "array", Items: true}, | ||
| b: &parser.Schema{Type: "array", Items: false}, | ||
| }, | ||
| { | ||
| name: "a boolean schema and an empty object schema", | ||
| a: parser.NewBoolSchema(true), | ||
| b: &parser.Schema{}, | ||
| }, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| assert.NotEqual(t, NewSchemaHasher().Hash(tt.a), NewSchemaHasher().Hash(tt.b), | ||
| "distinct schemas must not share a deduplication bucket") | ||
| }) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.