ResourceTypes


#1

Can I do the following?

resourceTypes
- collection
   get:
     responses:
        200:
           body:
              schema: <<resourcePathName>> # e.g. users

  post:
     responses:
        200:
           body:
              schema: <<resourcePathName | !singularize>>  # e.g. user

 /users:
      type: collection
      is: [ secured ] 
      get:
        responses:
          400:
          description: There was a problem with the client's request
          body:
             application/json:
                schema: <<error response schema >>

#2

@jayn:
What are you trying to do? (Actually, I’m writing some documentation about it right now).

The resourceTypes seem to be well defined, but remember that <> is a reserved parameter, so, the populated value will depend on the resource that is applying the type.

In this case, it will be resources and resource (for post).

I don’t see the “secured” trait defined on your code (maybe you copied a partial code).
But the weird thing I’m seeing is schema: <>. It is like if you were expecting some other kind of entity to reuse /users and to pass a parameter to it. I don’t think that makes sense, so I think you might be confusing and you would like to pass some particular schema to the /users get responses body. In that case, yes, you CAN overwrite the one defined in the resource type, but not using <<>>… Just writing the real value.

I’ll end like I started. What are you trying to do? If you describe it, I might be more helpful.
Cheers!


#3

Thanks very much for the reply. Apologies for not being clear. Here is what I am trying to do. If you look at the “collection” resourceType, I have two methods 1) get 2) post. However, below, for resource “users”, I have defined “type: collection” and also mentioned GET method with 400 error code.

My question: Is it okay to add additional error codes under a method under a resource, even though we’re using “type: collection” which only has one code i.e. 200?


#4

@jayn absolutely – you should be able to define additional details in a resource, even if it using a resourceType. Basically, resource types use a single-inheritance model. Resources can inherit from resourceTypes, and resourceTypes themselves can inherit from other resourceTypes in the same way. Any additional details you add to your RAML file in a resource or resourceType will be composed with the definition that you inherit.

Hope that helps!


#5

Excellent! Thanks a lot for the clarification.