in internal/pkg/core/router/service.go [176:209]
func (rs *RouterService) createQueryParamMiddleware(resource artifacts.Resource, next http.HandlerFunc) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
// If there are no predefined query parameters, just call the next handler
if len(resource.URITemplate.QueryParameters) == 0 {
next(w, r)
return
}
// Get query parameters from the request
queryParams := r.URL.Query()
// Check if query parameter keys match exactly with the predefined keys
// First, ensure all request query params exist in predefined params
for key := range queryParams {
if _, exists := resource.URITemplate.QueryParameters[key]; !exists {
// Query parameter not defined in the template, reject the request
http.Error(w, fmt.Sprintf("Unsupported query parameter: %s", key), http.StatusBadRequest)
return
}
}
// Now ensure all predefined query params exist in the request
for key := range resource.URITemplate.QueryParameters {
if !queryParams.Has(key) {
// Required query parameter is missing, reject the request
http.Error(w, fmt.Sprintf("Missing required query parameter: %s", key), http.StatusBadRequest)
return
}
}
// All parameters in the request are valid and all required parameters are present
next(w, r)
}
}