question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Uncaught Type Error: cannot read property $ref of undefined

See original GitHub issue

I am not sure why I am getting the following error. It occurred after generating my Swagger resources via swagger-php:

Uncaught TypeError: Cannot read property '$ref' of undefined swagger.js:698
SwaggerOperation swagger.js:698
SwaggerResource.addOperations swagger.js:471
SwaggerResource.addApiDeclaration swagger.js:402
obj.on.response swagger.js:357
res.response swagger.js:1307
EventEmitter.emit shred.bundle.js:1391
emit shred.bundle.js:1191
(anonymous function) shred.bundle.js:1211
setBodyAndFinish shred.bundle.js:1815
(anonymous function) shred.bundle.js:1832
EventEmitter.emit shred.bundle.js:1388
Response.handle shred.bundle.js:2715
xhr.onreadystatechange

My Swagger resources did not throw any upon doc generation. Here is what my resource looks like:

{
    "basePath":"https://myapp.com/v1",
    "swaggerVersion":"1.2.0",
    "apiVersion":"1.0.0",
    "resourcePath":"v1",
    "apis":[
        {
            "path":"/copyResources/",
            "description":"copyResources(): Handler to copy resources. Gets the user's home directory and prepends the home directory to each passed in path. Calls copyResources on the file controller with the full paths. This is available to users with the \"upload\"  permission.",
            "operations":[
                {
                    "method":"GET",
                    "summary":"Copies the specified file paths to the specified destination path",
                    "nickname":"copyResources",
                    "parameters":[
                        {
                            "paramType":"query",
                            "name":"filePaths",
                            "type":"array",
                            "required":true,
                            "description":"Remote paths of the files or folders to copy"
                        },
                        {
                            "paramType":"query",
                            "name":"destinationPath",
                            "type":"string",
                            "required":true,
                            "description":"Remote destination path to copy files/folders to"
                        }
                    ],
                    "responseMessages":[
                        {
                            "code":200,
                            "message":"OK"
                        }
                    ]
                }
            ]
        },
        {
            "path":"/createFolder/",
            "description":"createFolder(): Handler to create a new folder. Gets the user's home directory and calls create folder on the file controller with the full path. This is available to users  with the \"upload\" permission.",
            "operations":[
                {
                    "method":"GET",
                    "summary":"Get the user's home directory and calls getFolders on the file controller with the full path",
                    "nickname":"createFolder",
                    "parameters":[
                        {
                            "paramType":"query",
                            "name":"folderName",
                            "type":"string",
                            "required":true,
                            "description":"Name of the folder to create"
                        },
                        {
                            "paramType":"query",
                            "name":"path",
                            "type":"string",
                            "required":true,
                            "description":"Where to create the folder"
                        }
                    ],
                    "responseMessages":[
                        {
                            "code":200,
                            "message":"OK"
                        }
                    ]
                }
            ]
        },
        {
            "path":"/getFolders/",
            "description":"getFolders(): Handler to get folder list Gets the user's home directory and calls getFolders on the file  controller with the full path",
            "operations":[
                {
                    "method":"GET",
                    "summary":"Get the user's home directory and calls getFolders on the file controller with the full path",
                    "nickname":"getFolders",
                    "parameters":[
                        {
                            "paramType":"query",
                            "name":"path",
                            "type":"string",
                            "required":true,
                            "description":"The remote file path"
                        }
                    ],
                    "responseMessages":[
                        {
                            "code":200,
                            "message":"OK"
                        }
                    ]
                }
            ]
        },
        {
            "path":"/getResourceList/",
            "description":"getResourceList(): Handler for folder / file path listing Gets the user's home directory and calls getResourceList on the file controller  with the full path. This is available to users with the \"list files\" permission.",
            "operations":[
                {
                    "method":"GET",
                    "summary":"Get a listing of files/folders for the specified path. Available for users with list files permission",
                    "nickname":"getResourceList",
                    "parameters":[
                        {
                            "paramType":"query",
                            "name":"path",
                            "type":"string",
                            "required":true,
                            "description":"The remote file path"
                        },
                        {
                            "paramType":"query",
                            "name":"sortBy",
                            "type":"string",
                            "required":true,
                            "description":"Sort according to attribute"
                        },
                        {
                            "paramType":"query",
                            "name":"sortOrder",
                            "type":"string",
                            "required":true,
                            "description":"Sort in either ascending or descending order"
                        },
                        {
                            "paramType":"query",
                            "name":"offset",
                            "type":"integer",
                            "required":true,
                            "description":"Determines which item to start on for pagination"
                        },
                        {
                            "paramType":"query",
                            "name":"limit",
                            "type":"integer",
                            "required":true,
                            "description":"The number of files to limit the result"
                        },
                        {
                            "paramType":"query",
                            "name":"detailed",
                            "type":"boolean",
                            "description":"If true, returns sharedFolder, notifications or other objects associated with specified path"
                        },
                        {
                            "paramType":"query",
                            "name":"pattern",
                            "type":"string",
                            "description":"Regex string. If not null, perform a search with specified pattern"
                        }
                    ],
                    "responseMessages":[
                        {
                            "code":200,
                            "message":"OK"
                        }
                    ]
                }
            ]
        },
        {
            "path":"/moveResources/",
            "description":"moveResources(): Handler to move resources. Gets the user's home directory and prepends it to each passed in path. Calls moveResources on the file controller with the full paths. This is  available to users with the \"upload\" permission.",
            "operations":[
                {
                    "method":"GET",
                    "summary":"Moves the specified file paths to the specified destination path",
                    "nickname":"moveResources",
                    "parameters":[
                        {
                            "paramType":"query",
                            "name":"filePaths",
                            "type":"array",
                            "required":true,
                            "description":"Remote paths of the files or folders to move"
                        },
                        {
                            "paramType":"query",
                            "name":"destinationPath",
                            "type":"string",
                            "required":true,
                            "description":"Remote destination path to move files/folders to"
                        }
                    ],
                    "responseMessages":[
                        {
                            "code":200,
                            "message":"OK"
                        }
                    ]
                }
            ]
        }
    ],
    "produces":[
        "application/json",
        "application/xml",
        "text/plain",
        "text/html"
    ]
}

