From 5cbf18836b2d43cb7fcb9d15ae777af89432facf Mon Sep 17 00:00:00 2001 From: RussellLuo Date: Tue, 11 May 2021 10:52:45 +0800 Subject: [PATCH] Let users handle the cases where required fields are missing --- pkg/codec/httpcodec/param.go | 8 +------- pkg/codec/httpcodec/param_test.go | 8 -------- 2 files changed, 1 insertion(+), 15 deletions(-) diff --git a/pkg/codec/httpcodec/param.go b/pkg/codec/httpcodec/param.go index 591fd66..13004e2 100644 --- a/pkg/codec/httpcodec/param.go +++ b/pkg/codec/httpcodec/param.go @@ -408,14 +408,8 @@ func (p StructParams) Decode(in map[string][]string, out interface{}) error { } values := in[kokField.Name] - if len(values) == 0 { - if !kokField.Required { - continue - } - return ErrMissingRequired - } - fieldValuePtr := reflect.New(fieldValue.Type()) + codec := p.fieldCodec(field.Name) if err := codec.Decode(values, fieldValuePtr.Interface()); err != nil { return err diff --git a/pkg/codec/httpcodec/param_test.go b/pkg/codec/httpcodec/param_test.go index 60b7f17..973c10b 100644 --- a/pkg/codec/httpcodec/param_test.go +++ b/pkg/codec/httpcodec/param_test.go @@ -946,14 +946,6 @@ func TestStructParams_Decode(t *testing.T) { outPtr: ptrToValue, wantOut: value{Required: "wow"}, }, - { - name: "missing required field", - in: map[string][]string{ - "query.required": nil, - }, - outPtr: ptrToValue, - wantErr: ErrMissingRequired, - }, { name: "struct pointer", in: testIn,