Skip to content

Response not validated with custom API implementation #858

@marcmontu

Description

@marcmontu

Describe the bug

When you configure a client with both validateResponse: true and api: () => { /* whatever */ }, the response is not validated.
I understand this one might be on a gray zone, but as far as I can tell it's not documented, and the behaviour is a bit surprising.

How to reproduce

  • Create a client with initClient
  • Set validateResponse: true
  • Override implementation via api property
  • Do a query with the client
  • Response has not been validated

Expected behavior

Response would still be validated.
I understand if you're switching out the native implementation, you might not want that.
In that case, it could be made more obvious that validateResponse is not simultaneously supported.
For example, make them mutually exclusive via TypeScript types, or

Code reproduction

  initClient(
    { contracts },
    {
      baseUrl: 'http://example.com',
      validateResponse: true,
      api: () => { /* return some stubbed response */ }
    },
  );

Calling any contracts on this client will in fact not validate the response

ts-rest version

"@ts-rest/core": "3.51.0",
"@ts-rest/nest": "3.51.0",
"@ts-rest/open-api": "3.51.0",

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions