mirror of
https://github.com/googleapis/genai-toolbox.git
synced 2026-02-19 03:14:29 -05:00
Compare commits
2 Commits
test-link-
...
fix-param-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
17b875da3f | ||
|
|
fd22009322 |
@@ -144,7 +144,7 @@ func ParseParams(ps Parameters, data map[string]any, claimsMap map[string]map[st
|
||||
// parse non auth-required parameter
|
||||
var ok bool
|
||||
v, ok = data[name]
|
||||
if !ok {
|
||||
if !ok || v == nil {
|
||||
v = p.GetDefault()
|
||||
// if the parameter is required and no value given, throw an error
|
||||
if CheckParamRequired(p.GetRequired(), v) {
|
||||
|
||||
@@ -2347,3 +2347,23 @@ func TestCheckParamRequired(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseParams_ExplicitNullForRequiredParam(t *testing.T) {
|
||||
// Define a required string parameter
|
||||
params := parameters.Parameters{
|
||||
parameters.NewStringParameter("required_param", "this is required"),
|
||||
}
|
||||
|
||||
// Input map with explicit nil
|
||||
input := map[string]any{
|
||||
"required_param": nil,
|
||||
}
|
||||
|
||||
// Call ParseParams
|
||||
_, err := parameters.ParseParams(params, input, nil)
|
||||
|
||||
// Expect an error because the parameter is required
|
||||
if err == nil {
|
||||
t.Errorf("ParseParams allowed explicit nil for required parameter, expected error")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user