Bumping k8s dependencies to 1.13

This commit is contained in:
Cheng Xing
2018-11-16 14:08:25 -08:00
parent 305407125c
commit b4c0b68ec7
8002 changed files with 884099 additions and 276228 deletions

View File

@@ -61,6 +61,10 @@ func (s *referenceWalker) walkRef(ref spec.Ref) spec.Ref {
k := refStr[len(definitionPrefix):]
def := s.root.Definitions[k]
s.walkSchema(&def)
// Make sure we don't assign to nil map
if s.root.Definitions == nil {
s.root.Definitions = spec.Definitions{}
}
s.root.Definitions[k] = def
}
return s.walkRefCallback(ref)
@@ -83,13 +87,13 @@ func (s *referenceWalker) walkSchema(schema *spec.Schema) {
s.walkSchema(&v)
schema.PatternProperties[k] = v
}
for i, _ := range schema.AllOf {
for i := range schema.AllOf {
s.walkSchema(&schema.AllOf[i])
}
for i, _ := range schema.AnyOf {
for i := range schema.AnyOf {
s.walkSchema(&schema.AnyOf[i])
}
for i, _ := range schema.OneOf {
for i := range schema.OneOf {
s.walkSchema(&schema.OneOf[i])
}
if schema.Not != nil {
@@ -105,7 +109,7 @@ func (s *referenceWalker) walkSchema(schema *spec.Schema) {
if schema.Items.Schema != nil {
s.walkSchema(schema.Items.Schema)
}
for i, _ := range schema.Items.Schemas {
for i := range schema.Items.Schemas {
s.walkSchema(&schema.Items.Schemas[i])
}
}
@@ -147,6 +151,9 @@ func (s *referenceWalker) walkOperation(op *spec.Operation) {
}
func (s *referenceWalker) Start() {
if s.root.Paths == nil {
return
}
for _, pathItem := range s.root.Paths.Paths {
s.walkParams(pathItem.Parameters)
s.walkOperation(pathItem.Delete)
@@ -159,7 +166,7 @@ func (s *referenceWalker) Start() {
}
}
// usedDefinitionForSpec returns a map with all used definition in the provided spec as keys and true as values.
// usedDefinitionForSpec returns a map with all used definitions 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 {
@@ -172,7 +179,7 @@ func usedDefinitionForSpec(sp *spec.Swagger) map[string]bool {
}
// 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
// i.e. if a Path removed by this function, all definitions 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
@@ -220,6 +227,10 @@ func renameDefinition(s *spec.Swagger, old, new string) {
}
return ref
}, s)
// Make sure we don't assign to nil map
if s.Definitions == nil {
s.Definitions = spec.Definitions{}
}
s.Definitions[new] = s.Definitions[old]
delete(s.Definitions, old)
}
@@ -244,6 +255,15 @@ func MergeSpecs(dest, source *spec.Swagger) error {
func mergeSpecs(dest, source *spec.Swagger, renameModelConflicts, ignorePathConflicts bool) (err error) {
specCloned := false
// Paths may be empty, due to [ACL constraints](http://goo.gl/8us55a#securityFiltering).
if source.Paths == nil {
// When a source spec does not have any path, that means none of the definitions
// are used thus we should not do anything
return nil
}
if dest.Paths == nil {
dest.Paths = &spec.Paths{}
}
if ignorePathConflicts {
keepPaths := []string{}
hasConflictingPath := false
@@ -335,6 +355,9 @@ func mergeSpecs(dest, source *spec.Swagger, renameModelConflicts, ignorePathConf
}
for k, v := range source.Definitions {
if _, found := dest.Definitions[k]; !found {
if dest.Definitions == nil {
dest.Definitions = spec.Definitions{}
}
dest.Definitions[k] = v
}
}
@@ -343,6 +366,10 @@ func mergeSpecs(dest, source *spec.Swagger, renameModelConflicts, ignorePathConf
if _, found := dest.Paths.Paths[k]; found {
return fmt.Errorf("unable to merge: duplicated path %s", k)
}
// PathItem may be empty, due to [ACL constraints](http://goo.gl/8us55a#securityFiltering).
if dest.Paths.Paths == nil {
dest.Paths.Paths = map[string]spec.PathItem{}
}
dest.Paths.Paths[k] = v
}
return nil

View File

@@ -133,9 +133,9 @@ definitions:
format: "string"
`), &spec1_filtered)
assert := assert.New(t)
ast := assert.New(t)
FilterSpecByPaths(spec1, []string{"/test"})
assert.Equal(DebugSpec{spec1_filtered}, DebugSpec{spec1})
ast.Equal(DebugSpec{spec1_filtered}, DebugSpec{spec1})
}
func TestFilterSpecsWithUnusedDefinitions(t *testing.T) {
@@ -238,9 +238,9 @@ definitions:
type: "object"
`), &spec1Filtered)
assert := assert.New(t)
ast := assert.New(t)
FilterSpecByPaths(spec1, []string{"/test"})
assert.Equal(DebugSpec{spec1Filtered}, DebugSpec{spec1})
ast.Equal(DebugSpec{spec1Filtered}, DebugSpec{spec1})
}
func TestMergeSpecsSimple(t *testing.T) {
@@ -369,11 +369,211 @@ definitions:
type: "string"
`), &expected)
assert := assert.New(t)
if !assert.NoError(MergeSpecs(spec1, spec2)) {
ast := assert.New(t)
if !ast.NoError(MergeSpecs(spec1, spec2)) {
return
}
assert.Equal(DebugSpec{expected}, DebugSpec{spec1})
ast.Equal(DebugSpec{expected}, DebugSpec{spec1})
}
func TestMergeSpecsEmptyDefinitions(t *testing.T) {
var spec1, spec2, expected *spec.Swagger
yaml.Unmarshal([]byte(`
swagger: "2.0"
paths:
/test:
post:
tags:
- "test"
summary: "Test API"
operationId: "addTest"
parameters:
- in: "body"
name: "body"
description: "test object"
required: true
responses:
405:
description: "Invalid input"
`), &spec1)
yaml.Unmarshal([]byte(`
swagger: "2.0"
paths:
/othertest:
post:
tags:
- "test2"
summary: "Test2 API"
operationId: "addTest2"
consumes:
- "application/json"
produces:
- "application/xml"
parameters:
- in: "body"
name: "body"
description: "test2 object"
required: true
schema:
$ref: "#/definitions/Test2"
definitions:
Test2:
type: "object"
properties:
other:
$ref: "#/definitions/Other"
Other:
type: "string"
`), &spec2)
yaml.Unmarshal([]byte(`
swagger: "2.0"
paths:
/test:
post:
tags:
- "test"
summary: "Test API"
operationId: "addTest"
parameters:
- in: "body"
name: "body"
description: "test object"
required: true
responses:
405:
description: "Invalid input"
/othertest:
post:
tags:
- "test2"
summary: "Test2 API"
operationId: "addTest2"
consumes:
- "application/json"
produces:
- "application/xml"
parameters:
- in: "body"
name: "body"
description: "test2 object"
required: true
schema:
$ref: "#/definitions/Test2"
definitions:
Test2:
type: "object"
properties:
other:
$ref: "#/definitions/Other"
Other:
type: "string"
`), &expected)
ast := assert.New(t)
if !ast.NoError(MergeSpecs(spec1, spec2)) {
return
}
ast.Equal(DebugSpec{expected}, DebugSpec{spec1})
}
func TestMergeSpecsEmptyPaths(t *testing.T) {
var spec1, spec2, expected *spec.Swagger
yaml.Unmarshal([]byte(`
swagger: "2.0"
definitions:
Test:
type: "object"
properties:
id:
type: "integer"
format: "int64"
status:
type: "string"
description: "Status"
InvalidInput:
type: "string"
format: "string"
`), &spec1)
yaml.Unmarshal([]byte(`
swagger: "2.0"
paths:
/othertest:
post:
tags:
- "test2"
summary: "Test2 API"
operationId: "addTest2"
consumes:
- "application/json"
produces:
- "application/xml"
parameters:
- in: "body"
name: "body"
description: "test2 object"
required: true
schema:
$ref: "#/definitions/Test2"
definitions:
Test2:
type: "object"
properties:
other:
$ref: "#/definitions/Other"
Other:
type: "string"
`), &spec2)
yaml.Unmarshal([]byte(`
swagger: "2.0"
paths:
/othertest:
post:
tags:
- "test2"
summary: "Test2 API"
operationId: "addTest2"
consumes:
- "application/json"
produces:
- "application/xml"
parameters:
- in: "body"
name: "body"
description: "test2 object"
required: true
schema:
$ref: "#/definitions/Test2"
definitions:
Test:
type: "object"
properties:
id:
type: "integer"
format: "int64"
status:
type: "string"
description: "Status"
InvalidInput:
type: "string"
format: "string"
Test2:
type: "object"
properties:
other:
$ref: "#/definitions/Other"
Other:
type: "string"
`), &expected)
ast := assert.New(t)
if !ast.NoError(MergeSpecs(spec1, spec2)) {
return
}
ast.Equal(DebugSpec{expected}, DebugSpec{spec1})
}
func TestMergeSpecsReuseModel(t *testing.T) {
@@ -500,11 +700,11 @@ definitions:
format: "string"
`), &expected)
assert := assert.New(t)
if !assert.NoError(MergeSpecs(spec1, spec2)) {
ast := assert.New(t)
if !ast.NoError(MergeSpecs(spec1, spec2)) {
return
}
assert.Equal(DebugSpec{expected}, DebugSpec{spec1})
ast.Equal(DebugSpec{expected}, DebugSpec{spec1})
}
func TestMergeSpecsRenameModel(t *testing.T) {
@@ -636,11 +836,11 @@ definitions:
format: "string"
`), &expected)
assert := assert.New(t)
if !assert.NoError(MergeSpecs(spec1, spec2)) {
ast := assert.New(t)
if !ast.NoError(MergeSpecs(spec1, spec2)) {
return
}
assert.Equal(DebugSpec{expected}, DebugSpec{spec1})
ast.Equal(DebugSpec{expected}, DebugSpec{spec1})
}
func TestMergeSpecsRenameModelWithExistingV2InDestination(t *testing.T) {
@@ -715,11 +915,11 @@ definitions:
type: "object"
`), &expected)
assert := assert.New(t)
if !assert.NoError(MergeSpecs(spec1, spec2)) {
ast := assert.New(t)
if !ast.NoError(MergeSpecs(spec1, spec2)) {
return
}
assert.Equal(DebugSpec{expected}, DebugSpec{spec1})
ast.Equal(DebugSpec{expected}, DebugSpec{spec1})
}
func TestMergeSpecsRenameModelWithExistingV2InSource(t *testing.T) {
@@ -794,11 +994,11 @@ definitions:
type: "object"
`), &expected)
assert := assert.New(t)
if !assert.NoError(MergeSpecs(spec1, spec2)) {
ast := assert.New(t)
if !ast.NoError(MergeSpecs(spec1, spec2)) {
return
}
assert.Equal(DebugSpec{expected}, DebugSpec{spec1})
ast.Equal(DebugSpec{expected}, DebugSpec{spec1})
}
// This tests if there are three specs, where the first two use the same object definition,
@@ -881,14 +1081,14 @@ definitions:
type: "object"
`), &expected)
assert := assert.New(t)
if !assert.NoError(MergeSpecs(spec1, spec2)) {
ast := assert.New(t)
if !ast.NoError(MergeSpecs(spec1, spec2)) {
return
}
if !assert.NoError(MergeSpecs(spec1, spec3)) {
if !ast.NoError(MergeSpecs(spec1, spec3)) {
return
}
assert.Equal(DebugSpec{expected}, DebugSpec{spec1})
ast.Equal(DebugSpec{expected}, DebugSpec{spec1})
}
// This tests if there are three specs, where the last two use the same object definition,
@@ -969,14 +1169,14 @@ definitions:
type: "object"
`), &expected)
assert := assert.New(t)
if !assert.NoError(MergeSpecs(spec1, spec2)) {
ast := assert.New(t)
if !ast.NoError(MergeSpecs(spec1, spec2)) {
return
}
if !assert.NoError(MergeSpecs(spec1, spec3)) {
if !ast.NoError(MergeSpecs(spec1, spec3)) {
return
}
assert.Equal(DebugSpec{expected}, DebugSpec{spec1})
ast.Equal(DebugSpec{expected}, DebugSpec{spec1})
}
func TestSafeMergeSpecsSimple(t *testing.T) {
@@ -1079,15 +1279,15 @@ definitions:
format: "int64"
`), &expected)
assert := assert.New(t)
ast := assert.New(t)
actual, err := CloneSpec(fooSpec)
if !assert.NoError(err) {
if !ast.NoError(err) {
return
}
if !assert.NoError(MergeSpecsFailOnDefinitionConflict(actual, barSpec)) {
if !ast.NoError(MergeSpecsFailOnDefinitionConflict(actual, barSpec)) {
return
}
assert.Equal(DebugSpec{expected}, DebugSpec{actual})
ast.Equal(DebugSpec{expected}, DebugSpec{actual})
}
func TestSafeMergeSpecsReuseModel(t *testing.T) {
@@ -1184,15 +1384,15 @@ definitions:
format: "int64"
`), &expected)
assert := assert.New(t)
ast := assert.New(t)
actual, err := CloneSpec(fooSpec)
if !assert.NoError(err) {
if !ast.NoError(err) {
return
}
if !assert.NoError(MergeSpecsFailOnDefinitionConflict(actual, barSpec)) {
if !ast.NoError(MergeSpecsFailOnDefinitionConflict(actual, barSpec)) {
return
}
assert.Equal(DebugSpec{expected}, DebugSpec{actual})
ast.Equal(DebugSpec{expected}, DebugSpec{actual})
}
func TestSafeMergeSpecsReuseModelFails(t *testing.T) {
@@ -1291,12 +1491,12 @@ definitions:
format: "int64"
`), &expected)
assert := assert.New(t)
ast := assert.New(t)
actual, err := CloneSpec(fooSpec)
if !assert.NoError(err) {
if !ast.NoError(err) {
return
}
assert.Error(MergeSpecsFailOnDefinitionConflict(actual, barSpec))
ast.Error(MergeSpecsFailOnDefinitionConflict(actual, barSpec))
}
func TestMergeSpecsIgnorePathConflicts(t *testing.T) {
@@ -1402,22 +1602,22 @@ definitions:
format: "int64"
`), &expected)
assert := assert.New(t)
ast := assert.New(t)
actual, err := CloneSpec(fooSpec)
if !assert.NoError(err) {
if !ast.NoError(err) {
return
}
if !assert.Error(MergeSpecs(actual, barSpec)) {
if !ast.Error(MergeSpecs(actual, barSpec)) {
return
}
actual, err = CloneSpec(fooSpec)
if !assert.NoError(err) {
if !ast.NoError(err) {
return
}
if !assert.NoError(MergeSpecsIgnorePathConflict(actual, barSpec)) {
if !ast.NoError(MergeSpecsIgnorePathConflict(actual, barSpec)) {
return
}
assert.Equal(DebugSpec{expected}, DebugSpec{actual})
ast.Equal(DebugSpec{expected}, DebugSpec{actual})
}
func TestMergeSpecsIgnorePathConflictsAllConflicting(t *testing.T) {
@@ -1448,16 +1648,16 @@ definitions:
format: "int64"
`), &fooSpec)
assert := assert.New(t)
ast := assert.New(t)
foo2Spec, err := CloneSpec(fooSpec)
actual, err := CloneSpec(fooSpec)
if !assert.NoError(err) {
if !ast.NoError(err) {
return
}
if !assert.NoError(MergeSpecsIgnorePathConflict(actual, foo2Spec)) {
if !ast.NoError(MergeSpecsIgnorePathConflict(actual, foo2Spec)) {
return
}
assert.Equal(DebugSpec{fooSpec}, DebugSpec{actual})
ast.Equal(DebugSpec{fooSpec}, DebugSpec{actual})
}
func TestMergeSpecReplacesAllPossibleRefs(t *testing.T) {
@@ -1650,9 +1850,9 @@ definitions:
type: "object"
`), &expected)
assert := assert.New(t)
if !assert.NoError(MergeSpecs(spec1, spec2)) {
ast := assert.New(t)
if !ast.NoError(MergeSpecs(spec1, spec2)) {
return
}
assert.Equal(DebugSpec{expected}, DebugSpec{spec1})
ast.Equal(DebugSpec{expected}, DebugSpec{spec1})
}