Skip to content

Commit 5482579

Browse files
author
sunlei
committed
fix lowcoder-org#286 clear empty paramemters
1 parent 79209d5 commit 5482579

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

server/node-service/src/plugins/openApi/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
isOas3,
1010
normalizeParams,
1111
parseUrl,
12+
isFile,
1213
} from "./util";
1314
import { badRequest } from "../../common/error";
1415
import { safeJsonParse } from "../../common/util";

server/node-service/src/plugins/openApi/util.ts

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,20 @@ interface FileParamValue {
1717
type?: string;
1818
}
1919

20-
export function getFileData(value: FileParamValue | string): File | Buffer {
20+
export function getFileData(value: FileParamValue | string): File | Buffer | null {
21+
if (!value) {
22+
return null;
23+
}
2124
if (typeof value === "string") {
2225
return Buffer.from(value, "base64");
2326
}
2427
if (value instanceof Buffer || value instanceof File) {
2528
return value;
2629
}
2730
const { data = "", name = "file", type } = value || {};
31+
if (!data) {
32+
return null;
33+
}
2834
return new File([Buffer.from(data, "base64")], name, { type });
2935
}
3036

@@ -107,10 +113,12 @@ export function normalizeParams(
107113
}
108114
const isFile = isFileData(name, operation, isOas3);
109115
const value = isFile ? getFileData(params[key]) : params[key];
110-
if (isOas3 && position === "body") {
111-
bodyEntries.push([name, value]);
112-
} else {
113-
paramEntries.push([name, value]);
116+
if (value) {
117+
if (isOas3 && position === "body") {
118+
bodyEntries.push([name, value]);
119+
} else {
120+
paramEntries.push([name, value]);
121+
}
114122
}
115123
});
116124

@@ -130,7 +138,10 @@ export function normalizeParams(
130138
// process file fields
131139
const fileFields = findOas3FilePropertiesFromSchema(schema);
132140
fileFields.forEach(([name]) => {
133-
requestBody[name] = getFileData(requestBody[name]);
141+
const file = getFileData(requestBody[name]);
142+
if (file) {
143+
requestBody[name] = file;
144+
}
134145
});
135146
}
136147
}
@@ -143,7 +154,10 @@ export function normalizeParams(
143154
const [name, value] = bodyEntries[0];
144155
if (name === "body") {
145156
if (mediaType === MediaTypeOctetStream) {
146-
requestBody = getFileData(value);
157+
const file = getFileData(value);
158+
if (file) {
159+
requestBody = file;
160+
}
147161
} else {
148162
requestBody = value;
149163
}
@@ -191,6 +205,10 @@ export function findOperation(id: string, spec: OpenAPI.Document) {
191205
return null;
192206
}
193207

208+
export function isFile(file: any): file is File {
209+
return file instanceof File;
210+
}
211+
194212
export function isFileData(name: string, operation: OpenAPI.Operation, isOas3: boolean): boolean {
195213
if (isOas3) {
196214
const oas3Operation = operation as OpenAPIV3.OperationObject;

0 commit comments

Comments
 (0)