chenshuai2144 / openapi2typescript

一个被大范围使用的小工具
312 stars 136 forks source link

multipart/form-data 类型的值都被 JSON.stringify, 无法上传文件 #32

Closed GreatAuk closed 2 years ago

GreatAuk commented 2 years ago

image 还有就是不用手动设置 content-type: multipart/form-data, 要不会会由于未包含 boundary 信息,导致上传失败(https://github.com/umijs/umi-request/pull/118) image image

下面是复现的 swagger.json

{
  "openapi": "3.0.1",
  "info": {
    "title": "API Common",
    "description": "ASP.NET Core Web API Common",
    "version": "Common"
  },
  "paths": {
    "/api/CommonMicro/Uploader/Upload": {
      "post": {
        "tags": [
          "Uploader"
        ],
        "summary": "上传图片",
        "operationId": "Upload",
        "requestBody": {
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "properties": {
                  "BucketName": {
                    "type": "string"
                  },
                  "ObjectName": {
                    "type": "string"
                  }
                }
              },
              "encoding": {
                "BucketName": {
                  "style": "form"
                },
                "ObjectName": {
                  "style": "form"
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "text/plain": {
                "schema": {
                  "$ref": "#/components/schemas/StringListResponseResult"
                }
              },
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/StringListResponseResult"
                }
              },
              "text/json": {
                "schema": {
                  "$ref": "#/components/schemas/StringListResponseResult"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "StringListResponseResult": {
        "type": "object",
        "properties": {
          "success": {
            "type": "boolean",
            "description": "请求是否成功"
          },
          "code": {
            "type": "integer",
            "description": "响应代码 200 为成功, 非200为失败,Message为失败原因",
            "format": "int32"
          },
          "message": {
            "type": "string",
            "description": "消息",
            "nullable": true
          },
          "data": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "返回实体",
            "nullable": true
          }
        },
        "additionalProperties": false
      }
    },
    "securitySchemes": {
      "Bearer": {
        "type": "apiKey",
        "description": "JWT Authorization header using the Bearer scheme. \\r\\n\\r\\n \r\n                      Enter 'Bearer' [space] and then your token in the text input below.\r\n                      \\r\\n\\r\\nExample: 'Bearer 12345abcdef'",
        "name": "Authorization",
        "in": "header"
      }
    }
  },
  "security": [
    {
      "Bearer": [ ]
    }
  ]
}
chenshuai2144 commented 2 years ago

求pr

GreatAuk commented 2 years ago

巧了,本来准备试着提 pr 的,先试了下最新版本的 @umijs/plugin-openapi @umijs/openapi 发现已经没有这个问题了