raml-org / raml-spec

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

[RAML 1.0] Examples inheritance #236

Closed juancoen closed 7 years ago

juancoen commented 8 years ago

I've been playing a little bit with examples and noticed that the parser throws a Required Property error for each required property in a type's supertype that is not specified in its example, even if the example has been specified in the supertype, for example:

types:
  Person:
    type: object
    properties:
      firstname: string
      lastname: string
      age: number
    example:
      firstname: John
      lastname: Doe
      age: 20
  User:
    type: Person
    properties:
      id:
        type: number
        example: 12345678 # multiple errors in this line, one for each property in Person

However, if the example in User's id property is removed, the parser works fine and the resulting AST returns this example for the User type:

{
  "firstname": "Juan",
  "lastname": "Coen",
  "age": "31",
  "id": {}
}

The spec doesn't give a lot of detail on the rules of example definition, so the question is: should this work correctly and it's just a parser error or am I trying to achieve something that is invalid?

Thanks!

petrochenko-pavel-a commented 8 years ago

It is clearly bug in the parser. Thanks a lot for reporting this.

sichvoge commented 7 years ago

I'll close this as invalid.

jmjdamen commented 6 years ago

I ran into this and see this is flagged as invalid, why is this not supported in RAML 1.0?

So as my example is:

types: 
  Car:
    type: object
    properties: 
      brand:
      model:
      color:
      price: number
      year: number
    example:
      brand: Tesla
      model: Model S
      color: Grey
      price: 60000
      year: 2014   

  ElectricCar:
    type: Car
    properties: 
      battery:
      range: number
      unit: 

Using API designer on the Anypoint Platform (MuleSoft) the autocompletion options give me the fields of the supertype and subtype. So is this valid? Isn't there an option to include the example from the supertype (Car in this case) and only specify the values that are there regarding the subtype. And if not is there a reason, i saw @petrochenko-pavel-a said is was clearly a bug, so for me the support of this is a bit vague.

Meant to be or not? :)

image