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

Are Blueprint supported ? #33

Closed
ghost opened this issue Apr 19, 2016 · 9 comments
Closed

Are Blueprint supported ? #33

ghost opened this issue Apr 19, 2016 · 9 comments

Comments

@ghost
Copy link

ghost commented Apr 19, 2016

Hi,

I have a Flask app using Blueprints and would like to document the API using swagger. I love the idea of having a single source of truth when it comes to the API documentation and hence would like to use flask-swagger.
Does it support Blueprint ?
I must admit I didn't even try, I was hoping to first get some tips before messing around with my docstrings everywhere....

thanks

Brieuc

@atlithorn
Copy link
Contributor

Sorry, don't use Blueprints so I don't know... If Blueprints end up resolving to views then probably yes.

@alejoar
Copy link
Contributor

alejoar commented Apr 28, 2016

Yes. When calling swagger(), you can use the prefix arg and set it to the same you set url_prefix when defining your blueprint to limit the spec to said blueprint.

e.g:
In your __init__.py:

def create_app(config_name):
    app = Flask(__name__)
    (...)
    from .api_2_0 import api as api_2_0_blueprint
    app.register_blueprint(api_2_0_blueprint, url_prefix='/api/v2.0')

In some other file:

@api.route("/spec")
def spec():
    swag = swagger(current_app, prefix='/api/v2.0')
    (...)
    return jsonify(swag)

@atlithorn
Copy link
Contributor

Awesome! Thanks. I'll leave the ticket open to remind me to update the docs

@jjmurre
Copy link

jjmurre commented Jul 8, 2016

I don't see support for the 'prefix' keyword arg in the 'swagger' function. Has it been removed?

@atlithorn
Copy link
Contributor

It was never there. Possibly @alejoar has a fork that added this?

Anyways, if all you want to do is prefix the paths I think it would be better to update basePath in the swagger response.
For example:

@app.route('/spec.json')
def spec():
    swaggered = swagger(app)
    swaggered['basePath'] = "/v1"  
    return jsonify(swaggered)

@jjmurre
Copy link

jjmurre commented Jul 8, 2016

Great suggestion, these are my first Swagger experiments, so your comment is quite helpful, tx!

@PradeepJaiswar
Copy link

Any update on blueprint document update thing ? waiting for it.

@alejoar
Copy link
Contributor

alejoar commented Jul 18, 2016

@atlithorn @jjmurre
Sorry for the late reply. @atlithorn you are absolutely right, I'm using a fork I made myself and i forgot about it.

All I did is a very simple modification you can see here. Basically, if the prefix argument is present, it ignores all other url rules:

for rule in app.url_map.iter_rules():
    if prefix and rule.rule[:len(prefix)] != prefix:
        continue

I can create a pull request with this modification if there's interest. I already made another pull request (for a different feature) but it has been ignored for now.

Edit: Ended up submitting a new pull request.

@atlithorn
Copy link
Contributor

Thanks @alejoar, merged. I'll try to get a release out asap

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

4 participants