Skip to content

Commit 747611b

Browse files
committed
Fix missing parameters
1 parent 2d3679a commit 747611b

File tree

4 files changed

+68
-2
lines changed

4 files changed

+68
-2
lines changed

.changeset/fluffy-hounds-occur.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"openapi-typescript": patch
3+
---
4+
5+
Fix missing params when they have same name, different location

packages/openapi-typescript/src/transform/parameter-object-array.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export default function transformParameterObjectArray(parameterObjectArray: (Par
2020
output.push(
2121
indent(
2222
`${key}: ${transformParameterObject(node, {
23-
path: `${path}/${node.name}`,
23+
path: `${path}/${node.in}/${node.name}`,
2424
ctx: { ...ctx, indentLv: ctx.indentLv + 1 },
2525
})};`,
2626
ctx.indentLv,

packages/openapi-typescript/src/transform/path-item-object.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export default function transformPathItemObject(pathItem: PathItemObject, { path
2828
// important: OperationObject parameters come last, and will override any conflicts with PathItem parameters
2929
for (const parameter of [...(pathItem.parameters ?? []), ...(operationObject.parameters ?? [])]) {
3030
// note: the actual key doesn’t matter here, as long as it can match between PathItem and OperationObject
31-
keyedParameters["$ref" in parameter ? parameter.$ref : parameter.name] = parameter;
31+
keyedParameters["$ref" in parameter ? parameter.$ref : `${parameter.in}/${parameter.name}`] = parameter;
3232
}
3333
}
3434

packages/openapi-typescript/test/path-item-object.test.ts

+61
Original file line numberDiff line numberDiff line change
@@ -174,4 +174,65 @@ describe("Path Item Object", () => {
174174
get: components["schemas"]["GetUserOperation"]
175175
}`);
176176
});
177+
178+
it("operations with parameters with same name, different location", () => {
179+
const operations: GlobalContext["operations"] = {};
180+
const schema: PathItemObject = {
181+
get: {
182+
operationId: "getUserById",
183+
summary: "Returns a user by ID.",
184+
parameters: [
185+
{
186+
in: "path",
187+
name: "user_id",
188+
required: true,
189+
schema: { type: "string" },
190+
},
191+
{
192+
in: "query",
193+
name: "user_id",
194+
schema: { type: "string" },
195+
},
196+
],
197+
responses: {
198+
"200": {
199+
description: "OK",
200+
content: {
201+
"application/json": {
202+
schema: { type: "string" },
203+
},
204+
},
205+
},
206+
},
207+
},
208+
};
209+
const generated = transformPathItemObject(schema, { ...options, ctx: { ...options.ctx, operations } });
210+
expect(generated).toBe(`{
211+
/** Returns a user by ID. */
212+
get: operations["getUserById"];
213+
}`);
214+
expect(operations).toEqual({
215+
getUserById: {
216+
comment: "/** Returns a user by ID. */",
217+
operationType: `{
218+
parameters: {
219+
query?: {
220+
user_id?: string;
221+
};
222+
path: {
223+
user_id: string;
224+
};
225+
};
226+
responses: {
227+
/** @description OK */
228+
200: {
229+
content: {
230+
"application/json": string;
231+
};
232+
};
233+
};
234+
}`,
235+
},
236+
});
237+
});
177238
});

0 commit comments

Comments
 (0)