From 6eae11e166661b8a5fa5ca8b84ebc68e9da631bf Mon Sep 17 00:00:00 2001 From: nikhiljindal Date: Tue, 5 Apr 2016 18:08:46 -0700 Subject: [PATCH] Updating the schema validation code --- pkg/api/validation/schema.go | 2 +- pkg/api/validation/schema_test.go | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/pkg/api/validation/schema.go b/pkg/api/validation/schema.go index 713b96ac6536d..1900e7db209fb 100644 --- a/pkg/api/validation/schema.go +++ b/pkg/api/validation/schema.go @@ -284,8 +284,8 @@ func (s *SwaggerSchema) validateField(value interface{}, fieldName, fieldType st } // API servers before release 1.3 produce swagger spec with `type: "any"` as the fallback type, while newer servers produce spec with `type: "object"`. // We have both here so that kubectl can work with both old and new api servers. - case "any": case "object": + case "any": default: return append(allErrs, fmt.Errorf("unexpected type: %v", fieldType)) } diff --git a/pkg/api/validation/schema_test.go b/pkg/api/validation/schema_test.go index 695435f8925eb..9754110a5bd1a 100644 --- a/pkg/api/validation/schema_test.go +++ b/pkg/api/validation/schema_test.go @@ -162,14 +162,15 @@ func TestVersionRegex(t *testing.T) { } } -// Tests that validation works fine when spec contains "type": "object" instead of "type": "any" -func TestTypeObject(t *testing.T) { +// Tests that validation works fine when spec contains "type": "any" instead of "type": "object" +// Ref: https://github.com/kubernetes/kubernetes/issues/24309 +func TestTypeOAny(t *testing.T) { data, err := readSwaggerFile() if err != nil { t.Errorf("failed to read swagger file: %v", err) } // Replace type: "any" in the spec by type: "object" and verify that the validation still passes. - newData := strings.Replace(string(data), `"type": "any"`, `"type": "object"`, -1) + newData := strings.Replace(string(data), `"type": "object"`, `"type": "any"`, -1) schema, err := NewSwaggerSchemaFromBytes([]byte(newData)) if err != nil { t.Errorf("Failed to load: %v", err)