Skip to content

refactor: centralize Camel URI syntax analysis - #3576

Merged
PVinaches merged 2 commits into
KaotoIO:mainfrom
snowyukitty:refactor/camel-uri-analyze-syntax
Jul 31, 2026
Merged

PVinaches merged 2 commits into
KaotoIO:mainfrom
snowyukitty:refactor/camel-uri-analyze-syntax

Conversation

@snowyukitty

@snowyukitty snowyukitty commented Jul 29, 2026 •

Copy link
Copy Markdown
Contributor

Description

Centralize Camel URI syntax-template analysis in one private analyzeSyntax helper. Path serialization and parsing now obtain their syntax-template metadata from the same helper, while keeping runtime URI handling separate.

The maintainer-requested follow-up replaces the global-regex String.match() call with iterative RegExp.exec() matching to address Sonar S6594 without dropping repeated or mixed URI delimiters.

Closes #3558

Type of Change

  • Bug fix
  • New feature
  • Improvement
  • Documentation update
  • Other (please describe)

How Has This Been Tested?

  • yarn workspace @kaoto/kaoto test src/utils/camel-uri-helper.test.ts (103 passed)
  • yarn workspace @kaoto/kaoto test --maxWorkers=8 (480 test files passed, 1 skipped; 6947 tests passed, 5 skipped, 2 todo)
  • yarn workspace @kaoto/kaoto lint
  • yarn workspace @kaoto/kaoto lint:style
  • yarn workspace @kaoto/kaoto build

Checklist

  • I have read the Contributing Guidelines.
  • I have followed the coding style and conventions of the project.
  • I have tested my changes and ensured that they work as expected.
  • I have updated any relevant documentation.
  • I have added tests that prove my fix or feature works.

AI assistance

AI assistance: I used an AI coding assistant to help implement and review this refactor. I reviewed the changes and test results and take responsibility for the contribution.

Summary by CodeRabbit

  • Bug Fixes

    • Improved URI parsing and parameter serialization for consistent handling across supported URI formats.
    • Enhanced support for simple, delimited, protocol-style, and fragment-based URI patterns.
  • Tests

    • Added comprehensive coverage for URI syntax handling, including delimiters, schemas, and parameter extraction.

@coderabbitai

coderabbitai Bot commented Jul 29, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

CamelUriHelper centralizes URI syntax analysis in analyzeSyntax(), and both URI serialization and parameter extraction consume its shared metadata. Tests cover representative syntax patterns.

Changes

Camel URI syntax handling

Layer / File(s) Summary
Canonical syntax analyzer and coverage
packages/ui/src/utils/camel-uri-helper.ts, packages/ui/src/utils/camel-uri-helper.test.ts
Adds the SyntaxAnalysis structure and analyzeSyntax() helper, with parameterized tests for schema, delimiters, regex, and keys.
URI builder and parser integration
packages/ui/src/utils/camel-uri-helper.ts
Updates URI construction and path parameter extraction to use shared syntax metadata instead of duplicating delimiter and key derivation.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested reviewers: lordrip

Poem

