Skip to content
This repository has been archived by the owner on Sep 14, 2022. It is now read-only.

Hello World Endpoint throwing Exception #348

Closed
BigMrSunshine opened this issue Feb 8, 2016 · 8 comments
Closed

Hello World Endpoint throwing Exception #348

BigMrSunshine opened this issue Feb 8, 2016 · 8 comments

Comments

@BigMrSunshine
Copy link

I followed the instructions on the quick start page, selecting express as the framework.

When I hit the endpoint with curl, I get a truncated json response message:

{"message":"Res

The error below shows up on the console.

Thanks!

SyntaxError: Response validation failed: value expected to be an array/object but is not
    at Object.parse (native)
    at validateValue (/hdd/home/cpetty/projects/swagger/hello-world/node_modules/swagger-tools/middleware/swagger-validator.js:127:20)
    at ServerResponse.res.end (/hdd/home/cpetty/projects/swagger/hello-world/node_modules/swagger-tools/middleware/swagger-validator.js:254:9)
    at ServerResponse.send (/hdd/home/cpetty/projects/swagger/hello-world/node_modules/express/lib/response.js:204:10)
    at ServerResponse.json (/hdd/home/cpetty/projects/swagger/hello-world/node_modules/express/lib/response.js:249:15)
    at hello (/hdd/home/cpetty/projects/swagger/hello-world/api/controllers/hello_world.js:43:7)
    at swaggerRouter (/hdd/home/cpetty/projects/swagger/hello-world/node_modules/swagger-tools/middleware/swagger-router.js:407:20)
    at swagger_router (/hdd/home/cpetty/projects/swagger/hello-world/node_modules/swagger-node-runner/fittings/swagger_router.js:31:5)
    at null.<anonymous> (/hdd/home/cpetty/projects/swagger/hello-world/node_modules/bagpipes/lib/bagpipes.js:171:7)
    at bound (domain.js:280:14)
@BigMrSunshine
Copy link
Author

I did add some logging in swagger-validator when the validation fails:

`

  if (isModel) {
    if (_.isString(val)) {
      try {
        val = JSON.parse(val);
      } catch (err) {
        console.log("Petty - val: " + val);
        console.log("Petty - err: " + err);
        err.failedValidation = true;
        err.message = 'Value expected to be an array/object but is not';

        throw err;
      }
    }`

Petty - val: Hello, Scott!
Petty - err: SyntaxError: Unexpected token H

Thanks

@theganyo
Copy link
Contributor

theganyo commented Feb 8, 2016

@BigMrSunshine -

It looks like the template is actually wrong and some new validation logic in a library picked it up. Quick fix, change your swagger.yaml to have this:

definitions:
  HelloWorldResponse:
    type: string

Instead of this:

definitions:
  HelloWorldResponse:
    required:
      - message
    properties:
      message:
        type: string

@BigMrSunshine
Copy link
Author

That worked! I don't know the etiquette around this stuff. Should I close it? Fork and submit pull request. I'm kind of new to the github community. Thanks

@webron
Copy link
Contributor

webron commented Feb 8, 2016

If you find something wrong with the doc and want to fix it, then yeah, submitting a PR would be greatly appreciated.

@dreallday
Copy link

@theganyo Thank you! This worked perfectly.

@BigMrSunshine
Copy link
Author

@theganyo The pattern, of describing a simple string response as a message object is used several places in several templates. Are we sure this new validation logic is valid and the templates should be changed (via a PR) as you described above?

rajeget pushed a commit to rajeget/swagger-node that referenced this issue Feb 13, 2016
Its explained and resolved here . But not present in the code set swagger-api#348 .
Platform: Node-Express
fehguy added a commit that referenced this issue Feb 16, 2016
@fehguy
Copy link
Contributor

fehguy commented Feb 16, 2016

updated the templates

@fehguy fehguy closed this as completed Feb 16, 2016
@BigMrSunshine
Copy link
Author

Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants