swagger-ui-py icon indicating copy to clipboard operation
swagger-ui-py copied to clipboard

swagger-ui-py >="21.9.28" adds the "/api/doc/" on every URL of an api call

Open tropxy opened this issue 3 years ago • 6 comments

Hi, first let me thank your for coming up with this lib ;)

And before coming to the issue, here are my env settings:

python = 3.9
quart = "0.16.1"
quart-cors = "0.5.0"
swagger-ui-py = "21.9.28"
quart-openapi = "1.7.2"

I am generating the swager.json using quart-openapi and here is how my code looks like:

from quart import request, abort, jsonify
from quart_cors import cors
from quart_openapi import Pint, Resource
from swagger_ui import quart_api_doc

app = Pint(__name__, no_openapi=True)
app = cors(app, allow_origin="*")

@app.route("/api/doc/swagger.json")
async def openapi():
    return jsonify(app.__schema__)

quart_api_doc(
    app,
    config_url="http://localhost:8080/api/doc/swagger.json",
    url_prefix="/api/doc/",
    title="API doc",
    editor=True
)

@app.route("/sites")
class SitesInfoRequest(Resource):
    async def get(self):
        response = await get_all_sites_info()
        return jsonify(response), 200

....

when I run the project, locally, and access the url : http://localhost:8080/api/doc/, the page is generated correctly, with all the endpoints I created. The problem is, once I try out one of the endpoints, the URL that the page tries to hit is incorrect.

Instead of trying http://localhost:8080/sitesit is trying http://localhost:8080/api/doc/swagger.json/sites and I cant figure out what settings shall modify to make it work again.

[EDIT] I did a bit of a research and found out that the problem only occurs from version 21.9.27.post1 on; on versions 21.9.27 and below, it still works as expected. I hope this helps finding the issue...

Thanks!

tropxy avatar Nov 28 '21 14:11 tropxy

@tropxy Can you try this?

  • Remove openapi function
  • Update quart_api_doc like
    quart_api_doc(
        app,
        config=app.__schema__,
        url_prefix="/api/doc/",
        title="API doc",
        editor=True
    )
    

PWZER avatar Nov 29 '21 01:11 PWZER

Sorry, I havent realized you answered me... I will try soon your suggestion, thank you!

tropxy avatar Jan 20 '22 12:01 tropxy

I tried your suggestion and didnt work: Bildschirmfoto 2022-01-20 um 15 53 01

tropxy avatar Jan 20 '22 15:01 tropxy

Hi, any updates on this?

tropxy avatar Jan 31 '23 01:01 tropxy

Hi, any updates on this?

@tropxy Do you have a demo to reproduce the problem?

PWZER avatar Jan 31 '23 02:01 PWZER

@tropxy You should write it like this

@app.route("/api/doc/swagger.json")
async def openapi():
    config = app.__schema__
    for server in config.get('servers', []):
        server['url'] = 'http://localhost:8080'
    return jsonify(config)

PWZER avatar Jan 31 '23 02:01 PWZER