Socket
Socket
Sign inDemoInstall

express-openapi-validator

Package Overview
Dependencies
Maintainers
1
Versions
278
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

express-openapi-validator - npm Package Compare versions

Comparing version 0.3.34 to 0.3.35

273

dist/framework/util.js
"use strict";
exports.__esModule = true;
// import { Logger } from 'ts-log';
// import { URL } from 'url';
var base_path_1 = require("./base.path");
// import { IOpenAPIFramework } from './types';
// const difunc = require('difunc');
var fs = require('fs');
// const isDir = require('is-dir');
var jsYaml = require('js-yaml');
var path = require('path');
// export const METHOD_ALIASES = {
// // HTTP style
// DELETE: 'delete',
// GET: 'get',
// HEAD: 'head',
// OPTIONS: 'options',
// PATCH: 'patch',
// POST: 'post',
// PUT: 'put',
// // js style
// del: 'delete',
// delete: 'delete',
// get: 'get',
// head: 'head',
// options: 'options',
// patch: 'patch',
// post: 'post',
// put: 'put',
// };
// export function addOperationTagToApiDoc(apiDoc, tag) {
// const apiDocTags = apiDoc.tags || [];
// const availableTags = apiDocTags.map(t => {
// return t && t.name;
// });
// if (availableTags.indexOf(tag) === -1) {
// apiDocTags.push({
// name: tag
// });
// }
// apiDoc.tags = apiDocTags;
// }
// function allows(docs, prop, val) {
// return ![].slice.call(docs).filter(byProperty(prop, val)).length;
// }
// export function allowsCoercionFeature(framework: IOpenAPIFramework, ...docs) {
// return allows(
// arguments,
// `x-${framework.name}-disable-coercion-${framework.featureType}`,
// true
// );
// }
// export function allowsDefaultsFeature(framework: IOpenAPIFramework, ...docs) {
// return allows(
// arguments,
// `x-${framework.name}-disable-defaults-${framework.featureType}`,
// true
// );
// }
// export function allowsFeatures(framework: IOpenAPIFramework, ...docs) {
// return allows(
// docs,
// `x-${framework.name}-disable-${framework.featureType}`,
// true
// );
// }
// export function allowsResponseValidationFeature(
// framework: IOpenAPIFramework,
// ...docs
// ) {
// return allows(
// arguments,
// `x-${framework.name}-disable-response-validation-${framework.featureType}`,
// true
// );
// }
// export function allowsValidationFeature(framework: IOpenAPIFramework, ...docs) {
// return allows(
// docs,
// `x-${framework.name}-disable-validation-${framework.featureType}`,
// true
// );
// }
var fs = require("fs");
var jsYaml = require("js-yaml");
var path = require("path");
function assertRegExpAndSecurity(framework, tuple) {

@@ -96,30 +19,2 @@ if (!Array.isArray(tuple)) {

exports.assertRegExpAndSecurity = assertRegExpAndSecurity;
// export function byDefault(param) {
// return param && 'default' in param;
// }
// export function byDirectory(el) {
// return isDir.sync(el);
// }
// export function byMethods(name) {
// // not handling $ref at this time. Please open an issue if you need this.
// return name in METHOD_ALIASES;
// }
// function byProperty(property, value) {
// return obj => {
// return obj && property in obj && obj[property] === value;
// };
// }
// export function byRoute(a, b) {
// if (isDynamicRoute(a.path) && !isDynamicRoute(b.path)) {
// return 1;
// }
// if (!isDynamicRoute(a.path) && isDynamicRoute(b.path)) {
// return -1;
// }
// // invert compare to keep that /{foo} does not beat /{foo}.{bar}
// return -1 * a.path.localeCompare(b.path);
// }
// export function byString(el) {
// return typeof el === 'string';
// }
function copy(obj) {

@@ -129,62 +24,2 @@ return JSON.parse(JSON.stringify(obj));

exports.copy = copy;
// export function getAdditionalFeatures(
// framework: IOpenAPIFramework,
// logger: Logger,
// ...docs
// ) {
// const additionalFeatures = [];
// let index = docs.length - 1;
// const inheritProperty = `x-${framework.name}-inherit-additional-${
// framework.featureType
// }`;
// const additionalProperty = `x-${framework.name}-additional-${
// framework.featureType
// }`;
// while (index > 0) {
// --index;
// const currentDoc = docs[index + 1];
// const parentDoc = docs[index];
// if (currentDoc && currentDoc[inheritProperty] === false) {
// break;
// } else {
// [].unshift.apply(additionalFeatures, getDocFeature(parentDoc));
// }
// }
// return additionalFeatures.filter(feature => {
// if (typeof feature === 'function') {
// return true;
// } else {
// logger.warn(
// `${framework.loggingPrefix}Ignoring ${feature} as ${
// framework.featureType
// } in ${additionalProperty} array.`
// );
// return false;
// }
// });
// function getDocFeature(doc) {
// if (doc && Array.isArray(doc[additionalProperty])) {
// return doc[additionalProperty];
// }
// }
// }
// export function getSecurityDefinitionByPath(openapiPath, pathSecurity) {
// for (let i = pathSecurity.length; i--; ) {
// const tuple = pathSecurity[i];
// if (tuple[0].test(openapiPath)) {
// return tuple[1];
// }
// }
// }
// export function getMethodDoc(operationHandler) {
// const doc =
// operationHandler.apiDoc ||
// (Array.isArray(operationHandler)
// ? operationHandler.slice(-1)[0].apiDoc
// : null);
// if (doc) {
// return copy(doc);
// }
// return null;
// }
function loadSpecFile(filePath) {

@@ -212,76 +47,2 @@ if (typeof filePath === 'string') {

exports.handleYaml = handleYaml;
// export function injectDependencies(handlers, dependencies) {
// if (typeof handlers !== 'function') {
// return handlers;
// }
// return difunc(dependencies || {}, handlers);
// }
// export function isDynamicRoute(route) {
// return route.indexOf('{') > 0;
// }
// export function resolveParameterRefs(
// framework: IOpenAPIFramework,
// parameters,
// apiDoc
// ) {
// return parameters.map(parameter => {
// if (typeof parameter.$ref === 'string') {
// const apiVersion = apiDoc.swagger ? apiDoc.swagger : apiDoc.openapi;
// const apiDocParameters =
// apiVersion === '2.0' ? apiDoc.parameters : apiDoc.components.parameters;
// const PARAMETER_REF_REGEX =
// apiVersion === '2.0'
// ? /^#\/parameters\/(.+)$/
// : /^#\/components\/parameters\/(.+)$/;
// const match = PARAMETER_REF_REGEX.exec(parameter.$ref);
// const definition = match && (apiDocParameters || {})[match[1]];
// if (!definition) {
// throw new Error(
// `${
// framework.name
// }: Invalid parameter $ref or definition not found in apiDoc.parameters: ${
// parameter.$ref
// }`
// );
// }
// return definition;
// } else {
// return parameter;
// }
// });
// }
// export function resolveResponseRefs(
// framework: IOpenAPIFramework,
// responses,
// apiDoc,
// route
// ) {
// return Object.keys(responses).reduce((resolvedResponses, responseCode) => {
// const response = responses[responseCode];
// if (typeof response.$ref === 'string') {
// const apiVersion = apiDoc.swagger ? apiDoc.swagger : apiDoc.openapi;
// const apiDocResponses =
// apiVersion === '2.0' ? apiDoc.responses : apiDoc.components.responses;
// const RESPONSE_REF_REGEX =
// apiVersion === '2.0'
// ? /^#\/responses\/(.+)$/
// : /^#\/components\/responses\/(.+)$/;
// const match = RESPONSE_REF_REGEX.exec(response.$ref);
// const definition = match && (apiDocResponses || {})[match[1]];
// if (!definition) {
// throw new Error(
// `${
// framework.name
// }: Invalid response $ref or definition not found in apiDoc.responses: ${
// response.$ref
// }`
// );
// }
// resolvedResponses[responseCode] = definition;
// } else {
// resolvedResponses[responseCode] = response;
// }
// return resolvedResponses;
// }, {});
// }
function sortApiDocTags(apiDoc) {

@@ -295,30 +56,2 @@ if (apiDoc && Array.isArray(apiDoc.tags)) {

exports.sortApiDocTags = sortApiDocTags;
// export function sortOperationDocTags(operationDoc) {
// operationDoc.tags.sort((a, b) => {
// if (a < b) {
// return -1;
// }
// return 1;
// });
// }
// export function toAbsolutePath(part) {
// return path.resolve(process.cwd(), part);
// }
// export function withNoDuplicates(arr) {
// const parameters = [];
// const seenParams = {};
// let index = arr.length;
// while (index > 0) {
// --index;
// const item = arr[index];
// const key = [item.name, item.location].join(';////|||||\\\\;');
// if (key in seenParams) {
// continue;
// }
// seenParams[key] = true;
// // unshifting to preserve ordering.
// parameters.unshift(item);
// }
// return parameters;
// }
function getBasePathsFromServers(servers) {

@@ -325,0 +58,0 @@ if (!servers) {

4

dist/middlewares/openapi.metadata.js
"use strict";
exports.__esModule = true;
var pathToRegexp = require('path-to-regexp');
var _ = require('lodash');
var pathToRegexp = require("path-to-regexp");
var _ = require("lodash");
function applyOpenApiMetadata(openApiContext) {

@@ -6,0 +6,0 @@ return function (req, res, next) {

{
"name": "express-openapi-validator",
"version": "0.3.34",
"version": "0.3.35",
"description": "",

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

import { OpenAPIV3 } from 'openapi-types';
// import { Logger } from 'ts-log';
// import { URL } from 'url';
import BasePath from './base.path';
// import { IOpenAPIFramework } from './types';
// const difunc = require('difunc');
const fs = require('fs');
// const isDir = require('is-dir');
const jsYaml = require('js-yaml');
const path = require('path');
import * as fs from 'fs';
import * as jsYaml from 'js-yaml';
import * as path from 'path';
// export const METHOD_ALIASES = {
// // HTTP style
// DELETE: 'delete',
// GET: 'get',
// HEAD: 'head',
// OPTIONS: 'options',
// PATCH: 'patch',
// POST: 'post',
// PUT: 'put',
// // js style
// del: 'delete',
// delete: 'delete',
// get: 'get',
// head: 'head',
// options: 'options',
// patch: 'patch',
// post: 'post',
// put: 'put',
// };
// export function addOperationTagToApiDoc(apiDoc, tag) {
// const apiDocTags = apiDoc.tags || [];
// const availableTags = apiDocTags.map(t => {
// return t && t.name;
// });
// if (availableTags.indexOf(tag) === -1) {
// apiDocTags.push({
// name: tag
// });
// }
// apiDoc.tags = apiDocTags;
// }
// function allows(docs, prop, val) {
// return ![].slice.call(docs).filter(byProperty(prop, val)).length;
// }
// export function allowsCoercionFeature(framework: IOpenAPIFramework, ...docs) {
// return allows(
// arguments,
// `x-${framework.name}-disable-coercion-${framework.featureType}`,
// true
// );
// }
// export function allowsDefaultsFeature(framework: IOpenAPIFramework, ...docs) {
// return allows(
// arguments,
// `x-${framework.name}-disable-defaults-${framework.featureType}`,
// true
// );
// }
// export function allowsFeatures(framework: IOpenAPIFramework, ...docs) {
// return allows(
// docs,
// `x-${framework.name}-disable-${framework.featureType}`,
// true
// );
// }
// export function allowsResponseValidationFeature(
// framework: IOpenAPIFramework,
// ...docs
// ) {
// return allows(
// arguments,
// `x-${framework.name}-disable-response-validation-${framework.featureType}`,
// true
// );
// }
// export function allowsValidationFeature(framework: IOpenAPIFramework, ...docs) {
// return allows(
// docs,
// `x-${framework.name}-disable-validation-${framework.featureType}`,
// true
// );
// }
export function assertRegExpAndSecurity(framework, tuple) {

@@ -115,37 +27,2 @@ if (!Array.isArray(tuple)) {

// export function byDefault(param) {
// return param && 'default' in param;
// }
// export function byDirectory(el) {
// return isDir.sync(el);
// }
// export function byMethods(name) {
// // not handling $ref at this time. Please open an issue if you need this.
// return name in METHOD_ALIASES;
// }
// function byProperty(property, value) {
// return obj => {
// return obj && property in obj && obj[property] === value;
// };
// }
// export function byRoute(a, b) {
// if (isDynamicRoute(a.path) && !isDynamicRoute(b.path)) {
// return 1;
// }
// if (!isDynamicRoute(a.path) && isDynamicRoute(b.path)) {
// return -1;
// }
// // invert compare to keep that /{foo} does not beat /{foo}.{bar}
// return -1 * a.path.localeCompare(b.path);
// }
// export function byString(el) {
// return typeof el === 'string';
// }
export function copy(obj) {

@@ -155,71 +32,2 @@ return JSON.parse(JSON.stringify(obj));

// export function getAdditionalFeatures(
// framework: IOpenAPIFramework,
// logger: Logger,
// ...docs
// ) {
// const additionalFeatures = [];
// let index = docs.length - 1;
// const inheritProperty = `x-${framework.name}-inherit-additional-${
// framework.featureType
// }`;
// const additionalProperty = `x-${framework.name}-additional-${
// framework.featureType
// }`;
// while (index > 0) {
// --index;
// const currentDoc = docs[index + 1];
// const parentDoc = docs[index];
// if (currentDoc && currentDoc[inheritProperty] === false) {
// break;
// } else {
// [].unshift.apply(additionalFeatures, getDocFeature(parentDoc));
// }
// }
// return additionalFeatures.filter(feature => {
// if (typeof feature === 'function') {
// return true;
// } else {
// logger.warn(
// `${framework.loggingPrefix}Ignoring ${feature} as ${
// framework.featureType
// } in ${additionalProperty} array.`
// );
// return false;
// }
// });
// function getDocFeature(doc) {
// if (doc && Array.isArray(doc[additionalProperty])) {
// return doc[additionalProperty];
// }
// }
// }
// export function getSecurityDefinitionByPath(openapiPath, pathSecurity) {
// for (let i = pathSecurity.length; i--; ) {
// const tuple = pathSecurity[i];
// if (tuple[0].test(openapiPath)) {
// return tuple[1];
// }
// }
// }
// export function getMethodDoc(operationHandler) {
// const doc =
// operationHandler.apiDoc ||
// (Array.isArray(operationHandler)
// ? operationHandler.slice(-1)[0].apiDoc
// : null);
// if (doc) {
// return copy(doc);
// }
// return null;
// }
export function loadSpecFile(filePath) {

@@ -246,86 +54,2 @@ if (typeof filePath === 'string') {

// export function injectDependencies(handlers, dependencies) {
// if (typeof handlers !== 'function') {
// return handlers;
// }
// return difunc(dependencies || {}, handlers);
// }
// export function isDynamicRoute(route) {
// return route.indexOf('{') > 0;
// }
// export function resolveParameterRefs(
// framework: IOpenAPIFramework,
// parameters,
// apiDoc
// ) {
// return parameters.map(parameter => {
// if (typeof parameter.$ref === 'string') {
// const apiVersion = apiDoc.swagger ? apiDoc.swagger : apiDoc.openapi;
// const apiDocParameters =
// apiVersion === '2.0' ? apiDoc.parameters : apiDoc.components.parameters;
// const PARAMETER_REF_REGEX =
// apiVersion === '2.0'
// ? /^#\/parameters\/(.+)$/
// : /^#\/components\/parameters\/(.+)$/;
// const match = PARAMETER_REF_REGEX.exec(parameter.$ref);
// const definition = match && (apiDocParameters || {})[match[1]];
// if (!definition) {
// throw new Error(
// `${
// framework.name
// }: Invalid parameter $ref or definition not found in apiDoc.parameters: ${
// parameter.$ref
// }`
// );
// }
// return definition;
// } else {
// return parameter;
// }
// });
// }
// export function resolveResponseRefs(
// framework: IOpenAPIFramework,
// responses,
// apiDoc,
// route
// ) {
// return Object.keys(responses).reduce((resolvedResponses, responseCode) => {
// const response = responses[responseCode];
// if (typeof response.$ref === 'string') {
// const apiVersion = apiDoc.swagger ? apiDoc.swagger : apiDoc.openapi;
// const apiDocResponses =
// apiVersion === '2.0' ? apiDoc.responses : apiDoc.components.responses;
// const RESPONSE_REF_REGEX =
// apiVersion === '2.0'
// ? /^#\/responses\/(.+)$/
// : /^#\/components\/responses\/(.+)$/;
// const match = RESPONSE_REF_REGEX.exec(response.$ref);
// const definition = match && (apiDocResponses || {})[match[1]];
// if (!definition) {
// throw new Error(
// `${
// framework.name
// }: Invalid response $ref or definition not found in apiDoc.responses: ${
// response.$ref
// }`
// );
// }
// resolvedResponses[responseCode] = definition;
// } else {
// resolvedResponses[responseCode] = response;
// }
// return resolvedResponses;
// }, {});
// }
export function sortApiDocTags(apiDoc) {

@@ -339,37 +63,2 @@ if (apiDoc && Array.isArray(apiDoc.tags)) {

// export function sortOperationDocTags(operationDoc) {
// operationDoc.tags.sort((a, b) => {
// if (a < b) {
// return -1;
// }
// return 1;
// });
// }
// export function toAbsolutePath(part) {
// return path.resolve(process.cwd(), part);
// }
// export function withNoDuplicates(arr) {
// const parameters = [];
// const seenParams = {};
// let index = arr.length;
// while (index > 0) {
// --index;
// const item = arr[index];
// const key = [item.name, item.location].join(';////|||||\\\\;');
// if (key in seenParams) {
// continue;
// }
// seenParams[key] = true;
// // unshifting to preserve ordering.
// parameters.unshift(item);
// }
// return parameters;
// }
export function getBasePathsFromServers(

@@ -376,0 +65,0 @@ servers: OpenAPIV3.ServerObject[]

@@ -1,3 +0,3 @@

const pathToRegexp = require('path-to-regexp');
const _ = require('lodash');
import * as pathToRegexp from 'path-to-regexp';
import * as _ from 'lodash';
import { OpenApiContext } from '../openapi.context';

@@ -4,0 +4,0 @@

@@ -1,9 +0,9 @@

var express = require('express');
var path = require('path');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var logger = require('morgan');
import * as express from 'express';
import * as path from 'path';
import * as cookieParser from 'cookie-parser';
import * as bodyParser from 'body-parser';
import * as logger from 'morgan';
const { OpenApiValidator } = require('../src');
const { startServer, routes } = require('./app.common');
import { OpenApiValidator } from '../src';
import { startServer, routes } from './app.common';

@@ -10,0 +10,0 @@ var app = express();

@@ -1,7 +0,8 @@

const expect = require('chai').expect;
import { expect } from 'chai';
import * as request from 'supertest';
import app from './app';
const packageJson = require('../package.json');
const basePath = app.basePath;
const basePath = app.basePath;
describe(packageJson.name, () => {

@@ -8,0 +9,0 @@ after(() => {

@@ -1,3 +0,4 @@

const expect = require('chai').expect;
const { OpenApiValidator } = require('../src');
import { expect } from 'chai';
import { OpenApiValidator } from '../src';
const packageJson = require('../package.json');

@@ -9,3 +10,2 @@

apiSpecPath: './openapi.yaml',
enableObjectCoercion: true, // should be default
});

@@ -22,3 +22,2 @@

apiSpecPath: './not-found.yaml',
enableObjectCoercion: true, // should be default
});

@@ -25,0 +24,0 @@

@@ -1,2 +0,2 @@

const expect = require('chai').expect;
import { expect } from 'chai';
import * as request from 'supertest';

@@ -227,11 +227,13 @@ import app from './app';

const attributeId = '12';
return request(app)
.get(`${basePath}/pets/${id}/attributes/${attributeId}`)
// .expect(200)
.then(r => {
console.log(`${basePath}/pets/${id}/attributes/${attributeId}`)
console.log(r.body);
expect(r.body.id).equals(Number.parseInt(id));
expect(r.body.attribute_id).equals(Number.parseInt(attributeId));
});
return (
request(app)
.get(`${basePath}/pets/${id}/attributes/${attributeId}`)
// .expect(200)
.then(r => {
console.log(`${basePath}/pets/${id}/attributes/${attributeId}`);
console.log(r.body);
expect(r.body.id).equals(Number.parseInt(id));
expect(r.body.attribute_id).equals(Number.parseInt(attributeId));
})
);
});

@@ -238,0 +240,0 @@

Sorry, the diff of this file is not supported yet

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