Skip to content

Commit 165eeca

Browse files
committed
Sync open source content 🐝 (from c09ec6ca99d85a6c1af5608ccdc7b4d22b8d8e2c)
1 parent c29932d commit 165eeca

File tree

1 file changed

+72
-21
lines changed

1 file changed

+72
-21
lines changed

docs/speakeasy-reference/generation/ts-config.mdx

Lines changed: 72 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -75,19 +75,30 @@ typescript:
7575
]}
7676
/>
7777

78-
## Additional scripts
78+
## Package scripts and examples
7979

8080
```yml
8181
typescript:
8282
additionalScripts:
8383
format: "prettier --write src"
8484
docs: "typedoc --out docs src"
8585
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"
8693
```
8794

8895
<Table
8996
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`)." }
91102
]}
92103
columns={[
93104
{ key: "name", header: "Name" },
@@ -149,14 +160,15 @@ typescript:
149160
```yml
150161
typescript:
151162
maxMethodParams: 3
152-
methodArguments: "require-security-and-request"
163+
flatteningOrder: "parameters-first"
164+
methodArguments: "infer-optional-args"
153165
```
154166

155167
<Table
156168
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`." }
160172
]}
161173
columns={[
162174
{ key: "name", header: "Name" },
@@ -197,8 +209,8 @@ typescript:
197209

198210
<Table
199211
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." }
202214
]}
203215
columns={[
204216
{ key: "name", header: "Name" },
@@ -257,16 +269,26 @@ typescript:
257269
/>
258270

259271

260-
## Property naming configuration
272+
## Error and response handling
261273

262274
```yml
263275
typescript:
264-
modelPropertyCasing: "camel"
276+
clientServerStatusCodesAsErrors: true
277+
responseFormat: "flat"
278+
enumFormat: "union"
279+
defaultErrorName: "SDKError"
280+
baseErrorName: "HTTPError"
281+
acceptHeaderEnum: false
265282
```
266283

267284
<Table
268285
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" }
270292
]}
271293
columns={[
272294
{ key: "property", header: "Property" },
@@ -276,20 +298,30 @@ typescript:
276298
]}
277299
/>
278300

279-
## Error and response handling
301+
## Model validation and serialization
280302

281303
```yml
282304
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
286313
```
287314

288-
<Table
315+
<Table
289316
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" }
293325
]}
294326
columns={[
295327
{ key: "property", header: "Property" },
@@ -303,12 +335,31 @@ typescript:
303335

304336
```yml
305337
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
307358
```
308359

309360
<Table
310361
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" }
362+
{ property: "[enableReactQuery](/docs/sdks/customize/typescript/react-hooks)", description: "Generate React hooks using TanStack Query.", type: "boolean", default: "false" }
312363
]}
313364
columns={[
314365
{ key: "property", header: "Property" },

0 commit comments

Comments
 (0)