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

feat(AIP-123): add singular and plural validation #1143

Merged
merged 4 commits into from
May 11, 2023
Merged

feat(AIP-123): add singular and plural validation #1143

merged 4 commits into from
May 11, 2023

Conversation

toumorokoshi
Copy link
Contributor

Matching AIP-123 in requiring singular and plural annotations, and for singular matching the lowerCamelCase of type.

Fixes #722, but needs guidance updated in the AIPs around the values first.

Matching AIP-123 in requiring singular and plural annotations,
and for singular matching the lowerCamelCase of type.
@toumorokoshi toumorokoshi requested a review from a team as a code owner May 6, 2023 20:14
rules/aip0123/resource_singular.go Outdated Show resolved Hide resolved
rules/aip0123/resource_singular.go Outdated Show resolved Hide resolved
rules/aip0123/resource_plural.go Show resolved Hide resolved
rules/aip0123/resource_singular.go Show resolved Hide resolved
rules/aip0123/aip0123.go Show resolved Hide resolved
rules/aip0123/resource_singular.go Outdated Show resolved Hide resolved
- fixing all lint problems with suggested values.
- writing custom ToUpperCamelCase as existing one does not consider
  underscores / dashes as invalid characters, which are considered
  delimiters in the camel case conversion.
@toumorokoshi toumorokoshi added this to the gcp-strict-aips milestone May 11, 2023
@toumorokoshi toumorokoshi requested a review from noahdietz May 11, 2023 16:09
@toumorokoshi
Copy link
Contributor Author

@noahdietz finally ready for a pass! Thanks.


// ToUpperCamelCase returns the UpperCamelCase of a string, including removing
// delimiters (_,-,., ) and using them to denote a new word.
func ToUpperCamelCase(s string) string {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sooooo we could totally switch to using this but....we already use strcase for this type of stuff: https://pkg.go.dev/github.com/stoewer/go-strcase 😬 Not sure we need this file, unless we want to drop the external/non-google dependency (which would be fine if that was a goal, I do see value in such a "clean" module approach)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

strcase doesn't filter out "-" or "_" unfortunately. I did see some hacks with double-conversion to snake case, then to upperCamelCase, but I figured it might be best to roll our own that matches our own definition of "upperCamelCase".

I did find this version of strcase that matches our definition: https://github.com/iancoleman/strcase. But I decided against switching it because we need to vet that it works for the other use cases as well.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe what is needed is an extensible casing lib e.g. with an Option type like WithDelimiters(delim ...string) and ToUpperCamelCase(s string, opts ...Option) string

Anyways, thanks for the clarification. It's a tad confusing when we'd use one or the other rn, so I think we should try to replace strcase with this sooner rather than later if possible.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ack, here's a tracking issue: #1150. Agreed that mixed usage is confusing: i'll follow up to try to clean that up.

Once nice thing about our own handrolled one is we can add options as needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

AIP-122, AIP-123: Validate the singular and plural fields of google.api.resource annotations.
2 participants