From b68d7751bfdbe6583284a62033629146a06f0411 Mon Sep 17 00:00:00 2001 From: Thomas Rooney Date: Thu, 30 Nov 2023 19:26:27 +0000 Subject: [PATCH] fix: fix regression in serializing additionalProperties fields in v0.3.5 --- README.md | 16 ++++++++++------ USAGE.md | 4 ++-- gen.yaml | 4 ++-- internal/sdk/pkg/utils/json.go | 27 ++++++++++++++++++++++----- internal/sdk/sdk.go | 4 ++-- 5 files changed, 38 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index a5fed2bef..8cc3017af 100755 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ Developers will need to create an API Key within your [Developer Portal](https:/ The Developer Portal UI can also be used to help build your integration by showing information about network requests in the Requests tab. API usage information is also available to you in the Usage tab. - + ## SDK Installation To install this provider, copy and paste this code into your Terraform configuration. Then, run `terraform init`. @@ -33,9 +33,11 @@ provider "airbyte" { # Configuration options } ``` - + + + +## SDK Example Usage - ### Testing the provider locally Should you want to validate a change locally, the `--debug` flag allows you to execute the provider against a terraform instance locally. @@ -52,11 +54,13 @@ cd examples/your-example TF_REATTACH_PROVIDERS=... terraform init TF_REATTACH_PROVIDERS=... terraform apply ``` - + + + +## Available Resources and Operations - - + diff --git a/USAGE.md b/USAGE.md index 2ffc222a8..8e707bb12 100644 --- a/USAGE.md +++ b/USAGE.md @@ -1,4 +1,4 @@ - + ```sh go run main.go --debug # Copy the TF_REATTACH_PROVIDERS env var @@ -7,4 +7,4 @@ cd examples/your-example TF_REATTACH_PROVIDERS=... terraform init TF_REATTACH_PROVIDERS=... terraform apply ``` - \ No newline at end of file + \ No newline at end of file diff --git a/gen.yaml b/gen.yaml index aa9735cd7..b812ab317 100755 --- a/gen.yaml +++ b/gen.yaml @@ -7,9 +7,9 @@ generation: telemetryEnabled: true features: terraform: - additionalProperties: 0.1.1 + additionalProperties: 0.1.2 constsAndDefaults: 0.1.1 - core: 3.5.0 + core: 3.5.1 globalSecurity: 2.81.1 globalServerURLs: 2.82.1 unions: 2.81.5 diff --git a/internal/sdk/pkg/utils/json.go b/internal/sdk/pkg/utils/json.go index 6dce06639..927242c6c 100644 --- a/internal/sdk/pkg/utils/json.go +++ b/internal/sdk/pkg/utils/json.go @@ -66,7 +66,11 @@ func MarshalJSON(v interface{}, tag reflect.StructTag, topLevel bool) ([]byte, e } if additionalProperties == "true" { - if field.Type.Kind() != reflect.Map { + if isNil(field.Type, fieldVal) { + continue + } + fieldVal := trueReflectValue(fieldVal) + if fieldVal.Type().Kind() != reflect.Map { return nil, fmt.Errorf("additionalProperties must be a map") } @@ -202,20 +206,33 @@ func UnmarshalJSON(b []byte, v interface{}, tag reflect.StructTag, topLevel bool } if additionalPropertiesField != nil && additionalPropertiesValue != nil { - if additionalPropertiesValue.Kind() != reflect.Map { + typeOfMap := additionalPropertiesField.Type + if additionalPropertiesValue.Type().Kind() == reflect.Interface { + typeOfMap = reflect.TypeOf(map[string]interface{}{}) + } else if additionalPropertiesValue.Type().Kind() != reflect.Map { return fmt.Errorf("additionalProperties must be a map") } - additionalPropertiesValue.Set(reflect.MakeMap(additionalPropertiesField.Type)) + mapValue := reflect.MakeMap(typeOfMap) for key, value := range unmarhsaled { - val := reflect.New(additionalPropertiesField.Type.Elem()) + val := reflect.New(typeOfMap.Elem()) if err := unmarshalValue(value, val, additionalPropertiesField.Tag, disallowUnknownFields); err != nil { return err } - additionalPropertiesValue.SetMapIndex(reflect.ValueOf(key), val.Elem()) + if val.Elem().Type().String() == typeOfMap.Elem().String() { + mapValue.SetMapIndex(reflect.ValueOf(key), val.Elem()) + } else { + mapValue.SetMapIndex(reflect.ValueOf(key), trueReflectValue(val)) + } + + } + if additionalPropertiesValue.Type().Kind() == reflect.Interface { + additionalPropertiesValue.Set(mapValue) + } else { + additionalPropertiesValue.Set(mapValue) } } } diff --git a/internal/sdk/sdk.go b/internal/sdk/sdk.go index f699103c8..64f37cd5b 100644 --- a/internal/sdk/sdk.go +++ b/internal/sdk/sdk.go @@ -147,8 +147,8 @@ func New(opts ...SDKOption) *SDK { Language: "go", OpenAPIDocVersion: "1.0.0", SDKVersion: "0.3.5", - GenVersion: "2.195.2", - UserAgent: "speakeasy-sdk/go 0.3.5 2.195.2 1.0.0 airbyte", + GenVersion: "internal", + UserAgent: "speakeasy-sdk/go 0.3.5 internal 1.0.0 airbyte", }, } for _, opt := range opts {