Skip to content

Support nullable response headers #2267

Closed

Description

@fxedel

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.

Activity

  1. added 6 commits that reference this issue on Mar 23, 2026
    f55a1b0
    d8b06cb
    843d5d6
    241797e
    603e70f
    bf6c769
  2. added a commit that references this issue on Apr 12, 2026
    a4c36dc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions