Skip to content

Conversation

@jgclement91
Copy link
Contributor

@jgclement91 jgclement91 commented Nov 26, 2025

Jira issue link: EP-7657

When using the enum: true configuration option with openapi-typescript, the types-plugin was generating duplicate exports:

  1. Enum declarations from openapi-typescript (e.g., export enum Status)
  2. Type aliases from types-plugin (e.g., export type Status = components["schemas"]["Status"])

Description of changes

  • Modified src/plugins/types-plugin.ts to detect existing enum declarations using TypeScript's AST API (ts.isEnumDeclaration())
  • Added filtering logic to exclude enum names when generating convenience type aliases
  • Non-enum schemas continue to receive their type aliases as before (e.g., export type Task = components["schemas"]["Task"])
  • Added E2E test in tests/e2e.test.ts with test data file tests/data/enums.yaml to verify enums generate without duplicates
  • Fixed toSafeName function to use PascalCase transformation (src/plugins/types-plugin.ts:81-127)
    • Previously stripped special characters: "user-status" → "userstatus"
    • Now uses PascalCase to match openapi-typescript's enum naming: "user-status" → "UserStatus"
    • This ensures the enum filtering logic works correctly for schemas with special characters (hyphens, dots, etc.)
  • Enhanced test coverage for enum schemas with special characters
    • Added "user-status" and "task.priority" enum schemas to tests/data/enums.yaml
    • Updated E2E test assertions to verify no duplicate type aliases are generated for these cases
    • This prevents regression where enums with non-identifier characters would still generate duplicate type aliases
  • Updated doc reference url (https://openapi-ts.dev/cli#flags)

Breaking changes

No breaking change

Additional checks

  • Added new tests that cover the code changes + tested locally

(Had to close the previous PR because of the JIRA validation failing

Copilot finished reviewing on behalf of jgclement91 November 26, 2025 14:19
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes duplicate enum/type alias exports when using the enum: true configuration option with openapi-typescript. Previously, the types-plugin would generate both enum declarations (from openapi-typescript) and type aliases for the same schemas, causing duplicates.

Key Changes:

  • Added enum detection logic using TypeScript's AST API to filter out schemas that already have enum declarations
  • Updated toSafeName function to use PascalCase transformation (e.g., "user-status" → "UserStatus") to match openapi-typescript's enum naming conventions
  • Added comprehensive E2E and unit tests to verify enums generate without duplicate type aliases

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
packages/create-schemas/src/plugins/types-plugin.ts Added enum detection logic and updated toSafeName to PascalCase for matching enum names
packages/create-schemas/tests/plugins.test.ts Added unit test for enum filtering and updated expectations for PascalCase naming
packages/create-schemas/tests/generate.test.ts Updated test expectations to reflect PascalCase naming convention
packages/create-schemas/tests/e2e.test.ts Added E2E test verifying enums with special characters don't generate duplicate type aliases
packages/create-schemas/tests/data/enums.yaml Added test OpenAPI schema with various enum types and edge cases
packages/create-schemas/tests/snapshots/e2e.test.ts.snap Added snapshot for enum generation test output
docs/src/configuration.md Updated openapi-typescript documentation URL reference

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@jgclement91 jgclement91 removed the request for review from romanzhyn-workleap November 26, 2025 14:25
@jgclement91 jgclement91 merged commit c68c022 into main Nov 26, 2025
12 checks passed
@jgclement91 jgclement91 deleted the feature/squad1/EP-7657_resolve_enum_declaration_conflict branch November 26, 2025 14:26
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.

5 participants