-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi.py
53 lines (46 loc) · 1.23 KB
/
api.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
from flask import Flask, jsonify
from flasgger import Swagger
app = Flask(__name__)
swagger = Swagger(app)
@app.route('/meals/<breakfast>/')
def meals(breakfast):
"""
This is using Swagger to show an API with Docker
Getting Food info
---
parameters:
- name: breakfast
in: path
type: string
enum: ['Eggs', 'Hashbrowns', 'Coffee']
required: true
default: all
definitions:
Breakfast:
type: object
properties:
breakfast_food:
type: array
items:
$ref: '#/definitions/Meals'
Meals:
type: string
responses:
200:
description: Your food choice for breakfast
schema:
$ref: '#/definitions/Breakfast'
examples:
toast: ['white', 'wheat', 'rye']
"""
all_breakfast_food = {
'Eggs': [ 'over easy', 'over hard', 'scrambled'],
'Toast': [ 'white', 'wheat', 'rye', 'pumpernickel'],
'Coffee': [ 'Yes', 'No']
}
if breakfast == 'all':
result = all_breakfast_food
else:
result = {breakfast: all_breakfast_food.get(breakfast)}
return(jsonify(result))
app.run(host='0.0.0.0', debug=True)