openapi-enforcer
Advanced tools
Comparing version 0.9.1 to 0.9.2
@@ -479,4 +479,2 @@ /** | ||
let example; | ||
if (data && data.code) | ||
if (data && data.code && !options.ignoreDocumentExample) { | ||
@@ -483,0 +481,0 @@ example = store.get(context).version.getResponseExample({ |
@@ -160,13 +160,18 @@ /** | ||
// body already parsed, need to deserialize and check for errors | ||
if (paramMap.body && paramMap.body.schema && req.body !== undefined) { | ||
const schema = paramMap.body.schema; | ||
const typed = this.enforcer.deserialize(schema, req.body); | ||
if (typed.errors) { | ||
errors.push('Invalid request body:\n\t' + typed.errors.join('\n\t')); | ||
} else { | ||
const validationErrors = this.enforcer.errors(schema, typed.value); | ||
if (validationErrors) { | ||
errors.push('Invalid request body":\n\t' + validationErrors.join('\n\t')); | ||
if (paramMap.body) { | ||
if (paramMap.body.required && req.body === undefined) { | ||
errors.push('Missing required body parameter "' + paramMap.body.name + '"'); | ||
} else if (paramMap.body.schema && req.body !== undefined) { | ||
const schema = paramMap.body.schema; | ||
const typed = this.enforcer.deserialize(schema, req.body); | ||
if (typed.errors) { | ||
errors.push('Invalid request body:\n\t' + typed.errors.join('\n\t')); | ||
} else { | ||
result.body = typed.value; | ||
const validationErrors = this.enforcer.errors(schema, typed.value); | ||
if (validationErrors) { | ||
errors.push('Invalid request body":\n\t' + validationErrors.join('\n\t')); | ||
} else { | ||
result.body = typed.value; | ||
} | ||
} | ||
@@ -173,0 +178,0 @@ } |
@@ -189,19 +189,24 @@ /** | ||
// body already parsed, need to deserialize and check for errors | ||
if (mSchema.requestBody && req.body !== undefined) { | ||
const contentType = req.header['content-type'] || '*/*'; | ||
const content = mSchema.requestBody.content; | ||
const key = util.findMediaMatch(contentType, Object.keys(content))[0]; | ||
if (key && content[key].schema) { | ||
const schema = content[key].schema; | ||
const typed = this.enforcer.deserialize(schema, req.body); | ||
if (typed.errors) { | ||
errors.push('Invalid request body:\n\t' + typed.errors.join('\n\t')); | ||
} else { | ||
const validationErrors = this.enforcer.errors(schema, typed.value); | ||
if (validationErrors) { | ||
errors.push('Invalid request body":\n\t' + validationErrors.join('\n\t')); | ||
if (mSchema.requestBody) { | ||
if (req.body !== undefined) { | ||
const contentType = req.header['content-type'] || '*/*'; | ||
const content = mSchema.requestBody.content; | ||
const key = util.findMediaMatch(contentType, Object.keys(content))[0]; | ||
if (key && content[key].schema) { | ||
const schema = content[key].schema; | ||
const typed = this.enforcer.deserialize(schema, req.body); | ||
if (typed.errors) { | ||
errors.push('Invalid request body:\n\t' + typed.errors.join('\n\t')); | ||
} else { | ||
result.body = typed.value; | ||
const validationErrors = this.enforcer.errors(schema, typed.value); | ||
if (validationErrors) { | ||
errors.push('Invalid request body":\n\t' + validationErrors.join('\n\t')); | ||
} else { | ||
result.body = typed.value; | ||
} | ||
} | ||
} | ||
} else if (mSchema.requestBody.required && req.body === undefined) { | ||
errors.push('Missing required request body'); | ||
} | ||
@@ -208,0 +213,0 @@ } |
{ | ||
"name": "openapi-enforcer", | ||
"version": "0.9.1", | ||
"version": "0.9.2", | ||
"description": "Library for validating, parsing, and formatting data against open api schemas.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -109,2 +109,10 @@ /** | ||
it('missing required body', () => { | ||
const schema2 = modSchema(schema, { 'paths./.put.parameters.0': { required: true } }); | ||
const instance = new enforcer(schema2, {}); | ||
const params = instance.request({ path: '/', method: 'put' }); | ||
expect(params.errors.length).to.equal(1); | ||
expect(params.errors[0]).to.match(/missing required body/i); | ||
}); | ||
}); | ||
@@ -111,0 +119,0 @@ |
@@ -172,2 +172,10 @@ /** | ||
it('missing required body', () => { | ||
const schema2 = modSchema(schema, { 'paths./.put.requestBody': { required: true } }); | ||
const instance = new enforcer(schema2, {}); | ||
const params = instance.request({ path: '/', method: 'put' }); | ||
expect(params.errors.length).to.equal(1); | ||
expect(params.errors[0]).to.match(/missing required request body/i); | ||
}); | ||
}); | ||
@@ -174,0 +182,0 @@ |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
378586
6177
0