UNPKG

3.83 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 rejectDateType: boolean;
25 id: string;
26};
27export declare type PartialArgs = Partial<Args>;
28export declare type PrimitiveType = number | boolean | string | null;
29export declare type Definition = {
30 $ref?: string;
31 $schema?: string;
32 $id?: string;
33 description?: string;
34 examples?: any[];
35 allOf?: Definition[];
36 oneOf?: Definition[];
37 anyOf?: Definition[];
38 title?: string;
39 type?: string | string[];
40 definitions?: {
41 [key: string]: any;
42 };
43 format?: string;
44 items?: Definition | Definition[];
45 minItems?: number;
46 additionalItems?: {
47 anyOf: Definition[];
48 } | Definition;
49 enum?: PrimitiveType[] | Definition[];
50 default?: PrimitiveType | Object;
51 additionalProperties?: Definition | boolean;
52 required?: string[];
53 propertyOrder?: string[];
54 properties?: {
55 [key: string]: any;
56 };
57 defaultProperties?: string[];
58 patternProperties?: {
59 [pattern: string]: Definition;
60 };
61 typeof?: "function";
62};
63export declare type SymbolRef = {
64 name: string;
65 typeName: string;
66 fullyQualifiedName: string;
67 symbol: ts.Symbol;
68};
69export declare class JsonSchemaGenerator {
70 private args;
71 private tc;
72 private symbols;
73 private allSymbols;
74 private userSymbols;
75 private inheritingTypes;
76 private reffedDefinitions;
77 private userValidationKeywords;
78 private typeNamesById;
79 private typeIdsByName;
80 constructor(symbols: SymbolRef[], allSymbols: {
81 [name: string]: ts.Type;
82 }, userSymbols: {
83 [name: string]: ts.Symbol;
84 }, inheritingTypes: {
85 [baseName: string]: string[];
86 }, tc: ts.TypeChecker, args?: Args);
87 readonly ReffedDefinitions: {
88 [key: string]: Definition;
89 };
90 private parseCommentsIntoDefinition;
91 private getDefinitionForRootType;
92 private getReferencedTypeSymbol;
93 private getDefinitionForProperty;
94 private getEnumDefinition;
95 private getUnionDefinition;
96 private getIntersectionDefinition;
97 private getClassDefinition;
98 private getTypeName;
99 private makeTypeNameUnique;
100 private getTypeDefinition;
101 setSchemaOverride(symbolName: string, schema: Definition): void;
102 getSchemaForSymbol(symbolName: string, includeReffedDefinitions?: boolean): Definition;
103 getSchemaForSymbols(symbolNames: string[], includeReffedDefinitions?: boolean): Definition;
104 getSymbols(name?: string): SymbolRef[];
105 getUserSymbols(): string[];
106 getMainFileSymbols(program: ts.Program, onlyIncludeFiles?: string[]): string[];
107}
108export declare function getProgramFromFiles(files: string[], jsonCompilerOptions?: any, basePath?: string): ts.Program;
109export declare function buildGenerator(program: ts.Program, args?: PartialArgs, onlyIncludeFiles?: string[]): JsonSchemaGenerator | null;
110export declare function generateSchema(program: ts.Program, fullTypeName: string, args?: PartialArgs, onlyIncludeFiles?: string[]): Definition | null;
111export declare function programFromConfig(configFileName: string, onlyIncludeFiles?: string[]): ts.Program;
112export declare function exec(filePattern: string, fullTypeName: string, args?: Args): void;