Skip to content
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

Nullable property in an schema generated by openapigen #476

Closed
biancarosa opened this issue Jan 14, 2022 · 2 comments
Closed

Nullable property in an schema generated by openapigen #476

biancarosa opened this issue Jan 14, 2022 · 2 comments

Comments

@biancarosa
Copy link
Contributor

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?

@fenollp
Copy link
Collaborator

fenollp commented Feb 23, 2022

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/kin-openapi@v0.90.0/openapi3gen#example-SchemaCustomizer

@AnatolyRugalev
Copy link
Contributor

Duplicates #968

@fenollp fenollp closed this as completed Jul 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants