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

Swagger replaces quotes with angled quotes in documentation #5060

Closed
veqryn opened this issue Dec 1, 2018 · 7 comments
Closed

Swagger replaces quotes with angled quotes in documentation #5060

veqryn opened this issue Dec 1, 2018 · 7 comments

Comments

@veqryn
Copy link

veqryn commented Dec 1, 2018

In our documentation we have example curl calls and other things using single ' and double " quotes.

For whatever reason, when Swagger pulls in this documentation it insists on replacing the quotes with single ‘’ and double “” angled quotes.

Here is an example of what it looks like:
image

This is a bug because when our users copy and paste these commands into their shell, they don't work because of the angled quotes.

We are using swagger docker image: swaggerapi/swagger-ui:v3.19.3

And it is the API_URLS environment variable to pull the swagger json from another url.

The contents of the swagger json start with:

{
  "swagger": "2.0",
  "info": {
    "title": "Foobar Service",
    "description": "\u003cbr\u003e\u003cp\u003eExample of a simple GET request via curl with bearer HTTP Authentication:\u003c/p\u003e\u003cpre\u003ecurl -X GET \"https://foobar.com/stuff\" -H \"Accept: application/json\" -H \"Authorization: Bearer abc123.xyz.789\"\u003c/pre\u003e",
    "version": "2.0"
  },
  "paths": {}
}
@hkosova
Copy link
Contributor

hkosova commented Dec 3, 2018

Try using Markdown formatting instead of HTML tags. In Markdown, you can make code blocks by indenting the lines by four spaces or wrapping them in triple backticks ```.

JSON version:

"description": "Example of a simple request via curl:\n\n    curl -X POST \"https://api.foobar.com/stuff\" -H \"Accept: application/json\" -H \"Content-Type: application/json\" -d ''{}''",

or

"description": "Example of a simple request via curl:\n\n```curl -X POST \"https://api.foobar.com/stuff\" -H \"Accept: application/json\" -H \"Content-Type: application/json\" -d ''{}''```",

YAML version (to illustrate the original formatting):

info:
  description: >-
    Example of a simple request via curl:

        curl -X POST "https://api.foobar.com/stuff" -H "Accept: application/json" -H "Content-Type: application/json" -d ''{}''

# or

info:
  description: >-
    Example of a simple request via curl:

    ```
    curl -X POST "https://api.foobar.com/stuff" -H "Accept: application/json" -H "Content-Type: application/json" -d ''{}''
    ```

@shockey
Copy link
Contributor

shockey commented Dec 3, 2018

Hi @veqryn, I'm not able to reproduce this.

Using this string as an input to Swagger UI:

{
  "swagger": "2.0",
  "info": {
    "title": "Foobar Service",
    "description": "\u003cp\u003eExample of a simple request via curl:\u003c/p\u003e\u003cpre\u003ecurl -X POST \"https://api.foobar.com/stuff\" -H \"Accept: application/json\" -H \"Content-Type: application/json\" -d '{}'\u003c/pre\u003e",
    "version": "1.0"
  }
}

in Chrome 70, all quotation-like marks that Swagger UI renders into the Info section are either U+0022 quotation marks or U+0027 apostrophes, according to this Unicode character identifier.

Perhaps this is a browser bug? (You didn't fill out the information section of the template, so I don't know what you're using).

@shockey
Copy link
Contributor

shockey commented Dec 3, 2018

PS: you don't need to use escape codes to write HTML in your description, this will work fine:

info:
  description: '<p>Example of a simple request via curl:</p><pre>curl -X POST "https://api.foobar.com/stuff" -H "Accept: application/json" -H "Content-Type: application/json" -d ''{}''</pre>'

But, as @hkosova mentioned, taking advantage of Markdown's readability is even better.

@veqryn
Copy link
Author

veqryn commented Dec 3, 2018

@shockey Here is an easy reproducer:

  1. Open http://editor.swagger.io/#edit
  2. Delete all contents, then replace with:
{
  "swagger": "2.0",
  "info": {
    "title": "Foobar Service",
    "description": "\u003cbr\u003e\u003cp\u003eExample of a simple GET request via curl with bearer HTTP Authentication:\u003c/p\u003e\u003cpre\u003ecurl -X GET \"https://foobar.com/stuff\" -H \"Accept: application/json\" -H \"Authorization: Bearer abc123.xyz.789\"\u003c/pre\u003e",
    "version": "2.0"
  },
  "paths": {}
}

I see the quotes replaced every time I do this. Please let me know if you do not.

@shockey
Copy link
Contributor

shockey commented Jan 15, 2019

Confirmed.

To be clear: the definition itself still has regular quotation marks, but the rendered content uses smart quotes.

@shockey
Copy link
Contributor

shockey commented Feb 7, 2019

Fixed! Thanks for the help @veqryn 👍

@veqryn
Copy link
Author

veqryn commented Feb 7, 2019

Thank you!

@lock lock bot locked and limited conversation to collaborators Feb 7, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants