Adding declaration of unions outside type expressions
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 could you update your PR pls.
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
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 ...}}]
}
OK. Maybe we should adjust the description text in the spec with that. Its not really clear.
That will need to go into a new version of RAML, presumably 1.1, right ?