Skip to content

Commit

Permalink
fix golangci-lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephane Guy committed Oct 3, 2024
1 parent cd3a5d5 commit d332422
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 5 additions & 5 deletions huma.go
Original file line number Diff line number Diff line change
Expand Up @@ -1294,19 +1294,19 @@ func Register[I, O any](api API, op Operation, handler func(context.Context, *I)
}
} else {
// Set defaults for any fields that were not in the input:
atLeastOneFieldIsOverriden := false
atLeastOneFieldIsOverridden := false
defaults.Every(v, func(item reflect.Value, def any) {
if item.IsZero() && !reflect.ValueOf(def).IsZero() {
// There is one caveat here:
// - IF the default value is not the 'zero' of the field type
// - AND the 'zero' of the field type is a valid value specified in the input
// - THEN the input required field value is overriden with a different value
// - THEN the input required field value is overridden with a different value
item.Set(reflect.Indirect(reflect.ValueOf(def)))
atLeastOneFieldIsOverriden = true
atLeastOneFieldIsOverridden = true
}
})
// Restore wrongly overriden input values if any
if atLeastOneFieldIsOverriden {
// Restore wrongly overridden input values if any
if atLeastOneFieldIsOverridden {
_ = api.Unmarshal(ctx.Header("Content-Type"), body, f.Addr().Interface())
}
}
Expand Down
2 changes: 1 addition & 1 deletion huma_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ func TestFeatures(t *testing.T) {
assert.Equal(t, 5, input.Body.Count)
assert.Equal(t, []string{"foo", "bar"}, input.Body.Tags)
assert.Equal(t, []int{1, 2, 3}, input.Body.Numbers)
assert.Equal(t, len(input.Body.Items), 2)
assert.Len(t, input.Body.Items, 2)
assert.Equal(t, 1, input.Body.Items[0].ID)
assert.True(t, input.Body.Items[0].Verified)
assert.Equal(t, 1, input.Body.Items[1].ID)
Expand Down

0 comments on commit d332422

Please sign in to comment.