raml-org / raml-spec

RAML Specification
http://raml.org
3.87k stars 858 forks source link

Is it possible to mix multiple inheritance and general type definition notation? Why it is allowed to use [string, nil] in multiple inheritance? #677

Open alvassin opened 6 years ago

alvassin commented 6 years ago

According to documentation, there is two notations for type declaration:

1. Should parsers allow to mix two notations? Documentations does not say that you should use only one. (I can't do that in raml-js-parser2, it that a bug of parser?)

2. Is it allowed to create [string, nil] multiple inheritance? In raml-js-parser it is allowed. But it does not match documetation, right?

Multiple inheritance notation allows to use union symbol | and commas ,. raml-js-parser2 also allows to use () brackets to group expressions (but only for some cases). [] modificator can not be used to declare arrays.

Valid:
[One, Two | Three] -> Union[One + Two, Three]
[One, (Two | Three)] -> One + Union[Two, Three]

Invalid:
[(One, Two)] -> Inheriting from unknown type error
[One, Two][] - js yaml parsing error
[One[], Two[]] - js yaml parsing error
[[One, Two], Three] - nested ancestors not allowed too

General notation allows [] symbols for modifying types as arrays, '()' symbols are allowed for grouping (nested too) in any imaginary cases. Multiple inheritance using comma or '[]' brackets is not supported.

Valid: 
string[]
(UserDefinedOne | UserDefinedTwo)[]
UserDefinedOne | UserDefinedTwo[] | (UserDefinedThee | UserDefinedFour)
(UserDefinedOne | (UserDefinedTwo | UserDefinedThree)[])

Invalid:
UserDefinedOne, UserDefinedTwo
alvassin commented 6 years ago

Moreover, in official parser i can create very stupid declarations, like the following:

#%RAML 1.0
title: multiInheritance
types:
  WTFIsThat:
    type: [string, (number | array)]

Is that ok and the result should be Derived[String, Union] type, which allows ancestors of the different type?

From my point of view, if we are inheriting from Union type, parser must validate Union contents.