此模式在我的项目中反复出现(六次):
type: object
properties:
total:
type: integer
description: the count of all items that match the query
hits:
type: array
description: a single page of results
items:
$ref: '#/definitions/{various schema}'这种重复模式({various schema})的内部部分因每次使用而不同。我希望引用每个共享代码,而不是重复我自己。我通常使用$ref,但由于变量位,这里似乎不起作用。
我试图让anyOf为我自己工作,但它只有助于改变object的items,但我试图改变array的items。
我遗漏了什么吗?可能是一次小的重构,以使其适合于可重用模式?
发布于 2016-08-22 08:53:34
除了items约束之外,您可以定义重复的模式,然后在每个变体中使用allOf。
您的可重用模式将是这样的:
reusable:
type: object
properties:
total:
type: integer
description: the count of all items that match the query
hits:
type: array
description: a single page of results当您想要定义一个变体时,可以使用allOf添加可重用模式和附加约束:
variation1:
allOf:
- reusable
- properties:
hits:
items:
$ref: '#/definitions/variation_schema'https://stackoverflow.com/questions/39048481
复制相似问题