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

Autogenerated variables can be improved #1117

Closed
gabn88 opened this issue Nov 29, 2023 · 4 comments
Closed

Autogenerated variables can be improved #1117

gabn88 opened this issue Nov 29, 2023 · 4 comments

Comments

@gabn88
Copy link

gabn88 commented Nov 29, 2023

Describe the bug
The autogenerated variables are incorrect

Now the enums are fixed (#1113), we would like to use the Enums to generate the variables for the choices automatically.

For example:

class IntensityChoices(IntegerChoices):
   LOW = 1, 'low'
   HIGH = 2, 'high'

Becomes

    IntensityEnum:
      enum:
      - 1
      - 2
      type: integer
      description: |-
        * `1` - low.      
        * `2` - high.

Becomes (typescript generator):


/**
 * * `1` - low
 * * `2` - high
 */
export enum IntensityEnum {
  '_1' = 1,     // We would like to see; LOW = 1
  '_2' = 2,   // We would like to see: HIGH = 2
}

Expected behavior
Keep varnames from the server Enum and use them for the varname in the Enum in the schema

@gabn88 gabn88 changed the title Autogenerated labels are incorrect Autogenerated variables are incorrect Nov 29, 2023
@gabn88 gabn88 changed the title Autogenerated variables are incorrect Autogenerated variables can be improved Nov 29, 2023
@tfranzel
Copy link
Owner

hey @gabn88, that didn't take long. 😄 we had this discussion in other issues also.

So this is now a external limitation basically and it has been raised several times. OpenAPI 3.0.3 has no way to give an enum list a programmatic label list. The description is merely a string and just writing low or high there will change nothing from the perspective of the generator. We just implemented the recommendation: https://swagger.io/docs/specification/data-models/enums/

OpenAPI 3.1 does have a construction that allows this. After years of back and forth this was recently decided: OAI/OpenAPI-Specification#681

However, 3.1 integration in #825 is not merged yet and on top of that, the new construction is not implemented yet.

@gabn88
Copy link
Author

gabn88 commented Nov 29, 2023

@tfranzel You are also fast, thank you for the update on #1113!

I modified the issue a bit, as I think there are actually two issues.

  1. is for the label (requires 3.1, "other issue / non-fixable for now")
  2. is for the var names. Our frontend team is not very happy with the readability of Activity._1 (where _1 means LOW).

I thought the second issue is maybe fixable?

@tfranzel
Copy link
Owner

I get the pain on point 2. I had that pain myself, but OpenApi 3.0.3 has no official structure for it and the community/ecosystem was never able to settle on a solution. So all hacks only have limited support and adding a bunch of different hacks here will only lead to (maintainer-)misery. This is as good as it gets for 3.0.3 and it is basically completely out of our/my control.

We can implement that new convention OAI/OpenAPI-Specification#681 (comment) after merging 3.1 support, but it looks like the ecosystem has no support for this yet either.

@gabn88
Copy link
Author

gabn88 commented Nov 29, 2023

I see your point. Let's hope we get there some day. Thanks for your patience with answering my questions!

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

2 participants