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

openapi-format

Package Overview
Dependencies
Maintainers
0
Versions
71
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

openapi-format - npm Package Compare versions

Comparing version 1.24.2 to 1.25.0

utils/overlay.js

59

bin/cli.js

@@ -24,2 +24,3 @@ #!/usr/bin/env node

.option('-g, --generateFile <generateFile>', 'the file to specify generate rules')
.option('-l, --overlayFile <overlayFile>', 'the file to specify OpenAPI overlay changes')
.option('-c, --configFile <configFile>', 'the file with the OpenAPI-format CLI options')

@@ -202,2 +203,18 @@ .option('--no-sort', `don't sort the OpenAPI file`)

// Set OpenAPI overlay actions
if (options && options.overlayFile) {
infoOut(`- Overlay file:\t\t${options.overlayFile}`); // LOG - Casing file
try {
let overlayOptions = {overlaySet: {}};
overlayOptions.overlaySet = await openapiFormat.parseFile(options.overlayFile);
options = Object.assign({}, options, overlayOptions);
} catch (err) {
console.error('\x1b[31m', `Overlay file error - no such file or directory "${options.overlayOptions}"`);
if (options.verbose >= 1) {
console.error(err);
}
process.exit(1);
}
}
let resObj = {};

@@ -239,2 +256,19 @@ let output = {};

// Apply OpenAPI overlay actions
if (options.overlaySet) {
const resOverlay = await openapiFormat.openapiOverlay(resObj, options);
if (
resOverlay?.resultData &&
(resOverlay.resultData.unusedActions ||
resOverlay.resultData.totalUsedActions ||
resOverlay.resultData.totalActions)
) {
cliLog.unusedActions = resOverlay.resultData.unusedActions || [];
cliLog.totalUsedActions = resOverlay.resultData.totalUsedActions || 0;
cliLog.totalUnusedActions = resOverlay.resultData.totalUnusedActions || 0;
cliLog.totalActions = resOverlay.resultData.totalActions || 0;
}
resObj = resOverlay.data;
}
// Format & Order OpenAPI document

