如何解决挥舞着json,阻止“定义”-特定方法中的不同必填字段
我有一个简单的swagger.json文件,包含2种方法的Product rest api:发布(添加新产品)和放置(更新),我想根据POST的要求定义产品定义的“名称”,“价格”字段方法,但不适用于PUT方法。
如何在没有代码重复的情况下做到这一点?
有我的swagger.json文件
{
"paths" : {
"/products" : {
"post" : {
"summary" : "Add a new product","operationId" : "addProduct","consumes" : [ "application/json" ],"produces" : [ "application/json" ],"parameters" : [ {
"in" : "body","name" : "data","description" : "Product object that needs to be added to the store","required" : true,"schema" : {
"$ref" : "#/definitions/Product","required": ["name","price"] // <-------- not working
}
} ]
},},"/products/{id}" : {
"put" : {
"summary" : "Update a product","operationId" : "updateProduct","consumes" : [ "application/json","multipart/form-data" ],"parameters" : [
{
"in" : "path","name" : "id","description" : "Product id","type": "integer","format": "uint"
},{
"in" : "body","description" : "Product data for update","schema" : {
"$ref" : "#/definitions/Product"
}
}
]
}
}
},"definitions" : {
"Product": {
"type": "object","required": ["name"],"properties": {
"name" : {
"type" : "string"
},"price": {
"type": "number","format": "float"
}
}
}
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。