Skip to content

Conversation

sschw
Copy link
Contributor

@sschw sschw commented Aug 23, 2025

I recently saw that there is an issue with certain names in the schema.

components:
  responses:
    "400":
      description: Bad request

The schema above will generate the definition export type 400 = void where 400 is an invalid identifier.

The problem happens in schemaToTypeAliasDeclaration as the name is used without any check for its validity.

I addressed this issue by prepending invalid names by _ and if they are still invalid, by removing any non A-Za-z0-9 characters.

It might cause collisions though if you have e.g. 400 and _400, or you use a schema full of e.g. emojis as names.

@sschw sschw force-pushed the fix-invalid-types branch from 7ce0868 to 5e6a919 Compare August 23, 2025 18:54
@triglian
Copy link

+1

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

Successfully merging this pull request may close these issues.

2 participants