/
json-schema.ts
76 lines (68 loc) · 2.09 KB
/
json-schema.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
export enum JsonSchemaVersion {
/**
* In API Gateway models are defined using the JSON schema draft 4.
* @see https://tools.ietf.org/html/draft-zyp-json-schema-04
*/
DRAFT4 = 'http://json-schema.org/draft-04/schema#',
DRAFT7 = 'http://json-schema.org/draft-07/schema#'
}
export enum JsonSchemaType {
NULL = 'null',
BOOLEAN = 'boolean',
OBJECT = 'object',
ARRAY = 'array',
NUMBER = 'number',
INTEGER = 'integer',
STRING = 'string'
}
/**
* Represents a JSON schema definition of the structure of a
* REST API model. Copied from npm module jsonschema.
*
* @see http://json-schema.org/
* @see https://github.com/tdegrunt/jsonschema
*/
export interface JsonSchema {
// Special keywords
readonly schema?: JsonSchemaVersion;
readonly id?: string;
readonly ref?: string;
// Common properties
readonly type?: JsonSchemaType | JsonSchemaType[];
readonly title?: string;
readonly description?: string;
readonly 'enum'?: any[];
readonly format?: string;
readonly definitions?: { [name: string]: JsonSchema };
// Number or Integer
readonly multipleOf?: number;
readonly maximum?: number;
readonly exclusiveMaximum?: boolean;
readonly minimum?: number;
readonly exclusiveMinimum?: boolean;
// String
readonly maxLength?: number;
readonly minLength?: number;
readonly pattern?: string;
// Array
readonly items?: JsonSchema | JsonSchema[];
readonly additionalItems?: JsonSchema[];
readonly maxItems?: number;
readonly minItems?: number;
readonly uniqueItems?: boolean;
readonly contains?: JsonSchema | JsonSchema[];
// Object
readonly maxProperties?: number;
readonly minProperties?: number;
readonly required?: string[];
readonly properties?: { [name: string]: JsonSchema };
readonly additionalProperties?: JsonSchema | boolean;
readonly patternProperties?: { [name: string]: JsonSchema };
readonly dependencies?: { [name: string]: JsonSchema | string[] };
readonly propertyNames?: JsonSchema;
// Conditional
readonly allOf?: JsonSchema[];
readonly anyOf?: JsonSchema[];
readonly oneOf?: JsonSchema[];
readonly not?: JsonSchema;
}