Skip to content

fix(internal/sidekick/rust): match prost-build module snake_case - #7806

Merged
suzmue merged 3 commits into
googleapis:mainfrom
suzmue:prost-module-snake
Oct 27, 2026
Merged

suzmue merged 3 commits into
googleapis:mainfrom
suzmue:prost-module-snake

Conversation

@suzmue

@suzmue suzmue commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

prostMessageModulePath previously used strcase.ToSnake to compute nested message module names for prost conversions. However, strcase.ToSnake inserts an underscore between a letter and a digit, turning names like CVSSv3 into cvs_sv_3, whereas prost-build uses heck::ToSnakeCase which only splits on case transitions and non-alphanumeric boundaries, producing cvs_sv3.

Implement toProstWords and toProstSnake following heck's word boundary rules so that both toProstSnake and toProstPascal match prost-build's identifier formatting.

prostMessageModulePath previously used strcase.ToSnake to compute nested message module names for prost conversions. However, strcase.ToSnake inserts an underscore between a letter and a digit, turning names like CVSSv3 into cvs_sv_3, whereas prost-build uses heck::ToSnakeCase which only splits on case transitions and non-alphanumeric boundaries, producing cvs_sv3.

Implement toProstWords and toProstSnake following heck's word boundary rules so that both toProstSnake and toProstPascal match prost-build's identifier formatting.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request introduces the toProstWords and toProstSnake functions in internal/sidekick/rust/codec.go to align symbol name conversions (snake_case and PascalCase) with the word boundary rules of prost-build (from the Rust heck crate). It also updates escapeKeyword to handle the _ keyword, identifiers starting with digits, and the Rust 2024+ reserved keyword gen. Corresponding unit tests have been added in internal/sidekick/rust/codec_test.go to verify these changes. There are no review comments, so I have no feedback to provide.

@suzmue

suzmue commented Oct 22, 2026

Copy link
Copy Markdown
Contributor Author

Verified the test cases against prost-build = "=0.14.4" (prost_build::Config::new().compile_protos(...)) using this synthetic .proto:

Proto:
syntax = "proto3";
package test.pkg;

message Parent {
  message CVSSv3 { message Nested {} }
  message V2Beta1 { message Nested {} }
  message HTTP2Frame { message Nested {} }
  message OAuth2Config { message Nested {} }
  message VertexAISearch { message Nested {} }
  message XMLHttpRequest { message Nested {} }
  message FIELD_NAME11 { message Nested {} }
  message FieldNamE11 { message Nested {} }
  message Gen { message Nested {} }
  message Self { message Nested {} }
  message Mod { message Nested {} }
  message ABC123dEEf456FOO { message Nested {} }
}
Output generated by `prost-build`:
// This file is @generated by prost-build.
#[derive(Clone, Copy, PartialEq, Eq, Hash, ::prost::Message)]
pub struct Parent {}
/// Nested message and enum types in `Parent`.
pub mod parent {
    #[derive(Clone, Copy, PartialEq, Eq, Hash, ::prost::Message)]
    pub struct CvsSv3 {}
    /// Nested message and enum types in `CVSSv3`.
    pub mod cvs_sv3 {
        #[derive(Clone, Copy, PartialEq, Eq, Hash, ::prost::Message)]
        pub struct Nested {}
    }
    #[derive(Clone, Copy, PartialEq, Eq, Hash, ::prost::Message)]
    pub struct V2Beta1 {}
    /// Nested message and enum types in `V2Beta1`.
    pub mod v2_beta1 {
        #[derive(Clone, Copy, PartialEq, Eq, Hash, ::prost::Message)]
        pub struct Nested {}
    }
    #[derive(Clone, Copy, PartialEq, Eq, Hash, ::prost::Message)]
    pub struct Http2Frame {}
    /// Nested message and enum types in `HTTP2Frame`.
    pub mod http2_frame {
        #[derive(Clone, Copy, PartialEq, Eq, Hash, ::prost::Message)]
        pub struct Nested {}
    }
    #[derive(Clone, Copy, PartialEq, Eq, Hash, ::prost::Message)]
    pub struct OAuth2Config {}
    /// Nested message and enum types in `OAuth2Config`.
    pub mod o_auth2_config {
        #[derive(Clone, Copy, PartialEq, Eq, Hash, ::prost::Message)]
        pub struct Nested {}
    }
    #[derive(Clone, Copy, PartialEq, Eq, Hash, ::prost::Message)]
    pub struct VertexAiSearch {}
    /// Nested message and enum types in `VertexAISearch`.
    pub mod vertex_ai_search {
        #[derive(Clone, Copy, PartialEq, Eq, Hash, ::prost::Message)]
        pub struct Nested {}
    }
    #[derive(Clone, Copy, PartialEq, Eq, Hash, ::prost::Message)]
    pub struct XmlHttpRequest {}
    /// Nested message and enum types in `XMLHttpRequest`.
    pub mod xml_http_request {
        #[derive(Clone, Copy, PartialEq, Eq, Hash, ::prost::Message)]
        pub struct Nested {}
    }
    #[derive(Clone, Copy, PartialEq, Eq, Hash, ::prost::Message)]
    pub struct FieldName11 {}
    /// Nested message and enum types in `FIELD_NAME11`.
    pub mod field_name11 {
        #[derive(Clone, Copy, PartialEq, Eq, Hash, ::prost::Message)]
        pub struct Nested {}
    }
    #[derive(Clone, Copy, PartialEq, Eq, Hash, ::prost::Message)]
    pub struct FieldNamE11 {}
    /// Nested message and enum types in `FieldNamE11`.
    pub mod field_nam_e11 {
        #[derive(Clone, Copy, PartialEq, Eq, Hash, ::prost::Message)]
        pub struct Nested {}
    }
    #[derive(Clone, Copy, PartialEq, Eq, Hash, ::prost::Message)]
    pub struct Gen {}
    /// Nested message and enum types in `Gen`.
    pub mod r#gen {
        #[derive(Clone, Copy, PartialEq, Eq, Hash, ::prost::Message)]
        pub struct Nested {}
    }
    #[derive(Clone, Copy, PartialEq, Eq, Hash, ::prost::Message)]
    pub struct Self_ {}
    /// Nested message and enum types in `Self`.
    pub mod self_ {
        #[derive(Clone, Copy, PartialEq, Eq, Hash, ::prost::Message)]
        pub struct Nested {}
    }
    #[derive(Clone, Copy, PartialEq, Eq, Hash, ::prost::Message)]
    pub struct Mod {}
    /// Nested message and enum types in `Mod`.
    pub mod r#mod {
        #[derive(Clone, Copy, PartialEq, Eq, Hash, ::prost::Message)]
        pub struct Nested {}
    }
    #[derive(Clone, Copy, PartialEq, Eq, Hash, ::prost::Message)]
    pub struct Abc123dEEf456Foo {}
    /// Nested message and enum types in `ABC123dEEf456FOO`.
    pub mod abc123d_e_ef456_foo {
        #[derive(Clone, Copy, PartialEq, Eq, Hash, ::prost::Message)]
        pub struct Nested {}
    }
}

@suzmue
suzmue marked this pull request as ready for review October 22, 2026 17:45
@suzmue
suzmue requested a review from a team as a code owner October 22, 2026 17:45
@suzmue
suzmue enabled auto-merge (squash) October 27, 2026 16:58
@suzmue
suzmue merged commit 8790f1b into googleapis:main Oct 27, 2026
47 checks passed
sofisl pushed a commit that referenced this pull request Oct 27, 2026
🤖 I have created a release *beep* *boop*
---


##
[0.50.0](v0.49.0...v0.50.0)
(2026-10-27)


### Features

* **internal/librarian/java:** parallelize generation and formatting
([#7813](#7813))
([bf3b603](bf3b603))


### Bug Fixes

* **internal/librarian:** check explicit API paths in
findExistingLibraryForAPI
([#7816](#7816))
([00ae0ab](00ae0ab)),
refs [#7814](#7814)
* **internal/sidekick/rust_prost:** map BytesValue
([#7798](#7798))
([7080958](7080958))
* **internal/sidekick/rust:** match prost-build module snake_case
([#7806](#7806))
([8790f1b](8790f1b))
* **sidekick/swift:** support google.api.HttpBody in REST
([#7811](#7811))
([d427811](d427811))
* **swift:** strip backticks from DocC xref links
([#7804](#7804))
([6a931c5](6a931c5)),
refs [#751](#751)

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com>
@suzmue
suzmue deleted the prost-module-snake branch October 27, 2026 17:24
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.

2 participants