Skip to content

Commit cb41245

Browse files
t-edrisnikolasmatt
andauthored
Fix intstr.IntOrString to be number or string instead of object (#453) (#457)
* Fix intstr.IntOrString to be number or string instead of object (#453) * add intstr.IntOrStr custom handling and test * whitespace changes from codegen * add changelog * more autogenerated whitespace changes * remove more whitespaces * reset watcher.go * Move changelog to v0.30.2 --------- Co-authored-by: Nik Matthiopoulos <[email protected]>
1 parent 8c0d770 commit cb41245

File tree

4 files changed

+230
-336
lines changed

4 files changed

+230
-336
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
changelog:
2+
- type: FIX
3+
issueLink: https://github.com/solo-io/gloo-mesh-enterprise/issues/9194
4+
description: intstr.IntOrString fields now output the correct schema instead of an object
5+
skipCI: false

codegen/render/funcs.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
v1 "k8s.io/api/core/v1"
1818
"k8s.io/apimachinery/pkg/api/resource"
1919
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
20+
"k8s.io/apimachinery/pkg/util/intstr"
2021
"k8s.io/utils/strings/slices"
2122

2223
"github.com/BurntSushi/toml"
@@ -709,6 +710,15 @@ func createCustomTypeMapper(values values.UserHelmValues) customTypeMapper {
709710
}
710711
},
711712

713+
reflect.TypeOf(intstr.IntOrString{}): func(t reflect.Type, defaultSchema *jsonschema.Schema) *jsonschema.Schema {
714+
return &jsonschema.Schema{
715+
AnyOf: []*jsonschema.Schema{
716+
{Type: "string"},
717+
{Type: "number"},
718+
},
719+
}
720+
},
721+
712722
reflect.TypeOf(v1.SecurityContext{}): func(t reflect.Type, defaultSchema *jsonschema.Schema) *jsonschema.Schema {
713723
return &jsonschema.Schema{
714724
AnyOf: []*jsonschema.Schema{

codegen/render/funcs_test.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
v1 "k8s.io/api/core/v1"
1414
"k8s.io/apimachinery/pkg/api/resource"
1515
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
16+
"k8s.io/apimachinery/pkg/util/intstr"
1617

1718
"github.com/solo-io/skv2/codegen/model/values"
1819
"github.com/solo-io/skv2/codegen/render"
@@ -648,6 +649,30 @@ var _ = Describe("toJSONSchema", func() {
648649
Expect(result).To(Equal(expected))
649650
})
650651

652+
It("maps intstr.IntOrString as either a string or number", func() {
653+
type Type1 struct {
654+
Field1 intstr.IntOrString
655+
}
656+
result := render.ToJSONSchema(values.UserHelmValues{CustomValues: &Type1{}})
657+
expected := prepareExpected(`
658+
{
659+
"$schema": "https://json-schema.org/draft/2020-12/schema",
660+
"properties": {
661+
"Field1": {
662+
"anyOf": [
663+
{
664+
"type": "string"
665+
},
666+
{
667+
"type": "number"
668+
}
669+
]
670+
}
671+
}
672+
}`)
673+
Expect(result).To(Equal(expected))
674+
})
675+
651676
It("maps security context as something that can be mapped to a boolean", func() {
652677
type Type1 struct {
653678
Field1 *v1.SecurityContext

0 commit comments

Comments
 (0)