Flask 仅允许预期字段?
我的模型需要两个字段,我使用该模型验证我的端点:Flask 仅允许预期字段?,flask,flask-restplus,flask-restx,Flask,Flask Restplus,Flask Restx,我的模型需要两个字段,我使用该模型验证我的端点: config\u model=api.model('Configuration'{ “反应杯计数”:fields.Integer, “移液管计数”:字段。整数 }) #后来 类ConfigEndpoint(资源): @expect(配置模型,validate=True) def put(自): 我如何: 如果存在指定的两个密钥之外的密钥,则引发验证错误 如果两个密钥都不存在,但一次只需要一个密钥,则引发验证错误 如果存在指定的两个密钥之外的密钥
config\u model=api.model('Configuration'{
“反应杯计数”:fields.Integer,
“移液管计数”:字段。整数
})
#后来
类ConfigEndpoint(资源):
@expect(配置模型,validate=True)
def put(自):
我如何:
config_model = api.schema_model('Configuration', {
'type': 'object',
'properties': {
'cuvettes_count': {'type': 'integer'},
'pipettes_count': {'type': 'integer'}
},
'anyOf': [{'required': ['cuvettes_count']}, {'required': ['pipettes_count']}]
})
不幸的是,这只适用于验证输入数据,不适用于封送响应。很有趣,谢谢。你知道jsonschema的任何参考资料吗?谷歌对此很难理解……我想你可以从json-schema.org开始。我不知道任何快速入门文档,但希望以下页面能帮助您:;