32
32
from functools import wraps
33
33
from flask import request
34
34
from flask import current_app as app # Import Flask application
35
- from flask_restx import Resource , fields , reqparse , inputs
35
+ from flask_restx import Api , Resource , fields , reqparse , inputs
36
36
from service .models import Pet , Gender
37
37
from service .common import status # HTTP Status Codes
38
- from . import api
38
+
39
+ # Document the type of authorization required
40
+ authorizations = {"apikey" : {"type" : "apiKey" , "in" : "header" , "name" : "X-Api-Key" }}
41
+
42
+ ######################################################################
43
+ # Configure Swagger before initializing it
44
+ ######################################################################
45
+ api = Api (
46
+ app ,
47
+ version = "1.0.0" ,
48
+ title = "Pet Demo REST API Service" ,
49
+ description = "This is a sample server Pet store server." ,
50
+ default = "pets" ,
51
+ default_label = "Pet shop operations" ,
52
+ doc = "/apidocs" , # default also could use doc='/apidocs/'
53
+ authorizations = authorizations ,
54
+ prefix = "/api" ,
55
+ )
39
56
40
57
41
58
######################################################################
@@ -56,13 +73,9 @@ def index():
56
73
required = True ,
57
74
description = "The category of Pet (e.g., dog, cat, fish, etc.)" ,
58
75
),
59
- "available" : fields .Boolean (
60
- required = True , description = "Is the Pet available for purchase?"
61
- ),
76
+ "available" : fields .Boolean (required = True , description = "Is the Pet available for purchase?" ),
62
77
# pylint: disable=protected-access
63
- "gender" : fields .String (
64
- enum = Gender ._member_names_ , description = "The gender of the Pet"
65
- ),
78
+ "gender" : fields .String (enum = Gender ._member_names_ , description = "The gender of the Pet" ),
66
79
"birthday" : fields .Date (required = True , description = "The day the pet was born" ),
67
80
},
68
81
)
@@ -71,20 +84,14 @@ def index():
71
84
"PetModel" ,
72
85
create_model ,
73
86
{
74
- "_id" : fields .String (
75
- readOnly = True , description = "The unique id assigned internally by service"
76
- ),
87
+ "_id" : fields .String (readOnly = True , description = "The unique id assigned internally by service" ),
77
88
},
78
89
)
79
90
80
91
# query string arguments
81
92
pet_args = reqparse .RequestParser ()
82
- pet_args .add_argument (
83
- "name" , type = str , location = "args" , required = False , help = "List Pets by name"
84
- )
85
- pet_args .add_argument (
86
- "category" , type = str , location = "args" , required = False , help = "List Pets by category"
87
- )
93
+ pet_args .add_argument ("name" , type = str , location = "args" , required = False , help = "List Pets by name" )
94
+ pet_args .add_argument ("category" , type = str , location = "args" , required = False , help = "List Pets by category" )
88
95
pet_args .add_argument (
89
96
"available" ,
90
97
type = inputs .boolean ,
0 commit comments