Skip to content

feat(routing): validation for configs#10133

Merged
likhinbopanna merged 7 commits intomainfrom
feat-validation-for-configs
Nov 10, 2025
Merged

feat(routing): validation for configs#10133
likhinbopanna merged 7 commits intomainfrom
feat-validation-for-configs

Conversation

@AnkitKmrGupta
Copy link
Contributor

@AnkitKmrGupta AnkitKmrGupta commented Nov 5, 2025

Type of Change

  • Bugfix
  • New feature
  • Enhancement
  • Refactoring
  • Dependency updates
  • Documentation
  • CI/CD

Tagged Issue
juspay/hyperswitch-cloud/issues/11764

Description

This pull request introduces validation logic for routing configuration objects and improves error handling for dynamic routing setup. The main changes ensure that required fields are present in routing configs and provide clearer error messages when configurations are missing or invalid.

Routing Configuration Validation

  • Added a validate method to EliminationRoutingConfig and SuccessBasedRoutingConfig to check that at least one required field is present; returns a validation error if all fields are null. [1] [2]

Error Handling Improvements

  • Updated create_specific_dynamic_routing_setup to call the new validate methods and return a specific error if the configuration is invalid, with a clear message about missing fields. [1] [2]
  • Improved error mapping in link_routing_config to distinguish between not-found and internal server errors, providing more descriptive error contexts.

Code Maintenance

  • Added fp_utils to imports in crates/api_models/src/routing.rs to support the new validation logic.

Routing Algorithm Logic

  • Updated logic in DynamicRoutingAlgorithmRef to return false if algorithm_id is missing, ensuring more robust feature checks.

How did you test it?

create success_based with empty payload

curl --location 'http://localhost:8080/account/merchant_1762366132/business_profile/pro_OvIAO1lNAyVksNftih0N/dynamic_routing/success_based/create?enable=dynamic_connector_selection' \
--header 'Content-Type: application/json' \
--header 'api-key:****' \
--data '{}'
{
    "error": {
        "type": "invalid_request",
        "message": "All fields in SuccessBasedRoutingConfig cannot be null",
        "code": "IR_06"
    }
}

activate routing algo without descision_engine_config

curl --location 'http://localhost:8080/routing/routing_DkSrtH3FRM8olK7Mmf5s/activate' \
--header 'Content-Type: application/json' \
--header 'api-key:**** \
--data '{}'
{
    "error": {
        "type": "invalid_request",
        "message": "Config key does not exist in our records.",
        "code": "HE_02"
    }
}

Checklist

  • I formatted the code cargo +nightly fmt --all
  • I addressed lints thrown by cargo clippy
  • I reviewed the submitted code
  • I added unit tests for my changes where possible

@AnkitKmrGupta AnkitKmrGupta requested a review from a team as a code owner November 5, 2025 10:25
@semanticdiff-com
Copy link

semanticdiff-com bot commented Nov 5, 2025

Review changes with  SemanticDiff

Changed Files
File Status
  crates/router/src/core/routing/helpers.rs  30% smaller
  crates/router/src/core/routing.rs  30% smaller
  crates/api_models/src/routing.rs  1% smaller

@AnkitKmrGupta AnkitKmrGupta self-assigned this Nov 5, 2025
@codecov
Copy link

codecov bot commented Nov 5, 2025

Codecov Report

❌ Patch coverage is 0% with 37 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (main@1d3def3). Learn more about missing BASE report.

Files with missing lines Patch % Lines
crates/api_models/src/routing.rs 0.00% 37 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main   #10133   +/-   ##
=======================================
  Coverage        ?    3.89%           
=======================================
  Files           ?     1224           
  Lines           ?   303434           
  Branches        ?        0           
=======================================
  Hits            ?    11804           
  Misses          ?   291630           
  Partials        ?        0           

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@AnkitKmrGupta AnkitKmrGupta changed the title fix: validation for configs fix(routing): validation for configs Nov 6, 2025
@AnkitKmrGupta AnkitKmrGupta linked an issue Nov 6, 2025 that may be closed by this pull request
jagan-jaya
jagan-jaya previously approved these changes Nov 6, 2025
@AnkitKmrGupta AnkitKmrGupta changed the title fix(routing): validation for configs feat(routing): validation for configs Nov 6, 2025
@AnkitKmrGupta AnkitKmrGupta changed the title feat(routing): validation for configs fix(routing): validation for configs Nov 6, 2025
@AnkitKmrGupta AnkitKmrGupta changed the title fix(routing): validation for configs featrouting): validation for configs Nov 10, 2025
@AnkitKmrGupta AnkitKmrGupta changed the title featrouting): validation for configs feat(routing): validation for configs Nov 10, 2025
@likhinbopanna likhinbopanna added this pull request to the merge queue Nov 10, 2025
Merged via the queue into main with commit 0e287d7 Nov 10, 2025
40 of 43 checks passed
@likhinbopanna likhinbopanna deleted the feat-validation-for-configs branch November 10, 2025 13:21
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.

feat(routing): validation for configs

4 participants