Skip to content

Commit

Permalink
fix: fix regression in serializing additionalProperties fields in v0.3.5
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasRooney committed Nov 30, 2023
1 parent 585436d commit b68d775
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 17 deletions.
16 changes: 10 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

<!-- Start SDK Installation -->
<!-- Start SDK Installation [installation] -->
## SDK Installation

To install this provider, copy and paste this code into your Terraform configuration. Then, run `terraform init`.
Expand All @@ -33,9 +33,11 @@ provider "airbyte" {
# Configuration options
}
```
<!-- End SDK Installation -->
<!-- End SDK Installation [installation] -->

<!-- Start SDK Example Usage [usage] -->
## SDK Example Usage

<!-- Start 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.
Expand All @@ -52,11 +54,13 @@ cd examples/your-example
TF_REATTACH_PROVIDERS=... terraform init
TF_REATTACH_PROVIDERS=... terraform apply
```
<!-- End SDK Example Usage -->
<!-- End SDK Example Usage [usage] -->

<!-- Start Available Resources and Operations [operations] -->
## Available Resources and Operations

<!-- Start SDK Available Operations -->

<!-- End SDK Available Operations -->
<!-- End Available Resources and Operations [operations] -->

<!-- Placeholder for Future Speakeasy SDK Sections -->

Expand Down
4 changes: 2 additions & 2 deletions USAGE.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!-- Start SDK Example Usage -->
<!-- Start SDK Example Usage [usage] -->
```sh
go run main.go --debug
# Copy the TF_REATTACH_PROVIDERS env var
Expand All @@ -7,4 +7,4 @@ cd examples/your-example
TF_REATTACH_PROVIDERS=... terraform init
TF_REATTACH_PROVIDERS=... terraform apply
```
<!-- End SDK Example Usage -->
<!-- End SDK Example Usage [usage] -->
4 changes: 2 additions & 2 deletions gen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 22 additions & 5 deletions internal/sdk/pkg/utils/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down Expand Up @@ -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)
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions internal/sdk/sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit b68d775

Please sign in to comment.