Swagger/OpenAPI-根据授权级别的不同模型表示法
当我根据授权级别对每个模型有不同的表示时,如何使用Swagger模型 例如,管理员的国家/地区模型如下所示:Swagger/OpenAPI-根据授权级别的不同模型表示法,swagger,openapi,Swagger,Openapi,当我根据授权级别对每个模型有不同的表示时,如何使用Swagger模型 例如,管理员的国家/地区模型如下所示: definitions: Country: type: object properties: id: type: integer format: int64 name: type: string example: The Netherlands code:
definitions:
Country:
type: object
properties:
id:
type: integer
format: int64
name:
type: string
example: The Netherlands
code:
type: string
example: NL
created_at:
type: string
example: 2017-06-01 13:37:00
updated_at:
type: string
example: 2017-06-01 14:00:00
/admin/countries/{countryId}:
get:
tags:
- AdminCountries
summary: Find a country by ID
operationId: adminCountriesGetById
security:
- Bearer: []
parameters:
- in: path
type: integer
format: int64
name: countryId
required: true
responses:
'200':
description: Success
schema:
type: object
properties:
id:
type: integer
format: int64
name:
type: string
example: The Netherlands
code:
type: string
example: NL
created_at:
type: string
example: 2017-06-01 13:37:00
updated_at:
type: string
example: 2017-06-01 14:00:00
然而,只有一个普通的用户模型是这样的
definitions:
Country:
type: object
properties:
id:
type: integer
format: int64
name:
type: string
example: The Netherlands
code:
type: string
example: NL
我正在考虑将模型定义放在响应中,如下所示:
definitions:
Country:
type: object
properties:
id:
type: integer
format: int64
name:
type: string
example: The Netherlands
code:
type: string
example: NL
created_at:
type: string
example: 2017-06-01 13:37:00
updated_at:
type: string
example: 2017-06-01 14:00:00
/admin/countries/{countryId}:
get:
tags:
- AdminCountries
summary: Find a country by ID
operationId: adminCountriesGetById
security:
- Bearer: []
parameters:
- in: path
type: integer
format: int64
name: countryId
required: true
responses:
'200':
description: Success
schema:
type: object
properties:
id:
type: integer
format: int64
name:
type: string
example: The Netherlands
code:
type: string
example: NL
created_at:
type: string
example: 2017-06-01 13:37:00
updated_at:
type: string
example: 2017-06-01 14:00:00
我真的不确定我的“解决方案”是否是处理这个问题的正确方法。即将发布的OpenAPI规范3.0将支持
其中一个定义多个可能的请求/响应主体
在2.0中,您所能做的最多是将特定于管理员的属性定义为可选属性,并使用description
记录这些属性仅返回给管理员,而不返回给普通用户