Fix ContentType ignoring enumStyle: "union" in http-client#1762
Open
Upgrade220 wants to merge 2 commits into
Open
Fix ContentType ignoring enumStyle: "union" in http-client#1762Upgrade220 wants to merge 2 commits into
Upgrade220 wants to merge 2 commits into
Conversation
When enumStyle is set to "union", user-defined enums are generated as plain type aliases, but ContentType in the http-client was still generated as a regular enum. Call sites in the generated API also used ContentType.Json etc., which are invalid without a runtime object. Adds a union branch to both http-client templates that generates ContentType as a type alias. Introduces a shared partial (content-type-accessors.ejs) that returns the correct accessor strings for both http-client templates (CT.Json) and procedure-call templates (requestContentKind["JSON"]) based on the active enumStyle. Updates modular/api.ejs to use an inline type import for ContentType when in union mode, avoiding isolatedModules errors. Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
🦋 Changeset detectedLatest commit: 90cf9cc 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 |
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.
Problem
When
enumStyle: "union"is configured, user-defined enums are generated as plain type aliases. The built-inContentTypein the http-client was not covered by this path — it fell through to theelsebranch and was always generated as a regularenum. This was overlooked in #1754 whenenumStylewas introduced; only theconstcase was handled for ContentType.Beyond the declaration, all call sites inside the http-client class body (
contentFormatters,type || ContentType.Json,type !== ContentType.FormData) and in generated API methods (type: ContentType.Json) used dot-property access, which is invalid when ContentType is a type alias with no runtime object. This also causesisolatedModuleserrors in the modular output's import.Fixes #1761.
Solution
unionbranch to bothfetch-http-client.ejsandaxios-http-client.ejsthat emitsexport type ContentType = "application/json" | ...templates/base/content-type-accessors.ejs, a shared partial (following theroute-docs.ejspattern) that returns the correct accessor string for each content type based onenumStyle. It serves two consumers with different key conventions: http-client templates use camelCase keys (CT.Json), procedure-call templates use UPPER_SNAKE keys (requestContentKind["JSON"]) matching theCONTENT_KINDconstants fromschema-routes.tsmodular/api.ejsto emitimport { …, type ContentType, … }(inline type import) in union mode, avoidingisolatedModuleserrorsunion-enums-http-clienttest case to the existingenumStylespecSummary by cubic
Makes
ContentTypein generated http-clients respectenumStyle: "union", fixing invalid property access andisolatedModulesissues. Unifies content-type access across templates to work with both enum and union modes.Bug Fixes
ContentTypeas a union type infetch-http-client.ejsandaxios-http-client.ejswhenenumStyleis"union".templates/base/content-type-accessors.ejsin http-clients and procedure-call templates to avoid dot-property access in union mode.type ContentTypefrom the http-client when in union mode to satisfyisolatedModules.union-enums-http-clienttest coverage.Migration
ContentType.*at runtime while usingenumStyle: "union", switch to string literals (e.g.,"application/json") or treatContentTypeas a type-only import. No changes needed for generated API usage.Written for commit 90cf9cc. Summary will update on new commits. Review in cubic