hey-api / openapi-ts

🚀 The OpenAPI to TypeScript codegen. Generate clients, SDKs, validators, and more. Support: @mrlubos
https://heyapi.dev
Other
1.43k stars 106 forks source link

Generated type for an enum in a schema with single quote does not escape properly #1132

Closed esfox closed 3 weeks ago

esfox commented 1 month ago

Description

Single quotes in an enum in a schema do not escape properly so it breaks the generated type.

Expected

export type SomeRequest = {
  category: 'Category A' | 'Category B' | 'Category C';
  withSingleQuote: 'Yes' | 'No' | "Don't Know";
}

Actual

export type SomeRequest = {
  category: 'Category A' | 'Category B' | 'Category C';
  withSingleQuote: 'Yes' | 'No' | 'Don't Know';
}

Reproducible example or configuration

No response

OpenAPI specification (optional)

components:
  schemas:
    ...
      SomeRequest:
        type: object
        properties:
          category:
            type: string
            enum:
              - Category A
              - Category B
              - Category C
          withSingleQuote:
            type: string
            enum:
              - Yes
              - No
              - Don't Know

System information (optional)

No response

mrlubos commented 1 month ago

This will be fixed as part of the parser release – thank you for your patience!

mrlubos commented 3 weeks ago

Hey @esfox, this is fixed in the experimental parser https://github.com/hey-api/openapi-ts/blob/main/packages/openapi-ts/test/__snapshots__/3.0.x/enum-escape/types.gen.ts

You can learn more about the new parser in the docs https://heyapi.dev/openapi-ts/configuration.html#parser