Debian Codegraph @

examples/openapi3_examples.py

raw symbols SCIP
1 """
2 Example using Marshmallow Schema and fields as definitions
3 """
4 # coding: utf-8
5 from flask import Flask, jsonify, Response, request
6
7 from flasgger import Swagger, SwaggerView
8
9 swagger_config = {
10 "headers": [],
11 "openapi": "3.0.2",
12 "components": {
13 'schemas': {
14 'Species': {
15 'type': 'object',
16 'properties': {
17 'id': {
18 'type': 'integer',
19 'format': 'int64'
20 },
21 'name': {
22 'type': 'string'
23 }
24 }
25 },
26 'Animal': {
27 'type': 'object',
28 'properties': {
29 'species': {
30 '$ref': '#/components/schemas/Species'
31 },
32 'name': {
33 'type': 'string'
34 }
35 }
36 }
37 }
38 },
39 "title": "Animal Shelter API",
40 "version": '',
41 "termsOfService": "",
42 "static_url_path": "/characteristics/static",
43 "swagger_ui": True,
44 "description": "",
45 }
46
47
48 class Animals(SwaggerView):
49
50 def get(self):
51 """
52 find shelter animals that fit the criteria
53
54 ---
55 tags:
56 - Animals
57 description: Parameters can be provided in the query to search
58 operationId: getAnimals
59 parameters:
60 - name: species
61 in: query
62 required: true
63 schema:
64 type: string
65 - name: status
66 in: query
67 required: true
68 schema:
69 type: string
70 enum:
71 - adopted
72 - pending
73 - adoptable
74 - transferred
75 - sanctuary
76 - medical-hold
77 responses:
78 '200':
79 description: Animals to be returned
80 content:
81 application/json:
82 schema:
83 type: array
84 items:
85 $ref: '#/components/schemas/Animal'
86 """
87 species = request.args.get('name')
88 status = request.args.get('status')
89 return Response(status=200)
90
91
92 app = Flask(__name__)
93 swag = Swagger(app, config=swagger_config, merge=True)
94
95 app.add_url_rule(
96 '/animals',
97 view_func=Animals.as_view('animals'),
98 methods=['GET']
99 )
100
101 if __name__ == "__main__":
102 app.run(debug=True)