Search code examples
pythonpython-3.xherokuswagger-uiflask-restplus

hosting flask_restplus Swagger UI on Herokuapp says "No API Definition provided."


I'm trying to host the Swagger UI of Flask Restplus on Heroku server. It builds successfully and when checked in the logs of the heroku, even there it says "Build succeeded".

But the problem is when I check the actual hosting there's just a msg on the page saying
No API definition provided.

enter image description here Btw the swagger-UI loads successfully on the browser when run locally.

Following is a sample code snipet for swagger-ui

from flask import Flask
from flask_restplus import Resource, Api
import os

app = Flask(__name__)
api = Api(app)

@api.route('/hello')
class HelloWorld(Resource):
    def get(self):
        return {'hello': 'world'}

if __name__ == '__main__':
    port = int(os.environ.get("PORT", 5000)) 
    app.run(host="0.0.0.0", port=port, debug=True)

So what am I doing wrong here? Is there any way that you can host a simple minimal flask_restplus swagger-UI on heroku ? Any help is appreciated, thanks.

EDIT

Following is the content of the swagger.json

{
    "swagger": "2.0",
    "basePath": "/",
    "paths": {
        "/hello": {
            "get": {
                "responses": {
                    "200": {
                        "description": "Success"
                    }
                },
                "operationId": "get_hello_world",
                "tags": [
                    "default"
                ]
            }
        }
    },
    "info": {
        "title": "API",
        "version": "1.0"
    },
    "produces": [
        "application/json"
    ],
    "consumes": [
        "application/json"
    ],
    "tags": [
        {
            "name": "default",
            "description": "Default namespace"
        }
    ],
    "responses": {
        "ParseError": {
            "description": "When a mask can't be parsed"
        },
        "MaskError": {
            "description": "When any error occurs on mask"
        }
    }
}

Also if it helps, this is what's inside the Procfile

web: python app.py

Solution

  • Posting what worked for me, just in case if someone has the same concern in future.

    I changed the Procfile from

    web: python app.py
    

    to

    web: gunicorn app:app
    

    and then the swagger-UI first page also started showing up on heroku. Earlier the endpoints were still accessible but the first page ie. the swagger-UI page wasn't showing up. But making this change got it working.