openapi-enforcer
Advanced tools
Comparing version 0.9.3 to 0.9.4
@@ -445,4 +445,9 @@ /** | ||
function responseErrors(context, responses, data, config) { | ||
let errors = []; | ||
const errors = []; | ||
if (data.error) { | ||
errors.push(data.error); | ||
return errors; | ||
} | ||
// check body for errors | ||
@@ -477,2 +482,3 @@ if (config.hasOwnProperty('body')) { | ||
function responseExample(context, responses, data, options) { | ||
if (data.error) throw Error(data.error); | ||
if (!responses) throw Error('Cannot build example response without schema'); | ||
@@ -494,2 +500,4 @@ if (!options) options = {}; | ||
function responsePopulate(context, responses, data, options) { | ||
if (data.error) throw Error(data.error); | ||
const config = Object.assign({}, options); | ||
@@ -546,2 +554,4 @@ if (!config.headers) config.headers = {}; | ||
function responseSerialize(context, responses, data, config) { | ||
if (data.error) throw Error(data.error); | ||
const result = { headers: {} }; | ||
@@ -548,0 +558,0 @@ const version = store.get(context).version; |
@@ -55,12 +55,18 @@ /** | ||
* @param {{ code: string, contentType: string }} options | ||
* @returns {{ accept: string, code: string, contentType?: string, headers: object, schema?: object }|undefined} | ||
* @returns {{ accept?: string, code?: string, contentType?: string, error?: string, headers?: object, schema?: object }} | ||
*/ | ||
Version.prototype.getResponseData = function(produces, responses, options) { | ||
if (!responses) return; | ||
if (!responses) return { error: 'No response definitions exists' }; | ||
const code = options.hasOwnProperty('code') | ||
? options.code | ||
let code = options.hasOwnProperty('code') | ||
? '' + options.code | ||
: responses.hasOwnProperty('default') ? 'default' : Object.keys(responses)[0]; | ||
if (!responses.hasOwnProperty(code)) { | ||
if (responses.hasOwnProperty('default')) { | ||
code = 'default'; | ||
} else { | ||
return { error: 'Response code not valid' }; | ||
} | ||
} | ||
const schema = responses[code]; | ||
if (!schema) return; | ||
@@ -67,0 +73,0 @@ const result = { |
@@ -88,12 +88,18 @@ /** | ||
* @param {{ code: string, contentType: string }} options | ||
* @returns {{ accept: string, code: string, contentType?: string, headers: object, schema?: object }|undefined} | ||
* @returns {{ accept?: string, code?: string, contentType?: string, error?: string, headers?: object, schema?: object }} | ||
*/ | ||
Version.prototype.getResponseData = function(produces, responses, options) { | ||
if (!responses) return; | ||
if (!responses) return { error: 'No response definitions exists' }; | ||
const code = options.hasOwnProperty('code') | ||
? options.code | ||
let code = options.hasOwnProperty('code') | ||
? '' + options.code | ||
: responses.hasOwnProperty('default') ? 'default' : Object.keys(responses)[0]; | ||
if (!responses.hasOwnProperty(code)) { | ||
if (responses.hasOwnProperty('default')) { | ||
code = 'default'; | ||
} else { | ||
return { error: 'Response code not valid' }; | ||
} | ||
} | ||
const schema = responses[code]; | ||
if (!schema) return; | ||
@@ -100,0 +106,0 @@ const result = { |
{ | ||
"name": "openapi-enforcer", | ||
"version": "0.9.3", | ||
"version": "0.9.4", | ||
"description": "Library for validating, parsing, and formatting data against open api schemas.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
379336
6196