UNPKG

@citrineos/base

Version:

The base module for OCPP v2.0.1 including all interfaces. This module is not intended to be used directly, but rather as a dependency for other modules.

51 lines 1.52 kB
/** * Utility function for creating querystring schemas for fastify route definitions * @param name - The name of the schema * @param {QuerySchemaProperties} properties An array of objects each representing a unique property. Properties with types ending in '[]' will be treated as arrays of that type. * @returns */ export const QuerySchema = (name, properties) => { const schema = { $id: name, type: 'object', properties: {}, }; const required = []; properties.forEach((property) => { const { key, type, defaultValue, required: isRequired, pattern } = property; if (isRequired) { required.push(key); } // '[]' denotes an array if (type.endsWith('[]')) { schema['properties'][key] = { type: 'array', items: { type: type.slice(0, -2) }, // Remove '[]' to get the base type }; } else { // non-array types schema['properties'][key] = { type, default: defaultValue, pattern, }; } }); if (required.length > 0) { schema['required'] = [...required]; } return schema; }; export const MessageConfirmationSchema = QuerySchema('MessageConfirmationSchema', [ { key: 'success', type: 'boolean', required: true, }, { key: 'payload', type: 'string', }, ]); //# sourceMappingURL=querySchema.js.map