blob: 5e9a56a6b806de7986122a8abb1b5cb6a59d9add [file] [log] [blame]
Matthias Andreas Benkard832a54e2019-01-29 09:27:38 +01001/*
2Copyright 2016 The Kubernetes Authors.
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15*/
16
17package builder
18
19import (
20 "sort"
21
22 "github.com/emicklei/go-restful"
23 "github.com/go-openapi/spec"
24)
25
26type parameters []spec.Parameter
27
28func (s parameters) Len() int { return len(s) }
29func (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.
32type byNameIn struct {
33 parameters
34}
35
36func (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.
41func sortParameters(p []spec.Parameter) {
42 sort.Sort(byNameIn{p})
43}
44
45func groupRoutesByPath(routes []restful.Route) map[string][]restful.Route {
46 pathToRoutes := make(map[string][]restful.Route)
47 for _, r := range routes {
48 pathToRoutes[r.Path] = append(pathToRoutes[r.Path], r)
49 }
50 return pathToRoutes
51}
52
53func mapKeyFromParam(param *restful.Parameter) interface{} {
54 return struct {
55 Name string
56 Kind int
57 }{
58 Name: param.Data().Name,
59 Kind: param.Data().Kind,
60 }
61}