[ 
https://issues.apache.org/jira/browse/CAMEL-25663?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18127459#comment-18127459
 ] 

Andrea Cosentino commented on CAMEL-25663:
------------------------------------------

PR opened: https://github.com/apache/camel/pull/27897

DefaultRestOpenapiProcessorStrategy.loadMockData now guards the null 200 
ApiResponse, so an operation whose responses have no 200 (only 201, 204, 
default, 2XX, ...) returns an empty 204 in mock mode instead of throwing a 
NullPointerException. Unit test added in RestOpenapiProcessorStrategyTest.

_Claude Code on behalf of oscerd_

> camel-rest-openapi - mock mode throws NullPointerException for an operation 
> without a 200 response when no mock file matches
> ----------------------------------------------------------------------------------------------------------------------------
>
>                 Key: CAMEL-25663
>                 URL: https://issues.apache.org/jira/browse/CAMEL-25663
>             Project: Camel
>          Issue Type: Bug
>          Components: camel-rest-openapi
>            Reporter: Federico Mariani
>            Assignee: Andrea Cosentino
>            Priority: Major
>
> In mock mode ({{missingOperation=mock}}), 
> {{DefaultRestOpenapiProcessorStrategy.loadMockData}} 
> (components/camel-rest-openapi, main 4.23.0-SNAPSHOT, around line 333) falls 
> back to the example of the {{200}} response when no mock file matches the 
> request:
> {code:java}
> if (operation.getResponses() != null) {
>     ApiResponse a = operation.getResponses().get("200");
>     Content c = a.getContent();
> {code}
> {{a}} is null for an operation whose responses do not include {{200}} (for 
> example only {{201}}, {{204}}, {{default}} or {{2XX}}), so the request fails 
> with a {{NullPointerException}} instead of the documented "returns an empty 
> body with 204" behaviour. Reproduced in-process while writing the test of the 
> camel-jbang-mcp scaffold (CAMEL-25642 section C): a GET operation of the 
> petstore spec with only a {{default}} response, no mock file, 
> {{missingOperation=mock}}.
> Fix: treat a missing {{200}} (and a {{200}} without content) like "no 
> example": answer 204 with an empty body, or fall back to the first {{2xx}} / 
> {{default}} response that has content.
> _Claude Code on behalf of Croway_



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to