Complex resourceTypes, define a not required method


#1

Hi there,
I’m a developer from Stamplay. I’am trying to use Raml for creating our api’s documentation.
We have a very complex apis system, with a lot of resources and subresource.
My problem is to create optional http methods, I try to explain the problem with code:

 - collection-item:
      description: Entity representing a <<resourcePathName|!singularize>> in Stamplay app
      get:
        description: |
         Get the <<resourcePathName|!singularize>>
         with id = {<<resourcePathName|!singularize>>Id}
        responses:  
          200:
            body:
              application/json:
                example: <<itemGetResponse>>
          404:
            body:
              text/plain: 
                example: <<itemErrorResponse>>
      put:
        description: |
          Modify the <<resourcePathName|!singularize>>
          with id = {<<resourcePathName|!singularize>>Id}
        body:
          application/json:
            schema: <<itemPutRequest>>
        responses:
          200:
            body:
              application/json:
                example: <<itemPutResponse>>

For a lot of my endpoints this resourceTypes is perfect but have a problem when i have an endpoint with
type collection-item without a PUT endpoint.

It’s possible make method of resource types optional? There are work-arounds?
I have studied the documentation but I couldn’t find anything that would solve my problem.
Thanks
Cristian Roselli


#2

yes, of course for example

  #%RAML 0.8
title: Example of Optional Properties
resourceTypes:
  - auditableResource
      post?:
        body:
          createAuthority:
            description: |
              If the resource has a post method defined, expect a createAuthority
              property in its body
      delete?:
        body:
          deleteAuthority:
            description: |
              If the resource has a delete method defined, expect a deleteAuthority
              property in its body

Represents resource type with two optional methods (see optional properties of resource types and traits description at http://raml.org/spec.html)

Regards,
Pavel


#3

Thank Pavel. It works!
Sorry but have another question.
In the code I have wrote, I use Reserved Parameters (IE: <>).
When use Mulesoft editor for Raml file, even if the method is optional, the endpoint is still asking for the definition of Reserved Parameters. It’s a Mulesoft editor problem or I don’t understand something?
Cristian Roselli


#4

In the code I have wrote, I use Reserved Parameters (IE: <>).
Yes , you still have to define them because of the fact that they are needed to resolve resource type.

Regards,
Pavel