sindri/source/outputs/jsonschema.ts
2023-05-11 12:59:02 +02:00

83 lines
1.8 KiB
TypeScript

const output_jsonschema : type_output = {
"render": function (input_data) {
return lib_plankton.json.encode(
Object.fromEntries(
input_data.domains.map(
domain => ([
domain.name,
{
"type": ["array"],
"items": {
"type": ["object"],
"additionalProperties": false,
"properties": Object.fromEntries(
[]
.concat(
(domain.key_field === null)
? []
: [
[
domain.key_field.name,
{
"type": ["integer"],
"description": (domain.key_field.description ?? undefined),
}
]
]
)
.concat(
domain.data_fields
.map(
data_field => ([
data_field.name,
{
"type": (
[]
.concat(
data_field.nullable
? ["null"]
: []
)
.concat(
[
{
"boolean": "boolean",
"integer": "integer",
"float": "number",
"string_short": "string",
"string_medium": "string",
"string_long": "string",
}[data_field.type]
]
)
),
"description": (data_field.description ?? undefined),
}
])
)
)
),
"required": (
[]
.concat(
(domain.key_field === null)
? []
: [domain.key_field.name]
)
.concat(
domain.data_fields
.map(
data_field => data_field.name
)
)
)
},
}
])
)
),
true
);
},
};