Skip to content

feat: error handling + withResponse + includeClient option #26

feat: error handling + withResponse + includeClient option

feat: error handling + withResponse + includeClient option #26

Triggered via pull request August 1, 2025 10:37
Status Failure
Total duration 43s
Artifacts

build-and-test.yaml

on: pull_request
Build and Test
38s
Build and Test
Fit to window
Zoom out
Zoom in

Annotations

10 errors
tests/generate-runtime.test.ts > generate-runtime-docker.openapi > generate typebox: packages/typed-openapi/tests/generate-runtime.test.ts#L24
Error: Snapshot `generate-runtime-docker.openapi > generate typebox 1` mismatched - Expected + Received @@ -4650,51 +4650,66 @@ // Error handling types export type TypedApiResponse< TSuccess, TAllResponses extends Record<string | number, unknown> = {}, > = keyof TAllResponses extends never - ? { + ? Omit<Response, "ok" | "status" | "json"> & { ok: true; status: number; data: TSuccess; + json: () => Promise<TSuccess>; } : { [K in keyof TAllResponses]: K extends string ? K extends `${infer TStatusCode extends number}` ? TStatusCode extends StatusCode - ? { + ? Omit<Response, "ok" | "status" | "json"> & { ok: true; status: TStatusCode; - data: TAllResponses[K]; + data: TSuccess; + json: () => Promise<TSuccess>; } - : { + : Omit<Response, "ok" | "status" | "json"> & { ok: false; status: TStatusCode; - error: TAllResponses[K]; + data: TAllResponses[K]; + json: () => Promise<TAllResponses[K]>; } : never : K extends number ? K extends StatusCode - ? { + ? Omit<Response, "ok" | "status" | "json"> & { ok: true; status: K; - data: TAllResponses[K]; + data: TSuccess; + json: () => Promise<TSuccess>; } - : { + : Omit<Response, "ok" | "status" | "json"> & { ok: false; status: K; - error: TAllResponses[K]; + data: TAllResponses[K]; + json: () => Promise<TAllResponses[K]>; } : never; }[keyof TAllResponses]; export type SafeApiResponse<TEndpoint> = TEndpoint extends { response: infer TSuccess; responses: infer TResponses } ? TResponses extends Record<string, unknown> ? TypedApiResponse<TSuccess, TResponses> - : { ok: true; status: number; data: TSuccess } + : Omit<Response, "ok" | "status" | "json"> & { + ok: true; + status: number; + data: TSuccess; + json: () => Promise<TSuccess>; + } : TEndpoint extends { response: infer TSuccess } - ? { ok: true; status: number; data: TSuccess } + ? Omit<Response, "ok" | "status" | "json"> & { + ok: true; + status: number; + data: TSuccess; + json: () => Promise<TSuccess>; + } : never; type RequiredKeys<T> = { [P in keyof T]-?: undefined extends T[P] ? never : P; }[keyof T]; @@ -4744,16 +4759,21 @@ const { withResponse: _, ...fetchParams } = requestParams || {}; if (withResponse) { return this.fetcher("get", this.baseUrl + path, Object.keys(fetchParams).length ? fetchParams : undefined).then( async (response) => { + // Parse the response data const data = await this.parseResponse(response); - if (response.ok) { - return { ok: true, status: response.status, data }; - } else { - return { ok: false, status: response.status, error: data }; - } + + // Override properties while keeping the original Response object + const typedResponse = Object.assign(response, { + ok: response.ok, + status: response.status, + data: data, + json: () => Promise.resolve(data), + }); + return typedResponse; }, ); } else { return this.fetcher("get", this.baseUrl + path, requestParams).then((response) => this.parseResponse(response), @@ -4784,16 +4804,21 @@ const { withResponse: _, ...fetchParams } = requestParams || {}; if (withResponse) { return this.fetcher("post", this.baseUrl + path, Object.keys(fetchParams).length ? fetc
tests/generate-runtime.test.ts > generate-runtime-docker.openapi > generate none: packages/typed-openapi/tests/generate-runtime.test.ts#L24
Error: Snapshot `generate-runtime-docker.openapi > generate none 1` mismatched - Expected + Received @@ -2608,51 +2608,66 @@ // Error handling types export type TypedApiResponse< TSuccess, TAllResponses extends Record<string | number, unknown> = {}, > = keyof TAllResponses extends never - ? { + ? Omit<Response, "ok" | "status" | "json"> & { ok: true; status: number; data: TSuccess; + json: () => Promise<TSuccess>; } : { [K in keyof TAllResponses]: K extends string ? K extends `${infer TStatusCode extends number}` ? TStatusCode extends StatusCode - ? { + ? Omit<Response, "ok" | "status" | "json"> & { ok: true; status: TStatusCode; - data: TAllResponses[K]; + data: TSuccess; + json: () => Promise<TSuccess>; } - : { + : Omit<Response, "ok" | "status" | "json"> & { ok: false; status: TStatusCode; - error: TAllResponses[K]; + data: TAllResponses[K]; + json: () => Promise<TAllResponses[K]>; } : never : K extends number ? K extends StatusCode - ? { + ? Omit<Response, "ok" | "status" | "json"> & { ok: true; status: K; - data: TAllResponses[K]; + data: TSuccess; + json: () => Promise<TSuccess>; } - : { + : Omit<Response, "ok" | "status" | "json"> & { ok: false; status: K; - error: TAllResponses[K]; + data: TAllResponses[K]; + json: () => Promise<TAllResponses[K]>; } : never; }[keyof TAllResponses]; export type SafeApiResponse<TEndpoint> = TEndpoint extends { response: infer TSuccess; responses: infer TResponses } ? TResponses extends Record<string, unknown> ? TypedApiResponse<TSuccess, TResponses> - : { ok: true; status: number; data: TSuccess } + : Omit<Response, "ok" | "status" | "json"> & { + ok: true; + status: number; + data: TSuccess; + json: () => Promise<TSuccess>; + } : TEndpoint extends { response: infer TSuccess } - ? { ok: true; status: number; data: TSuccess } + ? Omit<Response, "ok" | "status" | "json"> & { + ok: true; + status: number; + data: TSuccess; + json: () => Promise<TSuccess>; + } : never; type RequiredKeys<T> = { [P in keyof T]-?: undefined extends T[P] ? never : P; }[keyof T]; @@ -2702,16 +2717,21 @@ const { withResponse: _, ...fetchParams } = requestParams || {}; if (withResponse) { return this.fetcher("get", this.baseUrl + path, Object.keys(fetchParams).length ? fetchParams : undefined).then( async (response) => { + // Parse the response data const data = await this.parseResponse(response); - if (response.ok) { - return { ok: true, status: response.status, data }; - } else { - return { ok: false, status: response.status, error: data }; - } + + // Override properties while keeping the original Response object + const typedResponse = Object.assign(response, { + ok: response.ok, + status: response.status, + data: data, + json: () => Promise.resolve(data), + }); + return typedResponse; }, ); } else { return this.fetcher("get", this.baseUrl + path, requestParams).then((response) => this.parseResponse(response), @@ -2742,16 +2762,21 @@ const { withResponse: _, ...fetchParams } = requestParams || {}; if (withResponse) { return this.fetcher("post", this.baseUrl + path, Object.keys(fetchParams).length ? fetchPa
tests/generate-runtime.test.ts > generate-runtime-docker.openapi > generate io-ts: packages/typed-openapi/tests/generate-runtime.test.ts#L24
Error: Snapshot `generate-runtime-docker.openapi > generate io-ts 1` mismatched - Expected + Received @@ -4373,51 +4373,66 @@ // Error handling types export type TypedApiResponse< TSuccess, TAllResponses extends Record<string | number, unknown> = {}, > = keyof TAllResponses extends never - ? { + ? Omit<Response, "ok" | "status" | "json"> & { ok: true; status: number; data: TSuccess; + json: () => Promise<TSuccess>; } : { [K in keyof TAllResponses]: K extends string ? K extends `${infer TStatusCode extends number}` ? TStatusCode extends StatusCode - ? { + ? Omit<Response, "ok" | "status" | "json"> & { ok: true; status: TStatusCode; - data: TAllResponses[K]; + data: TSuccess; + json: () => Promise<TSuccess>; } - : { + : Omit<Response, "ok" | "status" | "json"> & { ok: false; status: TStatusCode; - error: TAllResponses[K]; + data: TAllResponses[K]; + json: () => Promise<TAllResponses[K]>; } : never : K extends number ? K extends StatusCode - ? { + ? Omit<Response, "ok" | "status" | "json"> & { ok: true; status: K; - data: TAllResponses[K]; + data: TSuccess; + json: () => Promise<TSuccess>; } - : { + : Omit<Response, "ok" | "status" | "json"> & { ok: false; status: K; - error: TAllResponses[K]; + data: TAllResponses[K]; + json: () => Promise<TAllResponses[K]>; } : never; }[keyof TAllResponses]; export type SafeApiResponse<TEndpoint> = TEndpoint extends { response: infer TSuccess; responses: infer TResponses } ? TResponses extends Record<string, unknown> ? TypedApiResponse<TSuccess, TResponses> - : { ok: true; status: number; data: TSuccess } + : Omit<Response, "ok" | "status" | "json"> & { + ok: true; + status: number; + data: TSuccess; + json: () => Promise<TSuccess>; + } : TEndpoint extends { response: infer TSuccess } - ? { ok: true; status: number; data: TSuccess } + ? Omit<Response, "ok" | "status" | "json"> & { + ok: true; + status: number; + data: TSuccess; + json: () => Promise<TSuccess>; + } : never; type RequiredKeys<T> = { [P in keyof T]-?: undefined extends T[P] ? never : P; }[keyof T]; @@ -4467,16 +4482,21 @@ const { withResponse: _, ...fetchParams } = requestParams || {}; if (withResponse) { return this.fetcher("get", this.baseUrl + path, Object.keys(fetchParams).length ? fetchParams : undefined).then( async (response) => { + // Parse the response data const data = await this.parseResponse(response); - if (response.ok) { - return { ok: true, status: response.status, data }; - } else { - return { ok: false, status: response.status, error: data }; - } + + // Override properties while keeping the original Response object + const typedResponse = Object.assign(response, { + ok: response.ok, + status: response.status, + data: data, + json: () => Promise.resolve(data), + }); + return typedResponse; }, ); } else { return this.fetcher("get", this.baseUrl + path, requestParams).then((response) => this.parseResponse(response), @@ -4507,16 +4527,21 @@ const { withResponse: _, ...fetchParams } = requestParams || {}; if (withResponse) { return this.fetcher("post", this.baseUrl + path, Object.keys(fetchParams).length ? fetchP
tests/generate-runtime.test.ts > generate-runtime-petstore > generate zod: packages/typed-openapi/tests/generate-runtime.test.ts#L24
Error: Snapshot `generate-runtime-petstore > generate zod 1` mismatched - Expected + Received @@ -500,51 +500,66 @@ // Error handling types export type TypedApiResponse< TSuccess, TAllResponses extends Record<string | number, unknown> = {}, > = keyof TAllResponses extends never - ? { + ? Omit<Response, "ok" | "status" | "json"> & { ok: true; status: number; data: TSuccess; + json: () => Promise<TSuccess>; } : { [K in keyof TAllResponses]: K extends string ? K extends `${infer TStatusCode extends number}` ? TStatusCode extends StatusCode - ? { + ? Omit<Response, "ok" | "status" | "json"> & { ok: true; status: TStatusCode; - data: TAllResponses[K]; + data: TSuccess; + json: () => Promise<TSuccess>; } - : { + : Omit<Response, "ok" | "status" | "json"> & { ok: false; status: TStatusCode; - error: TAllResponses[K]; + data: TAllResponses[K]; + json: () => Promise<TAllResponses[K]>; } : never : K extends number ? K extends StatusCode - ? { + ? Omit<Response, "ok" | "status" | "json"> & { ok: true; status: K; - data: TAllResponses[K]; + data: TSuccess; + json: () => Promise<TSuccess>; } - : { + : Omit<Response, "ok" | "status" | "json"> & { ok: false; status: K; - error: TAllResponses[K]; + data: TAllResponses[K]; + json: () => Promise<TAllResponses[K]>; } : never; }[keyof TAllResponses]; export type SafeApiResponse<TEndpoint> = TEndpoint extends { response: infer TSuccess; responses: infer TResponses } ? TResponses extends Record<string, unknown> ? TypedApiResponse<TSuccess, TResponses> - : { ok: true; status: number; data: TSuccess } + : Omit<Response, "ok" | "status" | "json"> & { + ok: true; + status: number; + data: TSuccess; + json: () => Promise<TSuccess>; + } : TEndpoint extends { response: infer TSuccess } - ? { ok: true; status: number; data: TSuccess } + ? Omit<Response, "ok" | "status" | "json"> & { + ok: true; + status: number; + data: TSuccess; + json: () => Promise<TSuccess>; + } : never; type RequiredKeys<T> = { [P in keyof T]-?: undefined extends T[P] ? never : P; }[keyof T]; @@ -594,16 +609,21 @@ const { withResponse: _, ...fetchParams } = requestParams || {}; if (withResponse) { return this.fetcher("put", this.baseUrl + path, Object.keys(fetchParams).length ? fetchParams : undefined).then( async (response) => { + // Parse the response data const data = await this.parseResponse(response); - if (response.ok) { - return { ok: true, status: response.status, data }; - } else { - return { ok: false, status: response.status, error: data }; - } + + // Override properties while keeping the original Response object + const typedResponse = Object.assign(response, { + ok: response.ok, + status: response.status, + data: data, + json: () => Promise.resolve(data), + }); + return typedResponse; }, ); } else { return this.fetcher("put", this.baseUrl + path, requestParams).then((response) => this.parseResponse(response), @@ -634,16 +654,21 @@ const { withResponse: _, ...fetchParams } = requestParams || {}; if (withResponse) { return this.fetcher("post", this.baseUrl + path, Object.keys(fetchParams).length ? fetchParams : undefi
tests/generate-runtime.test.ts > generate-runtime-petstore > generate yup: packages/typed-openapi/tests/generate-runtime.test.ts#L24
Error: Snapshot `generate-runtime-petstore > generate yup 1` mismatched - Expected + Received @@ -517,51 +517,66 @@ // Error handling types export type TypedApiResponse< TSuccess, TAllResponses extends Record<string | number, unknown> = {}, > = keyof TAllResponses extends never - ? { + ? Omit<Response, "ok" | "status" | "json"> & { ok: true; status: number; data: TSuccess; + json: () => Promise<TSuccess>; } : { [K in keyof TAllResponses]: K extends string ? K extends `${infer TStatusCode extends number}` ? TStatusCode extends StatusCode - ? { + ? Omit<Response, "ok" | "status" | "json"> & { ok: true; status: TStatusCode; - data: TAllResponses[K]; + data: TSuccess; + json: () => Promise<TSuccess>; } - : { + : Omit<Response, "ok" | "status" | "json"> & { ok: false; status: TStatusCode; - error: TAllResponses[K]; + data: TAllResponses[K]; + json: () => Promise<TAllResponses[K]>; } : never : K extends number ? K extends StatusCode - ? { + ? Omit<Response, "ok" | "status" | "json"> & { ok: true; status: K; - data: TAllResponses[K]; + data: TSuccess; + json: () => Promise<TSuccess>; } - : { + : Omit<Response, "ok" | "status" | "json"> & { ok: false; status: K; - error: TAllResponses[K]; + data: TAllResponses[K]; + json: () => Promise<TAllResponses[K]>; } : never; }[keyof TAllResponses]; export type SafeApiResponse<TEndpoint> = TEndpoint extends { response: infer TSuccess; responses: infer TResponses } ? TResponses extends Record<string, unknown> ? TypedApiResponse<TSuccess, TResponses> - : { ok: true; status: number; data: TSuccess } + : Omit<Response, "ok" | "status" | "json"> & { + ok: true; + status: number; + data: TSuccess; + json: () => Promise<TSuccess>; + } : TEndpoint extends { response: infer TSuccess } - ? { ok: true; status: number; data: TSuccess } + ? Omit<Response, "ok" | "status" | "json"> & { + ok: true; + status: number; + data: TSuccess; + json: () => Promise<TSuccess>; + } : never; type RequiredKeys<T> = { [P in keyof T]-?: undefined extends T[P] ? never : P; }[keyof T]; @@ -611,16 +626,21 @@ const { withResponse: _, ...fetchParams } = requestParams || {}; if (withResponse) { return this.fetcher("put", this.baseUrl + path, Object.keys(fetchParams).length ? fetchParams : undefined).then( async (response) => { + // Parse the response data const data = await this.parseResponse(response); - if (response.ok) { - return { ok: true, status: response.status, data }; - } else { - return { ok: false, status: response.status, error: data }; - } + + // Override properties while keeping the original Response object + const typedResponse = Object.assign(response, { + ok: response.ok, + status: response.status, + data: data, + json: () => Promise.resolve(data), + }); + return typedResponse; }, ); } else { return this.fetcher("put", this.baseUrl + path, requestParams).then((response) => this.parseResponse(response), @@ -651,16 +671,21 @@ const { withResponse: _, ...fetchParams } = requestParams || {}; if (withResponse) { return this.fetcher("post", this.baseUrl + path, Object.keys(fetchParams).length ? fetchParams : undefi
tests/generate-runtime.test.ts > generate-runtime-petstore > generate valibot: packages/typed-openapi/tests/generate-runtime.test.ts#L24
Error: Snapshot `generate-runtime-petstore > generate valibot 1` mismatched - Expected + Received @@ -506,51 +506,66 @@ // Error handling types export type TypedApiResponse< TSuccess, TAllResponses extends Record<string | number, unknown> = {}, > = keyof TAllResponses extends never - ? { + ? Omit<Response, "ok" | "status" | "json"> & { ok: true; status: number; data: TSuccess; + json: () => Promise<TSuccess>; } : { [K in keyof TAllResponses]: K extends string ? K extends `${infer TStatusCode extends number}` ? TStatusCode extends StatusCode - ? { + ? Omit<Response, "ok" | "status" | "json"> & { ok: true; status: TStatusCode; - data: TAllResponses[K]; + data: TSuccess; + json: () => Promise<TSuccess>; } - : { + : Omit<Response, "ok" | "status" | "json"> & { ok: false; status: TStatusCode; - error: TAllResponses[K]; + data: TAllResponses[K]; + json: () => Promise<TAllResponses[K]>; } : never : K extends number ? K extends StatusCode - ? { + ? Omit<Response, "ok" | "status" | "json"> & { ok: true; status: K; - data: TAllResponses[K]; + data: TSuccess; + json: () => Promise<TSuccess>; } - : { + : Omit<Response, "ok" | "status" | "json"> & { ok: false; status: K; - error: TAllResponses[K]; + data: TAllResponses[K]; + json: () => Promise<TAllResponses[K]>; } : never; }[keyof TAllResponses]; export type SafeApiResponse<TEndpoint> = TEndpoint extends { response: infer TSuccess; responses: infer TResponses } ? TResponses extends Record<string, unknown> ? TypedApiResponse<TSuccess, TResponses> - : { ok: true; status: number; data: TSuccess } + : Omit<Response, "ok" | "status" | "json"> & { + ok: true; + status: number; + data: TSuccess; + json: () => Promise<TSuccess>; + } : TEndpoint extends { response: infer TSuccess } - ? { ok: true; status: number; data: TSuccess } + ? Omit<Response, "ok" | "status" | "json"> & { + ok: true; + status: number; + data: TSuccess; + json: () => Promise<TSuccess>; + } : never; type RequiredKeys<T> = { [P in keyof T]-?: undefined extends T[P] ? never : P; }[keyof T]; @@ -600,16 +615,21 @@ const { withResponse: _, ...fetchParams } = requestParams || {}; if (withResponse) { return this.fetcher("put", this.baseUrl + path, Object.keys(fetchParams).length ? fetchParams : undefined).then( async (response) => { + // Parse the response data const data = await this.parseResponse(response); - if (response.ok) { - return { ok: true, status: response.status, data }; - } else { - return { ok: false, status: response.status, error: data }; - } + + // Override properties while keeping the original Response object + const typedResponse = Object.assign(response, { + ok: response.ok, + status: response.status, + data: data, + json: () => Promise.resolve(data), + }); + return typedResponse; }, ); } else { return this.fetcher("put", this.baseUrl + path, requestParams).then((response) => this.parseResponse(response), @@ -640,16 +660,21 @@ const { withResponse: _, ...fetchParams } = requestParams || {}; if (withResponse) { return this.fetcher("post", this.baseUrl + path, Object.keys(fetchParams).length ? fetchParams : un
tests/generate-runtime.test.ts > generate-runtime-petstore > generate typebox: packages/typed-openapi/tests/generate-runtime.test.ts#L24
Error: Snapshot `generate-runtime-petstore > generate typebox 1` mismatched - Expected + Received @@ -535,51 +535,66 @@ // Error handling types export type TypedApiResponse< TSuccess, TAllResponses extends Record<string | number, unknown> = {}, > = keyof TAllResponses extends never - ? { + ? Omit<Response, "ok" | "status" | "json"> & { ok: true; status: number; data: TSuccess; + json: () => Promise<TSuccess>; } : { [K in keyof TAllResponses]: K extends string ? K extends `${infer TStatusCode extends number}` ? TStatusCode extends StatusCode - ? { + ? Omit<Response, "ok" | "status" | "json"> & { ok: true; status: TStatusCode; - data: TAllResponses[K]; + data: TSuccess; + json: () => Promise<TSuccess>; } - : { + : Omit<Response, "ok" | "status" | "json"> & { ok: false; status: TStatusCode; - error: TAllResponses[K]; + data: TAllResponses[K]; + json: () => Promise<TAllResponses[K]>; } : never : K extends number ? K extends StatusCode - ? { + ? Omit<Response, "ok" | "status" | "json"> & { ok: true; status: K; - data: TAllResponses[K]; + data: TSuccess; + json: () => Promise<TSuccess>; } - : { + : Omit<Response, "ok" | "status" | "json"> & { ok: false; status: K; - error: TAllResponses[K]; + data: TAllResponses[K]; + json: () => Promise<TAllResponses[K]>; } : never; }[keyof TAllResponses]; export type SafeApiResponse<TEndpoint> = TEndpoint extends { response: infer TSuccess; responses: infer TResponses } ? TResponses extends Record<string, unknown> ? TypedApiResponse<TSuccess, TResponses> - : { ok: true; status: number; data: TSuccess } + : Omit<Response, "ok" | "status" | "json"> & { + ok: true; + status: number; + data: TSuccess; + json: () => Promise<TSuccess>; + } : TEndpoint extends { response: infer TSuccess } - ? { ok: true; status: number; data: TSuccess } + ? Omit<Response, "ok" | "status" | "json"> & { + ok: true; + status: number; + data: TSuccess; + json: () => Promise<TSuccess>; + } : never; type RequiredKeys<T> = { [P in keyof T]-?: undefined extends T[P] ? never : P; }[keyof T]; @@ -629,16 +644,21 @@ const { withResponse: _, ...fetchParams } = requestParams || {}; if (withResponse) { return this.fetcher("put", this.baseUrl + path, Object.keys(fetchParams).length ? fetchParams : undefined).then( async (response) => { + // Parse the response data const data = await this.parseResponse(response); - if (response.ok) { - return { ok: true, status: response.status, data }; - } else { - return { ok: false, status: response.status, error: data }; - } + + // Override properties while keeping the original Response object + const typedResponse = Object.assign(response, { + ok: response.ok, + status: response.status, + data: data, + json: () => Promise.resolve(data), + }); + return typedResponse; }, ); } else { return this.fetcher("put", this.baseUrl + path, requestParams).then((response) => this.parseResponse(response), @@ -669,16 +689,21 @@ const { withResponse: _, ...fetchParams } = requestParams || {}; if (withResponse) { return this.fetcher("post", this.baseUrl + path, Object.keys(fetchParams).length ? fetchParams : un
tests/generate-runtime.test.ts > generate-runtime-petstore > generate none: packages/typed-openapi/tests/generate-runtime.test.ts#L24
Error: Snapshot `generate-runtime-petstore > generate none 1` mismatched - Expected + Received @@ -339,51 +339,66 @@ // Error handling types export type TypedApiResponse< TSuccess, TAllResponses extends Record<string | number, unknown> = {}, > = keyof TAllResponses extends never - ? { + ? Omit<Response, "ok" | "status" | "json"> & { ok: true; status: number; data: TSuccess; + json: () => Promise<TSuccess>; } : { [K in keyof TAllResponses]: K extends string ? K extends `${infer TStatusCode extends number}` ? TStatusCode extends StatusCode - ? { + ? Omit<Response, "ok" | "status" | "json"> & { ok: true; status: TStatusCode; - data: TAllResponses[K]; + data: TSuccess; + json: () => Promise<TSuccess>; } - : { + : Omit<Response, "ok" | "status" | "json"> & { ok: false; status: TStatusCode; - error: TAllResponses[K]; + data: TAllResponses[K]; + json: () => Promise<TAllResponses[K]>; } : never : K extends number ? K extends StatusCode - ? { + ? Omit<Response, "ok" | "status" | "json"> & { ok: true; status: K; - data: TAllResponses[K]; + data: TSuccess; + json: () => Promise<TSuccess>; } - : { + : Omit<Response, "ok" | "status" | "json"> & { ok: false; status: K; - error: TAllResponses[K]; + data: TAllResponses[K]; + json: () => Promise<TAllResponses[K]>; } : never; }[keyof TAllResponses]; export type SafeApiResponse<TEndpoint> = TEndpoint extends { response: infer TSuccess; responses: infer TResponses } ? TResponses extends Record<string, unknown> ? TypedApiResponse<TSuccess, TResponses> - : { ok: true; status: number; data: TSuccess } + : Omit<Response, "ok" | "status" | "json"> & { + ok: true; + status: number; + data: TSuccess; + json: () => Promise<TSuccess>; + } : TEndpoint extends { response: infer TSuccess } - ? { ok: true; status: number; data: TSuccess } + ? Omit<Response, "ok" | "status" | "json"> & { + ok: true; + status: number; + data: TSuccess; + json: () => Promise<TSuccess>; + } : never; type RequiredKeys<T> = { [P in keyof T]-?: undefined extends T[P] ? never : P; }[keyof T]; @@ -433,16 +448,21 @@ const { withResponse: _, ...fetchParams } = requestParams || {}; if (withResponse) { return this.fetcher("put", this.baseUrl + path, Object.keys(fetchParams).length ? fetchParams : undefined).then( async (response) => { + // Parse the response data const data = await this.parseResponse(response); - if (response.ok) { - return { ok: true, status: response.status, data }; - } else { - return { ok: false, status: response.status, error: data }; - } + + // Override properties while keeping the original Response object + const typedResponse = Object.assign(response, { + ok: response.ok, + status: response.status, + data: data, + json: () => Promise.resolve(data), + }); + return typedResponse; }, ); } else { return this.fetcher("put", this.baseUrl + path, requestParams).then((response) => this.parseResponse(response), @@ -473,16 +493,21 @@ const { withResponse: _, ...fetchParams } = requestParams || {}; if (withResponse) { return this.fetcher("post", this.baseUrl + path, Object.keys(fetchParams).length ? fetchParams : undef
tests/generate-runtime.test.ts > generate-runtime-petstore > generate io-ts: packages/typed-openapi/tests/generate-runtime.test.ts#L24
Error: Snapshot `generate-runtime-petstore > generate io-ts 1` mismatched - Expected + Received @@ -507,51 +507,66 @@ // Error handling types export type TypedApiResponse< TSuccess, TAllResponses extends Record<string | number, unknown> = {}, > = keyof TAllResponses extends never - ? { + ? Omit<Response, "ok" | "status" | "json"> & { ok: true; status: number; data: TSuccess; + json: () => Promise<TSuccess>; } : { [K in keyof TAllResponses]: K extends string ? K extends `${infer TStatusCode extends number}` ? TStatusCode extends StatusCode - ? { + ? Omit<Response, "ok" | "status" | "json"> & { ok: true; status: TStatusCode; - data: TAllResponses[K]; + data: TSuccess; + json: () => Promise<TSuccess>; } - : { + : Omit<Response, "ok" | "status" | "json"> & { ok: false; status: TStatusCode; - error: TAllResponses[K]; + data: TAllResponses[K]; + json: () => Promise<TAllResponses[K]>; } : never : K extends number ? K extends StatusCode - ? { + ? Omit<Response, "ok" | "status" | "json"> & { ok: true; status: K; - data: TAllResponses[K]; + data: TSuccess; + json: () => Promise<TSuccess>; } - : { + : Omit<Response, "ok" | "status" | "json"> & { ok: false; status: K; - error: TAllResponses[K]; + data: TAllResponses[K]; + json: () => Promise<TAllResponses[K]>; } : never; }[keyof TAllResponses]; export type SafeApiResponse<TEndpoint> = TEndpoint extends { response: infer TSuccess; responses: infer TResponses } ? TResponses extends Record<string, unknown> ? TypedApiResponse<TSuccess, TResponses> - : { ok: true; status: number; data: TSuccess } + : Omit<Response, "ok" | "status" | "json"> & { + ok: true; + status: number; + data: TSuccess; + json: () => Promise<TSuccess>; + } : TEndpoint extends { response: infer TSuccess } - ? { ok: true; status: number; data: TSuccess } + ? Omit<Response, "ok" | "status" | "json"> & { + ok: true; + status: number; + data: TSuccess; + json: () => Promise<TSuccess>; + } : never; type RequiredKeys<T> = { [P in keyof T]-?: undefined extends T[P] ? never : P; }[keyof T]; @@ -601,16 +616,21 @@ const { withResponse: _, ...fetchParams } = requestParams || {}; if (withResponse) { return this.fetcher("put", this.baseUrl + path, Object.keys(fetchParams).length ? fetchParams : undefined).then( async (response) => { + // Parse the response data const data = await this.parseResponse(response); - if (response.ok) { - return { ok: true, status: response.status, data }; - } else { - return { ok: false, status: response.status, error: data }; - } + + // Override properties while keeping the original Response object + const typedResponse = Object.assign(response, { + ok: response.ok, + status: response.status, + data: data, + json: () => Promise.resolve(data), + }); + return typedResponse; }, ); } else { return this.fetcher("put", this.baseUrl + path, requestParams).then((response) => this.parseResponse(response), @@ -641,16 +661,21 @@ const { withResponse: _, ...fetchParams } = requestParams || {}; if (withResponse) { return this.fetcher("post", this.baseUrl + path, Object.keys(fetchParams).length ? fetchParams : unde
tests/generate-runtime.test.ts > generate-runtime-petstore > generate arktype: packages/typed-openapi/tests/generate-runtime.test.ts#L24
Error: Snapshot `generate-runtime-petstore > generate arktype 1` mismatched - Expected + Received @@ -508,51 +508,66 @@ // Error handling types export type TypedApiResponse< TSuccess, TAllResponses extends Record<string | number, unknown> = {}, > = keyof TAllResponses extends never - ? { + ? Omit<Response, "ok" | "status" | "json"> & { ok: true; status: number; data: TSuccess; + json: () => Promise<TSuccess>; } : { [K in keyof TAllResponses]: K extends string ? K extends `${infer TStatusCode extends number}` ? TStatusCode extends StatusCode - ? { + ? Omit<Response, "ok" | "status" | "json"> & { ok: true; status: TStatusCode; - data: TAllResponses[K]; + data: TSuccess; + json: () => Promise<TSuccess>; } - : { + : Omit<Response, "ok" | "status" | "json"> & { ok: false; status: TStatusCode; - error: TAllResponses[K]; + data: TAllResponses[K]; + json: () => Promise<TAllResponses[K]>; } : never : K extends number ? K extends StatusCode - ? { + ? Omit<Response, "ok" | "status" | "json"> & { ok: true; status: K; - data: TAllResponses[K]; + data: TSuccess; + json: () => Promise<TSuccess>; } - : { + : Omit<Response, "ok" | "status" | "json"> & { ok: false; status: K; - error: TAllResponses[K]; + data: TAllResponses[K]; + json: () => Promise<TAllResponses[K]>; } : never; }[keyof TAllResponses]; export type SafeApiResponse<TEndpoint> = TEndpoint extends { response: infer TSuccess; responses: infer TResponses } ? TResponses extends Record<string, unknown> ? TypedApiResponse<TSuccess, TResponses> - : { ok: true; status: number; data: TSuccess } + : Omit<Response, "ok" | "status" | "json"> & { + ok: true; + status: number; + data: TSuccess; + json: () => Promise<TSuccess>; + } : TEndpoint extends { response: infer TSuccess } - ? { ok: true; status: number; data: TSuccess } + ? Omit<Response, "ok" | "status" | "json"> & { + ok: true; + status: number; + data: TSuccess; + json: () => Promise<TSuccess>; + } : never; type RequiredKeys<T> = { [P in keyof T]-?: undefined extends T[P] ? never : P; }[keyof T]; @@ -602,16 +617,21 @@ const { withResponse: _, ...fetchParams } = requestParams || {}; if (withResponse) { return this.fetcher("put", this.baseUrl + path, Object.keys(fetchParams).length ? fetchParams : undefined).then( async (response) => { + // Parse the response data const data = await this.parseResponse(response); - if (response.ok) { - return { ok: true, status: response.status, data }; - } else { - return { ok: false, status: response.status, error: data }; - } + + // Override properties while keeping the original Response object + const typedResponse = Object.assign(response, { + ok: response.ok, + status: response.status, + data: data, + json: () => Promise.resolve(data), + }); + return typedResponse; }, ); } else { return this.fetcher("put", this.baseUrl + path, requestParams).then((response) => this.parseResponse(response), @@ -642,16 +662,21 @@ const { withResponse: _, ...fetchParams } = requestParams || {}; if (withResponse) { return this.fetcher("post", this.baseUrl + path, Object.keys(fetchParams).length ? fetchParams : un