使用OpenApi 3.0.2的具有不同属性的相同架构

时间:2019-07-11 19:50:08

标签: swagger openapi

是否可以根据路径使用具有不同属性的相同架构?我想获取路径为UserId的用户,路径为UserUser且分数为TopUsers的用户。

paths:
  /Users: # user should only have userId property
    get:
      responses:
        200:
          description: "successful operation"
          content:
            application/xml:
              schema:
                $ref: "#/components/schemas/users"

  /TopUsers: # user should have both userId and score properties
    get:
      responses:
        200:
          description: "successful operation"
          content:
            application/xml:
              schema:
                $ref: "#/components/schemas/users"

components:
  schemas:
    users:
      type: "object"
      properties:
        user:
          type: "array"
          xml:
            name: "user"
            wrapped: false
          items:
            $ref: "#/components/schemas/user"
      xml:
        name: "users"    
    user:
      type: "object"
      properties:
        userId:
          type: "integer"
          format: "int64"
        score: # this property is only for Users, not TopUsers
          type: "integer"
          format: "int64"
      xml:
        name: "user"

0 个答案:

没有答案