Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion openapi/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -895,7 +895,17 @@ func (g *Generator) newSchemaFromType(t reflect.Type) *SchemaOrRef {
case reflect.Slice, reflect.Array, reflect.Map:
return g.buildSchemaRecursive(t)
case reflect.Struct:
return g.newSchemaFromStruct(t)
sor := g.newSchemaFromStruct(t)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already check if the type is "nullable" above when dereferencing the pointer. We could simply check if the schema pointed by the ref is non-nil and set the Nullable property accordingly.

var schema *Schema
if sor != nil && sor.Schema != nil {
schema = sor.Schema
} else if sor != nil {
schema = g.resolveSchema(sor)
}
if schema != nil {
schema.Nullable = nullable
}
return sor
}
}
if dt == TypeAny {
Expand Down
1 change: 1 addition & 0 deletions openapi/generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ func TestSchemaFromComplex(t *testing.T) {
sor = g.API().Components.Schemas["Y"]
schema = g.resolveSchema(sor)
assert.NotNil(t, schema)
assert.True(t, schema.Nullable)

actual, err = json.Marshal(schema)
if err != nil {
Expand Down