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

Error using JSON editor with array of $ref objects #2659

Closed
scottohara opened this issue Feb 9, 2017 · 5 comments
Closed

Error using JSON editor with array of $ref objects #2659

scottohara opened this issue Feb 9, 2017 · 5 comments

Comments

@scottohara
Copy link
Contributor

One of my end users has reported a problem when using type: "array" in the schema of a request body parameter.

On closer inspection, the error only appears when the jsonEditor is set to true.

The error is:
Uncaught TypeError: Cannot read property 'required' of undefined, and occurs in the following line in lib/jsoneditor.min.js:

s.required && Array.isArray(s.required) && e.schema.required && Array.isArray(e.schema.required) && (n.required = e.schema.required.concat(s.required)));

(s is the undefined reference. s is assigned a few lines above as s = this.types[t]; and the problem seems to be that this.types is an empty array - [])

Below is a reduced YAML example that should demonstrate the issue.

  1. Set jsonEditor to false and the API renders correctly
  2. Set jsonEditor to true and the above error occurs
swagger: "2.0"
info:
  title: "array test"
paths:
  /test:
    post:
      parameters:
      - in: "body"
        name: "FooList"
        required: true
        schema:
          $ref: "#/definitions/FooList"
      responses:
        200:
          description: "200 response"
definitions:
  Foo:
    type: "object"
    properties:
      unique_id:
        type: "string"
  FooList:
    type: "array"
    items:
      $ref: "#/definitions/Foo"
@zeConehead
Copy link

Just noticed the same error!

@iamsimakov
Copy link

The same problem. It's real cool feature. Guys, are you going to fix it? Thanks

@cabbonizio
Copy link

One of my teammates reported this last week and wanted to show another hand that we are affected also.

@iamsimakov
Copy link

iamsimakov commented Feb 14, 2017

it works if maximize jsoneditor.min.js and simplify ternary operator in 2583 line to view:

n = i({}, e.schema), n.type = s
// was:
// "string" == typeof s ? (n = i({}, e.schema), n.type = s) : 
// (n = i({}, e.schema, s), n = e.jsoneditor.expandRefs(n), s.required && Array.isArray(s.required) && e.schema.required && Array.isArray(e.schema.required) && (n.required = e.schema.required.concat(s.required)));

But I don't know what the meaning of these lines. Anyway thanks for Swagger UI.
JSON editor in swagger ui is not like as editor on official page http://editor.swagger.io/ (there is 'Try this operation')
Does anybody know how to integrate json editor from oficial page to project?

@scottohara
Copy link
Contributor Author

It seems that this issue can be resolved by updating to the latest version (v0.7.28) of the JSON editor. (Version currently used in this project is v0.7.22)/

Pull request coming shortly....

@fehguy fehguy closed this as completed in 911b9e0 Feb 22, 2017
fehguy added a commit that referenced this issue Feb 22, 2017
Update jsoneditor from v0.7.22 to v0.7.28 (Fixes #2659)
kodekracker pushed a commit to 91springboard/swagger-ui that referenced this issue Mar 2, 2017
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