api-doc-validator
Advanced tools
Comparing version 2.14.0 to 2.15.0
27
cli.js
@@ -21,2 +21,3 @@ #!/usr/bin/env node | ||
.option('-j, --json <path>', 'generate endpoints json') | ||
.option('-s, --export-schemas <names...>', 'generate schemas json') | ||
.option('-n, --namespace <namespace>', 'generate validators only with this namespace or comma separated namespaces') | ||
@@ -42,4 +43,7 @@ .option('-M, --default-method <method>', 'default @url METHOD') | ||
let configPath = program.config; | ||
/** @type {import('./index').CliConfig} */ | ||
const options = program.opts(); | ||
let configPath = options.config; | ||
if (configPath) { | ||
@@ -56,5 +60,7 @@ if (!isAbsolute(configPath)) { | ||
const configDir = configPath ? dirname(configPath) : CWD; | ||
/** @type {import('./index').CliConfig} */ | ||
const config = configPath ? JSON.parse(readFileSync(configPath, 'utf-8')) : {}; | ||
defaults(config, program, [ | ||
defaults(config, options, [ | ||
'include', | ||
@@ -72,2 +78,3 @@ 'baseUrl', | ||
'className', | ||
'exportSchemas', | ||
'pathToRegexp', | ||
@@ -79,3 +86,3 @@ 'requestMethod', | ||
resolvePath(config, program, [ | ||
resolvePath(config, options, [ | ||
'basePath', | ||
@@ -144,3 +151,3 @@ 'apiClient', | ||
var cache = {...defaultSchemas}; | ||
const cache = {...defaultSchemas}; | ||
@@ -160,3 +167,3 @@ filesToEndpoints(files, {...config, schemas: cache}) | ||
var schemas = {}; | ||
const schemas = {}; | ||
@@ -169,3 +176,3 @@ for (let name in cache) { | ||
var promises = []; | ||
const promises = []; | ||
@@ -220,2 +227,10 @@ if (config.apiClient) { | ||
if (config.exportSchemas) { | ||
const generateSchemas = require('./lib/generate/schemas'); | ||
promises.push( | ||
generateSchemas(endpoints, config.exportSchemas, configDir) | ||
); | ||
} | ||
return Promise.all(promises); | ||
@@ -222,0 +237,0 @@ }) |
module.exports = function (data) { | ||
var names = Object.keys(data.schema.properties); | ||
const names = Object.keys(data.schema.properties); | ||
@@ -4,0 +4,0 @@ return { |
const {readFileSync, createWriteStream} = require('fs'); | ||
const {resolve, dirname, relative} = require('path'); | ||
const mkdir = require('mkdirp'); | ||
const {mkdirpSync} = require('mkdirp'); | ||
const Ajv = require('ajv').default; | ||
@@ -29,3 +29,3 @@ const ajv = new Ajv({coerceTypes: true}); | ||
mkdir.sync(outputDir); | ||
mkdirpSync(outputDir); | ||
@@ -32,0 +32,0 @@ const getTemplate = function (filename) { |
@@ -1,8 +0,8 @@ | ||
const {readFile, writeFile} = require('fs').promises; | ||
const {readFile, writeFile} = require('fs/promises'); | ||
const {resolve, dirname} = require('path'); | ||
const mkdir = require('mkdirp'); | ||
const {mkdirpSync} = require('mkdirp'); | ||
const ajvToJsDoc = require('../ajvToJsDoc'); | ||
module.exports = async function (endpoints, file, {schemas = {}, jsdocTypedefs = true}) { | ||
mkdir.sync(dirname(file)); | ||
module.exports = async function (endpoints, file, {schemas = {}, jsdocTypedefs = true} = {}) { | ||
mkdirpSync(dirname(file)); | ||
@@ -9,0 +9,0 @@ endpoints = endpoints.filter(e => !!e.url); |
@@ -1,2 +0,2 @@ | ||
const {writeFile} = require('fs').promises; | ||
const {writeFile} = require('fs/promises'); | ||
@@ -3,0 +3,0 @@ module.exports = function generateJson(endpoints, path) { |
@@ -1,2 +0,2 @@ | ||
const glob = require('glob'); | ||
const {globSync} = require('glob'); | ||
const fs = require('fs'); | ||
@@ -11,3 +11,3 @@ const {join} = require('path'); | ||
return list.concat(glob.sync(path, { | ||
return list.concat(globSync(path, { | ||
nodir: true | ||
@@ -14,0 +14,0 @@ })); |
{ | ||
"name": "api-doc-validator", | ||
"version": "2.14.0", | ||
"version": "2.15.0", | ||
"description": "api doc and validator", | ||
"main": "index.js", | ||
"types": "index.d.ts", | ||
"scripts": { | ||
@@ -33,5 +34,5 @@ "test": "mocha --ui bdd ./tests" | ||
"adv-parser": "^2.4.1", | ||
"commander": "^5.1.0", | ||
"glob": "^7.2.3", | ||
"mkdirp": "^1.0.4" | ||
"commander": "^11.1.0", | ||
"glob": "^10.3.10", | ||
"mkdirp": "^3.0.1" | ||
}, | ||
@@ -38,0 +39,0 @@ "devDependencies": { |
@@ -357,20 +357,26 @@ # api ➡️ doc ➡️ validator | ||
``` | ||
-c, --config <path> path to config json file | ||
-i, --include <path> path to source file | ||
-a, --api-client <path> generate api client | ||
-d, --api-dts <path> generate api client .d.ts file | ||
-b, --base-url <url> default Api.baseUrl | ||
-p, --base-path <path> base path for @see filename comment | ||
-e, --express <path> generate express middleware validator | ||
-o, --open-api <path> generate Swagger OpenAPI v3 json | ||
-j, --json <path> generate endpoints json | ||
-n, --namespace <namespace> generate validators only with this namespace or comma separated namespaces | ||
-M, --default-method <method> default @url METHOD | ||
-C, --default-code <code> default @response CODE | ||
-S, --default-schemas <path> path to js file with default schemas | ||
-T, --jsdoc-methods <boolean> generate @type for methods, default true | ||
-T, --jsdoc-typedefs <boolean> generate @typedef, default true | ||
-R, --jsdoc-refs <boolean> use references to jsdoc @typedef or replace them with reference body, default true | ||
-I, --include-jsdoc <boolean> include to endpoints jsdoc annotations, default false | ||
-P, --extra-props <boolean> value for ajv "object" additionalProperties, default false | ||
-c, --config <path> path to config json file | ||
-i, --include <path> path to source file | ||
-a, --api-client <path> generate api client | ||
-d, --api-dts <path> generate api client .d.ts file | ||
-b, --base-url <url> default Api.baseUrl | ||
-p, --base-path <path> base path for @see filename comment | ||
-e, --express <path> generate express middleware validator | ||
-o, --open-api <path> generate Swagger OpenAPI v3 json | ||
-j, --json <path> generate endpoints json | ||
-s, --export-schemas <names...> generate schemas json | ||
-n, --namespace <namespace> generate validators only with this namespace or comma separated namespaces | ||
-M, --default-method <method> default @url METHOD | ||
-C, --default-code <code> default @response CODE | ||
-S, --default-schemas <path...> path to js file with default schemas | ||
-J, --jsdoc-methods <boolean> generate methods @type, default true | ||
-T, --jsdoc-typedefs <boolean> generate @typedef, default true | ||
-R, --jsdoc-refs <boolean> use references to jsdoc @typedef or replace them with reference body, default true | ||
-I, --include-jsdoc <boolean> include to endpoints standard jsdoc annotations, default false | ||
-P, --extra-props <boolean> value for ajv "object" additionalProperties, default false | ||
-N, --class-name <string> name of generated api client class, default "Api" | ||
--path-to-regexp <boolean> whether to add a path-to-regexp support, default true | ||
--request-method <boolean> whether to add a Api.request method, default true | ||
--get-ajv-method <boolean> whether to add a Api.getAjv method, default true | ||
--error-handler-method <boolean> whether to add a Api.errorHandler method, default true | ||
``` | ||
@@ -562,2 +568,4 @@ | ||
* `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 | ||
* `express` same as `--express <path>` | ||
@@ -564,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
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
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
63596
42
1798
591
11
+ Added@isaacs/cliui@8.0.2(transitive)
+ Added@pkgjs/parseargs@0.11.0(transitive)
+ Addedansi-regex@5.0.16.1.0(transitive)
+ Addedansi-styles@4.3.06.2.1(transitive)
+ Addedbrace-expansion@2.0.1(transitive)
+ Addedcolor-convert@2.0.1(transitive)
+ Addedcolor-name@1.1.4(transitive)
+ Addedcommander@11.1.0(transitive)
+ Addedcross-spawn@7.0.6(transitive)
+ Addedeastasianwidth@0.2.0(transitive)
+ Addedemoji-regex@8.0.09.2.2(transitive)
+ Addedforeground-child@3.3.0(transitive)
+ Addedglob@10.4.5(transitive)
+ Addedis-fullwidth-code-point@3.0.0(transitive)
+ Addedisexe@2.0.0(transitive)
+ Addedjackspeak@3.4.3(transitive)
+ Addedlru-cache@10.4.3(transitive)
+ Addedminimatch@9.0.5(transitive)
+ Addedminipass@7.1.2(transitive)
+ Addedmkdirp@3.0.1(transitive)
+ Addedpackage-json-from-dist@1.0.1(transitive)
+ Addedpath-key@3.1.1(transitive)
+ Addedpath-scurry@1.11.1(transitive)
+ Addedshebang-command@2.0.0(transitive)
+ Addedshebang-regex@3.0.0(transitive)
+ Addedsignal-exit@4.1.0(transitive)
+ Addedstring-width@4.2.35.1.2(transitive)
+ Addedstrip-ansi@6.0.17.1.0(transitive)
+ Addedwhich@2.0.2(transitive)
+ Addedwrap-ansi@7.0.08.1.0(transitive)
- Removedbrace-expansion@1.1.11(transitive)
- Removedcommander@5.1.0(transitive)
- Removedconcat-map@0.0.1(transitive)
- Removedfs.realpath@1.0.0(transitive)
- Removedglob@7.2.3(transitive)
- Removedinflight@1.0.6(transitive)
- Removedinherits@2.0.4(transitive)
- Removedminimatch@3.1.2(transitive)
- Removedmkdirp@1.0.4(transitive)
- Removedonce@1.4.0(transitive)
- Removedpath-is-absolute@1.0.1(transitive)
- Removedwrappy@1.0.2(transitive)
Updatedcommander@^11.1.0
Updatedglob@^10.3.10
Updatedmkdirp@^3.0.1