| 1 |
/* |
| 2 |
Copyright 2016 The Kubernetes Authors. |
| 3 |
|
| 4 |
Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 |
you may not use this file except in compliance with the License. |
| 6 |
You may obtain a copy of the License at |
| 7 |
|
| 8 |
http://www.apache.org/licenses/LICENSE-2.0 |
| 9 |
|
| 10 |
Unless required by applicable law or agreed to in writing, software |
| 11 |
distributed under the License is distributed on an "AS IS" BASIS, |
| 12 |
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 |
See the License for the specific language governing permissions and |
| 14 |
limitations under the License. |
| 15 |
*/ |
| 16 |
|
| 17 |
package builder |
| 18 |
|
| 19 |
import ( |
| 20 |
"sort" |
| 21 |
|
| 22 |
"k8s.io/kube-openapi/pkg/common" |
| 23 |
"k8s.io/kube-openapi/pkg/validation/spec" |
| 24 |
) |
| 25 |
|
| 26 |
type parameters []spec.Parameter |
| 27 |
|
| 28 |
func (s parameters) Len() int { return len(s) } |
| 29 |
func (s parameters) Swap(i, j int) { s[i], s[j] = s[j], s[i] } |
| 30 |
|
| 31 |
// byNameIn used in sorting parameters by Name and In fields. |
| 32 |
type byNameIn struct { |
| 33 |
parameters |
| 34 |
} |
| 35 |
|
| 36 |
func (s byNameIn) Less(i, j int) bool { |
| 37 |
return s.parameters[i].Name < s.parameters[j].Name || (s.parameters[i].Name == s.parameters[j].Name && s.parameters[i].In < s.parameters[j].In) |
| 38 |
} |
| 39 |
|
| 40 |
// SortParameters sorts parameters by Name and In fields. |
| 41 |
func sortParameters(p []spec.Parameter) { |
| 42 |
sort.Sort(byNameIn{p}) |
| 43 |
} |
| 44 |
|
| 45 |
func groupRoutesByPath(routes []common.Route) map[string][]common.Route { |
| 46 |
pathToRoutes := make(map[string][]common.Route) |
| 47 |
for _, r := range routes { |
| 48 |
pathToRoutes[r.Path()] = append(pathToRoutes[r.Path()], r) |
| 49 |
} |
| 50 |
return pathToRoutes |
| 51 |
} |
| 52 |
|
| 53 |
func mapKeyFromParam(param common.Parameter) interface{} { |
| 54 |
return struct { |
| 55 |
Name string |
| 56 |
Kind common.ParameterKind |
| 57 |
}{ |
| 58 |
Name: param.Name(), |
| 59 |
Kind: param.Kind(), |
| 60 |
} |
| 61 |
} |