Skip to content
This repository has been archived by the owner on Sep 6, 2019. It is now read-only.

In OAS30, converter should output all content types for one peculiar path #44

Open
jsamr opened this issue Aug 2, 2018 · 2 comments
Open

Comments

@jsamr
Copy link

jsamr commented Aug 2, 2018

oas-raml-coverter version 1.1.35

/foo route with GET method serves two representations of the same resource, one simple and one more complex, but all with the same format (json). Both content types application/vnd.representation1+json and application/vnd.representation2+json should be defined in OAS path /foo, but only one gets picked.

Full reproduction

RAML Source

/foo:
  get:
    responses:
      200:
        body:
          'application/vnd.representation1+json':
            type:
              properties:
                foo1: string
          'application/vnd.representation2+json':
            type:
              properties:
                foo1: number

expected (oas3+json)

{
  "paths": {
    "/foo": {
      "get": {
        "responses": {
          "200": {
            "description": "",
            "content": {
              "application/vnd.representation1+json": {
                "schema": {
                  "properties": {
                    "foo1": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "foo1"
                  ]
                }
              },
              "application/vnd.representation2+json": {
                "schema": {
                  "properties": {
                    "foo1": {
                      "type": "number"
                    }
                  },
                  "required": [
                    "foo1"
                  ]
                }
              }
            }
          }
        },
        "operationId": "GET_foo"
      }
    }
  }
}

observed (oas3+json)

Only the last content type is picked.

{
  "paths": {
    "/foo": {
      "get": {
        "responses": {
          "200": {
            "description": "",
            "content": {
              "application/vnd.representation2+json": {
                "schema": {
                  "properties": {
                    "foo1": {
                      "type": "number"
                    }
                  },
                  "required": [
                    "foo1"
                  ]
                }
              }
            }
          }
        },
        "operationId": "GET_foo"
      }
    }
  }
}
@jsamr
Copy link
Author

jsamr commented Aug 2, 2018

The problematic code is at src/oas30/oas30MethodConverter.js#L146

if (!_.isEmpty(schema)) {
  response.content = {};
  response.content[val.mimeType || '*/*'] = media;
}

There should be an iteration over multiple mime types, instead of a direct assignment.
val is of type Body declared in oas-raml-converter-model which mimeType field is an optional string. This should be changed, perhaps Body.mimeTypes

@jsamr
Copy link
Author

jsamr commented Aug 9, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant