Skip to content

Commit ee5673a

Browse files
committed
Add test cases where property schema is ref
1 parent 340d837 commit ee5673a

File tree

1 file changed

+51
-1
lines changed

1 file changed

+51
-1
lines changed

packages/openapi-typescript/test/transform/parameters-with-default.test.ts

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,18 @@ describe("parametersWithDefaults", () => {
1616
parameters: [
1717
{ in: "query", name: "no_default", required: false, schema: { type: "number" } },
1818
{ in: "query", name: "with_default", required: false, schema: { type: "number", default: 1337 } },
19+
{
20+
in: "query",
21+
name: "ref_without_default",
22+
required: false,
23+
schema: { $ref: "#/components/schemas/NoDefault" },
24+
},
25+
{
26+
in: "query",
27+
name: "ref_with_default",
28+
required: false,
29+
schema: { $ref: "#/components/schemas/WithDefault" },
30+
},
1931
],
2032
},
2133
},
@@ -25,6 +37,8 @@ describe("parametersWithDefaults", () => {
2537
query?: {
2638
no_default?: number;
2739
with_default?: number;
40+
ref_without_default?: components["schemas"]["NoDefault"];
41+
ref_with_default?: components["schemas"]["WithDefault"];
2842
};
2943
header?: never;
3044
path?: never;
@@ -53,6 +67,18 @@ describe("parametersWithDefaults", () => {
5367
parameters: [
5468
{ in: "query", name: "no_default", required: false, schema: { type: "number" } },
5569
{ in: "query", name: "with_default", required: false, schema: { type: "number", default: 1337 } },
70+
{
71+
in: "query",
72+
name: "ref_without_default",
73+
required: false,
74+
schema: { $ref: "#/components/schemas/NoDefault" },
75+
},
76+
{
77+
in: "query",
78+
name: "ref_with_default",
79+
required: false,
80+
schema: { $ref: "#/components/schemas/WithDefault" },
81+
},
5682
],
5783
},
5884
},
@@ -62,6 +88,8 @@ describe("parametersWithDefaults", () => {
6288
query: {
6389
no_default?: number;
6490
with_default: number;
91+
ref_without_default?: components["schemas"]["NoDefault"];
92+
ref_with_default: components["schemas"]["WithDefault"];
6593
};
6694
header?: never;
6795
path?: never;
@@ -89,7 +117,29 @@ describe("parametersWithDefaults", () => {
89117
test.skipIf(ci?.skipIf)(
90118
testName,
91119
async () => {
92-
const result = astToString(transformPathsObject(given, options));
120+
const result = astToString(
121+
transformPathsObject(given, {
122+
...options,
123+
resolve($ref) {
124+
switch ($ref) {
125+
case "#/components/schemas/NoDefault": {
126+
return {
127+
type: "number",
128+
};
129+
}
130+
case "#/components/schemas/WithDefault": {
131+
return {
132+
type: "number",
133+
default: 1338,
134+
};
135+
}
136+
default: {
137+
return undefined as any;
138+
}
139+
}
140+
},
141+
}),
142+
);
93143
if (want instanceof URL) {
94144
await expect(result).toMatchFileSnapshot(fileURLToPath(want));
95145
} else {

0 commit comments

Comments
 (0)