【问题标题】:Error while importing formData from swagger json to AWS API Gateway将 formData 从 swagger json 导入 AWS API Gateway 时出错
【发布时间】:2020-10-19 07:32:44
【问题描述】:

我正在使用flask-restx 构建一个带有swagger UI 的应用程序,并且我尝试将此swagger 文件作为AWS API Gateway 中的文档部分上传。通过这个 swagger UI,我允许用户上传 CSV 文件以进行进一步的数据处理。

我有以下swaggerjson:

{
    "swagger": "2.0",
    "basePath": "/",
    "paths": {
        "/upload_profile/csv": {
            "post": {
                "responses": {
                    "200": {
                        "description": "Profile uploaded"
                    },
                    "400": {
                        "description": "Validation Error"
                    },
                    "401": {
                        "description": "Not authorized"
                    }
                },
                "operationId": "Get uploaded profiles from user",
                "parameters": [
                    {
                        "name": "csv_file",
                        "in": "formData",
                        "type": "file",
                        "required": true,
                        "description": "CSV file"
                    }
                ],
                "consumes": [
                    "multipart/form-data"
                ],
                "tags": [
                    "upload_profile"
                ]
            }
        }
    },
    "info": {
        "title": "Upload Profile",
        "version": "0.0.1"
    },
    "produces": [
        "application/json"
    ],
    "consumes": [
        "application/json"
    ],
    "tags": [
        {
            "name": "upload_profile",
            "description": "Uploading User Profiles"
        }
    ],
    "responses": {
        "ParseError": {
            "description": "When a mask can't be parsed"
        },
        "MaskError": {
            "description": "When any error occurs on mask"
        }
    }
}

当我转到 API Gateway --> 文档 --> 导入文档并粘贴 json 时,我收到以下错误:

如何解决以下问题?如果API Gateway 不支持formData,是否有替代方案来托管swagger UI?

【问题讨论】:

    标签: amazon-web-services swagger aws-api-gateway swagger-ui swagger-2.0


    【解决方案1】:

    问题是 AWS API Gateway 需要 swagger/OpenAPI 版本 3,而您的文件是版本 2。如果您只想托管 swagger UI 以用于文档/协作目的,请查看 SwaggerHub https://swagger.io/tools/swaggerhub/

    但是,如果您真的必须使用 AWS API Gateway,那么您需要获取 OpenAPI-3 格式的规范。由于 API 相当小,我建议您自己准备 OpenAPI-3 规范(而不是生成它)并通过 swagger UI 在本地进行测试。

    【讨论】:

    • 嘿,我尝试使用 stackoverflow.com/questions/59749513/… 的 swagger 编辑器解决方案将 swagger 2.0 转换为 OpenAPI 3.0。但是转换将 type 从 'file' 更改为 'string'
    • 并且因为type被转换成字符串,所以上传功能丢失了。
    • 请检查swagger.io/docs/specification/describing-request-body/…,它说“文件使用类型:字符串模式,格式:二进制或格式:base64,取决于文件内容的编码方式......”所以看起来像“ type: string" 是正确的。
    • 谢谢。我去看看。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-07-29
    • 1970-01-01
    • 2021-07-22
    • 1970-01-01
    • 1970-01-01
    • 2019-06-09
    • 1970-01-01
    相关资源
    最近更新 更多