在Kubernetes CRD OpenAPI模式中正确使用Oneof
我试图描述OpenAPI V3模式中的相互排斥性。
我有一个自定义资源,可以使用属性widgetName
,widget
资源的名称或widgetDefinition
,inline 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可能包含这两个的一个”的正确方法是什么 属性,但不是两者”?
I am trying to describe mutually exclusive properties in an OpenAPI v3 schema.
I have a custom resource that can take a property widgetName
, a name of a Widget
resource, or widgetDefinition
, an inline Widget
definition. That is, this is valid:
widget:
widgetName: Foo
And this is valid:
widget:
widgetDefinition:
name: Foo
size: large
color: red
But you can't have both widget.widgetName
and widget.widgetDefinition
(it is allowed to have neither). I tried this:
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
But this doesn't work, because:
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
What's the correct way to say "the cr may contain one of these two
properties but not both"?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Larsks,我过去使用这样的语法定义了类似的CRD模式:
larsks, I've defined similar CRD schema in the past, using a syntax like this: