挥舞着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 (将#修改为@)