Fix common base path detection to match only complete path segments#1877
Closed
Fix common base path detection to match only complete path segments#1877
Conversation
|
|
Co-authored-by: TharmiganK <63336800+TharmiganK@users.noreply.github.com>
Co-authored-by: TharmiganK <63336800+TharmiganK@users.noreply.github.com>
|
Copilot
AI
changed the title
[WIP] Fix issue with OASModifier in openapi-tools
Fix common base path detection to match only complete path segments
Jan 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Purpose
When running
bal openapi alignon specs with paths like/v2/organizationsand/v2.1/organizations/{id}/accounts, the base path detection incorrectly matches/v2as a prefix of/v2.1/...due to character-levelstartsWith()matching. This causes paths to become.1/organizations/...(missing leading/).Related: ballerina-platform/ballerina-library#8574
Goals
Ensure common base path extraction only matches complete path segments, not partial segment prefixes.
Approach
Two changes in
OASModifier.java:startsWithPathSegment()- Validates prefix matches at segment boundaries (followed by/or exact match)removeCommonPath()to usesubstring()- Prevents incorrect replacement when path contains repeated segments like/api/api/testUser stories
N/A
Release note
Fixed an issue where
bal openapi alignwould corrupt paths when the API had similar version prefixes (e.g.,/v2/and/v2.1/), causing paths to lose their leading slash.Documentation
N/A - Bug fix with no API changes
Training
N/A
Certification
N/A - Bug fix
Marketing
N/A
Automation tests
testBasePathWithVersionMismatch()inOASModifierTests.javawith test specbasepath_version_mismatch.yamlSecurity checks
Samples
N/A
Related PRs
N/A
Migrations (if applicable)
N/A
Test environment
Java 17
Learning
N/A
Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
maven.wso2.org/usr/lib/jvm/temurin-17-jdk-amd64/bin/java /usr/lib/jvm/temurin-17-jdk-amd64/bin/java --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.lang.invoke=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED --add-opens=java.base/java.nio.charset=ALL-UNNAMED --add-opens=java.base/java.net=ALL-UNNAMED --add-opens=java.base/java.util.concurrent.atomic=ALL-UNNAMED --add-opens=java.xml/javax.xml.namespace=ALL-UNNAMED -Xmx4096M -Dfile.encoding=UTF-8 -Duser.country -Duser.language=en -Duser.variant -cp /home/REDACTED/.gradle/wrapper/dists/gradle-8.11.1-bin/bpt9gzteqjrbo1mjrsomdt32c/gradle-8.11.1/lib/gradle-daemon-main-8.11.1.jar(dns block)testng.org/opt/hostedtoolcache/CodeQL/2.23.9/x64/codeql/tools/linux64/java/bin/java /opt/hostedtoolcache/CodeQL/2.23.9/x64/codeql/tools/linux64/java/bin/java -jar /opt/hostedtoolcache/CodeQL/2.23.9/x64/codeql/xml/tools/xml-extractor.jar --fileList=/home/REDACTED/work/openapi-tools/.codeql-scratch/dbs/java/working/files-to-index16067121267421666683.list --sourceArchiveDir=/home/REDACTED/work/openapi-tools/.codeql-scratch/dbs/java/src --outputDir=/home/REDACTED/work/openapi-tools/.codeql-scratch/dbs/java/trap/java -j ACCEPT(dns block)www.puppycrawl.com/opt/hostedtoolcache/CodeQL/2.23.9/x64/codeql/tools/linux64/java/bin/java /opt/hostedtoolcache/CodeQL/2.23.9/x64/codeql/tools/linux64/java/bin/java -jar /opt/hostedtoolcache/CodeQL/2.23.9/x64/codeql/xml/tools/xml-extractor.jar --fileList=/home/REDACTED/work/openapi-tools/.codeql-scratch/dbs/java/working/files-to-index16067121267421666683.list --sourceArchiveDir=/home/REDACTED/work/openapi-tools/.codeql-scratch/dbs/java/src --outputDir=/home/REDACTED/work/openapi-tools/.codeql-scratch/dbs/java/trap/java -j ACCEPT(dns block)If you need me to access, download, or install something from one of these locations, you can either:
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.