-
-
Notifications
You must be signed in to change notification settings - Fork 1k
OpenAPI 3.1.0 Support null type #2385
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: feat/kin-openapi-3.1
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -190,7 +190,12 @@ func (p Property) ZeroValueIsNil() bool { | |
| return false | ||
| } | ||
|
|
||
| if schemaPrimaryType(p.Schema.OAPISchema.Type).Is("array") { | ||
| t := schemaPrimaryType(p.Schema.OAPISchema.Type) | ||
| if t.Is("array") { | ||
| return true | ||
| } | ||
|
|
||
| if t.Is("null") { | ||
| return true | ||
| } | ||
|
Comment on lines
+198
to
200
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
|
|
@@ -1007,6 +1012,10 @@ func oapiSchemaToGoType(schema *openapi3.Schema, path []string, outSchema *Schem | |
| outSchema.SkipOptionalPointer = true | ||
| } | ||
| outSchema.DefineViaAlias = true | ||
| } else if t.Is("null") { | ||
| spec := globalState.typeMapping.Null.Resolve(f) | ||
| outSchema.GoType = spec.Type | ||
| outSchema.DefineViaAlias = true | ||
|
Comment on lines
+1015
to
+1018
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This branch lets |
||
| } else { | ||
| return fmt.Errorf("unhandled Schema type: %v", t) | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new null branch makes
.RequiresNilChecktrue for every null parameter, even thoughtype-mapping.nullcan map null to a non-nilable Go type. With a mapping like null tostring, client, webhook, and callback templates can generateif params.X != nilfor astringparameter field. That generated code does not compile. Parameter nil checks should follow the resolved Go type instead of the OpenAPI type alone.