mirror of
https://github.com/legop3/MultiRoombaRover.git
synced 2026-09-15 17:12:59 -04:00
58 lines
1.4 KiB
JavaScript
58 lines
1.4 KiB
JavaScript
// Configuration Schema Helpers
|
|
// Purpose: Keeps repetitive declarations in the complete strict JSON Schema readable.
|
|
// Scope: Defines schema-building helpers only; validation and default application remain separate responsibilities.
|
|
|
|
function strictObject(properties, options = {}) {
|
|
/*
|
|
Configuration objects reject unknown keys at every level. A misspelled
|
|
operator setting must fail loudly instead of looking saved while the server
|
|
silently falls back to another value.
|
|
*/
|
|
return {
|
|
type: 'object',
|
|
additionalProperties: false,
|
|
properties,
|
|
...(options.title ? { title: options.title } : {}),
|
|
...(options.description ? { description: options.description } : {}),
|
|
...(Array.isArray(options.required) ? { required: options.required } : {}),
|
|
};
|
|
}
|
|
|
|
function string(options = {}) {
|
|
return { type: 'string', ...options };
|
|
}
|
|
|
|
function nullableString(options = {}) {
|
|
return { type: ['string', 'null'], ...options };
|
|
}
|
|
|
|
function boolean(options = {}) {
|
|
return { type: 'boolean', ...options };
|
|
}
|
|
|
|
function integer(options = {}) {
|
|
return { type: 'integer', ...options };
|
|
}
|
|
|
|
function number(options = {}) {
|
|
return { type: 'number', ...options };
|
|
}
|
|
|
|
function stringArray(options = {}) {
|
|
return {
|
|
type: 'array',
|
|
items: string(options.item || {}),
|
|
...options.array,
|
|
};
|
|
}
|
|
|
|
module.exports = {
|
|
strictObject,
|
|
string,
|
|
nullableString,
|
|
boolean,
|
|
integer,
|
|
number,
|
|
stringArray,
|
|
};
|