Skip to content

Commit 88de618

Browse files
authored
[WIRE-717] Fix unknown fields serialization issue (#174)
1 parent fb9f403 commit 88de618

File tree

9 files changed

+70
-19
lines changed

9 files changed

+70
-19
lines changed

.licenses/go/github.com/arduino/iot-client-go/v3.dep.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
name: github.com/arduino/iot-client-go/v3
3-
version: v3.0.1
3+
version: v3.1.1
44
type: go
55
summary:
66
homepage: https://pkg.go.dev/github.com/arduino/iot-client-go/v3

.licenses/go/golang.org/x/oauth2.dep.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
name: golang.org/x/oauth2
3-
version: v0.23.0
3+
version: v0.25.0
44
type: go
55
summary: Package oauth2 provides support for making OAuth2 authorized and authenticated
66
HTTP requests, as specified in RFC 6749.

.licenses/go/golang.org/x/oauth2/clientcredentials.dep.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
---
22
name: golang.org/x/oauth2/clientcredentials
3-
version: v0.23.0
3+
version: v0.25.0
44
type: go
55
summary: Package clientcredentials implements the OAuth2.0 "client credentials" token
66
flow, also known as the "two-legged OAuth 2.0".
77
homepage: https://pkg.go.dev/golang.org/x/oauth2/clientcredentials
88
license: bsd-3-clause
99
licenses:
10-
- sources: oauth2@v0.23.0/LICENSE
10+
- sources: oauth2@v0.25.0/LICENSE
1111
text: |
1212
Copyright 2009 The Go Authors.
1313

.licenses/go/golang.org/x/oauth2/internal.dep.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
---
22
name: golang.org/x/oauth2/internal
3-
version: v0.23.0
3+
version: v0.25.0
44
type: go
55
summary: Package internal contains support packages for oauth2 package.
66
homepage: https://pkg.go.dev/golang.org/x/oauth2/internal
77
license: bsd-3-clause
88
licenses:
9-
- sources: oauth2@v0.23.0/LICENSE
9+
- sources: oauth2@v0.25.0/LICENSE
1010
text: |
1111
Copyright 2009 The Go Authors.
1212

command/device/show.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,12 @@ func Show(ctx context.Context, deviceId string, cred *config.Credentials) (*Devi
5858
return nil, net, err
5959
}
6060
for _, netCred := range netCredentialsArray {
61-
net = append(net, netCredentials(netCred))
61+
var netCredToShow netCredentials
62+
netCredToShow.FriendlyName = netCred.FriendlyName
63+
netCredToShow.Required = netCred.Required
64+
netCredToShow.SecretName = netCred.SecretName
65+
netCredToShow.Sensitive = netCred.Sensitive
66+
net = append(net, netCredToShow)
6267
}
6368
}
6469

