api-doc-validator
Advanced tools
Comparing version 2.15.0 to 2.16.0
12
cli.js
@@ -20,4 +20,4 @@ #!/usr/bin/env node | ||
.option('-o, --open-api <path>', 'generate Swagger OpenAPI v3 json') | ||
.option('-j, --json <path>', 'generate endpoints json') | ||
.option('-s, --export-schemas <names...>', 'generate schemas json') | ||
.option('-j, --json <path>', 'save endpoints to json file') | ||
.option('-s, --only-schemas [names...]', 'save schemas instead of endpoints to json file') | ||
.option('-n, --namespace <namespace>', 'generate validators only with this namespace or comma separated namespaces') | ||
@@ -76,3 +76,3 @@ .option('-M, --default-method <method>', 'default @url METHOD') | ||
'className', | ||
'exportSchemas', | ||
'onlySchemas', | ||
'pathToRegexp', | ||
@@ -213,3 +213,3 @@ 'requestMethod', | ||
if (config.json) { | ||
if (config.json && !config.onlySchemas) { | ||
const generateJson = require('./lib/generate/json'); | ||
@@ -222,7 +222,7 @@ | ||
if (config.exportSchemas) { | ||
if (config.onlySchemas) { | ||
const generateSchemas = require('./lib/generate/schemas'); | ||
promises.push( | ||
generateSchemas(endpoints, config.exportSchemas, configDir) | ||
generateSchemas(endpoints, config.onlySchemas, config.json) | ||
); | ||
@@ -229,0 +229,0 @@ } |
@@ -17,3 +17,3 @@ export function filesToEndpoints(files: Strings, options: Partial<CliConfig>): Promise<Endpoint[]>; | ||
json: string, | ||
exportSchemas: Strings, | ||
onlySchemas: Strings, | ||
namespace: Strings, | ||
@@ -20,0 +20,0 @@ defaultMethod: "GET" | "POST", |
const {writeFile} = require('fs/promises'); | ||
const {resolve} = require('path'); | ||
module.exports = async function (endpoints, names, cwd = process.cwd()) { | ||
let path = names.find(name => /\.json$/i.test(name)); | ||
if (path) { | ||
names = names.filter(name => name !== path); | ||
path = resolve(cwd, path); | ||
} | ||
module.exports = async function (endpoints, names, path) { | ||
const schemas = []; | ||
@@ -18,8 +10,6 @@ | ||
for (const {name, schema} of e.schema) { | ||
if (names.length > 0) { | ||
if (name && names.includes(name)) { | ||
schemas.push(schema); | ||
} | ||
if (names === true) { | ||
schemas.push(schema); | ||
} | ||
else { | ||
else if (name && names.includes(name)) { | ||
schemas.push(schema); | ||
@@ -26,0 +16,0 @@ } |
{ | ||
"name": "api-doc-validator", | ||
"version": "2.15.0", | ||
"version": "2.16.0", | ||
"description": "api doc and validator", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -365,4 +365,4 @@ # api ➡️ doc ➡️ validator | ||
-o, --open-api <path> generate Swagger OpenAPI v3 json | ||
-j, --json <path> generate endpoints json | ||
-s, --export-schemas <names...> generate schemas json | ||
-j, --json <path> save endpoints to json file | ||
-s, --only-schemas [names...] save schemas instead of endpoints to json file | ||
-n, --namespace <namespace> generate validators only with this namespace or comma separated namespaces | ||
@@ -568,4 +568,4 @@ -M, --default-method <method> default @url METHOD | ||
* `json` same as `--json <path>` | ||
* `exportSchemas` array of schemas names to be saved as json. Could be empty array then will be exported all schemas. | ||
Last item of this array could be path to json file, if no path then formatted json will output to console | ||
* `onlySchemas` array of schemas names to be saved as json. Could be `true` or empty array then will be exported all schemas. | ||
If no `json` parameter passed then formatted json will output to console | ||
* `express` same as `--express <path>` | ||
@@ -572,0 +572,0 @@ * `openApi` same as `--open-api <path>` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
63428
1790