Brijesh-Thakkar opened a new pull request, #26755:
URL: https://github.com/apache/camel/pull/26755

   # Description
   
   When a REST OpenAPI contract's `servers[0].url` has no path component
   (e.g. `http://localhost:8080` instead of `http://localhost:8080/api`),
   the REST DSL still registered the operations from the contract, but
   every request to them returned a 404 via platform-http's "Resource
   not found" page. The same contract with a path in the servers URL
   (e.g. `http://localhost:8080/api`) worked correctly.
   
   ## Root cause
   
   `RestOpenApiHelper.getBasePathFromOpenApi(OpenAPI)` correctly returns
   an empty string `""` when the server URL has no path. However, both
   `RestOpenApiHelper.determineBasePath(...)` and
   `RestOpenApiEndpoint.determineBasePath(OpenAPI)` treated that empty
   string as "not specified" (via `isNotEmpty(specificationBasePath)`),
   so they fell through to `RestOpenApiComponent.DEFAULT_BASE_PATH`
   (`"/"`) instead. This `"/"` was then passed, unnormalized, into the
   consumer-creation path (`RestOpenApiEndpoint.createConsumerFor`),
   producing a registered/matched request path that differed from what
   the contract's operations actually expected, causing the 404.
   
   ## Fix
   
   In both `RestOpenApiHelper.determineBasePath` and
   `RestOpenApiEndpoint.determineBasePath`, only fall back to
   `DEFAULT_BASE_PATH` when the OpenAPI document has no `servers` entry
   at all (`servers == null || servers.isEmpty()`). When a `servers`
   entry is present but its URL has no path, the resulting empty base
   path (`""`) is now correctly honored instead of being overridden by
   the `"/"` default.
   
   ## Testing
   
   Added 
`RestOpenApiEndpointV3Test#shouldDetermineEmptyBasePathFromOpenApiServer`,
   which asserts that:
   - `RestOpenApiHelper.getBasePathFromOpenApi(...)` returns an empty
     base path for a servers URL with no path (already correct).
   - `RestOpenApiEndpoint.determineBasePath(...)` also returns an empty
     base path in the same scenario (previously returned `"/"`,
     reproducing the reported bug).
   
   Ran the full `camel-rest-openapi` module test suite locally; all
   tests pass.
   
   # Target
   
   - [x] I checked that the commit is targeting the correct branch (Camel 4 
uses the `main` branch)
   
   # Tracking
   - [x] Filed as 
[CAMEL-24825](https://issues.apache.org/jira/browse/CAMEL-24825)
   
   # Apache Camel coding standards and style
   
   - [x] I checked that each commit in the pull request has a meaningful 
subject line and body.
   - [ ] I have run `mvn clean install -DskipTests` locally from root folder 
and I have committed all auto-generated changes.
   
   # AI-assisted contributions
   
   - [x] This PR includes AI-assisted work. Claude (Anthropic) was used to help 
localize the root cause, draft the fix, and write the accompanying test. 
Commits include `Co-authored-by: Claude <[email protected]>` trailers where 
applicable.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to