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

Update toSnakeCase to better handle plurals, version numbers, and other pathological cases #3037

Merged
merged 4 commits into from
Oct 10, 2023

Conversation

rcoh
Copy link
Collaborator

@rcoh rcoh commented Oct 6, 2023

Motivation and Context

There are currently a lot of fields in the SDK that are clearly converted to snake-case wrong:
Screenshot 2023-10-09 at 12 00 43 PM
Screenshot 2023-10-09 at 12 02 48 PM

Description

  • Author a new splitWords algorithm
  • Add snapshot test
  • Add lots of individual tests.

Testing

  • snapshot testing, compared with current behavior.

Checklist

  • I have updated CHANGELOG.next.toml if I made changes to the smithy-rs codegen or runtime crates
  • I have updated CHANGELOG.next.toml if I made changes to the AWS SDK, generated SDK code, or SDK runtime crates

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@github-actions
Copy link

github-actions bot commented Oct 6, 2023

A new generated diff is ready to view.

A new doc preview is ready to view.

@rcoh rcoh changed the title update Update toSnakeCase to better handle plurals, version numbers, and other pathological cases Oct 6, 2023
@github-actions
Copy link

github-actions bot commented Oct 6, 2023

A new generated diff is ready to view.

  • AWS SDK (ignoring whitespace)
  • No codegen difference in the Client Test
  • No codegen difference in the Server Test
  • No codegen difference in the Server Test Python
  • No codegen difference in the Server Test Typescript

A new doc preview is ready to view.

@rcoh rcoh added the breaking-change This will require a breaking change label Oct 9, 2023
@rcoh rcoh marked this pull request as ready for review October 9, 2023 15:53
@rcoh rcoh requested review from a team as code owners October 9, 2023 15:53
@github-actions
Copy link

github-actions bot commented Oct 9, 2023

A new generated diff is ready to view.

  • AWS SDK (ignoring whitespace)
  • No codegen difference in the Client Test
  • No codegen difference in the Server Test
  • No codegen difference in the Server Test Python
  • No codegen difference in the Server Test Typescript

A new doc preview is ready to view.

@github-actions
Copy link

github-actions bot commented Oct 9, 2023

A new generated diff is ready to view.

  • AWS SDK (ignoring whitespace)
  • No codegen difference in the Client Test
  • No codegen difference in the Server Test
  • No codegen difference in the Server Test Python
  • No codegen difference in the Server Test Typescript

A new doc preview is ready to view.

private fun String.splitOnWordBoundaries(): List<String> {
val out = mutableListOf<String>()
// These are whole words but cased differently, e.g. `IPv4`, `MiB`, `GiB`, `TtL`
val completeWords = listOf("ipv4", "ipv6", "sigv4", "mib", "gib", "ttl")
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Will the algorithm work correctly if we add a word to the list that has a substring of it already in the list? For example, if "sigv4a" is added to the list?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we add "kib" to be future proof?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yeah should work (but sigv4a should probably work properly already because the issue is about when you get to the capital V)

private fun String.splitOnWordBoundaries(): List<String> {
val out = mutableListOf<String>()
// These are whole words but cased differently, e.g. `IPv4`, `MiB`, `GiB`, `TtL`
val completeWords = listOf("ipv4", "ipv6", "sigv4", "mib", "gib", "ttl")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we add "kib" to be future proof?

This commit introduces a word splitting algorithm used for snake casing that has much better results than the current Smithy algorithm. Specifically, it has better behavior for
acronyms ending in `s`, version numbers, and compound acronyms like `MiB` and `GiB`.
@github-actions
Copy link

github-actions bot commented Oct 9, 2023

A new generated diff is ready to view.

  • AWS SDK (ignoring whitespace)
  • No codegen difference in the Client Test
  • No codegen difference in the Server Test
  • No codegen difference in the Server Test Python
  • No codegen difference in the Server Test Typescript

A new doc preview is ready to view.

@github-actions
Copy link

A new generated diff is ready to view.

  • AWS SDK (ignoring whitespace)
  • No codegen difference in the Client Test
  • No codegen difference in the Server Test
  • No codegen difference in the Server Test Python
  • No codegen difference in the Server Test Typescript

A new doc preview is ready to view.

@github-actions
Copy link

A new generated diff is ready to view.

  • AWS SDK (ignoring whitespace)
  • No codegen difference in the Client Test
  • No codegen difference in the Server Test
  • No codegen difference in the Server Test Python
  • No codegen difference in the Server Test Typescript

A new doc preview is ready to view.

@rcoh rcoh added this pull request to the merge queue Oct 10, 2023
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Oct 10, 2023
@rcoh rcoh added this pull request to the merge queue Oct 10, 2023
Merged via the queue into main with commit e61fb6f Oct 10, 2023
40 of 41 checks passed
@rcoh rcoh deleted the fix-casing branch October 10, 2023 16:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking-change This will require a breaking change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants