aboutsummaryrefslogtreecommitdiff
path: root/types/ext/json-schema.d.ts
blob: 2d55eee54a397671c5b573abce0f7932db70c069 (plain)
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
/*
 * Copyright (C) 2023-2024  Yomitan Authors
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */

export type ValueObject = {[key: string]: Value};

export type Value = string | number | boolean | null | Value[] | ValueObject;

export type ValueObjectOrArray = ValueObject | Value[];

export type Type = 'string' | 'number' | 'integer' | 'object' | 'array' | 'boolean' | 'null';

export type SchemaObject = {
    type?: Type | Type[];
    required?: string[];

    default?: Value;
    enum?: Value[];
    const?: Value;
    minimum?: number;
    maximum?: number;
    exclusiveMinimum?: number;
    exclusiveMaximum?: number;
    multipleOf?: number;
    minLength?: number;
    maxLength?: number;
    pattern?: string;
    patternFlags?: string;
    minItems?: number;
    maxItems?: number;
    minProperties?: number;
    maxProperties?: number;
    definitions?: {[key: string]: Schema};

    $ref?: string;

    properties?: {[key: string]: Schema};
    additionalProperties?: Schema;
    not?: Schema;
    oneOf?: Schema[];
    allOf?: Schema[];
    anyOf?: Schema[];
    contains?: Schema;
    prefixItems?: Schema[];
    items?: Schema | Schema[]; // Legacy schema format for the array
    additionalItems?: Schema;
    if?: Schema;
    then?: Schema;
    else?: Schema;
};

export type Schema = SchemaObject | true | false;

export type SchemaStackItem = {
    schema: Schema | Schema[];
    path: string | number | null;
};

export type ValueStackItem = {
    value: unknown;
    path: string | number | null;
};