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:
type {{$opid}}{{$statusCode}}ResponseHeaders struct {
{{range .Headers -}}
+ {{if .Schema.OAPISchema.Nullable -}}
+ {{.GoName}} nullable.Nullable[{{.Schema.TypeDecl}}]
+ {{else -}}
{{.GoName}} {{.Schema.TypeDecl}}
+ {{end -}}
{{end -}}
}
and:
{{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.
The
strict-interfacetemplate currently treats all response headers as required. However, it should be possible to omit optional headers.Possible template changes could be:
type {{$opid}}{{$statusCode}}ResponseHeaders struct { {{range .Headers -}} + {{if .Schema.OAPISchema.Nullable -}} + {{.GoName}} nullable.Nullable[{{.Schema.TypeDecl}}] + {{else -}} {{.GoName}} {{.Schema.TypeDecl}} + {{end -}} {{end -}} }and:
{{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.