1

I have a type in raml1.0 with 4 properties and I need to implement this case: Two properties out of the four exist only exclusively, so if one of them exists the other should not exist and if they both occur a propper error message is thrown to the user.

For example:

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

Any help is highly appreciated. BTW, each of these types is a complex object. I only simplified it here just for presentation.

Donia Zaela
  • 317
  • 1
  • 4
  • 15

1 Answers1

1

Try this:

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

The documentation for union types can be found here: https://github.com/raml-org/raml-spec/blob/master/versions/raml-10/raml-10.md/#union-type

George
  • 2,758
  • 12
  • 16