Skip to content

Commit

Permalink
generator: support nulls in JSON
Browse files Browse the repository at this point in the history
ForceSendFields doesn't quite cover all the cases needed to correctly
patch a resource. Sometimes you have to send a JSON null to clear a
value; the zero value won't do.

Two examples from storage/v1.Objects.Patch:

- It is an error to send "" as the value of ContentLanguage.

- Sending the empty JSON map `{}` for Metadata is a no-op.

In both these cases, to clear the value you must send a null.

This CL:

- Adds a NullFields field to each resource, to complement
  ForceSendFields.

- Modifies the custom JSON marshalling logic to send null for
  any field in NullFields (and return an error for a non-empty
  field in NullFields).

- Regenerates all the clients.

- Updates the goldens in testdata.

Change-Id: I748921ae83e2df6fb2f168a87075615955fcc656
Reviewed-on: https://code-review.googlesource.com/8010
Reviewed-by: Jonathan Amsterdam <[email protected]>
  • Loading branch information
jba committed Oct 6, 2016
1 parent 74c274b commit 1ba8c3c
Show file tree
Hide file tree
Showing 191 changed files with 61,747 additions and 6,732 deletions.
41 changes: 37 additions & 4 deletions acceleratedmobilepageurl/v1/acceleratedmobilepageurl-gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,20 @@ type AmpUrl struct {
// server regardless of whether the field is empty or not. This may be
// used to include empty fields in Patch requests.
ForceSendFields []string `json:"-"`

// NullFields is a list of field names (e.g. "AmpUrl") to include in API
// requests with the JSON null value. By default, fields with empty
// values are omitted from API requests. However, any field with an
// empty value appearing in NullFields will be sent to the server as
// null. It is an error if a field on this list has a non-empty value.
// This may be used to include null fields in Patch requests.
NullFields []string `json:"-"`
}

func (s *AmpUrl) MarshalJSON() ([]byte, error) {
type noMethod AmpUrl
raw := noMethod(*s)
return gensupport.MarshalJSON(raw, s.ForceSendFields)
return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields)
}

// AmpUrlError: AMP URL Error resource for a requested URL that couldn't
Expand Down Expand Up @@ -147,12 +155,20 @@ type AmpUrlError struct {
// server regardless of whether the field is empty or not. This may be
// used to include empty fields in Patch requests.
ForceSendFields []string `json:"-"`

// NullFields is a list of field names (e.g. "ErrorCode") to include in
// API requests with the JSON null value. By default, fields with empty
// values are omitted from API requests. However, any field with an
// empty value appearing in NullFields will be sent to the server as
// null. It is an error if a field on this list has a non-empty value.
// This may be used to include null fields in Patch requests.
NullFields []string `json:"-"`
}

func (s *AmpUrlError) MarshalJSON() ([]byte, error) {
type noMethod AmpUrlError
raw := noMethod(*s)
return gensupport.MarshalJSON(raw, s.ForceSendFields)
return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields)
}

// BatchGetAmpUrlsRequest: AMP URL request for a batch of URLs.
Expand Down Expand Up @@ -190,12 +206,21 @@ type BatchGetAmpUrlsRequest struct {
// server regardless of whether the field is empty or not. This may be
// used to include empty fields in Patch requests.
ForceSendFields []string `json:"-"`

// NullFields is a list of field names (e.g. "LookupStrategy") to
// include in API requests with the JSON null value. By default, fields
// with empty values are omitted from API requests. However, any field
// with an empty value appearing in NullFields will be sent to the
// server as null. It is an error if a field on this list has a
// non-empty value. This may be used to include null fields in Patch
// requests.
NullFields []string `json:"-"`
}

func (s *BatchGetAmpUrlsRequest) MarshalJSON() ([]byte, error) {
type noMethod BatchGetAmpUrlsRequest
raw := noMethod(*s)
return gensupport.MarshalJSON(raw, s.ForceSendFields)
return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields)
}

// BatchGetAmpUrlsResponse: Batch AMP URL response.
Expand All @@ -222,12 +247,20 @@ type BatchGetAmpUrlsResponse struct {
// server regardless of whether the field is empty or not. This may be
// used to include empty fields in Patch requests.
ForceSendFields []string `json:"-"`

// NullFields is a list of field names (e.g. "AmpUrls") to include in
// API requests with the JSON null value. By default, fields with empty
// values are omitted from API requests. However, any field with an
// empty value appearing in NullFields will be sent to the server as
// null. It is an error if a field on this list has a non-empty value.
// This may be used to include null fields in Patch requests.
NullFields []string `json:"-"`
}

