Skip to content

Commit 302f2cc

Browse files
aaronstaleyjiuyangzhao
authored andcommitted
Fix code generation for unions (#53)
* full patch with tests: * simplified * fix fmt_type to get things compiling * drop missing import * simpler union decoding * update sdk version
1 parent af4558f commit 302f2cc

File tree

16 files changed

+570
-2041
lines changed

16 files changed

+570
-2041
lines changed

dropbox/async/types.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ const (
4949
func (u *LaunchResultBase) UnmarshalJSON(body []byte) error {
5050
type wrap struct {
5151
dropbox.Tagged
52+
// AsyncJobId : This response indicates that the processing is
53+
// asynchronous. The string is an id that can be used to obtain the
54+
// status of the asynchronous job.
55+
AsyncJobId string `json:"async_job_id,omitempty"`
5256
}
5357
var w wrap
5458
var err error
@@ -58,7 +62,7 @@ func (u *LaunchResultBase) UnmarshalJSON(body []byte) error {
5862
u.Tag = w.Tag
5963
switch u.Tag {
6064
case "async_job_id":
61-
err = json.Unmarshal(body, &u.AsyncJobId)
65+
u.AsyncJobId = w.AsyncJobId
6266

6367
if err != nil {
6468
return err
@@ -88,6 +92,10 @@ const (
8892
func (u *LaunchEmptyResult) UnmarshalJSON(body []byte) error {
8993
type wrap struct {
9094
dropbox.Tagged
95+
// AsyncJobId : This response indicates that the processing is
96+
// asynchronous. The string is an id that can be used to obtain the
97+
// status of the asynchronous job.
98+
AsyncJobId string `json:"async_job_id,omitempty"`
9199
}
92100
var w wrap
93101
var err error
@@ -97,7 +105,7 @@ func (u *LaunchEmptyResult) UnmarshalJSON(body []byte) error {
97105
u.Tag = w.Tag
98106
switch u.Tag {
99107
case "async_job_id":
100-
err = json.Unmarshal(body, &u.AsyncJobId)
108+
u.AsyncJobId = w.AsyncJobId
101109

102110
if err != nil {
103111
return err

dropbox/auth/types.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ func (u *AccessError) UnmarshalJSON(body []byte) error {
4949
type wrap struct {
5050
dropbox.Tagged
5151
// InvalidAccountType : Current account type cannot access the resource.
52-
InvalidAccountType json.RawMessage `json:"invalid_account_type,omitempty"`
52+
InvalidAccountType *InvalidAccountTypeError `json:"invalid_account_type,omitempty"`
5353
// PaperAccessDenied : Current account cannot access Paper.
54-
PaperAccessDenied json.RawMessage `json:"paper_access_denied,omitempty"`
54+
PaperAccessDenied *PaperAccessError `json:"paper_access_denied,omitempty"`
5555
}
5656
var w wrap
5757
var err error
@@ -61,13 +61,13 @@ func (u *AccessError) UnmarshalJSON(body []byte) error {
6161
u.Tag = w.Tag
6262
switch u.Tag {
6363
case "invalid_account_type":
64-
err = json.Unmarshal(w.InvalidAccountType, &u.InvalidAccountType)
64+
u.InvalidAccountType = w.InvalidAccountType
6565

6666
if err != nil {
6767
return err
6868
}
6969
case "paper_access_denied":
70-
err = json.Unmarshal(w.PaperAccessDenied, &u.PaperAccessDenied)
70+
u.PaperAccessDenied = w.PaperAccessDenied
7171

7272
if err != nil {
7373
return err

dropbox/common/types.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,14 @@ const (
5252
func (u *PathRoot) UnmarshalJSON(body []byte) error {
5353
type wrap struct {
5454
dropbox.Tagged
55+
// Root : Paths are relative to the authenticating user's root namespace
56+
// (This results in `PathRootError.invalid_root` if the user's root
57+
// namespace has changed.).
58+
Root string `json:"root,omitempty"`
59+
// NamespaceId : Paths are relative to given namespace id (This results
60+
// in `PathRootError.no_permission` if you don't have access to this
61+
// namespace.).
62+
NamespaceId string `json:"namespace_id,omitempty"`
5563
}
5664
var w wrap
5765
var err error
@@ -61,13 +69,13 @@ func (u *PathRoot) UnmarshalJSON(body []byte) error {
6169
u.Tag = w.Tag
6270
switch u.Tag {
6371
case "root":
64-
err = json.Unmarshal(body, &u.Root)
72+
u.Root = w.Root
6573

6674
if err != nil {
6775
return err
6876
}
6977
case "namespace_id":
70-
err = json.Unmarshal(body, &u.NamespaceId)
78+
u.NamespaceId = w.NamespaceId
7179

7280
if err != nil {
7381
return err
@@ -107,7 +115,7 @@ func (u *PathRootError) UnmarshalJSON(body []byte) error {
107115
u.Tag = w.Tag
108116
switch u.Tag {
109117
case "invalid_root":
110-
u.InvalidRoot, err = IsRootInfoFromJSON(body)
118+
u.InvalidRoot, err = IsRootInfoFromJSON(w.InvalidRoot)
111119

112120
if err != nil {
113121
return err
@@ -161,10 +169,6 @@ const (
161169
func (u *rootInfoUnion) UnmarshalJSON(body []byte) error {
162170
type wrap struct {
163171
dropbox.Tagged
164-
// Team : has no documentation (yet)
165-
Team json.RawMessage `json:"team,omitempty"`
166-
// User : has no documentation (yet)
167-
User json.RawMessage `json:"user,omitempty"`
168172
}
169173
var w wrap
170174
var err error

dropbox/contacts/types.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func (u *DeleteManualContactsError) UnmarshalJSON(body []byte) error {
6161
// ContactsNotFound : Can't delete contacts from this list. Make sure
6262
// the list only has manually added contacts. The deletion was
6363
// cancelled.
64-
ContactsNotFound json.RawMessage `json:"contacts_not_found,omitempty"`
64+
ContactsNotFound []string `json:"contacts_not_found,omitempty"`
6565
}
6666
var w wrap
6767
var err error
@@ -71,7 +71,7 @@ func (u *DeleteManualContactsError) UnmarshalJSON(body []byte) error {
7171
u.Tag = w.Tag
7272
switch u.Tag {
7373
case "contacts_not_found":
74-
err = json.Unmarshal(body, &u.ContactsNotFound)
74+
u.ContactsNotFound = w.ContactsNotFound
7575

7676
if err != nil {
7777
return err

0 commit comments

Comments
 (0)