Skip to content

Feat/ser/length#60

Merged
j03-dev merged 2 commits intomainfrom
feat/ser/length
Jul 7, 2025
Merged

Feat/ser/length#60
j03-dev merged 2 commits intomainfrom
feat/ser/length

Conversation

@j03-dev
Copy link
Copy Markdown
Owner

@j03-dev j03-dev commented Jul 7, 2025

Summary by CodeRabbit

  • New Features

    • Added support for a new optional length attribute to fields, allowing users to specify a fixed length for applicable fields.
  • Documentation

    • Updated documentation to include details about the new length parameter for fields.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Jul 7, 2025

Walkthrough

The changes add an optional length attribute to the Field struct and its Python bindings, update the constructor signatures and documentation, and modify JSON schema serialization logic to use length for both minLength and maxLength when set. The macro for generating field subclasses is also updated to support this new parameter.

Changes

File(s) Change Summary
src/serializer/fields.rs Added optional length field to Field struct, updated constructor, JSON schema logic, and docs.
src/serializer/fields.rs (macro) Updated define_fields! macro to include length in generated subclasses and their constructors.

Sequence Diagram(s)

sequenceDiagram
    participant PythonUser
    participant PyFieldClass
    participant RustFieldStruct

    PythonUser->>PyFieldClass: Create Field(length=5)
    PyFieldClass->>RustFieldStruct: new(length=Some(5))
    PythonUser->>PyFieldClass: Call to_json_schema_value()
    PyFieldClass->>RustFieldStruct: to_json_schema_value()
    RustFieldStruct-->>PyFieldClass: JSON schema with minLength=5, maxLength=5
    PyFieldClass-->>PythonUser: Return JSON schema
Loading

Poem

A field now has a length to show,
In schema seeds the bounds will grow.
Macros learn a brand new trick,
Constructors gain a length to pick.
Rust and Python, side by side—
In harmony, their types abide!
🥕

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 Clippy (1.86.0)
Updating crates.io index

warning: failed to write cache, path: /usr/local/registry/index/index.crates.io-1949cf8c6b5b557f/.cache/ah/as/ahash, error: Permission denied (os error 13)
Downloading crates ...
Downloaded autocfg v1.4.0
error: failed to create directory /usr/local/registry/cache/index.crates.io-1949cf8c6b5b557f

Caused by:
Permission denied (os error 13)

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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>, please review it.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • 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/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Copy Markdown
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.

Actionable comments posted: 0

🧹 Nitpick comments (2)
src/serializer/fields.rs (2)

44-44: Consider clarifying the interaction between length and min_length/max_length.

The documentation should explain that when length is specified, it takes precedence over min_length and max_length parameters, setting both minLength and maxLength to the same value in the JSON schema.

-    ///     length (int, optional): Length for string fields.
+    ///     length (int, optional): Exact length for string fields. When set, overrides `min_length` and `max_length`.

97-102: Update capacity calculation to account for the new length field.

The capacity calculation doesn't account for the fact that when length is specified, both minLength and maxLength are added to the schema (2 entries), potentially causing map reallocation.

 let capacity = 1
     + self.format.is_some() as usize
-    + self.min_length.is_some() as usize
-    + self.max_length.is_some() as usize
+    + if self.length.is_some() { 2 } else { self.min_length.is_some() as usize + self.max_length.is_some() as usize }
     + self.pattern.is_some() as usize
     + self.enum_values.is_some() as usize;
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 545c446 and b01dd36.

📒 Files selected for processing (1)
  • src/serializer/fields.rs (10 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (14)
  • GitHub Check: linux (ubuntu-22.04, ppc64le)
  • GitHub Check: macos (macos-14, aarch64)
  • GitHub Check: windows (windows-latest, x64)
  • GitHub Check: windows (windows-latest, x86)
  • GitHub Check: macos (macos-13, x86_64)
  • GitHub Check: linux (ubuntu-22.04, s390x)
  • GitHub Check: linux (ubuntu-22.04, aarch64)
  • GitHub Check: linux (ubuntu-22.04, armv7)
  • GitHub Check: musllinux (ubuntu-22.04, x86_64)
  • GitHub Check: linux (ubuntu-22.04, x86_64)
  • GitHub Check: musllinux (ubuntu-22.04, aarch64)
  • GitHub Check: musllinux (ubuntu-22.04, x86)
  • GitHub Check: linux (ubuntu-22.04, x86)
  • GitHub Check: musllinux (ubuntu-22.04, armv7)
🔇 Additional comments (3)
src/serializer/fields.rs (3)

19-20: LGTM! Field addition is properly implemented.

The new length field is correctly added with appropriate Python binding annotation and consistent typing with other length-related fields.


116-126: LGTM! The JSON schema logic correctly prioritizes length over individual min/max constraints.

The implementation properly handles the semantic meaning where length represents an exact length constraint, setting both minLength and maxLength to the same value.


189-189: LGTM! Macro updates are consistent with the base struct changes.

The define_fields! macro correctly includes the new length parameter in all generated field subclasses, maintaining consistency across the codebase.

Also applies to: 200-200, 214-214

@j03-dev j03-dev linked an issue Jul 7, 2025 that may be closed by this pull request
@j03-dev j03-dev merged commit 0021941 into main Jul 7, 2025
17 checks passed
@j03-dev j03-dev deleted the feat/ser/length branch July 7, 2025 23:53
@coderabbitai coderabbitai bot mentioned this pull request Jul 9, 2025
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.

length of serializer fields

1 participant