The `strict-interface` template currently treats all response headers as required. However, it should be possible to omit optional headers. Possible template changes could be: ```diff type {{$opid}}{{$statusCode}}ResponseHeaders struct { {{range .Headers -}} + {{if .Schema.OAPISchema.Nullable -}} + {{.GoName}} nullable.Nullable[{{.Schema.TypeDecl}}] + {{else -}} {{.GoName}} {{.Schema.TypeDecl}} + {{end -}} {{end -}} } ``` and: ```diff {{range $headers -}} + {{if .Schema.OAPISchema.Nullable -}} + if val, err := response.Headers.{{.GoName}}.Get(); err == nil { + w.Header().Set("{{.Name}}", fmt.Sprint(val)) + } + {{else -}} w.Header().Set("{{.Name}}", fmt.Sprint(response.Headers.{{.GoName}})) + {{end -}} {{end -}} ``` Maybe it might also make sense respecting the pointers vs. nullable setting and using pointers accordingly.
Activity
support optional/nullable response headers
support optional/nullable response headers
Add HeadersImplicitlyRequired compatibility flag for oapi-codegen#2267
Add HeadersImplicitlyRequired compatibility flag for oapi-codegen#2267
support optional/nullable response headers
Add HeadersImplicitlyRequired compatibility flag for oapi-codegen#2267
support optional/nullable response headers (oapi-codegen#2301)