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

Adding declaration of unions outside type expressions#541

Open
antoniogarrote wants to merge 1 commit intoraml-org:masterfrom
antoniogarrote:union-declaration
Open

Adding declaration of unions outside type expressions#541
antoniogarrote wants to merge 1 commit intoraml-org:masterfrom
antoniogarrote:union-declaration

Conversation

@antoniogarrote
Copy link
Copy Markdown

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.

Comment thread versions/raml-10/raml-10.md Outdated

| Facet | Descriptions |
|:------|:-------------|
| anyOf | array with the super types of the union. It cannot be empty. |
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And at least two elements right?

Copy link
Copy Markdown
Contributor

@petrochenko-pavel-a petrochenko-pavel-a left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep,originally there was an items option for union types, but anyOf is definitely a better name

@sichvoge sichvoge added this to the Patch Release 2016/31/10 milestone Oct 4, 2016
@sichvoge
Copy link
Copy Markdown
Contributor

sichvoge commented Oct 4, 2016

@antoniogarrote could you update your PR pls.

@sichvoge
Copy link
Copy Markdown
Contributor

sichvoge commented Oct 4, 2016

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[]?

@antoniogarrote
Copy link
Copy Markdown
Author

@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 ...}}]
}

@sichvoge
Copy link
Copy Markdown
Contributor

sichvoge commented Dec 2, 2016

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

@sichvoge sichvoge removed this from the Patch Release 2016/31/10 milestone Apr 11, 2017
@sichvoge sichvoge requested a review from usarid November 4, 2017 18:50
@usarid
Copy link
Copy Markdown
Contributor

usarid commented Nov 4, 2017

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Development

Successfully merging this pull request may close these issues.

4 participants