Commit a4c36dc
support optional/nullable response headers (#2301)
* support optional/nullable response headers
Closes: #2267
Response headers in strict server code were always generated as direct
value types regardless of whether they were required. This adds support
for optional and nullable response headers in the strict-interface and
strict-responses templates.
Add Required and Nullable fields to ResponseHeaderDefinition, populated
from the OpenAPI header object. Add GoTypeDef(), IsOptional(), and
IsNullable() methods that mirror the existing Property logic for
determining whether a field should be a pointer, nullable.Nullable[T],
or a direct value.
Update strict-interface.tmpl and strict-responses.tmpl to use GoTypeDef
for struct field types, and to conditionally guard w.Header().Set()
calls with nil/IsSpecified checks for optional/nullable headers.
Note: this is a breaking change for specs where response headers lack
explicit `required: true`, since the OpenAPI default is false. Existing
headers will change from direct values to pointers. This may need to be
gated behind a config option.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* Add HeadersImplicitlyRequired compatibility flag for #2267
Allows users to restore the pre-v2.5.0 behavior where all response
headers are treated as required, ignoring the OpenAPI `required` field.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>1 parent 9107bfb commit a4c36dc
File tree
15 files changed
+315
-159
lines changed- internal/test
- issues
- issue-1676
- issue-head-digit-of-httpheader
- strict-server
- chi
- echo
- fiber
- gin
- gorilla
- iris
- stdhttp
- pkg/codegen
- templates/strict
15 files changed
+315
-159
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
115 | 115 | | |
116 | 116 | | |
117 | 117 | | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
118 | 122 | | |
119 | 123 | | |
120 | 124 | | |
| |||
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
0 commit comments