I like how RAML can dynamically refer to different schemas when declaring a resourceType type:
resourceTypes: - collection: get: responses: 200: body: application/json: schema: <<schema>> post: body: application/json: schema: <<schema>>Create responses: 200: body: application/json: schema: <<schema>>
Here I can use it as
/users: type: { collection: { schema: user } }
and RAML will give me user schema responses from GET and POST, as well as a userCreate schema for sending POST requests. Cool! Now I can reuse the definition of my collection with many different schemas.
But now that I want to have a json example for everything, I was hoping to use <<schema>> var in another way to use "code reuse". I was hoping I could do
resourceTypes: - collection: get: responses: 200: body: application/json: schema: <<schema>> example: examples/v1-<<schema>>.json post: body: application/json: schema: <<schema>>Create example: examples/v1-<<schema>>-create.json responses: 200: body: application/json: schema: <<schema>> example: examples/v1-<<schema>>.json
but unfortunately this does not work. I get an error
error: File with path "/examples/v1-%3C%3Cschema%3E%3E.json" does not exist
So now I resorted to manually adding this to all my collections, and the /users example above was
/users: type: { collection: { schema: user } } get: responses: 200: body: application/json: example: !include examples/v1-user.json post: body: application/json: example: !include examples/v1-user-create.json responses: 200: body: application/json: example: !include examples/v1-user.json
For me, this is too much overhead to add examples. Especially when I want to repeat the pattern across many resources.
Question: Is there a way to do this?
raml
Eric Olson
source share