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