mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-12-20 03:17:14 +00:00
[Java] Add missing Locale to String.format() invocations (#21871)
* [Java] Add missing Locale to String.format() invocations * chore: ./bin/generate-samples.sh ./bin/configs/*.yaml
This commit is contained in:
@@ -1265,7 +1265,8 @@ public class ApiClient {
|
||||
if (serverIndex != null) {
|
||||
if (serverIndex < 0 || serverIndex >= servers.size()) {
|
||||
throw new ArrayIndexOutOfBoundsException(String.format(
|
||||
"Invalid index %d when selecting the host settings. Must be less than %d", serverIndex, servers.size()
|
||||
Locale.ROOT,
|
||||
"Invalid index %d when selecting the host settings. Must be less than %d", serverIndex, servers.size()
|
||||
));
|
||||
}
|
||||
baseURL = servers.get(serverIndex).URL(serverVariables);
|
||||
@@ -1337,11 +1338,11 @@ public class ApiClient {
|
||||
*/
|
||||
public void processCookieParams(Map<String, String> cookieParams, Request.Builder reqBuilder) {
|
||||
for (Entry<String, String> param : cookieParams.entrySet()) {
|
||||
reqBuilder.addHeader("Cookie", String.format("%s=%s", param.getKey(), param.getValue()));
|
||||
reqBuilder.addHeader("Cookie", String.format(Locale.ROOT, "%s=%s", param.getKey(), param.getValue()));
|
||||
}
|
||||
for (Entry<String, String> param : defaultCookieMap.entrySet()) {
|
||||
if (!cookieParams.containsKey(param.getKey())) {
|
||||
reqBuilder.addHeader("Cookie", String.format("%s=%s", param.getKey(), param.getValue()));
|
||||
reqBuilder.addHeader("Cookie", String.format(Locale.ROOT, "%s=%s", param.getKey(), param.getValue()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ package org.openapitools.client;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
|
||||
/**
|
||||
@@ -161,7 +162,7 @@ public class ApiException extends Exception {
|
||||
* @return The exception message
|
||||
*/
|
||||
public String getMessage() {
|
||||
return String.format("Message: %s%nHTTP response code: %s%nHTTP response body: %s%nHTTP response headers: %s",
|
||||
return String.format(Locale.ROOT, "Message: %s%nHTTP response code: %s%nHTTP response body: %s%nHTTP response headers: %s",
|
||||
super.getMessage(), this.getCode(), this.getResponseBody(), this.getResponseHeaders());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
package org.openapitools.client.model;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.Locale;
|
||||
import com.google.gson.TypeAdapter;
|
||||
import com.google.gson.annotations.JsonAdapter;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
@@ -38,6 +39,7 @@ import java.util.HashSet;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Locale;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
@@ -117,7 +119,7 @@ public class MyExampleGet200Response extends AbstractOpenApiSchema {
|
||||
try {
|
||||
// validate the JSON object to see if any exception is thrown
|
||||
if (!jsonElement.isJsonArray()) {
|
||||
throw new IllegalArgumentException(String.format("Expected json element to be a array type in the JSON string but got `%s`", jsonElement.toString()));
|
||||
throw new IllegalArgumentException(String.format(Locale.ROOT, "Expected json element to be a array type in the JSON string but got `%s`", jsonElement.toString()));
|
||||
}
|
||||
|
||||
JsonArray array = jsonElement.getAsJsonArray();
|
||||
@@ -130,7 +132,7 @@ public class MyExampleGet200Response extends AbstractOpenApiSchema {
|
||||
log.log(Level.FINER, "Input data matches schema 'List<@Valid OneOf1>'");
|
||||
} catch (Exception e) {
|
||||
// deserialization failed, continue
|
||||
errorMessages.add(String.format("Deserialization for List<@Valid OneOf1> failed with `%s`.", e.getMessage()));
|
||||
errorMessages.add(String.format(Locale.ROOT, "Deserialization for List<@Valid OneOf1> failed with `%s`.", e.getMessage()));
|
||||
log.log(Level.FINER, "Input data does not match schema 'List<@Valid OneOf1>'", e);
|
||||
}
|
||||
// deserialize OneOf1
|
||||
@@ -142,7 +144,7 @@ public class MyExampleGet200Response extends AbstractOpenApiSchema {
|
||||
log.log(Level.FINER, "Input data matches schema 'OneOf1'");
|
||||
} catch (Exception e) {
|
||||
// deserialization failed, continue
|
||||
errorMessages.add(String.format("Deserialization for OneOf1 failed with `%s`.", e.getMessage()));
|
||||
errorMessages.add(String.format(Locale.ROOT, "Deserialization for OneOf1 failed with `%s`.", e.getMessage()));
|
||||
log.log(Level.FINER, "Input data does not match schema 'OneOf1'", e);
|
||||
}
|
||||
|
||||
@@ -152,7 +154,7 @@ public class MyExampleGet200Response extends AbstractOpenApiSchema {
|
||||
return ret;
|
||||
}
|
||||
|
||||
throw new IOException(String.format("Failed deserialization for MyExampleGet200Response: %d classes match result, expected 1. Detailed failure message for oneOf schemas: %s. JSON: %s", match, errorMessages, jsonElement.toString()));
|
||||
throw new IOException(String.format(Locale.ROOT, "Failed deserialization for MyExampleGet200Response: %d classes match result, expected 1. Detailed failure message for oneOf schemas: %s. JSON: %s", match, errorMessages, jsonElement.toString()));
|
||||
}
|
||||
}.nullSafe();
|
||||
}
|
||||
@@ -252,7 +254,7 @@ public class MyExampleGet200Response extends AbstractOpenApiSchema {
|
||||
// validate the json string with List<@Valid OneOf1>
|
||||
try {
|
||||
if (!jsonElement.isJsonArray()) {
|
||||
throw new IllegalArgumentException(String.format("Expected json element to be a array type in the JSON string but got `%s`", jsonElement.toString()));
|
||||
throw new IllegalArgumentException(String.format(Locale.ROOT, "Expected json element to be a array type in the JSON string but got `%s`", jsonElement.toString()));
|
||||
}
|
||||
JsonArray array = jsonElement.getAsJsonArray();
|
||||
// validate array items
|
||||
@@ -261,7 +263,7 @@ public class MyExampleGet200Response extends AbstractOpenApiSchema {
|
||||
}
|
||||
validCount++;
|
||||
} catch (Exception e) {
|
||||
errorMessages.add(String.format("Deserialization for List<@Valid OneOf1> failed with `%s`.", e.getMessage()));
|
||||
errorMessages.add(String.format(Locale.ROOT, "Deserialization for List<@Valid OneOf1> failed with `%s`.", e.getMessage()));
|
||||
// continue to the next one
|
||||
}
|
||||
// validate the json string with OneOf1
|
||||
@@ -269,11 +271,11 @@ public class MyExampleGet200Response extends AbstractOpenApiSchema {
|
||||
OneOf1.validateJsonElement(jsonElement);
|
||||
validCount++;
|
||||
} catch (Exception e) {
|
||||
errorMessages.add(String.format("Deserialization for OneOf1 failed with `%s`.", e.getMessage()));
|
||||
errorMessages.add(String.format(Locale.ROOT, "Deserialization for OneOf1 failed with `%s`.", e.getMessage()));
|
||||
// continue to the next one
|
||||
}
|
||||
if (validCount != 1) {
|
||||
throw new IOException(String.format("The JSON string is invalid for MyExampleGet200Response with oneOf schemas: List<@Valid OneOf1>, OneOf1. %d class(es) match the result, expected 1. Detailed failure message for oneOf schemas: %s. JSON: %s", validCount, errorMessages, jsonElement.toString()));
|
||||
throw new IOException(String.format(Locale.ROOT, "The JSON string is invalid for MyExampleGet200Response with oneOf schemas: List<@Valid OneOf1>, OneOf1. %d class(es) match the result, expected 1. Detailed failure message for oneOf schemas: %s. JSON: %s", validCount, errorMessages, jsonElement.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
package org.openapitools.client.model;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.Locale;
|
||||
import com.google.gson.TypeAdapter;
|
||||
import com.google.gson.annotations.JsonAdapter;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
@@ -44,6 +45,7 @@ import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.openapitools.client.JSON;
|
||||
|
||||
@@ -139,7 +141,7 @@ public class OneOf1 {
|
||||
public static void validateJsonElement(JsonElement jsonElement) throws IOException {
|
||||
if (jsonElement == null) {
|
||||
if (!OneOf1.openapiRequiredFields.isEmpty()) { // has required fields but JSON element is null
|
||||
throw new IllegalArgumentException(String.format("The required field(s) %s in OneOf1 is not found in the empty JSON string", OneOf1.openapiRequiredFields.toString()));
|
||||
throw new IllegalArgumentException(String.format(Locale.ROOT, "The required field(s) %s in OneOf1 is not found in the empty JSON string", OneOf1.openapiRequiredFields.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -147,12 +149,12 @@ public class OneOf1 {
|
||||
// check to see if the JSON string contains additional fields
|
||||
for (Map.Entry<String, JsonElement> entry : entries) {
|
||||
if (!OneOf1.openapiFields.contains(entry.getKey())) {
|
||||
throw new IllegalArgumentException(String.format("The field `%s` in the JSON string is not defined in the `OneOf1` properties. JSON: %s", entry.getKey(), jsonElement.toString()));
|
||||
throw new IllegalArgumentException(String.format(Locale.ROOT, "The field `%s` in the JSON string is not defined in the `OneOf1` properties. JSON: %s", entry.getKey(), jsonElement.toString()));
|
||||
}
|
||||
}
|
||||
JsonObject jsonObj = jsonElement.getAsJsonObject();
|
||||
if ((jsonObj.get("message1") != null && !jsonObj.get("message1").isJsonNull()) && !jsonObj.get("message1").isJsonPrimitive()) {
|
||||
throw new IllegalArgumentException(String.format("Expected the field `message1` to be a primitive type in the JSON string but got `%s`", jsonObj.get("message1").toString()));
|
||||
throw new IllegalArgumentException(String.format(Locale.ROOT, "Expected the field `message1` to be a primitive type in the JSON string but got `%s`", jsonObj.get("message1").toString()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user