引用定义但从中减去“id”属性?

问题描述

假设我有一个 Pet 定义:

deFinitions:
  Pet:
    type: object
    properties:
      id:
        type: string
        format: uuid
      name:
        type: string
      age:
        type: integer

还有一个用于获取单个宠物的 /pet/{id} GET 方法

paths:
  /pet/{id}:
    get:
      produces:
      - application/json
      parameters:
      - name: id
        in: path
        required: true
        type: string
        format: uuid
      responses:
        200:
          description: Ok
          schema:
            $ref: '#/deFinitions/Pet'

现在我想添加 /pet POST 方法添加新宠物,如下所示:

paths:
  /pet
    post:
      consumes:
      - application/json
      produces:
      - application/json
      parameters:
      - name: pet
        in: body
        required: true
        schema:
          $ref: '#/deFinitions/Pet' # <-- issue line
      responses:
        200:
          description: Ok
          schema:
            $ref: '#/deFinitions/Pet'

问题出在参数的 schema 上,因为 id 是由服务器生成的,我不想在请求正文中提供它。然而,实际的 Pet 定义非常复杂,在没有 id 属性的情况下在多个地方重复它会很愚蠢。

有没有办法使用模式然后从它“减去”一个属性

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...