UNPKG

3.91 kBTypeScriptView Raw
1import * as ts from "typescript";
2export { Program, CompilerOptions, Symbol } from "typescript";
3export declare function getDefaultArgs(): Args;
4export declare type ValidationKeywords = {
5 [prop: string]: boolean;
6};
7export declare type Args = {
8 ref: boolean;
9 aliasRef: boolean;
10 topRef: boolean;
11 titles: boolean;
12 defaultProps: boolean;
13 noExtraProps: boolean;
14 propOrder: boolean;
15 typeOfKeyword: boolean;
16 required: boolean;
17 strictNullChecks: boolean;
18 ignoreErrors: boolean;
19 out: string;
20 validationKeywords: string[];
21 include: string[];
22 excludePrivate: boolean;
23 uniqueNames: boolean;
24};
25export declare type PartialArgs = Partial<Args>;
26export declare type PrimitiveType = number | boolean | string | null;
27export declare type Definition = {
28 $ref?: string;
29 $schema?: string;
30 description?: string;
31 allOf?: Definition[];
32 oneOf?: Definition[];
33 anyOf?: Definition[];
34 title?: string;
35 type?: string | string[];
36 definitions?: {
37 [key: string]: any;
38 };
39 format?: string;
40 items?: Definition | Definition[];
41 minItems?: number;
42 additionalItems?: {
43 anyOf: Definition[];
44 };
45 enum?: PrimitiveType[] | Definition[];
46 default?: PrimitiveType | Object;
47 additionalProperties?: Definition | boolean;
48 required?: string[];
49 propertyOrder?: string[];
50 properties?: {
51 [key: string]: any;
52 };
53 defaultProperties?: string[];
54 typeof?: "function";
55};
56export declare type SymbolRef = {
57 name: string;
58 typeName: string;
59 fullyQualifiedName: string;
60 symbol: ts.Symbol;
61};
62export declare class JsonSchemaGenerator {
63 private args;
64 private tc;
65 private symbols;
66 private allSymbols;
67 private userSymbols;
68 private inheritingTypes;
69 private reffedDefinitions;
70 private userValidationKeywords;
71 private typeNamesById;
72 private typeNamesUsed;
73 constructor(symbols: SymbolRef[], allSymbols: {
74 [name: string]: ts.Type;
75 }, userSymbols: {
76 [name: string]: ts.Symbol;
77 }, inheritingTypes: {
78 [baseName: string]: string[];
79 }, tc: ts.TypeChecker, args?: Args);
80 readonly ReffedDefinitions: {
81 [key: string]: Definition;
82 };
83 private parseCommentsIntoDefinition(symbol, definition, otherAnnotations);
84 private getDefinitionForRootType(propertyType, reffedType, definition);
85 private getReferencedTypeSymbol(prop);
86 private getDefinitionForProperty(prop, node);
87 private getEnumDefinition(clazzType, definition);
88 private getUnionDefinition(unionType, prop, unionModifier, definition);
89 private getIntersectionDefinition(intersectionType, definition);
90 private getClassDefinition(clazzType, definition);
91 private getTypeName(typ);
92 private getTypeDefinition(typ, asRef?, unionModifier?, prop?, reffedType?, pairedSymbol?);
93 setSchemaOverride(symbolName: string, schema: Definition): void;
94 getSchemaForSymbol(symbolName: string, includeReffedDefinitions?: boolean): Definition;
95 getSchemaForSymbols(symbolNames: string[], includeReffedDefinitions?: boolean): Definition;
96 getSymbols(name?: string): SymbolRef[];
97 getUserSymbols(): string[];
98 getMainFileSymbols(program: ts.Program, onlyIncludeFiles?: string[]): string[];
99}
100export declare function getProgramFromFiles(files: string[], jsonCompilerOptions?: any, basePath?: string): ts.Program;
101export declare function buildGenerator(program: ts.Program, args?: PartialArgs, onlyIncludeFiles?: string[]): JsonSchemaGenerator | null;
102export declare function generateSchema(program: ts.Program, fullTypeName: string, args?: PartialArgs, onlyIncludeFiles?: string[]): Definition | null;
103export declare function programFromConfig(configFileName: string, onlyIncludeFiles?: string[]): ts.Program;
104export declare function exec(filePattern: string, fullTypeName: string, args?: Args): void;