Skip to content

Commit ce1d05d

Browse files
committed
Fix param
1 parent 863cd5f commit ce1d05d

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

src/transform/operation-object.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,10 @@ export default function transformOperationObject(
7171
else if (p.$ref) {
7272
const parts = parseTSIndex(p.$ref);
7373
const paramI = parts.indexOf("parameters");
74-
if (paramI === -1 || parts[paramI + 1] !== paramIn || !parts[paramI + 2]) continue;
74+
// note: parameters can share names in different parts of the `in` key. `partsParamIn` makes sure we’re not
75+
// referencing the wrong parameter with the same name but a different `in`
76+
const partsParamIn = parts.find((p) => p === "query" || p === "header" || p === "path" || p === "cookie");
77+
if (paramI === -1 || (partsParamIn && partsParamIn !== paramIn)) continue;
7578
const key = parts.pop() as string;
7679
const index = makeTSIndex(parts);
7780
if (!refs[index]) refs[index] = [key];

src/types.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ export interface ParameterObject extends Extensable {
238238
/** Determines whether the parameter value SHOULD allow reserved characters, as defined by [RFC3986] `:/?#[]@!$&'()*+,;=` to be included without percent-encoding. This property only applies to parameters with an `in` value of `query`. The default value is `false`. */
239239
allowReserved?: boolean;
240240
/** The schema defining the type used for the parameter. */
241-
schema?: SchemaObject;
241+
schema?: SchemaObject | ReferenceObject;
242242
/** Example of the parameter’s potential value. */
243243
example?: any;
244244
/** Examples of the parameter’s potential value. */

test/path-item-object.test.ts

+7
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ describe("Path Item Object", () => {
5252
404: { $ref: 'components["responses"]["NotFound"]' },
5353
},
5454
},
55+
parameters: [{ $ref: 'components["parameters"]["PerPage"]' }, { $ref: 'components["parameters"]["PageNumber"]' }],
5556
};
5657
const generated = transformPathItemObject(schema, options);
5758
expect(generated).toBe(`{
@@ -79,6 +80,12 @@ describe("Path Item Object", () => {
7980
404: components["responses"]["NotFound"];
8081
};
8182
};
83+
parameters?: {
84+
query?: Pick<NonNullable<components["parameters"]>, "PerPage" | "PageNumber">;
85+
header?: Pick<NonNullable<components["parameters"]>, "PerPage" | "PageNumber">;
86+
path?: Pick<components["parameters"], "PerPage" | "PageNumber">;
87+
cookie?: Pick<NonNullable<components["parameters"]>, "PerPage" | "PageNumber">;
88+
};
8289
}`);
8390
});
8491

0 commit comments

Comments
 (0)