go.mod

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ require (
66
github.com/arduino/arduino-cli v0.0.0-20240927141754-d9dd4ba1ed71
77
github.com/arduino/go-paths-helper v1.12.1
88
github.com/arduino/go-win32-utils v1.0.0
9-
github.com/arduino/iot-client-go/v3 v3.0.1
9+
github.com/arduino/iot-client-go/v3 v3.1.1
1010
github.com/gofrs/uuid v4.2.0+incompatible
1111
github.com/google/go-cmp v0.6.0
1212
github.com/howeyc/crc16 v0.0.0-20171223171357-2b2a61e366a6
@@ -19,7 +19,7 @@ require (
1919
go.bug.st/cleanup v1.0.0
2020
go.bug.st/serial v1.6.2
2121
golang.org/x/crypto v0.18.0
22-
golang.org/x/oauth2 v0.23.0
22+
golang.org/x/oauth2 v0.25.0
2323
google.golang.org/grpc v1.61.0
2424
gopkg.in/yaml.v3 v3.0.1
2525
gotest.tools v2.2.0+incompatible

go.sum

+4-4
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ github.com/arduino/go-properties-orderedmap v1.7.1 h1:HQ9Pn/mk3+XyfrE39EEvaZwJkr
7171
github.com/arduino/go-properties-orderedmap v1.7.1/go.mod h1:DKjD2VXY/NZmlingh4lSFMEYCVubfeArCsGPGDwb2yk=
7272
github.com/arduino/go-win32-utils v1.0.0 h1:/cXB86sOJxOsCHP7sQmXGLkdValwJt56mIwOHYxgQjQ=
7373
github.com/arduino/go-win32-utils v1.0.0/go.mod h1:0jqM7doGEAs6DaJCxxhLBUDS5OawrqF48HqXkcEie/Q=
74-
github.com/arduino/iot-client-go/v3 v3.0.1 h1:AwkctEtP7ilVXBOF2yZPJZpjpuUmKNGr/OdYxPx/4QQ=
75-
github.com/arduino/iot-client-go/v3 v3.0.1/go.mod h1:r2QEAP5Jalkr0YWNPhFl0EJzFRQNy24wN5CVbn11f64=
74+
github.com/arduino/iot-client-go/v3 v3.1.1 h1:bQhbV5PlH8tDuSmeimw9Rjrh5KbIUhqvYWWI/xYMi1M=
75+
github.com/arduino/iot-client-go/v3 v3.1.1/go.mod h1:r2QEAP5Jalkr0YWNPhFl0EJzFRQNy24wN5CVbn11f64=
7676
github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o=
7777
github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY=
7878
github.com/armon/go-metrics v0.3.10/go.mod h1:4O98XIr/9W0sxpJ8UaYkvjk10Iff7SnFrb4QAOwNTFc=
@@ -582,8 +582,8 @@ golang.org/x/oauth2 v0.0.0-20210805134026-6f1e6394065a/go.mod h1:KelEdhl1UZF7XfJ
582582
golang.org/x/oauth2 v0.0.0-20210819190943-2bc19b11175f/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A=
583583
golang.org/x/oauth2 v0.0.0-20211005180243-6b3c2da341f1/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A=
584584
golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A=
585-
golang.org/x/oauth2 v0.23.0 h1:PbgcYx2W7i4LvjJWEbf0ngHV6qJYr86PkAV3bXdLEbs=
586-
golang.org/x/oauth2 v0.23.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=
585+
golang.org/x/oauth2 v0.25.0 h1:CY4y7XT9v0cRI9oupztF8AgiIu99L/ksR/Xp/6jrZ70=
586+
golang.org/x/oauth2 v0.25.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=
587587
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
588588
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
589589
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=

internal/iot/client_test.go

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package iot
2+
3+
import (
4+
"testing"
5+
6+
iotclient "github.com/arduino/iot-client-go/v3"
7+
"github.com/stretchr/testify/assert"
8+
)
9+
10+
func TestJSON_UnknownFields_areAccepted(t *testing.T) {
11+
12+
cert := iotclient.ArduinoDevicev2Cert{}
13+
14+
// Add unknown fields to the JSON and verify that marshalling and unmarshalling works without raising error.
15+
// This is useful when the API is extended with new fields and the client is not updated yet.
16+
certJson := `{
17+
"compressed": {
18+
"not_after": "0001-01-01T00:00:00Z",
19+
"not_before": "0001-01-01T00:00:00Z",
20+
"serial": "",
21+
"signature": "signature",
22+
"signature_asn1_x": "",
23+
"signature_asn1_y": ""
24+
},
25+
"der": "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA",
26+
"device_id": "123",
27+
"enabled": true,
28+
"href": "",
29+
"id": "",
30+
"pem": "-----BEGIN CERTIFICATE-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA",
31+
"unknown_field": "value",
32+
"unknown_field2": "value2",
33+
"new_api_field": 2222
34+
}`
35+
36+
err := cert.UnmarshalJSON([]byte(certJson))
37+
if err != nil {
38+
t.Errorf("UnmarshalJSON failed: %s", err)
39+
}
40+
assert.Equal(t, 3, len(cert.AdditionalProperties))
41+
}

internal/template/load_test.go

+11-6
Original file line numberDiff line numberDiff line change
@@ -68,53 +68,58 @@ var (
6868
Widgets: []iotclient.Widget{
6969
{Name: toStringPointer("Switch-name"), Height: 1, HeightMobile: toInt64Pointer(2), Width: 3, WidthMobile: toInt64Pointer(4),
7070
X: 5, XMobile: toInt64Pointer(6), Y: 7, YMobile: toInt64Pointer(8), Options: map[string]interface{}{"showLabels": true},
71-
Type: "Switch",
71+
Type: "Switch", AdditionalProperties: map[string]any{},
7272
},
7373
},
74+
AdditionalProperties: map[string]any{},
7475
}
7576

7677
dashboardNoOptions = &iotclient.Dashboardv2{
7778
Name: toStringPointer("dashboard-no-options"),
7879
Widgets: []iotclient.Widget{
7980
{Name: toStringPointer("Switch-name"), Height: 1, HeightMobile: toInt64Pointer(2), Width: 3, WidthMobile: toInt64Pointer(4),
8081
X: 5, XMobile: toInt64Pointer(6), Y: 7, YMobile: toInt64Pointer(8), Options: map[string]interface{}{},
81-
Type: "Switch",
82+
Type: "Switch", AdditionalProperties: map[string]any{},
8283
},
8384
},
85+
AdditionalProperties: map[string]any{},
8486
}
8587

8688
dashboardWithVariable = &iotclient.Dashboardv2{
8789
Name: toStringPointer("dashboard-with-variable"),
8890
Widgets: []iotclient.Widget{
8991
{Name: toStringPointer("Switch-name"), Height: 1, HeightMobile: toInt64Pointer(2), Width: 3, WidthMobile: toInt64Pointer(4),
9092
X: 5, XMobile: toInt64Pointer(6), Y: 7, YMobile: toInt64Pointer(8), Options: map[string]interface{}{"showLabels": true}, Type: "Switch",
91-
Variables: []string{switchyID},
93+
Variables: []string{switchyID}, AdditionalProperties: map[string]any{},
9294
},
9395
},
96+
AdditionalProperties: map[string]any{},
9497
}
9598

9699
dashboardVariableOverride = &iotclient.Dashboardv2{
97100
Name: toStringPointer("dashboard-with-variable"),
98101
Widgets: []iotclient.Widget{
99102
{Name: toStringPointer("Switch-name"), Height: 1, HeightMobile: toInt64Pointer(2), Width: 3, WidthMobile: toInt64Pointer(4),
100103
X: 5, XMobile: toInt64Pointer(6), Y: 7, YMobile: toInt64Pointer(8), Options: map[string]interface{}{"showLabels": true}, Type: "Switch",
101-
Variables: []string{switchyOverriddenID},
104+
Variables: []string{switchyOverriddenID}, AdditionalProperties: map[string]any{},
102105
},
103106
},
107+
AdditionalProperties: map[string]any{},
104108
}
105109

106110
dashboardTwoWidgets = &iotclient.Dashboardv2{
107111
Name: toStringPointer("dashboard-two-widgets"),
108112
Widgets: []iotclient.Widget{
109113
{Name: toStringPointer("blink_speed"), Height: 7, Width: 8,
110114
X: 7, Y: 5, Options: map[string]interface{}{"min": float64(0), "max": float64(5000)}, Type: "Slider",
111-
Variables: []string{blinkSpeedID},
115+
Variables: []string{blinkSpeedID}, AdditionalProperties: map[string]any{},
112116
},
113117
{Name: toStringPointer("relay_2"), Height: 5, Width: 5,
114118
X: 5, Y: 0, Options: map[string]interface{}{"showLabels": true}, Type: "Switch",
115-
Variables: []string{relayID},
119+
Variables: []string{relayID}, AdditionalProperties: map[string]any{},
116120
},
117121
},
122+
AdditionalProperties: map[string]any{},
118123
}
119124
)
120125

0 commit comments

Comments
 (0)