[Java][Native] Fix an issue leading to an altered String parameter when consuming formatted strings like XML (#11640)

* Fix the generated request builder when using a string body parameter

* Update the samples according to the fix for #11638
This commit is contained in:
Paul-Etienne François 2022-02-18 04:50:15 +01:00 committed by GitHub
parent d6a97b0c39
commit d45cb6511f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 12 deletions

View File

@ -346,12 +346,17 @@ public class {{classname}} {
localVarRequestBuilder.header("Accept", "{{#hasProduces}}{{#produces}}{{mediaType}}{{^-last}}, {{/-last}}{{/produces}}{{/hasProduces}}{{#hasProduces}}{{^produces}}application/json{{/produces}}{{/hasProduces}}{{^hasProduces}}application/json{{/hasProduces}}"); localVarRequestBuilder.header("Accept", "{{#hasProduces}}{{#produces}}{{mediaType}}{{^-last}}, {{/-last}}{{/produces}}{{/hasProduces}}{{#hasProduces}}{{^produces}}application/json{{/produces}}{{/hasProduces}}{{^hasProduces}}application/json{{/hasProduces}}");
{{#bodyParam}} {{#bodyParam}}
{{#isString}}
localVarRequestBuilder.method("{{httpMethod}}", HttpRequest.BodyPublishers.ofString({{paramName}}));
{{/isString}}
{{^isString}}
try { try {
byte[] localVarPostBody = memberVarObjectMapper.writeValueAsBytes({{paramName}}); byte[] localVarPostBody = memberVarObjectMapper.writeValueAsBytes({{paramName}});
localVarRequestBuilder.method("{{httpMethod}}", HttpRequest.BodyPublishers.ofByteArray(localVarPostBody)); localVarRequestBuilder.method("{{httpMethod}}", HttpRequest.BodyPublishers.ofByteArray(localVarPostBody));
} catch (IOException e) { } catch (IOException e) {
throw new ApiException(e); throw new ApiException(e);
} }
{{/isString}}
{{/bodyParam}} {{/bodyParam}}
{{^bodyParam}} {{^bodyParam}}
localVarRequestBuilder.method("{{httpMethod}}", HttpRequest.BodyPublishers.noBody()); localVarRequestBuilder.method("{{httpMethod}}", HttpRequest.BodyPublishers.noBody());

View File

@ -519,12 +519,7 @@ public class FakeApi {
localVarRequestBuilder.header("Content-Type", "application/json"); localVarRequestBuilder.header("Content-Type", "application/json");
localVarRequestBuilder.header("Accept", "*/*"); localVarRequestBuilder.header("Accept", "*/*");
try { localVarRequestBuilder.method("POST", HttpRequest.BodyPublishers.ofString(body));
byte[] localVarPostBody = memberVarObjectMapper.writeValueAsBytes(body);
localVarRequestBuilder.method("POST", HttpRequest.BodyPublishers.ofByteArray(localVarPostBody));
} catch (IOException e) {
throw new ApiException(e);
}
if (memberVarReadTimeout != null) { if (memberVarReadTimeout != null) {
localVarRequestBuilder.timeout(memberVarReadTimeout); localVarRequestBuilder.timeout(memberVarReadTimeout);
} }

View File

@ -445,12 +445,7 @@ public class FakeApi {
localVarRequestBuilder.header("Content-Type", "application/json"); localVarRequestBuilder.header("Content-Type", "application/json");
localVarRequestBuilder.header("Accept", "*/*"); localVarRequestBuilder.header("Accept", "*/*");
try { localVarRequestBuilder.method("POST", HttpRequest.BodyPublishers.ofString(body));
byte[] localVarPostBody = memberVarObjectMapper.writeValueAsBytes(body);
localVarRequestBuilder.method("POST", HttpRequest.BodyPublishers.ofByteArray(localVarPostBody));
} catch (IOException e) {
throw new ApiException(e);
}
if (memberVarReadTimeout != null) { if (memberVarReadTimeout != null) {
localVarRequestBuilder.timeout(memberVarReadTimeout); localVarRequestBuilder.timeout(memberVarReadTimeout);
} }