Federico Mariani created CAMEL-25663:
----------------------------------------
Summary: 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
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)