Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

exegesis

Package Overview
Dependencies
Maintainers
1
Versions
66
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

exegesis - npm Package Compare versions

Comparing version 2.1.1 to 2.2.0

6

lib/core/ExegesisContextImpl.d.ts
/// <reference types="node" />
import * as http from 'http';
import { ParametersByLocation, ParametersMap, ExegesisContext, AuthenticationSuccess, HttpIncomingMessage, ExegesisPluginContext, Callback, ParameterLocations, ParameterLocation, ExegesisOptions, ResolvedOperation } from '../types';
import { ParametersByLocation, ParametersMap, ExegesisContext, AuthenticationSuccess, HttpIncomingMessage, ExegesisPluginContext, Callback, ParameterLocations, ParameterLocation, ExegesisOptions, ResolvedOperation, ExegesisRoute } from '../types';
import ExegesisResponseImpl from './ExegesisResponseImpl';

@@ -19,2 +19,4 @@ import { HttpError, ValidationError } from '../errors';

parameterLocations: ParameterLocations;
route: ExegesisRoute;
baseUrl: string;
private _operation;

@@ -26,3 +28,3 @@ private _paramsResolved;

api: T, options: ExegesisOptions);
_setOperation(operation: ResolvedOperation): void;
_setOperation(baseUrl: string, path: string, operation: ResolvedOperation): void;
makeError(statusCode: number, message: string): HttpError;

@@ -29,0 +31,0 @@ makeValidationError(message: string, parameterLocation: ParameterLocation): ValidationError;

"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());

@@ -24,3 +23,3 @@ });

path: Object.create(null),
cookie: Object.create(null)
cookie: Object.create(null),
});

@@ -31,4 +30,7 @@ const EMPTY_PARAM_LOCATIONS = deep_freeze_1.default({

path: Object.create(null),
cookie: Object.create(null)
cookie: Object.create(null),
});
const EMPTY_ROUTE = deep_freeze_1.default({
path: '',
});
class ExegesisContextImpl {

@@ -39,2 +41,4 @@ constructor(req, // http2.Http2ServerRequest,

this.parameterLocations = EMPTY_PARAM_LOCATIONS;
this.route = EMPTY_ROUTE;
this.baseUrl = '';
this._paramsResolved = false;

@@ -52,5 +56,16 @@ this._bodyResolved = false;

}
_setOperation(operation) {
_setOperation(baseUrl, path, operation) {
this.baseUrl = baseUrl;
this.route = { path };
this._operation = operation;
this.parameterLocations = operation.parameterLocations;
// Set `req.baseUrl` and `req.path` to make this behave like Express.
const req = this.req;
if (req.baseUrl) {
req.baseUrl = `${req.baseUrl}/${baseUrl}`;
}
else {
req.baseUrl = baseUrl;
}
req.route = { path };
}

@@ -73,3 +88,3 @@ makeError(statusCode, message) {

if (!this._operation) {
throw new Error("Cannot get parameters - no resolved operation.");
throw new Error('Cannot get parameters - no resolved operation.');
}

@@ -90,3 +105,3 @@ this.params = this._operation.parseParameters();

if (!this._operation) {
throw new Error("Cannot get parameters - no resolved operation.");
throw new Error('Cannot get parameters - no resolved operation.');
}

@@ -93,0 +108,0 @@ if (!this._bodyResolved) {

"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());

@@ -136,3 +135,3 @@ });

const { operation } = resolved;
context._setOperation(operation);
context._setOperation(resolved.baseUrl, resolved.path, operation);
if (!operation.controllerModule || !operation.controller) {

@@ -139,0 +138,0 @@ throw new Error(`No controller found for ${method} ${url}`);

"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());

@@ -9,0 +8,0 @@ });

"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());

@@ -9,0 +8,0 @@ });

"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());

@@ -9,0 +8,0 @@ });

@@ -52,2 +52,3 @@ "use strict";

let serverParams;
let baseUrl = '';
if (!this._servers) {

@@ -62,2 +63,3 @@ pathToResolve = pathname;

serverParams = serverData.serverParams;
baseUrl = serverData.baseUrl;
}

