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

Decide on representation of enum values in OpenAPI3 #1371

Closed
markcowl opened this issue Dec 5, 2022 · 5 comments
Closed

Decide on representation of enum values in OpenAPI3 #1371

markcowl opened this issue Dec 5, 2022 · 5 comments
Assignees
Labels
design:needed A design request has been raised that needs a proposal
Milestone

Comments

@markcowl
Copy link
Contributor

markcowl commented Dec 5, 2022

We should be crisp about the meaning of enums in Cadl in general:

  • enum is a fixed set of values that can be updated in a new api-version
  • We may need additional patterns for
    • enums that will never add values
      • is this really a pattern?
    • enums that may add values without changing api-version
      • can this be represented using example values?
  • Decide on how enums should be represented in OpenAPI3
    • Should we bring over any part of x-ms-enum?
@ghost ghost added the Needs Triage label Dec 5, 2022
@markcowl markcowl added the design:needed A design request has been raised that needs a proposal label Dec 5, 2022
@markcowl markcowl self-assigned this Dec 8, 2022
@markcowl markcowl added this to the [2023] March milestone Dec 8, 2022
@markcowl markcowl removed their assignment Dec 8, 2022
@mikekistler
Copy link
Member

I don't mind deferring the work to document how @knownValues is used by the OpenAPI emitter if this design issue is taken up quickly. But if this design discussion does not happen until March (as the milestone seems to indicate), that means that our documentation is incomplete / incorrect for at least 3 months, and that seems too long to me. Can we move up the date for this design discussion to at least Feb (i.e. we'd discuss in a design meeting in January)? If that's not possible, then I think we should either document the current behavior or remove it so that our docs accurately reflect the behavior of the code.

@stefan-schweiger
Copy link

Just to have it here as well for better visibility for this discussion

#189 (comment)

It's kind of hard to follow all the discussion around the topic of extensible enums. What would actually be generated for those extensible properties? I've seen mentioned a few times the x-ms-enum pattern or using anyOf.

For example there is the "zalando" way of doing it like this, which is what I would like to do:

DeliveryMethod:
  type: string
  x-extensible-enum:
    - Parcel
    - Letter
    - Email

There is an ongoing discussion in the OpenAPI specification about this topic. Maybe some comments in there could be a good inspiration for what people are currently using to define extensible enums, and it would be great if at least a few of the more common ones could be achieved with cadl.

OAI/OpenAPI-Specification#1552

@mikekistler
Copy link
Member

This is resolved. The openapi3 emitter generates enums and unions of string values as enum.

@stefan-schweiger
Copy link

@mikekistler how would one generate one of the alternative extensible formats? write a custom emitter?

@mikekistler
Copy link
Member

I don't think you need a custom emitter -- you can just add the extension by hand.

Playground example

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
design:needed A design request has been raised that needs a proposal
Projects
None yet
Development

No branches or pull requests

3 participants