How to parameterize media type in response body


#1

E.g., this doesn’t work:

#%RAML 1.0
title: Parameterizing media type gives "invalid media type" error
resourceTypes:
  thingy:
   get:
      responses:
        200:
          body:
            <<mediaType>>:
              type: file
/books:
  type:
    thingy:
      mediaType: application/json

I am trying to document an existing API for which this would greatly improve maintainability.

Thanks,
Kevin


#2

Pl, try using Accept header to identify the response mediaType. Here is the updated sample RAML definition:

#%RAML 1.0
title: Parameterizing media type gives "invalid media type" error
version: v1
baseUri: http://0.0.0.0:8081/api/{version}
protocols: [ HTTP, HTTPS ]
mediaType: [application/json, application/xml ]

documentation:
  - title: Sample API to return the thingy status
    content: |
      The interface exposes status of the Server in various response format.

resourceTypes:
  thingy:
   get:
      responses:
        200: # HTTP status code
          body: # declare content of response
              text/html: # media type
	        type: file
                example: 
              application/json:
	        type: file
                example: 
              application/xml:
	        type: file
                example: 
/books:
  type:
    thingy:
      mediaType: application/json

#3

@nirajtrip, this is actually not the problem but rather that the parser has a bug! Raised it here.


#4

Update: https://github.com/raml-org/raml-js-parser-2/issues/760