我试图在OpenAPI v3模式中描述相互排斥的属性。
我有一个自定义资源,可以使用属性widgetName ( Widget资源的名称)或widgetDefinition (内联Widget定义)。也就是说,这是有效的:
widget:
widgetName: Foo这是有效的:
widget:
widgetDefinition:
name: Foo
size: large
color: red但是您不能同时拥有widget.widgetName和widget.widgetDefinition (允许两者都拥有)。我试过这个:
versions:
- name: v1beta1
schema:
openAPIV3Schema:
type: object
properties:
spec:
type: object
properties:
widget:
type: object
oneOf:
- properties:
widgetName:
type: string
- properties:
widgetDefinition:
type: object
properties:
name:
type: string
size:
type: string
color:
type: string但这行不通,因为:
The CustomResourceDefinition "widgetcontainers.factory.example.com" is invalid:
* spec.validation.openAPIV3Schema.properties[spec].properties[widget].oneOf[0].properties[widgetName].type: Forbidden: must be empty to be structural
* spec.validation.openAPIV3Schema.properties[spec].properties[widget].oneOf[1].properties[widgetDefinition].properties[color].type: Forbidden: must be empty to be structural
* spec.validation.openAPIV3Schema.properties[spec].properties[widget].oneOf[1].properties[widgetDefinition].properties[name].type: Forbidden: must be empty to be structural
* spec.validation.openAPIV3Schema.properties[spec].properties[widget].oneOf[1].properties[widgetDefinition].properties[size].type: Forbidden: must be empty to be structural
* spec.validation.openAPIV3Schema.properties[spec].properties[widget].oneOf[1].properties[widgetDefinition].type: Forbidden: must be empty to be structural如何正确地说“cr可能包含这两种属性中的一种,而不是同时包含这两种属性”?
发布于 2022-07-06 22:01:56
在过去,我使用如下语法定义了类似的CRD模式:
versions:
- name: v1beta1
schema:
openAPIV3Schema:
type: object
properties:
spec:
type: object
properties:
widget:
type: object
properties:
widgetName:
type: string
widgetDefinition:
type: object
properties:
name:
type: string
size:
type: string
color:
type: string
oneOf:
- properties:
required: [ "widgetName" ]
- properties:
required: [ "widgetDefinition" ]https://stackoverflow.com/questions/72690407
复制相似问题