raml-spec icon indicating copy to clipboard operation
raml-spec copied to clipboard

Adding declaration of unions outside type expressions

Open antoniogarrote opened this issue 9 years ago • 5 comments

Fixes #530

Extends the spec to make it possible to declare a union without using a type expression.

It introduces a new facet anyOf to declare the super types of the union. It adds two restrictions to anyOf:

  • It is mandatory for unions
  • It cannot e empty.

antoniogarrote avatar Jul 27 '16 16:07 antoniogarrote

@antoniogarrote could you update your PR pls.

sichvoge avatar Oct 04 '16 13:10 sichvoge

QQ: whats the value of each item inside the anyOf array? a simple string representing a reference to another type or also an object. For example, how do I express Person | Animal[]?

sichvoge avatar Oct 04 '16 14:10 sichvoge

@sichvoge

In my opinion, any valid type declaration should be allowed:

anyOf:
  - Person | Animal[]

Expresses: Union(Union(Persion,Animal[]))

anyOf:
  - Person 
  - Animal[]

Expresses: Union(Person,Animal[])

anyOf:
  - type:
      Person
  - type:
      array
    items:
      Animal

Expresses: Union(Person,Animal[])

Etc.

At the of the day, if you run the canonical form, all of them become:

{type: "union"
 anyOf:[
  {type: "object", properties:{... properties of person ...}},
  {type: "array", items: {type: "Object", properties: {... properties of animal here ...}}]
}

antoniogarrote avatar Dec 02 '16 11:12 antoniogarrote

OK. Maybe we should adjust the description text in the spec with that. Its not really clear.

sichvoge avatar Dec 02 '16 11:12 sichvoge

That will need to go into a new version of RAML, presumably 1.1, right ?

usarid avatar Nov 04 '17 23:11 usarid