kyma-incubator/compass

Compass API returns modified API spec

crabtree opened this issue · 2 comments

Description

When fetching the API spec from the Director API the new line characters are removed in a way the overall Spec is no longer processable. I first faced this issue when I was trying to register the commerce-mock application from the xf-application-mocks. To make it simple I tried to register the package with the following spec (the description field contains two newlines characters)

"{\"swagger\":\"2.0\",\"info\":{\"title\":\"test\"},\"paths\":{\"/foo\":{\"get\":{\"parameters\": {\"description\":\"foo\n\nbar\"}}}}}"

The response returns the following:

"{\"swagger\":\"2.0\",\"info\":{\"title\":\"test\"},\"paths\":{\"/foo\":{\"get\":{\"parameters\": {\"description\":\"foo\bar\"}}}}}"

Another problem appeared when I tried to register the API spec with a description that contains a single newline character. For example:

"{\"swagger\":\"2.0\",\"info\":{\"title\":\"test\"},\"paths\":{\"/foo\":{\"get\":{\"parameters\": {\"description\":\"foo\nbar\"}}}}}"

In this case, the API returns the following error:

{
  "errors": [
    {
      "message": "Unexpected <Invalid>",
      "locations": [
        {
          "line": 1,
          "column": 344
        }
      ]
    }
  ],
  "data": null
}

Expected result

Compass API should be able to store and return unchanged API specifications.

Actual result

Compass API returns API specification which differs from the initial one. It may lead to a crash of the JSON parser.

Steps to reproduce

See the description.

Troubleshooting

@crabtree please test again after the fix from #1732

@dpanayotov looks good, thanks