From 41d68b3c586fbd25927fb092b8599d4434eac4b2 Mon Sep 17 00:00:00 2001 From: webbrain-one <295484252+webbrain-one@users.noreply.github.com> Date: Wed, 5 Aug 2026 19:34:20 +0300 Subject: [PATCH] Do not set nullable by default on pointer fields Pointer fields are now only marked as nullable in the generated OpenAPI schema if the `openapi:"nullable"` tag is present. --- docparser/model.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/docparser/model.go b/docparser/model.go index 4350862..dfcbd6c 100644 --- a/docparser/model.go +++ b/docparser/model.go @@ -7,6 +7,7 @@ import ( "io/ioutil" "os" "path/filepath" + "reflect" "regexp" "strings" @@ -476,6 +477,17 @@ func (spec *openAPI) parseStructs(f *ast.File, tpe *ast.StructType) (interface{} p.Enum = j.enum } + // Only set nullable if the openapi:"nullable" tag is present + if p.Nullable != nil { + nullable := false + if fld.Tag != nil { + nullable = reflect.StructTag(fld.Tag.Value).Get("openapi") == "nullable" + } + if !nullable { + p.Nullable = nil + } + } + if p != nil { e.Properties[j.name] = p }