Skip to content

Commit 9682ec1

Browse files
committed
Sync open source content 🐝 (from 9b81e41ec8430ce90771df3e6663804c2580bc56)
1 parent 4e5a8c1 commit 9682ec1

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

docs/speakeasy-reference/extensions.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { Table } from "@/mdx/components";
1111
<Table
1212
data={[
1313
{ extension: "x-speakeasy-name-override", description: "Use it globally to change method names or inline to change the name of a method, parameter, or class." },
14+
{ extension: "x-speakeasy-model-namespace", description: "Place generated models in a specific namespace to avoid naming conflicts when merging multiple OpenAPI documents with identically named schemas." },
1415
{ extension: "x-speakeasy-group", description: "Defines custom namespaces when adding this property to any operation in the OpenAPI spec. If added, the tags for that method will be ignored" },
1516
{ extension: "x-speakeasy-ignore", description: "Exclude certain methods from your SDK with this extension." },
1617
{ extension: "x-speakeasy-include", description: "Can be used to force the generation of an unused or orphaned schema from the `components` section inside the main document." },

docs/speakeasy-reference/workflow-file.mdx

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,70 @@ authentication may need to be provided.
9999
# .... more openapi documents can be added here
100100
```
101101

102+
### Model namespace
103+
104+
When merging multiple OpenAPI documents, schema components with the same name can cause naming conflicts in generated code. The `modelNamespace` option allows each input document to specify a namespace for its schema components, ensuring unique names in the merged output.
105+
106+
```yaml
107+
sources:
108+
merged-api:
109+
inputs:
110+
- location: service-a.yaml
111+
modelNamespace: serviceA
112+
- location: service-b.yaml
113+
modelNamespace: serviceB
114+
```
115+
116+
When `modelNamespace` is specified, the merge process automatically adds `x-speakeasy-name-override` and `x-speakeasy-model-namespace` extensions to each schema component from that input. This preserves the original schema name for serialization while placing the generated model in a separate namespace to avoid conflicts.
117+
118+
For example, if both `service-a.yaml` and `service-b.yaml` define a `Pet` schema:
119+
120+
```yaml
121+
# service-a.yaml
122+
components:
123+
schemas:
124+
Pet:
125+
type: object
126+
properties:
127+
name:
128+
type: string
129+
```
130+
131+
```yaml
132+
# service-b.yaml
133+
components:
134+
schemas:
135+
Pet:
136+
type: object
137+
properties:
138+
species:
139+
type: string
140+
```
141+
142+
The merged output will contain both schemas with unique names and namespace extensions:
143+
144+
```yaml
145+
# merged.yaml
146+
components:
147+
schemas:
148+
serviceA_Pet:
149+
x-speakeasy-name-override: Pet
150+
x-speakeasy-model-namespace: serviceA
151+
type: object
152+
properties:
153+
name:
154+
type: string
155+
serviceB_Pet:
156+
x-speakeasy-name-override: Pet
157+
x-speakeasy-model-namespace: serviceB
158+
type: object
159+
properties:
160+
species:
161+
type: string
162+
```
163+
164+
For more granular control over which schemas belong to which namespace, apply the `x-speakeasy-model-namespace` extension directly to individual schemas in the OpenAPI document instead of using `modelNamespace` in the workflow file.
165+
102166
### Transformations
103167

104168
Sources can include transformations that modify the OpenAPI document before it's used to generate SDKs. Transformations are applied in order after merging inputs and applying overlays.

0 commit comments

Comments
 (0)