You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/speakeasy-reference/generation/ts-config.mdx
+72-21Lines changed: 72 additions & 21 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -75,19 +75,30 @@ typescript:
75
75
]}
76
76
/>
77
77
78
-
## Additional scripts
78
+
## Package scripts and examples
79
79
80
80
```yml
81
81
typescript:
82
82
additionalScripts:
83
83
format: "prettier --write src"
84
84
docs: "typedoc --out docs src"
85
85
custom-test: "vitest run --coverage"
86
+
generateExamples: true
87
+
compileCommand: ["npm", "run", "build"]
88
+
usageSDKInit: "new Petstore({})"
89
+
usageSDKInitImports:
90
+
- package: "@petstore/sdk"
91
+
import: "Petstore"
92
+
type: "packageImport"
86
93
```
87
94
88
95
<Table
89
96
data={[
90
-
{ name: "additionalScripts", required: "false", default: "{}", description: "Custom npm scripts to add to the `package.json` file. Scripts with the same name as default scripts will override them." }
97
+
{ name: "additionalScripts", required: "false", default: "{}", description: "Custom npm scripts to add to the `package.json` file. Scripts with the same name as default scripts will override them." },
98
+
{ name: "generateExamples", required: "false", default: "true", description: "Whether to generate example files in an examples directory demonstrating SDK usage." },
99
+
{ name: "compileCommand", required: "false", default: "N/A", description: "The command to use for compiling the SDK. Must be an array where the first element is the command and the rest are arguments." },
100
+
{ name: "usageSDKInit", required: "false", default: "N/A", description: "The SDK initialization code to use in usage examples (e.g., `new Petstore({})`)." },
101
+
{ name: "usageSDKInitImports", required: "false", default: "[]", description: "Array of imports to add when `usageSDKInit` is configured. Each import should have `package`, `import`, and optionally `type` fields (options: `typeImport`, `packageImport`, `aliasImport`)." }
91
102
]}
92
103
columns={[
93
104
{ key: "name", header: "Name" },
@@ -149,14 +160,15 @@ typescript:
149
160
```yml
150
161
typescript:
151
162
maxMethodParams: 3
152
-
methodArguments: "require-security-and-request"
163
+
flatteningOrder: "parameters-first"
164
+
methodArguments: "infer-optional-args"
153
165
```
154
166
155
167
<Table
156
168
data={[
157
-
{ name: "[maxMethodParams](/docs/customize/methods)", required: "false", default: "0", description: "Maximum number of parameters before an input object is created. `0` means input objects are always used." },
158
-
{ name: "[flatteningOrder](/docs/customize/methods#configuring-method-signatures)", required: "false", default: "parameters-first or body-first", description: "Determines the ordering of method arguments when flattening parameters and body fields." },
159
-
{ name: "methodArguments", required: "false", default: "require-security-and-request", description: "Determines how arguments for SDK methods are generated." }
169
+
{ name: "[maxMethodParams](/docs/sdks/customize/methods)", required: "false", default: "0", description: "Maximum number of parameters before an input object is created. `0` means input objects are always used." },
170
+
{ name: "[flatteningOrder](/docs/sdks/customize/methods#configuring-method-signatures)", required: "false", default: "parameters-first", description: "Determines the ordering of method arguments when flattening parameters and body fields. Options: `parameters-first` or `body-first`." },
171
+
{ name: "methodArguments", required: "false", default: "infer-optional-args", description: "Determines how arguments for SDK methods are generated. If set to `infer-optional-args`, the method argument will be optional when all parameters and the request body are optional. Options: `infer-optional-args` or `require-security-and-request`." }
160
172
]}
161
173
columns={[
162
174
{ key: "name", header: "Name" },
@@ -197,8 +209,8 @@ typescript:
197
209
198
210
<Table
199
211
data={[
200
-
{ name: "[useIndexModules](/docs/customize/typescript/disabling-barrel-files)", required: "false", default: "true", description: "Controls generation of index modules (`index.ts`). Setting to `false` improves tree-shaking and build performance by avoiding barrel files." },
201
-
{ name: "[moduleFormat](/docs/customize/typescript/configuring-module-format)", required: "false", default: "commonjs", description: "Sets the module format to use when compiling the SDK (`commonjs`, `esm`, or `dual`). Using `dual` provides optimal compatibility while enabling modern bundler optimizations." }
212
+
{ name: "[useIndexModules](/docs/sdks/customize/typescript/disabling-barrel-files)", required: "false", default: "true", description: "Controls generation of index modules (`index.ts`). Setting to `false` improves tree-shaking and build performance by avoiding barrel files." },
213
+
{ name: "[moduleFormat](/docs/sdks/customize/typescript/configuring-module-format)", required: "false", default: "dual", description: "Sets the module format to use when compiling the SDK. Options: `commonjs`, `esm`, or `dual`. Using `dual` provides optimal compatibility while enabling modern bundler optimizations." }
202
214
]}
203
215
columns={[
204
216
{ key: "name", header: "Name" },
@@ -257,16 +269,26 @@ typescript:
257
269
/>
258
270
259
271
260
-
## Property naming configuration
272
+
## Error and response handling
261
273
262
274
```yml
263
275
typescript:
264
-
modelPropertyCasing: "camel"
276
+
clientServerStatusCodesAsErrors: true
277
+
responseFormat: "flat"
278
+
enumFormat: "union"
279
+
defaultErrorName: "SDKError"
280
+
baseErrorName: "HTTPError"
281
+
acceptHeaderEnum: false
265
282
```
266
283
267
284
<Table
268
285
data={[
269
-
{ property: "modelPropertyCasing", description: "Controls the casing of model property names in generated TypeScript types. Options: `camel` (camelCase) or `snake` (snake_case).", type: "string", default: "camel" }
286
+
{ property: "[responseFormat](/docs/sdks/customize/responses/responses)", description: "Defines how responses are structured. Options: `envelope`, `envelope-http`, or `flat`.", type: "string", default: "flat" },
287
+
{ property: "enumFormat", description: "Determines how enums are generated. Options: `enum` (TypeScript enums) or `union` (union types).", type: "string", default: "union" },
288
+
{ property: "clientServerStatusCodesAsErrors", description: "Treats `4XX` and `5XX` status codes as errors. Set to `false` to treat them as normal responses.", type: "boolean", default: "true" },
289
+
{ property: "defaultErrorName", description: "The name of the fallback error class if no more specific error class is matched. Must start with a capital letter and contain only letters and numbers.", type: "string", default: "SDKError" },
290
+
{ property: "baseErrorName", description: "The name of the base error class used for HTTP error responses. Must start with a capital letter and contain only letters and numbers.", type: "string", default: "HTTPError" },
291
+
{ property: "acceptHeaderEnum", description: "Whether to generate TypeScript enums for controlling the return content type of SDK methods when multiple accept types are available.", type: "boolean", default: "false" }
270
292
]}
271
293
columns={[
272
294
{ key: "property", header: "Property" },
@@ -276,20 +298,30 @@ typescript:
276
298
]}
277
299
/>
278
300
279
-
## Error and response handling
301
+
## Model validation and serialization
280
302
281
303
```yml
282
304
typescript:
283
-
clientServerStatusCodesAsErrors: false
284
-
responseFormat: "envelope-http"
285
-
enumFormat: "union"
305
+
jsonpath: "rfc9535"
306
+
zodVersion: "v4-mini"
307
+
constFieldsAlwaysOptional: false
308
+
modelPropertyCasing: "camel"
309
+
unionStrategy: "populated-fields"
310
+
laxMode: "lax"
311
+
alwaysIncludeInboundAndOutbound: false
312
+
exportZodModelNamespace: false
286
313
```
287
314
288
-
<Table
315
+
<Table
289
316
data={[
290
-
{ property: "[responseFormat](/docs/customize/responses/responses)", description: "Defines how responses are structured. Options: `envelope`, `envelope-http`, or `flat`.", type: "string", default: "envelope-http" },
291
-
{ property: "enumFormat", description: "Determines how enums are generated. Options: `enum` (TypeScript enums) or `union` (union types).", type: "string", default: "union" },
292
-
{ property: "clientServerStatusCodesAsErrors", description: "Treats `4XX` and `5XX` status codes as errors. Set to `false` to treat them as normal responses.", type: "boolean", default: "true" }
317
+
{ property: "jsonpath", description: "Sets the JSONPath implementation to use. Options: `legacy` (deprecated) or `rfc9535` (recommended). The `rfc9535` option follows the JSONPath specification and should be preferred for new SDKs.", type: "string", default: "rfc9535" },
318
+
{ property: "zodVersion", description: "The version of Zod to use for schema validation. Options: `v3`, `v4`, or `v4-mini`.", type: "string", default: "v4-mini" },
319
+
{ property: "constFieldsAlwaysOptional", description: "Whether const fields should be treated as optional in TypeScript types and schemas regardless of OpenAPI spec requirements. When `true` (legacy behavior), all const fields are optional. When `false` (recommended), const fields respect the OpenAPI spec's required array.", type: "boolean", default: "false" },
320
+
{ property: "[modelPropertyCasing](/docs/sdks/customize/typescript/property-naming)", description: "Property naming convention to use. Options: `camel` (converts to camelCase) or `snake` (converts to snake_case).", type: "string", default: "camel" },
321
+
{ property: "unionStrategy", description: "Strategy for deserializing union types. Options: `left-to-right` (tries each type in order and returns the first valid match) or `populated-fields` (tries all types and returns the one with the most matching fields, including optional fields).", type: "string", default: "populated-fields" },
322
+
{ property: "laxMode", description: "Controls validation strictness. When set to `lax`, required fields will be coerced to their zero value (e.g., a missing required string will fallback to `\"\"`). Lax mode also applies other coercions (e.g., boolean schemas will accept the string `\"true\"`). Lax mode only applies to deserialization of responses. When `laxMode` is enabled, `unionStrategy` is automatically set to `populated-fields`. Options: `lax` or `strict`.", type: "string", default: "lax" },
323
+
{ property: "alwaysIncludeInboundAndOutbound", description: "Whether to always include both inbound and outbound schemas for all types regardless of usage.", type: "boolean", default: "false" },
324
+
{ property: "exportZodModelNamespace", description: "Whether to export the deprecated `$` namespace containing `inboundSchema` and `outboundSchema` aliases.", type: "boolean", default: "false" }
293
325
]}
294
326
columns={[
295
327
{ key: "property", header: "Property" },
@@ -303,12 +335,31 @@ typescript:
303
335
304
336
```yml
305
337
typescript:
306
-
sseFlatResponse: true
338
+
sseFlatResponse: false
339
+
```
340
+
341
+
<Table
342
+
data={[
343
+
{ property: "[sseFlatResponse](/docs/sdks/customize/runtime/server-sent-events)", description: "Whether to flatten SSE (Server-Sent Events) responses by extracting the `data` field from wrapper models, providing direct access to the event data instead of the wrapper object.", type: "boolean", default: "false" }
344
+
]}
345
+
columns={[
346
+
{ key: "property", header: "Property" },
347
+
{ key: "description", header: "Description" },
348
+
{ key: "type", header: "Type" },
349
+
{ key: "default", header: "Default" }
350
+
]}
351
+
/>
352
+
353
+
## Advanced features
354
+
355
+
```yml
356
+
typescript:
357
+
enableReactQuery: false
307
358
```
308
359
309
360
<Table
310
361
data={[
311
-
{ property: "sseFlatResponse", description: "When enabled, hoists the `data` field content to the top level for server-sent events, eliminating the need to destructure data from yielded items. Consumers can directly access the data without additional parsing.", type: "boolean", default: "true" }
0 commit comments