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

add Blueprint class #200

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open

add Blueprint class #200

wants to merge 7 commits into from

Conversation

bonashen
Copy link

@bonashen bonashen commented Sep 6, 2020

#input some packages ....
from flask_apispec import FlaskApiSpec, MethodResource
from flask_apispec import doc, marshal_with, use_kwargs
from flask_apispec.blueprint import Blueprint

app = flask.Flask(__name__)
docs = FlaskApiSpec(app)

blueprint = Blueprint(docs, 'pet', __name__)

logging.basicConfig(level=logging.DEBUG)

class Pet:
    def __init__(self, name, type):
        self.name = name
        self.type = type


class PetSchema(ma.Schema):
    name = ma.fields.Str()
    type = ma.fields.Str()


@blueprint.route('/pets/<pet_id>')
@doc(params={'pet_id': {'description': 'pet id'}})
@marshal_with(PetSchema)
@use_kwargs({'breed': ma.fields.Str()},location='query')
def get_pet(pet_id,**kwargs):
    return Pet('calici', 'cat')


@blueprint.route('/cat/<pet_id>')
@doc(
    tags=['pets'],
    params={'pet_id': {'description': 'the pet name'}},
)
class CatResource(MethodResource):

    @marshal_with(PetSchema)
    def get(self, pet_id):
        return Pet('calici', 'cat')

if __name__ == '__main__':
    app.register_blueprint(blueprint)
    app.run(debug=True)

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

Successfully merging this pull request may close these issues.

1 participant