1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const shared = (root) => {
|
4 | const sch = {
|
5 | nullable: { type: "boolean" },
|
6 | metadata: {
|
7 | optionalProperties: {
|
8 | union: { elements: { ref: "schema" } },
|
9 | },
|
10 | additionalProperties: true,
|
11 | },
|
12 | };
|
13 | if (root)
|
14 | sch.definitions = { values: { ref: "schema" } };
|
15 | return sch;
|
16 | };
|
17 | const emptyForm = (root) => ({
|
18 | optionalProperties: shared(root),
|
19 | });
|
20 | const refForm = (root) => ({
|
21 | properties: {
|
22 | ref: { type: "string" },
|
23 | },
|
24 | optionalProperties: shared(root),
|
25 | });
|
26 | const typeForm = (root) => ({
|
27 | properties: {
|
28 | type: {
|
29 | enum: [
|
30 | "boolean",
|
31 | "timestamp",
|
32 | "string",
|
33 | "float32",
|
34 | "float64",
|
35 | "int8",
|
36 | "uint8",
|
37 | "int16",
|
38 | "uint16",
|
39 | "int32",
|
40 | "uint32",
|
41 | ],
|
42 | },
|
43 | },
|
44 | optionalProperties: shared(root),
|
45 | });
|
46 | const enumForm = (root) => ({
|
47 | properties: {
|
48 | enum: { elements: { type: "string" } },
|
49 | },
|
50 | optionalProperties: shared(root),
|
51 | });
|
52 | const elementsForm = (root) => ({
|
53 | properties: {
|
54 | elements: { ref: "schema" },
|
55 | },
|
56 | optionalProperties: shared(root),
|
57 | });
|
58 | const propertiesForm = (root) => ({
|
59 | properties: {
|
60 | properties: { values: { ref: "schema" } },
|
61 | },
|
62 | optionalProperties: {
|
63 | optionalProperties: { values: { ref: "schema" } },
|
64 | additionalProperties: { type: "boolean" },
|
65 | ...shared(root),
|
66 | },
|
67 | });
|
68 | const optionalPropertiesForm = (root) => ({
|
69 | properties: {
|
70 | optionalProperties: { values: { ref: "schema" } },
|
71 | },
|
72 | optionalProperties: {
|
73 | additionalProperties: { type: "boolean" },
|
74 | ...shared(root),
|
75 | },
|
76 | });
|
77 | const discriminatorForm = (root) => ({
|
78 | properties: {
|
79 | discriminator: { type: "string" },
|
80 | mapping: {
|
81 | values: {
|
82 | metadata: {
|
83 | union: [propertiesForm(false), optionalPropertiesForm(false)],
|
84 | },
|
85 | },
|
86 | },
|
87 | },
|
88 | optionalProperties: shared(root),
|
89 | });
|
90 | const valuesForm = (root) => ({
|
91 | properties: {
|
92 | values: { ref: "schema" },
|
93 | },
|
94 | optionalProperties: shared(root),
|
95 | });
|
96 | const schema = (root) => ({
|
97 | metadata: {
|
98 | union: [
|
99 | emptyForm,
|
100 | refForm,
|
101 | typeForm,
|
102 | enumForm,
|
103 | elementsForm,
|
104 | propertiesForm,
|
105 | optionalPropertiesForm,
|
106 | discriminatorForm,
|
107 | valuesForm,
|
108 | ].map((s) => s(root)),
|
109 | },
|
110 | });
|
111 | const jtdMetaSchema = {
|
112 | definitions: {
|
113 | schema: schema(false),
|
114 | },
|
115 | ...schema(true),
|
116 | };
|
117 | exports.default = jtdMetaSchema;
|
118 |
|
\ | No newline at end of file |