Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion lib/add-tests.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,19 @@ addTests = (raml, tests, hooks, parent, callback, testFactory) ->
# expect content-type of response body to be identical to request body
if contentType && res.body[contentType]?.schema
test.response.schema = parseSchema res.body[contentType].schema
try
test.response.example = JSON.parse res.body[contentType]?.example
catch
console.warn "cannot parse JSON example response body for #{test.name}"
# otherwise filter in responses section for compatible content-types (vendor tree, i.e. application/vnd.api+json)
else
contentType = (type for type of res.body when type.match(/^application\/(.*\+)?json/i))?[0]
if res.body[contentType]?.schema
test.response.schema = parseSchema res.body[contentType].schema
try
test.response.example = JSON.parse res.body[contentType]?.example
catch
console.warn "cannot parse JSON example response body for #{test.name}"

callback()
, (err) ->
Expand All @@ -101,4 +109,3 @@ addTests = (raml, tests, hooks, parent, callback, testFactory) ->


module.exports = addTests