-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
[Go] validate required fields when unmarshalling JSON #16863
Conversation
268ecb5
to
a5fc00e
Compare
can you please take a look at the CI failure when you've time? |
04c8426
to
209e5a0
Compare
f1c8b9e
to
01479c4
Compare
@wing328 I updated the PR to only generate the |
overall it looks good. when you've time, can you please PM me via Slack for a few quick questions/feedback? |
01479c4
to
e9b4247
Compare
e9b4247
to
e0ac538
Compare
Relates to #12201
Code generated by the Go client generator does not validate
required
fields, which is especially problematic inoneOf
schemas where the sub-schemas are differentiated by required fields.For example, consider the following schema:
Assume that the API itself only returns an object that has
foo
or an object that hasbar
; it will not return an object with both properties. Existing versions ofopenapi-generator
Go client generator will generate models that do not enforce required properties; as a result, any attempt to use theThing
model will result in an error likeError when calling <something>: data matches more than one schema in oneOf(Thing)
.This PR replicates the required field validation that exists in the
okhttp-gson
generator:PR checklist
This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
These must match the expectations made by your contribution.
You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example
./bin/generate-samples.sh bin/configs/java*
.For Windows users, please run the script in Git BASH.
master
(upcoming 7.1.0 minor release - breaking changes with fallbacks),8.0.x
(breaking changes without fallbacks)