Skip to content
This repository has been archived by the owner on Feb 17, 2024. It is now read-only.

Adding declaration of unions outside type expressions #541

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions versions/raml-10/raml-10.md
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ The RAML type system defines the following built-in types:
* [any](#the-any-type)
* [object](#object-type)
* [array](#array-type)
* [union](#union-type) via type expression
* [union](#union-type)
* one of the following [scalar types](#scalar-types): number, boolean, string, date-only, time-only, datetime-only, datetime, file, integer, or null

Additional to the built-in types, the RAML type system also allows to define [JSON or XML schema](#using-xml-and-json-schema).
Expand Down Expand Up @@ -1083,7 +1083,12 @@ Declaring the type of a property to be `null` represents the lack of a value in

#### Union Type

A union type is used to allow instances of data to be described by any of several types. A union type is declared via a type expression that combines 2 or more types delimited by pipe (`|`) symbols; these combined types are referred to as the union type's super types. In the following example, instances of the `Device` type may be described by either the `Phone` type or the `Notebook` type:
A union type is used to allow instances of data to be described by any of several types. A union type is declared via a type expression that combines 2 or more types delimited by pipe (`|`) symbols; these combined types are referred to as the union type's super types. Union types can also be declared using a combination of the `type` facet with value `union` and a facet `anyOf` with a value containing an array of all the union super types. In the following example, instances of the `Device` type may be described by either the `Phone` type or the `Notebook` type:

| Facet | Descriptions |
|:------|:-------------|
| anyOf | array with the super types of the union. At least 2 elements. |


```yaml
#%RAML 1.0
Expand Down Expand Up @@ -1115,8 +1120,9 @@ The following example defines two types and a third type which is a union of tho

```yaml
types:
CatOrDog:
type: Cat | Dog # elements: Cat or Dog
CatOrDog: # equivalent to type: Cat | Dog
type: union
anyOf: [ Cat, Dog ]
Cat:
type: object
properties:
Expand Down