Commit 6eae11e1 authored by nikhiljindal's avatar nikhiljindal

Updating the schema validation code

parent 8bb7c80f
...@@ -284,8 +284,8 @@ func (s *SwaggerSchema) validateField(value interface{}, fieldName, fieldType st ...@@ -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"`. // 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. // We have both here so that kubectl can work with both old and new api servers.
case "any":
case "object": case "object":
case "any":
default: default:
return append(allErrs, fmt.Errorf("unexpected type: %v", fieldType)) return append(allErrs, fmt.Errorf("unexpected type: %v", fieldType))
} }
......
...@@ -162,14 +162,15 @@ func TestVersionRegex(t *testing.T) { ...@@ -162,14 +162,15 @@ func TestVersionRegex(t *testing.T) {
} }
} }
// Tests that validation works fine when spec contains "type": "object" instead of "type": "any" // Tests that validation works fine when spec contains "type": "any" instead of "type": "object"
func TestTypeObject(t *testing.T) { // Ref: https://github.com/kubernetes/kubernetes/issues/24309
func TestTypeOAny(t *testing.T) {
data, err := readSwaggerFile() data, err := readSwaggerFile()
if err != nil { if err != nil {
t.Errorf("failed to read swagger file: %v", err) 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. // 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)) schema, err := NewSwaggerSchemaFromBytes([]byte(newData))
if err != nil { if err != nil {
t.Errorf("Failed to load: %v", err) t.Errorf("Failed to load: %v", err)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment