mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-11 17:12:51 +00:00
Merge pull request #2471 from phanimarupaka/OpenAPIValidations
Validate setters against openAPI
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user