lorenzodonini / ocpp-go

Open Charge Point Protocol implementation in Go
MIT License
262 stars 125 forks source link

OCPP 2.0 Reset Request Validator Error #217

Closed MattGrouchy closed 11 months ago

MattGrouchy commented 1 year ago

Tagged co-worker - @jonesywolf

Hello! Thanks for looking at the issue and helping out.

Issue

We are implementing OCPP 2.0 (as the charging station) and testing with the official OCA OCTT2.0 tool. When the tool sends a ResetRequest with the following format:

INFO[2023-08-17T12:03:18-04:00] provisioning.ResetRequest: 
{
    "type": "OnIdle"
} 

The validator raises an error and does not call our handler. As far as we can determine, this request is valid and the validator should pass it.

Possible solution

It looks like someone found this earlier and commented on a old merged pull request.

https://github.com/lorenzodonini/ocpp-go/pull/204#issuecomment-1602504832

It may be using the 1.6 validator

I tested the validator by making a struct and using the types.Validate.Struct() method. Here is the code that I used:

        _evseId := 42

    req := ocpp201provisioning.ResetRequest{
        Type: "OnIdle",
    }

    req2 := ocpp201provisioning.ResetRequest{
        Type: "Hard",
    }

    req3 := ocpp201provisioning.ResetRequest{
        Type:   "OnIdle",
        EvseID: &_evseId,
    }

    err = tocpp.Validate.Struct(req)
    if err != nil {
        log.Errorf("req: %v", err)
    }
    err = tocpp.Validate.Struct(req2)
    if err != nil {
        log.Errorf("req2: %v", err)
    }
    err = tocpp.Validate.Struct(req3)
    if err != nil {
        log.Errorf("req3: %v", err)
    }

And the resulting output of the file.

ERRO[2023-08-17T13:32:16-04:00] req: Key: 'ResetRequest.Type' Error:Field validation for 'Type' failed on the 'resetType' tag 
ERRO[2023-08-17T13:32:16-04:00] req3: Key: 'ResetRequest.Type' Error:Field validation for 'Type' failed on the 'resetType' tag 

Here are the ocpp imports in the top of the file. We have an implementation of both 1.6 and 2.0.1. This is from the root file that calls this method.

    "github.com/lorenzodonini/ocpp-go/ocpp1.6/core"
    tocpp16 "github.com/lorenzodonini/ocpp-go/ocpp1.6/types"
    ocpp201provisioning "github.com/lorenzodonini/ocpp-go/ocpp2.0.1/provisioning"
    "github.com/lorenzodonini/ocpp-go/ocpp2.0.1/transactions"
    tocpp "github.com/lorenzodonini/ocpp-go/ocpp2.0.1/types"

Are you able to help us debug the issue and determine why the validator is not working correctly?

Versions

github.com/go-playground/validator v9.31.0+incompatible
github.com/lorenzodonini/ocpp-go v0.16.1-0.20230730211316-139992cfbe11
lorenzodonini commented 1 year ago

Should be fixed by @Yuanzjls in the MR above (your suspicion was correct), let me know if the issue persists.

A release will follow in the next few days containing lots of bugfixes and improvements, so you don't have to target master branch.

Jonesywolf commented 1 year ago

It's fixed now, thanks for merging in @Yuanzjls PR @lorenzodonini !