Skip to content

Fix ContentType ignoring enumStyle: "union" in http-client#1762

Open
Upgrade220 wants to merge 2 commits into
acacode:mainfrom
Upgrade220:fix/union-content-type
Open

Fix ContentType ignoring enumStyle: "union" in http-client#1762
Upgrade220 wants to merge 2 commits into
acacode:mainfrom
Upgrade220:fix/union-content-type

Conversation

@Upgrade220
Copy link
Copy Markdown
Contributor

@Upgrade220 Upgrade220 commented May 21, 2026

Problem

When enumStyle: "union" is configured, user-defined enums are generated as plain type aliases. The built-in ContentType in the http-client was not covered by this path — it fell through to the else branch and was always generated as a regular enum. This was overlooked in #1754 when enumStyle was introduced; only the const case 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 causes isolatedModules errors in the modular output's import.

Fixes #1761.

Solution

  • Adds a union branch to both fetch-http-client.ejs and axios-http-client.ejs that emits export type ContentType = "application/json" | ...
  • Introduces templates/base/content-type-accessors.ejs, a shared partial (following the route-docs.ejs pattern) that returns the correct accessor string for each content type based on enumStyle. 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 the CONTENT_KIND constants from schema-routes.ts
  • Updates modular/api.ejs to emit import { …, type ContentType, … } (inline type import) in union mode, avoiding isolatedModules errors
  • Adds a union-enums-http-client test case to the existing enumStyle spec

Summary by cubic

Makes ContentType in generated http-clients respect enumStyle: "union", fixing invalid property access and isolatedModules issues. Unifies content-type access across templates to work with both enum and union modes.

  • Bug Fixes

    • Generate ContentType as a union type in fetch-http-client.ejs and axios-http-client.ejs when enumStyle is "union".
    • Use shared accessors via templates/base/content-type-accessors.ejs in http-clients and procedure-call templates to avoid dot-property access in union mode.
    • In modular builds, import type ContentType from the http-client when in union mode to satisfy isolatedModules.
    • Add union-enums-http-client test coverage.
  • Migration

    • If you reference ContentType.* at runtime while using enumStyle: "union", switch to string literals (e.g., "application/json") or treat ContentType as a type-only import. No changes needed for generated API usage.

Written for commit 90cf9cc. Summary will update on new commits. Review in cubic

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-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 21, 2026

🦋 Changeset detected

Latest commit: 90cf9cc

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 Patch

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

Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

No issues found across 9 files

Re-trigger cubic

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
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.

ContentType in http-client ignores enumStyle: "union"

1 participant