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

String example breaks UI #2369

Closed
morris opened this issue Aug 31, 2016 · 3 comments
Closed

String example breaks UI #2369

morris opened this issue Aug 31, 2016 · 3 comments

Comments

@morris
Copy link

morris commented Aug 31, 2016

Consider this Swagger File:

{
  "swagger": "2.0",
  "info": {
    "version": "1.0",
    "title": "Bug"
  },
  "paths": {
    "/": {
      "get": {
        "description": "Bug",
        "responses": {
          "200": {
            "description": "Ok",
            "schema": {
              "properties": {
                "test": {
                  "type": "string",
                }
              }
            },
            "examples": {
              "application/json": "{}"
            }
          },
        }
      }
    }
  }
}

Importing this into Swagger UI 2.2.2 breaks with "jsyaml is not defined". Change the examples.application/json value to an unquoted {}, and it will work. Looks like Swagger UI expects an object there, even though a string is valid JSON, too.

Putting JSON inside a string example is not intended by the spec (http://swagger.io/specification/#exampleObject) but I would not expect Swagger UI to break. Maybe a console warning is enough.

Thanks for your effort!

@JodyLognoul
Copy link

+1

@kshakir
Copy link

kshakir commented Sep 24, 2016

This is the commit that seems to have caused the issue of "jsyaml is not defined": e4dc264
A git bisect on master returns: 515f142

The js-yaml js file is still present in this repo, and re-adding it back to dist/index.html seems to fix this issue. I don't know if re-adding the js regresses #2221. As I don't know how to test that issue, I'm forgoing a PR at this time.

FYI: Instead of the json reported earlier, we're using yaml and are having the same issue with a using a string value.

Broken

swagger: '2.0'
info:
  title: Debug Yaml
  version: '2369'
paths:
  '/example':
    get:
      responses:
        '200':
          schema:
            properties:
          examples:
            application/json: |
              {}

Working

swagger: '2.0'
info:
  title: Debug Yaml
  version: '2369'
paths:
  '/example':
    get:
      responses:
        '200':
          schema:
            properties:
          examples:
            application/json: {}

richvdh added a commit to matrix-org/matrix.org that referenced this issue Nov 22, 2016
... mostly to see if it fixes
matrix-org/matrix-spec-proposals#736 (it doesn't).

This necessitates the addition of js-yaml to index.html to work around
swagger-api/swagger-ui#2369.

Also includes patches to make the sourcemaps in swagger-ui.js work right.
gilbode added a commit to gilbode/swagger-ui that referenced this issue Mar 17, 2017
…es don't fail

to render with cannot find jsyaml.  Make it tolerant to parsing errors.
@webron
Copy link
Contributor

webron commented Mar 24, 2017

No longer an issue in 3.X.

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

4 participants