我正在为响应中包含的字段不同的 API 编写规范。我希望能够提供多个示例来说明这一点。我的用例是:
- 其中一个 API 调用有一个
include
参数,允许用户指定一些附加字段以包含在响应中 - 对于某些 API 调用,响应中包含的字段取决于与用户的 API 密钥关联的权限
我想做的是这样的:
+ Response 200 (application/json)
{
"id": 1,
"name": "Joe Bloggs",
"email": "joe@example.com"
}
+ Response 200 (application/json)
If `include=telephone` was specified:
{
"id": 1,
"name": "Joe Bloggs",
"email": "joe@example.com",
"telephone": "0123456789"
}
+ Response 200 (application/json)
If the API key has access to address data:
{
"id": 1,
"name": "Joe Bloggs",
"email": "joe@example.com",
"address": [{
"address1": "101 My street",
"address2": "My area"
}]
}
据我所知,尽管您可以提供多个响应,但只有在响应代码或内容类型不同时才能这样做。有没有办法做到这一点?