@@ -23,16 +23,16 @@ type QueryParamParser struct {
23
23
// Parsed is a map of all query params that were parsed. This is useful
24
24
// for checking if extra query params were passed in.
25
25
Parsed map [string ]bool
26
- // RequiredParams is a map of all query params that are required. This is useful
26
+ // RequiredNotEmptyParams is a map of all query params that are required. This is useful
27
27
// for forcing a value to be provided.
28
- RequiredParams map [string ]bool
28
+ RequiredNotEmptyParams map [string ]bool
29
29
}
30
30
31
31
func NewQueryParamParser () * QueryParamParser {
32
32
return & QueryParamParser {
33
- Errors : []codersdk.ValidationError {},
34
- Parsed : map [string ]bool {},
35
- RequiredParams : map [string ]bool {},
33
+ Errors : []codersdk.ValidationError {},
34
+ Parsed : map [string ]bool {},
35
+ RequiredNotEmptyParams : map [string ]bool {},
36
36
}
37
37
}
38
38
@@ -90,9 +90,9 @@ func (p *QueryParamParser) Boolean(vals url.Values, def bool, queryParam string)
90
90
return v
91
91
}
92
92
93
- func (p * QueryParamParser ) Required (queryParam ... string ) * QueryParamParser {
93
+ func (p * QueryParamParser ) RequiredNotEmpty (queryParam ... string ) * QueryParamParser {
94
94
for _ , q := range queryParam {
95
- p .RequiredParams [q ] = true
95
+ p .RequiredNotEmptyParams [q ] = true
96
96
}
97
97
return p
98
98
}
@@ -246,10 +246,10 @@ func ParseCustomList[T any](parser *QueryParamParser, vals url.Values, def []T,
246
246
func parseQueryParam [T any ](parser * QueryParamParser , vals url.Values , parse func (v string ) (T , error ), def T , queryParam string ) (T , error ) {
247
247
parser .addParsed (queryParam )
248
248
// If the query param is required and not present, return an error.
249
- if parser .RequiredParams [queryParam ] && (! vals .Has (queryParam ) || vals .Get (queryParam ) == "" ) {
249
+ if parser .RequiredNotEmptyParams [queryParam ] && (! vals .Has (queryParam ) || vals .Get (queryParam ) == "" ) {
250
250
parser .Errors = append (parser .Errors , codersdk.ValidationError {
251
251
Field : queryParam ,
252
- Detail : fmt .Sprintf ("Query param %q is required" , queryParam ),
252
+ Detail : fmt .Sprintf ("Query param %q is required and cannot be empty " , queryParam ),
253
253
})
254
254
return def , nil
255
255
}
0 commit comments