@hoth/typescript-to-json-schema
Advanced tools
Comparing version
@@ -16,3 +16,3 @@ "use strict"; | ||
} | ||
function isLibPath(filePath) { | ||
function isTsLibPath(filePath) { | ||
return filePath.includes('/node_modules/typescript/lib/'); | ||
@@ -50,3 +50,3 @@ } | ||
} | ||
const path = $ref.split('/'); | ||
const path = $ref.split(exports.REF_PREFIX)[1].split('/'); | ||
const cacheSchema = lodash_1.get(this.defCache, path); | ||
@@ -65,3 +65,3 @@ if (cacheSchema) { | ||
case ts_morph_1.ts.SyntaxKind.ImportSpecifier: { | ||
const realSourceFile = declaration.getImportDeclaration().getModuleSpecifierSourceFile(); | ||
const realSourceFile = identifier.getDefinitions()[0].getSourceFile(); | ||
const node = this.getSourceFileNode(realSourceFile, identifier.getText()); | ||
@@ -118,3 +118,2 @@ if (node) { | ||
catch (err) { | ||
console.log(err); | ||
const { line, column } = sourceFile.getLineAndColumnAtPos(typeNode.getStart()); | ||
@@ -202,3 +201,3 @@ const msg = 'Get schema failed! Ignore this property.'; | ||
return { | ||
$ref: `${exports.REF_PREFIX}${$ref}${accesses.map(a => '/properties/' + util_1.getLiteralTypeValue(a))}` | ||
$ref: `${$ref}${accesses.map(a => '/properties/' + util_1.getLiteralTypeValue(a))}` | ||
}; | ||
@@ -281,3 +280,3 @@ } | ||
} | ||
if (isLibPath(declaration.getSourceFile().getFilePath())) { | ||
if (isTsLibPath(declaration.getSourceFile().getFilePath())) { | ||
return; | ||
@@ -354,3 +353,3 @@ } | ||
const subPath = node.getText().toLowerCase().split('.').join('/'); | ||
return `${getId(node.getSourceFile().getFilePath())}/${subPath}`; | ||
return `${exports.REF_PREFIX}${getId(node.getSourceFile().getFilePath())}/${subPath}`; | ||
} | ||
@@ -364,3 +363,3 @@ let file = null; | ||
}, []); | ||
return `${getId(file.getFilePath())}/${defNames.join('/')}`; | ||
return `${exports.REF_PREFIX}${getId(file.getFilePath())}/${defNames.join('/')}`; | ||
} | ||
@@ -367,0 +366,0 @@ } |
@@ -12,14 +12,19 @@ "use strict"; | ||
function mergeAnyOf(schema) { | ||
const { anyOf } = schema; | ||
if (!anyOf) { | ||
return schema; | ||
const ret = Object.assign({}, schema); | ||
for (const key in ret) { | ||
if (!ret.hasOwnProperty(key)) { | ||
continue; | ||
} | ||
if (lodash_1.isPlainObject(ret[key])) { | ||
ret[key] = mergeAnyOf(ret[key]); | ||
} | ||
} | ||
if (!lodash_1.isArray(anyOf)) { | ||
return lodash_1.omit(schema, 'anyOf'); | ||
if (lodash_1.isArray(ret.anyOf)) { | ||
let afschema = mergeAnyOf(ret.anyOf[0]); | ||
for (let i = 1; i < ret.anyOf.length; i++) { | ||
afschema = util_1.mergeSchema(afschema, mergeAnyOf(ret.anyOf[i])); | ||
} | ||
return Object.assign(lodash_1.omit(ret, 'anyOf'), afschema); | ||
} | ||
let ret = lodash_1.omit(anyOf[0], '$ref'); | ||
for (let i = 1; i < anyOf.length; i++) { | ||
ret = util_1.mergeSchema(ret, lodash_1.omit(anyOf[i], '$ref')); | ||
} | ||
return Object.assign(lodash_1.omit(schema, 'anyOf'), ret); | ||
return lodash_1.omit(ret, 'anyOf'); | ||
} | ||
@@ -64,11 +69,11 @@ class Translate { | ||
if (isRef && $ref) { | ||
lodash_1.set(definitions, $ref.split('/'), schema); | ||
Object.assign(root, { $ref: `${definition_1.REF_PREFIX}${$ref}` }); | ||
lodash_1.set(definitions, $ref.split(definition_1.REF_PREFIX)[1].split('/'), schema); | ||
} | ||
else { | ||
Object.assign(root, schema); | ||
delete root.$ref; | ||
} | ||
} | ||
schema = mergeAnyOf(schema); | ||
return Object.keys(definitions).length === 0 ? schema : Object.assign(Object.assign({}, schema), { definitions }); | ||
schema = Object.keys(definitions).length === 0 ? schema : Object.assign(Object.assign({}, schema), { definitions }); | ||
return mergeAnyOf(schema); | ||
} | ||
@@ -75,0 +80,0 @@ mergeDefinitions(schema) { |
{ | ||
"name": "@hoth/typescript-to-json-schema", | ||
"version": "2.1.0-3", | ||
"version": "2.1.0-4", | ||
"description": "typescript to json-schema transpiler", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
83509
0.46%1071
0.37%