New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

openapi-enforcer

Package Overview
Dependencies
Maintainers
1
Versions
131
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

openapi-enforcer - npm Package Compare versions

Comparing version 0.9.1 to 0.9.2

2

bin/openapi.js

@@ -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({

25

bin/v2/index.js

@@ -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 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc