0

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?

some_programmer
  • 3,268
  • 4
  • 24
  • 59

1 Answers1

2

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.

Eugene Prikazchikov
  • 1,794
  • 1
  • 13
  • 11
  • Hey, I tried converting swagger 2.0 to OpenAPI 3.0 using the swagger editor solution at https://stackoverflow.com/questions/59749513/how-to-convert-openapi-2-0-to-openapi-3-0#:~:text=Paste%20your%20OpenAPI%202.0%20definition,OpenAPI%203%20from%20the%20menu. But the conversion changes the `type` from 'file' to 'string' – some_programmer Oct 21 '20 at 10:45
  • And because the `type` is converted to string, the uploading functionality is lost. – some_programmer Oct 21 '20 at 10:46
  • Please check https://swagger.io/docs/specification/describing-request-body/file-upload/ , it says "Files use a type: string schema with format: binary or format: base64, depending on how the file contents will be encoded..." So looks like "type: string" is correct. – Eugene Prikazchikov Oct 21 '20 at 10:50
  • Thank you. I will check it out. – some_programmer Oct 21 '20 at 11:04