Goal: create resourceTypes for CRUD endpoints without repeating myself.
(working with RAML 1.0 in Anypoint Studio and Mulesoft Design Center)
Let's start a couple resourceTypes for single action endpoints:
resourceTypes:
getItem:
get:
responses:
200:
body:
application/json
postItem:
post:
responses:
201:
body: null
deleteItem:
delete:
responses:
200:
body: null
So far, so good.
Now I want to create a resourceType for an endpoint that allows both GET and DELETE requests. This is valid:
getDeleteItem:
type: getItem
delete:
responses:
200:
body: null
... but I had to repeat the code from deleteItem, which I don't like.
These approaches do not work:
# the syntax for a union of types, does not work for resourceTypes
getDeleteItem:
type: getItem | deleteItem
# no error here, but everything after the first type reference is ignored
getDeleteItem:
type: { getItem, deleteItem }
Is there a better way?
I came up with an ugly workaround ("base" resourceTypes that each have their type set to a variable, so they can be strung together), but it seems to cause inconsistent errors and crashes in Mulesoft Design Center.