Skip to content

Commit 9b9236f

Browse files
authored
Add test for unknown schema in param (#440)
1 parent 675a3c1 commit 9b9236f

File tree

3 files changed

+51
-2
lines changed

3 files changed

+51
-2
lines changed

src/types/OpenAPI3.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export interface OpenAPI3Operation {
3737
[statusCode: number]: OpenAPI3ResponseObject;
3838
default?: OpenAPI3ResponseObject;
3939
};
40+
tags?: string[];
4041
}
4142

4243
export type Parameter = { $ref: string } | OpenAPI3Parameter;
@@ -46,7 +47,7 @@ export interface OpenAPI3Parameter {
4647
description?: string;
4748
required?: boolean;
4849
in: "query" | "header" | "path" | "cookie";
49-
schema: OpenAPI3SchemaObject | OpenAPI3Reference;
50+
schema?: OpenAPI3SchemaObject | OpenAPI3Reference;
5051
}
5152

5253
export interface OpenAPI3ResponseObject {

src/v3.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,9 @@ export default function generateTypesV3(input: OpenAPI3 | OpenAPI3Schemas, optio
173173
return;
174174
}
175175
if (paramProps.description) output += comment(paramProps.description);
176-
output += `"${paramName}"${paramProps.required === true ? "" : "?"}: ${transform(paramProps.schema)};\n`;
176+
output += `"${paramName}"${paramProps.required === true ? "" : "?"}: ${
177+
paramProps.schema ? transform(paramProps.schema) : "unknown"
178+
};\n`;
177179
});
178180
output += `}\n`;
179181
});

tests/v3/index.test.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -988,6 +988,52 @@ describe("responses", () => {
988988
);
989989
});
990990

991+
it("parameters missing schema (#377)", () => {
992+
const schema: OpenAPI3 = {
993+
openapi: "3.0.1",
994+
paths: {
995+
"/c/{id}.json": {
996+
get: {
997+
description: "Get a list of topics in the specified category\n",
998+
tags: ["Categories"],
999+
parameters: [
1000+
{
1001+
name: "id",
1002+
in: "path",
1003+
required: true,
1004+
},
1005+
],
1006+
responses: {},
1007+
},
1008+
},
1009+
},
1010+
};
1011+
1012+
expect(swaggerToTS(schema)).toEqual(
1013+
format(`
1014+
export interface paths {
1015+
"/c/{id}.json": {
1016+
/**
1017+
* Get a list of topics in the specified category
1018+
*/
1019+
get: {
1020+
parameters: {
1021+
path: {
1022+
id: unknown;
1023+
}
1024+
}
1025+
responses: {}
1026+
}
1027+
}
1028+
}
1029+
1030+
export interface operations {}
1031+
1032+
export interface components {}
1033+
`)
1034+
);
1035+
});
1036+
9911037
it("operations interface (#341)", () => {
9921038
const schema: OpenAPI3 = {
9931039
openapi: "3.0.1",

0 commit comments

Comments
 (0)