func (s *BatchGetAmpUrlsResponse) MarshalJSON() ([]byte, error) {
type noMethod BatchGetAmpUrlsResponse
raw := noMethod(*s)
return gensupport.MarshalJSON(raw, s.ForceSendFields)
return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields)
}

// method id "acceleratedmobilepageurl.ampUrls.batchGet":
Expand Down
92 changes: 83 additions & 9 deletions adexchangebuyer/v1.2/adexchangebuyer-gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,21 @@ type Account struct {
// server regardless of whether the field is empty or not. This may be
// used to include empty fields in Patch requests.
ForceSendFields []string `json:"-"`

// NullFields is a list of field names (e.g. "BidderLocation") to
// include in API requests with the JSON null value. By default, fields
// with empty values are omitted from API requests. However, any field
// with an empty value appearing in NullFields will be sent to the
// server as null. It is an error if a field on this list has a
// non-empty value. This may be used to include null fields in Patch
// requests.
NullFields []string `json:"-"`
}

func (s *Account) MarshalJSON() ([]byte, error) {
type noMethod Account
raw := noMethod(*s)
return gensupport.MarshalJSON(raw, s.ForceSendFields)
return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields)
}

type AccountBidderLocation struct {
Expand All @@ -172,12 +181,20 @@ type AccountBidderLocation struct {
// server regardless of whether the field is empty or not. This may be
// used to include empty fields in Patch requests.
ForceSendFields []string `json:"-"`

// NullFields is a list of field names (e.g. "MaximumQps") to include in
// API requests with the JSON null value. By default, fields with empty
// values are omitted from API requests. However, any field with an
// empty value appearing in NullFields will be sent to the server as
// null. It is an error if a field on this list has a non-empty value.
// This may be used to include null fields in Patch requests.
NullFields []string `json:"-"`
}

func (s *AccountBidderLocation) MarshalJSON() ([]byte, error) {
type noMethod AccountBidderLocation
raw := noMethod(*s)
return gensupport.MarshalJSON(raw, s.ForceSendFields)
return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields)
}

// AccountsList: An account feed lists Ad Exchange buyer accounts that
Expand All @@ -201,12 +218,20 @@ type AccountsList struct {
// server regardless of whether the field is empty or not. This may be
// used to include empty fields in Patch requests.
ForceSendFields []string `json:"-"`

// NullFields is a list of field names (e.g. "Items") to include in API
// requests with the JSON null value. By default, fields with empty
// values are omitted from API requests. However, any field with an
// empty value appearing in NullFields will be sent to the server as
// null. It is an error if a field on this list has a non-empty value.
// This may be used to include null fields in Patch requests.
NullFields []string `json:"-"`
}

func (s *AccountsList) MarshalJSON() ([]byte, error) {
type noMethod AccountsList
raw := noMethod(*s)
return gensupport.MarshalJSON(raw, s.ForceSendFields)
return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields)
}

// Creative: A creative and its classification data.
Expand Down Expand Up @@ -314,12 +339,20 @@ type Creative struct {
// server regardless of whether the field is empty or not. This may be
// used to include empty fields in Patch requests.
ForceSendFields []string `json:"-"`

// NullFields is a list of field names (e.g. "HTMLSnippet") to include
// in API requests with the JSON null value. By default, fields with
// empty values are omitted from API requests. However, any field with
// an empty value appearing in NullFields will be sent to the server as
// null. It is an error if a field on this list has a non-empty value.
// This may be used to include null fields in Patch requests.
NullFields []string `json:"-"`
}

func (s *Creative) MarshalJSON() ([]byte, error) {
type noMethod Creative
raw := noMethod(*s)
return gensupport.MarshalJSON(raw, s.ForceSendFields)
return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields)
}

