From 46422b54203c8f34dd97f4840e0ee1ef1ce3dbf8 Mon Sep 17 00:00:00 2001 From: SDKAuto Date: Fri, 10 Feb 2023 03:42:47 +0000 Subject: [PATCH] CodeGen from PR 22541 in Azure/azure-rest-api-specs Merge 200066b18054fd6751cf6ea089ac17f32033f537 into 33a7dbc1743fdacb8e2259011a035154a98cad66 --- .../commerce/armcommerce/CHANGELOG.md | 4 + .../commerce/armcommerce/autorest.md | 6 +- ...zz_generated_constants.go => constants.go} | 3 +- .../commerce/armcommerce/go.mod | 14 +- .../commerce/armcommerce/go.sum | 24 +- .../{zz_generated_models.go => models.go} | 3 +- .../commerce/armcommerce/models_serde.go | 525 ++++++++++++++++++ ...phic_helpers.go => polymorphic_helpers.go} | 3 +- ..._ratecard_client.go => ratecard_client.go} | 18 +- ...ed_response_types.go => response_types.go} | 3 +- ...erated_time_rfc3339.go => time_rfc3339.go} | 3 +- ...es_client.go => usageaggregates_client.go} | 18 +- ..._generated_example_ratecard_client_test.go | 38 -- .../armcommerce/zz_generated_models_serde.go | 263 --------- 14 files changed, 568 insertions(+), 357 deletions(-) rename sdk/resourcemanager/commerce/armcommerce/{zz_generated_constants.go => constants.go} (97%) rename sdk/resourcemanager/commerce/armcommerce/{zz_generated_models.go => models.go} (99%) create mode 100644 sdk/resourcemanager/commerce/armcommerce/models_serde.go rename sdk/resourcemanager/commerce/armcommerce/{zz_generated_polymorphic_helpers.go => polymorphic_helpers.go} (97%) rename sdk/resourcemanager/commerce/armcommerce/{zz_generated_ratecard_client.go => ratecard_client.go} (86%) rename sdk/resourcemanager/commerce/armcommerce/{zz_generated_response_types.go => response_types.go} (91%) rename sdk/resourcemanager/commerce/armcommerce/{zz_generated_time_rfc3339.go => time_rfc3339.go} (96%) rename sdk/resourcemanager/commerce/armcommerce/{zz_generated_usageaggregates_client.go => usageaggregates_client.go} (89%) delete mode 100644 sdk/resourcemanager/commerce/armcommerce/ze_generated_example_ratecard_client_test.go delete mode 100644 sdk/resourcemanager/commerce/armcommerce/zz_generated_models_serde.go diff --git a/sdk/resourcemanager/commerce/armcommerce/CHANGELOG.md b/sdk/resourcemanager/commerce/armcommerce/CHANGELOG.md index 653b0fb8f81b..fbdd1db28147 100644 --- a/sdk/resourcemanager/commerce/armcommerce/CHANGELOG.md +++ b/sdk/resourcemanager/commerce/armcommerce/CHANGELOG.md @@ -1,5 +1,9 @@ # Release History +## 0.1.1 (2023-02-10) +### Other Changes + + ## 0.1.0 (2022-06-10) The package of `github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/commerce/armcommerce` is using our [next generation design principles](https://azure.github.io/azure-sdk/general_introduction.html) since version 0.1.0, which contains breaking changes. diff --git a/sdk/resourcemanager/commerce/armcommerce/autorest.md b/sdk/resourcemanager/commerce/armcommerce/autorest.md index cd14bcd541e7..de9f7c80ce5b 100644 --- a/sdk/resourcemanager/commerce/armcommerce/autorest.md +++ b/sdk/resourcemanager/commerce/armcommerce/autorest.md @@ -5,9 +5,9 @@ ``` yaml azure-arm: true require: -- https://github.com/Azure/azure-rest-api-specs/blob/163e27c0ca7570bc39e00a46f255740d9b3ba3cb/specification/commerce/resource-manager/readme.md -- https://github.com/Azure/azure-rest-api-specs/blob/163e27c0ca7570bc39e00a46f255740d9b3ba3cb/specification/commerce/resource-manager/readme.go.md +- /mnt/vss/_work/1/s/azure-rest-api-specs/specification/commerce/resource-manager/readme.md +- /mnt/vss/_work/1/s/azure-rest-api-specs/specification/commerce/resource-manager/readme.go.md license-header: MICROSOFT_MIT_NO_VERSION -module-version: 0.1.0 +module-version: 0.1.1 ``` \ No newline at end of file diff --git a/sdk/resourcemanager/commerce/armcommerce/zz_generated_constants.go b/sdk/resourcemanager/commerce/armcommerce/constants.go similarity index 97% rename from sdk/resourcemanager/commerce/armcommerce/zz_generated_constants.go rename to sdk/resourcemanager/commerce/armcommerce/constants.go index e1f35c39754c..355a4b1e1a5b 100644 --- a/sdk/resourcemanager/commerce/armcommerce/zz_generated_constants.go +++ b/sdk/resourcemanager/commerce/armcommerce/constants.go @@ -5,12 +5,13 @@ // Licensed under the MIT License. See License.txt in the project root for license information. // Code generated by Microsoft (R) AutoRest Code Generator. // Changes may cause incorrect behavior and will be lost if the code is regenerated. +// DO NOT EDIT. package armcommerce const ( moduleName = "armcommerce" - moduleVersion = "v0.1.0" + moduleVersion = "v0.1.1" ) type AggregationGranularity string diff --git a/sdk/resourcemanager/commerce/armcommerce/go.mod b/sdk/resourcemanager/commerce/armcommerce/go.mod index 0bdae7ae92d7..94d6c1d1c183 100644 --- a/sdk/resourcemanager/commerce/armcommerce/go.mod +++ b/sdk/resourcemanager/commerce/armcommerce/go.mod @@ -2,20 +2,12 @@ module github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/commerce/armcommerc go 1.18 -require ( - github.com/Azure/azure-sdk-for-go/sdk/azcore v1.0.0 - github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.1.0 -) +require github.com/Azure/azure-sdk-for-go/sdk/azcore v1.0.0 require ( github.com/Azure/azure-sdk-for-go/sdk/internal v1.0.0 // indirect - github.com/AzureAD/microsoft-authentication-library-for-go v0.5.1 // indirect - github.com/golang-jwt/jwt v3.2.1+incompatible // indirect - github.com/google/uuid v1.1.1 // indirect - github.com/kylelemons/godebug v1.1.0 // indirect - github.com/pkg/browser v0.0.0-20210115035449-ce105d075bb4 // indirect - golang.org/x/crypto v0.0.0-20220511200225-c6db032c6c88 // indirect + github.com/davecgh/go-spew v1.1.1 // indirect golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4 // indirect - golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e // indirect golang.org/x/text v0.3.7 // indirect + gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect ) diff --git a/sdk/resourcemanager/commerce/armcommerce/go.sum b/sdk/resourcemanager/commerce/armcommerce/go.sum index 8828b17b1853..3afb578030a5 100644 --- a/sdk/resourcemanager/commerce/armcommerce/go.sum +++ b/sdk/resourcemanager/commerce/armcommerce/go.sum @@ -1,33 +1,15 @@ github.com/Azure/azure-sdk-for-go/sdk/azcore v1.0.0 h1:sVPhtT2qjO86rTUaWMr4WoES4TkjGnzcioXcnHV9s5k= github.com/Azure/azure-sdk-for-go/sdk/azcore v1.0.0/go.mod h1:uGG2W01BaETf0Ozp+QxxKJdMBNRWPdstHG0Fmdwn1/U= -github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.1.0 h1:QkAcEIAKbNL4KoFr4SathZPhDhF4mVwpBMFlYjyAqy8= -github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.1.0/go.mod h1:bhXu1AjYL+wutSL/kpSq6s7733q2Rb0yuot9Zgfqa/0= github.com/Azure/azure-sdk-for-go/sdk/internal v1.0.0 h1:jp0dGvZ7ZK0mgqnTSClMxa5xuRL7NZgHameVYF6BurY= github.com/Azure/azure-sdk-for-go/sdk/internal v1.0.0/go.mod h1:eWRD7oawr1Mu1sLCawqVc0CUiF43ia3qQMxLscsKQ9w= -github.com/AzureAD/microsoft-authentication-library-for-go v0.5.1 h1:BWe8a+f/t+7KY7zH2mqygeUD0t8hNFXe08p1Pb3/jKE= -github.com/AzureAD/microsoft-authentication-library-for-go v0.5.1/go.mod h1:Vt9sXTKwMyGcOxSmLDMnGPgqsUg7m8pe215qMLrDXw4= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= -github.com/dnaeon/go-vcr v1.1.0 h1:ReYa/UBrRyQdant9B4fNHGoCNKw6qh6P0fsdGmZpR7c= -github.com/golang-jwt/jwt v3.2.1+incompatible h1:73Z+4BJcrTC+KczS6WvTPvRGOp1WmfEP4Q1lOd9Z/+c= -github.com/golang-jwt/jwt v3.2.1+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I= -github.com/golang-jwt/jwt/v4 v4.2.0 h1:besgBTC8w8HjP6NzQdxwKH9Z5oQMZ24ThTrHp3cZ8eU= -github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY= -github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= -github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= -github.com/montanaflynn/stats v0.6.6/go.mod h1:etXPPgVO6n31NxCd9KQUMvCM+ve0ruNzt6R8Bnaayow= -github.com/pkg/browser v0.0.0-20210115035449-ce105d075bb4 h1:Qj1ukM4GlMWXNdMBuXcXfz/Kw9s1qm0CLY32QxuSImI= -github.com/pkg/browser v0.0.0-20210115035449-ce105d075bb4/go.mod h1:N6UoU20jOqggOuDwUaBQpluzLNDqif3kq9z2wpdYEfQ= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= -golang.org/x/crypto v0.0.0-20220511200225-c6db032c6c88 h1:Tgea0cVUD0ivh5ADBX4WwuI12DUd2to3nCYe2eayMIw= -golang.org/x/crypto v0.0.0-20220511200225-c6db032c6c88/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4 h1:HVyaeDAYux4pnY+D/SiwmLOR36ewZ4iGQIIrtnuCjFA= golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= -golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e h1:fLOSk5Q00efkSvAm+4xcoXD+RRmLmmulPn5I3Y9F2EM= -golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= -gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo= +gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/sdk/resourcemanager/commerce/armcommerce/zz_generated_models.go b/sdk/resourcemanager/commerce/armcommerce/models.go similarity index 99% rename from sdk/resourcemanager/commerce/armcommerce/zz_generated_models.go rename to sdk/resourcemanager/commerce/armcommerce/models.go index 80358ce193d8..8afab235ecc7 100644 --- a/sdk/resourcemanager/commerce/armcommerce/zz_generated_models.go +++ b/sdk/resourcemanager/commerce/armcommerce/models.go @@ -5,6 +5,7 @@ // Licensed under the MIT License. See License.txt in the project root for license information. // Code generated by Microsoft (R) AutoRest Code Generator. // Changes may cause incorrect behavior and will be lost if the code is regenerated. +// DO NOT EDIT. package armcommerce @@ -190,7 +191,7 @@ type ResourceRateCardInfo struct { OfferTerms []OfferTermInfoAutoGeneratedClassification `json:"OfferTerms,omitempty"` } -// UsageAggregatesClientListOptions contains the optional parameters for the UsageAggregatesClient.List method. +// UsageAggregatesClientListOptions contains the optional parameters for the UsageAggregatesClient.NewListPager method. type UsageAggregatesClientListOptions struct { // Daily (default) returns the data in daily granularity, Hourly returns the data in hourly granularity. AggregationGranularity *AggregationGranularity diff --git a/sdk/resourcemanager/commerce/armcommerce/models_serde.go b/sdk/resourcemanager/commerce/armcommerce/models_serde.go new file mode 100644 index 000000000000..c4c1a85465c7 --- /dev/null +++ b/sdk/resourcemanager/commerce/armcommerce/models_serde.go @@ -0,0 +1,525 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. +// DO NOT EDIT. + +package armcommerce + +import ( + "encoding/json" + "fmt" + "github.com/Azure/azure-sdk-for-go/sdk/azcore" + "reflect" +) + +// MarshalJSON implements the json.Marshaller interface for type ErrorResponse. +func (e ErrorResponse) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "code", e.Code) + populate(objectMap, "message", e.Message) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type ErrorResponse. +func (e *ErrorResponse) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", e, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "code": + err = unpopulate(val, "Code", &e.Code) + delete(rawMsg, key) + case "message": + err = unpopulate(val, "Message", &e.Message) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", e, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type InfoField. +func (i InfoField) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "project", i.Project) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type InfoField. +func (i *InfoField) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", i, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "project": + err = unpopulate(val, "Project", &i.Project) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", i, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type MeterInfo. +func (m MeterInfo) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populateTimeRFC3339(objectMap, "EffectiveDate", m.EffectiveDate) + populate(objectMap, "IncludedQuantity", m.IncludedQuantity) + populate(objectMap, "MeterCategory", m.MeterCategory) + populate(objectMap, "MeterId", m.MeterID) + populate(objectMap, "MeterName", m.MeterName) + populate(objectMap, "MeterRates", m.MeterRates) + populate(objectMap, "MeterRegion", m.MeterRegion) + populate(objectMap, "MeterSubCategory", m.MeterSubCategory) + populate(objectMap, "MeterTags", m.MeterTags) + populate(objectMap, "Unit", m.Unit) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type MeterInfo. +func (m *MeterInfo) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", m, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "EffectiveDate": + err = unpopulateTimeRFC3339(val, "EffectiveDate", &m.EffectiveDate) + delete(rawMsg, key) + case "IncludedQuantity": + err = unpopulate(val, "IncludedQuantity", &m.IncludedQuantity) + delete(rawMsg, key) + case "MeterCategory": + err = unpopulate(val, "MeterCategory", &m.MeterCategory) + delete(rawMsg, key) + case "MeterId": + err = unpopulate(val, "MeterID", &m.MeterID) + delete(rawMsg, key) + case "MeterName": + err = unpopulate(val, "MeterName", &m.MeterName) + delete(rawMsg, key) + case "MeterRates": + err = unpopulate(val, "MeterRates", &m.MeterRates) + delete(rawMsg, key) + case "MeterRegion": + err = unpopulate(val, "MeterRegion", &m.MeterRegion) + delete(rawMsg, key) + case "MeterSubCategory": + err = unpopulate(val, "MeterSubCategory", &m.MeterSubCategory) + delete(rawMsg, key) + case "MeterTags": + err = unpopulate(val, "MeterTags", &m.MeterTags) + delete(rawMsg, key) + case "Unit": + err = unpopulate(val, "Unit", &m.Unit) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", m, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type MonetaryCommitment. +func (m MonetaryCommitment) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populateTimeRFC3339(objectMap, "EffectiveDate", m.EffectiveDate) + populate(objectMap, "ExcludedMeterIds", m.ExcludedMeterIDs) + objectMap["Name"] = OfferTermInfoMonetaryCommitment + populate(objectMap, "TieredDiscount", m.TieredDiscount) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type MonetaryCommitment. +func (m *MonetaryCommitment) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", m, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "EffectiveDate": + err = unpopulateTimeRFC3339(val, "EffectiveDate", &m.EffectiveDate) + delete(rawMsg, key) + case "ExcludedMeterIds": + err = unpopulate(val, "ExcludedMeterIDs", &m.ExcludedMeterIDs) + delete(rawMsg, key) + case "Name": + err = unpopulate(val, "Name", &m.Name) + delete(rawMsg, key) + case "TieredDiscount": + err = unpopulate(val, "TieredDiscount", &m.TieredDiscount) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", m, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type MonetaryCredit. +func (m MonetaryCredit) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "Credit", m.Credit) + populateTimeRFC3339(objectMap, "EffectiveDate", m.EffectiveDate) + populate(objectMap, "ExcludedMeterIds", m.ExcludedMeterIDs) + objectMap["Name"] = OfferTermInfoMonetaryCredit + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type MonetaryCredit. +func (m *MonetaryCredit) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", m, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "Credit": + err = unpopulate(val, "Credit", &m.Credit) + delete(rawMsg, key) + case "EffectiveDate": + err = unpopulateTimeRFC3339(val, "EffectiveDate", &m.EffectiveDate) + delete(rawMsg, key) + case "ExcludedMeterIds": + err = unpopulate(val, "ExcludedMeterIDs", &m.ExcludedMeterIDs) + delete(rawMsg, key) + case "Name": + err = unpopulate(val, "Name", &m.Name) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", m, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type OfferTermInfoAutoGenerated. +func (o OfferTermInfoAutoGenerated) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populateTimeRFC3339(objectMap, "EffectiveDate", o.EffectiveDate) + objectMap["Name"] = o.Name + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type OfferTermInfoAutoGenerated. +func (o *OfferTermInfoAutoGenerated) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", o, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "EffectiveDate": + err = unpopulateTimeRFC3339(val, "EffectiveDate", &o.EffectiveDate) + delete(rawMsg, key) + case "Name": + err = unpopulate(val, "Name", &o.Name) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", o, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type RateCardQueryParameters. +func (r RateCardQueryParameters) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "Currency", r.Currency) + populate(objectMap, "Locale", r.Locale) + populate(objectMap, "OfferDurableId", r.OfferDurableID) + populate(objectMap, "RegionInfo", r.RegionInfo) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type RateCardQueryParameters. +func (r *RateCardQueryParameters) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", r, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "Currency": + err = unpopulate(val, "Currency", &r.Currency) + delete(rawMsg, key) + case "Locale": + err = unpopulate(val, "Locale", &r.Locale) + delete(rawMsg, key) + case "OfferDurableId": + err = unpopulate(val, "OfferDurableID", &r.OfferDurableID) + delete(rawMsg, key) + case "RegionInfo": + err = unpopulate(val, "RegionInfo", &r.RegionInfo) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", r, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type RecurringCharge. +func (r RecurringCharge) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populateTimeRFC3339(objectMap, "EffectiveDate", r.EffectiveDate) + objectMap["Name"] = OfferTermInfoRecurringCharge + populate(objectMap, "RecurringCharge", r.RecurringCharge) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type RecurringCharge. +func (r *RecurringCharge) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", r, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "EffectiveDate": + err = unpopulateTimeRFC3339(val, "EffectiveDate", &r.EffectiveDate) + delete(rawMsg, key) + case "Name": + err = unpopulate(val, "Name", &r.Name) + delete(rawMsg, key) + case "RecurringCharge": + err = unpopulate(val, "RecurringCharge", &r.RecurringCharge) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", r, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type ResourceRateCardInfo. +func (r ResourceRateCardInfo) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "Currency", r.Currency) + populate(objectMap, "IsTaxIncluded", r.IsTaxIncluded) + populate(objectMap, "Locale", r.Locale) + populate(objectMap, "Meters", r.Meters) + populate(objectMap, "OfferTerms", r.OfferTerms) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type ResourceRateCardInfo. +func (r *ResourceRateCardInfo) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", r, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "Currency": + err = unpopulate(val, "Currency", &r.Currency) + delete(rawMsg, key) + case "IsTaxIncluded": + err = unpopulate(val, "IsTaxIncluded", &r.IsTaxIncluded) + delete(rawMsg, key) + case "Locale": + err = unpopulate(val, "Locale", &r.Locale) + delete(rawMsg, key) + case "Meters": + err = unpopulate(val, "Meters", &r.Meters) + delete(rawMsg, key) + case "OfferTerms": + r.OfferTerms, err = unmarshalOfferTermInfoAutoGeneratedClassificationArray(val) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", r, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type UsageAggregation. +func (u UsageAggregation) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "id", u.ID) + populate(objectMap, "name", u.Name) + populate(objectMap, "properties", u.Properties) + populate(objectMap, "type", u.Type) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type UsageAggregation. +func (u *UsageAggregation) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", u, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "id": + err = unpopulate(val, "ID", &u.ID) + delete(rawMsg, key) + case "name": + err = unpopulate(val, "Name", &u.Name) + delete(rawMsg, key) + case "properties": + err = unpopulate(val, "Properties", &u.Properties) + delete(rawMsg, key) + case "type": + err = unpopulate(val, "Type", &u.Type) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", u, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type UsageAggregationListResult. +func (u UsageAggregationListResult) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "nextLink", u.NextLink) + populate(objectMap, "value", u.Value) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type UsageAggregationListResult. +func (u *UsageAggregationListResult) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", u, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "nextLink": + err = unpopulate(val, "NextLink", &u.NextLink) + delete(rawMsg, key) + case "value": + err = unpopulate(val, "Value", &u.Value) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", u, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type UsageSample. +func (u UsageSample) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "infoFields", u.InfoFields) + populate(objectMap, "instanceData", u.InstanceData) + populate(objectMap, "meterCategory", u.MeterCategory) + populate(objectMap, "meterId", u.MeterID) + populate(objectMap, "meterName", u.MeterName) + populate(objectMap, "meterRegion", u.MeterRegion) + populate(objectMap, "meterSubCategory", u.MeterSubCategory) + populate(objectMap, "quantity", u.Quantity) + populate(objectMap, "subscriptionId", u.SubscriptionID) + populate(objectMap, "unit", u.Unit) + populateTimeRFC3339(objectMap, "usageEndTime", u.UsageEndTime) + populateTimeRFC3339(objectMap, "usageStartTime", u.UsageStartTime) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type UsageSample. +func (u *UsageSample) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", u, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "infoFields": + err = unpopulate(val, "InfoFields", &u.InfoFields) + delete(rawMsg, key) + case "instanceData": + err = unpopulate(val, "InstanceData", &u.InstanceData) + delete(rawMsg, key) + case "meterCategory": + err = unpopulate(val, "MeterCategory", &u.MeterCategory) + delete(rawMsg, key) + case "meterId": + err = unpopulate(val, "MeterID", &u.MeterID) + delete(rawMsg, key) + case "meterName": + err = unpopulate(val, "MeterName", &u.MeterName) + delete(rawMsg, key) + case "meterRegion": + err = unpopulate(val, "MeterRegion", &u.MeterRegion) + delete(rawMsg, key) + case "meterSubCategory": + err = unpopulate(val, "MeterSubCategory", &u.MeterSubCategory) + delete(rawMsg, key) + case "quantity": + err = unpopulate(val, "Quantity", &u.Quantity) + delete(rawMsg, key) + case "subscriptionId": + err = unpopulate(val, "SubscriptionID", &u.SubscriptionID) + delete(rawMsg, key) + case "unit": + err = unpopulate(val, "Unit", &u.Unit) + delete(rawMsg, key) + case "usageEndTime": + err = unpopulateTimeRFC3339(val, "UsageEndTime", &u.UsageEndTime) + delete(rawMsg, key) + case "usageStartTime": + err = unpopulateTimeRFC3339(val, "UsageStartTime", &u.UsageStartTime) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", u, err) + } + } + return nil +} + +func populate(m map[string]any, k string, v any) { + if v == nil { + return + } else if azcore.IsNullValue(v) { + m[k] = nil + } else if !reflect.ValueOf(v).IsNil() { + m[k] = v + } +} + +func unpopulate(data json.RawMessage, fn string, v any) error { + if data == nil { + return nil + } + if err := json.Unmarshal(data, v); err != nil { + return fmt.Errorf("struct field %s: %v", fn, err) + } + return nil +} diff --git a/sdk/resourcemanager/commerce/armcommerce/zz_generated_polymorphic_helpers.go b/sdk/resourcemanager/commerce/armcommerce/polymorphic_helpers.go similarity index 97% rename from sdk/resourcemanager/commerce/armcommerce/zz_generated_polymorphic_helpers.go rename to sdk/resourcemanager/commerce/armcommerce/polymorphic_helpers.go index 56ec2f130d98..90a20987874b 100644 --- a/sdk/resourcemanager/commerce/armcommerce/zz_generated_polymorphic_helpers.go +++ b/sdk/resourcemanager/commerce/armcommerce/polymorphic_helpers.go @@ -5,6 +5,7 @@ // Licensed under the MIT License. See License.txt in the project root for license information. // Code generated by Microsoft (R) AutoRest Code Generator. // Changes may cause incorrect behavior and will be lost if the code is regenerated. +// DO NOT EDIT. package armcommerce @@ -14,7 +15,7 @@ func unmarshalOfferTermInfoAutoGeneratedClassification(rawMsg json.RawMessage) ( if rawMsg == nil { return nil, nil } - var m map[string]interface{} + var m map[string]any if err := json.Unmarshal(rawMsg, &m); err != nil { return nil, err } diff --git a/sdk/resourcemanager/commerce/armcommerce/zz_generated_ratecard_client.go b/sdk/resourcemanager/commerce/armcommerce/ratecard_client.go similarity index 86% rename from sdk/resourcemanager/commerce/armcommerce/zz_generated_ratecard_client.go rename to sdk/resourcemanager/commerce/armcommerce/ratecard_client.go index 8e18e249940f..1fa8e0fcb96c 100644 --- a/sdk/resourcemanager/commerce/armcommerce/zz_generated_ratecard_client.go +++ b/sdk/resourcemanager/commerce/armcommerce/ratecard_client.go @@ -5,6 +5,7 @@ // Licensed under the MIT License. See License.txt in the project root for license information. // Code generated by Microsoft (R) AutoRest Code Generator. // Changes may cause incorrect behavior and will be lost if the code is regenerated. +// DO NOT EDIT. package armcommerce @@ -31,10 +32,10 @@ type RateCardClient struct { } // NewRateCardClient creates a new instance of RateCardClient with the specified values. -// subscriptionID - It uniquely identifies Microsoft Azure subscription. The subscription ID forms part of the URI for every -// service call. -// credential - used to authorize requests. Usually a credential from azidentity. -// options - pass nil to accept the default values. +// - subscriptionID - It uniquely identifies Microsoft Azure subscription. The subscription ID forms part of the URI for every +// service call. +// - credential - used to authorize requests. Usually a credential from azidentity. +// - options - pass nil to accept the default values. func NewRateCardClient(subscriptionID string, credential azcore.TokenCredential, options *arm.ClientOptions) (*RateCardClient, error) { if options == nil { options = &arm.ClientOptions{} @@ -63,11 +64,12 @@ func NewRateCardClient(subscriptionID string, credential azcore.TokenCredential, // to change due to a new billing model, you will be notified in advance of the // change. // If the operation fails it returns an *azcore.ResponseError type. +// // Generated from API version 2015-06-01-preview -// filter - The filter to apply on the operation. It ONLY supports the 'eq' and 'and' logical operators at this time. All -// the 4 query parameters 'OfferDurableId', 'Currency', 'Locale', 'Region' are required to be -// a part of the $filter. -// options - RateCardClientGetOptions contains the optional parameters for the RateCardClient.Get method. +// - filter - The filter to apply on the operation. It ONLY supports the 'eq' and 'and' logical operators at this time. All +// the 4 query parameters 'OfferDurableId', 'Currency', 'Locale', 'Region' are required to be +// a part of the $filter. +// - options - RateCardClientGetOptions contains the optional parameters for the RateCardClient.Get method. func (client *RateCardClient) Get(ctx context.Context, filter string, options *RateCardClientGetOptions) (RateCardClientGetResponse, error) { req, err := client.getCreateRequest(ctx, filter, options) if err != nil { diff --git a/sdk/resourcemanager/commerce/armcommerce/zz_generated_response_types.go b/sdk/resourcemanager/commerce/armcommerce/response_types.go similarity index 91% rename from sdk/resourcemanager/commerce/armcommerce/zz_generated_response_types.go rename to sdk/resourcemanager/commerce/armcommerce/response_types.go index cf88d9bade58..c7ead68605ae 100644 --- a/sdk/resourcemanager/commerce/armcommerce/zz_generated_response_types.go +++ b/sdk/resourcemanager/commerce/armcommerce/response_types.go @@ -5,6 +5,7 @@ // Licensed under the MIT License. See License.txt in the project root for license information. // Code generated by Microsoft (R) AutoRest Code Generator. // Changes may cause incorrect behavior and will be lost if the code is regenerated. +// DO NOT EDIT. package armcommerce @@ -13,7 +14,7 @@ type RateCardClientGetResponse struct { ResourceRateCardInfo } -// UsageAggregatesClientListResponse contains the response from method UsageAggregatesClient.List. +// UsageAggregatesClientListResponse contains the response from method UsageAggregatesClient.NewListPager. type UsageAggregatesClientListResponse struct { UsageAggregationListResult } diff --git a/sdk/resourcemanager/commerce/armcommerce/zz_generated_time_rfc3339.go b/sdk/resourcemanager/commerce/armcommerce/time_rfc3339.go similarity index 96% rename from sdk/resourcemanager/commerce/armcommerce/zz_generated_time_rfc3339.go rename to sdk/resourcemanager/commerce/armcommerce/time_rfc3339.go index 1e5619b704f7..a0a3c173ba59 100644 --- a/sdk/resourcemanager/commerce/armcommerce/zz_generated_time_rfc3339.go +++ b/sdk/resourcemanager/commerce/armcommerce/time_rfc3339.go @@ -5,6 +5,7 @@ // Licensed under the MIT License. See License.txt in the project root for license information. // Code generated by Microsoft (R) AutoRest Code Generator. // Changes may cause incorrect behavior and will be lost if the code is regenerated. +// DO NOT EDIT. package armcommerce @@ -61,7 +62,7 @@ func (t *timeRFC3339) Parse(layout, value string) error { return err } -func populateTimeRFC3339(m map[string]interface{}, k string, t *time.Time) { +func populateTimeRFC3339(m map[string]any, k string, t *time.Time) { if t == nil { return } else if azcore.IsNullValue(t) { diff --git a/sdk/resourcemanager/commerce/armcommerce/zz_generated_usageaggregates_client.go b/sdk/resourcemanager/commerce/armcommerce/usageaggregates_client.go similarity index 89% rename from sdk/resourcemanager/commerce/armcommerce/zz_generated_usageaggregates_client.go rename to sdk/resourcemanager/commerce/armcommerce/usageaggregates_client.go index 67b137e39594..6c308bc93f65 100644 --- a/sdk/resourcemanager/commerce/armcommerce/zz_generated_usageaggregates_client.go +++ b/sdk/resourcemanager/commerce/armcommerce/usageaggregates_client.go @@ -5,6 +5,7 @@ // Licensed under the MIT License. See License.txt in the project root for license information. // Code generated by Microsoft (R) AutoRest Code Generator. // Changes may cause incorrect behavior and will be lost if the code is regenerated. +// DO NOT EDIT. package armcommerce @@ -33,10 +34,10 @@ type UsageAggregatesClient struct { } // NewUsageAggregatesClient creates a new instance of UsageAggregatesClient with the specified values. -// subscriptionID - It uniquely identifies Microsoft Azure subscription. The subscription ID forms part of the URI for every -// service call. -// credential - used to authorize requests. Usually a credential from azidentity. -// options - pass nil to accept the default values. +// - subscriptionID - It uniquely identifies Microsoft Azure subscription. The subscription ID forms part of the URI for every +// service call. +// - credential - used to authorize requests. Usually a credential from azidentity. +// - options - pass nil to accept the default values. func NewUsageAggregatesClient(subscriptionID string, credential azcore.TokenCredential, options *arm.ClientOptions) (*UsageAggregatesClient, error) { if options == nil { options = &arm.ClientOptions{} @@ -58,11 +59,12 @@ func NewUsageAggregatesClient(subscriptionID string, credential azcore.TokenCred } // NewListPager - Query aggregated Azure subscription consumption data for a date range. -// If the operation fails it returns an *azcore.ResponseError type. +// // Generated from API version 2015-06-01-preview -// reportedStartTime - The start of the time range to retrieve data for. -// reportedEndTime - The end of the time range to retrieve data for. -// options - UsageAggregatesClientListOptions contains the optional parameters for the UsageAggregatesClient.List method. +// - reportedStartTime - The start of the time range to retrieve data for. +// - reportedEndTime - The end of the time range to retrieve data for. +// - options - UsageAggregatesClientListOptions contains the optional parameters for the UsageAggregatesClient.NewListPager +// method. func (client *UsageAggregatesClient) NewListPager(reportedStartTime time.Time, reportedEndTime time.Time, options *UsageAggregatesClientListOptions) *runtime.Pager[UsageAggregatesClientListResponse] { return runtime.NewPager(runtime.PagingHandler[UsageAggregatesClientListResponse]{ More: func(page UsageAggregatesClientListResponse) bool { diff --git a/sdk/resourcemanager/commerce/armcommerce/ze_generated_example_ratecard_client_test.go b/sdk/resourcemanager/commerce/armcommerce/ze_generated_example_ratecard_client_test.go deleted file mode 100644 index 8302810f4ab0..000000000000 --- a/sdk/resourcemanager/commerce/armcommerce/ze_generated_example_ratecard_client_test.go +++ /dev/null @@ -1,38 +0,0 @@ -//go:build go1.18 -// +build go1.18 - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See License.txt in the project root for license information. -// Code generated by Microsoft (R) AutoRest Code Generator. -// Changes may cause incorrect behavior and will be lost if the code is regenerated. - -package armcommerce_test - -import ( - "context" - "log" - - "github.com/Azure/azure-sdk-for-go/sdk/azidentity" - "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/commerce/armcommerce" -) - -// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/tree/main/specification/commerce/resource-manager/Microsoft.Commerce/preview/2015-06-01-preview/examples/GetRateCard.json -func ExampleRateCardClient_Get() { - cred, err := azidentity.NewDefaultAzureCredential(nil) - if err != nil { - log.Fatalf("failed to obtain a credential: %v", err) - } - ctx := context.Background() - client, err := armcommerce.NewRateCardClient("6d61cc05-8f8f-4916-b1b9-f1d9c25aae27", cred, nil) - if err != nil { - log.Fatalf("failed to create client: %v", err) - } - res, err := client.Get(ctx, - "OfferDurableId eq 'MS-AZR-0003P' and Currency eq 'USD' and Locale eq 'en-US' and RegionInfo eq 'US'", - nil) - if err != nil { - log.Fatalf("failed to finish the request: %v", err) - } - // TODO: use response item - _ = res -} diff --git a/sdk/resourcemanager/commerce/armcommerce/zz_generated_models_serde.go b/sdk/resourcemanager/commerce/armcommerce/zz_generated_models_serde.go deleted file mode 100644 index e673ac594aa3..000000000000 --- a/sdk/resourcemanager/commerce/armcommerce/zz_generated_models_serde.go +++ /dev/null @@ -1,263 +0,0 @@ -//go:build go1.18 -// +build go1.18 - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See License.txt in the project root for license information. -// Code generated by Microsoft (R) AutoRest Code Generator. -// Changes may cause incorrect behavior and will be lost if the code is regenerated. - -package armcommerce - -import ( - "encoding/json" - "fmt" -) - -// UnmarshalJSON implements the json.Unmarshaller interface for type MeterInfo. -func (m *MeterInfo) UnmarshalJSON(data []byte) error { - var rawMsg map[string]json.RawMessage - if err := json.Unmarshal(data, &rawMsg); err != nil { - return fmt.Errorf("unmarshalling type %T: %v", m, err) - } - for key, val := range rawMsg { - var err error - switch key { - case "EffectiveDate": - err = unpopulateTimeRFC3339(val, "EffectiveDate", &m.EffectiveDate) - delete(rawMsg, key) - case "IncludedQuantity": - err = unpopulate(val, "IncludedQuantity", &m.IncludedQuantity) - delete(rawMsg, key) - case "MeterCategory": - err = unpopulate(val, "MeterCategory", &m.MeterCategory) - delete(rawMsg, key) - case "MeterId": - err = unpopulate(val, "MeterID", &m.MeterID) - delete(rawMsg, key) - case "MeterName": - err = unpopulate(val, "MeterName", &m.MeterName) - delete(rawMsg, key) - case "MeterRates": - err = unpopulate(val, "MeterRates", &m.MeterRates) - delete(rawMsg, key) - case "MeterRegion": - err = unpopulate(val, "MeterRegion", &m.MeterRegion) - delete(rawMsg, key) - case "MeterSubCategory": - err = unpopulate(val, "MeterSubCategory", &m.MeterSubCategory) - delete(rawMsg, key) - case "MeterTags": - err = unpopulate(val, "MeterTags", &m.MeterTags) - delete(rawMsg, key) - case "Unit": - err = unpopulate(val, "Unit", &m.Unit) - delete(rawMsg, key) - } - if err != nil { - return fmt.Errorf("unmarshalling type %T: %v", m, err) - } - } - return nil -} - -// UnmarshalJSON implements the json.Unmarshaller interface for type MonetaryCommitment. -func (m *MonetaryCommitment) UnmarshalJSON(data []byte) error { - var rawMsg map[string]json.RawMessage - if err := json.Unmarshal(data, &rawMsg); err != nil { - return fmt.Errorf("unmarshalling type %T: %v", m, err) - } - for key, val := range rawMsg { - var err error - switch key { - case "EffectiveDate": - err = unpopulateTimeRFC3339(val, "EffectiveDate", &m.EffectiveDate) - delete(rawMsg, key) - case "ExcludedMeterIds": - err = unpopulate(val, "ExcludedMeterIDs", &m.ExcludedMeterIDs) - delete(rawMsg, key) - case "Name": - err = unpopulate(val, "Name", &m.Name) - delete(rawMsg, key) - case "TieredDiscount": - err = unpopulate(val, "TieredDiscount", &m.TieredDiscount) - delete(rawMsg, key) - } - if err != nil { - return fmt.Errorf("unmarshalling type %T: %v", m, err) - } - } - return nil -} - -// UnmarshalJSON implements the json.Unmarshaller interface for type MonetaryCredit. -func (m *MonetaryCredit) UnmarshalJSON(data []byte) error { - var rawMsg map[string]json.RawMessage - if err := json.Unmarshal(data, &rawMsg); err != nil { - return fmt.Errorf("unmarshalling type %T: %v", m, err) - } - for key, val := range rawMsg { - var err error - switch key { - case "Credit": - err = unpopulate(val, "Credit", &m.Credit) - delete(rawMsg, key) - case "EffectiveDate": - err = unpopulateTimeRFC3339(val, "EffectiveDate", &m.EffectiveDate) - delete(rawMsg, key) - case "ExcludedMeterIds": - err = unpopulate(val, "ExcludedMeterIDs", &m.ExcludedMeterIDs) - delete(rawMsg, key) - case "Name": - err = unpopulate(val, "Name", &m.Name) - delete(rawMsg, key) - } - if err != nil { - return fmt.Errorf("unmarshalling type %T: %v", m, err) - } - } - return nil -} - -// UnmarshalJSON implements the json.Unmarshaller interface for type OfferTermInfoAutoGenerated. -func (o *OfferTermInfoAutoGenerated) UnmarshalJSON(data []byte) error { - var rawMsg map[string]json.RawMessage - if err := json.Unmarshal(data, &rawMsg); err != nil { - return fmt.Errorf("unmarshalling type %T: %v", o, err) - } - for key, val := range rawMsg { - var err error - switch key { - case "EffectiveDate": - err = unpopulateTimeRFC3339(val, "EffectiveDate", &o.EffectiveDate) - delete(rawMsg, key) - case "Name": - err = unpopulate(val, "Name", &o.Name) - delete(rawMsg, key) - } - if err != nil { - return fmt.Errorf("unmarshalling type %T: %v", o, err) - } - } - return nil -} - -// UnmarshalJSON implements the json.Unmarshaller interface for type RecurringCharge. -func (r *RecurringCharge) UnmarshalJSON(data []byte) error { - var rawMsg map[string]json.RawMessage - if err := json.Unmarshal(data, &rawMsg); err != nil { - return fmt.Errorf("unmarshalling type %T: %v", r, err) - } - for key, val := range rawMsg { - var err error - switch key { - case "EffectiveDate": - err = unpopulateTimeRFC3339(val, "EffectiveDate", &r.EffectiveDate) - delete(rawMsg, key) - case "Name": - err = unpopulate(val, "Name", &r.Name) - delete(rawMsg, key) - case "RecurringCharge": - err = unpopulate(val, "RecurringCharge", &r.RecurringCharge) - delete(rawMsg, key) - } - if err != nil { - return fmt.Errorf("unmarshalling type %T: %v", r, err) - } - } - return nil -} - -// UnmarshalJSON implements the json.Unmarshaller interface for type ResourceRateCardInfo. -func (r *ResourceRateCardInfo) UnmarshalJSON(data []byte) error { - var rawMsg map[string]json.RawMessage - if err := json.Unmarshal(data, &rawMsg); err != nil { - return fmt.Errorf("unmarshalling type %T: %v", r, err) - } - for key, val := range rawMsg { - var err error - switch key { - case "Currency": - err = unpopulate(val, "Currency", &r.Currency) - delete(rawMsg, key) - case "IsTaxIncluded": - err = unpopulate(val, "IsTaxIncluded", &r.IsTaxIncluded) - delete(rawMsg, key) - case "Locale": - err = unpopulate(val, "Locale", &r.Locale) - delete(rawMsg, key) - case "Meters": - err = unpopulate(val, "Meters", &r.Meters) - delete(rawMsg, key) - case "OfferTerms": - r.OfferTerms, err = unmarshalOfferTermInfoAutoGeneratedClassificationArray(val) - delete(rawMsg, key) - } - if err != nil { - return fmt.Errorf("unmarshalling type %T: %v", r, err) - } - } - return nil -} - -// UnmarshalJSON implements the json.Unmarshaller interface for type UsageSample. -func (u *UsageSample) UnmarshalJSON(data []byte) error { - var rawMsg map[string]json.RawMessage - if err := json.Unmarshal(data, &rawMsg); err != nil { - return fmt.Errorf("unmarshalling type %T: %v", u, err) - } - for key, val := range rawMsg { - var err error - switch key { - case "infoFields": - err = unpopulate(val, "InfoFields", &u.InfoFields) - delete(rawMsg, key) - case "instanceData": - err = unpopulate(val, "InstanceData", &u.InstanceData) - delete(rawMsg, key) - case "meterCategory": - err = unpopulate(val, "MeterCategory", &u.MeterCategory) - delete(rawMsg, key) - case "meterId": - err = unpopulate(val, "MeterID", &u.MeterID) - delete(rawMsg, key) - case "meterName": - err = unpopulate(val, "MeterName", &u.MeterName) - delete(rawMsg, key) - case "meterRegion": - err = unpopulate(val, "MeterRegion", &u.MeterRegion) - delete(rawMsg, key) - case "meterSubCategory": - err = unpopulate(val, "MeterSubCategory", &u.MeterSubCategory) - delete(rawMsg, key) - case "quantity": - err = unpopulate(val, "Quantity", &u.Quantity) - delete(rawMsg, key) - case "subscriptionId": - err = unpopulate(val, "SubscriptionID", &u.SubscriptionID) - delete(rawMsg, key) - case "unit": - err = unpopulate(val, "Unit", &u.Unit) - delete(rawMsg, key) - case "usageEndTime": - err = unpopulateTimeRFC3339(val, "UsageEndTime", &u.UsageEndTime) - delete(rawMsg, key) - case "usageStartTime": - err = unpopulateTimeRFC3339(val, "UsageStartTime", &u.UsageStartTime) - delete(rawMsg, key) - } - if err != nil { - return fmt.Errorf("unmarshalling type %T: %v", u, err) - } - } - return nil -} - -func unpopulate(data json.RawMessage, fn string, v interface{}) error { - if data == nil { - return nil - } - if err := json.Unmarshal(data, v); err != nil { - return fmt.Errorf("struct field %s: %v", fn, err) - } - return nil -}