Swagger API generation for Flask-MongoRest
Project description
flask-mongorest-swagger
=======================
Swagger API generation for Flask-MongoRest
Example
------
rest_api = MongoRest(app)
swagger = Swagger(rest_api)
class ApiResource(mongorest.Resource):
document = DocumentClass
parameters = {
'extra_parameter': Parameter('query', 'string',
'Does something else')}
@swagger.register(url='/api-endpoint')
class ApiView(ResourceView):
resource = ApiResource
@swagger.route(
'/api-function', methods=['POST'],
description='The description of this API view',
endpoints=[Endpoint(
Endpoint(
'/api-function/',
login_description,
operations=[Operation(
'POST', 'function', 'More description!',
response_class='Token',
parameters={
'data': Parameter(
'body', 'Input', 'Whatever you need to pass in',
required=True)},
error_responses={401: 'Invalid e-mail/password'})])],
models={
'Input': Model('Input', {
'input_string': Property('string', 'Input to the function')}),
'Token': Model('Token', {
'token': Property(
'string', 'The token which comes back')})})
def api_function():
return 'Thanks!'
This generates a Swagger API available at <http://localhost:5000/api-docs.json>.
Thanks to
---------
* Swagger <https://developers.helloreverb.com/swagger/>
* Flask <http://flask.pocoo.org/>
* Flask-MongoRest <https://github.com/elasticsales/flask-mongorest>
* Matchbox <http://matchbox.net/>
=======================
Swagger API generation for Flask-MongoRest
Example
------
rest_api = MongoRest(app)
swagger = Swagger(rest_api)
class ApiResource(mongorest.Resource):
document = DocumentClass
parameters = {
'extra_parameter': Parameter('query', 'string',
'Does something else')}
@swagger.register(url='/api-endpoint')
class ApiView(ResourceView):
resource = ApiResource
@swagger.route(
'/api-function', methods=['POST'],
description='The description of this API view',
endpoints=[Endpoint(
Endpoint(
'/api-function/',
login_description,
operations=[Operation(
'POST', 'function', 'More description!',
response_class='Token',
parameters={
'data': Parameter(
'body', 'Input', 'Whatever you need to pass in',
required=True)},
error_responses={401: 'Invalid e-mail/password'})])],
models={
'Input': Model('Input', {
'input_string': Property('string', 'Input to the function')}),
'Token': Model('Token', {
'token': Property(
'string', 'The token which comes back')})})
def api_function():
return 'Thanks!'
This generates a Swagger API available at <http://localhost:5000/api-docs.json>.
Thanks to
---------
* Swagger <https://developers.helloreverb.com/swagger/>
* Flask <http://flask.pocoo.org/>
* Flask-MongoRest <https://github.com/elasticsales/flask-mongorest>
* Matchbox <http://matchbox.net/>