Skip to content

feat: const object-style enum generation #1281

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

bjohnso5
Copy link

Closes #1040.

Copy link

changeset-bot bot commented Jun 10, 2025

🦋 Changeset detected

Latest commit: 9d1d74e

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
swagger-typescript-api Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@bjohnso5 bjohnso5 force-pushed the feat/1040-const-object-enums branch from e92ab65 to ef626cf Compare June 10, 2025 23:01
@bjohnso5 bjohnso5 marked this pull request as ready for review June 10, 2025 23:49
@bjohnso5
Copy link
Author

I'm not clear on how best to extend this to the inline enum generation, or if that even makes sense - I'd love some guidance.

@smorimoto smorimoto requested a review from Copilot June 11, 2025 03:34
Copy link

@Copilot 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 implements the generation of enums as pairs of const objects and derived types, making this behavior mutually exclusive with the union enums generation. Key changes include updating configuration interfaces, modifications to the CLI, updates in the schema formatter to support const object enums, and new tests and snapshots covering this feature.

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.

Show a summary per file
File Description
types/index.ts Added the generateConstObjectEnums flag in API parameters and configuration.
tests/spec/constObjectEnums/schema.json New schema file for testing const object enum generation.
tests/spec/constObjectEnums/basic.test.ts Added test to validate const object enums generation.
tests/spec/constObjectEnums/snapshots/basic.test.ts.snap Updated snapshot reflecting the new const object enums.
templates/base/data-contracts.ejs Added template support for const object enums.
src/schema-parser/schema-formatters.ts Updated schema formatting to generate const object enums when enabled.
src/configuration.ts Updated configuration to include the new generateConstObjectEnums flag.
index.ts Included the new CLI flag and passed the option to the API generator.
Comments suppressed due to low confidence (2)

index.ts:184

  • Consider clarifying in the CLI flag description that this option is mutually exclusive with generateUnionEnums to ensure consistency with the documentation provided in the API interface comments.
    "generate-const-object-enums": {

src/schema-parser/schema-formatters.ts:41

  • [nitpick] Ensure that the generated code block for const object enums adheres to consistent formatting standards (e.g., semicolon usage and newlines) across all generated files.
          typeIdentifier: this.config.Ts.Keyword.Const,

@bjohnso5 bjohnso5 changed the title Implement const object-style enum generation feat: const object-style enum generation Jun 11, 2025
@smorimoto
Copy link
Collaborator

bugbot run

Copy link

cursor-com bot commented Jun 11, 2025

🚨 BugBot couldn't run

Pull requests from forked repositories are not yet supported (requestId: serverGenReqId_5bf595eb-a690-4534-8c07-4a24d2f0a837).

@bjohnso5 bjohnso5 force-pushed the feat/1040-const-object-enums branch from d7169f5 to 9d1d74e Compare June 11, 2025 17:54
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.

Generate objects instead of enums
3 participants