Skip to content

react-query generator uses { data } for SSE endpoints (ServerSentEventsResult) causing TS2339; should use stream #3203

@hqw567

Description

@hqw567

Description

Bug report

When using text/event-stream (SSE) responses, openapi-ts generates a TanStack React Query mutation that destructures { data } from the client call, but the generated client returns ServerSentEventsResult<...> (no data field). This causes TypeScript errors like TS2339: Property 'data' does not exist on type 'ServerSentEventsResult<...>'.

OpenAPI snippet (minimal)

/api/v1/documents/{domain_id}/ingest_permanent_document_batch:
  post:
    summary: Ingest permanent documents and link them to assistants.
    description: Uses Server-Sent Events (SSE) to stream progress updates.
    parameters:
      - name: domain_id
        in: path
        required: true
        schema:
          type: string
          format: uuid
    requestBody:
      required: true
      content:
        multipart/form-data:
          schema:
            $ref: "#/components/schemas/Body_ingestPermanentDocumentBatch"
    responses:
      "200":
        description: SSE stream with progress updates
        content:
          text/event-stream:
            schema:
              oneOf:
                - $ref: "#/components/schemas/BatchIngestionSSEUpdate"
                - $ref: "#/components/schemas/BatchIngestionSSEResult"
                - $ref: "#/components/schemas/BatchIngestionSSEError"

Generated code (problem)

File: src/services/_openapi/.../@tanstack/react-query.gen.ts

mutationFn: async (fnOptions) => {
  const { data } = await PostSse({
    ...options,
    ...fnOptions,
    throwOnError: true,
  })
  return data
}

TypeScript error

error TS2339: Property 'data' does not exist on type
'ServerSentEventsResult<PostSseResponses, PostSseErrors>'.

const { data } = await PostSse(...)
        ^^^^ no data on SSE result

Expected behavior

For SSE endpoints, the generated mutation should NOT assume a JSON response with data.
Instead it should return the SSE stream result, e.g.:

mutationFn: async (fnOptions) => {
  const { stream } = await PostSse({
    ...options,
    ...fnOptions,
    throwOnError: true,
  })
  return stream
}

(or return the entire ServerSentEventsResult object, depending on the intended API.)

Actual behavior

Generator always emits { data } = await <operation>() and return data, even for SSE endpoints.

Environment

  • openapi-ts: 0.90.3
  • generator: @tanstack/react-query
  • TypeScript: 5.9
  • runtime: axios

Reproducible example or configuration

No response

OpenAPI specification (optional)

No response

System information (optional)

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug 🔥Broken or incorrect behavior.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions