sanic-org / sanic-openapi

Easily document your Sanic API with a UI
https://sanic-openapi.readthedocs.io/
MIT License
505 stars 108 forks source link

[Bug]can not render all methods with the same url when use routes of Blueprint way #232

Closed hsz1273327 closed 3 years ago

hsz1273327 commented 3 years ago

Describe the bug can not render all methods with the same url when use routes of Blueprint way

Screenshots api-1

To Reproduce Your code snippet or steps to reproduce the bug.

code as blow:

usernamespace_v1.get("/", strict_slashes=True)(UserListSource_GET)
usernamespace_v1.post("/", strict_slashes=True)(UserListSource_POST)

usernamespace_v1.get("/<uid:int>", strict_slashes=True)(UserSource_GET)
usernamespace_v1.put("/<uid:int>", strict_slashes=True)(UserSource_PUT)
usernamespace_v1.delete("/<uid:int>", strict_slashes=True)(UserSource_DELETE)

Expected behavior

there should have all method sections in user part,but there are only 2 with diffrent url

Environment (please complete the following information):

Additional context Add any other context about the problem here. This might be how to fix this bug or some hint to fix it.

ahopkins commented 3 years ago
from sanic import Blueprint, Sanic, text
from sanic_openapi import openapi3_blueprint

app = Sanic(__name__)
app.config.API_URI_FILTER = "all"
bp = Blueprint(__name__, version=1)

async def handler(request):
    return text(request.ip)

bp.get("/", strict_slashes=True)(handler)
bp.post("/", strict_slashes=True)(handler)

bp.get("/<uid:int>", strict_slashes=True)(handler)
bp.put("/<uid:int>", strict_slashes=True)(handler)
bp.delete("/<uid:int>", strict_slashes=True)(handler)

app.blueprint(bp)
app.blueprint(openapi3_blueprint)
app.run(port=9999, debug=True)

image

Seems to work okay for me. One thing to note, app.config.API_URI_FILTER = "all" forces the inclusion of routes that end with /. Since you have the empty routes with strict_slashes on, they would be removed.


LMK if I am missing something.

hsz1273327 commented 3 years ago

thanks