微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

从swagger json导入formData到AWS API Gateway时出错

如何解决从swagger json导入formData到AWS API Gateway时出错

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

我有以下swagger json:

{
    "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网关->文档->导入文档并粘贴json时,出现以下错误

enter image description here

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

解决方法

问题在于,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在本地对其进行测试。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。