Skip to content

Commit

Permalink
Fix code generation for unions (#53)
Browse files Browse the repository at this point in the history
* full patch with tests:

* simplified

* fix fmt_type to get things compiling

* drop missing import

* simpler union decoding

* update sdk version
  • Loading branch information
aaronstaley authored and jiuyangzhao committed Oct 23, 2019
1 parent af4558f commit 302f2cc
Show file tree
Hide file tree
Showing 16 changed files with 570 additions and 2,041 deletions.
12 changes: 10 additions & 2 deletions dropbox/async/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ const (
func (u *LaunchResultBase) UnmarshalJSON(body []byte) error {
type wrap struct {
dropbox.Tagged
// AsyncJobId : This response indicates that the processing is
// asynchronous. The string is an id that can be used to obtain the
// status of the asynchronous job.
AsyncJobId string `json:"async_job_id,omitempty"`
}
var w wrap
var err error
Expand All @@ -58,7 +62,7 @@ func (u *LaunchResultBase) UnmarshalJSON(body []byte) error {
u.Tag = w.Tag
switch u.Tag {
case "async_job_id":
err = json.Unmarshal(body, &u.AsyncJobId)
u.AsyncJobId = w.AsyncJobId

if err != nil {
return err
Expand Down Expand Up @@ -88,6 +92,10 @@ const (
func (u *LaunchEmptyResult) UnmarshalJSON(body []byte) error {
type wrap struct {
dropbox.Tagged
// AsyncJobId : This response indicates that the processing is
// asynchronous. The string is an id that can be used to obtain the
// status of the asynchronous job.
AsyncJobId string `json:"async_job_id,omitempty"`
}
var w wrap
var err error
Expand All @@ -97,7 +105,7 @@ func (u *LaunchEmptyResult) UnmarshalJSON(body []byte) error {
u.Tag = w.Tag
switch u.Tag {
case "async_job_id":
err = json.Unmarshal(body, &u.AsyncJobId)
u.AsyncJobId = w.AsyncJobId

if err != nil {
return err
Expand Down
8 changes: 4 additions & 4 deletions dropbox/auth/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ func (u *AccessError) UnmarshalJSON(body []byte) error {
type wrap struct {
dropbox.Tagged
// InvalidAccountType : Current account type cannot access the resource.
InvalidAccountType json.RawMessage `json:"invalid_account_type,omitempty"`
InvalidAccountType *InvalidAccountTypeError `json:"invalid_account_type,omitempty"`
// PaperAccessDenied : Current account cannot access Paper.
PaperAccessDenied json.RawMessage `json:"paper_access_denied,omitempty"`
PaperAccessDenied *PaperAccessError `json:"paper_access_denied,omitempty"`
}
var w wrap
var err error
Expand All @@ -61,13 +61,13 @@ func (u *AccessError) UnmarshalJSON(body []byte) error {
u.Tag = w.Tag
switch u.Tag {
case "invalid_account_type":
err = json.Unmarshal(w.InvalidAccountType, &u.InvalidAccountType)
u.InvalidAccountType = w.InvalidAccountType

if err != nil {
return err
}
case "paper_access_denied":
err = json.Unmarshal(w.PaperAccessDenied, &u.PaperAccessDenied)
u.PaperAccessDenied = w.PaperAccessDenied

if err != nil {
return err
Expand Down
18 changes: 11 additions & 7 deletions dropbox/common/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ const (
func (u *PathRoot) UnmarshalJSON(body []byte) error {
type wrap struct {
dropbox.Tagged
// Root : Paths are relative to the authenticating user's root namespace
// (This results in `PathRootError.invalid_root` if the user's root
// namespace has changed.).
Root string `json:"root,omitempty"`
// NamespaceId : Paths are relative to given namespace id (This results
// in `PathRootError.no_permission` if you don't have access to this
// namespace.).
NamespaceId string `json:"namespace_id,omitempty"`
}
var w wrap
var err error
Expand All @@ -61,13 +69,13 @@ func (u *PathRoot) UnmarshalJSON(body []byte) error {
u.Tag = w.Tag
switch u.Tag {
case "root":
err = json.Unmarshal(body, &u.Root)
u.Root = w.Root

if err != nil {
return err
}
case "namespace_id":
err = json.Unmarshal(body, &u.NamespaceId)
u.NamespaceId = w.NamespaceId

if err != nil {
return err
Expand Down Expand Up @@ -107,7 +115,7 @@ func (u *PathRootError) UnmarshalJSON(body []byte) error {
u.Tag = w.Tag
switch u.Tag {
case "invalid_root":
u.InvalidRoot, err = IsRootInfoFromJSON(body)
u.InvalidRoot, err = IsRootInfoFromJSON(w.InvalidRoot)

if err != nil {
return err
Expand Down Expand Up @@ -161,10 +169,6 @@ const (
func (u *rootInfoUnion) UnmarshalJSON(body []byte) error {
type wrap struct {
dropbox.Tagged
// Team : has no documentation (yet)
Team json.RawMessage `json:"team,omitempty"`
// User : has no documentation (yet)
User json.RawMessage `json:"user,omitempty"`
}
var w wrap
var err error
Expand Down
4 changes: 2 additions & 2 deletions dropbox/contacts/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (u *DeleteManualContactsError) UnmarshalJSON(body []byte) error {
// ContactsNotFound : Can't delete contacts from this list. Make sure
// the list only has manually added contacts. The deletion was
// cancelled.
ContactsNotFound json.RawMessage `json:"contacts_not_found,omitempty"`
ContactsNotFound []string `json:"contacts_not_found,omitempty"`
}
var w wrap
var err error
Expand All @@ -71,7 +71,7 @@ func (u *DeleteManualContactsError) UnmarshalJSON(body []byte) error {
u.Tag = w.Tag
switch u.Tag {
case "contacts_not_found":
err = json.Unmarshal(body, &u.ContactsNotFound)
u.ContactsNotFound = w.ContactsNotFound

if err != nil {
return err
Expand Down
Loading

0 comments on commit 302f2cc

Please sign in to comment.