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

support x-enum-varnames #731

Closed
chiptus opened this issue Dec 17, 2023 · 2 comments · Fixed by #734
Closed

support x-enum-varnames #731

chiptus opened this issue Dec 17, 2023 · 2 comments · Fixed by #734
Labels
enhancement New feature or request

Comments

@chiptus
Copy link
Contributor

chiptus commented Dec 17, 2023

What is the problem this feature would solve?

currently kubb supports x-enumNames for naming the enum fields. on our server we use swaggo (https://github.com/swaggo/swag) to generate the swagger yaml and it uses x-enum-varnames.

testing, if I change the output swagger from x-enum-varnames to x-enumNames the generated types are correct (see sandbox), would be nice to have support for both.

External documents/projects?

https://codesandbox.io/p/devbox/naughty-noyce-5g2n53

What is the feature you are proposing to solve the problem?

for createSwaggerTs add option enumsInput: "x-enum-varnames" | "x-enumNames"

another option can be to give createSwagger an option to transform the doc (maybe a function that takes a node of the yaml and returns another node)

What alternatives have you considered?

just running another tool to transform the swagger doc

@chiptus chiptus added the enhancement New feature or request label Dec 17, 2023
@stijnvanhulle
Copy link
Collaborator

stijnvanhulle commented Dec 17, 2023

Hi, not sure if an option is needed. We can just add a check for x-enum-varnames or for x-enumNames. This means a developer does not need to specify which type he is using and in the background will Kubb handle the conversion.

 if ('x-enumNames' in schema) {
    enums = [...new Set(schema['x-enumNames'] as string[])].map((key: string, index) => {
      return [key, schema.enum?.[index] as string]
    })
  }
 if ('x-enum-varnames' in schema) {
    enums = [...new Set(schema['x-enum-varnames'] as string[])].map((key: string, index) => {
      return [key, schema.enum?.[index] as string]
    })
  }

@chiptus
Copy link
Contributor Author

chiptus commented Dec 18, 2023

ok, I'll open a pr

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants