[Go] Add strictResponseDecoding option to Go-server generator. Fixes issue #21446 #21456
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.
Summary
This PR introduces a new generator property,
strictResponseDecoding
, to the go-server generator. When enabled (the new default), every JSON decoder in generated handlers will callDisallowUnknownFields()
, causing the server to reject any incoming payloads that contain fields not defined in the spec. Users can disable strict mode and allow extra fields by passing--additional-properties strictResponseDecoding=false
. Fixes issue #21446.Changes
Codegen configuration
File:
GoServerCodegen.java
What’s changed:
STRICT_RESPONSE_DECODING
CLI option (default:true
).strictResponseDecoding
boolean inadditionalProperties
for use in templates.Template guard
File:
server.mustache
What’s changed:
decoder.DisallowUnknownFields()
in a{{#strictResponseDecoding}}…{{/strictResponseDecoding}}
block.Documentation
File: Go-server README (
modules/openapi-generator/README.md
)What’s changed:
--additional-properties=strictResponseDecoding={true|false}
flag, its default behavior, and usage example.Impact
Backward compatibility:
Client generation:
Usage Example
Checklist
GoServerCodegen.java
server.mustache
template@antihax @grokify @kemokemo @jirikuncar @ph4r5h4d @lwj5
PR checklist
master
(upcoming7.x.0
minor release - breaking changes with fallbacks),8.0.x
(breaking changes without fallbacks)