Replace generateUnionEnums with unified enumStyle option#1754
Open
Upgrade220 wants to merge 3 commits into
Open
Replace generateUnionEnums with unified enumStyle option#1754Upgrade220 wants to merge 3 commits into
Upgrade220 wants to merge 3 commits into
Conversation
Replaces the boolean generateUnionEnums flag with a unified enumStyle: "enum" | "union" | "const" field. generateUnionEnums is kept as a deprecated alias with a runtime warning. Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
🦋 Changeset detectedLatest commit: cb32443 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
There was a problem hiding this comment.
1 issue found across 14 files
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
The type alias line now respects contract.internal, matching the export control behaviour of the other handlers. Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1040
Problem
The library currently exposes
generateUnionEnumsas a boolean flag to switch enum output to union types. PR #1281 proposes adding a second booleangenerateConstObjectEnumsforas constobject output. I think adding a second independent boolean is the wrong direction — two mutually exclusive flags that silently override each other is confusing API design, and it still leaves a gap:ContentTypein the http-client is always emitted as a traditionalenumregardless of what the user configures, making the output inconsistent.Proposal
I propose replacing both flags with a single unified
enumStyleoption:This makes the three output modes explicit and mutually exclusive by construction.
generateUnionEnumsis preserved as a deprecated alias — it still works and emits a runtime warning pointing users to the new option, so nothing breaks for existing consumers.I also propose extending the
"const"style to coverContentTypein the http-client templates. WhenenumStyle: "const"is set,ContentTypeis emitted as:This makes the entire generated output consistent — schema enums and internal http-client constants follow the same pattern.
Changes
enumStyle: "enum" | "union" | "const"config option and--enum-styleCLI flaggenerateUnionEnums: trueauto-promotes toenumStyle: "union"with a deprecation warning"const"style generatesas constobjects with a companion type alias for all schema enums"const"style also convertsContentTypein both Axios and Fetch http-client templatesenum-data-contract.ejssubtemplate updated to support all three stylesTs.Keyword.Constadded for template authors who usecodeGenConstructsenumStyle: "const"Summary by cubic
Replaces
generateUnionEnumswith a unifiedenumStyleoption ("enum" | "union" | "const") to control enum output, and applies the"const"style toContentTypein Axios and Fetch clients. Adds a CLI flag, deprecates the old option with a warning, keeps the default as"enum", and fixes an internal export leak forconstenums.New Features
enumStyle("enum" | "union" | "const") and--enum-styleCLI flag;generateUnionEnumsremains as a deprecated alias that auto-promotes toenumStyle: "union"with a warning."const"style emitsas constobjects with a companion type alias and updatesContentTypein both clients; parsers/discriminator handling/templates updated; snapshot tests added.Bug Fixes
consthandler now respectsinternaland does not export the type alias for internal contracts.Written for commit cb32443. Summary will update on new commits. Review in cubic