在哪里定义 OpenAPI 3 中的可重用子模式?
Where to define reusable subschemas in OpenAPI 3?
我正在处理 OpenAPI 3 文档。我有一个名为 CustomerInfo:
的架构,其中包含 属性 Address
。 Address
的属性之一是名为 State
的枚举。如何使 State
成为可以在 CustomerInfo
的其他部分引用的可重复使用的 属性?
components:
schemas:
CustomerInfo:
type: object
properties:
Address:
type: object
description: Contains the street, city, zip, and state associated with an address.
properties:
State:
$ref: ''
required:
- Street1
- State
我正在考虑在 CustomerInfo
中的 definitions:
下定义一个 State
,但是 https://editor.swagger.io/ 抛出异常:
components:
schemas:
CustomerInfo:
type: object
properties:
Address:
type: object
description: Contains the street, city, zip, and state associated with an address.
properties:
State:
$ref: '#/components/schemas/CustomerInfo/definitions/State'
required:
- Street1
- State
definitions:
State: ....
把State
的schema放到components/schemas
下,可以引用
components:
schemas:
CustomerInfo:
type: object
properties:
Address:
type: object
description: Contains the street, city, zip, and state associated with an address.
properties:
State:
$ref: '#/components/schemas/State'
required:
- State
State:
type: string
enum:
- Alabama
- Alaska
- Arizona
我正在处理 OpenAPI 3 文档。我有一个名为 CustomerInfo:
的架构,其中包含 属性 Address
。 Address
的属性之一是名为 State
的枚举。如何使 State
成为可以在 CustomerInfo
的其他部分引用的可重复使用的 属性?
components:
schemas:
CustomerInfo:
type: object
properties:
Address:
type: object
description: Contains the street, city, zip, and state associated with an address.
properties:
State:
$ref: ''
required:
- Street1
- State
我正在考虑在 CustomerInfo
中的 definitions:
下定义一个 State
,但是 https://editor.swagger.io/ 抛出异常:
components:
schemas:
CustomerInfo:
type: object
properties:
Address:
type: object
description: Contains the street, city, zip, and state associated with an address.
properties:
State:
$ref: '#/components/schemas/CustomerInfo/definitions/State'
required:
- Street1
- State
definitions:
State: ....
把State
的schema放到components/schemas
下,可以引用
components:
schemas:
CustomerInfo:
type: object
properties:
Address:
type: object
description: Contains the street, city, zip, and state associated with an address.
properties:
State:
$ref: '#/components/schemas/State'
required:
- State
State:
type: string
enum:
- Alabama
- Alaska
- Arizona