Skip to content

writeOnly regression: response types now use writable variant #2849

@adri1wald

Description

@adri1wald

Description

The fix for #2792 shipped in @hey-api/openapi-ts@0.86.4 restored writeOnly fields for request bodies, but it now propagates the writable shape everywhere the schema is referenced. If a schema is shared between a request body and a response, the generated response type is also replaced with PayloadWritable.

This is different from the original bug: request payloads are now correct, but responses are incorrectly using the writable variant instead of the read-only one.

Reproducible example or configuration

npx --yes @hey-api/openapi-ts@latest \
  --input writeonly-regression.yml \
  --output out \
  --plugins @hey-api/typescript

Generated snippet (out/types.gen.ts):

export type Item = {
    payload: PayloadWritable;
};

export type CreateItemRequest = {
    payload: PayloadWritable;
};

export type Payload = {
    kind: 'jpeg';
};

export type PayloadWritable = {
    kind: 'jpeg';
    /**
     * Data sent on write only
     */
    encoded: string;
};

export type ItemCreateData = {
    body: CreateItemRequest;
    path?: never;
    query?: never;
    url: '/items';
};

export type ItemCreateResponses = {
    /**
     * Created item
     */
    201: Item;
};

export type ItemCreateResponse = ItemCreateResponses[keyof ItemCreateResponses];

export type ItemRetrieveData = {
    body?: never;
    path: {
        id: string;
    };
    query?: never;
    url: '/items/{id}';
};

export type ItemRetrieveResponses = {
    /**
     * Item
     */
    200: Item;
};

export type ItemRetrieveResponse = ItemRetrieveResponses[keyof ItemRetrieveResponses];

OpenAPI specification

openapi: 3.0.3
info:
  title: writeOnly regression repro
  version: 1.0.0
paths:
  /items:
    post:
      operationId: item_create
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateItemRequest'
      responses:
        '201':
          description: Created item
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Item'
  /items/{id}:
    get:
      operationId: item_retrieve
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
      responses:
        '200':
          description: Item
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Item'
components:
  schemas:
    Item:
      type: object
      required: [payload]
      properties:
        payload:
          $ref: '#/components/schemas/Payload'
    CreateItemRequest:
      type: object
      required: [payload]
      properties:
        payload:
          $ref: '#/components/schemas/Payload'
    Payload:
      type: object
      required: [kind, encoded]
      properties:
        kind:
          type: string
          enum: [jpeg]
        encoded:
          type: string
          writeOnly: true
          description: Data sent on write only

System information

@hey-api/openapi-ts 0.86.4
Node.js v23.7.0
macOS 15.7.1 (24G231)

Metadata

Metadata

Assignees

Labels

bug 🔥Broken or incorrect behavior.

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