Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Line breaks lost on bundle() #112

Open
timothymcmackin opened this issue Mar 21, 2019 · 3 comments
Open

Line breaks lost on bundle() #112

timothymcmackin opened this issue Mar 21, 2019 · 3 comments

Comments

@timothymcmackin
Copy link

timothymcmackin commented Mar 21, 2019

I'm using swagger-parser.bundle to pull in external examples in my Swagger file via $ref. I'm noticing that in certain cases, the line breaks in the external files are lost.

For example, check out this gist, which I adapted from petstore v2:
https://gist.github.com/timothymcmackin/0f9a7edd694252f38f8df1426a01c395

In my swagger, I have this $ref:

"x-code-samples": [
  {
    "lang": "shell",
    "source":{
      "$ref": "example.sh"
    }
  }
]

example.sh is a two-line file:

curl "https://petstore.swagger.io" \
--data-urlencode "petname=Roscoe"

When I transform (see resolve.js in the gist), the output document loses the line breaks:

"x-code-samples": [
  {
    "lang": "shell",
    "source": "curl \"https://petstore.swagger.io\" \\ --data-urlencode \"petname=Roscoe\""
  }
]

However, if I change example.sh to this:

curl "https://petstore.swagger.io" \
--data-urlencode "petname=Roscoe: "

the output retains the line breaks:

"x-code-samples": [
  {
    "lang": "shell",
    "source": "curl \"https://petstore.swagger.io\" \\\r\n--data-urlencode \"petname=Roscoe: \"\r\n"
  }
]

There's something about having that : in the external file that makes the line breaks stay in. Is there some bug here that's making the line breaks drop out?

Edit: I'm using swagger-parser v6.0.5.

@timothymcmackin timothymcmackin changed the title Line breaks lost on bundle resolve Line breaks lost on bundle() Mar 21, 2019
@timothymcmackin
Copy link
Author

I've been over this a few times and it does not seem to have anything to do with unix vs dos line breaks in the files.

@timothymcmackin
Copy link
Author

Possible workaround:

  const myParser = {
    order: 1,
    parse(file) {
      return file.data.toString();
    }
  };

  const bundleOptions = {
    parse: {
      text: myParser,
    },
  };

  return new Promise((resolve) => {
    SwaggerParser.bundle(passedSourceFile, bundleOptions, (err, api) => {
      resolve(api);
    });
  });

@timothymcmackin
Copy link
Author

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

No branches or pull requests

1 participant