Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changes/unreleased/BUG FIXES-20231220-133159.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
kind: BUG FIXES
body: Fixed a bug where schema defaults were not detected for integer/int32 properties
time: 2023-12-20T13:31:59.436063-05:00
custom:
Issue: "111"
6 changes: 5 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/hashicorp/cli v1.1.6
github.com/hashicorp/terraform-plugin-codegen-spec v0.1.0
github.com/mattn/go-colorable v0.1.13
github.com/pb33f/libopenapi v0.13.22
github.com/pb33f/libopenapi v0.14.4
gopkg.in/yaml.v3 v3.0.1
)

Expand All @@ -16,21 +16,25 @@ require (
github.com/Masterminds/semver/v3 v3.2.0 // indirect
github.com/Masterminds/sprig/v3 v3.2.3 // indirect
github.com/armon/go-radix v1.0.0 // indirect
github.com/bahlo/generic-list-go v0.2.0 // indirect
github.com/bgentry/speakeasy v0.1.0 // indirect
github.com/buger/jsonparser v1.1.1 // indirect
github.com/dprotaso/go-yit v0.0.0-20220510233725-9ba8df137936 // indirect
github.com/fatih/color v1.16.0 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/huandu/xstrings v1.4.0 // indirect
github.com/imdario/mergo v0.3.15 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/posener/complete v1.2.3 // indirect
github.com/shopspring/decimal v1.3.1 // indirect
github.com/spf13/cast v1.5.0 // indirect
github.com/vmware-labs/yaml-jsonpath v0.3.2 // indirect
github.com/wk8/go-ordered-map/v2 v2.1.8 // indirect
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f // indirect
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
github.com/xeipuuv/gojsonschema v1.2.0 // indirect
Expand Down
19 changes: 15 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@ github.com/Masterminds/sprig/v3 v3.2.3 h1:eL2fZNezLomi0uOLqjQoN6BfsDD+fyLtgbJMAj
github.com/Masterminds/sprig/v3 v3.2.3/go.mod h1:rXcFaZ2zZbLRJv/xSysmlgIM1u11eBaRMhvYXJNkGuM=
github.com/armon/go-radix v1.0.0 h1:F4z6KzEeeQIMeLFa97iZU6vupzoecKdU5TX24SNppXI=
github.com/armon/go-radix v1.0.0/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8=
github.com/bahlo/generic-list-go v0.2.0 h1:5sz/EEAK+ls5wF+NeqDpk5+iNdMDXrh3z3nPnH1Wvgk=
github.com/bahlo/generic-list-go v0.2.0/go.mod h1:2KvAjgMlE5NNynlg/5iLrrCCZ2+5xWbdbCW3pNTGyYg=
github.com/bgentry/speakeasy v0.1.0 h1:ByYyxL9InA1OWqxJqqp2A5pYHUrCiAL6K3J+LKSsQkY=
github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs=
github.com/buger/jsonparser v1.1.1 h1:2PnMjfWD7wBILjqQbt530v576A/cAbQvEW9gGIpYMUs=
github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0=
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
Expand Down Expand Up @@ -62,13 +66,16 @@ github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:
github.com/imdario/mergo v0.3.11/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA=
github.com/imdario/mergo v0.3.15 h1:M8XP7IuFNsqUx6VPK2P9OSmsYsI/YFaGil0uD21V3dM=
github.com/imdario/mergo v0.3.15/go.mod h1:WBLT9ZmE3lPoWsEzCh9LPo3TiwVN+ZKEjmz+hD27ysY=
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0=
github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
Expand All @@ -95,8 +102,10 @@ github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1y
github.com/onsi/gomega v1.17.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAlGdZY=
github.com/onsi/gomega v1.19.0 h1:4ieX6qQjPP/BfC3mpsAtIGGlxTWPeA3Inl/7DtXw1tw=
github.com/onsi/gomega v1.19.0/go.mod h1:LY+I3pBVzYsTBU1AnDwOSxaYi9WoWiqgwooUqq9yPro=
github.com/pb33f/libopenapi v0.13.22 h1:QivxHLf+ZaYl2mFivUFkKZ7315mtYMipaQP5zp0U1H4=
github.com/pb33f/libopenapi v0.13.22/go.mod h1:Lv2eEtsAtbRFlF8hjH82L8SIGoUNgemMVoKoB6A9THk=
github.com/pb33f/libopenapi v0.14.3 h1:GeUaHFre9WiI5jHAg283HvBNdxhSKfFkNQikNAj2gqY=
github.com/pb33f/libopenapi v0.14.3/go.mod h1:m+4Pwri31UvcnZjuP8M7TlbR906DXJmMvYsbis234xg=
github.com/pb33f/libopenapi v0.14.4 h1:NbcYaBbG/6pnJM8lw4F6b5e54HandyKF452HUl4+9j4=
github.com/pb33f/libopenapi v0.14.4/go.mod h1:m+4Pwri31UvcnZjuP8M7TlbR906DXJmMvYsbis234xg=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/posener/complete v1.2.3 h1:NP0eAhjcjImqslEwo/1hq7gpajME0fTLTezBKDqfXqo=
Expand All @@ -116,10 +125,12 @@ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXf
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/vmware-labs/yaml-jsonpath v0.3.2 h1:/5QKeCBGdsInyDCyVNLbXyilb61MXGi9NP674f9Hobk=
github.com/vmware-labs/yaml-jsonpath v0.3.2/go.mod h1:U6whw1z03QyqgWdgXxvVnQ90zN1BWz5V+51Ewf8k+rQ=
github.com/wk8/go-ordered-map/v2 v2.1.8 h1:5h/BUHu93oj4gIdvHHHGsScSTMijfx5PeYkE/fJgbpc=
github.com/wk8/go-ordered-map/v2 v2.1.8/go.mod h1:5nJHM5DyteebpVlHnWMV0rPz6Zp7+xBAnxjb1X5vnTw=
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f h1:J9EGpcZtP0E/raorCMxlFGSTBrsSlaDGf3jU/qvAE2c=
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU=
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 h1:EzJWgHovont7NscjpAxXsDA8S8BMYve8Y5+7cuRE7R0=
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func (cmd *GenerateCommand) runInternal(logger *slog.Logger) error {
}

// 7. Log a warning if the provider code spec is not valid based on the JSON schema
err = spec.Validate(context.Background(), bytes)
err = spec.Validate(context.TODO(), bytes)
if err != nil {
logger.Warn(
"generated provider code spec failed validation",
Expand Down
85 changes: 68 additions & 17 deletions internal/cmd/testdata/kubernetes/provider_code_spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,10 @@
{
"name": "weight",
"int64": {
"computed_optional_required": "required",
"computed_optional_required": "computed_optional",
"default": {
"static": 0
},
"description": "Weight associated with matching the corresponding nodeSelectorTerm, in the range 1-100."
}
}
Expand Down Expand Up @@ -1033,7 +1036,10 @@
{
"name": "weight",
"int64": {
"computed_optional_required": "required",
"computed_optional_required": "computed_optional",
"default": {
"static": 0
},
"description": "weight associated with matching the corresponding podAffinityTerm, in the range 1-100."
}
}
Expand Down Expand Up @@ -1360,7 +1366,10 @@
{
"name": "weight",
"int64": {
"computed_optional_required": "required",
"computed_optional_required": "computed_optional",
"default": {
"static": 0
},
"description": "weight associated with matching the corresponding podAffinityTerm, in the range 1-100."
}
}
Expand Down Expand Up @@ -2087,7 +2096,10 @@
{
"name": "port",
"int64": {
"computed_optional_required": "required",
"computed_optional_required": "computed_optional",
"default": {
"static": 0
},
"description": "Port number of the gRPC service. Number must be in the range 1 to 65535."
}
},
Expand Down Expand Up @@ -2254,7 +2266,10 @@
{
"name": "container_port",
"int64": {
"computed_optional_required": "required",
"computed_optional_required": "computed_optional",
"default": {
"static": 0
},
"description": "Number of port to expose on the pod's IP address. This must be a valid port number, 0 \u003c x \u003c 65536."
}
},
Expand Down Expand Up @@ -2333,7 +2348,10 @@
{
"name": "port",
"int64": {
"computed_optional_required": "required",
"computed_optional_required": "computed_optional",
"default": {
"static": 0
},
"description": "Port number of the gRPC service. Number must be in the range 1 to 65535."
}
},
Expand Down Expand Up @@ -2795,7 +2813,10 @@
{
"name": "port",
"int64": {
"computed_optional_required": "required",
"computed_optional_required": "computed_optional",
"default": {
"static": 0
},
"description": "Port number of the gRPC service. Number must be in the range 1 to 65535."
}
},
Expand Down Expand Up @@ -3699,7 +3720,10 @@
{
"name": "port",
"int64": {
"computed_optional_required": "required",
"computed_optional_required": "computed_optional",
"default": {
"static": 0
},
"description": "Port number of the gRPC service. Number must be in the range 1 to 65535."
}
},
Expand Down Expand Up @@ -3866,7 +3890,10 @@
{
"name": "container_port",
"int64": {
"computed_optional_required": "required",
"computed_optional_required": "computed_optional",
"default": {
"static": 0
},
"description": "Number of port to expose on the pod's IP address. This must be a valid port number, 0 \u003c x \u003c 65536."
}
},
Expand Down Expand Up @@ -3945,7 +3972,10 @@
{
"name": "port",
"int64": {
"computed_optional_required": "required",
"computed_optional_required": "computed_optional",
"default": {
"static": 0
},
"description": "Port number of the gRPC service. Number must be in the range 1 to 65535."
}
},
Expand Down Expand Up @@ -4407,7 +4437,10 @@
{
"name": "port",
"int64": {
"computed_optional_required": "required",
"computed_optional_required": "computed_optional",
"default": {
"static": 0
},
"description": "Port number of the gRPC service. Number must be in the range 1 to 65535."
}
},
Expand Down Expand Up @@ -5332,7 +5365,10 @@
{
"name": "port",
"int64": {
"computed_optional_required": "required",
"computed_optional_required": "computed_optional",
"default": {
"static": 0
},
"description": "Port number of the gRPC service. Number must be in the range 1 to 65535."
}
},
Expand Down Expand Up @@ -5499,7 +5535,10 @@
{
"name": "container_port",
"int64": {
"computed_optional_required": "required",
"computed_optional_required": "computed_optional",
"default": {
"static": 0
},
"description": "Number of port to expose on the pod's IP address. This must be a valid port number, 0 \u003c x \u003c 65536."
}
},
Expand Down Expand Up @@ -5578,7 +5617,10 @@
{
"name": "port",
"int64": {
"computed_optional_required": "required",
"computed_optional_required": "computed_optional",
"default": {
"static": 0
},
"description": "Port number of the gRPC service. Number must be in the range 1 to 65535."
}
},
Expand Down Expand Up @@ -6040,7 +6082,10 @@
{
"name": "port",
"int64": {
"computed_optional_required": "required",
"computed_optional_required": "computed_optional",
"default": {
"static": 0
},
"description": "Port number of the gRPC service. Number must be in the range 1 to 65535."
}
},
Expand Down Expand Up @@ -6851,7 +6896,10 @@
{
"name": "max_skew",
"int64": {
"computed_optional_required": "required",
"computed_optional_required": "computed_optional",
"default": {
"static": 0
},
"description": "MaxSkew describes the degree to which pods may be unevenly distributed. When `whenUnsatisfiable=DoNotSchedule`, it is the maximum permitted difference between the number of matching pods in the target topology and the global minimum. The global minimum is the minimum number of matching pods in an eligible domain or zero if the number of eligible domains is less than MinDomains. For example, in a 3-zone cluster, MaxSkew is set to 1, and pods with the same labelSelector spread as 2/2/1: In this case, the global minimum is 1. | zone1 | zone2 | zone3 | | P P | P P | P | - if MaxSkew is 1, incoming pod can only be scheduled to zone3 to become 2/2/2; scheduling it onto zone1(zone2) would make the ActualSkew(3-1) on zone1(zone2) violate MaxSkew(1). - if MaxSkew is 2, incoming pod can be scheduled onto any zone. When `whenUnsatisfiable=ScheduleAnyway`, it is used to give higher precedence to topologies that satisfy it. It's a required field. Default value is 1 and 0 is not allowed."
}
},
Expand Down Expand Up @@ -8185,7 +8233,10 @@
{
"name": "lun",
"int64": {
"computed_optional_required": "required",
"computed_optional_required": "computed_optional",
"default": {
"static": 0
},
"description": "lun represents iSCSI Target Lun number."
}
},
Expand Down
22 changes: 12 additions & 10 deletions internal/explorer/config_explorer.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,27 +117,29 @@ func extractOp(paths *high.Paths, oasLocation *config.OpenApiSpecLocation) (*hig
return nil, nil
}

if paths == nil || paths.PathItems == nil || paths.PathItems[oasLocation.Path] == nil {
if paths == nil || paths.PathItems == nil || paths.PathItems.GetOrZero(oasLocation.Path) == nil {
return nil, fmt.Errorf("path '%s' not found in OpenAPI spec", oasLocation.Path)
}

pathItem, _ := paths.PathItems.Get(oasLocation.Path)

switch strings.ToLower(oasLocation.Method) {
case low.PostLabel:
return paths.PathItems[oasLocation.Path].Post, nil
return pathItem.Post, nil
case low.GetLabel:
return paths.PathItems[oasLocation.Path].Get, nil
return pathItem.Get, nil
case low.PutLabel:
return paths.PathItems[oasLocation.Path].Put, nil
return pathItem.Put, nil
case low.DeleteLabel:
return paths.PathItems[oasLocation.Path].Delete, nil
return pathItem.Delete, nil
case low.PatchLabel:
return paths.PathItems[oasLocation.Path].Patch, nil
return pathItem.Patch, nil
case low.OptionsLabel:
return paths.PathItems[oasLocation.Path].Options, nil
return pathItem.Options, nil
case low.HeadLabel:
return paths.PathItems[oasLocation.Path].Head, nil
return pathItem.Head, nil
case low.TraceLabel:
return paths.PathItems[oasLocation.Path].Trace, nil
return pathItem.Trace, nil
default:
return nil, fmt.Errorf("method '%s' not found at OpenAPI path '%s'", oasLocation.Method, oasLocation.Path)
}
Expand All @@ -158,7 +160,7 @@ func extractSchemaProxy(document high.Document, componentRef string) (*highbase.
}

// populate low-level schema, using root document.Index for resolving
err = lowSchema.Build(context.Background(), indexRef.Node, document.Index)
err = lowSchema.Build(context.TODO(), indexRef.Node, document.Index)
if err != nil {
return nil, fmt.Errorf("error populating low-level schema: %w", err)
}
Expand Down
Loading