Can resource types define nested resources?


#1

In Rails, I can write resources :someresource in the routes file, and it will generate a bunch of standard routes. When I try to capture that with resource types in the RAML API Designer I get an error stating “resource type cannot define child resources”:

#%RAML 0.8
title: Example API
resourceTypes:
  - standardResource:
      get:
      /new:
        get: 
      post:
      /{id}:
        get:
        /edit:
          get:
        patch:
        put:
        delete:
/some-resource:
  type: standardResource

But I didn’t see anything in the spec specifically prohibiting nested resources in resource types. Is it allowed?


#2

It’s not allowed, and it’s a decision we made very early on – early enough to have lost the explicit prohibition of this in the spec. I just updated the spec to reflect this explicitly. It was part of a section that clarified all the differences between a resource definition and a resourceType definition, and similarly between methods and traits.

We can definitely discuss the possibilities of nested resources in resource types for future RAML versions, but it gets messy quickly.


#3

Just ran into this myself, actually. I wanted to create a resourceType that standardized a specific set of resources that are repeated at several levels of resource hierarchy. Sort of like the following (i’ve omitted everything but the resource paths for clarity):

/someResource:
  /properties:
  /docs:
  /actions:
/someOtherResource:
  /properties:
  /docs:
  /actions:
etc.

It’s going to be an incredible pain to have to redeclare every one of those resources without the benefit of being able to use a template of some kind. Maybe traits is the answer? but I don’t think those support templating like <>, or do they?

If none of the above are going to work, where do I +1 nested resource types (or child resources in a resource type)?

Regards