-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgreeting.py
38 lines (30 loc) · 1012 Bytes
/
greeting.py
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
import os
from apiflask import APIFlask, Schema
from apiflask.fields import String
import yaml
app = APIFlask('greeting', title='Greeting Service')
class PersonData(Schema):
name = String(required=True)
title = String()
description = String()
@app.get("/formatGreeting")
@app.input(PersonData, "query")
def format_greeting(query_data):
name = query_data.get('name')
title = query_data.get('title')
description = query_data.get('description')
greeting = 'Hello'
greeting += ', '
if title:
greeting += title + ' '
greeting += name + '!'
if description:
greeting += ' ' + description + " is my favourite!"
return greeting
if __name__ == "__main__":
port = 0 if "DYNAMIC_PORTS" in os.environ else 5002
if "DUMP_SCHEMA" in os.environ:
print("Writing schema file")
with open(os.path.join(os.path.dirname(__file__), "greeting-openapi.yaml"), "w") as f:
yaml.dump(app.spec, f)
app.run(port=port)