【发布时间】:2016-12-12 07:39:19
【问题描述】:
这是我第一次涉足 Swagger,所以请保持温和。
我有以下定义:
definitions:
Payload:
type: object
properties:
indicators:
type: array
items:
$ref: '#/definitions/Indicator'
Indicator:
type: object
properties:
type:
type: string
computeOn:
type: array
items:
type: string
default:
- close
parameters:
type: object
BBANDS:
properties:
type:
type: string
default: BBANDS
computeOn:
type: array
items:
type: string
default:
- close
parameters:
type: object
properties:
timeperiod:
type: integer
format: int32
default: 5
nbdevup:
type: integer
format: int32
default: 2
nbdevdn:
type: integer
format: int32
default: 2
matype:
type: integer
format: int32
default: 0
DEMA:
properties:
type:
type: string
default: DEMA
computeOn:
type: array
items:
type: string
default:
- close
parameters:
type: object
properties:
timeperiod:
type: integer
format: int32
default: 5
所以Payload 有一个名为indicator 的属性,它是Indicators 的数组。 BBANDS 和 DEMA 是 type Indicator 的模型(我知道这不会转化为 Swagger)。我想做的是用它们的默认值定义一个实际模型的数组,在本例中为BBANDS 和DEMA。像这样的:
definitions:
Payload:
type: object
properties:
indicators:
type: array
items:
- '#/definitions/BBANDS'
- '#/definitions/DEMA'
或
definitions:
Payload:
type: object
properties:
indicators:
type: array
items:
- $ref '#/definitions/BBANDS'
- $ref '#/definitions/DEMA'
当然,两者都不起作用。原因是虽然Indicator 模型正确描述了indicator,但不同的indicators 可以有不同的参数集。
有没有办法从本质上定义几个模型的列表,或者将BBANDS 和DEMA 模型映射到Indicator?
编辑:在 Swagger 编辑器中使用@Helen 的第一个建议的结果
【问题讨论】:
标签: swagger swagger-2.0