Ciasto piekarz
Ciasto piekarz

Reputation: 8277

how to add namespace.expect for parameters passed in url as argument

I have written below Resource Class:

@clinic_api_ns.route("/patient/profile")
class PatientProfile(Resource):
    def get(self):
        patient = request.args.get(patient)
        relative = request.args.get(relative)
        relationType = request.args.get(relationType)
        contactNumber = request.args.get(contactNumber)
        townCity = request.args.get(townCity)
        return controller.get_patient_profile(patient, relative, relationType, contactNumber, townCity)

so that to get patient profile , I can use passed parameters through URL such as http://ip.address/api/clinic/patient/profile?patient=<patientName>&relative=<relativeName>&relationType=<relation>

but this throws error in swagger documentation and even if I tried adding @_api_ns.expect(patient_profile, validate=True)

where patient_profile is

class PatientProfile(object):
    profile = clinic_api_ns.model("profile", {
        "patient": fields.String(required=True, description="name of the patient."),
        "relative": fields.String(required=True, description="name of parent or husband."),
        "relation": fields.String(required=True, description="type of relation with patient."),
        "contactnumber": fields.String(required=True, description="contact number of the patient."),
        "townCity": fields.String(required=True, description="town or city the patient belongs to."),        
        })

Upvotes: 2

Views: 586

Answers (1)

HelenShy
HelenShy

Reputation: 336

You can use parser to solve this.

parser = api.parser()
parser.add_argument('param', type=int, help='Some param', location='path') # "location='path'" means look only in the querystring


@api.expect(parser)

Upvotes: 1

Related Questions