raml-org / raml-spec

RAML Specification
http://raml.org
3.87k stars 858 forks source link

Type declaration in response body with default media types #517

Closed dustinmoris closed 8 years ago

dustinmoris commented 8 years ago

Hi, I can't seem to get this working.

I have the following default media type at the top of my document: mediaType: [ application/json, application/xml ]

Then I have a custom type declared:

types:
  MyType:
    type: object
    properties:
      status: string
      message: string

Now I would like to specify that the response object of an API call will be of that type:

responses:
      200:
        body:
          type: MyType

but unfortunately this doesn't seem to get parsed as valid RAML. It seems like I have to place the media type in between the body and type declaration, but that defeats the whole purpose of the default media type at the top. What am I doing wrong?

andjarnic commented 8 years ago

I saw this same issue but because I have always used the media type, I didnt think nothing of it. I see in the spec/examples where it shows that you can avoid using it if you declare the media type like you have, so I assume it should allow what you have here?

dustinmoris commented 8 years ago

I am using the Anypoint platform to document my API. Perhaps it is an issue in the designer, but how can I validate that? What is the official way of validating my RAML?

ddenisenko commented 8 years ago

@dustinmoris,

RAML looks valid according to the spec.

Here is the JSON output of RAML parser for the method:

...
"methods": [
        {
          "responses": {
            "200": {
              "code": "200",
              "body": {
                "application/json": {
                  "name": "application/json",
                  "displayName": "application/json",
                  "type": [
                    "MyType"
                  ],
                  "repeat": false,
                  "required": true
                },
                "application/xml": {
                  "name": "application/xml",
                  "displayName": "application/xml",
                  "type": [
                    "MyType"
                  ],
                  "repeat": false,
                  "required": true
                }
              }
            }
          },
          "protocols": [
            "HTTPS"
          ],
          "method": "get"
        }
      ],
...

So, this should work.

Checked in latest API Designer, and in the one deployed to Anypoint. Looks working too:

apidesignermediatype

What exactly fails for you and in which tool?

sichvoge commented 8 years ago

@dustinmoris any news on that, or can i close it?

dustinmoris commented 8 years ago

Yup that can be closed. Worked for me as well. Thank you!

sichvoge commented 8 years ago

Perfect! thanks!