forked from loafle/openapi-generator-original
[java][jersey] Remove double brace initialization and some more jersey cleanup (#14783)
* Remove double brace initialization * Use diamond operator * Less clutter in generated api classes * Optimize isJsonMime * Revert change in escapeString Skip toString() on string parameters. * Fix edge-cases A ServerVariable without enumValues and/or operationServers with any ServerVariables would lead to invalid code.
This commit is contained in:
@@ -35,6 +35,7 @@ import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
import org.glassfish.jersey.logging.LoggingFeature;
|
||||
import java.util.AbstractMap.SimpleEntry;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.Collection;
|
||||
@@ -42,11 +43,14 @@ import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Arrays;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
import java.time.OffsetDateTime;
|
||||
|
||||
import java.net.URLEncoder;
|
||||
@@ -68,25 +72,26 @@ import org.openapitools.client.auth.ApiKeyAuth;
|
||||
*/
|
||||
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen")
|
||||
public class ApiClient extends JavaTimeFormatter {
|
||||
protected Map<String, String> defaultHeaderMap = new HashMap<String, String>();
|
||||
protected Map<String, String> defaultCookieMap = new HashMap<String, String>();
|
||||
private static final Pattern JSON_MIME_PATTERN = Pattern.compile("(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$");
|
||||
|
||||
protected Map<String, String> defaultHeaderMap = new HashMap<>();
|
||||
protected Map<String, String> defaultCookieMap = new HashMap<>();
|
||||
protected String basePath = "http://localhost";
|
||||
protected String userAgent;
|
||||
private static final Logger log = Logger.getLogger(ApiClient.class.getName());
|
||||
|
||||
protected List<ServerConfiguration> servers = new ArrayList<ServerConfiguration>(Arrays.asList(
|
||||
new ServerConfiguration(
|
||||
"",
|
||||
"No description provided",
|
||||
new HashMap<String, ServerVariable>()
|
||||
)
|
||||
protected List<ServerConfiguration> servers = new ArrayList<>(Arrays.asList(
|
||||
new ServerConfiguration(
|
||||
"",
|
||||
"No description provided",
|
||||
new LinkedHashMap<>()
|
||||
)
|
||||
));
|
||||
protected Integer serverIndex = 0;
|
||||
protected Map<String, String> serverVariables = null;
|
||||
protected Map<String, List<ServerConfiguration>> operationServers = new HashMap<String, List<ServerConfiguration>>() {{
|
||||
}};
|
||||
protected Map<String, Integer> operationServerIndex = new HashMap<String, Integer>();
|
||||
protected Map<String, Map<String, String>> operationServerVariables = new HashMap<String, Map<String, String>>();
|
||||
protected Map<String, List<ServerConfiguration>> operationServers = new HashMap<>();
|
||||
protected Map<String, Integer> operationServerIndex = new HashMap<>();
|
||||
protected Map<String, Map<String, String>> operationServerVariables = new HashMap<>();
|
||||
protected boolean debugging = false;
|
||||
protected ClientConfig clientConfig;
|
||||
protected int connectionTimeout = 0;
|
||||
@@ -123,13 +128,13 @@ public class ApiClient extends JavaTimeFormatter {
|
||||
setUserAgent("OpenAPI-Generator/1.0.0/java");
|
||||
|
||||
// Setup authentications (key: authentication name, value: authentication).
|
||||
authentications = new HashMap<String, Authentication>();
|
||||
authentications = new HashMap<>();
|
||||
Authentication auth = null;
|
||||
// Prevent the authentications from being modified.
|
||||
authentications = Collections.unmodifiableMap(authentications);
|
||||
|
||||
// Setup authentication lookup (key: authentication alias, value: authentication name)
|
||||
authenticationLookup = new HashMap<String, String>();
|
||||
authenticationLookup = new HashMap<>();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -610,7 +615,7 @@ public class ApiClient extends JavaTimeFormatter {
|
||||
* @return List of pairs
|
||||
*/
|
||||
public List<Pair> parameterToPairs(String collectionFormat, String name, Object value){
|
||||
List<Pair> params = new ArrayList<Pair>();
|
||||
List<Pair> params = new ArrayList<>();
|
||||
|
||||
// preconditions
|
||||
if (name == null || name.isEmpty() || value == null) return params;
|
||||
@@ -669,14 +674,13 @@ public class ApiClient extends JavaTimeFormatter {
|
||||
* application/json; charset=UTF8
|
||||
* APPLICATION/JSON
|
||||
* application/vnd.company+json
|
||||
* "* / *" is also default to JSON
|
||||
* "*{@literal /}*" is also considered JSON by this method.
|
||||
*
|
||||
* @param mime MIME
|
||||
* @return True if the MIME type is JSON
|
||||
*/
|
||||
public boolean isJsonMime(String mime) {
|
||||
String jsonMime = "(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$";
|
||||
return mime != null && (mime.matches(jsonMime) || mime.equals("*/*"));
|
||||
return mime != null && (mime.equals("*/*") || JSON_MIME_PATTERN.matcher(mime).matches());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -688,8 +692,8 @@ public class ApiClient extends JavaTimeFormatter {
|
||||
* @return The Accept header to use. If the given array is empty,
|
||||
* null will be returned (not to set the Accept header explicitly).
|
||||
*/
|
||||
public String selectHeaderAccept(String[] accepts) {
|
||||
if (accepts.length == 0) {
|
||||
public String selectHeaderAccept(String... accepts) {
|
||||
if (accepts == null || accepts.length == 0) {
|
||||
return null;
|
||||
}
|
||||
for (String accept : accepts) {
|
||||
@@ -709,8 +713,8 @@ public class ApiClient extends JavaTimeFormatter {
|
||||
* @return The Content-Type header to use. If the given array is empty,
|
||||
* JSON will be used.
|
||||
*/
|
||||
public String selectHeaderContentType(String[] contentTypes) {
|
||||
if (contentTypes.length == 0) {
|
||||
public String selectHeaderContentType(String... contentTypes) {
|
||||
if (contentTypes == null || contentTypes.length == 0) {
|
||||
return "application/json";
|
||||
}
|
||||
for (String contentType : contentTypes) {
|
||||
@@ -1002,15 +1006,17 @@ public class ApiClient extends JavaTimeFormatter {
|
||||
Map<String, String> allHeaderParams = new HashMap<>(defaultHeaderMap);
|
||||
allHeaderParams.putAll(headerParams);
|
||||
|
||||
// update different parameters (e.g. headers) for authentication
|
||||
updateParamsForAuth(
|
||||
authNames,
|
||||
queryParams,
|
||||
allHeaderParams,
|
||||
cookieParams,
|
||||
null,
|
||||
method,
|
||||
target.getUri());
|
||||
if (authNames != null) {
|
||||
// update different parameters (e.g. headers) for authentication
|
||||
updateParamsForAuth(
|
||||
authNames,
|
||||
queryParams,
|
||||
allHeaderParams,
|
||||
cookieParams,
|
||||
null,
|
||||
method,
|
||||
target.getUri());
|
||||
}
|
||||
|
||||
for (Entry<String, String> entry : allHeaderParams.entrySet()) {
|
||||
String value = entry.getValue();
|
||||
@@ -1182,10 +1188,10 @@ public class ApiClient extends JavaTimeFormatter {
|
||||
* @return a {@link java.util.Map} of response headers.
|
||||
*/
|
||||
protected Map<String, List<String>> buildResponseHeaders(Response response) {
|
||||
Map<String, List<String>> responseHeaders = new HashMap<String, List<String>>();
|
||||
Map<String, List<String>> responseHeaders = new HashMap<>();
|
||||
for (Entry<String, List<Object>> entry: response.getHeaders().entrySet()) {
|
||||
List<Object> values = entry.getValue();
|
||||
List<String> headers = new ArrayList<String>();
|
||||
List<String> headers = new ArrayList<>();
|
||||
for (Object o : values) {
|
||||
headers.add(String.valueOf(o));
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ public class JSON implements ContextResolver<ObjectMapper> {
|
||||
public static Class<?> getClassForElement(JsonNode node, Class<?> modelClass) {
|
||||
ClassDiscriminatorMapping cdm = modelDiscriminators.get(modelClass);
|
||||
if (cdm != null) {
|
||||
return cdm.getClassForElement(node, new HashSet<Class<?>>());
|
||||
return cdm.getClassForElement(node, new HashSet<>());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -84,7 +84,7 @@ public class JSON implements ContextResolver<ObjectMapper> {
|
||||
ClassDiscriminatorMapping(Class<?> cls, String propertyName, Map<String, Class<?>> mappings) {
|
||||
modelClass = cls;
|
||||
discriminatorName = propertyName;
|
||||
discriminatorMappings = new HashMap<String, Class<?>>();
|
||||
discriminatorMappings = new HashMap<>();
|
||||
if (mappings != null) {
|
||||
discriminatorMappings.putAll(mappings);
|
||||
}
|
||||
@@ -193,12 +193,12 @@ public class JSON implements ContextResolver<ObjectMapper> {
|
||||
/**
|
||||
* A map of discriminators for all model classes.
|
||||
*/
|
||||
private static Map<Class<?>, ClassDiscriminatorMapping> modelDiscriminators = new HashMap<Class<?>, ClassDiscriminatorMapping>();
|
||||
private static Map<Class<?>, ClassDiscriminatorMapping> modelDiscriminators = new HashMap<>();
|
||||
|
||||
/**
|
||||
* A map of oneOf/anyOf descendants for each model class.
|
||||
*/
|
||||
private static Map<Class<?>, Map<String, GenericType>> modelDescendants = new HashMap<Class<?>, Map<String, GenericType>>();
|
||||
private static Map<Class<?>, Map<String, GenericType>> modelDescendants = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Register a model class discriminator.
|
||||
|
||||
@@ -12,6 +12,7 @@ import org.openapitools.client.model.MySchemaNameCharacters;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -74,37 +75,11 @@ public class DefaultApi {
|
||||
</table>
|
||||
*/
|
||||
public ApiResponse<MySchemaNameCharacters> testPostWithHttpInfo(MySchemaNameCharacters mySchemaNameCharacters) throws ApiException {
|
||||
Object localVarPostBody = mySchemaNameCharacters;
|
||||
|
||||
// create path and map variables
|
||||
String localVarPath = "/test";
|
||||
|
||||
// query params
|
||||
List<Pair> localVarQueryParams = new ArrayList<Pair>();
|
||||
Map<String, String> localVarHeaderParams = new HashMap<String, String>();
|
||||
Map<String, String> localVarCookieParams = new HashMap<String, String>();
|
||||
Map<String, Object> localVarFormParams = new HashMap<String, Object>();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
final String[] localVarAccepts = {
|
||||
"application/json"
|
||||
};
|
||||
final String localVarAccept = apiClient.selectHeaderAccept(localVarAccepts);
|
||||
|
||||
final String[] localVarContentTypes = {
|
||||
"application/json"
|
||||
};
|
||||
final String localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes);
|
||||
|
||||
String[] localVarAuthNames = new String[] { };
|
||||
|
||||
String localVarAccept = apiClient.selectHeaderAccept("application/json");
|
||||
String localVarContentType = apiClient.selectHeaderContentType("application/json");
|
||||
GenericType<MySchemaNameCharacters> localVarReturnType = new GenericType<MySchemaNameCharacters>() {};
|
||||
|
||||
return apiClient.invokeAPI("DefaultApi.testPost", localVarPath, "POST", localVarQueryParams, localVarPostBody,
|
||||
localVarHeaderParams, localVarCookieParams, localVarFormParams, localVarAccept, localVarContentType,
|
||||
localVarAuthNames, localVarReturnType, false);
|
||||
return apiClient.invokeAPI("DefaultApi.testPost", "/test", "POST", new ArrayList<>(), mySchemaNameCharacters,
|
||||
new LinkedHashMap<>(), new LinkedHashMap<>(), new LinkedHashMap<>(), localVarAccept, localVarContentType,
|
||||
null, localVarReturnType, false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,7 +92,7 @@ public class ChildSchema extends Parent {
|
||||
@JsonAnySetter
|
||||
public ChildSchema putAdditionalProperty(String key, Object value) {
|
||||
if (this.additionalProperties == null) {
|
||||
this.additionalProperties = new HashMap<String, Object>();
|
||||
this.additionalProperties = new HashMap<>();
|
||||
}
|
||||
this.additionalProperties.put(key, value);
|
||||
return this;
|
||||
@@ -160,11 +160,11 @@ public class ChildSchema extends Parent {
|
||||
return o.toString().replace("\n", "\n ");
|
||||
}
|
||||
|
||||
static {
|
||||
// Initialize and register the discriminator mappings.
|
||||
Map<String, Class<?>> mappings = new HashMap<String, Class<?>>();
|
||||
mappings.put("ChildSchema", ChildSchema.class);
|
||||
JSON.registerDiscriminator(ChildSchema.class, "objectType", mappings);
|
||||
}
|
||||
static {
|
||||
// Initialize and register the discriminator mappings.
|
||||
Map<String, Class<?>> mappings = new HashMap<>();
|
||||
mappings.put("ChildSchema", ChildSchema.class);
|
||||
JSON.registerDiscriminator(ChildSchema.class, "objectType", mappings);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -93,7 +93,7 @@ public class MySchemaNameCharacters extends Parent {
|
||||
@JsonAnySetter
|
||||
public MySchemaNameCharacters putAdditionalProperty(String key, Object value) {
|
||||
if (this.additionalProperties == null) {
|
||||
this.additionalProperties = new HashMap<String, Object>();
|
||||
this.additionalProperties = new HashMap<>();
|
||||
}
|
||||
this.additionalProperties.put(key, value);
|
||||
return this;
|
||||
@@ -161,11 +161,11 @@ public class MySchemaNameCharacters extends Parent {
|
||||
return o.toString().replace("\n", "\n ");
|
||||
}
|
||||
|
||||
static {
|
||||
// Initialize and register the discriminator mappings.
|
||||
Map<String, Class<?>> mappings = new HashMap<String, Class<?>>();
|
||||
mappings.put("MySchemaName._-Characters", MySchemaNameCharacters.class);
|
||||
JSON.registerDiscriminator(MySchemaNameCharacters.class, "objectType", mappings);
|
||||
}
|
||||
static {
|
||||
// Initialize and register the discriminator mappings.
|
||||
Map<String, Class<?>> mappings = new HashMap<>();
|
||||
mappings.put("MySchemaName._-Characters", MySchemaNameCharacters.class);
|
||||
JSON.registerDiscriminator(MySchemaNameCharacters.class, "objectType", mappings);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -120,13 +120,13 @@ public class Parent {
|
||||
return o.toString().replace("\n", "\n ");
|
||||
}
|
||||
|
||||
static {
|
||||
// Initialize and register the discriminator mappings.
|
||||
Map<String, Class<?>> mappings = new HashMap<String, Class<?>>();
|
||||
mappings.put("ChildSchema", ChildSchema.class);
|
||||
mappings.put("MySchemaName._-Characters", MySchemaNameCharacters.class);
|
||||
mappings.put("Parent", Parent.class);
|
||||
JSON.registerDiscriminator(Parent.class, "objectType", mappings);
|
||||
}
|
||||
static {
|
||||
// Initialize and register the discriminator mappings.
|
||||
Map<String, Class<?>> mappings = new HashMap<>();
|
||||
mappings.put("ChildSchema", ChildSchema.class);
|
||||
mappings.put("MySchemaName._-Characters", MySchemaNameCharacters.class);
|
||||
mappings.put("Parent", Parent.class);
|
||||
JSON.registerDiscriminator(Parent.class, "objectType", mappings);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user