type CreativeCorrections struct {
Expand All @@ -336,12 +369,20 @@ type CreativeCorrections struct {
// server regardless of whether the field is empty or not. This may be
// used to include empty fields in Patch requests.
ForceSendFields []string `json:"-"`

// NullFields is a list of field names (e.g. "Details") to include in
// API requests with the JSON null value. By default, fields with empty
// values are omitted from API requests. However, any field with an
// empty value appearing in NullFields will be sent to the server as
// null. It is an error if a field on this list has a non-empty value.
// This may be used to include null fields in Patch requests.
NullFields []string `json:"-"`
}

func (s *CreativeCorrections) MarshalJSON() ([]byte, error) {
type noMethod CreativeCorrections
raw := noMethod(*s)
return gensupport.MarshalJSON(raw, s.ForceSendFields)
return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields)
}

type CreativeDisapprovalReasons struct {
Expand All @@ -358,12 +399,20 @@ type CreativeDisapprovalReasons struct {
// server regardless of whether the field is empty or not. This may be
// used to include empty fields in Patch requests.
ForceSendFields []string `json:"-"`

// NullFields is a list of field names (e.g. "Details") to include in
// API requests with the JSON null value. By default, fields with empty
// values are omitted from API requests. However, any field with an
// empty value appearing in NullFields will be sent to the server as
// null. It is an error if a field on this list has a non-empty value.
// This may be used to include null fields in Patch requests.
NullFields []string `json:"-"`
}

func (s *CreativeDisapprovalReasons) MarshalJSON() ([]byte, error) {
type noMethod CreativeDisapprovalReasons
raw := noMethod(*s)
return gensupport.MarshalJSON(raw, s.ForceSendFields)
return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields)
}

// CreativeFilteringReasons: The filtering reasons for the creative.
Expand All @@ -383,12 +432,20 @@ type CreativeFilteringReasons struct {
// server regardless of whether the field is empty or not. This may be
// used to include empty fields in Patch requests.
ForceSendFields []string `json:"-"`

// NullFields is a list of field names (e.g. "Date") to include in API
// requests with the JSON null value. By default, fields with empty
// values are omitted from API requests. However, any field with an
// empty value appearing in NullFields will be sent to the server as
// null. It is an error if a field on this list has a non-empty value.
// This may be used to include null fields in Patch requests.
NullFields []string `json:"-"`
}

func (s *CreativeFilteringReasons) MarshalJSON() ([]byte, error) {
type noMethod CreativeFilteringReasons
raw := noMethod(*s)
return gensupport.MarshalJSON(raw, s.ForceSendFields)
return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields)
}

type CreativeFilteringReasonsReasons struct {
Expand All @@ -408,12 +465,21 @@ type CreativeFilteringReasonsReasons struct {
// server regardless of whether the field is empty or not. This may be
// used to include empty fields in Patch requests.
ForceSendFields []string `json:"-"`

// NullFields is a list of field names (e.g. "FilteringCount") to
// include in API requests with the JSON null value. By default, fields
// with empty values are omitted from API requests. However, any field
// with an empty value appearing in NullFields will be sent to the
// server as null. It is an error if a field on this list has a
// non-empty value. This may be used to include null fields in Patch
// requests.
NullFields []string `json:"-"`
}

func (s *CreativeFilteringReasonsReasons) MarshalJSON() ([]byte, error) {
type noMethod CreativeFilteringReasonsReasons
raw := noMethod(*s)
return gensupport.MarshalJSON(raw, s.ForceSendFields)
return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields)
}

// CreativesList: The creatives feed lists the active creatives for the
Expand Down Expand Up @@ -442,12 +508,20 @@ type CreativesList struct {
// server regardless of whether the field is empty or not. This may be
// used to include empty fields in Patch requests.
ForceSendFields []string `json:"-"`

// NullFields is a list of field names (e.g. "Items") to include in API
// requests with the JSON null value. By default, fields with empty
// values are omitted from API requests. However, any field with an
// empty value appearing in NullFields will be sent to the server as
// null. It is an error if a field on this list has a non-empty value.
// This may be used to include null fields in Patch requests.
NullFields []string `json:"-"`
}

func (s *CreativesList) MarshalJSON() ([]byte, error) {
type noMethod CreativesList
raw := noMethod(*s)
return gensupport.MarshalJSON(raw, s.ForceSendFields)
return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields)
}

// method id "adexchangebuyer.accounts.get":
Expand Down
Loading

0 comments on commit 1ba8c3c

Please sign in to comment.