Does anyone have any idea why this might be?

Issue Analytics

  • State:closed
  • Created 10 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

7reactions
gregwebscommented, Mar 5, 2016

Can swagger output a descriptive error message rather than throw a runtime exception with little information?

When I past into the swagger editor, I see very useful information and it still renders the HTML

✖ Swagger Error
Missing required property: items
Jump to line 148
Details
 Object
6reactions
fehguycommented, Mar 12, 2014

Yes, if you’re passing an array, you have to specify the inner type of the array like such:

primitive array values

{
  "type": "array",
  "items": {
    "type": "string"
  }
}

complex array values

{
  "type": "array",
  "items": {
    "$ref": "User"
  }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot read property 'ref' of undefined - Stack Overflow
I'm building a simple web app with Vue + Firebase + Vuefire and I get "Uncaught TypeError: Cannot read property 'ref' of undefined"...
Read more >
Cannot read property 'ref' of undefined Firebase-storage react ...
Coding example for the question TypeError: Cannot read property 'ref' of undefined Firebase-storage react-Reactjs.
Read more >
Cannot read properties of undefined (reading createRef)
This page will help you to understand and solve this issue: https://typeofnan.dev/fix-cannot-read-property-map-of-undefined-error-in-react/.
Read more >
Uncaught TypeError: Cannot read property of undefined In
Uncaught TypeError : Cannot read property of undefined ... JavaScript TypeError is thrown when an operand or argument passed to a function is...
Read more >
Refs is not there (Cannot read properties of undefined ... - Reddit
function() executes in the context it's called. That means this.$refs is not defined. Either use an arrow function or assign this.$refs to ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found