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

open API exporter supports custom extensions #2638

Open
gotwarlost opened this issue Oct 9, 2023 · 2 comments
Open

open API exporter supports custom extensions #2638

gotwarlost opened this issue Oct 9, 2023 · 2 comments
Labels
FeatureRequest New feature or request Triage Requires triage/attention

Comments

@gotwarlost
Copy link

gotwarlost commented Oct 9, 2023

Is your feature request related to a problem? Please describe.

I'm trying to create openAPI schemas from cue schemas and this works well. One limitation of the exporter is that there is no way to add extensions to the generated schema.

See: https://swagger.io/docs/specification/openapi-extensions/

The specific use-case that I'm struggling with is to declare an open struct in a Kubernetes CRD schema. Kubernetes will not allow an empty object spec unless it also has the extension x-kubernetes-preserve-unknown-fields set to true.

Describe the solution you'd like

I'd like a way to tag a field in a cue schema such that the schema generator can write the extension when generating the type definition in openAPI.

Seems to me that this is expressed best as a cue attribute of the form @extension("x-name=value") which the openAPI exporter respects and emits in its output.

Describe alternatives you've considered

There is no workaround for this at the cue level. I have a horrible sed hack that looks like this:

sed 's/additionalProperties: {}/additionalProperties: true, "x-kubernetes-preserve-unknown-fields": true/g'

Additional context

I think the above is self-explanatory. If not, please let me know.

@gotwarlost gotwarlost added FeatureRequest New feature or request Triage Requires triage/attention labels Oct 9, 2023
@gotwarlost gotwarlost changed the title open API exporter support custom extensions open API exporter supports custom extensions Oct 9, 2023
@verdverm
Copy link

I'd posit that a better CUE attribute would be @openapi(...) which could support a variety of options, @extension sounds a bit too generic for people to look at and understand what it is for

@openapi(extension:"x-name=value",extension:x-foo:bar)

@gotwarlost
Copy link
Author

works for me. Just need to get the functionality :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
FeatureRequest New feature or request Triage Requires triage/attention
Projects
None yet
Development

No branches or pull requests

2 participants