-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Consistent Go naming for JSON fields #605
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
Comments
We can also consider adding a new field |
Good point. I like it. Maybe a general sweep might be in order. |
@gmlewis I'm down for doing it either way, but #588 is already unavoidably (afaics, unless we want to return |
ok, I'll proceed as described with the deprecated fields and increment the version number. |
https://github.com/google/go-github/blob/master/github/activity_events.go#L19
|
IMO, it's probably for the best to leave The only field I think is worth dealing with for now is |
Hmm, ok. I interpreted 'full sweep' to mean all json fields should be
inspected for naming consistency. For instance, there is a lot of swapping
of 'Repo' and 'repository', and at least one place where the field is
called Repository but the json field is 'repo'.
…On Fri, Mar 31, 2017 at 4:43 PM, Dmitri Shuralyov ***@***.***> wrote:
IMO, it's probably for the best to leave RawPayload alone for now. It has
a lot of machinery around it to parse it and convert it to something higher
level, that calling that field "raw" should not be confusing.
The only field I think is worth dealing with for now is TotalCount.
@gmlewis <https://github.com/gmlewis>, are there others you wanted to
tackle?
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#605 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAlDnB4lqlyU_zQ389zxRW5mp5RTuuhAks5rrXN_gaJpZM4Mtrr->
.
--
Aleks Clark
cell: 775-391-6114
|
Ah, @gmlewis said that in a comment, not the original issue. I missed that. Sure. A general sweep is okay. I think |
One of my worries about a full sweep is that it might be hard to justify renaming fields that are well named but happen not to match exactly. It introduces a new deprecated field, and I'm not entirely sure it's always an improvement. But let's consider it on a case-by-case basis. |
I think |
@gmlewis sounds good to me. Can you assign to me please?
…On Fri, Mar 31, 2017 at 5:01 PM, Glenn Lewis ***@***.***> wrote:
I think TotalCount was the most obvious. Maybe whoever tackles this one
could come up with a list of inconsistencies for review?
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#605 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAlDnPWFyebSVqgWU3O7qYtoER7PRbKDks5rrXfUgaJpZM4Mtrr->
.
--
Aleks Clark
cell: 775-391-6114
|
Hi, I just started working on a spreadsheet of discrepancies. Any issue with assigning to me? |
Ok with me
…On Aug 20, 2017 10:19 PM, "Elliott Beach" ***@***.***> wrote:
Hi, I just started working on a spreadsheet of discrepancies. Any issue
with assigning to me?
—
You are receiving this because you were assigned.
Reply to this email directly, view it on GitHub
<#605 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAlDnMn0KoD9FLyRGtjUaU-UNOzjwNU5ks5saPdUgaJpZM4Mtrr->
.
|
Here's a list of all inconsistencies:
It seems that the use of "Repo" or "Repository" for field names is inconsistent. The full list was generated using a script I cooked up at https://gist.github.com/e-beach/120a6f26c72c8d08f2895b933d1af8ab, I discarded these differences that seem highly intentional:
I don't think I can take further action on this myself, but I believe the script caught all the differences by detecting API fields that not equivalent to the json field converted to camelCase. |
Thanks, @e-beach! Invite sent. |
Thanks, accepted! To be clear, I don't think I can make a PR based on this as I'm not currently in a position to judge what changes should be made. |
Thank you very much for contributing those investigation results in #605 (comment), @e-beach! That is extremely helpful (and often undervalued), because it will make it much easier for anyone to contribute a code fix and for us to review it. Your contribution gets a 🌟 from me! :) We should discuss here first what changes we want to make, before working on a PR, since it'll be easier and more efficient this way. |
Let's start with the easier ones. I think it's for sure that we want to fix these inconsistencies, because they're a typo:
I think a breaking API change for both is the most effective way to move forward. We should definitely do it for The one in
UpdatedAt *Timestamp `json:"updated_at,omitempty"`
UpdateAt *Timestamp `json:"updated_at,omitempty"` // Deprecated: Use UpdatedAt instead. Edit: Not fine, see following comment. Anyone who wants can send a PR to resolve these two. This comment is made possible thanks to @e-beach's investigation, so thanks again for that! |
Actually, as I suspected, it won't be possible to use a deprecated field like that. Due to the rules for overlapping JSON fields in https://godoc.org/encoding/json:
There will be multiple fields and they will be ignored. See https://play.golang.org/p/MWsbl69mT8. So it has to be a simple breaking API change. |
I'll copy my #709 (comment) from the PR so we can discuss it here:
Also, I just noticed there are two go-github/github/repos_deployments.go Line 26 in 5f3187e
go-github/github/repos_deployments.go Line 140 in 5f3187e
Both were added in c491754 by @dlapiduz 3 years ago. Any chance you remember if there was a reason for the discrepancy, or was it an oversight? I think there'd be a comment if it were on purpose, so I suspect it was unintended. |
It was done in PR #139. There's no discussion about the discrepancy, so that pretty much confirms it was unintentional. |
The In addition to the documentation, sending requests to https://api.github.com/repos/github/hub/deployments/16449242 (a deployment) shows that both instances should use |
@shurcooL @e-beach I don't recall exactly what happened but I think that the deployments API was alpha/beta at that time and it was changing. That might be the source of the discrepancy. |
I see, that would make sense. Thanks for looking into it and providing confirmation @e-beach and @dlapiduz! |
Authorization struct had a "updated_at" JSON key mapped to UpdateAt, which was an oversight/typo. It has been renamed to UpdatedAt, like all other similar fields. Deployments and DeploymentStatus structs had incorrectly mapped their UpdatedAt field to a non-existing "pushed_at" JSON key. That means their values were never populated. This change fixes that. Bump library version as this is a breaking change. Helps #605.
Now that we've renamed a few fields, a decision should also be made on what, if any, other fields ought to be changed. The comments above mentioned |
Yeah. I'm going to think about it some more, but I think a likely good next step is to stop here and close this issue. |
…ogle#709) Authorization struct had a "updated_at" JSON key mapped to UpdateAt, which was an oversight/typo. It has been renamed to UpdatedAt, like all other similar fields. Deployments and DeploymentStatus structs had incorrectly mapped their UpdatedAt field to a non-existing "pushed_at" JSON key. That means their values were never populated. This change fixes that. Bump library version as this is a breaking change. Helps google#605.
@dmitshur Please close the issue. It lead me to read the entire thread and in the end, I realized there's no work to be done. Thanks |
Sorry for the inconvenience, @RajatVaryani. |
As discussed in #520 (comment) and #602 (comment) the naming of fields such as
Total
(as opposed toTotalCount
) where the JSON name istotal_count
seems inconsistent and it would be nice to consolidate.However, this is a breaking API change.
This issue has been opened to discuss the situation and see if it is worth breaking the API to have more consistency.
The text was updated successfully, but these errors were encountered: