[BUG][Java Native] Generator with XML request body alters the XML content and adds surrounding quotes and escape chars
Created by: Paul-Etienne
Bug Report Checklist
-
Have you provided a full/minimal spec to reproduce the issue? -
Have you validated the input using an OpenAPI validator (example)? -
Have you tested with the latest master to confirm the issue still exists? -
Have you searched for related issues/PRs? -
What's the actual output vs expected output? -
[Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
I stumbled upon a bug after fixing another XML related issue on the Java native generator. It turns out, when an endpoint has a XML request body, the generated code uses a ofByteArray()
method rather than ofString()
in the request builder which leads to an altered XML when using the client.
openapi-generator version
This bug is present on the latest version of openapi-generator-maven-plugin
(v5.4.0). I don't see how this could be a regression, I believe it's been present from the beginning.
OpenAPI declaration file content or url
A very simple YAML with a request that has a XML request body is needed to reproduce this issue:
openapi: 3.0.0
info:
title: "Pet Store"
version: 1.0.0
paths:
/pet:
post:
operationId: pet
summary: "Find pet by XML"
requestBody:
required: true
content:
application/xml:
schema:
type: string
responses:
'200':
description: "Pet found"
'404':
description: "Pet not found"
Generation Details
To reproduce this issue, here's the config I've used :
<library>native</library>
<configOptions>
<java8>false</java8>
<sourceFolder>src/gen/java/main</sourceFolder>
<interfaceOnly>true</interfaceOnly>
<delegatePattern>false</delegatePattern>
<useBeanValidation>false</useBeanValidation>
<performBeanValidation>true</performBeanValidation>
<unhandledException>true</unhandledException>
</configOptions>
Steps to reproduce
Create a Maven project using the openapi-generator-maven-plugin
5.4.0 and add an execution step using the provided spec as the input. Look for what should be the lines 143 to 148 of the generated API class and you should see the use of ofByteArray()
.
Now using this generated client in a project and passing a simple XML string as a parameter, you should receive an altered XML on the server side surrounded by double quotes and with every double quotes inside escaped.
Suggest a fix
I have already found a fix that I'm using on my company project through the use of a template. I'm gonna make a PR as soon as possible.