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 1.0.0 to 1.0.1

2

bin/enforcers/Header.js

@@ -27,3 +27,3 @@ /**

if (major === 2) {
const def = base.extractSchemaDefinition(this);
const def = base.extractSchemaDefinition({}, this);
const [schema, error, warning] = context.Schema(def);

@@ -30,0 +30,0 @@ if (schema) this.schema = schema;

@@ -40,3 +40,3 @@ /**

// TODO: type might be file which is not really supported in Schema - shouldn't be a problem but I need to test it
const def = Base.extractSchemaDefinition(this);
const def = Base.extractSchemaDefinition({}, this);
if (def.type === 'file') def.type = 'string';

@@ -43,0 +43,0 @@ const [ schema, err, warning ] = new context.Schema(def);

@@ -47,3 +47,7 @@ /**

default: { allowed: true },
enum: { allowed: true },
enum: {
allowed: true,
type: 'array',
items: { freeForm: true }
},
exclusiveMaximum: { allowed: true },

@@ -90,3 +94,3 @@ exclusiveMinimum: { allowed: true },

},
example: {},
example: EnforcerRef('Example'),
examples: {

@@ -115,13 +119,14 @@ type: 'object',

function extractSchemaDefinition(definition) {
const result = {};
function extractSchemaDefinition(result, definition) {
schemaProperties.forEach(key => {
if (definition.hasOwnProperty(key)) {
const value = definition[key];
if (Array.isArray(value)) {
result[key] = value.map(extractSchemaDefinition)
} else if (value && typeof value === 'object') {
result[key] = extractSchemaDefinition(value);
} else {
result[key] = value;
switch (key) {
case 'items':
result[key] = extractSchemaDefinition({}, value);
break;
default:
result[key] = value;
break;
}

@@ -128,0 +133,0 @@ }

@@ -37,3 +37,3 @@ /**

let openapi;
let warnings;
let warnings = Exception('One or more warnings exist int he OpenAPI definition');

@@ -43,2 +43,3 @@ // normalize options

if (!options.hasOwnProperty('hideWarnings')) options.hideWarnings = false;
if (!options.hasOwnProperty('fullResult')) options.fullResult = false;

@@ -68,3 +69,4 @@ const refParser = new RefParser();

if (!options.hideWarnings && warnings) console.warn(warnings.toString());
if (options.fullResult) return new Result(openapi, exception, warnings);
if (!options.hideWarnings && warnings && warnings.hasException) console.warn(warnings.toString());
if (exception && exception.hasException) throw Error(exception.toString());

@@ -71,0 +73,0 @@ return openapi;

{
"name": "openapi-enforcer",
"version": "1.0.0",
"version": "1.0.1",
"description": "Library for validating, parsing, and formatting data against open api schemas.",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -238,2 +238,32 @@ /**

describe('enum', () => {
describe('v2', () => {
it('can have enum', () => {
const [ , err ] = Enforcer.v2_0.Parameter({
name: 'hi',
in: 'query',
type: 'string',
enum: ['hero', 'normal', 'villain']
});
expect(err).to.be.undefined;
});
it('must have valid enum values', () => {
const [ , err ] = Enforcer.v2_0.Parameter({
name: 'hi',
in: 'query',
type: 'string',
enum: ['hero', true, 5]
});
expect(err).to.match(/at: 1\s+Value must be a string/);
expect(err).to.match(/at: 2\s+Value must be a string/);
expect(err.count).to.equal(2);
});
});
});
describe('examples', () => {

@@ -240,0 +270,0 @@

Sorry, the diff of this file is not supported yet

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