+ protected validateRequestPayload<T extends JsonType>(
+ chargingStation: ChargingStation,
+ commandName: RequestCommand | IncomingRequestCommand,
+ payload: T
+ ): boolean {
+ if (chargingStation.getPayloadSchemaValidation() === false) {
+ return true;
+ }
+ const schema = this.getRequestPayloadValidationSchema(chargingStation, commandName);
+ if (schema === false) {
+ return true;
+ }
+ const validate = this.ajv.compile(schema);
+ OCPPServiceUtils.convertDateToISOString<T>(payload);
+ if (validate(payload)) {
+ return true;
+ }
+ logger.error(
+ `${chargingStation.logPrefix()} ${moduleName}.validateRequestPayload: Command '${commandName}' request PDU is invalid: %j`,
+ validate.errors
+ );
+ // OCPPError usage here is debatable: it's an error in the OCPP stack but not targeted to sendError().
+ throw new OCPPError(
+ OCPPServiceUtils.ajvErrorsToErrorType(validate.errors),
+ 'Request PDU is invalid',
+ commandName,
+ JSON.stringify(validate.errors, null, 2)
+ );
+ }
+