Skip to content

ContentType in http-client ignores enumStyle: "union" #1761

@Upgrade220

Description

@Upgrade220

When enumStyle: "union" is set, all user-defined enums are correctly generated as plain type aliases (e.g. export type Status = "active" | "inactive"). However, the built-in ContentType in the generated http-client is still emitted as a regular TypeScript enum regardless of the setting.

Additionally, the generated API call sites use ContentType.Json, ContentType.FormData, etc. — dot-property access that requires a runtime object. Since a plain type alias has no runtime representation, this produces invalid TypeScript under isolatedModules: true and breaks at runtime.

This was missed in #1754 where enumStyle was introduced. The const branch was handled for ContentType (it generates a const object + type alias), but no union branch was added.

Expected behaviour:

With enumStyle: "union":

// http-client
export type ContentType = "application/json" | "application/vnd.api+json" | "multipart/form-data" | "application/x-www-form-urlencoded" | "text/plain";

// generated API call
createPet(data: Pet, params: RequestParams = {}) =>
  this.request<Pet, any>({
    path: `/pets`,
    method: "POST",
    body: data,
    type: "application/json",  // ← string literal, not ContentType.Json
    ...params,
  })

Actual behaviour:

ContentType is generated as export enum ContentType { ... } and call sites use type: ContentType.Json.

Apologies for the oversight — this should have been caught and included in #1754.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions