Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API prefix does not work #149

Open
NMO13 opened this issue Nov 30, 2020 · 0 comments
Open

API prefix does not work #149

NMO13 opened this issue Nov 30, 2020 · 0 comments

Comments

@NMO13
Copy link

NMO13 commented Nov 30, 2020

I have an app with a URL prefix:

api = Api(app, prefix="/api/v1")

And a simple view:


class AnimalView(Resource):
    @swagger.operation(notes="get an animal by ID", )
    def get(self, animal_id):
        return build_data_response({}, 200)

And I simply register this view with:

def register_views(api):
    from app.views.animal import AnimalView
    from flask_restful_swagger import swagger, registry
    api = swagger.docs(
    api,
    apiVersion="0.1",
    basePath="http://localhost:5000/api/v1",
    resourcePath="/",
    produces=["application/json", "text/html"],
    api_spec_url="/spec3",
    description="A Basic API")

But this doesn't work. It seems like the library cannot find the static files. I debugged the flask-restful-swagger code and found out that the prefix for x-api-prefix needs to be set. So I changed the code to:

def register_views(api):
    from app.views.animal import AnimalView
    from flask_restful_swagger import swagger, registry
    api = swagger.docs(
    api,
    apiVersion="0.1",
    basePath="http://localhost:5000/api/v1",
    resourcePath="/",
    produces=["application/json", "text/html"],
    api_spec_url="/spec",
    description="A Basic API")

    api.add_resource(AnimalView, "/animals/<animal_id>")

    registry["app"]["x-api-prefix"] = "/api/v1"

And now it works. So shouldn't the x-api-prefix become a parameter of docs()? So for example to call it like this:

    api = swagger.docs(
    api,
    apiVersion="0.1",
    basePath="http://localhost:5000/api/v1",
    resourcePath="/",
    produces=["application/json", "text/html"],
    api_spec_url="/spec",
    description="A Basic API",
    x-api-prefix="/api/v1"
)

Because at the moment it is a ("minor") hack. Or did I overlooked something?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant