X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fcharging-station%2Focpp%2FOCPPResponseService.ts;h=0e9c6164d299a927dd8adf3f58a15d7247e6ced6;hb=505390847039ec18d52b665e2bc5afff69414aab;hp=5ee6e2d09058e9199dffc8015ab28298ef434155;hpb=24d15716245469249b57e5aa790147d703d60a4e;p=e-mobility-charging-stations-simulator.git diff --git a/src/charging-station/ocpp/OCPPResponseService.ts b/src/charging-station/ocpp/OCPPResponseService.ts index 5ee6e2d0..0e9c6164 100644 --- a/src/charging-station/ocpp/OCPPResponseService.ts +++ b/src/charging-station/ocpp/OCPPResponseService.ts @@ -1,7 +1,6 @@ import _Ajv, { type ValidateFunction } from 'ajv' import _ajvFormats from 'ajv-formats' -import { OCPPServiceUtils } from './OCPPServiceUtils.js' import type { ChargingStation } from '../../charging-station/index.js' import { OCPPError } from '../../exception/index.js' import type { @@ -11,6 +10,7 @@ import type { RequestCommand } from '../../types/index.js' import { Constants, logger } from '../../utils/index.js' +import { OCPPServiceUtils } from './OCPPServiceUtils.js' type Ajv = _Ajv.default // eslint-disable-next-line @typescript-eslint/no-redeclare const Ajv = _Ajv.default @@ -22,8 +22,9 @@ export abstract class OCPPResponseService { private static instance: OCPPResponseService | null = null private readonly version: OCPPVersion protected readonly ajv: Ajv - protected abstract jsonSchemasValidateFunction: Map> - public abstract jsonSchemasIncomingRequestResponseValidateFunction: Map< + protected readonly ajvIncomingRequest: Ajv + protected abstract payloadValidateFunctions: Map> + public abstract incomingRequestResponsePayloadValidateFunctions: Map< IncomingRequestCommand, ValidateFunction > @@ -35,6 +36,11 @@ export abstract class OCPPResponseService { multipleOfPrecision: 2 }) ajvFormats(this.ajv) + this.ajvIncomingRequest = new Ajv({ + keywords: ['javaType'], + multipleOfPrecision: 2 + }) + ajvFormats(this.ajvIncomingRequest) this.responseHandler = this.responseHandler.bind(this) this.validateResponsePayload = this.validateResponsePayload.bind(this) } @@ -54,7 +60,7 @@ export abstract class OCPPResponseService { if (chargingStation.stationInfo?.ocppStrictCompliance === false) { return true } - const validate = this.jsonSchemasValidateFunction.get(commandName) + const validate = this.payloadValidateFunctions.get(commandName) if (validate?.(payload) === true) { return true }