8000 Further path improvements by Copilot · Pull Request #1868 · specmatic/specmatic · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Further path improvements #1868

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

Merged
merged 7 commits into from
May 30, 2025

Conversation

Copilot
Copy link
Contributor
@Copilot Copilot AI commented May 29, 2025

Problem

The current implementation of calculatePath in JSONObjectPattern.kt had limitations when handling deeply nested AnyPattern structures:

  1. DeferredPattern typeAlias information was lost - When AnyPattern contained DeferredPattern references like DeferredPattern("(Address)"), the typeAlias extraction didn't properly handle the parentheses cleanup
  2. Nested JSONObjectPattern inside AnyPattern weren't recursively processed - If an AnyPattern resolved to a JSONObjectPattern that itself contained nested AnyPatterns, those nested paths were not discovered
  3. Inconsistent path formatting for deeply nested structures - Path concatenation didn't properly handle typeAliases throughout multiple levels of nesting

Solution

Key Changes

1. Enhanced AnyPattern.calculatePath()

  • DeferredPattern Handling: Added special logic to extract typeAlias from DeferredPattern.pattern and clean parentheses properly
  • Recursive JSONObjectPattern Processing: When AnyPattern resolves to JSONObjectPattern, recursively call its calculatePath() to discover nested AnyPatterns
  • Improved Path Concatenation: Better handling of typeAlias prefix for nested paths across multiple levels

2. Simplified JSONObjectPattern.calculatePathForAnyPattern()

  • Removed complex path structure detection since AnyPattern now handles this properly
  • Streamlined to handle multiple paths returned from AnyPattern.calculatePath()

Examples

Before: DeferredPattern typeAlias extraction was inconsistent

// DeferredPattern("(Address)") might not properly extract "Address"

After: Proper typeAlias extraction and nested path discovery

// DeferredPattern("(Address)") correctly extracts "Address" as typeAlias
// Nested structures like AnyPattern -> JSONObjectPattern -> AnyPattern 
// now return complete paths like "TypeAlias.nestedField{string}"

Test Coverage

Added comprehensive test cases covering all scenarios mentioned in the requirements:

  • Deeply nested AnyPattern with typeAlias at multiple levels
  • AnyPattern containing JSONObjectPattern with nested AnyPatterns
  • DeferredPattern handling without direct typeAlias
  • Multiple levels of nesting without typeAlias
  • OneOf scenarios at deeper levels (level 3)

Backward Compatibility

All changes are backward compatible and maintain existing functionality while extending capabilities for deeply nested structures. Existing test cases continue to pass with the same expected behavior.

Files Changed

  • core/src/main/kotlin/io/specmatic/core/pattern/AnyPattern.kt - Enhanced calculatePath method
  • core/src/main/kotlin/io/specmatic/core/pattern/JSONObjectPattern.kt - Simplified path handling
  • core/src/test/kotlin/io/specmatic/core/CalculatePathTest.kt - Added comprehensive test coverage

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 3 commits May 29, 2025 20:04
…rredPattern

Co-authored-by: joelrosario <63343+joelrosario@users.noreply.github.com>
Co-authored-by: joelrosario <63343+joelrosario@users.noreply.github.com>
Co-authored-by: joelrosario <63343+joelrosario@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] Enhance nested AnyPattern support in calculatePath Improve handling of nested AnyPattern scenarios with better typeAlias and DeferredPattern support May 29, 2025
@Copilot Copilot AI requested a review from joelrosario May 29, 2025 20:10
Copilot finished work on behalf of joelrosario May 29, 2025 20:10
@joelrosario joelrosario changed the title Improve handling of nested AnyPattern scenarios with better typeAlias and DeferredPattern support Further path improvements May 30, 2025
Co-authored-by: joelrosario <63343+joelrosario@users.noreply.github.com>
Copy link
Contributor Author
Copilot AI commented May 30, 2025

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

If you need me to access, download, or install something from one of these locations, you can either:

Copilot finished work on behalf of joelrosario May 30, 2025 04:55
…eadability

Co-authored-by: joelrosario <63343+joelrosario@users.noreply.github.com>
Copilot finished work on behalf of joelrosario May 30, 2025 05:24
@joelrosario joelrosario marked this pull request as ready for review May 30, 2025 07:18
@joelrosario joelrosario merged commit 0a6eda6 into main May 30, 2025
1 check failed
@joelrosario joelrosario deleted the copilot/fix-a92f6387-2747-4260-bfb9-9bc4fcb19006 branch May 30, 2025 07:18
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.

2 participants
0