Skip to content

Commit

Permalink
Merge pull request #15 from grid-x/fix/allow_change_configuration_wit…
Browse files Browse the repository at this point in the history
…h_empty_value

Fix value field validation of ChangeConfigurationRequest
  • Loading branch information
Marco Trettner authored Dec 6, 2022
2 parents 938db1f + 8687395 commit 7cf6811
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
5 changes: 3 additions & 2 deletions ocpp1.6/core/change_configuration.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package core

import (
"reflect"

"github.com/lorenzodonini/ocpp-go/ocpp1.6/types"
"gopkg.in/go-playground/validator.v9"
"reflect"
)

// -------------------- Change Configuration (CS -> CP) --------------------
Expand Down Expand Up @@ -33,7 +34,7 @@ func isValidConfigurationStatus(fl validator.FieldLevel) bool {
// The field definition of the ChangeConfiguration request payload sent by the Central System to the Charge Point.
type ChangeConfigurationRequest struct {
Key string `json:"key" validate:"required,max=50"`
Value string `json:"value" validate:"required,max=500"`
Value string `json:"value" validate:"omitempty,max=500"`
}

// This field definition of the ChangeConfiguration confirmation payload, sent by the Charge Point to the Central System in response to a ChangeConfigurationRequest.
Expand Down
3 changes: 2 additions & 1 deletion ocpp1.6_test/change_configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package ocpp16_test

import (
"fmt"

"github.com/lorenzodonini/ocpp-go/ocpp1.6/core"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
Expand All @@ -13,7 +14,7 @@ func (suite *OcppV16TestSuite) TestChangeConfigurationRequestValidation() {
t := suite.T()
var requestTable = []GenericTestEntry{
{core.ChangeConfigurationRequest{Key: "someKey", Value: "someValue"}, true},
{core.ChangeConfigurationRequest{Key: "someKey"}, false},
{core.ChangeConfigurationRequest{Key: "someKey", Value: ""}, true},
{core.ChangeConfigurationRequest{Value: "someValue"}, false},
{core.ChangeConfigurationRequest{}, false},
{core.ChangeConfigurationRequest{Key: ">50................................................", Value: "someValue"}, false},
Expand Down

0 comments on commit 7cf6811

Please sign in to comment.