api-doc-validator
Advanced tools
Comparing version 2.7.2 to 2.7.3
@@ -6,7 +6,13 @@ module.exports = ajvToJsDoc; | ||
function ajvToJsDoc(schema, params = {}) { | ||
const {schemas = {}, any = '*', jsDocNull = true, anyObject = 'Object'} = params; | ||
const {schemas = {}, any = '*', jsDocNull = true, anyObject = 'Object', usedSchemas} = params; | ||
const {type, title} = schema; | ||
if (schemas.hasOwnProperty(title)) return normalizeName(title); | ||
if (schemas.hasOwnProperty(title)) { | ||
if (usedSchemas && !usedSchemas.includes(title)) { | ||
usedSchemas.push(title); | ||
} | ||
return normalizeName(title); | ||
} | ||
if (type === 'string' || type === 'number') { | ||
@@ -61,3 +67,13 @@ if (!schema.enum) return type; | ||
if (anyOf || allOf) { | ||
return (anyOf || allOf).map(item => ajvToJsDoc(item, params)).join('|'); | ||
const list = []; | ||
for (const item of (anyOf || allOf)) { | ||
const schema = ajvToJsDoc(item, params); | ||
if (list.includes(schema)) continue; | ||
list.push(schema); | ||
} | ||
return list.join('|'); | ||
} | ||
@@ -64,0 +80,0 @@ |
@@ -55,3 +55,2 @@ const {readFileSync, createWriteStream} = require('fs'); | ||
const dtsStream = dtsFile && createWriteStream(dtsFile); | ||
const dtsParams = {any: 'any'} | ||
@@ -156,3 +155,5 @@ const p = Promise.all([ | ||
const methodBase = (params) => createMethod({outputDir, endpoints, schemas, ...params}); | ||
const usedSchemas = []; | ||
const methodBase = (params) => createMethod({outputDir, endpoints, schemas, usedSchemas, ...params}); | ||
const methodJs = (method, tag, indent = 1) => methodBase({tpl: methodTpl, method, tag, indent, generator: ajvToJsDoc}); | ||
@@ -200,3 +201,3 @@ const methodDts = (method, tag, indent = 1) => methodBase({tpl: `method = (params) => Promise<*>`, indent, method, tag, generator: ajvToDTs, any: 'any'}); | ||
for (let name in schemas) { | ||
for (let name of usedSchemas) { | ||
const schema = ajvToDTs(schemas[name]); | ||
@@ -257,6 +258,6 @@ name = normalizeName(name); | ||
function createMethod({tpl, endpoints, outputDir, indent, method, tag, schemas, generator, any = '*'}) { | ||
function createMethod({tpl, endpoints, outputDir, indent, method, tag, schemas, generator, usedSchemas, any = '*'}) { | ||
const n = tag.match(/\d+$/)[0]; | ||
const e = endpoints[n]; | ||
const jsDoc = (schema) => generator(schema, {schemas, any}); | ||
const jsDoc = (schema) => generator(schema, {schemas, any, usedSchemas}); | ||
@@ -263,0 +264,0 @@ |
{ | ||
"name": "api-doc-validator", | ||
"version": "2.7.2", | ||
"version": "2.7.3", | ||
"description": "api doc and validator", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
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
58342
1634