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)

206
types.go
View File

@ -122,41 +122,41 @@ Customer related types
// Customer type. // Customer type.
type Customer struct { type Customer struct {
ID int `json:"id,omitempty"` ID int `json:"id,omitempty"`
ExternalID string `json:"externalId,omitempty"` ExternalID string `json:"externalId,omitempty"`
FirstName string `json:"firstName,omitempty"` FirstName string `json:"firstName,omitempty"`
LastName string `json:"lastName,omitempty"` LastName string `json:"lastName,omitempty"`
Patronymic string `json:"patronymic,omitempty"` Patronymic string `json:"patronymic,omitempty"`
Sex string `json:"sex,omitempty"` Sex string `json:"sex,omitempty"`
Email string `json:"email,omitempty"` Email string `json:"email,omitempty"`
Phones []Phone `json:"phones,omitempty"` Phones []Phone `json:"phones,omitempty"`
Address *Address `json:"address,omitempty"` Address *Address `json:"address,omitempty"`
CreatedAt string `json:"createdAt,omitempty"` CreatedAt string `json:"createdAt,omitempty"`
Birthday string `json:"birthday,omitempty"` Birthday string `json:"birthday,omitempty"`
ManagerID int `json:"managerId,omitempty"` ManagerID int `json:"managerId,omitempty"`
Vip bool `json:"vip,omitempty"` Vip bool `json:"vip,omitempty"`
Bad bool `json:"bad,omitempty"` Bad bool `json:"bad,omitempty"`
Site string `json:"site,omitempty"` Site string `json:"site,omitempty"`
Source *Source `json:"source,omitempty"` Source *Source `json:"source,omitempty"`
Contragent *Contragent `json:"contragent,omitempty"` Contragent *Contragent `json:"contragent,omitempty"`
PersonalDiscount float32 `json:"personalDiscount,omitempty"` PersonalDiscount float32 `json:"personalDiscount,omitempty"`
CumulativeDiscount float32 `json:"cumulativeDiscount,omitempty"` CumulativeDiscount float32 `json:"cumulativeDiscount,omitempty"`
DiscountCardNumber string `json:"discountCardNumber,omitempty"` DiscountCardNumber string `json:"discountCardNumber,omitempty"`
EmailMarketingUnsubscribedAt string `json:"emailMarketingUnsubscribedAt,omitempty"` EmailMarketingUnsubscribedAt string `json:"emailMarketingUnsubscribedAt,omitempty"`
AvgMarginSumm float32 `json:"avgMarginSumm,omitempty"` AvgMarginSumm float32 `json:"avgMarginSumm,omitempty"`
MarginSumm float32 `json:"marginSumm,omitempty"` MarginSumm float32 `json:"marginSumm,omitempty"`
TotalSumm float32 `json:"totalSumm,omitempty"` TotalSumm float32 `json:"totalSumm,omitempty"`
AverageSumm float32 `json:"averageSumm,omitempty"` AverageSumm float32 `json:"averageSumm,omitempty"`
OrdersCount int `json:"ordersCount,omitempty"` OrdersCount int `json:"ordersCount,omitempty"`
CostSumm float32 `json:"costSumm,omitempty"` CostSumm float32 `json:"costSumm,omitempty"`
MaturationTime int `json:"maturationTime,omitempty"` MaturationTime int `json:"maturationTime,omitempty"`
FirstClientID string `json:"firstClientId,omitempty"` FirstClientID string `json:"firstClientId,omitempty"`
LastClientID string `json:"lastClientId,omitempty"` LastClientID string `json:"lastClientId,omitempty"`
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"`
} }
// CorporateCustomer type. // CorporateCustomer type.
@ -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"`
} }
@ -508,24 +508,24 @@ type PacksHistoryRecord struct {
// Offer type. // Offer type.
type Offer struct { type Offer struct {
ID int `json:"id,omitempty"` ID int `json:"id,omitempty"`
ExternalID string `json:"externalId,omitempty"` ExternalID string `json:"externalId,omitempty"`
Name string `json:"name,omitempty"` Name string `json:"name,omitempty"`
XMLID string `json:"xmlId,omitempty"` XMLID string `json:"xmlId,omitempty"`
Article string `json:"article,omitempty"` Article string `json:"article,omitempty"`
VatRate string `json:"vatRate,omitempty"` VatRate string `json:"vatRate,omitempty"`
Price float32 `json:"price,omitempty"` Price float32 `json:"price,omitempty"`
PurchasePrice float32 `json:"purchasePrice,omitempty"` PurchasePrice float32 `json:"purchasePrice,omitempty"`
Quantity float32 `json:"quantity,omitempty"` Quantity float32 `json:"quantity,omitempty"`
Height float32 `json:"height,omitempty"` Height float32 `json:"height,omitempty"`
Width float32 `json:"width,omitempty"` Width float32 `json:"width,omitempty"`
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"`
} }
// Inventory type. // Inventory type.
@ -913,25 +913,25 @@ type ProductGroup struct {
// Product type. // Product type.
type Product struct { type Product struct {
ID int `json:"id,omitempty"` ID int `json:"id,omitempty"`
MaxPrice float32 `json:"maxPrice,omitempty"` MaxPrice float32 `json:"maxPrice,omitempty"`
MinPrice float32 `json:"minPrice,omitempty"` MinPrice float32 `json:"minPrice,omitempty"`
Name string `json:"name,omitempty"` Name string `json:"name,omitempty"`
URL string `json:"url,omitempty"` URL string `json:"url,omitempty"`
Article string `json:"article,omitempty"` Article string `json:"article,omitempty"`
ExternalID string `json:"externalId,omitempty"` ExternalID string `json:"externalId,omitempty"`
Manufacturer string `json:"manufacturer,omitempty"` Manufacturer string `json:"manufacturer,omitempty"`
ImageURL string `json:"imageUrl,omitempty"` ImageURL string `json:"imageUrl,omitempty"`
Description string `json:"description,omitempty"` Description string `json:"description,omitempty"`
Popular bool `json:"popular,omitempty"` Popular bool `json:"popular,omitempty"`
Stock bool `json:"stock,omitempty"` Stock bool `json:"stock,omitempty"`
Novelty bool `json:"novelty,omitempty"` Novelty bool `json:"novelty,omitempty"`
Recommended bool `json:"recommended,omitempty"` Recommended bool `json:"recommended,omitempty"`
Active bool `json:"active,omitempty"` Active bool `json:"active,omitempty"`
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.
@ -943,36 +943,36 @@ type DeliveryHistoryRecord struct {
// DeliveryShipment type. // DeliveryShipment type.
type DeliveryShipment struct { type DeliveryShipment struct {
IntegrationCode string `json:"integrationCode,omitempty"` IntegrationCode string `json:"integrationCode,omitempty"`
ID int `json:"id,omitempty"` ID int `json:"id,omitempty"`
ExternalID string `json:"externalId,omitempty"` ExternalID string `json:"externalId,omitempty"`
DeliveryType string `json:"deliveryType,omitempty"` DeliveryType string `json:"deliveryType,omitempty"`
Store string `json:"store,omitempty"` Store string `json:"store,omitempty"`
ManagerID int `json:"managerId,omitempty"` ManagerID int `json:"managerId,omitempty"`
Status string `json:"status,omitempty"` Status string `json:"status,omitempty"`
Date string `json:"date,omitempty"` Date string `json:"date,omitempty"`
Time *DeliveryTime `json:"time,omitempty"` Time *DeliveryTime `json:"time,omitempty"`
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.
type IntegrationModule struct { type IntegrationModule struct {
Code string `json:"code,omitempty"` Code string `json:"code,omitempty"`
IntegrationCode string `json:"integrationCode,omitempty"` IntegrationCode string `json:"integrationCode,omitempty"`
Active bool `json:"active,omitempty"` Active bool `json:"active,omitempty"`
Freeze bool `json:"freeze,omitempty"` Freeze bool `json:"freeze,omitempty"`
Native bool `json:"native,omitempty"` Native bool `json:"native,omitempty"`
Name string `json:"name,omitempty"` Name string `json:"name,omitempty"`
Logo string `json:"logo,omitempty"` Logo string `json:"logo,omitempty"`
ClientID string `json:"clientId,omitempty"` ClientID string `json:"clientId,omitempty"`
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"`
} }
// Integrations type. // Integrations type.
@ -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"`