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

fix(grpc): schema validation for fields in snake_case #1527

Merged
merged 1 commit into from
Mar 20, 2024
Merged

Conversation

meskill
Copy link
Contributor

@meskill meskill commented Mar 20, 2024

Summary:
Following by grpc style guide fields should be named in snake_case. prost also automatically converts snake_case naming to camelCase and other way around on serde serialization/deserialization for protobuf message. But the schema validation in tailcall was only checking raw name fields without considering that conversion happening.

This pr changes proto naming style to follow grpc guide and updates schema validation to execute the comparison between camelCase field names

Build & Testing:

  • I ran cargo test successfully.
  • I have run ./lint.sh --mode=fix to fix all linting issues raised by ./lint.sh --mode=check.

Checklist:

  • I have added relevant unit & integration tests.
  • I have updated the documentation accordingly.
  • I have performed a self-review of my code.
  • PR follows the naming convention of <type>(<optional scope>): <title>

Summary by CodeRabbit

  • Refactor
    • Improved code visibility and external testing capabilities.
  • Style
    • Standardized field naming conventions across protobuf definitions.
  • New Features
    • Enhanced JSON schema support with automatic snake_case to camelCase conversion for field names.

Copy link
Contributor

coderabbitai bot commented Mar 20, 2024

Walkthrough

The recent modifications enhance visibility and naming conventions across several components, with a focus on gRPC and JSON handling. The changes make certain functions public for broader testing, improve field naming consistency in protobuf definitions, and incorporate a case conversion utility to ensure JSON schema field names adhere to camelCase standards. Additionally, there's an emphasis on facilitating protobuf to JSON conversion testing, indicating a stride towards more flexible and interoperable data handling.

Changes

Files Change Summaries
src/grpc/protobuf.rs - Made get_proto_file public
- Made tests module public
src/grpc/tests/proto/news.proto
src/grpc/tests/proto/news_no_pkg.proto
- Renamed field postImage to post_image
src/json/json_schema.rs - Added convert_case crate
- Modified field name insertion to camelCase
- Added camelCase conversion & imports

Poem

🐇✨
In the realm of code, where binaries roam,
A rabbit hopped, making it home.
"Let's tidy up," it said with glee,
Fields in camelCase, for you and me.
🌟 Protos gleam, JSON sings,
Unified changes, joy it brings.
With every hop, the rabbit knew,
Better code, for me and you.
🐇✨

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit-tests for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit tests for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

@github-actions github-actions bot added the type: fix Iterations on existing features or infrastructure. label Mar 20, 2024
Copy link

codecov bot commented Mar 20, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 88.36%. Comparing base (d591d33) to head (f822c49).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1527      +/-   ##
==========================================
+ Coverage   88.34%   88.36%   +0.01%     
==========================================
  Files         135      135              
  Lines       14611    14631      +20     
==========================================
+ Hits        12908    12928      +20     
  Misses       1703     1703              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@meskill
Copy link
Contributor Author

meskill commented Mar 20, 2024

updated the examples tailcallhq/rust-grpc#15 and tailcallhq/node-grpc#5

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between d591d33 and f822c49.
Files ignored due to path filters (2)
  • Cargo.lock is excluded by: !**/*.lock
  • Cargo.toml is excluded by: !**/*.toml
Files selected for processing (4)
  • src/grpc/protobuf.rs (2 hunks)
  • src/grpc/tests/proto/news.proto (1 hunks)
  • src/grpc/tests/proto/news_no_pkg.proto (1 hunks)
  • src/json/json_schema.rs (4 hunks)
Files skipped from review due to trivial changes (1)
  • src/grpc/tests/proto/news.proto
Additional comments: 5
src/grpc/tests/proto/news_no_pkg.proto (1)
  • 9-9: The field renaming from postImage to post_image correctly follows the gRPC style guide's recommendation for using snake_case in protobuf message fields. Good job adhering to the conventions.
src/json/json_schema.rs (2)
  • 3-3: The addition of the convert_case crate is a suitable choice for converting field names from snake_case to camelCase, aligning with the PR objectives and the prost library's behavior.
  • 162-165: Correctly implementing the conversion of field names from snake_case to camelCase using the convert_case crate ensures that the schema validation logic aligns with the automatic conversion behavior of the prost library. This is a crucial update for consistency.
src/grpc/protobuf.rs (2)
  • 235-235: Making the get_proto_file function public enhances the testability of the codebase by allowing external access for testing purposes. This is a positive change in line with the PR objectives.
  • 204-204: Making the tests module public is a good practice for facilitating external testing, further improving the testability and maintainability of the codebase.

src/json/json_schema.rs Show resolved Hide resolved
@tusharmath tusharmath enabled auto-merge (squash) March 20, 2024 16:39
@tusharmath tusharmath merged commit 06cbc4a into main Mar 20, 2024
31 checks passed
@tusharmath tusharmath deleted the fix/grpc-case branch March 20, 2024 16:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: fix Iterations on existing features or infrastructure.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants