Fix incorrect marshaling for some string maps

This commit is contained in:
Alex Lushpai 2021-10-27 17:25:15 +03:00 committed by GitHub
commit e9b2a04a4a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 108 additions and 108 deletions

View File

@ -34,21 +34,21 @@ func (a *APIErrorsList) UnmarshalJSON(data []byte) error {
return nil return nil
} }
func (l *CustomFieldsList) UnmarshalJSON(data []byte) error { func (l *StringMap) UnmarshalJSON(data []byte) error {
var i interface{} var i interface{}
var m CustomFieldsList var m StringMap
if err := json.Unmarshal(data, &i); err != nil { if err := json.Unmarshal(data, &i); err != nil {
return err return err
} }
switch e := i.(type) { switch e := i.(type) {
case map[string]interface{}: case map[string]interface{}:
m = make(CustomFieldsList, len(e)) m = make(StringMap, len(e))
for idx, val := range e { for idx, val := range e {
m[idx] = fmt.Sprint(val) m[idx] = fmt.Sprint(val)
} }
case []interface{}: case []interface{}:
m = make(CustomFieldsList, len(e)) m = make(StringMap, len(e))
for idx, val := range e { for idx, val := range e {
m[strconv.Itoa(idx)] = fmt.Sprint(val) m[strconv.Itoa(idx)] = fmt.Sprint(val)
} }

View File

@ -41,7 +41,7 @@ func TestAPIErrorsList_UnmarshalJSON(t *testing.T) {
} }
func TestCustomFieldsList_UnmarshalJSON(t *testing.T) { func TestCustomFieldsList_UnmarshalJSON(t *testing.T) {
var list CustomFieldsList var list StringMap
require.NoError(t, json.Unmarshal([]byte(`["first", "second"]`), &list)) require.NoError(t, json.Unmarshal([]byte(`["first", "second"]`), &list))
assert.Len(t, list, 2) assert.Len(t, list, 2)

View File

@ -155,7 +155,7 @@ type Customer struct {
BrowserID string `json:"browserId,omitempty"` BrowserID string `json:"browserId,omitempty"`
MgCustomerID string `json:"mgCustomerId,omitempty"` MgCustomerID string `json:"mgCustomerId,omitempty"`
PhotoURL string `json:"photoUrl,omitempty"` PhotoURL string `json:"photoUrl,omitempty"`
CustomFields CustomFieldsList `json:"customFields,omitempty"` CustomFields StringMap `json:"customFields,omitempty"`
Tags []Tag `json:"tags,omitempty"` Tags []Tag `json:"tags,omitempty"`
} }
@ -167,7 +167,7 @@ type CorporateCustomer struct {
CreatedAt string `json:"createdAt,omitempty"` CreatedAt string `json:"createdAt,omitempty"`
Vip bool `json:"vip,omitempty"` Vip bool `json:"vip,omitempty"`
Bad bool `json:"bad,omitempty"` Bad bool `json:"bad,omitempty"`
CustomFields CustomFieldsList `json:"customFields,omitempty"` CustomFields StringMap `json:"customFields,omitempty"`
PersonalDiscount float32 `json:"personalDiscount,omitempty"` PersonalDiscount float32 `json:"personalDiscount,omitempty"`
DiscountCardNumber string `json:"discountCardNumber,omitempty"` DiscountCardNumber string `json:"discountCardNumber,omitempty"`
ManagerID int `json:"managerId,omitempty"` ManagerID int `json:"managerId,omitempty"`
@ -228,7 +228,7 @@ type Company struct {
CreatedAt string `json:"createdAt,omitempty"` CreatedAt string `json:"createdAt,omitempty"`
Contragent *Contragent `json:"contragent,omitempty"` Contragent *Contragent `json:"contragent,omitempty"`
Address *IdentifiersPair `json:"address,omitempty"` Address *IdentifiersPair `json:"address,omitempty"`
CustomFields CustomFieldsList `json:"customFields,omitempty"` CustomFields StringMap `json:"customFields,omitempty"`
} }
// CorporateCustomerNote type. // CorporateCustomerNote type.
@ -274,7 +274,7 @@ Order related types
*/ */
type OrderPayments map[string]OrderPayment type OrderPayments map[string]OrderPayment
type CustomFieldsList map[string]string type StringMap map[string]string
// Order type. // Order type.
type Order struct { type Order struct {
@ -325,7 +325,7 @@ type Order struct {
Delivery *OrderDelivery `json:"delivery,omitempty"` Delivery *OrderDelivery `json:"delivery,omitempty"`
Marketplace *OrderMarketplace `json:"marketplace,omitempty"` Marketplace *OrderMarketplace `json:"marketplace,omitempty"`
Items []OrderItem `json:"items,omitempty"` Items []OrderItem `json:"items,omitempty"`
CustomFields CustomFieldsList `json:"customFields,omitempty"` CustomFields StringMap `json:"customFields,omitempty"`
Payments OrderPayments `json:"payments,omitempty"` Payments OrderPayments `json:"payments,omitempty"`
} }
@ -522,7 +522,7 @@ type Offer struct {
Length float32 `json:"length,omitempty"` Length float32 `json:"length,omitempty"`
Weight float32 `json:"weight,omitempty"` Weight float32 `json:"weight,omitempty"`
Stores []Inventory `json:"stores,omitempty"` Stores []Inventory `json:"stores,omitempty"`
Properties map[string]string `json:"properties,omitempty"` Properties StringMap `json:"properties,omitempty"`
Prices []OfferPrice `json:"prices,omitempty"` Prices []OfferPrice `json:"prices,omitempty"`
Images []string `json:"images,omitempty"` Images []string `json:"images,omitempty"`
Unit *Unit `json:"unit,omitempty"` Unit *Unit `json:"unit,omitempty"`
@ -931,7 +931,7 @@ type Product struct {
Quantity float32 `json:"quantity,omitempty"` Quantity float32 `json:"quantity,omitempty"`
Offers []Offer `json:"offers,omitempty"` Offers []Offer `json:"offers,omitempty"`
Groups []ProductGroup `json:"groups,omitempty"` Groups []ProductGroup `json:"groups,omitempty"`
Properties map[string]string `json:"properties,omitempty"` Properties StringMap `json:"properties,omitempty"`
} }
// DeliveryHistoryRecord type. // DeliveryHistoryRecord type.
@ -955,7 +955,7 @@ type DeliveryShipment struct {
LunchTime string `json:"lunchTime,omitempty"` LunchTime string `json:"lunchTime,omitempty"`
Comment string `json:"comment,omitempty"` Comment string `json:"comment,omitempty"`
Orders []Order `json:"orders,omitempty"` Orders []Order `json:"orders,omitempty"`
ExtraData map[string]string `json:"extraData,omitempty"` ExtraData StringMap `json:"extraData,omitempty"`
} }
// IntegrationModule type. // IntegrationModule type.
@ -971,7 +971,7 @@ type IntegrationModule struct {
BaseURL string `json:"baseUrl,omitempty"` BaseURL string `json:"baseUrl,omitempty"`
AccountURL string `json:"accountUrl,omitempty"` AccountURL string `json:"accountUrl,omitempty"`
AvailableCountries []string `json:"availableCountries,omitempty"` AvailableCountries []string `json:"availableCountries,omitempty"`
Actions map[string]string `json:"actions,omitempty"` Actions StringMap `json:"actions,omitempty"`
Integrations *Integrations `json:"integrations,omitempty"` Integrations *Integrations `json:"integrations,omitempty"`
} }
@ -987,7 +987,7 @@ type Integrations struct {
// Delivery type. // Delivery type.
type Delivery struct { type Delivery struct {
Description string `json:"description,omitempty"` Description string `json:"description,omitempty"`
Actions map[string]string `json:"actions,omitempty"` Actions StringMap `json:"actions,omitempty"`
PayerType []string `json:"payerType,omitempty"` PayerType []string `json:"payerType,omitempty"`
PlatePrintLimit int `json:"platePrintLimit,omitempty"` PlatePrintLimit int `json:"platePrintLimit,omitempty"`
RateDeliveryCost bool `json:"rateDeliveryCost,omitempty"` RateDeliveryCost bool `json:"rateDeliveryCost,omitempty"`