Skip to content

Commit 170072e

Browse files
committed
Sync open source content 🐝 (from 0e3b439710632d865d36af29459a4bf056c97d56)
1 parent 74a74a1 commit 170072e

2 files changed

Lines changed: 31 additions & 1 deletion

File tree

β€Ždocs/sdks/customize/data-model/oneof-schemas.mdxβ€Ž

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,35 @@ Will result in these response types:
456456
]}
457457
/>
458458

459+
## Discriminator display names
460+
461+
When a `oneOf` schema uses a `discriminator` with mapping keys that contain special characters (e.g., `$login`, `$challenge`), the generated SDK identifiers can become unwieldy. For example, a `$login` key produces a Go function named `CreateRiskDollarLogin` because the `$` character is sanitized to `Dollar`.
462+
463+
The `x-speakeasy-discriminator` extension provides clean display names for discriminator mapping keys while preserving the original values for JSON serialization.
464+
465+
```yaml
466+
components:
467+
schemas:
468+
RiskAssessment:
469+
oneOf:
470+
- $ref: "#/components/schemas/LoginRiskRequest"
471+
- $ref: "#/components/schemas/ChallengeRiskRequest"
472+
discriminator:
473+
propertyName: type
474+
mapping:
475+
$login: "#/components/schemas/LoginRiskRequest"
476+
$challenge: "#/components/schemas/ChallengeRiskRequest"
477+
x-speakeasy-discriminator:
478+
$login: login
479+
$challenge: challenge
480+
```
481+
482+
In this example, the generated Go SDK uses `CreateRiskAssessmentLogin` and `CreateRiskAssessmentChallenge` as function names instead of `CreateRiskAssessmentDollarLogin` and `CreateRiskAssessmentDollarChallenge`. The wire values (`"$login"` and `"$challenge"`) remain unchanged during JSON serialization.
483+
484+
The extension maps each discriminator mapping key to a display name. Only keys that need renaming must be included. Any key not listed in `x-speakeasy-discriminator` retains its original name for identifier generation.
485+
486+
This extension is supported in Go, Terraform, and mock server targets.
487+
459488
### Splitting `oneOf` schema types
460489

461490
By defining similar operations with aligned but different schemas, you can apply `x-speakeasy-type-override: any` for untyped operations and use `oneOf` to define stricter types in others. This allows you to use methods like `DoSomething(StrictObject{...})` alongside `DoSomethingUntyped({...})`, providing flexibility across SDK methods based on the required schema type.

β€Ždocs/speakeasy-reference/extensions.mdxβ€Ž

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ import { Table } from "@/mdx/components";
3535
{ extension: "x-speakeasy-mcp", description: "Customize how API operations are exposed as MCP tools with properties for disabled, name, title, scopes, description, and behavioral hints (destructiveHint, idempotentHint, openWorldHint, readOnlyHint)." },
3636
{ extension: "x-speakeasy-overridable-scopes", description: "Allow end users to override OAuth 2.0 scopes at runtime for the `clientCredentials` flow by adding an optional `scopes` field to the security model." },
3737
{ extension: "x-speakeasy-param-encoding-override", description: "When set with a value of `allowReserved`, path parameters will appear in a request URL with reserved characters `:/?#[]@!$&'()*+,;=` unencoded." },
38-
{ extension: "x-speakeasy-token-endpoint-additional-properties", description: "Define additional properties for OAuth token endpoint requests, allowing generated SDKs to handle custom fields like audience parameters." }
38+
{ extension: "x-speakeasy-token-endpoint-additional-properties", description: "Define additional properties for OAuth token endpoint requests, allowing generated SDKs to handle custom fields like audience parameters." },
39+
{ extension: "x-speakeasy-discriminator", description: "Provide clean display names for discriminator mapping keys that contain special characters, improving generated identifier names while preserving wire values." }
3940
]}
4041
columns={[
4142
{ key: "extension", header: "Extension" },

0 commit comments

Comments
Β (0)