Byron / google-apis-rs

A binding and CLI generator for all Google APIs
http://byron.github.io/google-apis-rs
Other
1.01k stars 131 forks source link

Google Sheets: Don't remove Value::Null from ValueRange.values #416

Open JacksonDCollins opened 1 year ago

JacksonDCollins commented 1 year ago

For the use-case we currently have, we only want to update certain cells in a range and leave the rest as-is. According to the documentation of the values field of ValueRange: For input, supported value types are: bool, string, and double. Null values will be skipped.

However, when updating values or appending a new row, these null values are stripped from the Vec before being sent, resulting in values later in the Vec being inserted into the sheet where a blank cells should be, compressing the Vec and overwriting cells. Forking the repo and commenting out all occurences of client::remove_json_null_values(&mut value); from sheets4/src/api.rs has achieved the desired result.

Can I suggest this as the fix? Or is it required to remove the null values for another reason?

Byron commented 1 year ago

Thanks for letting me know.

The only persisting fix would be to add another option to the generation which can then be set on a per-API basis. The per-API override mechanism is already available and used for the youtube API if I remember correctly, but a flag to conditionally remove null doesn't exist yet.

The reason null is removed is because (at least when the generator was made years ago) the Google APIs were very upset if null was sent to them. That might still be the case and generally it turned out to be a good idea to remove null (except for when it isn't).

A PR would definitely be welcome to incorporate selective inclusion of null on a per API basis, and with the overrides on the youtube API as reference it shouldn't turn out to be too complicated either.