[JAVA] fix toUrlQueryString for BigDecimal (#15764)

* add MyImportTest.java

* fix original issue

* fix same issue for native library

* remove MyImportTest

* add test configs

* generate samples (again?)

* generate samples again

* generate samples again, undo pom.xml mistake [amended to retrigger circliCi]
This commit is contained in:
martin-mfg
2023-06-08 03:34:06 +02:00
committed by GitHub
parent fbe768bb9c
commit b7f2b723aa
176 changed files with 7934 additions and 8 deletions

View File

@@ -19,6 +19,7 @@ import org.openapitools.client.Pair;
import java.math.BigDecimal;
import org.openapitools.client.model.Client;
import org.openapitools.client.model.FakeBigDecimalMap200Response;
import java.io.File;
import org.openapitools.client.model.FileSchemaTestClass;
import org.openapitools.client.model.HealthCheckResult;
@@ -97,6 +98,92 @@ public class FakeApi {
return operationId + " call failed with: " + statusCode + " - " + body;
}
/**
*
* for Java apache and Java native, test toUrlQueryString for maps with BegDecimal keys
* @return CompletableFuture<FakeBigDecimalMap200Response>
* @throws ApiException if fails to make API call
*/
public CompletableFuture<FakeBigDecimalMap200Response> fakeBigDecimalMap() throws ApiException {
try {
HttpRequest.Builder localVarRequestBuilder = fakeBigDecimalMapRequestBuilder();
return memberVarHttpClient.sendAsync(
localVarRequestBuilder.build(),
HttpResponse.BodyHandlers.ofString()).thenComposeAsync(localVarResponse -> {
if (localVarResponse.statusCode()/ 100 != 2) {
return CompletableFuture.failedFuture(getApiException("fakeBigDecimalMap", localVarResponse));
}
try {
String responseBody = localVarResponse.body();
return CompletableFuture.completedFuture(
responseBody == null || responseBody.isBlank() ? null : memberVarObjectMapper.readValue(responseBody, new TypeReference<FakeBigDecimalMap200Response>() {})
);
} catch (IOException e) {
return CompletableFuture.failedFuture(new ApiException(e));
}
});
}
catch (ApiException e) {
return CompletableFuture.failedFuture(e);
}
}
/**
*
* for Java apache and Java native, test toUrlQueryString for maps with BegDecimal keys
* @return CompletableFuture&lt;ApiResponse&lt;FakeBigDecimalMap200Response&gt;&gt;
* @throws ApiException if fails to make API call
*/
public CompletableFuture<ApiResponse<FakeBigDecimalMap200Response>> fakeBigDecimalMapWithHttpInfo() throws ApiException {
try {
HttpRequest.Builder localVarRequestBuilder = fakeBigDecimalMapRequestBuilder();
return memberVarHttpClient.sendAsync(
localVarRequestBuilder.build(),
HttpResponse.BodyHandlers.ofString()).thenComposeAsync(localVarResponse -> {
if (memberVarAsyncResponseInterceptor != null) {
memberVarAsyncResponseInterceptor.accept(localVarResponse);
}
if (localVarResponse.statusCode()/ 100 != 2) {
return CompletableFuture.failedFuture(getApiException("fakeBigDecimalMap", localVarResponse));
}
try {
String responseBody = localVarResponse.body();
return CompletableFuture.completedFuture(
new ApiResponse<FakeBigDecimalMap200Response>(
localVarResponse.statusCode(),
localVarResponse.headers().map(),
responseBody == null || responseBody.isBlank() ? null : memberVarObjectMapper.readValue(responseBody, new TypeReference<FakeBigDecimalMap200Response>() {}))
);
} catch (IOException e) {
return CompletableFuture.failedFuture(new ApiException(e));
}
}
);
}
catch (ApiException e) {
return CompletableFuture.failedFuture(e);
}
}
private HttpRequest.Builder fakeBigDecimalMapRequestBuilder() throws ApiException {
HttpRequest.Builder localVarRequestBuilder = HttpRequest.newBuilder();
String localVarPath = "/fake/BigDecimalMap";
localVarRequestBuilder.uri(URI.create(memberVarBaseUri + localVarPath));
localVarRequestBuilder.header("Accept", "*/*");
localVarRequestBuilder.method("GET", HttpRequest.BodyPublishers.noBody());
if (memberVarReadTimeout != null) {
localVarRequestBuilder.timeout(memberVarReadTimeout);
}
if (memberVarInterceptor != null) {
memberVarInterceptor.accept(localVarRequestBuilder);
}
return localVarRequestBuilder;
}
/**
* Health check endpoint
*

View File

@@ -0,0 +1,201 @@
/*
* OpenAPI Petstore
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
*
* The version of the OpenAPI document: 1.0.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
package org.openapitools.client.model;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.StringJoiner;
import java.util.Objects;
import java.util.Arrays;
import java.util.Map;
import java.util.HashMap;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonTypeName;
import com.fasterxml.jackson.annotation.JsonValue;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
/**
* FakeBigDecimalMap200Response
*/
@JsonPropertyOrder({
FakeBigDecimalMap200Response.JSON_PROPERTY_SOME_ID,
FakeBigDecimalMap200Response.JSON_PROPERTY_SOME_MAP
})
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen")
public class FakeBigDecimalMap200Response {
public static final String JSON_PROPERTY_SOME_ID = "someId";
private BigDecimal someId;
public static final String JSON_PROPERTY_SOME_MAP = "someMap";
private Map<String, BigDecimal> someMap = new HashMap<>();
public FakeBigDecimalMap200Response() {
}
public FakeBigDecimalMap200Response someId(BigDecimal someId) {
this.someId = someId;
return this;
}
/**
* Get someId
* @return someId
**/
@javax.annotation.Nullable
@JsonProperty(JSON_PROPERTY_SOME_ID)
@JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)
public BigDecimal getSomeId() {
return someId;
}
@JsonProperty(JSON_PROPERTY_SOME_ID)
@JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)
public void setSomeId(BigDecimal someId) {
this.someId = someId;
}
public FakeBigDecimalMap200Response someMap(Map<String, BigDecimal> someMap) {
this.someMap = someMap;
return this;
}
public FakeBigDecimalMap200Response putSomeMapItem(String key, BigDecimal someMapItem) {
if (this.someMap == null) {
this.someMap = new HashMap<>();
}
this.someMap.put(key, someMapItem);
return this;
}
/**
* Get someMap
* @return someMap
**/
@javax.annotation.Nullable
@JsonProperty(JSON_PROPERTY_SOME_MAP)
@JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)
public Map<String, BigDecimal> getSomeMap() {
return someMap;
}
@JsonProperty(JSON_PROPERTY_SOME_MAP)
@JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)
public void setSomeMap(Map<String, BigDecimal> someMap) {
this.someMap = someMap;
}
/**
* Return true if this fakeBigDecimalMap_200_response object is equal to o.
*/
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
FakeBigDecimalMap200Response fakeBigDecimalMap200Response = (FakeBigDecimalMap200Response) o;
return Objects.equals(this.someId, fakeBigDecimalMap200Response.someId) &&
Objects.equals(this.someMap, fakeBigDecimalMap200Response.someMap);
}
@Override
public int hashCode() {
return Objects.hash(someId, someMap);
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("class FakeBigDecimalMap200Response {\n");
sb.append(" someId: ").append(toIndentedString(someId)).append("\n");
sb.append(" someMap: ").append(toIndentedString(someMap)).append("\n");
sb.append("}");
return sb.toString();
}
/**
* Convert the given object to string with each line indented by 4 spaces
* (except the first line).
*/
private String toIndentedString(Object o) {
if (o == null) {
return "null";
}
return o.toString().replace("\n", "\n ");
}
/**
* Convert the instance into URL query string.
*
* @return URL query string
*/
public String toUrlQueryString() {
return toUrlQueryString(null);
}
/**
* Convert the instance into URL query string.
*
* @param prefix prefix of the query string
* @return URL query string
*/
public String toUrlQueryString(String prefix) {
String suffix = "";
String containerSuffix = "";
String containerPrefix = "";
if (prefix == null) {
// style=form, explode=true, e.g. /pet?name=cat&type=manx
prefix = "";
} else {
// deepObject style e.g. /pet?id[name]=cat&id[type]=manx
prefix = prefix + "[";
suffix = "]";
containerSuffix = "]";
containerPrefix = "[";
}
StringJoiner joiner = new StringJoiner("&");
// add `someId` to the URL query string
if (getSomeId() != null) {
joiner.add(String.format("%ssomeId%s=%s", prefix, suffix, URLEncoder.encode(String.valueOf(getSomeId()), StandardCharsets.UTF_8).replaceAll("\\+", "%20")));
}
// add `someMap` to the URL query string
if (getSomeMap() != null) {
for (String _key : getSomeMap().keySet()) {
joiner.add(String.format("%ssomeMap%s%s=%s", prefix, suffix,
"".equals(suffix) ? "" : String.format("%s%d%s", containerPrefix, _key, containerSuffix),
getSomeMap().get(_key), URLEncoder.encode(String.valueOf(getSomeMap().get(_key)), StandardCharsets.UTF_8).replaceAll("\\+", "%20")));
}
}
return joiner.toString();
}
}

View File

@@ -0,0 +1,58 @@
/*
* OpenAPI Petstore
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
*
* The version of the OpenAPI document: 1.0.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
package org.openapitools.client.model;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonTypeName;
import com.fasterxml.jackson.annotation.JsonValue;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
/**
* Model tests for FakeBigDecimalMap200Response
*/
public class FakeBigDecimalMap200ResponseTest {
private final FakeBigDecimalMap200Response model = new FakeBigDecimalMap200Response();
/**
* Model tests for FakeBigDecimalMap200Response
*/
@Test
public void testFakeBigDecimalMap200Response() {
// TODO: test FakeBigDecimalMap200Response
}
/**
* Test the property 'someId'
*/
@Test
public void someIdTest() {
// TODO: test someId
}
/**
* Test the property 'someMap'
*/
@Test
public void someMapTest() {
// TODO: test someMap
}
}