-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
58 lines (45 loc) · 1.41 KB
/
Copy pathserver.py
File metadata and controls
58 lines (45 loc) · 1.41 KB
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
from flask import Flask
from flask.views import MethodView
from flask_smorest import Api, Blueprint, abort
import marshmallow as ma
from dataclasses import dataclass
@dataclass
class Profit:
id: int
name: str
amount: float
class ProfitSchema(ma.Schema):
id = ma.fields.Integer()
name = ma.fields.String()
amount = ma.fields.Float()
class ProfitQueryArgsSchema(ma.Schema):
name = ma.fields.String()
amount = ma.fields.Float()
blp = Blueprint(
"profits", "profits", url_prefix="/profits", description="Operations on profits"
)
@blp.route("/")
class Profits(MethodView):
@blp.arguments(ProfitQueryArgsSchema, location="query")
@blp.response(200, ProfitSchema)
def get(self, args):
""" Profit amount for a specific person """
return Profit(1, "AJ", 123.456)
class Config:
API_TITLE = "Test API"
API_VERSION = "1.0.0"
OPENAPI_VERSION = "3.0.2"
OPENAPI_URL_PREFIX = '/doc'
OPENAPI_REDOC_PATH = '/redoc'
OPENAPI_SWAGGER_UI_PATH = '/swagger'
OPENAPI_SWAGGER_UI_VERSION = '3.24.2'
# app.config['API_DESCRIPTION'] = "A super cool test API, complete with dope auto-documentation!"
app = Flask(__name__)
app.config.from_object(Config)
api = Api(app = app)
api.register_blueprint(blp)
# @app.route("/andris")
# def hello_andris():
# return "Hello Andris, we've been waiting for you..."
if __name__ == "__main__":
app.run(debug=True)