uriParameters in traits?


#1

I’m pretty sure I’ve seen an example using uriParameters inside a trait definition, but I can’t find it right now. It doesn’t seem to be mentioned specifically in version 0.8 of the spec, so… perhaps it was a bad example, or I missed something key.

What I’d like to be able to do is use a particular kind of id in different resource paths, then say this resource is has that trait, to pick up the specification for what that uri parameter really is, instead of spelling it out again for each resource path that uses it.

Is there a way to do that?

-Fred


#2

Was this a difficult question, or am I using traits incorrectly in some way that’s obvious to everyone else?


#3

Go to http://raml.org/docs-200.html#traits

traits:
  - client-id-required:
      queryParameters:
        client_id:
          type: string
          required: true
        client_secret:
          type: string
          required: true

#4

I’ve seen the examples showing queryParameters, and I understand the spelling, but processors complain if I try to do that with uriParameters, which is why I asked.


#5

Hey fdrake,
I believe the reason you’re running into issues is that traits are applied at the method level, not the resource level.

Because RAML is designed for an HTTP REST-based API, you cannot manipulate the resource from within its child (ie the method) but instead any URI Parameters would need to be across the board for all it’s methods.

queryParameters on the other hand are explicit to the method, as you would probably not want queryParameters within your POST method.

Hopefully this helps clarify why you’re not able to use traits with uriParameters. In the case you mentioned above, I would look at using resourceTypes - as those are defined to provide a template for the resource as a whole and would be able to meet your needs.

Any other questions just let me know.

Good luck,
Mike


#6

Great explanation; thanks, Mike! I’ll have to play around with resource types.