Skip to content

Commit f9d236c

Browse files
jagregoryomissis
authored andcommitted
Fix non-nullable type with two options
If you have a type with exactly two options, neither of which is null, then the null-checking logic incorrectly uses the last item in the list as the type instead of interface{}. e.g. `"type": ["string", "boolean"]` becomes `*bool` instead of `interface{}`
1 parent f2a0dad commit f9d236c

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

pkg/generator/schema_generator.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,9 @@ func (g *schemaGenerator) generateTypeInline(
603603

604604
typeIndex = i
605605
}
606-
} else if len(t.Type) > 1 {
606+
}
607+
608+
if len(t.Type) > 1 && !typeShouldBePointer {
607609
g.warner("Property has multiple types; will be represented as interface{} with no validation")
608610

609611
return codegen.EmptyInterfaceType{}, nil

tests/data/validation/typeMultiple/typeMultiple.go

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/data/validation/typeMultiple/typeMultiple.json

+6
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@
4444
"null"
4545
]
4646
}
47+
},
48+
"onlyTwoOptions": {
49+
"type": [
50+
"number",
51+
"boolean"
52+
]
4753
}
4854
}
4955
}

0 commit comments

Comments
 (0)