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

doc in blueprint still documents entire app #35

Closed
mpandzo opened this issue Aug 29, 2017 · 3 comments · Fixed by #80
Closed

doc in blueprint still documents entire app #35

mpandzo opened this issue Aug 29, 2017 · 3 comments · Fixed by #80

Comments

@mpandzo
Copy link

mpandzo commented Aug 29, 2017

Even though document calls are only done in a blueprint, say a blue print with url prefix /bp/, swagger goes ahead and documents everything including routes in the root.

Is there a way to register or restrict the documenting for only the blueprint prefix?

@chenjr0719
Copy link
Member

@mpandzo Are you still there? I want to confirm that what you talk about is blueprint scoped swagger?
For example:

test.py:

from sanic import Sanic
from sanic.response import text
from bp import bp

app = Sanic()
app.static('/license', './LICENSE')
app.blueprint(bp)


@app.get('/')
def version(request):
    return text('0.0.1')

if __name__ == '__main__':
    app.run()

bp.py:

from sanic import Blueprint
from sanic.response import text
from sanic_openapi import swagger_blueprint

blueprint = Blueprint('bp')
bp = Blueprint.group(blueprint, swagger_blueprint, url_prefix='/bp/')


@blueprint.get('')
def bp_echo(request):
    return text('foo')

Do you only want to see bp_echo be document in swagger?

@gtors
Copy link

gtors commented Apr 30, 2019

Faced with same problem:

from sanic import Sanic
from sanic.response import text
from bp import bp_public, bp_internal

app = Sanic()
app.static('/license', './LICENSE')
app.blueprint(bp_public)  # Swagger should process only this blueprint
app.blueprint(bp_internal)  # Swagger should ignore this blueprint

@app.get('/')
def version(request):
    return text('0.0.1')

if __name__ == '__main__':
    app.run()

For now, it's impossible to hide bp_internal from Swagger.

@chenjr0719
Copy link
Member

Yep, it is impossible currently because sanic_openapi uses the router of sanic to generate the swagger.json. This will document all the routes include every blueprint's routes at swagger.json.

Some possible solutions:

  1. After merge fix static and exclude #80, using exclude at every route you don't want to document at swagger.
  2. Add a list in app.config, when sanic_openapi generate the swagger.json, read this list to decide which blueprint should be or should not be document at swagger. Related code:
    https://github.com/huge-success/sanic-openapi/blob/3b3410da07766d93d615271768e42123211f95d0/sanic_openapi/swagger.py#L78-L84

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