Skip to content

Commit

Permalink
Let users handle the cases where required fields are missing
Browse files Browse the repository at this point in the history
  • Loading branch information
RussellLuo committed May 11, 2021
1 parent 0ac48f0 commit 5cbf188
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 15 deletions.
8 changes: 1 addition & 7 deletions pkg/codec/httpcodec/param.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 0 additions & 8 deletions pkg/codec/httpcodec/param_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 5cbf188

Please sign in to comment.