Skip to content

Flatten property schema validation branching (#36)#197

Draft
leynos wants to merge 1 commit into
mainfrom
issue-36-deep-nested-complexity-refactor-validate-property-schema
Draft

Flatten property schema validation branching (#36)#197
leynos wants to merge 1 commit into
mainfrom
issue-36-deep-nested-complexity-refactor-validate-property-schema

Conversation

@leynos
Copy link
Copy Markdown
Owner

@leynos leynos commented May 22, 2026

Summary

This branch flattens validate_property_schema in the tool schema helper so
array and nested object validation use guard-clause helpers instead of nested
conditionals. The validation rules, error strings and public API remain
unchanged.

Closes #36.

Related review thread: #18.

Review walkthrough

Validation

  • cargo fmt --all: passed.
  • cargo test test_validate_tool_schema_nested_path_uses_child: passed.
  • coderabbit review --agent: passed with 0 findings after one recoverable rate-limit retry.
  • make all: passed, including 4,110 nextest tests and 5 GitHub tool tests.

Notes

  • No public API changes are included.
  • No feature parity status changed; this is an internal refactor only.

Summary by Sourcery

Enhancements:

  • Extract helper functions to validate nested object schemas and array item schemas, simplifying control flow in property schema validation and maintaining current validation rules and error messages.

Split nested array and object handling out of `validate_property_schema`
so the validator keeps the same behaviour while staying below the nesting threshold.
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 22, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: a52f0cbc-7c20-4044-a948-16cf2b9eabd8

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch issue-36-deep-nested-complexity-refactor-validate-property-schema

Comment @coderabbitai help to get the list of available commands and usage tips.

@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai Bot commented May 22, 2026

Reviewer's Guide

Refactors property schema validation to use early returns and small helper functions for object and array types, simplifying control flow without changing validation behavior or public API.

Flow diagram for flattened validate_property_schema control flow

flowchart LR
    A[validate_property_schema] --> B{prop.type present?}
    B -- no --> C[return]
    B -- object --> D[validate_nested_object_schema]
    B -- array --> E[validate_array_items]
    D --> F[validate_tool_schema_at]

    subgraph ArrayValidation
      E --> G{items present?}
      G -- no --> H[push array property missing items]
      G -- yes --> I{is_object_type}
      I -- no --> J[return]
      I -- yes --> K[child items path]
      K --> L[validate_tool_schema_at]
    end
Loading

File-Level Changes

Change Details Files
Flattened validate_property_schema control flow and delegated type-specific logic to helper functions.
  • Replaced nested conditional logic inside validate_property_schema with a match on the resolved type using an early return when type is absent.
  • Delegated object-type property validation to a new helper that forwards to validate_tool_schema_at.
  • Delegated array-type property validation to a new helper that encapsulates item presence/type checks and nested schema validation.
src/tools/tool/schema_helpers.rs
Introduced dedicated helpers for nested object and array item schema validation.
  • Added validate_nested_object_schema helper to wrap validate_tool_schema_at for object properties using the computed property path.
  • Added validate_array_items helper that validates presence of items, checks that items is an object type via is_object_type, and then validates the nested schema at items path.
  • Replaced inline array items validation logic with calls to the new helpers, preserving existing error messages for missing items and overall behavior.
src/tools/tool/schema_helpers.rs

Assessment against linked issues

Issue Objective Addressed Explanation
#36 Reduce the nesting depth of validate_property_schema below the threshold by flattening control flow using guard clauses and helper functions, without changing its externally visible behavior.
#36 Preserve existing behavior, validation rules, and error strings (including for array items and nested object validation) while refactoring.
#36 Avoid public API changes to validate_property_schema and keep the module’s external interface intact while ensuring tests continue to pass.

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@github-actions github-actions Bot added size: S 10-49 changed lines risk: medium Business logic, config, or moderate-risk modules contributor: core 20+ merged PRs labels May 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contributor: core 20+ merged PRs risk: medium Business logic, config, or moderate-risk modules size: S 10-49 changed lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Deep, Nested Complexity: refactor validate_property_schema in src/tools/tool/schema_helpers.rs

1 participant