@@ -131,3 +133,5 @@ }

requestBodyMediaTypeObject: mediaType && mediaType.oaMediaType,
}
},
path: resolvedPath.pathKey,
baseUrl,
};

@@ -134,0 +138,0 @@ }

"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());

@@ -9,0 +8,0 @@ });

import Oas3CompileContext from '../Oas3CompileContext';
import Path from '../Path';
import { ParametersMap } from '../../types';
export interface ResolvedPath {
path: Path;
pathKey: string;
rawPathParams: ParametersMap<string | string[]> | undefined;
}
export default class Paths {

@@ -14,4 +19,4 @@ private readonly _pathResolver;

* to be stripped before calling this.
* @returns A `{pathObject, pathParams}` object.
* `pathParams` will be an object where keys are parameter names from path
* @returns A `{path, rawPathParams}` object.
* `rawPathParams` will be an object where keys are parameter names from path
* templating. If the path cannot be resolved, returns null, although

@@ -21,6 +26,3 @@ * note that if the path is resolved and the operation is not found, this

*/
resolvePath(urlPathname: string): {
path: Path;
rawPathParams: ParametersMap<string | string[]> | undefined;
} | undefined;
resolvePath(urlPathname: string): ResolvedPath | undefined;
}

@@ -31,4 +31,4 @@ "use strict";

* to be stripped before calling this.
* @returns A `{pathObject, pathParams}` object.
* `pathParams` will be an object where keys are parameter names from path
* @returns A `{path, rawPathParams}` object.
* `rawPathParams` will be an object where keys are parameter names from path
* templating. If the path cannot be resolved, returns null, although

@@ -43,3 +43,4 @@ * note that if the path is resolved and the operation is not found, this

path: result.value,
rawPathParams: result.rawPathParams
rawPathParams: result.rawPathParams,
pathKey: result.path,
};

@@ -46,0 +47,0 @@ }

@@ -54,3 +54,4 @@ import { ParametersMap } from '../../types';

rawPathParams: ParametersMap<string | string[]> | undefined;
path: string;
} | undefined;
}

@@ -81,3 +81,3 @@ "use strict";

const { parser } = compileTemplatePath(path);
this._dynamicPaths.push({ value, parser });
this._dynamicPaths.push({ value, parser, path });
}

@@ -100,2 +100,3 @@ else {

let rawPathParams;
let path = urlPathname;
if (!value) {

@@ -107,2 +108,3 @@ for (const dynamicPath of this._dynamicPaths) {

rawPathParams = matched.rawPathParams;
path = dynamicPath.path;
}

@@ -114,3 +116,4 @@ }

value,
rawPathParams
rawPathParams,
path
};

@@ -117,0 +120,0 @@ }

import * as oas3 from 'openapi3-ts';
import { ParametersMap } from '../types';
export interface ResolvedServer {
/**
* The server definition that was matched from the `servers`
* section of the OpenAPI document.
*/
oaServer: oas3.ServerObject;
/**
* The values of any template parameters defined in
* the `server.url` of the matching `server` object.
*/
serverParams: ParametersMap<string | string[]>;
/** The unmatched portion of the `pathname`. */
pathnameRest: string;
/** The matched portion of the `pathname`. */
baseUrl: string;
}

