mashery / iodocs

Interactive API documentation system
MIT License
1.89k stars 415 forks source link

"SyntaxError: Unexpected token o" when adding a header parameter #212

Closed DavidBiesack closed 9 years ago

DavidBiesack commented 9 years ago

I'm trying out I/O Docs. I cloned this repo today and installed/ran it successfully (I can drive the rottentomatoes API for example).

I added a test API to the top of my apiconfig.json before klout.json and added the following to public/data/microurl.json

{ "basePath" : "http://djb.na.sas.com",
  "publicPath": "mu/rest",
  "name" : "MicroUrl URL shortening serice",
  "resources" : {
      "API Root" : {
          "methods" : {
              "getRoot" : {
                  "name" : "List API resources and collections",
                  "description" : "Get a list of links to all the API resources and collections",
                  "httpMethod" : "GET",
                  "path" : "/"
                  }
              }
          }
      }
  }
}

This stub API also works, but when I try to add an Accept header parameter to the getRoot method

              "getRoot" : {
                  "name" : "List API resources and collections",
                  "description" : "Get a list of links to all the API resources and collections",
                  "httpMethod" : "GET",
                  "path" : "/",
                  "parameters" : {
                      "Accept" : {
                          "description" : "The media type of the requested response body",
                          "location" : "header",
                          "required" : true,
                          "title" : "Accept",
                          "type" : [ "application/json", "application/xml" ]
                      }
                  }
              }

I get an exception when I click Try it! . I enabled debug in the config.json and see the following:


in processRequest
{ httpMethod: 'GET',
  oauth: '',
  methodUri: '/',
  accessToken: '',
  json: '',
  locations: '',
  apiKey: '',
  apiSecret: '',
  apiName: 'microurl' }
SyntaxError: Unexpected token o
    at Object.parse (native)
    at processRequest (/r/sanyo.unx.sas.com/vol/vol220/u22/sasdjb/dev/iodocs/app.js:613:17)
    at callbacks (/r/sanyo.unx.sas.com/vol/vol220/u22/sasdjb/dev/iodocs/node_modules/express/lib/router/index.js:161:37)
    at param (/r/sanyo.unx.sas.com/vol/vol220/u22/sasdjb/dev/iodocs/node_modules/express/lib/router/index.js:135:11)
    at pass (/r/sanyo.unx.sas.com/vol/vol220/u22/sasdjb/dev/iodocs/node_modules/express/lib/router/index.js:142:5)
    at Router._dispatch (/r/sanyo.unx.sas.com/vol/vol220/u22/sasdjb/dev/iodocs/node_modules/express/lib/router/index.js:170:5)
    at Object.router (/r/sanyo.unx.sas.com/vol/vol220/u22/sasdjb/dev/iodocs/node_modules/express/lib/router/index.js:33:10)
    at next (/r/sanyo.unx.sas.com/vol/vol220/u22/sasdjb/dev/iodocs/node_modules/express/node_modules/connect/lib/proto.js:190:15)
    at Object.dynamicHelpers [as handle] (/r/sanyo.unx.sas.com/vol/vol220/u22/sasdjb/dev/iodocs/app.js:1127:5)
    at next (/r/sanyo.unx.sas.com/vol/vol220/u22/sasdjb/dev/iodocs/node_modules/express/node_modules/connect/lib/proto.js:190:15)
10.23.16.105 - - [Tue, 07 Oct 2014 17:42:13 GMT] "POST /processReq HTTP/1.1" 500 - "http://djb.na.sas.com:3000/microurl" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.125 Safari/537.36"
mansilladev commented 9 years ago

Hi @DavidBiesack, update your parameter block to the following:

  "parameters" : {
      "Accept" : {
          "description" : "The media type of the requested response body",
          "location" : "header",
          "required" : true,
          "title" : "Accept",
          "enum" : [ "application/json", "application/xml" ],
          "type" : "string"
      }
  }

With yours, it was trying to parse "type" and ran into an unexpected array.

DavidBiesack commented 9 years ago

Thanks, that got me going.. However, rather than close this, I suggest leaving it open so error handling (on admittedly bad input) can be improved. Certainly this error (hidden in the console and not exposed in the UI) is cryptic.

Is there a JSON schema for I/O Docs? That would let me validate my JSON outside of the tool. Thanks.