Skip to content
New issue

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

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

Already on GitHub? # to your account

Uncaught Error: invalid keyPath #2918

Closed
shockey opened this issue Apr 15, 2017 · 3 comments
Closed

Uncaught Error: invalid keyPath #2918

shockey opened this issue Apr 15, 2017 · 3 comments

Comments

@shockey
Copy link
Contributor

shockey commented Apr 15, 2017

This spec:

swagger: '2.0'
info:
  description: >-
    This is a sample server Petstore server.  You can find out more about    
    Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net,
    #swagger](http://swagger.io/irc/).      For this sample, you can use the api
    key `special-key` to test the authorization     filters.
  version: 1.0.0
  title: Swagger Petstore
  termsOfService: 'http://swagger.io/terms/'
  contact:
    email: apiteam@swagger.io
  license:
    name: Apache 2.0
    url: 'http://www.apache.org/licenses/LICENSE-2.0.html'
host: petstore.swagger.io
basePath: /v2
tags:
  - name: pet
    description: Everything about your Pets
    externalDocs:
      description: Find out more
      url: 'http://swagger.io'
  - name: store
    description: Access to Petstore orders
  - name: user
    description: Operations about user
    externalDocs:
      description: Find out more about our store
      url: 'http://swagger.io'
schemes:
  - http
paths:
  /pet:
    post: null # <---------- null causes the error

causes a Uncaught Error: invalid keyPath error, which kills the React lifecycle. Refresh and load of a different spec is required to avoid.

This is especially bad for the Editor.

The error is originating here.

@shockey
Copy link
Contributor Author

shockey commented Apr 15, 2017

cc @webron

@webron
Copy link
Contributor

webron commented Apr 16, 2017

Thanks @shockey. FWIW, null is not a valid value anywhere in the spec.

@shockey
Copy link
Contributor Author

shockey commented Apr 17, 2017

@webron rightly so! Apologies, my initial description wasn't abundantly clear. There's a combination of things at work here:

  1. blank YAML values are translated to null for representation in JS. Consider this:
paths:
  /pet:
    post: 

The resulting JS object (or JSON even) would be:

{
  "paths": {
    "/pet": {
      "post": null
    }
  }
}

You'd never actually publish this in a spec (I hope), but this would be a common place to pause when you're handwriting a spec, so this mostly affects the Editor, in practice.

When we try to grab the operation at paths.pets.post for rendering, we get null back. That's not ideal, but harmless, except for the fact that....

  1. We assume elsewhere, that when we query a valid position at paths.[path].[method] in the spec, we'll get an object back.

Here is the culprit, as I mentioned earlier. The big problem is that this code is in a reducer, which is not covered under our React try/catch guard. So, when the error throws, it blows up the app's lifecycle, which requires a page refresh to fix.

shockey added a commit to shockey/swagger-ui that referenced this issue Apr 18, 2017
@lock lock bot locked and limited conversation to collaborators Jul 3, 2019
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Projects
None yet
Development

No branches or pull requests

2 participants