ts-json-schema-generator
Advanced tools
Comparing version 0.47.0 to 0.48.0
@@ -1,7 +0,3 @@ | ||
export declare abstract class BaseError implements Error { | ||
private callStack; | ||
constructor(); | ||
readonly stack: string; | ||
abstract readonly name: string; | ||
abstract readonly message: string; | ||
export declare abstract class BaseError extends Error { | ||
constructor(message?: string); | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
class BaseError { | ||
constructor() { | ||
this.callStack = new Error().stack; | ||
class BaseError extends Error { | ||
constructor(message) { | ||
super(message); | ||
} | ||
get stack() { | ||
return this.callStack; | ||
} | ||
} | ||
exports.BaseError = BaseError; | ||
//# sourceMappingURL=BaseError.js.map |
@@ -6,5 +6,3 @@ import * as ts from "typescript"; | ||
constructor(diagnostics: ReadonlyArray<ts.Diagnostic>); | ||
readonly name: string; | ||
readonly message: string; | ||
getDiagnostics(): readonly ts.Diagnostic[]; | ||
} |
@@ -7,13 +7,7 @@ "use strict"; | ||
constructor(diagnostics) { | ||
super(); | ||
super(diagnostics | ||
.map((diagnostic) => ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n")) | ||
.join("\n\n")); | ||
this.diagnostics = diagnostics; | ||
} | ||
get name() { | ||
return "DiagnosticError"; | ||
} | ||
get message() { | ||
return this.diagnostics | ||
.map((diagnostic) => ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n")) | ||
.join("\n\n"); | ||
} | ||
getDiagnostics() { | ||
@@ -20,0 +14,0 @@ return this.diagnostics; |
@@ -5,4 +5,2 @@ import { BaseError } from "./BaseError"; | ||
constructor(msg: string); | ||
readonly name: string; | ||
readonly message: string; | ||
} |
@@ -6,13 +6,7 @@ "use strict"; | ||
constructor(msg) { | ||
super(); | ||
super(msg); | ||
this.msg = msg; | ||
} | ||
get name() { | ||
return "LogicError"; | ||
} | ||
get message() { | ||
return this.msg; | ||
} | ||
} | ||
exports.LogicError = LogicError; | ||
//# sourceMappingURL=LogicError.js.map |
@@ -5,5 +5,3 @@ import { BaseError } from "./BaseError"; | ||
constructor(type: string); | ||
readonly name: string; | ||
readonly message: string; | ||
getType(): string; | ||
} |
@@ -6,11 +6,5 @@ "use strict"; | ||
constructor(type) { | ||
super(); | ||
super(`No root type "${type}" found`); | ||
this.type = type; | ||
} | ||
get name() { | ||
return "NoRootTypeError"; | ||
} | ||
get message() { | ||
return `No root type "${this.type}" found`; | ||
} | ||
getType() { | ||
@@ -17,0 +11,0 @@ return this.type; |
@@ -7,6 +7,4 @@ import * as ts from "typescript"; | ||
constructor(node: ts.Node, reference?: ts.Node | undefined); | ||
readonly name: string; | ||
readonly message: string; | ||
getNode(): ts.Node; | ||
getReference(): ts.Node | undefined; | ||
} |
@@ -6,12 +6,6 @@ "use strict"; | ||
constructor(node, reference) { | ||
super(); | ||
super(`Unknown node "${node.getFullText()}`); | ||
this.node = node; | ||
this.reference = reference; | ||
} | ||
get name() { | ||
return "UnknownNodeError"; | ||
} | ||
get message() { | ||
return `Unknown node "${this.node.getFullText()}`; | ||
} | ||
getNode() { | ||
@@ -18,0 +12,0 @@ return this.node; |
@@ -6,5 +6,3 @@ import { BaseType } from "../Type/BaseType"; | ||
constructor(type: BaseType); | ||
readonly name: string; | ||
readonly message: string; | ||
getType(): BaseType; | ||
} |
@@ -6,11 +6,5 @@ "use strict"; | ||
constructor(type) { | ||
super(); | ||
super(`Unknown type "${type.getId()}"`); | ||
this.type = type; | ||
} | ||
get name() { | ||
return "UnknownTypeError"; | ||
} | ||
get message() { | ||
return `Unknown type "${this.type.getId()}"`; | ||
} | ||
getType() { | ||
@@ -17,0 +11,0 @@ return this.type; |
@@ -35,2 +35,5 @@ "use strict"; | ||
} | ||
else if (node.parent.kind === ts.SyntaxKind.Parameter) { | ||
return node.parent; | ||
} | ||
else { | ||
@@ -37,0 +40,0 @@ return node; |
@@ -8,2 +8,5 @@ "use strict"; | ||
const StringType_1 = require("../Type/StringType"); | ||
const TupleType_1 = require("../Type/TupleType"); | ||
const UnionType_1 = require("../Type/UnionType"); | ||
const derefType_1 = require("../Utils/derefType"); | ||
const typeKeys_1 = require("../Utils/typeKeys"); | ||
@@ -18,18 +21,26 @@ class IndexedAccessTypeNodeParser { | ||
createType(node, context) { | ||
const objectType = derefType_1.derefType(this.childNodeParser.createType(node.objectType, context)); | ||
const indexType = this.childNodeParser.createType(node.indexType, context); | ||
if (!(indexType instanceof LiteralType_1.LiteralType || indexType instanceof StringType_1.StringType || indexType instanceof NumberType_1.NumberType)) { | ||
throw new LogicError_1.LogicError(`Unexpected type "${indexType.getId()}" (expected "LiteralType" or "StringType" ` + | ||
`or "NumberType")`); | ||
} | ||
const objectType = this.childNodeParser.createType(node.objectType, context); | ||
const propertyType = typeKeys_1.getTypeByKey(objectType, indexType); | ||
if (!propertyType) { | ||
if (indexType instanceof LiteralType_1.LiteralType) { | ||
throw new LogicError_1.LogicError(`Invalid index "${indexType.getValue()}" in type "${objectType.getId()}"`); | ||
const indexTypes = indexType instanceof UnionType_1.UnionType ? indexType.getTypes() : [indexType]; | ||
const propertyTypes = indexTypes.map(type => { | ||
if (!(type instanceof LiteralType_1.LiteralType || type instanceof StringType_1.StringType | ||
|| type instanceof NumberType_1.NumberType)) { | ||
throw new LogicError_1.LogicError(`Unexpected type "${type.getId()}" (expected "LiteralType" or "StringType" ` + | ||
`or "NumberType")`); | ||
} | ||
else { | ||
throw new LogicError_1.LogicError(`No additional properties in type "${objectType.getId()}"`); | ||
const propertyType = typeKeys_1.getTypeByKey(objectType, type); | ||
if (!propertyType) { | ||
if (type instanceof NumberType_1.NumberType && objectType instanceof TupleType_1.TupleType) { | ||
return new UnionType_1.UnionType(objectType.getTypes()); | ||
} | ||
else if (type instanceof LiteralType_1.LiteralType) { | ||
throw new LogicError_1.LogicError(`Invalid index "${type.getValue()}" in type "${objectType.getId()}"`); | ||
} | ||
else { | ||
throw new LogicError_1.LogicError(`No additional properties in type "${objectType.getId()}"`); | ||
} | ||
} | ||
} | ||
return propertyType; | ||
return propertyType; | ||
}); | ||
return propertyTypes.length === 1 ? propertyTypes[0] : new UnionType_1.UnionType(propertyTypes); | ||
} | ||
@@ -36,0 +47,0 @@ } |
@@ -7,2 +7,3 @@ "use strict"; | ||
const isHidden_1 = require("../Utils/isHidden"); | ||
const modifiers_1 = require("../Utils/modifiers"); | ||
const nodeKey_1 = require("../Utils/nodeKey"); | ||
@@ -69,20 +70,14 @@ class InterfaceAndClassNodeParser { | ||
getProperties(node, context) { | ||
function isProperty(member) { | ||
return ts.isPropertySignature(member) || ts.isPropertyDeclaration(member); | ||
} | ||
return node.members | ||
.filter(isProperty) | ||
.filter(prop => !prop.modifiers || !prop.modifiers.some(modifier => modifier.kind === ts.SyntaxKind.PrivateKeyword || | ||
modifier.kind === ts.SyntaxKind.ProtectedKeyword || | ||
modifier.kind === ts.SyntaxKind.StaticKeyword)) | ||
.reduce((result, propertyNode) => { | ||
const propertySymbol = propertyNode.symbol; | ||
const propertyType = propertyNode.type; | ||
if (!propertyType || isHidden_1.isHidden(propertySymbol)) { | ||
return result; | ||
.reduce((members, member) => { | ||
if (ts.isConstructorDeclaration(member)) { | ||
members.push(...member.parameters.filter(ts.isParameterPropertyDeclaration)); | ||
} | ||
const objectProperty = new ObjectType_1.ObjectProperty(propertySymbol.getName(), this.childNodeParser.createType(propertyType, context), !propertyNode.questionToken); | ||
result.push(objectProperty); | ||
return result; | ||
}, []); | ||
else if (ts.isPropertySignature(member) || ts.isPropertyDeclaration(member)) { | ||
members.push(member); | ||
} | ||
return members; | ||
}, []) | ||
.filter(member => modifiers_1.isPublic(member) && !modifiers_1.isStatic(member) && member.type && !isHidden_1.isNodeHidden(member)) | ||
.map(member => new ObjectType_1.ObjectProperty(member.name.getText(), this.childNodeParser.createType(member.type, context), !member.questionToken)); | ||
} | ||
@@ -89,0 +84,0 @@ getAdditionalProperties(node, context) { |
@@ -93,4 +93,6 @@ "use strict"; | ||
it("type-indexed-access-tuple-2", assertSchema("type-indexed-access-tuple-2", "MyType")); | ||
it("type-indexed-access-tuple-union", assertSchema("type-indexed-access-tuple-union", "FormLayout")); | ||
it("type-indexed-access-object-1", assertSchema("type-indexed-access-object-1", "MyType")); | ||
it("type-indexed-access-object-2", assertSchema("type-indexed-access-object-2", "MyType")); | ||
it("type-indexed-access-keyof", assertSchema("type-indexed-access-keyof", "MyType")); | ||
it("type-keyof-tuple", assertSchema("type-keyof-tuple", "MyType")); | ||
@@ -97,0 +99,0 @@ it("type-keyof-object", assertSchema("type-keyof-object", "MyType")); |
{ | ||
"name": "ts-json-schema-generator", | ||
"version": "0.47.0", | ||
"version": "0.48.0", | ||
"description": "Generate JSON schema from your Typescript sources", | ||
@@ -59,3 +59,3 @@ "main": "dist/index.js", | ||
"ts-node": "^8.3.0", | ||
"tslint": "~5.17.0" | ||
"tslint": "~5.18.0" | ||
}, | ||
@@ -62,0 +62,0 @@ "scripts": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
705015
370
4508