@@ -333,2 +367,27 @@ if (options.sort === true) {

// Show unused components
if (options.overlaySet && (cliLog?.totalActions || cliLog?.totalUsedActions || cliLog?.unusedActions)) {
// Log summary of actions
logOut(`${consoleLine}`, options.verbose); // LOG - horizontal rule
logOut(`OpenAPI Overlay actions summary:`, options.verbose);
logOut(`- Total actions: \t${cliLog.totalActions}`, options.verbose);
logOut(`- Applied actions: \t${cliLog.totalUsedActions}`, options.verbose);
logOut(`- Unused actions: \t${cliLog.totalUnusedActions}`, options.verbose);
const cliOut = [];
cliLog.unusedActions.forEach(action => {
const description = action.description || 'No description provided';
cliOut.push(
`- Target: ${action.target}\n Type: ${action.update ? 'update' : action.remove ? 'remove' : 'unknown'}`
);
});
if (cliLog.unusedActions.length > 0) {
// Log unused actions
logOut(`${consoleLine}`, options.verbose); // LOG - horizontal rule
logOut(`Unused overlay actions:`, options.verbose);
logOut(cliOut.join('\n'), options.verbose);
}
}
// Final result

@@ -335,0 +394,0 @@ infoOut(`\x1b[32m${consoleLine}\x1b[0m`); // LOG - horizontal rule

4

CHANGELOG.md
## unreleased
## [1.25.0] - 2025-01-01
- CLI - Added option to apply OpenAPI overlay actions
## [1.24.2] - 2024-10-07

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

@@ -35,2 +35,3 @@ #!/usr/bin/env node

const {dirname, extname} = require('path');
const {openapiOverlay, resolveJsonPath, resolveJsonPathValue} = require('./utils/overlay');

@@ -1149,2 +1150,3 @@ /**

openapiChangeCase: openapiChangeCase,
openapiOverlay: openapiOverlay,
openapiSplit: openapiSplit,

@@ -1160,3 +1162,5 @@ openapiConvertVersion: openapiConvertVersion,

analyzeOpenApi: analyzeOpenApi,
changeCase: changeCase
changeCase: changeCase,
resolveJsonPath: resolveJsonPath,
resolveJsonPathValue: resolveJsonPathValue
};
{
"name": "openapi-format",
"version": "1.24.2",
"version": "1.25.0",
"description": "Format an OpenAPI document by ordering, formatting and filtering fields.",

@@ -15,2 +15,4 @@ "keywords": [

"case",
"generate",
"overlay",
"cli"

@@ -41,2 +43,3 @@ ],

"commander": "^7.2.0",
"jsonpath-plus": "^10.2.0",
"neotraverse": "^0.6.18"

@@ -61,2 +64,3 @@ },

"utils/logging.js",
"utils/overlay.js",
"utils/parseTpl.js",

@@ -63,0 +67,0 @@ "utils/sorting.js",

// openapi-format.d.ts
declare module 'openapi-format' {
// OpenAPI types
import { OpenAPIV3 } from 'openapi-types'
// OpenAPI Overlay
interface OpenAPIOverlay {
overlay: string;
info: Info;
actions: OverlayAction[];
}
interface Info {
title: string;
version: string;
}
type OverlayAction = UpdateAction | RemoveAction;
interface UpdateAction {
target: string;
update: Record<string, unknown>;
description?: string;
}
interface RemoveAction {
target: string;
remove: boolean;
description?: string;
}
// OpenAPI Format types
interface OpenAPISortSet {

@@ -81,5 +109,16 @@ root?: Array<'openapi' | 'info' | 'servers' | 'paths' | 'components' | 'tags' | 'x-tagGroups' | 'externalDocs'>

interface OpenAPIOverlayOptions {
overlaySet: {
actions: Array<{
target: string;
update?: Record<string, unknown>;
remove?: boolean;
description?: string;
}>;
};
}
interface OpenAPIResult {
data: OpenAPIV3.Document | string
resultData: Record<string, never>
resultData: Record<string, any>
}

@@ -152,2 +191,13 @@

/**
* Applies OpenAPI overlay actions to an OpenAPI Specification (OAS).
* @param {Object} baseOAS - The OpenAPI document.
* @param {Object} options - The options containing overlaySet and additional configurations.
* @returns {Object} - The processed OpenAPI Specification and result metadata.
*/
export function openapiOverlay(
baseOAS: OpenAPIV3.Document,
options: OpenAPIOverlayOptions
): Promise<OpenAPIResult>;
/**
* Parses a JSON or YAML file into a JavaScript object.

@@ -195,2 +245,3 @@ * @param {string} filePath - The path to the JSON or YAML file.

): Promise<void>;
/**

@@ -221,2 +272,24 @@ * Changes the case of a given string to the specified case type.

): Promise<string>;
/**
* Resolves JSONPath expressions to matching nodes in an object.
* @param {Object} obj - The object to resolve paths in.
* @param {string} path - The JSONPath-like expression.
* @returns {Array<{ value: any; parent: any; key: string | number }>} - An array of matching nodes with value, parent, and key metadata.
*/
export function resolveJsonPath(
obj: Record<string, unknown>,
path: string
): Array<{ value: any; parent: any; key: string | number }>;
/**
* Resolves JSONPath expressions to matching node values in an object.
* @param {Object} obj - The object to resolve paths in.
* @param {string} path - The JSONPath-like expression.
* @returns {Array<any>} - An array of matching node values.
*/
export function resolveJsonPathValue(
obj: Record<string, unknown>,
path: string
): Array<any>;
}

@@ -15,2 +15,7 @@ const fs = require('fs');

async function parseString(str, options = {}) {
// Exit early
if (str.length === 0) {
return str;
}
// Convert large number values safely before parsing

@@ -17,0 +22,0 @@ let encodedContent = encodeLargeNumbers(str);

Sorry, the diff of this file is too big to display

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