【问题标题】:how to add namespace.expect for parameters passed in url as argument如何为在 url 中作为参数传递的参数添加 namespace.expect
【发布时间】:2019-05-27 07:04:32
【问题描述】:

我在Resource类下面写了:

@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)

为了获取患者资料,我可以使用通过 URL 传递的参数,例如 http://ip.address/api/clinic/patient/profile?patient=<patientName>&relative=<relativeName>&relationType=<relation>

但这会在 swagger 文档中引发错误,即使我尝试添加 @_api_ns.expect(patient_profile, validate=True)

patient_profile 在哪里

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."),        
        })

【问题讨论】:

    标签: swagger-ui flask-restful flask-restplus


    【解决方案1】:

    你可以使用解析器来解决这个问题。

    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)
    

    【讨论】:

      猜你喜欢
      • 2011-12-24
      • 2017-08-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-22
      • 1970-01-01
      • 2017-06-19
      相关资源
      最近更新 更多