petrochenko-pavel-a / raml-js-parser2-issues

0 stars 0 forks source link

Allow defining multiple default media types #46

Closed VasiliyLysokobylko closed 8 years ago

VasiliyLysokobylko commented 8 years ago

Defining a default media type has been described in RAML 0.8 as a mechanism to define the default media type returned by API responses, and expected from API requests that accept a body.

The proposal is to extend that to be able to define a list of default media types with the premise that all of them are described by exactly the same types and /or examples.

#%RAML 1.0
title: New API
mediaType: [ application/json, application/xml]
types:
  Person:
/list:
  get:
    responses:
      200:
        body: Person[]
/send:
  post:
    body: Person

The equivalent RAML to the example above is:

#%RAML 1.0
title: New API
types:
  Person:
/list:
  get:
    responses:
      200:
        body:
          application/json: Person[]
          application/xml: Person[]
/send:
  post:
    body:
      application/json: Person
      application/xml: Person

If you have cases where you need to override the default behaviour, you MAY define media types explicitly when describing your API response or request. The following example illustrates that:

#%RAML 1.0
title: New API
mediaType: [ application/json, application/xml]
types:
  Person:
  Another:
/list:
  get:
    responses:
      200:
        body: Person[]
/send:
  post:
    body:
      application/json:
        type: Another
VasiliyLysokobylko commented 8 years ago

https://github.com/raml-org/raml-spec/issues/234

sichvoge commented 8 years ago

Just to comment here as well; its seems the parser has no problems with mediaType: [ application/json, application/xml ], but complains in any body node:

#%RAML 1.0
title: API with Types
mediaType: [ application/json, application/xml ] # no error

/users/{id}:
  get:
    responses:
      200:
        body:
          description: jfkdsjhfk # error saying 'invalid media type'

changing the media type back to only one, the error disappears.