Skip to content

Commit

Permalink
Handle upstream breaking changes
Browse files Browse the repository at this point in the history
  • Loading branch information
praneetloke committed Apr 6, 2024
1 parent b4fc9d5 commit a7a0eb5
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 57 deletions.
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ require (
github.com/kylelemons/godebug v1.1.0 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-localereader v0.0.1 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
Expand Down
37 changes: 2 additions & 35 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,6 @@ github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69
github.com/golang-jwt/jwt/v5 v5.2.0 h1:d/ix8ftRUorsN+5eMIlF4T6J8CAt9rch3My2winC1Jw=
github.com/golang-jwt/jwt/v5 v5.2.0/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
github.com/golang/glog v1.2.0 h1:uCdmnmatrKCgMBlM4rMuJZWOkPDqdbZPnrMXDY4gI68=
github.com/golang/glog v1.2.0/go.mod h1:6AhwSGph0fcJtXVM/PEHPqZlFeoLxhs7/t5UDAwmO+w=
github.com/golang/glog v1.2.1 h1:OptwRhECazUx5ix5TTWC3EZhsZEHWcYWY4FQHTIubm4=
github.com/golang/glog v1.2.1/go.mod h1:6AhwSGph0fcJtXVM/PEHPqZlFeoLxhs7/t5UDAwmO+w=
github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
Expand Down Expand Up @@ -307,7 +305,6 @@ github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hd
github.com/mattn/go-isatty v0.0.11/go.mod h1:PhnuNfih5lzO57/f3n+odYbM4JtupLOxQOAqxQCu2WE=
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-localereader v0.0.1 h1:ygSAOl7ZXTx4RdPYinUpg6W99U8jWvWi9Ye2JC/oIi4=
Expand Down Expand Up @@ -374,28 +371,8 @@ github.com/pulumi/appdash v0.0.0-20231130102222-75f619a67231 h1:vkHw5I/plNdTr435
github.com/pulumi/appdash v0.0.0-20231130102222-75f619a67231/go.mod h1:murToZ2N9hNJzewjHBgfFdXhZKjY3z5cYC1VXk+lbFE=
github.com/pulumi/esc v0.8.2 h1:+PZg+qAWW9SYrRCHex36QNueAWdxz9b7hi/q/Zb31V0=
github.com/pulumi/esc v0.8.2/go.mod h1:v5VAPxYDa9DRwvubbzKt4ZYf5y0esWC2ccSp/AT923I=
github.com/pulumi/pulumi/pkg/v3 v3.106.0 h1:5mQGmad/qS/nESIswUKey6xyFZ2ZJ7iMTwZzoCMN+zI=
github.com/pulumi/pulumi/pkg/v3 v3.106.0/go.mod h1:sZMGEPMp2sLbB0PEyrPWDvAX+W2AwOptAKnKOHyX01k=
github.com/pulumi/pulumi/pkg/v3 v3.109.0 h1:Nww0a/qil7sDBPsott3d3p1YWOQ3QGNYLXTtzzcMz3Q=
github.com/pulumi/pulumi/pkg/v3 v3.109.0/go.mod h1:rU/82+ujNGv9oFx4LJKIIQjYhrl6LV3kOgK6XQgGuEM=
github.com/pulumi/pulumi/pkg/v3 v3.110.0 h1:HXe50491kF7jkGMZizkweUBWMEPZ9QUHo7Q1PYxriAA=
github.com/pulumi/pulumi/pkg/v3 v3.110.0/go.mod h1:bJkaCCsj7Nqb/Sp7tBdonVWjzWDJFedrkA4IUzZkJrU=
github.com/pulumi/pulumi/pkg/v3 v3.111.0 h1:+qZ8J182jN6dn12AEJip0XTkUuTIHbnfcUYeIIydVfc=
github.com/pulumi/pulumi/pkg/v3 v3.111.0/go.mod h1:hlXLgOHv1xIzhJMc4PGdHEWsXIp8mP/mNRj27gkzG6Y=
github.com/pulumi/pulumi/pkg/v3 v3.111.1 h1:SrVgQE96T7YlZx/AZoFSlXYwur7ZmQUHyjbPI8sH96Q=
github.com/pulumi/pulumi/pkg/v3 v3.111.1/go.mod h1:ZWsq8Y0EMHZ5E2ju92jC+POz97TEXs3BbQ6r2o0U4SA=
github.com/pulumi/pulumi/pkg/v3 v3.112.0 h1:vhoM6sx1eegJntIeUZENtck3VeMtK1zBiQ2E3EPOnHw=
github.com/pulumi/pulumi/pkg/v3 v3.112.0/go.mod h1:GQhNr0v5E8TACF8j0p6UQqyr7mZreUpoMfVjLeu6eY0=
github.com/pulumi/pulumi/sdk/v3 v3.106.0 h1:Og3sPKC3SJ2xyQ0dF5si6C126SwcR6rm4lupHh83ELk=
github.com/pulumi/pulumi/sdk/v3 v3.106.0/go.mod h1:Ml3rpGfyZlI4zQCG7LN2XDSmH4XUNYdyBwJ3yEr/OpI=
github.com/pulumi/pulumi/sdk/v3 v3.109.0 h1:bcejf5DNcx2I66X1M2tYFKzZGvefPD44sGzOMr0UB00=
github.com/pulumi/pulumi/sdk/v3 v3.109.0/go.mod h1:5A6GHUwAJlRY1SSLZh84aDIbsBShcrfcmHzI50ecSBg=
github.com/pulumi/pulumi/sdk/v3 v3.110.0 h1:uuo5Wkr/6aB1bSY7rC2wWx2VZviO/4Yh3Fi1vORnnxE=
github.com/pulumi/pulumi/sdk/v3 v3.110.0/go.mod h1:5A6GHUwAJlRY1SSLZh84aDIbsBShcrfcmHzI50ecSBg=
github.com/pulumi/pulumi/sdk/v3 v3.111.0 h1:XyH2cH2Zm7gMr1rHyFhPXmYE5PsJVfRDDq6iA7R1nkQ=
github.com/pulumi/pulumi/sdk/v3 v3.111.0/go.mod h1:5A6GHUwAJlRY1SSLZh84aDIbsBShcrfcmHzI50ecSBg=
github.com/pulumi/pulumi/sdk/v3 v3.111.1 h1:uOeG/b6YxBuL59xHtmFPspMa8BB6ovjHelL7sVCGJZw=
github.com/pulumi/pulumi/sdk/v3 v3.111.1/go.mod h1:5A6GHUwAJlRY1SSLZh84aDIbsBShcrfcmHzI50ecSBg=
github.com/pulumi/pulumi/sdk/v3 v3.112.0 h1:cq2x5N6iuYhSLdeOdRs+LIq0EneB0Cb54WOlD/VaX3E=
github.com/pulumi/pulumi/sdk/v3 v3.112.0/go.mod h1:JWSzKBoHd8rlncC1DhXLf7YdV+Bk/Qf+hSZOOQh0WwQ=
github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
Expand Down Expand Up @@ -428,8 +405,9 @@ github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY=
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
Expand All @@ -439,8 +417,6 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/texttheater/golang-levenshtein v1.0.1 h1:+cRNoVrfiwufQPhoMzB6N0Yf/Mqajr6t1lOv8GyGE2U=
Expand Down Expand Up @@ -497,8 +473,6 @@ golang.org/x/crypto v0.3.1-0.20221117191849-2c476679df9a/go.mod h1:hebNnKkNXi2Uz
golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU=
golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliYc=
golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg=
golang.org/x/crypto v0.19.0 h1:ENy+Az/9Y1vSrlrvBSyna3PITt4tiZLf7sgCjZBX7Wo=
golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU=
golang.org/x/crypto v0.21.0 h1:X31++rzVUdKhX5sWmSOFZxx8UW/ldWx55cbf08iNAMA=
golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
Expand Down Expand Up @@ -573,7 +547,6 @@ golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20220615213510-4f61da869c0c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
Expand All @@ -582,8 +555,6 @@ golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y=
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
Expand All @@ -594,8 +565,6 @@ golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U=
golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo=
golang.org/x/term v0.12.0/go.mod h1:owVbMEjm3cBLCHdkQu9b1opXd4ETQWc3BhuQGKgXgvU=
golang.org/x/term v0.16.0/go.mod h1:yn7UURbUtPyrVJPGPq404EukNFxcm/foM+bV/bfcDsY=
golang.org/x/term v0.17.0 h1:mkTF7LCd6WGJNL3K1Ad7kwxNfYAW6a8a8QqtMblp/4U=
golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk=
golang.org/x/term v0.18.0 h1:FcHjZXDMxI8mM3nwhX9HlKop4C0YQvCVCdwYl2wOtE8=
golang.org/x/term v0.18.0/go.mod h1:ILwASektA3OnRv7amZ1xhE/KTR+u50pbXfZ03+6Nx58=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
Expand Down Expand Up @@ -667,8 +636,6 @@ google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpAD
google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.32.0 h1:pPC6BG5ex8PDFnkbrGU3EixyhKcQ2aDuBS36lqK/C7I=
google.golang.org/protobuf v1.32.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI=
google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
42 changes: 21 additions & 21 deletions pkg/openapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func (o *OpenAPIContext) GatherResourcesFromAPI(csharpNamespaces map[string]stri

// Use the type and operationID as a hint to determine if this GET endpoint returns a single resource
// or a list of resources.
if resourceType.Type != openapi3.TypeArray && !strings.Contains(strings.ToLower(pathItem.Get.OperationID), "list") {
if !resourceType.Type.Is(openapi3.TypeArray) && !strings.Contains(strings.ToLower(pathItem.Get.OperationID), "list") {
// If there is a discriminator then we should set this operation
// as the read endpoint for each of the types in the mapping.
if resourceType.Discriminator != nil {
Expand Down Expand Up @@ -196,7 +196,7 @@ func (o *OpenAPIContext) GatherResourcesFromAPI(csharpNamespaces map[string]stri
}

// Add the API operation as a list* function.
if resourceType.Type == openapi3.TypeArray || strings.Contains(strings.ToLower(pathItem.Get.OperationID), "list") {
if resourceType.Type.Is(openapi3.TypeArray) || strings.Contains(strings.ToLower(pathItem.Get.OperationID), "list") {
funcName := "list" + getResourceTitleFromOperationID(pathItem.Get.OperationID, http.MethodGet, o.OperationIdsHaveTypeSpecNamespace)
funcTypeToken := o.Pkg.Name + ":" + module + ":" + funcName
funcSpec, err := o.genListFunc(*pathItem, *jsonReq.Schema, module, funcName)
Expand Down Expand Up @@ -791,7 +791,7 @@ func (o *OpenAPIContext) gatherResourceProperties(resourceName string, requestBo
var types []pschema.TypeSpec
newlyAddedTypes := codegen.NewStringSet()
for _, schemaRef := range requestBodySchema.AllOf {
if schemaRef == nil || (schemaRef.Value.Type != "object" && len(schemaRef.Value.AllOf) == 0) {
if schemaRef == nil || (!schemaRef.Value.Type.Is(openapi3.TypeObject) && len(schemaRef.Value.AllOf) == 0) {
continue
}

Expand Down Expand Up @@ -868,7 +868,7 @@ func (ctx *resourceContext) genPropertySpec(propName string, p openapi3.SchemaRe
Description: p.Value.Description,
}

if p.Value.Default != nil && p.Value.Type != openapi3.TypeArray {
if p.Value.Default != nil && !p.Value.Type.Is(openapi3.TypeArray) {
propertySpec.Default = p.Value.Default
}

Expand Down Expand Up @@ -907,7 +907,7 @@ func (ctx *resourceContext) genPropertySpec(propName string, p openapi3.SchemaRe
func (ctx *resourceContext) propertyTypeSpec(parentName string, propSchema openapi3.SchemaRef) (*pschema.TypeSpec, bool, error) {
// References to other type definitions as long as the type is not an array.
// Arrays and enums will be handled later in this method.
if propSchema.Ref != "" && propSchema.Value.Type != openapi3.TypeArray && len(propSchema.Value.Enum) == 0 {
if propSchema.Ref != "" && !propSchema.Value.Type.Is(openapi3.TypeArray) && len(propSchema.Value.Enum) == 0 {
schemaName := strings.TrimPrefix(propSchema.Ref, componentsSchemaRefPrefix)
typName := ToPascalCase(schemaName)
tok := fmt.Sprintf("%s:%s:%s", ctx.pkg.Name, ctx.mod, typName)
Expand All @@ -925,11 +925,11 @@ func (ctx *resourceContext) propertyTypeSpec(parentName string, propSchema opena
// return a TypeSpec for that type.
// Properties can refer to reusable schema types
// which are actually just simple types.
if typeSchema.Value.Type != openapi3.TypeObject &&
if !typeSchema.Value.Type.Is(openapi3.TypeObject) &&
len(typeSchema.Value.Properties) == 0 &&
len(typeSchema.Value.AllOf) == 0 {
return &pschema.TypeSpec{
Type: typeSchema.Value.Type,
Type: typeSchema.Value.Type.Slice()[0],
}, false, nil
}

Expand Down Expand Up @@ -1049,18 +1049,18 @@ func (ctx *resourceContext) propertyTypeSpec(parentName string, propSchema opena
}

// All other types.
switch propSchema.Value.Type {
case openapi3.TypeInteger:
switch {
case propSchema.Value.Type.Is(openapi3.TypeInteger):
return &pschema.TypeSpec{Type: "integer"}, false, nil
case openapi3.TypeString:
case propSchema.Value.Type.Is(openapi3.TypeString):
return &pschema.TypeSpec{Type: "string"}, false, nil
case openapi3.TypeBoolean:
case propSchema.Value.Type.Is(openapi3.TypeBoolean):
return &pschema.TypeSpec{Type: "boolean"}, false, nil
case openapi3.TypeNumber:
case propSchema.Value.Type.Is(openapi3.TypeNumber):
return &pschema.TypeSpec{Type: "number"}, false, nil
case openapi3.TypeObject:
case propSchema.Value.Type.Is(openapi3.TypeObject):
return &pschema.TypeSpec{Ref: "pulumi.json#/Any"}, false, nil
case openapi3.TypeArray:
case propSchema.Value.Type.Is(openapi3.TypeArray):
elementType, _, err := ctx.propertyTypeSpec(parentName+"Item", *propSchema.Value.Items)
if err != nil {
return nil, false, errors.Wrapf(err, "generating array item type (parentName: %s)", parentName)
Expand Down Expand Up @@ -1140,7 +1140,7 @@ func (ctx *resourceContext) genProperties(parentName string, typeSchema openapi3
// Don't set default values for array-type properties
// since Pulumi doesn't support it and also it isn't
// very helpful anyway for arrays.
if value.Value.Default != nil && value.Value.Type != openapi3.TypeArray {
if value.Value.Default != nil && !value.Value.Type.Is(openapi3.TypeArray) {
propertySpec.Default = value.Value.Default
}

Expand Down Expand Up @@ -1172,7 +1172,7 @@ func (ctx *resourceContext) genPropertiesFromAllOf(parentName string, allOf open
newlyAddedTypes := codegen.NewStringSet()

for _, schemaRef := range allOf {
if schemaRef.Ref == "" && schemaRef.Value.Type != "object" {
if schemaRef.Ref == "" && !schemaRef.Value.Type.Is(openapi3.TypeObject) {
glog.Warningf("Prop type %s uses allOf schema but one of the schema refs is invalid", parentName)
continue
}
Expand Down Expand Up @@ -1260,7 +1260,7 @@ func getIntegerEnumValues(rawEnumValues []interface{}) ([]pschema.EnumValueSpec,

// genEnumType generates the enum type for a given schema.
func (ctx *resourceContext) genEnumType(enumName string, propSchema openapi3.Schema) (*pschema.TypeSpec, error) {
if len(propSchema.Type) == 0 {
if len(propSchema.Type.Slice()) == 0 {
return nil, nil
}

Expand All @@ -1270,16 +1270,16 @@ func (ctx *resourceContext) genEnumType(enumName string, propSchema openapi3.Sch
enumSpec := &pschema.ComplexTypeSpec{
ObjectTypeSpec: pschema.ObjectTypeSpec{
Description: propSchema.Description,
Type: propSchema.Type,
Type: propSchema.Type.Slice()[0],
},
}

var names codegen.StringSet

switch propSchema.Type {
case openapi3.TypeString:
switch {
case propSchema.Type.Is(openapi3.TypeString):
enumSpec.Enum, names = getStringEnumValues(propSchema.Enum)
case openapi3.TypeInteger:
case propSchema.Type.Is(openapi3.TypeInteger):
enumSpec.Enum, names = getIntegerEnumValues(propSchema.Enum)
default:
return nil, errors.Errorf("cannot handle enum values of type %s", propSchema.Type)
Expand Down

0 comments on commit a7a0eb5

Please sign in to comment.