Skip to content

chore(api): declare typed responses in OpenAPI so the generated client returns real types #6

Description

@SKonteye

Problem

No endpoint declares a response type. Every handler returns a plain object or a TypeScript interface, which vanishes at runtime, so Swagger emits either no schema or { "type": "object" }. @wantere/api-client therefore returns { [key: string]: unknown } for every call (see listingsControllerFindOneV1200.ts, conversationsControllerStartV1201.ts). The web app follow-ups for #4 will have to hand-write types that already exist in the API, and any drift between the two will go unnoticed until runtime.

Proposal

Adopt one convention for the 24 existing endpoints and every new one:

  1. Turn each response interface (ListingSummary, ListingDetail, ConversationView, MessageView, the favorites and notifications shapes, the public profile) into a class with @ApiProperty() decorators. Interfaces cannot be seen by Swagger; classes can.
  2. Add @ApiOkResponse({ type: X }) or @ApiCreatedResponse({ type: X }) to every handler. @HttpCode(204) routes get @ApiNoContentResponse().
  3. Add a small helper for paginated lists, e.g. ApiPaginatedResponse(ItemDto), that builds the Paginated<T> schema from PageMetaDto so items is typed too.
  4. Regenerate the client once with pnpm api:generate and check that packages/api-client/src/generated/models no longer contains { [key: string]: unknown } types.
  5. Add a CONTRIBUTING note: a new endpoint is not done until its response is declared.

Acceptance criteria

  • Every operation in apps/api/openapi.json has a response schema with named properties.
  • The generated client exposes a named type for each response; no *V1200.ts / *V1201.ts files with unknown maps remain.
  • Existing unit and end-to-end tests pass unchanged, since the wire format does not move.
  • pnpm lint, pnpm typecheck, pnpm build pass.

Out of scope

Changing any response shape. This is declaration only.

Context

Raised while implementing #4 (PR #5). Rough size: one afternoon.

https://claude.ai/code/session_01VGBQpJZopVVa1AWeVsNaWg

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions