Merge pull request #2471 from phanimarupaka/OpenAPIValidations

Validate setters against openAPI
This commit is contained in:
Kubernetes Prow Robot
2020-05-14 11:42:23 -07:00
committed by GitHub
10 changed files with 373 additions and 39 deletions

View File

@@ -66,13 +66,17 @@ func IsYaml1_1NonString(node *Node) bool {
// not a keyword
return false
}
if strings.Contains(node.Value, "\n") {
return IsValueNonString(node.Value)
}
func IsValueNonString(value string) bool {
if strings.Contains(value, "\n") {
// multi-line strings will fail to unmarshal
return false
}
// check if the value will unmarshal into a non-string value using a yaml 1.1 parser
var i1 interface{}
if err := y1_1.Unmarshal([]byte(node.Value), &i1); err != nil {
if err := y1_1.Unmarshal([]byte(value), &i1); err != nil {
return false
}
if reflect.TypeOf(i1) != stringType {

View File

@@ -20,6 +20,8 @@ func TestIsYaml1_1NonString(t *testing.T) {
testCases := []testCase{
{val: "hello world", expected: false},
{val: "2.0", expected: true},
{val: "2", expected: true},
{val: "true", expected: true},
{val: "1.0\nhello", expected: false}, // multiline strings should always be false
}