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

fixed json unmarshal for BoolOrSchema #168

Merged
merged 1 commit into from
Dec 1, 2023
Merged

Conversation

fredbi
Copy link
Member

@fredbi fredbi commented Nov 30, 2023

According to the json draft 4 (or later) spec, empty schema is equivalent to true.

According to the json draft 4 (or later) spec, empty schema is
equivalent to true.

* checked with the OP's test case (spec expansion)
* added unit test
* fixes go-openapi#148

Signed-off-by: Frederic BIDON <[email protected]>
@fredbi fredbi changed the title fixed json unmarshal for BoolOrSchema WIP: fixed json unmarshal for BoolOrSchema Nov 30, 2023
@fredbi
Copy link
Member Author

fredbi commented Nov 30, 2023

WIP: I am currently testing this branch against go-swagger's full test suite

@fredbi
Copy link
Member Author

fredbi commented Nov 30, 2023

Seems ok on go-swagger CI.

@fredbi fredbi changed the title WIP: fixed json unmarshal for BoolOrSchema fixed json unmarshal for BoolOrSchema Nov 30, 2023
if data[0] == '{' {
var sch Schema
if err := json.Unmarshal(data, &sch); err != nil {
return err
}
nw.Schema = &sch
}
nw.Allows = !(data[0] == 'f' && data[1] == 'a' && data[2] == 'l' && data[3] == 's' && data[4] == 'e')
nw.Allows = !bytes.Equal(data, []byte("false"))
Copy link
Member

Choose a reason for hiding this comment

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

this allocates

@casualjim casualjim merged commit 95bb41d into go-openapi:master Dec 1, 2023
5 checks passed
@fredbi fredbi deleted the fix-148 branch December 1, 2023 09:42
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.

AdditionalProperties doesn't differ empty schema or explicit false
3 participants