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

@oas-tools/commons

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@oas-tools/commons - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

CHANGELOG.md

2

dist/index.d.ts
export * from "./middleware/index.js";
export * from "./utils/index.js";
export * from '../typings'
export CHANGELOG.md LICENSE README.md dist node_modules package-lock.json package.json schemas src tsconfig.json typings from ../typings

@@ -0,0 +0,0 @@ "use strict";

@@ -0,0 +0,0 @@ import { Express } from "express";

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.OASBase = void 0;
const utils_1 = require("../utils");
const operations = [

@@ -22,7 +23,24 @@ "get",

register(app) {
let servers;
if (this.#oasFile.servers?.length > 0) {
servers = _getServers(this.#oasFile.servers);
}
else {
servers = ["/"];
}
Object.entries(this.#oasFile.paths ?? {}).forEach(([path, methodObj]) => {
if (methodObj.servers?.length > 0)
servers = _getServers(methodObj.servers);
Object.keys(methodObj ?? {})
.filter((key) => operations.includes(key))
.forEach((method) => {
app[method](path, this.#middleware);
const pathItemObj = methodObj[method];
if (pathItemObj.servers?.length > 0)
servers = _getServers(pathItemObj.servers);
servers.forEach(prefix => {
app[method]((prefix + path).replace(/\/\//g, "/"), (req, res, next) => {
req.route.path = req.route.path.replace(prefix, prefix === "/" ? "/" : "");
this.#middleware(req, res, next);
});
});
});

@@ -39,1 +57,26 @@ });

exports.OASBase = OASBase;
function _getServers(oasServers) {
if (oasServers.length > 1) {
utils_1.logger.warn("Multiple server hosting is not yet supported.");
}
return [...new Set(oasServers.flatMap(server => {
const url = new URL(server.url, 'http://localhost');
if (url.hostname !== "localhost" && url.hostname !== "127.0.0.1") {
utils_1.logger.warn(`Found ${url.hostname} in servers property: Multiple server hosting is not yet supported. OAS Tools will assume all servers' host as localhost`);
}
if (server.variables) {
return Object.entries(server.variables).flatMap(([varName, varObj]) => {
const regex = new RegExp(`%7B${varName}%7D`, "g");
if (varObj.enum?.length > 0) {
return varObj.enum.map(value => url.pathname.replace(regex, value));
}
else {
return url.pathname.replace(regex, varObj.default);
}
});
}
else {
return url.pathname;
}
}))];
}
export { OASBase } from "./base.js";

@@ -0,0 +0,0 @@ "use strict";

@@ -0,0 +0,0 @@ export * from "./modules/logger.js";

@@ -0,0 +0,0 @@ "use strict";

@@ -0,0 +0,0 @@ declare class BaseError extends Error {

@@ -0,0 +0,0 @@ "use strict";

@@ -0,0 +0,0 @@ import { Logger as winstonLogger } from "winston";

@@ -0,0 +0,0 @@ "use strict";

@@ -0,0 +0,0 @@ export declare function validateOASFile(oasFilePath: string): void;

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

throw new index_1.ValidationError(`Specification file does not meet OpenAPI ${version} schema.\n` +
`${validate.errors.map((e) => `- Validation failed at ${e.instancePath.split('/').map((s) => s.includes('~1') ? `[${s.replaceAll('~1', '/')}]` : s).join('/')} > ${e.message}`).join("\n")}`);
`${validate.errors.map((e) => `- Validation failed at ${e.instancePath.split('/').map((s) => s.includes('~1') ? `[${s.replace(/~1/g, '/')}]` : s).join('/')} > ${e.message}`).join("\n")}`);
}

@@ -43,0 +43,0 @@ }

{
"name": "@oas-tools/commons",
"version": "1.0.1",
"type": "commonjs",

@@ -49,4 +50,3 @@ "description": "Utility library for the development of new features and modules for oas-tools project",

"url": "git+https://github.com/oas-tools/oas-commons.git"
},
"version": "1.0.0"
}
}

@@ -7,5 +7,5 @@ # Commons Library

![npm](https://img.shields.io/npm/v/oas-tools/commons)
![node-current](https://img.shields.io/node/v/oas-tools/commons)
![npm](https://img.shields.io/npm/dw/oas-tools/commons)
![npm](https://img.shields.io/npm/v/@oas-tools/commons)
![node-current](https://img.shields.io/node/v/@oas-tools/commons)
![npm](https://img.shields.io/npm/dw/@oas-tools/commons)
[![Known Vulnerabilities](https://snyk.io/test/github/oas-tools/oas-commons/main/badge.svg)](https://snyk.io/test/github/oas-tools/oas-commons)

@@ -31,2 +31,2 @@ [![Conventional Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-green.svg)](https://conventionalcommits.org)

- **Middleware**:
- **OASBase**: Base class for all middlewares.
- **OASBase**: Base class for all middlewares.

@@ -0,0 +0,0 @@ {

@@ -0,0 +0,0 @@ {

@@ -171,4 +171,3 @@ {

"url": {
"type": "string",
"format": "uri-reference"
"type": "string"
},

@@ -175,0 +174,0 @@ "description": {

@@ -0,0 +0,0 @@ {

export * from './middleware';
export * from './openapi';

@@ -0,0 +0,0 @@ import { OpenAPIV3Doc } from ".";

import { OpenAPIV3, OpenAPIV3_1 } from "openapi-types";
export type OpenAPIV3Doc = OpenAPIV3.Document | OpenAPIV3_1.Document;

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