目前我有这样的东西:
paths:
/home
...
responses:
200:
description: Successful operation
401:
$ref: '#/components/responses/401UnauthorizedDefault'
404:
$ref: '#/components/responses/404NotFound'
502:
$ref: '#/components/responses/502BadGatewayDefault'
/sign_up
...
responses:
201:
description: Created
401:
$ref: '#/components/responses/401UnauthorizedDefault'
404:
$ref: '#/components/responses/404NotFound'
502:
$ref: '#/components/responses/502BadGatewayDefault'
是否可以组合所有三个错误响应并使用 $ref 引用它们?
paths:
/home
...
responses:
200:
description: Successful operation
$ref: '#/components/responses/AllCommonErrorResponses’
/sign_up
...
responses:
201:
description: Created
$ref: '#/components/responses/AllCommonErrorResponses’
目前我不知道我们将使用的所有错误响应。但会有一组共享。如果我们稍后扩展它们,我不想到达每个端点并调整响应。
最佳答案
OpenAPI v3 不允许引用多个响应的列表。
您可以使用specific (e.g., "200") response codes or default对于其他人。
没有选项可以导入标准响应列表并重复使用它。
关于swagger - 是否可以定义一组/列表的响应以在开放 API 中重用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72867301/