簡體   English   中英

將 formData 從 swagger json 導入 AWS API Gateway 時出錯

[英]Error while importing formData from swagger json to AWS API Gateway

我正在使用flask-restx構建一個帶有 swagger UI 的應用程序,我嘗試將此 swagger 文件上傳為AWS API Gateway的文檔部分。 通過這個 swagger 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 Gateway --> Documentation --> Import Documentation 並粘貼 json 時,出現以下錯誤:

在此處輸入圖片說明

如何解決以下問題? 如果API Gateway不支持formData ,是否有替代方法來托管 swagger UI?

問題是 AWS API Gateway 需要 swagger/OpenAPI 版本 3,而您的文件是版本 2。如果您只想以一種方式為文檔/協作目的托管 swagger UI,請查看 SwaggerHub https://swagger.io/工具/swaggerhub/

但是,如果您真的必須使用 AWS API Gateway,那么您需要獲取 OpenAPI-3 格式的規范。 由於 API 相當小,我建議您自己准備 OpenAPI-3 規范(而不是生成它)並通過 swagger UI 在本地進行測試。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM