kin-openapi icon indicating copy to clipboard operation
kin-openapi copied to clipboard

Nullable property in an schema generated by openapigen

Open biancarosa opened this issue 2 years ago • 1 comments

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?

biancarosa avatar Jan 14 '22 18:01 biancarosa

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

fenollp avatar Feb 23 '22 09:02 fenollp