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

auto generated models break when descriptor contains enum whose name equals the qualified name of a schema property #841

Closed
fauxbytes opened this issue Mar 5, 2024 · 2 comments · Fixed by #851
Labels
bug Something isn't working

Comments

@fauxbytes
Copy link

What version of kubb is running?

kubb/2.7.0 win32-x64 node-v18.16.0

What platform is your computer?

win

What version of external packages are you using(@tanstack-query, MSW, React, Vue, ...)

n/a (bare kubb)

What steps can reproduce the bug?

kubb.config.ts:

{
        root: '.',
        output: {path: './src/openapi/pets', clean: true},
        plugins: [
            ['@kubb/swagger', {output: false, validate: true}],
            ['@kubb/swagger-ts', {output: {path: 'models.ts'}, enumType: 'enum', dateType: 'string'}],
        ],
        input: {path: 'petStore.yaml'},
    }

Modified examples/typescript/petStore.yaml from kubb repo, as-per attached patch.

Resulting models.ts declares OrderType twice:

//...
 export enum OrderType {
    "placed" = "placed",
    "approved" = "approved",
    "delivered" = "delivered"
}
//....
 export enum OrderType2 {
    "foo" = "foo",
    "bar" = "bar"
}
export type OrderType = OrderType2;
//...
}

gen_breaks_when_descriptor_contains_enum_whose_name_equals_the_qualified_name_of_a_schema_.patch

How often does this bug happen?

Every time

What is the expected behavior?

No response

Swagger/OpenAPI file?

No response

Additional information

No response

@fauxbytes fauxbytes added the bug Something isn't working label Mar 5, 2024
@stijnvanhulle
Copy link
Collaborator

This is not easy to do because we use the schemaName for the type append the key(if the type is object). If that combination is already(not unique enough) there because another type has the same name, we add a number to make it unique. Not sure what else we can do there or what we can use coming from the OpenAPI/Swagger file.

@fauxbytes
Copy link
Author

Would adopting openapi-generators approach work? Seems like they append an "Enum" suffix to an enum property. This would yield:

export enum OrderType {
    Foo = 'foo',
    Bar = 'bar'
}
//...
export interface Order {
    //...
    type?: OrderTypeEnum;
    //...
}

export enum OrderTypeEnum {
    Placed = 'placed',
    Approved = 'approved',
    Delivered = 'delivered'
}

and do away with the type aliasing

@stijnvanhulle stijnvanhulle linked a pull request Mar 9, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants