| 1 |
/* |
| 2 |
Copyright 2021 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 builder3 |
| 18 |
|
| 19 |
import ( |
| 20 |
"sort" |
| 21 |
|
| 22 |
"k8s.io/kube-openapi/pkg/common" |
| 23 |
"k8s.io/kube-openapi/pkg/spec3" |
| 24 |
) |
| 25 |
|
| 26 |
func mapKeyFromParam(param common.Parameter) interface{} { |
| 27 |
return struct { |
| 28 |
Name string |
| 29 |
Kind common.ParameterKind |
| 30 |
}{ |
| 31 |
Name: param.Name(), |
| 32 |
Kind: param.Kind(), |
| 33 |
} |
| 34 |
} |
| 35 |
|
| 36 |
func (s parameters) Len() int { return len(s) } |
| 37 |
func (s parameters) Swap(i, j int) { s[i], s[j] = s[j], s[i] } |
| 38 |
|
| 39 |
type parameters []*spec3.Parameter |
| 40 |
|
| 41 |
type byNameIn struct { |
| 42 |
parameters |
| 43 |
} |
| 44 |
|
| 45 |
func (s byNameIn) Less(i, j int) bool { |
| 46 |
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) |
| 47 |
} |
| 48 |
|
| 49 |
// SortParameters sorts parameters by Name and In fields. |
| 50 |
func sortParameters(p []*spec3.Parameter) { |
| 51 |
sort.Sort(byNameIn{p}) |
| 52 |
} |