以下是 OpenAPI 3 定义的示例:
components:
schemas:
Foo:
properties:
string:
type: string
enumField:
type: string
enum: ['VALUE_1', 'VALUE_2']
Bar:
properties:
enumField:
type: string
enum: ['VALUE_1', 'VALUE_2']
Run Code Online (Sandbox Code Playgroud)
有没有办法重用enumField或者我每次使用时都必须指定它?
我不知道是否可以引用单个属性,但您可以使用模式并通过拆分它来实现。
以下是您可以做什么的基本结构示例:
SchemaBase:
type: object
properties:
foo:
type: string
SchemaFull:
allOf:
- $ref: '#/components/schemas/SchemaBase'
- type: object
properties:
bar:
type: string
Run Code Online (Sandbox Code Playgroud)
在你的情况下可能是这样的:
components:
schemas:
EnumField:
properties:
enumField:
type: string
enum: ['VALUE_1', 'VALUE_2']
Foo:
allOf:
- $ref: '#/components/schemas/EnumField'
- properties:
string:
type: string
Bar:
allOf:
- $ref: '#/components/schemas/EnumField'
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4512 次 |
| 最近记录: |