I’m a rabbit with syntax tucked neat,
One helper makes parsing complete.
Delimiters align,
Keys hop into line,
And URI paths march to the beat.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The implementation centralizes syntax analysis for serialization and parsing, preserves behavior categories, and adds regression tests as required by [#3558].
Out of Scope Changes check ✅ Passed The changes are limited to the requested CamelUriHelper refactor and focused regression tests, with no unrelated scope identified.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the centralization of Camel URI syntax analysis, matching the primary refactoring in the changeset.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

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

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

🧹 Nitpick comments (1)
packages/ui/src/utils/camel-uri-helper.test.ts (1)

452-507: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Add a regression case for overlapping delimiters.

Add a syntax such as foo:path/segment//tail and assert that the delimiter regex matches // before /, with keys ['path', 'segment', '', 'tail']. This test would prevent the parser regression described in analyzeSyntax.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/ui/src/utils/camel-uri-helper.test.ts` around lines 452 - 507, Add
an analyzeSyntax regression case for foo:path/segment//tail, asserting
delimiters recognize the overlapping // token before the single / token and
produce keys ['path', 'segment', '', 'tail']; keep the test alongside the
existing canonical syntax cases in the analyzeSyntax suite.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/ui/src/utils/camel-uri-helper.ts`:
- Around line 218-222: Normalize delimiter matches in the split-regex
construction near URI separator parsing by escaping each delimiter and ordering
them longest-first before joining them, so overlapping separators such as "/"
and "//" match the longer token first. Add mixed-delimiter coverage in
packages/ui/src/utils/camel-uri-helper.test.ts within the existing delimiter
parsing tests, verifying both source and test behavior for syntaxes like
example:x/y//z:w:a.

---

Nitpick comments:
In `@packages/ui/src/utils/camel-uri-helper.test.ts`:
- Around line 452-507: Add an analyzeSyntax regression case for
foo:path/segment//tail, asserting delimiters recognize the overlapping // token
before the single / token and produce keys ['path', 'segment', '', 'tail']; keep
the test alongside the existing canonical syntax cases in the analyzeSyntax
suite.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: b9ab7560-b1a3-4aff-99a6-5114e5315eca

📥 Commits

Reviewing files that changed from the base of the PR and between 795743a and c1566fe.

📒 Files selected for processing (2)
  • packages/ui/src/utils/camel-uri-helper.test.ts
  • packages/ui/src/utils/camel-uri-helper.ts

@PVinaches

Copy link
Copy Markdown
Member

Hello! Thanks for checking this issue. Could you also fix the sonarqube issue, please?

@snowyukitty

Copy link
Copy Markdown
Contributor Author

No problem - I'll take care of the SonarQube issue. Thanks for pointing it out!

@snowyukitty
snowyukitty force-pushed the refactor/camel-uri-analyze-syntax branch from c1566fe to 7c55439 Compare July 31, 2026 00:49
@sonarqubecloud

Copy link
Copy Markdown

@coderabbitai coderabbitai 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.

🧹 Nitpick comments (1)
packages/ui/src/utils/camel-uri-helper.ts (1)

227-228: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick win

Bound the generated delimiter regex.

Line 227 preserves every separator occurrence, so templates with repeated separators create a regex with repeated alternatives whose size grows with the syntax length. Prefer a bounded matcher or deduplicated delimiter set while preserving the existing discovery order and behavior.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/ui/src/utils/camel-uri-helper.ts` around lines 227 - 228,
Deduplicate the delimiter alternatives before constructing delimiterRegex so
repeated separators in syntax cannot make the generated matcher grow with every
occurrence. Preserve the first-seen discovery order and existing syntax.split
behavior, including the null-delimiter path.

Source: Linters/SAST tools

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@packages/ui/src/utils/camel-uri-helper.ts`:
- Around line 227-228: Deduplicate the delimiter alternatives before
constructing delimiterRegex so repeated separators in syntax cannot make the
generated matcher grow with every occurrence. Preserve the first-seen discovery
order and existing syntax.split behavior, including the null-delimiter path.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: e8cf11c7-ec38-43f8-96ad-85249c902cf4

📥 Commits

Reviewing files that changed from the base of the PR and between c1566fe and 7c55439.

📒 Files selected for processing (2)
  • packages/ui/src/utils/camel-uri-helper.test.ts
  • packages/ui/src/utils/camel-uri-helper.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/ui/src/utils/camel-uri-helper.test.ts

@PVinaches PVinaches left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM. Thanks for working on this issue!

@PVinaches
PVinaches merged commit 86e02eb into KaotoIO:main Jul 31, 2026
20 of 21 checks passed
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.

Refactor CamelUriHelper syntax parsing into a canonical analyzeSyntax helper

2 participants