UNPKG

3.69 kBTypeScriptView Raw
1import * as ts from "typescript";
2export declare function getDefaultArgs(): {
3 useRef: boolean;
4 useTypeAliasRef: boolean;
5 useRootRef: boolean;
6 useTitle: boolean;
7 useDefaultProperties: boolean;
8 disableExtraProperties: boolean;
9 usePropertyOrder: boolean;
10 generateRequired: boolean;
11 strictNullChecks: boolean;
12 out: string;
13};
14export declare type Definition = {
15 $ref?: string;
16 description?: string;
17 allOf?: Definition[];
18 oneOf?: Definition[];
19 anyOf?: Definition[];
20 title?: string;
21 type?: string | string[];
22 definitions?: {
23 [key: string]: any;
24 };
25 format?: string;
26 items?: Definition;
27 minItems?: number;
28 additionalItems?: {
29 anyOf: Definition;
30 };
31 enum?: string[] | Definition[];
32 default?: string | number | boolean | Object;
33 additionalProperties?: Definition;
34 required?: string[];
35 propertyOrder?: string[];
36 properties?: {};
37 defaultProperties?: string[];
38};
39export declare class JsonSchemaGenerator {
40 private args;
41 private static validationKeywords;
42 private allSymbols;
43 private inheritingTypes;
44 private tc;
45 private reffedDefinitions;
46 constructor(allSymbols: {
47 [name: string]: ts.Type;
48 }, inheritingTypes: {
49 [baseName: string]: string[];
50 }, tc: ts.TypeChecker, args?: {
51 useRef: boolean;
52 useTypeAliasRef: boolean;
53 useRootRef: boolean;
54 useTitle: boolean;
55 useDefaultProperties: boolean;
56 disableExtraProperties: boolean;
57 usePropertyOrder: boolean;
58 generateRequired: boolean;
59 strictNullChecks: boolean;
60 out: string;
61 });
62 readonly ReffedDefinitions: {
63 [key: string]: Definition;
64 };
65 private parseValue(value);
66 private parseCommentsIntoDefinition(symbol, definition, otherAnnotations);
67 private extractLiteralValue(typ);
68 private resolveTupleType(propertyType);
69 private getDefinitionForRootType(propertyType, tc, reffedType, definition);
70 private getReferencedTypeSymbol(prop, tc);
71 private getDefinitionForProperty(prop, tc, node);
72 private getEnumDefinition(clazzType, tc, definition);
73 private getUnionDefinition(unionType, prop, tc, unionModifier, definition);
74 private getClassDefinition(clazzType, tc, definition);
75 private simpleTypesAllowedProperties;
76 private addSimpleType(def, type);
77 private makeNullable(def);
78 private getTypeDefinition(typ, tc, asRef?, unionModifier?, prop?, reffedType?);
79 getSchemaForSymbol(symbolName: string, includeReffedDefinitions?: boolean): Definition;
80 getSchemaForSymbols(symbols: {
81 [name: string]: ts.Type;
82 }): Definition;
83}
84export declare function getProgramFromFiles(files: string[], compilerOptions?: ts.CompilerOptions): ts.Program;
85export declare function generateSchema(program: ts.Program, fullTypeName: string, args?: {
86 useRef: boolean;
87 useTypeAliasRef: boolean;
88 useRootRef: boolean;
89 useTitle: boolean;
90 useDefaultProperties: boolean;
91 disableExtraProperties: boolean;
92 usePropertyOrder: boolean;
93 generateRequired: boolean;
94 strictNullChecks: boolean;
95 out: string;
96}): Definition;
97export declare function programFromConfig(configFileName: string): ts.Program;
98export declare function exec(filePattern: string, fullTypeName: string, args?: {
99 useRef: boolean;
100 useTypeAliasRef: boolean;
101 useRootRef: boolean;
102 useTitle: boolean;
103 useDefaultProperties: boolean;
104 disableExtraProperties: boolean;
105 usePropertyOrder: boolean;
106 generateRequired: boolean;
107 strictNullChecks: boolean;
108 out: string;
109}): void;
110export declare function run(): void;