diff --git a/package.json b/package.json index 48822cc19..fe1a7381a 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,7 @@ "dependencies": { "advisable": "~0.2.0", "async": "^0.9.x", + "blueprint-transactions": "^0.0.2", "chai": "^2.1.0", "clone": "^1.0.0", "coffee-script": "^1.9.1", @@ -34,13 +35,13 @@ "node-uuid": "~1.4.2", "optimist": "~0.6.1", "pitboss-ng": "^0.3.1", + "prettyjson": "^1.1.3", "proxyquire": "~1.4.x", "request": "^2.53.0", "setimmediate": "^1.0.2", "spawn-sync": "^1.0.11", "uri-template": "~1.0.0", - "winston": "^1.0.0", - "blueprint-transactions": "^0.0.2" + "winston": "^1.0.0" }, "devDependencies": { "body-parser": "^1.12.0", diff --git a/src/prettify-response.coffee b/src/prettify-response.coffee index afd4b649e..aa4a7b169 100644 --- a/src/prettify-response.coffee +++ b/src/prettify-response.coffee @@ -1,4 +1,5 @@ html = require 'html' +prettyjson = require 'prettyjson' logger = require './logger' @@ -12,15 +13,20 @@ prettifyResponse = (response) -> logger.debug "Could not stringify: " + obj obj + prettifySchema = (schema, contentType) -> + if typeof contentType != 'undefined' && contentType.indexOf('application/json') > -1 + schema = prettyjson.render JSON.parse(schema) + else + schema = stringify schema + schema + prettifyBody = (body, contentType) -> - switch contentType - when 'application/json' - body = stringify body - when 'text/html' - body = html.prettyPrint body, {indent_size: 2} + if typeof contentType != 'undefined' && contentType.indexOf('application/json') > -1 + body = prettyjson.render JSON.parse(body) + else + body = html.prettyPrint body, {indent_size: 2} body - contentType = (response?.headers['content-type'] || response?.headers['Content-Type']) if response?.headers? stringRepresentation = "" @@ -28,8 +34,8 @@ prettifyResponse = (response) -> for own key, value of response if key is 'body' value = '\n' + prettifyBody value, contentType - else if key is 'schema' - value = '\n' + stringify value + else if key is 'schema' || key is 'bodySchema' + value = '\n' + prettifySchema value, contentType else if key is 'headers' header = '\n' for own hkey, hval of value