1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
|
"""
A test to ensure that MethodView inheritance works as expected
"""
from flask import Flask, jsonify
from flask.views import MethodView
from flasgger import Swagger
class BaseAPIView(MethodView):
"""BAse view"""
class ModelAPIView(BaseAPIView):
"""Model api view"""
class PostAPIView(ModelAPIView):
def get(self, team_id):
"""
Get a list of users
First line is the summary
All following lines until the hyphens is added to description
---
tags:
- users
parameters:
- name: team_id
in: path
description: ID of team (type any number)
required: true
type: integer
definitions:
User:
type: object
properties:
name:
type: string
team:
type: integer
responses:
200:
description: Returns a list of users
schema:
id: Users
type: object
properties:
users:
type: array
items:
$ref: '#/definitions/User'
examples:
users: [{'name': 'Russel Allen', 'team': 66}]
"""
data = {
"users": [
{"name": "Steven Wilson", "team": team_id},
{"name": "Mikael Akerfeldt", "team": team_id},
{"name": "Daniel Gildenlow", "team": team_id}
]
}
return jsonify(data)
app = Flask(__name__)
swag = Swagger(app)
app.add_url_rule(
'/user/<team_id>',
view_func=PostAPIView.as_view('user'),
methods=['GET']
)
if __name__ == "__main__":
app.run(debug=True)
|