lorenzodonini / ocpp-go

Open Charge Point Protocol implementation in Go
MIT License
277 stars 126 forks source link

Validator instance seperate in ocpp1.6 and ocpp2.0.1 #200

Closed qosmotec closed 1 year ago

qosmotec commented 1 year ago

Hello Lorenzo,

I figured out that using 1.6 and 2.0.1 in parallel will lead to strange validation errors. I used SetChargingProfile with ocpp1.6 and types.ChargingProfilePurposeChargePointMaxProfile "ChargePointMaxProfile" as ChargingProfilePurposeType which is perfectly valid for 1.6 but leads to validation errors.

This is due to the fact that

_ = Validate.RegisterValidation("chargingProfilePurpose", isValidChargingProfilePurpose)

registers chargingProfilePurpose twice. Once for 1.6 ond once for 2.0.1. "ChargePointMaxProfile" is a valid value for 1.6 but changed to "ChargingStationMaxProfile" in ocpp 2.0.1 spec.

Since both register their validations in Validator object, only last one is considered which leads to validation for 1.6 fail with SetChargingProfile - Key: 'Call.Payload.ChargingProfile.ChargingProfilePurpose' Error:Field validation for 'ChargingProfilePurpose' failed on the 'chargingProfilePurpose' tag

Please let me know if I can help.

lorenzodonini commented 1 year ago

Nice find sir. I addressed the immediate issue in the linked PR. It is possible that more validation keys are overwritten when using both protocol versions (keep in mind the library wasn't initially designed with the idea of using both versions within the same process).

If you happen to find more conflicting keys, feel free to submit a PR or le let me know and I'll take care of it.