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
72ce8773
Commit
72ce8773
authored
Aug 31, 2017
by
mbohlool
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update Godep for kube-openapi
parent
76e24f21
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
130 additions
and
60 deletions
+130
-60
Godeps.json
Godeps/Godeps.json
+6
-6
aggregator.go
vendor/k8s.io/kube-openapi/pkg/aggregator/aggregator.go
+123
-54
openapi.go
vendor/k8s.io/kube-openapi/pkg/generators/openapi.go
+1
-0
No files found.
Godeps/Godeps.json
View file @
72ce8773
...
...
@@ -3099,27 +3099,27 @@
},
{
"ImportPath"
:
"k8s.io/kube-openapi/pkg/aggregator"
,
"Rev"
:
"8
0f07ef71bb4f781233c65aa8d0369e4ecafab87
"
"Rev"
:
"8
68f2f29720b192240e18284659231b440f9cda5
"
},
{
"ImportPath"
:
"k8s.io/kube-openapi/pkg/builder"
,
"Rev"
:
"8
0f07ef71bb4f781233c65aa8d0369e4ecafab87
"
"Rev"
:
"8
68f2f29720b192240e18284659231b440f9cda5
"
},
{
"ImportPath"
:
"k8s.io/kube-openapi/pkg/common"
,
"Rev"
:
"8
0f07ef71bb4f781233c65aa8d0369e4ecafab87
"
"Rev"
:
"8
68f2f29720b192240e18284659231b440f9cda5
"
},
{
"ImportPath"
:
"k8s.io/kube-openapi/pkg/generators"
,
"Rev"
:
"8
0f07ef71bb4f781233c65aa8d0369e4ecafab87
"
"Rev"
:
"8
68f2f29720b192240e18284659231b440f9cda5
"
},
{
"ImportPath"
:
"k8s.io/kube-openapi/pkg/handler"
,
"Rev"
:
"8
0f07ef71bb4f781233c65aa8d0369e4ecafab87
"
"Rev"
:
"8
68f2f29720b192240e18284659231b440f9cda5
"
},
{
"ImportPath"
:
"k8s.io/kube-openapi/pkg/util"
,
"Rev"
:
"8
0f07ef71bb4f781233c65aa8d0369e4ecafab87
"
"Rev"
:
"8
68f2f29720b192240e18284659231b440f9cda5
"
},
{
"ImportPath"
:
"k8s.io/utils/exec"
,
...
...
vendor/k8s.io/kube-openapi/pkg/aggregator/aggregator.go
View file @
72ce8773
...
...
@@ -154,8 +154,28 @@ func (s *referenceWalker) Start() {
}
}
// FilterSpecByPaths remove unnecessary paths and unused definitions.
// usedDefinitionForSpec returns a map with all used definition in the provided spec as keys and true as values.
func
usedDefinitionForSpec
(
sp
*
spec
.
Swagger
)
map
[
string
]
bool
{
usedDefinitions
:=
map
[
string
]
bool
{}
walkOnAllReferences
(
func
(
ref
spec
.
Ref
)
spec
.
Ref
{
if
refStr
:=
ref
.
String
();
refStr
!=
""
&&
strings
.
HasPrefix
(
refStr
,
definitionPrefix
)
{
usedDefinitions
[
refStr
[
len
(
definitionPrefix
)
:
]]
=
true
}
return
ref
},
sp
)
return
usedDefinitions
}
// FilterSpecByPaths removes unnecessary paths and definitions used by those paths.
// i.e. if a Path removed by this function, all definition used by it and not used
// anywhere else will also be removed.
func
FilterSpecByPaths
(
sp
*
spec
.
Swagger
,
keepPathPrefixes
[]
string
)
{
// Walk all references to find all used definitions. This function
// want to only deal with unused definitions resulted from filtering paths.
// Thus a definition will be removed only if it has been used before but
// it is unused because of a path prune.
initialUsedDefinitions
:=
usedDefinitionForSpec
(
sp
)
// First remove unwanted paths
prefixes
:=
util
.
NewTrie
(
keepPathPrefixes
)
orgPaths
:=
sp
.
Paths
...
...
@@ -174,34 +194,24 @@ func FilterSpecByPaths(sp *spec.Swagger, keepPathPrefixes []string) {
}
// Walk all references to find all definition references.
usedDefinitions
:=
map
[
string
]
bool
{}
walkOnAllReferences
(
func
(
ref
spec
.
Ref
)
spec
.
Ref
{
if
ref
.
String
()
!=
""
{
refStr
:=
ref
.
String
()
if
strings
.
HasPrefix
(
refStr
,
definitionPrefix
)
{
usedDefinitions
[
refStr
[
len
(
definitionPrefix
)
:
]]
=
true
}
}
return
ref
},
sp
)
usedDefinitions
:=
usedDefinitionForSpec
(
sp
)
// Remove unused definitions
orgDefinitions
:=
sp
.
Definitions
sp
.
Definitions
=
spec
.
Definitions
{}
for
k
,
v
:=
range
orgDefinitions
{
if
usedDefinitions
[
k
]
{
if
usedDefinitions
[
k
]
||
!
initialUsedDefinitions
[
k
]
{
sp
.
Definitions
[
k
]
=
v
}
}
}
func
renameDefinition
(
s
*
spec
.
Swagger
,
old
,
new
string
)
{
old
_r
ef
:=
definitionPrefix
+
old
new
_r
ef
:=
definitionPrefix
+
new
old
R
ef
:=
definitionPrefix
+
old
new
R
ef
:=
definitionPrefix
+
new
walkOnAllReferences
(
func
(
ref
spec
.
Ref
)
spec
.
Ref
{
if
ref
.
String
()
==
old
_r
ef
{
return
spec
.
MustCreateRef
(
new
_r
ef
)
if
ref
.
String
()
==
old
R
ef
{
return
spec
.
MustCreateRef
(
new
R
ef
)
}
return
ref
},
s
)
...
...
@@ -209,58 +219,117 @@ func renameDefinition(s *spec.Swagger, old, new string) {
delete
(
s
.
Definitions
,
old
)
}
// Copy paths and definitions from source to dest, rename definitions if needed.
// dest will be mutated, and source will not be changed.
// MergeSpecsIgnorePathConflict is the same as MergeSpecs except it will ignore any path
// conflicts by keeping the paths of destination. It will rename definition conflicts.
func
MergeSpecsIgnorePathConflict
(
dest
,
source
*
spec
.
Swagger
)
error
{
return
mergeSpecs
(
dest
,
source
,
true
,
true
)
}
// MergeSpecsFailOnDefinitionConflict is differ from MergeSpecs as it fails if there is
// a definition conflict.
func
MergeSpecsFailOnDefinitionConflict
(
dest
,
source
*
spec
.
Swagger
)
error
{
return
mergeSpecs
(
dest
,
source
,
false
,
false
)
}
// MergeSpecs copies paths and definitions from source to dest, rename definitions if needed.
// dest will be mutated, and source will not be changed. It will fail on path conflicts.
func
MergeSpecs
(
dest
,
source
*
spec
.
Swagger
)
error
{
sourceCopy
,
err
:=
CloneSpec
(
source
)
if
err
!=
nil
{
return
err
}
for
k
,
v
:=
range
sourceCopy
.
Paths
.
Paths
{
if
_
,
found
:=
dest
.
Paths
.
Paths
[
k
];
found
{
return
fmt
.
Errorf
(
"unable to merge: duplicated path %s"
,
k
)
return
mergeSpecs
(
dest
,
source
,
true
,
false
)
}
func
mergeSpecs
(
dest
,
source
*
spec
.
Swagger
,
renameModelConflicts
,
ignorePathConflicts
bool
)
(
err
error
)
{
specCloned
:=
false
if
ignorePathConflicts
{
keepPaths
:=
[]
string
{}
hasConflictingPath
:=
false
for
k
:=
range
source
.
Paths
.
Paths
{
if
_
,
found
:=
dest
.
Paths
.
Paths
[
k
];
!
found
{
keepPaths
=
append
(
keepPaths
,
k
)
}
else
{
hasConflictingPath
=
true
}
}
if
len
(
keepPaths
)
==
0
{
// There is nothing to merge. All paths are conflicting.
return
nil
}
if
hasConflictingPath
{
source
,
err
=
CloneSpec
(
source
)
if
err
!=
nil
{
return
err
}
specCloned
=
true
FilterSpecByPaths
(
source
,
keepPaths
)
}
dest
.
Paths
.
Paths
[
k
]
=
v
}
usedNames
:=
map
[
string
]
bool
{}
for
k
:=
range
dest
.
Definitions
{
usedNames
[
k
]
=
true
}
type
Rename
struct
{
from
,
to
string
// Check for model conflicts
conflicts
:=
false
for
k
,
v
:=
range
source
.
Definitions
{
v2
,
found
:=
dest
.
Definitions
[
k
]
if
found
&&
!
reflect
.
DeepEqual
(
v
,
v2
)
{
if
!
renameModelConflicts
{
return
fmt
.
Errorf
(
"model name conflict in merging OpenAPI spec: %s"
,
k
)
}
conflicts
=
true
break
}
}
renames
:=
[]
Rename
{}
for
k
,
v
:=
range
sourceCopy
.
Definitions
{
if
usedNames
[
k
]
{
v2
,
found
:=
dest
.
Definitions
[
k
]
// Reuse model iff they are exactly the same.
if
found
&&
reflect
.
DeepEqual
(
v
,
v2
)
{
continue
if
conflicts
{
if
!
specCloned
{
source
,
err
=
CloneSpec
(
source
)
if
err
!=
nil
{
return
err
}
i
:=
2
newName
:=
fmt
.
Sprintf
(
"%s_v%d"
,
k
,
i
)
_
,
foundInSource
:=
sourceCopy
.
Definitions
[
newName
]
for
usedNames
[
newName
]
||
foundInSource
{
i
+=
1
newName
=
fmt
.
Sprintf
(
"%s_v%d"
,
k
,
i
)
_
,
foundInSource
=
sourceCopy
.
Definitions
[
newName
]
}
specCloned
=
true
usedNames
:=
map
[
string
]
bool
{}
for
k
:=
range
dest
.
Definitions
{
usedNames
[
k
]
=
true
}
type
Rename
struct
{
from
,
to
string
}
renames
:=
[]
Rename
{}
for
k
,
v
:=
range
source
.
Definitions
{
if
usedNames
[
k
]
{
v2
,
found
:=
dest
.
Definitions
[
k
]
// Reuse model iff they are exactly the same.
if
found
&&
reflect
.
DeepEqual
(
v
,
v2
)
{
continue
}
i
:=
2
newName
:=
fmt
.
Sprintf
(
"%s_v%d"
,
k
,
i
)
_
,
foundInSource
:=
source
.
Definitions
[
newName
]
for
usedNames
[
newName
]
||
foundInSource
{
i
++
newName
=
fmt
.
Sprintf
(
"%s_v%d"
,
k
,
i
)
_
,
foundInSource
=
source
.
Definitions
[
newName
]
}
renames
=
append
(
renames
,
Rename
{
from
:
k
,
to
:
newName
})
usedNames
[
newName
]
=
true
}
renames
=
append
(
renames
,
Rename
{
from
:
k
,
to
:
newName
})
usedNames
[
newName
]
=
true
}
for
_
,
r
:=
range
renames
{
renameDefinition
(
source
,
r
.
from
,
r
.
to
)
}
}
for
_
,
r
:=
range
renames
{
renameDefinition
(
sourceCopy
,
r
.
from
,
r
.
to
)
}
for
k
,
v
:=
range
sourceCopy
.
Definitions
{
for
k
,
v
:=
range
source
.
Definitions
{
if
_
,
found
:=
dest
.
Definitions
[
k
];
!
found
{
dest
.
Definitions
[
k
]
=
v
}
}
// Check for path conflicts
for
k
,
v
:=
range
source
.
Paths
.
Paths
{
if
_
,
found
:=
dest
.
Paths
.
Paths
[
k
];
found
{
return
fmt
.
Errorf
(
"unable to merge: duplicated path %s"
,
k
)
}
dest
.
Paths
.
Paths
[
k
]
=
v
}
return
nil
}
// Clone OpenAPI spec
// Clone
Spec clones
OpenAPI spec
func
CloneSpec
(
source
*
spec
.
Swagger
)
(
*
spec
.
Swagger
,
error
)
{
// TODO(mehdy): Find a faster way to clone an spec
bytes
,
err
:=
json
.
Marshal
(
source
)
...
...
vendor/k8s.io/kube-openapi/pkg/generators/openapi.go
View file @
72ce8773
...
...
@@ -328,6 +328,7 @@ func (g openAPITypeWriter) generateMembers(t *types.Type, required []string) ([]
required
=
append
(
required
,
name
)
}
if
err
=
g
.
generateProperty
(
&
m
,
t
);
err
!=
nil
{
glog
.
Errorf
(
"Error when generating: %v, %v
\n
"
,
name
,
m
)
return
required
,
err
}
}
...
...
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