Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate a deleteX() method for use with PATCH to delete a field #466

Closed
wonderfly opened this issue Jan 10, 2015 · 7 comments
Closed

Generate a deleteX() method for use with PATCH to delete a field #466

wonderfly opened this issue Jan 10, 2015 · 7 comments
Assignees
Labels
imported priority: p1 Important issue which blocks shipping the next release. Will be fixed prior to next release. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.

Comments

@wonderfly
Copy link
Contributor

From yan...@google.com on April 06, 2012 14:03:37

External references, such as a standards document, or specification? http://googlecode.blogspot.com/2011/07/lightning-fast-performance-tips-for.html https://developers.google.com/google-apps/tasks/performance#patch Java environments (e.g. Java 6, Android 2.3, App Engine, or All)? All Please describe the feature requested. See the example from the Tasks API documentation that shows deleting a "comment" field from some fictional "demo" API:

PATCH https://www.googleapis.com/demo/v1/324?fields=etag,title,comment,characteristics Authorization: /* Auth token goes here */
Content-Type: application/json
If-Match: "ETagString"

{
"etag": "ETagString"
"title": "", /* Clear the value of the title by setting it to the empty string. /
"comment": null, /
Delete the comment by replacing its value with null. /
"characteristics": { /
Omit the length field, since it's not changing. /
"length": "short",
"level": "10", /
Modify the level value. /
"followers": ["Jo", "Liz"], /
Replace the followers array to delete Will and add Liz. /
"accuracy": "high" /
Add a new characteristic. */
},
}

In order to accomplish this with the generated service-specific library, you would have to do something like this:

resource.setComment(Data.NULL_STRING);

but this is not intuitive. Most users will honestly give up trying by this point.

What might be more intuitive is if we generated a method like deleteComment() that would encapsulate that logic, e.g.:

/** Deletes the comment field for use with a PATCH request. */
public Resource deleteComment() {
return setComment(Data.NULL_STRING);
}

Trivial to implement for us, and hopefully be more intuitive to find and use.

Original issue: http://code.google.com/p/google-api-java-client/issues/detail?id=451

@wonderfly wonderfly added type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. imported priority: p1 Important issue which blocks shipping the next release. Will be fixed prior to next release. 2–5 stars labels Jan 10, 2015
@wonderfly wonderfly self-assigned this Jan 10, 2015
@wonderfly
Copy link
Contributor Author

From rmis...@google.com on April 09, 2012 07:42:32

This is unfortunately not a trivial implementation. My original logic was to do something like:

set{% camel_case param.wireName %}(com.google.api.client.util.Data.NULL_{{ param.codeType|upper }});

but this does not work because the type of the parameter may not be a primitive type. Eg: For one parameter I ran into List.

I also think it is not that hard for users to figure out resource.setComment(Data.NULL_STRING) but to help them out we could (only for Patch methods) generate an additional comment in the javadoc pointing them to com.google.api.client.util.Data for JSON null values.

What do you think?

@wonderfly
Copy link
Contributor Author

From yan...@google.com on April 10, 2012 05:17:20

In general you can call Data.nullOf() to get the JSON null object for any type. I do think it is hard for users to figure it out. As you say, this is "unfortunately not trivial".

Adding a comment to the JavaDoc is reasonable, but my concern is that:

  1. Developers often don't read JavaDoc so are less likely to discover it
  2. If you do know how it works, it is human nature to accidentally call setComment(null) when you meant to call setComment(Data.NULL_STRING).

I do see the down-side of adding more clutter in terms of extra generated methods. This is particularly true in the case where a field cannot be modified. We may be able to solve this problem though: there are plans to add information in Discovery about which fields are modifiable. Perhaps we should wait for that before implementing deleteX()?

@wonderfly
Copy link
Contributor Author

From rmis...@google.com on April 16, 2012 05:16:05

Yes it makes sense to wait for that before implementing deleteX(), we do not want to provide deleteX() if X cannot be modified, this will lead to confusion.

Do not see how to mark that we have a dependency for this bug, lowering priority instead.

Labels: -Priority-Medium Priority-Low

@wonderfly
Copy link
Contributor Author

From rmis...@google.com on May 16, 2012 06:24:37

Labels: -Milestone-CodeGenVersion1.6.0 Milestone-CodeGenVersion1.7.0

@wonderfly
Copy link
Contributor Author

From rmis...@google.com on May 30, 2012 12:26:30

Labels: -Milestone-CodeGenVersion1.7.0 Milestone-CodeGenVersion1.8.0

@wonderfly
Copy link
Contributor Author

From yan...@google.com on August 02, 2012 07:38:13

Labels: -Milestone-CodeGenVersion1.8.0 Milestone-CodeGenVersion1.9.0

@wonderfly
Copy link
Contributor Author

From yan...@google.com on September 26, 2012 05:43:48

Status: Accepted
Labels: -Priority-Low -Milestone-CodeGenVersion1.9.0 Priority-High

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
imported priority: p1 Important issue which blocks shipping the next release. Will be fixed prior to next release. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.
Projects
None yet
Development

No branches or pull requests

3 participants