fast-typescript-to-jsonschema
Advanced tools
Comparing version 0.0.4 to 0.0.5
@@ -226,9 +226,13 @@ "use strict"; | ||
entry.refKeyTime[$refKey] = (entry.refKeyTime[$refKey] || 0) + 1; | ||
if ($refJson.type === typescript_to_file_datas_1.ImportType.ImportNamespaceSpecifier) { | ||
$refKey = otherKeys.join('.'); | ||
} | ||
item.$ref = `#/definitions/${$refKey}`; | ||
return $refJson; | ||
} | ||
entry.keySet.add($refKey); | ||
entry.refKeyTime[$refKey] = (entry.refKeyTime[$refKey] || 0) + 1; | ||
if ($refJson.type === typescript_to_file_datas_1.ImportType.ImportNamespaceSpecifier) { | ||
$refKey = otherKeys.join('.'); | ||
} | ||
entry.keySet.add($refKey); | ||
entry.refKeyTime[$refKey] = (entry.refKeyTime[$refKey] || 0) + 1; | ||
item.$ref = `#/definitions/${$refKey}`; | ||
@@ -235,0 +239,0 @@ if (!$refJson.$ref || fileJson[$refJson.$ref.replace(/#(\/definitions\/)?/, '')]) { |
@@ -37,2 +37,3 @@ export declare type AnyOption = Record<string, any>; | ||
refKey?: string; | ||
namespaces?: string[]; | ||
} | ||
@@ -43,2 +44,3 @@ export interface TSTypeAnnotationConfig { | ||
file?: string; | ||
namespaces?: string[]; | ||
} | ||
@@ -45,0 +47,0 @@ export declare type EntryType = { |
@@ -29,3 +29,3 @@ import type { AnyOption, TSTypeAnnotationConfig, TypeAnnotationConfig } from './types'; | ||
}; | ||
getTypeName(typeName: AnyOption): string; | ||
getTypeName(typeName: AnyOption, namespaces?: string[]): string; | ||
simpleTsTypeTransform(tsType: string): string | null; | ||
@@ -32,0 +32,0 @@ transformTypeAnnotation(option: TypeAnnotationConfig): AnyOption | null; |
@@ -39,3 +39,3 @@ "use strict"; | ||
handleTSTypeAnnotation(json, parentJson, option) { | ||
const { node, parentKey, file } = option || {}; | ||
const { node, parentKey, file, namespaces } = option || {}; | ||
const key = _.get(node, 'key.name') || _.get(node, 'key.value') || ''; | ||
@@ -49,2 +49,3 @@ const required = !node.optional; | ||
attrKey: key, | ||
namespaces, | ||
}); | ||
@@ -248,3 +249,3 @@ if (typeAnnotation && typeof typeAnnotation === 'object') { | ||
const key = _.get(path, 'node.key.name') || _.get(path, 'node.key.value'); | ||
_this.handleTSTypeAnnotation(json, null, { node: path.node, file }); | ||
_this.handleTSTypeAnnotation(json, null, { node: path.node, file, namespaces, }); | ||
path.traverse({ | ||
@@ -262,2 +263,3 @@ TSTypeLiteral(path) { | ||
file, | ||
namespaces, | ||
}); | ||
@@ -418,5 +420,8 @@ }, | ||
} | ||
getTypeName(typeName) { | ||
getTypeName(typeName, namespaces) { | ||
const name = _.get(typeName, 'name'); | ||
if (name) { | ||
if (typeName.type === 'Identifier' && Array.isArray(namespaces) && namespaces.length) { | ||
return `${namespaces.join('.')}.${name}`; | ||
} | ||
return name; | ||
@@ -449,3 +454,3 @@ } | ||
transformTypeAnnotation(option) { | ||
const { typeAnnotation, file, attrKey, refKey } = option || {}; | ||
const { typeAnnotation, file, attrKey, refKey, namespaces } = option || {}; | ||
if (!typeAnnotation) | ||
@@ -467,3 +472,3 @@ return null; | ||
if (cType === 'TSTypeReference') { | ||
const name = this.getTypeName(typeAnnotation.typeName); | ||
const name = this.getTypeName(typeAnnotation.typeName, namespaces); | ||
const type = this.handleRelationTypes(name); | ||
@@ -477,2 +482,3 @@ let items = null; | ||
refKey: name, | ||
namespaces, | ||
}); | ||
@@ -505,3 +511,8 @@ } | ||
typeAnnotation.params.forEach((item) => { | ||
const res = this.transformTypeAnnotation({ typeAnnotation: item, file, attrKey }); | ||
const res = this.transformTypeAnnotation({ | ||
typeAnnotation: item, | ||
file, | ||
attrKey, | ||
namespaces, | ||
}); | ||
if (res) { | ||
@@ -524,2 +535,3 @@ params.push(res); | ||
attrKey, | ||
namespaces, | ||
}); | ||
@@ -532,2 +544,3 @@ } | ||
attrKey, | ||
namespaces, | ||
}); | ||
@@ -541,2 +554,3 @@ return type ? { type: 'array', items: type } : null; | ||
attrKey, | ||
namespaces, | ||
}); | ||
@@ -549,3 +563,3 @@ return type; | ||
members.forEach((item) => { | ||
this.handleTSTypeAnnotation(json, null, { node: item, file }); | ||
this.handleTSTypeAnnotation(json, null, { node: item, file, namespaces, }); | ||
}); | ||
@@ -552,0 +566,0 @@ this.formatJsonSchema(json); |
{ | ||
"name": "fast-typescript-to-jsonschema", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"description": "fast-typescript-to-jsonschema generates JSON Schema files from your Typescript sources.", | ||
@@ -5,0 +5,0 @@ "main": "./dist/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
123461
1397