【问题标题】:Using specific properties while referencing to schema在引用模式时使用特定属性
【发布时间】:2019-05-29 15:43:14
【问题描述】:

我正在使用 swagger 2.0,并且我有以下架构(定义):

"User": {
    "type": "object",
    "properties": {
        "firstName": {
            "type": "string",
            "example": "Tom"
        },
        "lastName": {
            "type": "string",
            "example": "Hanks"
        },
        "email": {
            "type": "string",
            "example": "Tom.Hanks@gmail.com"
        },
        "password": {
            "type": "string",
            "example": "azerty@123456"
    }
}

我想在我的一个回复中引用此架构,所以我执行以下操作:

"responses": {
    "201": {
        "description": "Created.",
        "schema": {
            "$ref": "#/definitions/User"
        }
    }
}

到目前为止,一切正常,但我不想在响应模式中公开密码属性。无论如何要从Userdefinition 中选择我想要使用的属性吗?

【问题讨论】:

    标签: swagger swagger-ui swagger-2.0 swagger-codegen


    【解决方案1】:

    不,没有办法。我建议你定义两种类型:

    • 一种用于无密码的用户数据,我们将其命名为User
    • 还有另一种类型,从它继承,另外还包含一个password 属性。让我们将其命名为UserWithCredential

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-28
      • 1970-01-01
      • 1970-01-01
      • 2022-01-21
      • 1970-01-01
      相关资源
      最近更新 更多