1 import {SchemaObject} from "../types"
3 type MetaSchema = (root: boolean) => SchemaObject
5 const shared: MetaSchema = (root) => {
6 const sch: SchemaObject = {
7 nullable: {type: "boolean"},
10 union: {elements: {ref: "schema"}},
12 additionalProperties: true,
15 if (root) sch.definitions = {values: {ref: "schema"}}
19 const emptyForm: MetaSchema = (root) => ({
20 optionalProperties: shared(root),
23 const refForm: MetaSchema = (root) => ({
25 ref: {type: "string"},
27 optionalProperties: shared(root),
30 const typeForm: MetaSchema = (root) => ({
48 optionalProperties: shared(root),
51 const enumForm: MetaSchema = (root) => ({
53 enum: {elements: {type: "string"}},
55 optionalProperties: shared(root),
58 const elementsForm: MetaSchema = (root) => ({
60 elements: {ref: "schema"},
62 optionalProperties: shared(root),
65 const propertiesForm: MetaSchema = (root) => ({
67 properties: {values: {ref: "schema"}},
70 optionalProperties: {values: {ref: "schema"}},
71 additionalProperties: {type: "boolean"},
76 const optionalPropertiesForm: MetaSchema = (root) => ({
78 optionalProperties: {values: {ref: "schema"}},
81 additionalProperties: {type: "boolean"},
86 const discriminatorForm: MetaSchema = (root) => ({
88 discriminator: {type: "string"},
92 union: [propertiesForm(false), optionalPropertiesForm(false)],
97 optionalProperties: shared(root),
100 const valuesForm: MetaSchema = (root) => ({
102 values: {ref: "schema"},
104 optionalProperties: shared(root),
107 const schema: MetaSchema = (root) => ({
116 optionalPropertiesForm,
119 ].map((s) => s(root)),
123 const jtdMetaSchema: SchemaObject = {
125 schema: schema(false),
130 export default jtdMetaSchema