如何让两个 raml 属性互斥?
How to have two raml properties mutually exclusive?
我在 raml1.0 中有一个具有 4 个属性的类型,我需要实现这个案例:
四个属性中的两个属性仅独占存在,因此如果其中一个存在,则另一个不应该存在,如果它们都出现,则会向用户抛出适当的错误消息。
例如:
types:
TypeOne:
description: "Need the first two properties exist only mutually exclusively"
type: object
additionalProperties: false
properties:
Prop1:
description: "This is the first property"
type: string
required: true
Prop2:
description: "This should not exist if Prop1 exist"
type: String
required: true (only if Prop1 does not exist)
Prop3:
description: "This is optional if Prop1 exists"
type: string
required: false
Prop4:
description: "This is optional if Prop2 exists"
type: string
required: false
非常感谢任何帮助。顺便说一句,这些类型中的每一个都是一个复杂的对象。我这里只是简化了,只是为了展示。
试试这个:
types:
Base:
properties:
Prop3:
description: "This is optional if Prop1 exists"
type: string
required: false
Prop4:
description: "This is optional if Prop2 exists"
type: string
required: false
TypeOne:
type: Base
additionalProperties: false
properties:
Prop1:
description: "This is the first property"
type: string
required: true
TypeTwo:
type: Base
additionalProperties: false
properties:
Prop2:
description: "This is the first property"
type: string
required: true
MainType:
type: TypeOne | TypeTwo
联合类型的文档可以在这里找到:https://github.com/raml-org/raml-spec/blob/master/versions/raml-10/raml-10.md/#union-type
我在 raml1.0 中有一个具有 4 个属性的类型,我需要实现这个案例: 四个属性中的两个属性仅独占存在,因此如果其中一个存在,则另一个不应该存在,如果它们都出现,则会向用户抛出适当的错误消息。
例如:
types:
TypeOne:
description: "Need the first two properties exist only mutually exclusively"
type: object
additionalProperties: false
properties:
Prop1:
description: "This is the first property"
type: string
required: true
Prop2:
description: "This should not exist if Prop1 exist"
type: String
required: true (only if Prop1 does not exist)
Prop3:
description: "This is optional if Prop1 exists"
type: string
required: false
Prop4:
description: "This is optional if Prop2 exists"
type: string
required: false
非常感谢任何帮助。顺便说一句,这些类型中的每一个都是一个复杂的对象。我这里只是简化了,只是为了展示。
试试这个:
types:
Base:
properties:
Prop3:
description: "This is optional if Prop1 exists"
type: string
required: false
Prop4:
description: "This is optional if Prop2 exists"
type: string
required: false
TypeOne:
type: Base
additionalProperties: false
properties:
Prop1:
description: "This is the first property"
type: string
required: true
TypeTwo:
type: Base
additionalProperties: false
properties:
Prop2:
description: "This is the first property"
type: string
required: true
MainType:
type: TypeOne | TypeTwo
联合类型的文档可以在这里找到:https://github.com/raml-org/raml-spec/blob/master/versions/raml-10/raml-10.md/#union-type