RAML model inheritance



Been trying all day to implement a simple use case where I want to have parts of a schema defined in one place for reuse and have other parts of my API reusing those parent definitions. Tried all manner of different approaches, specially focusing on ResourceTypes but cannot understand how this concept will allow me to define a parent resource and a series of sub-resources that inherit the properties from the parent. Instead of describing my exact domain, maybe easiest to think about stereotypical pets API where I wish to define common properties for a pet e.g. name, and have specific sub-types e.g. dog, cat etc that add additional properties.

Also tried using json-schema pointers i.e. ‘$ref’ however these don’t seem to get expanded - well certainly not in the API console. Instead you just see the ‘$ref’ string.

How using RAML would one achieve such reuse?

Without this level of reuse am I going to have to type a gazillon lines and have a maintenance nightmare!

Love RAML so far, but really frustrated now… :wink:


Take a look at the example here. It makes use of parameterized resource types. As you can see most of the code is in the various resource types so when it comes to the resource definition you only have to define that which is different (or not included) in the resource type. You can think of the resource type as an OOP base class and the resource is a class that inherits from the resource type.

Also regarding the JSON Schema references not expanding. I think this is probably just a feature that hasn’t been implemented yet.


Thanks for the response.

The question really relates to how resource types allow you to define part of the schema in the resource type and part of the it in the resource. I cannot see how this is possible because when you define a schema object in the resource it replaces what is defined in the resource type. So resource types to me allow you to define things in one place or the another not both.

Interestingly, looking at your included json-schema files you are making use of json-schema pointers to bring about composition which I really what I need. I will try and externalise the json-schema files and see how the RAML console displays the schema definitions e.g. does it expand your notes collection $ref with the note schema object. Without that readers of your API (using RAML console) will not know what the note-schema definition is when looking an API that returns a collection.


As you have probably noticed by now the API console does not expand the JSON pointers :frowning: I plan on looking into this issue myself when I get some time.


Did you get this to work on RAML 0.8?


@Mark_Graves; that still seems an issue of the old JS parser for RAML .8 and therefore that does not seem to be fixed.