repositories
/
e-mobility-charging-stations-simulator.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Add missing OCPP 1.6 command payload OCA JSON schemas
[e-mobility-charging-stations-simulator.git]
/
src
/
charging-station
/
ocpp
/
OCPPRequestService.ts
diff --git
a/src/charging-station/ocpp/OCPPRequestService.ts
b/src/charging-station/ocpp/OCPPRequestService.ts
index c089c86a1af4092dd57e1deb281dab48c9d7769a..e4890a91d8a6a88e2c8d282fcd603c2b2c31baef 100644
(file)
--- a/
src/charging-station/ocpp/OCPPRequestService.ts
+++ b/
src/charging-station/ocpp/OCPPRequestService.ts
@@
-37,7
+37,10
@@
export default abstract class OCPPRequestService {
protected constructor(version: OCPPVersion, ocppResponseService: OCPPResponseService) {
this.version = version;
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);
ajvFormats(this.ajv);
this.ocppResponseService = ocppResponseService;
this.requestHandler.bind(this);
@@
-127,19
+130,23
@@
export default abstract class OCPPRequestService {
protected validateRequestPayload<T extends JsonType>(
chargingStation: ChargingStation,
protected validateRequestPayload<T extends JsonType>(
chargingStation: ChargingStation,
- commandName: RequestCommand,
- schema: JSONSchemaType<T>,
+ commandName: RequestCommand | IncomingRequestCommand,
payload: T
): boolean {
if (chargingStation.getPayloadSchemaValidation() === false) {
return true;
}
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);
const validate = this.ajv.compile(schema);
+ OCPPServiceUtils.convertDateToISOString<T>(payload);
if (validate(payload)) {
return true;
}
logger.error(
if (validate(payload)) {
return true;
}
logger.error(
- `${chargingStation.logPrefix()} ${moduleName}.validateRequestPayload:
R
equest PDU is invalid: %j`,
+ `${chargingStation.logPrefix()} ${moduleName}.validateRequestPayload:
Command '${commandName}' r
equest PDU is invalid: %j`,
validate.errors
);
// OCPPError usage here is debatable: it's an error in the OCPP stack but not targeted to sendError().
validate.errors
);
// OCPPError usage here is debatable: it's an error in the OCPP stack but not targeted to sendError().
@@
-327,6
+334,7
@@
export default abstract class OCPPRequestService {
commandName,
messagePayload as JsonType,
]);
commandName,
messagePayload as JsonType,
]);
+ this.validateRequestPayload(chargingStation, commandName, messagePayload as JsonType);
messageToSend = JSON.stringify([
messageType,
messageId,
messageToSend = JSON.stringify([
messageType,
messageId,
@@
-337,6
+345,7
@@
export default abstract class OCPPRequestService {
// Response
case MessageType.CALL_RESULT_MESSAGE:
// Build response
// Response
case MessageType.CALL_RESULT_MESSAGE:
// Build response
+ // FIXME: Validate response payload
messageToSend = JSON.stringify([messageType, messageId, messagePayload] as Response);
break;
// Error Message
messageToSend = JSON.stringify([messageType, messageId, messagePayload] as Response);
break;
// Error Message
@@
-384,4
+393,9
@@
export default abstract class OCPPRequestService {
commandParams?: JsonType,
params?: RequestParams
): Promise<ResType>;
commandParams?: JsonType,
params?: RequestParams
): Promise<ResType>;
+
+ protected abstract getRequestPayloadValidationSchema(
+ chargingStation: ChargingStation,
+ commandName: RequestCommand | IncomingRequestCommand
+ ): JSONSchemaType<JsonObject> | false;
}
}