3232from functools import wraps
3333from flask import request
3434from 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
3636from service .models import Pet , Gender
3737from 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+ )
3956
4057
4158######################################################################
@@ -56,13 +73,9 @@ def index():
5673 required = True ,
5774 description = "The category of Pet (e.g., dog, cat, fish, etc.)" ,
5875 ),
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?" ),
6277 # 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" ),
6679 "birthday" : fields .Date (required = True , description = "The day the pet was born" ),
6780 },
6881)
@@ -71,20 +84,14 @@ def index():
7184 "PetModel" ,
7285 create_model ,
7386 {
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" ),
7788 },
7889)
7990
8091# query string arguments
8192pet_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" )
8895pet_args .add_argument (
8996 "available" ,
9097 type = inputs .boolean ,
0 commit comments