带Swagger的Python Flask Rest API-如何发布自定义模型
我正试图用Swagger构建一个FlaskRESTAPI,它接受2个输入参数(BodyTemperature和CoughSeverity),并生成一个输出JSON 如果我通过URL提供这两个参数,代码运行良好。我的代码看起来像这样带Swagger的Python Flask Rest API-如何发布自定义模型,python,flask,flask-restful,Python,Flask,Flask Restful,我正试图用Swagger构建一个FlaskRESTAPI,它接受2个输入参数(BodyTemperature和CoughSeverity),并生成一个输出JSON 如果我通过URL提供这两个参数,代码运行良好。我的代码看起来像这样 from flask import Flask from flask_restplus import Resource, Api, fields app = Flask(__name__) api = Api(app = app, version = "1
from flask import Flask
from flask_restplus import Resource, Api, fields
app = Flask(__name__)
api = Api(app = app, version = "1.0", title = "Patient Predictor",
description = "Takes patiens symptoms as input and provides a estimated health condition of the patient")
name_space = api.namespace('PatientCondition', description='Get patient condition by symptoms')
@name_space.route("/GetPatientCondition/<float:BodyTemp>/<int:CoughSeverity>")
class PatientCondition(Resource):
def post(self, BodyTemp, CoughSeverity):
return {
"status": "Success",
"PatientCondition": "Patient temp is " + str(BodyTemp),
"CoughSeverity": "Patient cough severity is " + str(CoughSeverity)
}
if __name__ == '__main__':
app.run()
但是我不知道如何在POST方法中使用这个模型,这样我就可以在swagger UI中通过JSON输入模型。任何帮助都将是非常感激的
PatientSymptomModel = api.model('PatientSymptom',
{
'BodyTemp': fields.Float(required = True, description="Body Temparature of the person"),
'CoughSeverity': fields.Float(required = True, description="Cough Severity of the person")
}
)