Skip to content

Commit 4709201

Browse files
authored
Improved Hey API configuration (#33)
1 parent d0b3369 commit 4709201

3 files changed

Lines changed: 20 additions & 2 deletions

File tree

src/openapi-ts.config.mts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,14 @@ export default defineConfig(
7777
// Use PascalCase for schema names
7878
case: "PascalCase",
7979

80+
dates: {
81+
// Allow datetimes without timezone
82+
local: true,
83+
84+
// Allow datetimes with offset timezone
85+
offset: true,
86+
},
87+
8088
definitions: {
8189
name: "{{name}}Schema",
8290
},

src/src/common/apis/icanhazdadjoke/client/clnt.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,10 +182,16 @@ export const createClient = (config: Config = {}): Client => {
182182
case "arrayBuffer":
183183
case "blob":
184184
case "formData":
185-
case "json":
186185
case "text":
187186
data = await response[parseAs]();
188187
break;
188+
case "json": {
189+
// Some servers return 200 with no Content-Length and empty body.
190+
// response.json() would throw; read as text and parse if non-empty.
191+
const text = await response.text();
192+
data = text ? JSON.parse(text) : {};
193+
break;
194+
}
189195
case "stream":
190196
return opts.responseStyle === "data"
191197
? response.body
@@ -267,6 +273,10 @@ export const createClient = (config: Config = {}): Client => {
267273
}
268274
return request;
269275
},
276+
serializedBody: getValidRequestBody(opts) as
277+
| BodyInit
278+
| null
279+
| undefined,
270280
url,
271281
});
272282
};

src/src/common/apis/icanhazdadjoke/schemas.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// This file is auto-generated by @hey-api/openapi-ts
22

3-
import { z } from "zod";
3+
import * as z from "zod";
44

55
/**
66
* Success response payload for getting a random joke

0 commit comments

Comments
 (0)