You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Includes a path helper that allows you to pass a Flask-RESTful resource object to path.
Inspired by AndrewPashkin/apispec_restful plugin.
Install
pip install apispec_flask_restful
Usage
Typical usage
frompprintimportpprintfromflask_restfulimportApi, ResourcefromflaskimportFlaskfromapispecimportAPISpecfromapispec_flask_restfulimportRestfulPluginclassHelloResource(Resource):
defget(self, hello_id):
'''A greeting endpoint. --- description: get a greeting responses: 200: description: a pet to be returned schema: $ref: #/definitions/Pet '''passapp=Flask(__name__)
api=Api(app)
spec=APISpec(title='Spec', version='1.0', openapi_version='3.0.2', plugins=[RestfulPlugin()])
api.add_resource(HelloResource, '/hello')
spec.path(resource=HelloResource, api=api)
pprint(spec.to_dict()['paths'])
# OrderedDict([('/hello',# {'get': {'description': 'get a greeting',# 'responses': {200: {'description': 'a pet to be returned',# 'schema': {'$ref': None}}}}})])
Without API
Method path can be invoked with a resource path in a path parameter instead of api parameter:
spec.path(resource=HelloResource, path='/hello')
With Blueprint
Flask blueprints are supported too by passing Flask app in app parameter: