【问题标题】:Access to specific property of a definition in Swagger访问 Swagger 中定义的特定属性
【发布时间】:2016-03-18 11:49:00
【问题描述】:

如何访问特定定义的属性?我需要在我的 200 响应中显示“模式”节点中的属性,而不是整个“定义”。

这是 Yaml 代码:

paths: 
 /user/{user_id}:
            get:
              description: Devuelve un `user` pasándole su `user_id`.
              produces:
                - application/json
              parameters:
                - name: user_id
                  in: path
                  description: Identificador del `user`.
                  required: true
                  type: string
                  format: VarChar (255)
              responses:
                '200':
                  description: Ok 
                  schema:
                    $ref: "#/definitions/User"

definitions:
  User:
    properties:
      user_id:
        type: integer
        format: BigInt
        description: Identificador del usuario.
      email:
        type: string
        format: VarChar (255)
        description: Email del usuario
      pwd:
        type: string
        format: VarChar (255)
        description: Password del usuario.

我的意思是,我只需要这样的东西:

responses:
                    '200':
                      description: Ok 
                      schema:
                        $ref: "#/definitions/User/user_id"

有什么想法吗?

【问题讨论】:

    标签: yaml swagger


    【解决方案1】:

    响应必须是正确的架构。并且你的引用需要跟随实际对象中的元素。

    如果你这样做:

    '200':
      description: Ok 
      schema:
        $ref: "#/definitions/User/properties/user_id"
    

    它应该可以正常工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-05
      • 2012-07-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多