apigee 127 - JSON is escaped when ran in mock mode

138 views Asked by At

I'm guessing I've missed something silly so I apologize in advance.

I'm trying to run the example found at the following URL in mock mode: https://github.com/apigee-127/a127-samples/blob/master/weather-basic/api/swagger/swagger.yaml

The JSON response looks like it's being escaped and it's causing the response validator to fail:

{
  "message": "Response validation failed: invalid content type (text/plain).  These are valid: application/json",
  "failedValidation": true,
  "originalResponse": "{\"base\":\"Sample text\",\"clouds\":{\"all\":1},\"cod\":1,\"coord\":{\"lat\":1,\"lon\":1},\"dt\":1,\"id\":1,\"main\":{\"humidity\":1,\"pressure\":1,\"temp_max\":1,\"temp_min\":1,\"temp\":1},\"name\":\"Sample text\",\"sys\":{\"country\":\"Sample text\",\"id\":1,\"message\":1,\"sunrise\":1,\"sunset\":1,\"type\":1},\"weather\":[{\"description\":\"Sample text\",\"icon\":\"Sample text\",\"id\":1,\"main\":\"Sample text\"}],\"wind\":{\"deg\":1,\"speed\":1}}"
}

Any ideas would be awesome!

2

There are 2 answers

0
Ashish Yadav On

You need to send something like this res.json({});

0
Ashish Yadav On

Send as json object don't stringify your result object ,

var result = {name:"asdf",id:1212}
res.json(result);