3

I'm using swagger 2.0 and I have the following schema(definition) :

"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"
    }
}

and i want to refer to this schema in one of my responses, so i do the following:

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

Until now everything works perfectly, but i don't want to expose the password property in the response schema. is the anyway to choose exactly the properties i want to use from the Userdefinition ?

Ayoub k
  • 7,788
  • 9
  • 34
  • 57

1 Answers1

1

No, there is no way. I'd suggest you define 2 types:

  • One type for user data without password, let's name it User.
  • And another type that inherits from it and contains additionally a password attribute. Let's name it UserWithCredential.
mentallurg
  • 4,967
  • 5
  • 28
  • 36