@@ -17,11 +28,5 @@ export default class Servers {

* @returns If a matching `server` is found, returns a
* `{serverObject, serverParams, pathnameRest}` object, where:
* - `serverObject` is the server definition that was matched from the `servers`
* section of the OpenAPI document.
* - `serverParams` are the values of any template parameters defined in
* the `server.url` of the matching `server` object.
* - `pathnameRest` is the unmatched portion of the `pathname`.
* Returns `null` if no match was found.
* `ResolvedServer` object. Returns `null` if no match was found.
*/
resolveServer(host: string, pathname: string): ResolvedServer | null;
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const PathResolver_1 = require("./Paths/PathResolver");
const FULL_URL_RE = /^(.*?):\/\/([^/]*?)\/(.*)$/; // e.g. https://foo.bar/v1
const FULL_URL_RE = /^(.*?):\/\/([^/]*?)(?:\/(.*))?$/; // e.g. https://foo.bar/v1
const ABSOLUTE_URL_RE = /^(\/.*)$/; // e.g. /v1

@@ -14,16 +14,23 @@ function generateServerParser(oaServer) {

if (serverUrl === '') {
result = (_host, pathname) => ({ oaServer, pathnameRest: pathname, serverParams: Object.create(null) });
result = (_host, pathname) => ({
oaServer,
pathnameRest: pathname,
serverParams: Object.create(null),
baseUrl: '',
});
// tslint:disable-next-line: no-conditional-assignment
}
else if (match = FULL_URL_RE.exec(serverUrl)) { // tslint:disable-line: no-conditional-assignment
else if ((match = FULL_URL_RE.exec(serverUrl))) {
const hostname = match[2];
const basepath = match[3];
const basepath = match[3] || '';
const { parser: hostnameAcceptFunction } = PathResolver_1.compileTemplatePath(hostname);
let basepathAcceptFunction;
if (basepath) {
basepathAcceptFunction = PathResolver_1.compileTemplatePath('/' + basepath, { openEnded: true }).parser;
basepathAcceptFunction = PathResolver_1.compileTemplatePath('/' + basepath, { openEnded: true })
.parser;
}
else {
basepathAcceptFunction = () => ({
matched: '/',
rawPathParams: Object.create(null)
matched: '',
rawPathParams: Object.create(null),
});

@@ -39,2 +46,3 @@ }

serverParams: Object.assign({}, hostMatch.rawPathParams, pathMatch.rawPathParams),
baseUrl: pathMatch.matched,
};

@@ -46,4 +54,5 @@ }

};
// tslint:disable-next-line: no-conditional-assignment
}
else if (match = ABSOLUTE_URL_RE.exec(serverUrl)) { // tslint:disable-line: no-conditional-assignment
else if ((match = ABSOLUTE_URL_RE.exec(serverUrl))) {
const basepath = match[1];

@@ -57,3 +66,4 @@ const { parser: basepathParser } = PathResolver_1.compileTemplatePath(basepath, { openEnded: true });

serverParams: pathMatch.rawPathParams,
pathnameRest: pathname.slice(pathMatch.matched.length)
pathnameRest: pathname.slice(pathMatch.matched.length),
baseUrl: pathMatch.matched,
};

@@ -83,9 +93,3 @@ }

* @returns If a matching `server` is found, returns a
* `{serverObject, serverParams, pathnameRest}` object, where:
* - `serverObject` is the server definition that was matched from the `servers`
* section of the OpenAPI document.
* - `serverParams` are the values of any template parameters defined in
* the `server.url` of the matching `server` object.
* - `pathnameRest` is the unmatched portion of the `pathname`.
* Returns `null` if no match was found.
* `ResolvedServer` object. Returns `null` if no match was found.
*/

@@ -92,0 +96,0 @@ resolveServer(host, pathname) {

@@ -13,2 +13,5 @@ /// <reference types="node" />

}
export interface ExegesisRoute {
path: string;
}
export interface ExegesisResponse {

@@ -64,2 +67,4 @@ statusCode: number;

options: ExegesisOptions;
route: ExegesisRoute;
baseUrl: string;
}

@@ -152,2 +157,4 @@ export interface ExegesisPluginContext extends ExegesisContextBase {

api: T;
path: string;
baseUrl: string;
}

@@ -154,0 +161,0 @@ export interface ApiInterface<T> {

{
"name": "exegesis",
"version": "2.1.1",
"version": "2.2.0",
"description": "Parses OpenAPI documents",

@@ -59,3 +59,3 @@ "main": "lib/index.js",

"@types/mocha": "^5.2.6",
"@types/node": "^12.0.1",
"@types/node": "^12.12.2",
"@types/pump": "^1.0.1",

@@ -62,0 +62,0 @@ "@types/qs": "^6.5.1",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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