Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
ef8ee84c
Commit
ef8ee84c
authored
May 31, 2017
by
mbohlool
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove unused servePath from GetOperationIDAndTags and GetDefinitionName
parent
3837d951
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
34 additions
and
40 deletions
+34
-40
common.go
staging/src/k8s.io/apimachinery/pkg/openapi/common.go
+2
-2
openapi.go
...ing/src/k8s.io/apiserver/pkg/endpoints/openapi/openapi.go
+23
-27
openapi_test.go
...rc/k8s.io/apiserver/pkg/endpoints/openapi/openapi_test.go
+2
-2
openapi.go
staging/src/k8s.io/apiserver/pkg/server/openapi/openapi.go
+6
-8
openapi_test.go
...g/src/k8s.io/apiserver/pkg/server/openapi/openapi_test.go
+1
-1
No files found.
staging/src/k8s.io/apimachinery/pkg/openapi/common.go
View file @
ef8ee84c
...
...
@@ -65,11 +65,11 @@ type Config struct {
GetDefinitions
GetOpenAPIDefinitions
// GetOperationIDAndTags returns operation id and tags for a restful route. It is an optional function to customize operation IDs.
GetOperationIDAndTags
func
(
servePath
string
,
r
*
restful
.
Route
)
(
string
,
[]
string
,
error
)
GetOperationIDAndTags
func
(
r
*
restful
.
Route
)
(
string
,
[]
string
,
error
)
// GetDefinitionName returns a friendly name for a definition base on the serving path. parameter `name` is the full name of the definition.
// It is an optional function to customize model names.
GetDefinitionName
func
(
servePath
string
,
name
string
)
(
string
,
spec
.
Extensions
)
GetDefinitionName
func
(
name
string
)
(
string
,
spec
.
Extensions
)
// PostProcessSpec runs after the spec is ready to serve. It allows a final modification to the spec before serving.
PostProcessSpec
func
(
*
spec
.
Swagger
)
(
*
spec
.
Swagger
,
error
)
...
...
staging/src/k8s.io/apiserver/pkg/endpoints/openapi/openapi.go
View file @
ef8ee84c
...
...
@@ -59,7 +59,7 @@ func ToValidOperationID(s string, capitalizeFirstLetter bool) string {
}
// GetOperationIDAndTags returns a customize operation ID and a list of tags for kubernetes API server's OpenAPI spec to prevent duplicate IDs.
func
GetOperationIDAndTags
(
servePath
string
,
r
*
restful
.
Route
)
(
string
,
[]
string
,
error
)
{
func
GetOperationIDAndTags
(
r
*
restful
.
Route
)
(
string
,
[]
string
,
error
)
{
op
:=
r
.
Operation
path
:=
r
.
Path
var
tags
[]
string
...
...
@@ -67,33 +67,29 @@ func GetOperationIDAndTags(servePath string, r *restful.Route) (string, []string
if
strings
.
HasPrefix
(
path
,
"/apis/extensions/v1beta1/namespaces/{namespace}/"
)
&&
strings
.
HasSuffix
(
op
,
"ScaleScale"
)
{
op
=
op
[
:
len
(
op
)
-
10
]
+
strings
.
Title
(
strings
.
Split
(
path
[
48
:
],
"/"
)[
0
])
+
"Scale"
}
switch
servePath
{
case
"/swagger.json"
:
prefix
,
exists
:=
verbs
.
GetPrefix
(
op
)
if
!
exists
{
return
op
,
tags
,
fmt
.
Errorf
(
"operation names should start with a verb. Cannot determine operation verb from %v"
,
op
)
}
op
=
op
[
len
(
prefix
)
:
]
parts
:=
strings
.
Split
(
strings
.
Trim
(
path
,
"/"
),
"/"
)
// Assume /api is /apis/core, remove this when we actually server /api/... on /apis/core/...
if
len
(
parts
)
>=
1
&&
parts
[
0
]
==
"api"
{
parts
=
append
([]
string
{
"apis"
,
"core"
},
parts
[
1
:
]
...
)
}
if
len
(
parts
)
>=
2
&&
parts
[
0
]
==
"apis"
{
prefix
=
prefix
+
ToValidOperationID
(
strings
.
TrimSuffix
(
parts
[
1
],
".k8s.io"
),
prefix
!=
""
)
tag
:=
ToValidOperationID
(
strings
.
TrimSuffix
(
parts
[
1
],
".k8s.io"
),
false
)
if
len
(
parts
)
>
2
{
prefix
=
prefix
+
ToValidOperationID
(
parts
[
2
],
prefix
!=
""
)
tag
=
tag
+
"_"
+
ToValidOperationID
(
parts
[
2
],
false
)
}
tags
=
append
(
tags
,
tag
)
}
else
if
len
(
parts
)
>=
1
{
tags
=
append
(
tags
,
ToValidOperationID
(
parts
[
0
],
false
))
prefix
,
exists
:=
verbs
.
GetPrefix
(
op
)
if
!
exists
{
return
op
,
tags
,
fmt
.
Errorf
(
"operation names should start with a verb. Cannot determine operation verb from %v"
,
op
)
}
op
=
op
[
len
(
prefix
)
:
]
parts
:=
strings
.
Split
(
strings
.
Trim
(
path
,
"/"
),
"/"
)
// Assume /api is /apis/core, remove this when we actually server /api/... on /apis/core/...
if
len
(
parts
)
>=
1
&&
parts
[
0
]
==
"api"
{
parts
=
append
([]
string
{
"apis"
,
"core"
},
parts
[
1
:
]
...
)
}
if
len
(
parts
)
>=
2
&&
parts
[
0
]
==
"apis"
{
trimmed
:=
strings
.
TrimSuffix
(
parts
[
1
],
".k8s.io"
)
prefix
=
prefix
+
ToValidOperationID
(
trimmed
,
prefix
!=
""
)
tag
:=
ToValidOperationID
(
trimmed
,
false
)
if
len
(
parts
)
>
2
{
prefix
=
prefix
+
ToValidOperationID
(
parts
[
2
],
prefix
!=
""
)
tag
=
tag
+
"_"
+
ToValidOperationID
(
parts
[
2
],
false
)
}
return
prefix
+
ToValidOperationID
(
op
,
prefix
!=
""
),
tags
,
nil
default
:
return
op
,
tags
,
nil
tags
=
append
(
tags
,
tag
)
}
else
if
len
(
parts
)
>=
1
{
tags
=
append
(
tags
,
ToValidOperationID
(
parts
[
0
],
false
))
}
return
prefix
+
ToValidOperationID
(
op
,
prefix
!=
""
),
tags
,
nil
}
type
groupVersionKinds
[]
v1
.
GroupVersionKind
...
...
@@ -161,7 +157,7 @@ func NewDefinitionNamer(s *runtime.Scheme) DefinitionNamer {
}
// GetDefinitionName returns the name and tags for a given definition
func
(
d
*
DefinitionNamer
)
GetDefinitionName
(
servePath
string
,
name
string
)
(
string
,
spec
.
Extensions
)
{
func
(
d
*
DefinitionNamer
)
GetDefinitionName
(
name
string
)
(
string
,
spec
.
Extensions
)
{
if
groupVersionKinds
,
ok
:=
d
.
typeGroupVersionKinds
[
name
];
ok
{
return
friendlyName
(
name
),
spec
.
Extensions
{
extensionGVK
:
[]
v1
.
GroupVersionKind
(
groupVersionKinds
),
...
...
staging/src/k8s.io/apiserver/pkg/endpoints/openapi/openapi_test.go
View file @
ef8ee84c
...
...
@@ -71,7 +71,7 @@ func TestGetDefinitionName(t *testing.T) {
s
:=
runtime
.
NewScheme
()
s
.
AddKnownTypeWithName
(
testType
.
GroupVersionKind
(),
&
testType
)
namer
:=
NewDefinitionNamer
(
s
)
n
,
e
:=
namer
.
GetDefinitionName
(
""
,
typePkgName
)
n
,
e
:=
namer
.
GetDefinitionName
(
typePkgName
)
assertEqual
(
t
,
typeFriendlyName
,
n
)
assertEqual
(
t
,
e
[
"x-kubernetes-group-version-kind"
],
[]
v1
.
GroupVersionKind
{
{
...
...
@@ -80,7 +80,7 @@ func TestGetDefinitionName(t *testing.T) {
Kind
:
"TestType"
,
},
})
n
,
e2
:=
namer
.
GetDefinitionName
(
"
"
,
"
test.com/another.Type"
)
n
,
e2
:=
namer
.
GetDefinitionName
(
"test.com/another.Type"
)
assertEqual
(
t
,
"com.test.another.Type"
,
n
)
assertEqual
(
t
,
e2
,
spec
.
Extensions
(
nil
))
}
staging/src/k8s.io/apiserver/pkg/server/openapi/openapi.go
View file @
ef8ee84c
...
...
@@ -60,7 +60,6 @@ type openAPI struct {
swaggerPbGz
[]
byte
lastModified
time
.
Time
protocolList
[]
string
servePath
string
definitions
map
[
string
]
openapi
.
OpenAPIDefinition
}
...
...
@@ -79,7 +78,6 @@ func RegisterOpenAPIService(servePath string, webServices []*restful.WebService,
o
:=
openAPI
{
config
:
config
,
servePath
:
servePath
,
swagger
:
&
spec
.
Swagger
{
SwaggerProps
:
spec
.
SwaggerProps
{
Swagger
:
OpenAPIVersion
,
...
...
@@ -132,17 +130,17 @@ func RegisterOpenAPIService(servePath string, webServices []*restful.WebService,
func
(
o
*
openAPI
)
init
(
webServices
[]
*
restful
.
WebService
)
error
{
if
o
.
config
.
GetOperationIDAndTags
==
nil
{
o
.
config
.
GetOperationIDAndTags
=
func
(
_
string
,
r
*
restful
.
Route
)
(
string
,
[]
string
,
error
)
{
o
.
config
.
GetOperationIDAndTags
=
func
(
r
*
restful
.
Route
)
(
string
,
[]
string
,
error
)
{
return
r
.
Operation
,
nil
,
nil
}
}
if
o
.
config
.
GetDefinitionName
==
nil
{
o
.
config
.
GetDefinitionName
=
func
(
_
,
name
string
)
(
string
,
spec
.
Extensions
)
{
o
.
config
.
GetDefinitionName
=
func
(
name
string
)
(
string
,
spec
.
Extensions
)
{
return
name
[
strings
.
LastIndex
(
name
,
"/"
)
+
1
:
],
nil
}
}
o
.
definitions
=
o
.
config
.
GetDefinitions
(
func
(
name
string
)
spec
.
Ref
{
defName
,
_
:=
o
.
config
.
GetDefinitionName
(
o
.
servePath
,
name
)
defName
,
_
:=
o
.
config
.
GetDefinitionName
(
name
)
return
spec
.
MustCreateRef
(
"#/definitions/"
+
openapi
.
EscapeJsonPointer
(
defName
))
})
if
o
.
config
.
CommonResponses
==
nil
{
...
...
@@ -210,7 +208,7 @@ func getCanonicalizeTypeName(t reflect.Type) string {
}
func
(
o
*
openAPI
)
buildDefinitionRecursively
(
name
string
)
error
{
uniqueName
,
extensions
:=
o
.
config
.
GetDefinitionName
(
o
.
servePath
,
name
)
uniqueName
,
extensions
:=
o
.
config
.
GetDefinitionName
(
name
)
if
_
,
ok
:=
o
.
swagger
.
Definitions
[
uniqueName
];
ok
{
return
nil
}
...
...
@@ -252,7 +250,7 @@ func (o *openAPI) buildDefinitionForType(sample interface{}) (string, error) {
if
err
:=
o
.
buildDefinitionRecursively
(
name
);
err
!=
nil
{
return
""
,
err
}
defName
,
_
:=
o
.
config
.
GetDefinitionName
(
o
.
servePath
,
name
)
defName
,
_
:=
o
.
config
.
GetDefinitionName
(
name
)
return
"#/definitions/"
+
openapi
.
EscapeJsonPointer
(
defName
),
nil
}
...
...
@@ -356,7 +354,7 @@ func (o *openAPI) buildOperations(route restful.Route, inPathCommonParamsMap map
ret
.
Extensions
.
Add
(
k
,
v
)
}
}
if
ret
.
ID
,
ret
.
Tags
,
err
=
o
.
config
.
GetOperationIDAndTags
(
o
.
servePath
,
&
route
);
err
!=
nil
{
if
ret
.
ID
,
ret
.
Tags
,
err
=
o
.
config
.
GetOperationIDAndTags
(
&
route
);
err
!=
nil
{
return
ret
,
err
}
...
...
staging/src/k8s.io/apiserver/pkg/server/openapi/openapi_test.go
View file @
ef8ee84c
...
...
@@ -200,7 +200,7 @@ func getConfig(fullMethods bool) (*openapi.Config, *restful.Container) {
"k8s.io/apiserver/pkg/server/openapi/go_default_test.TestOutput"
:
*
TestOutput
{}
.
OpenAPIDefinition
(),
}
},
GetDefinitionName
:
func
(
_
string
,
name
string
)
(
string
,
spec
.
Extensions
)
{
GetDefinitionName
:
func
(
name
string
)
(
string
,
spec
.
Extensions
)
{
friendlyName
:=
name
[
strings
.
LastIndex
(
name
,
"/"
)
+
1
:
]
if
strings
.
HasPrefix
(
friendlyName
,
"go_default_test"
)
{
friendlyName
=
"openapi"
+
friendlyName
[
len
(
"go_default_test"
)
:
]
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment