Skip to content

Generated runtime validations (zod, io-ts, ...) are not validating/parsing the response #29

@Colmea

Description

@Colmea

Hi @astahmer,

Sorry for 2 issues in one day 🥲

I would like to use this library because of the runtime validation support (zod mainly) it provides.

Based on this from README

you can also generate a client with runtime validation using one of the following runtimes

I would expect that the generated ApiClient actually uses these zod schemas and parse the response with them, but it looks like it's note the case.

See the generated GET request here. It never uses the generated zod schema.

  // <ApiClient.get>
  get<Path extends keyof GetEndpoints, TEndpoint extends GetEndpoints[Path]>(
    path: Path,
    ...params: MaybeOptionalArg<z.infer<TEndpoint['parameters']>>
  ): Promise<z.infer<TEndpoint['response']>> {
    return this.fetcher('get', this.baseUrl + path, params[0]) as Promise<
      z.infer<TEndpoint['response']>
    >;
  }
  // </ApiClient.get>

Am I missing something ? Or are we just supposed to use the generated zod schemas on our own (if so, why not directly use them in the ApiClient ?)

Thanks for your help!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions