protected constructor(version: OCPPVersion, ocppResponseService: OCPPResponseService) {
this.version = version;
- this.ajv = new Ajv();
+ this.ajv = new Ajv({
+ keywords: ['javaType'],
+ multipleOfPrecision: 2,
+ });
ajvFormats(this.ajv);
this.ocppResponseService = ocppResponseService;
this.requestHandler.bind(this);
protected validateRequestPayload<T extends JsonType>(
chargingStation: ChargingStation,
- commandName: RequestCommand,
- schema: JSONSchemaType<T>,
+ 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: Request PDU is invalid: %j`,
+ `${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().
commandName,
messagePayload as JsonType,
]);
+ this.validateRequestPayload(chargingStation, commandName, messagePayload as JsonType);
messageToSend = JSON.stringify([
messageType,
messageId,
// Response
case MessageType.CALL_RESULT_MESSAGE:
// Build response
+ // FIXME: Validate response payload
messageToSend = JSON.stringify([messageType, messageId, messagePayload] as Response);
break;
// Error Message
commandParams?: JsonType,
params?: RequestParams
): Promise<ResType>;
+
+ protected abstract getRequestPayloadValidationSchema(
+ chargingStation: ChargingStation,
+ commandName: RequestCommand | IncomingRequestCommand
+ ): JSONSchemaType<JsonObject> | false;
}