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

openapi-format

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

openapi-format - npm Package Compare versions

Comparing version 1.6.4 to 1.7.0

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

let cliLog = {};
const consoleLine = process.stdout.columns ? '='.repeat(process.stdout.columns) : '='.repeat(80)
const consoleLine = process.stdout.columns ? '='.repeat(process.stdout.columns - 6) : '='.repeat(80)

@@ -218,5 +218,5 @@ if (!oaFile) {

// Final result
infoOut(`${consoleLine}\n`); // LOG - horizontal rule
infoOut(`✅ OpenAPI ${outputLogFiltered}formatted successfully\n`, 99) // LOG - success message
infoOut(`${consoleLine}\n`); // LOG - horizontal rule
infoOut(`\x1b[32m ${consoleLine}\x1b[0m`); // LOG - horizontal rule
infoOut(`\x1b[32m ✅\tOpenAPI ${outputLogFiltered}formatted successfully\x1b[0m`, 99) // LOG - success message
infoOut(`\x1b[32m ${consoleLine}\x1b[0m`); // LOG - horizontal rule
}
{
"methods": [],
"inverseMethods": [],
"tags": [],
"inverseTags": [],
"operationIds": [],
"inverseOperationIds": [],
"operations": [],

@@ -6,0 +9,0 @@ "flags": [],

@@ -236,2 +236,8 @@ #!/usr/bin/env node

const filterProps = [...filterSet.operationIds, ...filterSet.flags, ...fixedFlags];
// Inverse object filters
const inverseFilterKeys = [...filterSet.inverseMethods];
const inverseFilterProps = [...filterSet.inverseOperationIds];
const inverseFilterArray = [...filterSet.inverseTags];
const stripFlags = [...filterSet.stripFlags];

@@ -309,2 +315,10 @@ const stripUnused = [...filterSet.unusedComponents];

// Filter out object matching the inverse "methods"
if (inverseFilterKeys.length > 0 && !inverseFilterKeys.includes(this.key)
&& this.parent && this.parent.parent && this.parent.parent.key === 'paths') {
// debugFilterStep = 'Filter - inverse methods'
// Parent has other nodes, so remove only targeted node
this.remove();
}
// Filter out object matching the "methods"

@@ -319,2 +333,16 @@ if (filterKeys.length > 0 && filterKeys.includes(this.key)) {

if (Array.isArray(node)) {
// Filter out object matching the inverse "tags"
if (inverseFilterArray.length > 0 && this.key === 'tags' && !inverseFilterArray.some(i => node.includes(i)) && this.parent.parent !== undefined) {
// debugFilterStep = 'Filter - inverse tags'
// Top parent has other nodes, so remove only targeted parent node of matching element
this.parent.delete();
}
// Filter out the top OpenApi.tags matching the inverse "tags"
if (inverseFilterArray.length > 0 && this.key === 'tags' && this.parent.parent === undefined) {
// debugFilterStep = 'Filter - inverse top tags'
node = node.filter(value => inverseFilterArray.includes(value.name))
this.update(node);
}
// Filter out object matching the "tags"

@@ -386,2 +414,8 @@ if (filterArray.length > 0 && this.key === 'tags' && filterArray.some(i => node.includes(i))) {

// Filter out fields matching the inverse Tags/operationIds
if (inverseFilterProps.length > 0 && this.key === 'operationId' && !inverseFilterProps.includes(node)) {
// debugFilterStep = 'Filter - Single field - Inverse Tags/operationIds'
this.parent.remove();
}
// Filter out fields matching the Tags/operationIds

@@ -464,6 +498,8 @@ if (filterProps.length > 0 && filterProps.includes(node)) {

if (fixedFlags.length > 0) {
debugFilterStep = 'Filter - tag/x-tagGroup - fixed flags'
// debugFilterStep = 'Filter - tag/x-tagGroup - fixed flags'
// Deep filter array of tag/x-tagGroup
let oaTags = JSON.parse(JSON.stringify(node)); // Deep copy of the object
const oaFilteredTags = oaTags.filter(item => !fixedFlags.some(i => (Object.keys(item || {}).includes(i))));
const oaFilteredTags = oaTags
.filter(item => !fixedFlags.some(i => (Object.keys(item || {}).includes(i))))
.filter(e => e);
this.update(oaFilteredTags);

@@ -474,3 +510,3 @@ }

// Remove empty objects
if (node && Object.keys(node).length === 0 && node.constructor === Object) {
if (node && Object.keys(node).length === 0 && node.constructor === Object && this.parent.key !== 'security') {
// debugFilterStep = 'Filter - Remove empty objects'

@@ -477,0 +513,0 @@ this.delete();

{
"name": "openapi-format",
"version": "1.6.4",
"version": "1.7.0",
"description": "Format an OpenAPI document by ordering and filtering fields.",

@@ -5,0 +5,0 @@ "keywords": [

@@ -117,3 +117,3 @@ # openapi-format

-o, --output Save the formated OpenAPI file as JSON/YAML [path]
--output, -o Save the formated OpenAPI file as JSON/YAML [path]

@@ -141,17 +141,17 @@ --sortFile The file to specify custom OpenAPI fields ordering [path]

| Parameter | Alias | Description | Input type | Default | Required/Optional |
|-------------------------|---------------|-----------------------------------------------------------------------------|--------------|-----------------------------|-------------------|
| file | | the original OpenAPI file | path to file | | required |
| --output | -o | save the formatted OpenAPI file as JSON/YAML | path to file | | optional |
| --sortFile | -s | the file to specify custom OpenAPI fields ordering | path to file | defaultSort.json | optional |
| --filterFile | -f | the file to specify filter setting | path to file | defaultFilter.json | optional |
| --no-sort | | don't sort the OpenAPI file | boolean | FALSE | optional |
| --sortComponentsFile | | sort the items of the components (schemas, parameters, ...) by alphabet | path to file | defaultSortComponents.json | optional |
| --rename | | rename the OpenAPI title | string | | optional |
| --configFile | -c | the file with all the format config options | path to file | | optional |
| --lineWidth | | max line width of YAML output | number | -1 (Infinity) | optional |
| --json | | prints the file to stdout as JSON | | FALSE | optional |
| --yaml | | prints the file to stdout as YAML | | FALSE | optional |
| --verbose | -v, -vv, -vvv | verbosity that can be increased, which will show more output of the process | | | optional |
| --help | h | display help for command | | | optional |
| Parameter | Alias | Description | Input type | Default | Info |
|-----------------------|---------------|-----------------------------------------------------------------------------|--------------|-----------------------------|-----------|
| file | | the original OpenAPI file | path to file | | required |
| --output | -o | save the formatted OpenAPI file as JSON/YAML | path to file | | optional |
| --sortFile | -s | the file to specify custom OpenAPI fields ordering | path to file | defaultSort.json | optional |
| --filterFile | -f | the file to specify filter setting | path to file | defaultFilter.json | optional |
| --no-sort | | don't sort the OpenAPI file | boolean | FALSE | optional |
| --sortComponentsFile | | sort the items of the components (schemas, parameters, ...) by alphabet | path to file | defaultSortComponents.json | optional |
| --rename | | rename the OpenAPI title | string | | optional |
| --configFile | -c | the file with all the format config options | path to file | | optional |
| --lineWidth | | max line width of YAML output | number | -1 (Infinity) | optional |
| --json | | prints the file to stdout as JSON | | FALSE | optional |
| --yaml | | prints the file to stdout as YAML | | FALSE | optional |
| --verbose | -v, -vv, -vvv | verbosity that can be increased, which will show more output of the process | | | optional |
| --help | h | display help for command | | | optional |

@@ -195,13 +195,16 @@ ## OpenAPI sort configuration options

| Type | Description | Type | Examples |
|------------------|----------------------------------------------|-------|-------------------------------------------|
| methods | a list OpenAPI methods. | array | ['get','post','put'] |
| tags | a list OpenAPI tags. | array | ['pet','user'] |
| operationIds | a list OpenAPI operation ID's. | array | ['findPetsByStatus','updatePet'] |
| operations | a list OpenAPI operations. | array | ['GET::/pets','PUT::/pets'] |
| flags | a list of custom flags | array | ['x-exclude','x-internal'] |
| flagValues | a list of custom flags with a specific value | array | ['x-version: 1.0','x-version: 3.0'] |
| unusedComponents | a list of unused components | array | ['examples','schemas'] |
| stripFlags | a list of custom flags that will be stripped | array | ['x-exclude','x-internal'] |
| textReplace | a list of search & replace values to replace | array | [{'searchFor':'Pet','replaceWith':'Dog'}] |
| Type | Description | Type | Examples |
|---------------------|--------------------------------------------|-------|-------------------------------------------|
| methods | OpenAPI methods. | array | ['get','post','put'] |
| inverseMethods | OpenAPI methods that will be kept. | array | ['get','post','put'] |
| tags | OpenAPI tags. | array | ['pet','user'] |
| inverseTags | OpenAPI tags that will be kept. | array | ['pet','user'] |
| operationIds | OpenAPI operation ID's. | array | ['findPetsByStatus','updatePet'] |
| inverseOperationIds | OpenAPI operation ID's that will be kept. | array | ['findPetsByStatus','updatePet'] |
| operations | OpenAPI operations. | array | ['GET::/pets','PUT::/pets'] |
| flags | Custom flags | array | ['x-exclude','x-internal'] |
| flagValues | Custom flags with a specific value | array | ['x-version: 1.0','x-version: 3.0'] |
| unusedComponents | Unused components | array | ['examples','schemas'] |
| stripFlags | Custom flags that will be stripped | array | ['x-exclude','x-internal'] |
| textReplace | Search & replace values to replace | array | [{'searchFor':'Pet','replaceWith':'Dog'}] |

@@ -208,0 +211,0 @@ Some more details on the available filter types: