Skip to content

Commit cec2bdf

Browse files
authored
Feat: add support for "type": "file" in parameters (#766)
1 parent 2a266be commit cec2bdf

File tree

5 files changed

+24
-4
lines changed

5 files changed

+24
-4
lines changed

src/transform/schema.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ export function transformSchemaObj(node: any, options: TransformSchemaObjOptions
9797
}
9898
case "string":
9999
case "number":
100-
case "boolean": {
100+
case "boolean":
101+
case "unknown": {
101102
output += nodeType(node) || "any";
102103
break;
103104
}

src/utils.ts

+16-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,17 @@ export function isRef(obj: any): obj is ReferenceObject {
3232
}
3333

3434
/** Return type of node (works for v2 or v3, as there are no conflicting types) */
35-
type SchemaObjectType = "anyOf" | "array" | "boolean" | "enum" | "number" | "object" | "oneOf" | "ref" | "string";
35+
type SchemaObjectType =
36+
| "anyOf"
37+
| "array"
38+
| "boolean"
39+
| "enum"
40+
| "number"
41+
| "object"
42+
| "oneOf"
43+
| "ref"
44+
| "string"
45+
| "unknown";
3646
export function nodeType(obj: any): SchemaObjectType | undefined {
3747
if (!obj || typeof obj !== "object") {
3848
return undefined;
@@ -67,6 +77,11 @@ export function nodeType(obj: any): SchemaObjectType | undefined {
6777
return "array";
6878
}
6979

80+
// file
81+
if (obj.type === "file") {
82+
return "unknown";
83+
}
84+
7085
// return object by default
7186
return "object";
7287
}

tests/schema.test.ts

+4
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,10 @@ describe("SchemaObject", () => {
209209
`components["parameters"]["ReferenceObject"]`
210210
);
211211
});
212+
213+
it("file", () => {
214+
expect(transform({ type: "file" }, { ...defaults })).toBe("unknown");
215+
});
212216
});
213217

214218
describe("advanced", () => {

tests/v2/expected/petstore.immutable.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ export interface operations {
235235
/** Additional data to pass to server */
236236
readonly additionalMetadata?: string;
237237
/** file to upload */
238-
readonly file?: { readonly [key: string]: unknown };
238+
readonly file?: unknown;
239239
};
240240
};
241241
readonly responses: {

tests/v2/expected/petstore.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ export interface operations {
235235
/** Additional data to pass to server */
236236
additionalMetadata?: string;
237237
/** file to upload */
238-
file?: { [key: string]: unknown };
238+
file?: unknown;
239239
};
240240
};
241241
responses: {

0 commit comments

Comments
 (0)