diff --git a/.changeset/old-moments-share.md b/.changeset/old-moments-share.md new file mode 100644 index 0000000..3e876d5 --- /dev/null +++ b/.changeset/old-moments-share.md @@ -0,0 +1,5 @@ +--- +'openapi-ts-request': patch +--- + +fix: fix global File type conflict #507 diff --git a/templates/serviceController.njk b/templates/serviceController.njk index b4bb4e0..0a81d70 100644 --- a/templates/serviceController.njk +++ b/templates/serviceController.njk @@ -64,7 +64,7 @@ {%- for file in api.file -%} {{ file.title | safe }} {{- "?" if not api.file.required -}} - : File {{ "[]" if file.multiple }} + : globalThis.File {{ "[]" if file.multiple }} {{ ";" if not loop.last }} {%- endfor -%} {%- endif -%} @@ -105,7 +105,7 @@ {% endif %} if (item !== undefined && item !== null) { {% if genType === "ts" %} - if (typeof item === 'object' && !(item instanceof File)) { + if (typeof item === 'object' && !(item instanceof globalThis.File)) { if (item instanceof Array) { item.forEach((f) => formData.append(ele, f || '')); } else { diff --git "a/test/__snapshots__/common/\346\226\207\344\273\266\344\270\212\344\274\240.snap" "b/test/__snapshots__/common/\346\226\207\344\273\266\344\270\212\344\274\240.snap" index b07af8b..9045dd7 100644 --- "a/test/__snapshots__/common/\346\226\207\344\273\266\344\270\212\344\274\240.snap" +++ "b/test/__snapshots__/common/\346\226\207\344\273\266\344\270\212\344\274\240.snap" @@ -39,7 +39,7 @@ export function webapiClearImportNavReCheckFileUsingPost({ options, }: { body: API.WebapiClearImportNavReCheckFileUsingPostBody; - file?: File; + file?: globalThis.File; options?: { [key: string]: unknown }; }) { const formData = new FormData(); @@ -52,7 +52,7 @@ export function webapiClearImportNavReCheckFileUsingPost({ const item = (body as { [key: string]: any })[ele]; if (item !== undefined && item !== null) { - if (typeof item === 'object' && !(item instanceof File)) { + if (typeof item === 'object' && !(item instanceof globalThis.File)) { if (item instanceof Array) { item.forEach((f) => formData.append(ele, f || '')); } else { diff --git "a/test/__snapshots__/common/\346\265\213\350\257\225 swagger =_ openapi, schema \345\276\252\347\216\257\345\274\225\347\224\250.snap" "b/test/__snapshots__/common/\346\265\213\350\257\225 swagger =_ openapi, schema \345\276\252\347\216\257\345\274\225\347\224\250.snap" index a846b2e..76fdefc 100644 --- "a/test/__snapshots__/common/\346\265\213\350\257\225 swagger =_ openapi, schema \345\276\252\347\216\257\345\274\225\347\224\250.snap" +++ "b/test/__snapshots__/common/\346\265\213\350\257\225 swagger =_ openapi, schema \345\276\252\347\216\257\345\274\225\347\224\250.snap" @@ -974,7 +974,7 @@ export function adminUtilsUploadsUsingPost({ options, }: { body: API.AdminUtilsUploadsUsingPostBody; - file?: File; + file?: globalThis.File; options?: { [key: string]: unknown }; }) { const formData = new FormData(); @@ -987,7 +987,7 @@ export function adminUtilsUploadsUsingPost({ const item = (body as { [key: string]: any })[ele]; if (item !== undefined && item !== null) { - if (typeof item === 'object' && !(item instanceof File)) { + if (typeof item === 'object' && !(item instanceof globalThis.File)) { if (item instanceof Array) { item.forEach((f) => formData.append(ele, f || '')); } else { diff --git "a/test/__snapshots__/common/\346\265\213\350\257\225\347\224\237\346\210\220 JSON Schemas.snap" "b/test/__snapshots__/common/\346\265\213\350\257\225\347\224\237\346\210\220 JSON Schemas.snap" index a47f6d0..60774fe 100644 --- "a/test/__snapshots__/common/\346\265\213\350\257\225\347\224\237\346\210\220 JSON Schemas.snap" +++ "b/test/__snapshots__/common/\346\265\213\350\257\225\347\224\237\346\210\220 JSON Schemas.snap" @@ -1421,7 +1421,7 @@ export function v2ApiFileUsingPost({ const item = (body as { [key: string]: any })[ele]; if (item !== undefined && item !== null) { - if (typeof item === 'object' && !(item instanceof File)) { + if (typeof item === 'object' && !(item instanceof globalThis.File)) { if (item instanceof Array) { item.forEach((f) => formData.append(ele, f || '')); } else { diff --git "a/test/__snapshots__/common/\346\265\213\350\257\225\347\224\237\346\210\220 react-query \347\232\204 vue \346\250\241\345\274\217.snap" "b/test/__snapshots__/common/\346\265\213\350\257\225\347\224\237\346\210\220 react-query \347\232\204 vue \346\250\241\345\274\217.snap" index 48572b0..5f9c093 100644 --- "a/test/__snapshots__/common/\346\265\213\350\257\225\347\224\237\346\210\220 react-query \347\232\204 vue \346\250\241\345\274\217.snap" +++ "b/test/__snapshots__/common/\346\265\213\350\257\225\347\224\237\346\210\220 react-query \347\232\204 vue \346\250\241\345\274\217.snap" @@ -2653,7 +2653,7 @@ export function v2ApiFileUsingPost({ const item = (body as { [key: string]: any })[ele]; if (item !== undefined && item !== null) { - if (typeof item === 'object' && !(item instanceof File)) { + if (typeof item === 'object' && !(item instanceof globalThis.File)) { if (item instanceof Array) { item.forEach((f) => formData.append(ele, f || '')); } else { diff --git "a/test/__snapshots__/common/\346\265\213\350\257\225\347\224\237\346\210\220 react-query.snap" "b/test/__snapshots__/common/\346\265\213\350\257\225\347\224\237\346\210\220 react-query.snap" index b4f7434..a7d742c 100644 --- "a/test/__snapshots__/common/\346\265\213\350\257\225\347\224\237\346\210\220 react-query.snap" +++ "b/test/__snapshots__/common/\346\265\213\350\257\225\347\224\237\346\210\220 react-query.snap" @@ -2741,7 +2741,7 @@ export function v2ApiFileUsingPost({ const item = (body as { [key: string]: any })[ele]; if (item !== undefined && item !== null) { - if (typeof item === 'object' && !(item instanceof File)) { + if (typeof item === 'object' && !(item instanceof globalThis.File)) { if (item instanceof Array) { item.forEach((f) => formData.append(ele, f || '')); } else { diff --git "a/test/__snapshots__/common/\346\265\213\350\257\225\350\247\243\346\236\220 swagger.yaml_openapi.yaml.snap" "b/test/__snapshots__/common/\346\265\213\350\257\225\350\247\243\346\236\220 swagger.yaml_openapi.yaml.snap" index 44cadc4..2aa2060 100644 --- "a/test/__snapshots__/common/\346\265\213\350\257\225\350\247\243\346\236\220 swagger.yaml_openapi.yaml.snap" +++ "b/test/__snapshots__/common/\346\265\213\350\257\225\350\247\243\346\236\220 swagger.yaml_openapi.yaml.snap" @@ -131,7 +131,7 @@ export function petPetIdUploadImageUsingPost({ // 叠加生成的Param类型 (非body参数openapi默认没有生成对象) params: API.PetPetIdUploadImageUsingPostParams; body: API.PetPetIdUploadImageUsingPostBody; - file?: File; + file?: globalThis.File; options?: { [key: string]: unknown }; }) { const { petId: param0, ...queryParams } = params; @@ -145,7 +145,7 @@ export function petPetIdUploadImageUsingPost({ const item = (body as { [key: string]: any })[ele]; if (item !== undefined && item !== null) { - if (typeof item === 'object' && !(item instanceof File)) { + if (typeof item === 'object' && !(item instanceof globalThis.File)) { if (item instanceof Array) { item.forEach((f) => formData.append(ele, f || '')); } else { diff --git "a/test/__snapshots__/common/\346\265\213\350\257\225\350\256\276\347\275\256 path \345\211\215\347\274\200.snap" "b/test/__snapshots__/common/\346\265\213\350\257\225\350\256\276\347\275\256 path \345\211\215\347\274\200.snap" index 58b131d..cd3c04e 100644 --- "a/test/__snapshots__/common/\346\265\213\350\257\225\350\256\276\347\275\256 path \345\211\215\347\274\200.snap" +++ "b/test/__snapshots__/common/\346\265\213\350\257\225\350\256\276\347\275\256 path \345\211\215\347\274\200.snap" @@ -131,7 +131,7 @@ export function petPetIdUploadImageUsingPost({ // 叠加生成的Param类型 (非body参数openapi默认没有生成对象) params: API.PetPetIdUploadImageUsingPostParams; body: API.PetPetIdUploadImageUsingPostBody; - file?: File; + file?: globalThis.File; options?: { [key: string]: unknown }; }) { const { petId: param0, ...queryParams } = params; @@ -145,7 +145,7 @@ export function petPetIdUploadImageUsingPost({ const item = (body as { [key: string]: any })[ele]; if (item !== undefined && item !== null) { - if (typeof item === 'object' && !(item instanceof File)) { + if (typeof item === 'object' && !(item instanceof globalThis.File)) { if (item instanceof Array) { item.forEach((f) => formData.append(ele, f || '')); } else { diff --git "a/test/__snapshots__/common/\347\224\237\346\210\220\346\236\232\344\270\276\347\277\273\350\257\221, \347\224\237\346\210\220 type \347\277\273\350\257\221.snap" "b/test/__snapshots__/common/\347\224\237\346\210\220\346\236\232\344\270\276\347\277\273\350\257\221, \347\224\237\346\210\220 type \347\277\273\350\257\221.snap" index babc053..1171b23 100644 --- "a/test/__snapshots__/common/\347\224\237\346\210\220\346\236\232\344\270\276\347\277\273\350\257\221, \347\224\237\346\210\220 type \347\277\273\350\257\221.snap" +++ "b/test/__snapshots__/common/\347\224\237\346\210\220\346\236\232\344\270\276\347\277\273\350\257\221, \347\224\237\346\210\220 type \347\277\273\350\257\221.snap" @@ -3265,7 +3265,7 @@ export function v2ApiFileUsingPost({ const item = (body as { [key: string]: any })[ele]; if (item !== undefined && item !== null) { - if (typeof item === 'object' && !(item instanceof File)) { + if (typeof item === 'object' && !(item instanceof globalThis.File)) { if (item instanceof Array) { item.forEach((f) => formData.append(ele, f || '')); } else {