kin-openapi
kin-openapi copied to clipboard
Nullable property in an schema generated by openapigen
I am generating the schema for an image like that https://github.com/RedHatInsights/edge-api/blob/main/cmd/spec/main.go#L33
In some cases, this Commit and Installer attributes are expanded but in other cases they are not. Is there a way to annotate a field (in this case, https://github.com/RedHatInsights/edge-api/blob/main/pkg/models/images.go#L32, for example) to add a nullable: true property?
Hi @biancarosa! One way to add nullable true is simply to set the Schema struct field. For instance with your Commit example (untested code):
// ...
gen.addSchema("v1.Image", &models.Image{})
gen.Components.Schemas["v1.Image"].Value.Properties["Commit"].Value.Nullable = true
// ...
You can also annotate a field by defining a customizer. See https://pkg.go.dev/github.com/getkin/[email protected]/openapi3gen#example-SchemaCustomizer