Search code examples
amazon-web-servicesswaggeraws-api-gatewayswagger-uiswagger-2.0

Error while importing formData from swagger json to AWS API Gateway


I am using flask-restx to build an app with a swagger UI and I trying to upload this swagger file as a documentation part in AWS API Gateway. Through this swagger UI, I am enabling the user to upload a CSV file for further data processing.

I have the following 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"
        }
    }
}

When I go to API Gateway --> Documentation --> Import Documentation and paste the json, I get the following error:

enter image description here

How can the following issue be solved? If formData isn't supported by API Gateway, is there an alternate for hosting the swagger UI?


Solution

  • The problem is that AWS API Gateway expects swagger/OpenAPI version 3, and your file is version 2. If you only want a way to host swagger UI for documentation/collaboration purposes, take a look at SwaggerHub https://swagger.io/tools/swaggerhub/.

    But, if you really have to use AWS API Gateway, then you need to get spec in OpenAPI-3 format. Since the API is rather small, I'd suggest preparing OpenAPI-3 spec yourself (rather than generating it) and testing it locally via swagger UI.