@@ -26,6 +26,7 @@ const (
2626 itemsKey = "items"
2727 propertiesKey = "properties"
2828 defaultKey = "default"
29+ nullableKey = "nullable"
2930)
3031
3132var keyOrder = map [string ]int {
@@ -35,6 +36,7 @@ var keyOrder = map[string]int{
3536 itemsKey : 4 ,
3637 propertiesKey : 5 ,
3738 defaultKey : 6 ,
39+ nullableKey : 7 ,
3840}
3941
4042const (
@@ -211,6 +213,11 @@ func (h HelmValuesSchemaGen) calculateProperties(key *yaml3.Node, value *yaml3.N
211213 if err != nil {
212214 return nil , err
213215 }
216+ if value .Tag == nullTag {
217+ // We cannot infer a key's type from a null value and must assume "any".
218+ apiKeys = append (apiKeys , newAnyType ())
219+ break
220+ }
214221 apiKeys = append (apiKeys , & MapItem {Key : typeKey , Value : h .openAPIType (value .Tag , value .Value )})
215222 apiKeys = append (apiKeys , & MapItem {Key : defaultKey , Value : defaultVal })
216223 if value .Tag == floatTag {
@@ -266,7 +273,6 @@ func (h HelmValuesSchemaGen) openAPIType(tag, value string) string {
266273 }
267274 }
268275 return "string"
269-
270276}
271277
272278func (h HelmValuesSchemaGen ) getDefaultValue (tag , value string ) (interface {}, error ) {
@@ -281,3 +287,29 @@ func (h HelmValuesSchemaGen) getDefaultValue(tag, value string) (interface{}, er
281287 return value , nil
282288 }
283289}
290+
291+ func newAnyType () * MapItem {
292+ nullable := func (t string ) map [string ]interface {} {
293+ n := map [string ]interface {}{
294+ typeKey : t ,
295+ defaultKey : nil ,
296+ nullableKey : true ,
297+ }
298+ if t == "array" {
299+ n ["items" ] = map [string ]string {}
300+ }
301+ return n
302+ }
303+ return & MapItem {
304+ Key : "oneOf" ,
305+ Value : []map [string ]interface {}{
306+ nullable ("integer" ),
307+ nullable ("number" ),
308+ nullable ("boolean" ),
309+ nullable ("string" ),
310+ nullable ("object" ),
311+ nullable ("array" ),
312+ },
313+ }
314+ }
315+
0 commit comments