Put back api.model because reqparse documentation is bad.

This commit is contained in:
yohan 2024-06-06 22:45:58 +02:00
parent 6fdf7f3c05
commit 2cbfe5781d

View File

@ -175,14 +175,18 @@ cursor.execute("CREATE TABLE IF NOT EXISTS set_mode (name TEXT PRIMARY KEY DEFAU
Set_mode_parser = api.parser() Set_mode_parser = api.parser()
Set_mode_parser.add_argument( Set_mode_parser.add_argument(
"value", type=str, choices=targets+modes, required=True, help="value", location="json" "value", type=str, choices=targets+modes, required=True, help="Thermostat mode", location="json"
) )
Set_mode_resource_fields = {
'value': fields.String(required=True, description='Thermostat mode', enum=targets+modes),
}
Set_mode_model = api.model('Set_mode_Model', Set_mode_resource_fields)
@ns_thermostat.route('/set_mode') @ns_thermostat.route('/set_mode')
class Set_mode_thermostat(Resource): class Set_mode_thermostat(Resource):
@auth_required @auth_required
@api.doc(parser=Set_mode_parser) @api.expect(Set_mode_model, validate=True)
@api.expect(Set_mode_parser, validate=True)
def post(self): def post(self):
global new_forced_mode global new_forced_mode
try: try:
@ -205,10 +209,15 @@ Set_verbosity_parser.add_argument(
"value", type=str, choices=["DEBUG", "INFO", "WARNING"], required=True, help="Verbosity", location="json" "value", type=str, choices=["DEBUG", "INFO", "WARNING"], required=True, help="Verbosity", location="json"
) )
Set_verbosity_resource_fields = {
'value': fields.String(required=True, description='Verbosity', enum=["DEBUG", "INFO", "WARNING"])
}
Set_verbosity_model = api.model('Set_verbosity_Model', Set_verbosity_resource_fields)
@ns_thermostat.route('/set_verbosity') @ns_thermostat.route('/set_verbosity')
class Set_verbosity_thermostat(Resource): class Set_verbosity_thermostat(Resource):
@auth_required @auth_required
@api.expect(Set_verbosity_parser, validate=True) @api.expect(Set_verbosity_model, validate=True)
def put(self): def put(self):
try: try:
args = Set_verbosity_parser.parse_args() args = Set_verbosity_parser.parse_args()