From a34569f06543be7d322cc670fd7d10077bd172d3 Mon Sep 17 00:00:00 2001 From: agilob Date: Tue, 2 Mar 2021 09:24:25 +0000 Subject: [PATCH] Correct use of loggers with placeholders and remove some redundant operations (#8842) * Remove redundant operations * Use logger correctly with object placeholders * static compile of frequently used pattern compile pattern ahead of time to reduce object creation and optimize method * Fix typo in method name --- .../codegen/config/GeneratorSettings.java | 22 +-- .../codegen/config/WorkflowSettings.java | 2 +- .../openapitools/codegen/DefaultCodegen.java | 139 +++++++++--------- .../languages/DartJaguarClientCodegen.java | 25 ++-- .../languages/JavaCXFExtServerCodegen.java | 2 +- 5 files changed, 94 insertions(+), 96 deletions(-) diff --git a/modules/openapi-generator-core/src/main/java/org/openapitools/codegen/config/GeneratorSettings.java b/modules/openapi-generator-core/src/main/java/org/openapitools/codegen/config/GeneratorSettings.java index 0fdfc209d51..e1044092007 100644 --- a/modules/openapi-generator-core/src/main/java/org/openapitools/codegen/config/GeneratorSettings.java +++ b/modules/openapi-generator-core/src/main/java/org/openapitools/codegen/config/GeneratorSettings.java @@ -30,10 +30,10 @@ import java.util.*; public final class GeneratorSettings implements Serializable { private static final Logger LOGGER = LoggerFactory.getLogger(GeneratorSettings.class); - private static String DEFAULT_GIT_HOST = "github.com"; - private static String DEFAULT_GIT_USER_ID = "GIT_USER_ID"; - private static String DEFAULT_GIT_REPO_ID = "GIT_REPO_ID"; - private static String DEFAULT_RELEASE_NOTE = "Minor update"; + private static final String DEFAULT_GIT_HOST = "github.com"; + private static final String DEFAULT_GIT_USER_ID = "GIT_USER_ID"; + private static final String DEFAULT_GIT_REPO_ID = "GIT_REPO_ID"; + private static final String DEFAULT_RELEASE_NOTE = "Minor update"; private String generatorName; private String apiPackage; @@ -48,13 +48,13 @@ public final class GeneratorSettings implements Serializable { private String artifactVersion; private String library; - private ImmutableMap instantiationTypes; - private ImmutableMap typeMappings; - private ImmutableMap additionalProperties; - private ImmutableMap importMappings; - private ImmutableSet languageSpecificPrimitives; - private ImmutableMap reservedWordMappings; - private ImmutableMap serverVariables; + private final ImmutableMap instantiationTypes; + private final ImmutableMap typeMappings; + private final ImmutableMap additionalProperties; + private final ImmutableMap importMappings; + private final ImmutableSet languageSpecificPrimitives; + private final ImmutableMap reservedWordMappings; + private final ImmutableMap serverVariables; private String gitHost; private String gitUserId; diff --git a/modules/openapi-generator-core/src/main/java/org/openapitools/codegen/config/WorkflowSettings.java b/modules/openapi-generator-core/src/main/java/org/openapitools/codegen/config/WorkflowSettings.java index 4a2487cf9b7..c387f43c323 100644 --- a/modules/openapi-generator-core/src/main/java/org/openapitools/codegen/config/WorkflowSettings.java +++ b/modules/openapi-generator-core/src/main/java/org/openapitools/codegen/config/WorkflowSettings.java @@ -36,7 +36,7 @@ import java.util.regex.Pattern; */ @SuppressWarnings("WeakerAccess") public class WorkflowSettings { - private static final AtomicLong lastWarning = new AtomicLong(0); + private static final Logger LOGGER = LoggerFactory.getLogger(WorkflowSettings.class); public static final String DEFAULT_OUTPUT_DIR = "."; public static final boolean DEFAULT_VERBOSE = false; diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java index 9483fa48535..02a5a06e9bd 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java @@ -142,10 +142,10 @@ public class DefaultCodegen implements CodegenConfig { protected GeneratorMetadata generatorMetadata; protected String inputSpec; protected String outputFolder = ""; - protected Set defaultIncludes = new HashSet(); - protected Map typeMapping = new HashMap(); - protected Map instantiationTypes = new HashMap(); - protected Set reservedWords = new HashSet(); + protected Set defaultIncludes; + protected Map typeMapping; + protected Map instantiationTypes; + protected Set reservedWords; protected Set languageSpecificPrimitives = new HashSet(); protected Map importMapping = new HashMap(); protected String modelPackage = "", apiPackage = "", fileSuffix; @@ -179,6 +179,10 @@ public class DefaultCodegen implements CodegenConfig { protected boolean removeOperationIdPrefix; protected boolean skipOperationExample; + protected final static Pattern JSON_MIME_PATTERN = Pattern.compile("(?i)application\\/json(;.*)?"); + protected final static Pattern JSON_VENDOR_MIME_PATTERN = Pattern.compile("(?i)application\\/vnd.(.*)+json(;.*)?"); + private static final Pattern COMMON_PREFIX_ENUM_NAME = Pattern.compile("[a-zA-Z0-9]+\\z"); + /** * True if the code generator supports multiple class inheritance. * This is used to model the parent hierarchy based on the 'allOf' composed schemas. @@ -315,12 +319,12 @@ public class DefaultCodegen implements CodegenConfig { } if (additionalProperties.containsKey(CodegenConstants.REMOVE_OPERATION_ID_PREFIX)) { - this.setRemoveOperationIdPrefix(Boolean.valueOf(additionalProperties + this.setRemoveOperationIdPrefix(Boolean.parseBoolean(additionalProperties .get(CodegenConstants.REMOVE_OPERATION_ID_PREFIX).toString())); } if (additionalProperties.containsKey(CodegenConstants.SKIP_OPERATION_EXAMPLE)) { - this.setSkipOperationExample(Boolean.valueOf(additionalProperties + this.setSkipOperationExample(Boolean.parseBoolean(additionalProperties .get(CodegenConstants.SKIP_OPERATION_EXAMPLE).toString())); } @@ -330,26 +334,26 @@ public class DefaultCodegen implements CodegenConfig { } if (additionalProperties.containsKey(CodegenConstants.ENABLE_POST_PROCESS_FILE)) { - this.setEnablePostProcessFile(Boolean.valueOf(additionalProperties + this.setEnablePostProcessFile(Boolean.parseBoolean(additionalProperties .get(CodegenConstants.ENABLE_POST_PROCESS_FILE).toString())); } if (additionalProperties.containsKey(CodegenConstants.GENERATE_ALIAS_AS_MODEL)) { - ModelUtils.setGenerateAliasAsModel(Boolean.valueOf(additionalProperties + ModelUtils.setGenerateAliasAsModel(Boolean.parseBoolean(additionalProperties .get(CodegenConstants.GENERATE_ALIAS_AS_MODEL).toString())); } if (additionalProperties.containsKey(CodegenConstants.REMOVE_ENUM_VALUE_PREFIX)) { - this.setRemoveEnumValuePrefix(Boolean.valueOf(additionalProperties + this.setRemoveEnumValuePrefix(Boolean.parseBoolean(additionalProperties .get(CodegenConstants.REMOVE_ENUM_VALUE_PREFIX).toString())); } if (additionalProperties.containsKey(CodegenConstants.LEGACY_DISCRIMINATOR_BEHAVIOR)) { - this.setLegacyDiscriminatorBehavior(Boolean.valueOf(additionalProperties + this.setLegacyDiscriminatorBehavior(Boolean.parseBoolean(additionalProperties .get(CodegenConstants.LEGACY_DISCRIMINATOR_BEHAVIOR).toString())); } if (additionalProperties.containsKey(CodegenConstants.DISALLOW_ADDITIONAL_PROPERTIES_IF_NOT_PRESENT)) { - this.setDisallowAdditionalPropertiesIfNotPresent(Boolean.valueOf(additionalProperties + this.setDisallowAdditionalPropertiesIfNotPresent(Boolean.parseBoolean(additionalProperties .get(CodegenConstants.DISALLOW_ADDITIONAL_PROPERTIES_IF_NOT_PRESENT).toString())); } } @@ -402,10 +406,9 @@ public class DefaultCodegen implements CodegenConfig { Map modelValue = new HashMap<>(additionalProperties()); modelValue.put("model", cm); - List modelsValue = Arrays.asList(modelValue); - List> importsValue = new ArrayList>(); + List> importsValue = new ArrayList<>(); Map objsValue = new HashMap<>(); - objsValue.put("models", modelsValue); + objsValue.put("models", Collections.singletonList(modelValue)); objsValue.put("package", modelPackage()); objsValue.put("imports", importsValue); objsValue.put("classname", cm.classname); @@ -416,7 +419,7 @@ public class DefaultCodegen implements CodegenConfig { // Gather data from all the models that contain oneOf into OneOfImplementorAdditionalData classes // (see docstring of that class to find out what information is gathered and why) Map additionalDataMap = new HashMap(); - for (Map.Entry modelsEntry : objs.entrySet()) { + for (Map.Entry modelsEntry : objs.entrySet()) { Map modelsAttrs = (Map) modelsEntry.getValue(); List models = (List) modelsAttrs.get("models"); List> modelsImports = (List>) modelsAttrs.getOrDefault("imports", new ArrayList>()); @@ -438,7 +441,7 @@ public class DefaultCodegen implements CodegenConfig { } // Add all the data from OneOfImplementorAdditionalData classes to the implementing models - for (Map.Entry modelsEntry : objs.entrySet()) { + for (Map.Entry modelsEntry : objs.entrySet()) { Map modelsAttrs = (Map) modelsEntry.getValue(); List models = (List) modelsAttrs.get("models"); List> imports = (List>) modelsAttrs.get("imports"); @@ -464,10 +467,8 @@ public class DefaultCodegen implements CodegenConfig { protected Map getModelNameToSchemaCache() { if (modelNameToSchemaCache == null) { // Create a cache to efficiently lookup schema based on model name. - Map m = new HashMap(); - ModelUtils.getSchemas(openAPI).forEach((key, schema) -> { - m.put(toModelName(key), schema); - }); + Map m = new HashMap<>(); + ModelUtils.getSchemas(openAPI).forEach((key, schema) -> m.put(toModelName(key), schema)); modelNameToSchemaCache = Collections.unmodifiableMap(m); } return modelNameToSchemaCache; @@ -508,7 +509,7 @@ public class DefaultCodegen implements CodegenConfig { cm.setParentModel(allModels.get(cm.getParent())); } if (cm.getInterfaces() != null && !cm.getInterfaces().isEmpty()) { - cm.setInterfaceModels(new ArrayList(cm.getInterfaces().size())); + cm.setInterfaceModels(new ArrayList<>(cm.getInterfaces().size())); for (String intf : cm.getInterfaces()) { CodegenModel intfModel = allModels.get(intf); if (intfModel != null) { @@ -526,7 +527,7 @@ public class DefaultCodegen implements CodegenConfig { // TODO Determine what to do if the parent discriminator name == the grandparent discriminator name while (parent != null) { if (parent.getChildren() == null) { - parent.setChildren(new ArrayList()); + parent.setChildren(new ArrayList<>()); } parent.getChildren().add(cm); parent.hasChildren = true; @@ -575,13 +576,13 @@ public class DefaultCodegen implements CodegenConfig { } return prop.dataType == null ? null : prop; }) - .filter(prop -> prop != null) + .filter(Objects::nonNull) .collect(Collectors.toList()); } private void setCircularReferencesOnProperties(final String root, final Map> dependencyMap) { - dependencyMap.getOrDefault(root, new ArrayList<>()).stream() + dependencyMap.getOrDefault(root, new ArrayList<>()) .forEach(prop -> { final List unvisited = Collections.singletonList(prop.isContainer ? prop.items.dataType : prop.dataType); @@ -686,7 +687,8 @@ public class DefaultCodegen implements CodegenConfig { String prefix = StringUtils.getCommonPrefix(listStr); // exclude trailing characters that should be part of a valid variable // e.g. ["status-on", "status-off"] => "status-" (not "status-o") - return prefix.replaceAll("[a-zA-Z0-9]+\\z", ""); + final Matcher matcher = COMMON_PREFIX_ENUM_NAME.matcher(prefix); + return matcher.replaceAll(""); } catch (ArrayStoreException e) { // do nothing, just return default value } @@ -1628,7 +1630,7 @@ public class DefaultCodegen implements CodegenConfig { } else if (Parameter.StyleEnum.SPACEDELIMITED.equals(qp.getStyle())) { paramPart.append("%20"); } else { - LOGGER.warn("query parameter '" + param.getName() + "style not support: " + qp.getStyle()); + LOGGER.warn("query parameter '{}' style not support: {}", param.getName(), qp.getStyle()); } } else { paramPart.append(param.getName()); @@ -2004,7 +2006,7 @@ public class DefaultCodegen implements CodegenConfig { } return getAlias(schemaName); } else { - LOGGER.warn("Error obtaining the datatype from ref:" + unaliasSchema.get$ref() + ". Default to 'object'"); + LOGGER.warn("Error obtaining the datatype from ref: {}. Default to 'object'", unaliasSchema.get$ref()); return "object"; } } else { // primitive type or model @@ -2092,7 +2094,7 @@ public class DefaultCodegen implements CodegenConfig { return "AnyType"; } else if (StringUtils.isNotEmpty(schema.getType())) { if (!importMapping.containsKey(schema.getType())) { - LOGGER.warn("Unknown type found in the schema: " + schema.getType()); + LOGGER.warn("Unknown type found in the schema: {}", schema.getType()); } return schema.getType(); } @@ -2799,10 +2801,10 @@ public class DefaultCodegen implements CodegenConfig { * @return the list of oneOf and anyOf MappedModel that need to be added to the discriminator map */ protected List getOneOfAnyOfDescendants(String composedSchemaName, String discPropName, ComposedSchema c, OpenAPI openAPI) { - ArrayList> listOLists = new ArrayList>(); + ArrayList> listOLists = new ArrayList<>(); listOLists.add(c.getOneOf()); listOLists.add(c.getAnyOf()); - List descendentSchemas = new ArrayList(); + List descendentSchemas = new ArrayList<>(); for (List schemaList : listOLists) { if (schemaList == null) { continue; @@ -3061,11 +3063,11 @@ public class DefaultCodegen implements CodegenConfig { LOGGER.error("Undefined property/schema for `{}`. Default to type:string.", name); return null; } - LOGGER.debug("debugging fromProperty for " + name + " : " + p); + LOGGER.debug("debugging fromProperty for {} : {}", name, p); NamedSchema ns = new NamedSchema(name, p); CodegenProperty cpc = schemaCodegenPropertyCache.get(ns); if (cpc != null) { - LOGGER.debug("Cached fromProperty for " + name + " : " + p.getName()); + LOGGER.debug("Cached fromProperty for {} : {}", name, p.getName()); return cpc; } // unalias schema @@ -3317,8 +3319,8 @@ public class DefaultCodegen implements CodegenConfig { property.isModel = (ModelUtils.isComposedSchema(refOrCurrent) || ModelUtils.isObjectSchema(refOrCurrent)) && ModelUtils.isModel(refOrCurrent); } - addVarsRequiredVarsAdditionaProps(p, property); - LOGGER.debug("debugging from property return: " + property); + addVarsRequiredVarsAdditionalProps(p, property); + LOGGER.debug("debugging from property return: {}", property); schemaCodegenPropertyCache.put(ns, property); return property; } @@ -3331,7 +3333,9 @@ public class DefaultCodegen implements CodegenConfig { */ protected void updatePropertyForArray(CodegenProperty property, CodegenProperty innerProperty) { if (innerProperty == null) { - LOGGER.warn("skipping invalid array property " + Json.pretty(property)); + if(LOGGER.isWarnEnabled()) { + LOGGER.warn("skipping invalid array property {}", Json.pretty(property)); + } return; } property.dataFormat = innerProperty.dataFormat; @@ -3364,7 +3368,9 @@ public class DefaultCodegen implements CodegenConfig { */ protected void updatePropertyForMap(CodegenProperty property, CodegenProperty innerProperty) { if (innerProperty == null) { - LOGGER.warn("skipping invalid map property " + Json.pretty(property)); + if(LOGGER.isWarnEnabled()) { + LOGGER.warn("skipping invalid map property {}", Json.pretty(property)); + } return; } if (!languageSpecificPrimitives.contains(innerProperty.baseType)) { @@ -3413,7 +3419,7 @@ public class DefaultCodegen implements CodegenConfig { protected Map getInnerEnumAllowableValues(CodegenProperty property) { CodegenProperty currentProperty = getMostInnerItems(property); - return currentProperty == null ? new HashMap() : currentProperty.allowableValues; + return currentProperty == null ? new HashMap<>() : currentProperty.allowableValues; } /** @@ -3614,7 +3620,7 @@ public class DefaultCodegen implements CodegenConfig { String httpMethod, Operation operation, List servers) { - LOGGER.debug("fromOperation => operation: " + operation); + LOGGER.debug("fromOperation => operation: {}", operation); if (operation == null) throw new RuntimeException("operation cannot be null in fromOperation"); @@ -3794,7 +3800,7 @@ public class DefaultCodegen implements CodegenConfig { } else if (param instanceof CookieParameter || "cookie".equalsIgnoreCase(param.getIn())) { cookieParams.add(p.copy()); } else { - LOGGER.warn("Unknown parameter type " + p.baseType + " for " + p.baseName); + LOGGER.warn("Unknown parameter type {} for {}", p.baseType, p.baseName); } } @@ -4031,7 +4037,7 @@ public class DefaultCodegen implements CodegenConfig { } else if (Boolean.TRUE.equals(cp.isAnyType)) { r.isAnyType = true; } else { - LOGGER.debug("Property type is not primitive: " + cp.dataType); + LOGGER.debug("Property type is not primitive: {}", cp.dataType); } if (cp.isContainer) { @@ -4047,7 +4053,7 @@ public class DefaultCodegen implements CodegenConfig { r.primitiveType = (r.baseType == null || languageSpecificPrimitives().contains(r.baseType)); - addVarsRequiredVarsAdditionaProps(responseSchema, r); + addVarsRequiredVarsAdditionalProps(responseSchema, r); } if (r.baseType == null) { @@ -4143,8 +4149,8 @@ public class DefaultCodegen implements CodegenConfig { codegenParameter.jsonSchema = Json.pretty(parameter); if (GlobalSettings.getProperty("debugParser") != null) { - LOGGER.info("working on Parameter " + parameter.getName()); - LOGGER.info("JSON schema: " + codegenParameter.jsonSchema); + LOGGER.info("working on Parameter {}", parameter.getName()); + LOGGER.info("JSON schema: {}", codegenParameter.jsonSchema); } if (parameter.getExtensions() != null && !parameter.getExtensions().isEmpty()) { @@ -4169,7 +4175,7 @@ public class DefaultCodegen implements CodegenConfig { if (parameterSchema != null) { parameterSchema = unaliasSchema(parameterSchema, Collections.emptyMap()); if (parameterSchema == null) { - LOGGER.warn("warning! Schema not found for parameter \"" + parameter.getName() + "\", using String"); + LOGGER.warn("warning! Schema not found for parameter \" {} \", using String", parameter.getName()); parameterSchema = new StringSchema().description("//TODO automatically added by openapi-generator due to missing type definition."); } ModelUtils.syncValidationProperties(parameterSchema, codegenParameter); @@ -4318,10 +4324,10 @@ public class DefaultCodegen implements CodegenConfig { codegenParameter.pattern != null || codegenParameter.multipleOf != null) { codegenParameter.hasValidation = true; } - addVarsRequiredVarsAdditionaProps(parameterSchema, codegenParameter); + addVarsRequiredVarsAdditionalProps(parameterSchema, codegenParameter); } else { - LOGGER.error("ERROR! Not handling " + parameter + " as Body Parameter at the moment"); + LOGGER.error("Not handling {} as Body Parameter at the moment", parameter); } if (parameter instanceof QueryParameter || "query".equalsIgnoreCase(parameter.getIn())) { @@ -4334,7 +4340,7 @@ public class DefaultCodegen implements CodegenConfig { } else if (parameter instanceof CookieParameter || "cookie".equalsIgnoreCase(parameter.getIn())) { codegenParameter.isCookieParam = true; } else { - LOGGER.warn("Unknown parameter type: " + parameter.getName()); + LOGGER.warn("Unknown parameter type: {}", parameter.getName()); } // default to UNKNOWN_PARAMETER_NAME if paramName is null @@ -4361,7 +4367,7 @@ public class DefaultCodegen implements CodegenConfig { setParameterExampleValue(codegenParameter, parameter); postProcessParameter(codegenParameter); - LOGGER.debug("debugging codegenParameter return: " + codegenParameter); + LOGGER.debug("debugging codegenParameter return: {}", codegenParameter); return codegenParameter; } @@ -4552,7 +4558,7 @@ public class DefaultCodegen implements CodegenConfig { } } operationId = sanitizeName(builder.toString()); - LOGGER.warn("Empty operationId found for path: " + httpMethod + " " + path + ". Renamed to auto-generated operationId: " + operationId); + LOGGER.warn("Empty operationId found for path: {} {}. Renamed to auto-generated operationId: {}", httpMethod, path, operationId); } return operationId; } @@ -4599,7 +4605,7 @@ public class DefaultCodegen implements CodegenConfig { Schema schema; if (header.getSchema() == null) { - LOGGER.warn("No schema defined for Header '" + headerEntry.getKey() + "', using a String schema"); + LOGGER.warn("No schema defined for Header '{}', using a String schema", headerEntry.getKey()); schema = new StringSchema(); } else { schema = header.getSchema(); @@ -5336,7 +5342,7 @@ public class DefaultCodegen implements CodegenConfig { } else if (Boolean.TRUE.equals(property.isAnyType)) { parameter.isAnyType = true; } else { - LOGGER.debug("Property type is not primitive: " + property.dataType); + LOGGER.debug("Property type is not primitive: {}", property.dataType); } if (Boolean.TRUE.equals(property.isFile)) { @@ -5507,7 +5513,7 @@ public class DefaultCodegen implements CodegenConfig { public boolean convertPropertyToBoolean(String propertyKey) { final Object booleanValue = additionalProperties.get(propertyKey); - Boolean result = Boolean.FALSE; + boolean result = Boolean.FALSE; if (booleanValue instanceof Boolean) { result = (Boolean) booleanValue; } else if (booleanValue instanceof String) { @@ -5536,7 +5542,6 @@ public class DefaultCodegen implements CodegenConfig { if (flow.getScopes() != null && !flow.getScopes().isEmpty()) { List> scopes = new ArrayList<>(); - int count = 0, numScopes = flow.getScopes().size(); for (Map.Entry scopeEntry : flow.getScopes().entrySet()) { Map scope = new HashMap<>(); scope.put("scope", scopeEntry.getKey()); @@ -5555,7 +5560,6 @@ public class DefaultCodegen implements CodegenConfig { Set consumes = requestBody.getContent().keySet(); List> mediaTypeList = new ArrayList<>(); - int count = 0; for (String key : consumes) { Map mediaType = new HashMap<>(); if ("*/*".equals(key)) { @@ -5626,13 +5630,12 @@ public class DefaultCodegen implements CodegenConfig { existingMediaTypes.add(mediaType.get("mediaType")); } - int count = 0; for (String key : produces) { // escape quotation to avoid code injection, "*/*" is a special case, do nothing String encodedKey = "*/*".equals(key) ? key : escapeText(escapeQuotationMark(key)); //Only unique media types should be added to "produces" if (!existingMediaTypes.contains(encodedKey)) { - Map mediaType = new HashMap(); + Map mediaType = new HashMap<>(); mediaType.put("mediaType", encodedKey); codegenOperation.produces.add(mediaType); codegenOperation.hasProduces = Boolean.TRUE; @@ -5696,8 +5699,8 @@ public class DefaultCodegen implements CodegenConfig { } public List fromRequestBodyToFormParameters(RequestBody body, Set imports) { - List parameters = new ArrayList(); - LOGGER.debug("debugging fromRequestBodyToFormParameters= " + body); + List parameters = new ArrayList<>(); + LOGGER.debug("debugging fromRequestBodyToFormParameters= {}", body); Schema schema = ModelUtils.getSchemaFromRequestBody(body); schema = ModelUtils.getReferencedSchema(this.openAPI, schema); List allRequired = new ArrayList(); @@ -5706,7 +5709,7 @@ public class DefaultCodegen implements CodegenConfig { if (!properties.isEmpty()) { for (Map.Entry entry : properties.entrySet()) { - CodegenParameter codegenParameter = CodegenModelFactory.newInstance(CodegenModelType.PARAMETER); + CodegenParameter codegenParameter; // key => property name // value => property schema Schema s = entry.getValue(); @@ -5728,7 +5731,7 @@ public class DefaultCodegen implements CodegenConfig { if (codegenParameter.baseType != null && codegenParameter.enumName != null) { codegenParameter.datatypeWithEnum = codegenParameter.dataType.replace(codegenParameter.baseType, codegenParameter.enumName); } else { - LOGGER.warn("Could not compute datatypeWithEnum from " + codegenParameter.baseType + ", " + codegenParameter.enumName); + LOGGER.warn("Could not compute datatypeWithEnum from {}, {}", codegenParameter.baseType, codegenParameter.enumName); } //TODO fix collectformat for form parameters //collectionFormat = getCollectionFormat(s); @@ -5898,7 +5901,7 @@ public class DefaultCodegen implements CodegenConfig { "It could be due to form parameter defined in OpenAPI v2 spec with incorrect consumes. " + "A correct 'consumes' for form parameters should be " + "'application/x-www-form-urlencoded' or 'multipart/?'"); - LOGGER.warn("schema: " + schema); + LOGGER.warn("schema: {}", schema); LOGGER.warn("codegenModel is null. Default to UNKNOWN_BASE_TYPE"); codegenModelName = "UNKNOWN_BASE_TYPE"; codegenModelDescription = "UNKNOWN_DESCRIPTION"; @@ -5944,7 +5947,7 @@ public class DefaultCodegen implements CodegenConfig { } String name = null; - LOGGER.debug("Request body = " + body); + LOGGER.debug("Request body = {}", body); Schema schema = ModelUtils.getSchemaFromRequestBody(body); if (schema == null) { throw new RuntimeException("Request body cannot be null. Possible cause: missing schema in body parameter (OAS v2): " + body); @@ -6097,7 +6100,7 @@ public class DefaultCodegen implements CodegenConfig { setParameterNullable(codegenParameter, codegenProperty); } - addVarsRequiredVarsAdditionaProps(schema, codegenParameter); + addVarsRequiredVarsAdditionalProps(schema, codegenParameter); addJsonSchemaForBodyRequestInCaseItsNotPresent(codegenParameter, body); // set the parameter's example value @@ -6107,7 +6110,7 @@ public class DefaultCodegen implements CodegenConfig { return codegenParameter; } - private void addVarsRequiredVarsAdditionaProps(Schema schema, IJsonSchemaValidationProperties property){ + private void addVarsRequiredVarsAdditionalProps(Schema schema, IJsonSchemaValidationProperties property){ if (!"object".equals(schema.getType())) { return; } @@ -6137,7 +6140,6 @@ public class DefaultCodegen implements CodegenConfig { CodegenProperty cp = fromProperty("", (Schema) schema.getAdditionalProperties()); property.setAdditionalProperties(cp); } - return; } private void addJsonSchemaForBodyRequestInCaseItsNotPresent(CodegenParameter codegenParameter, RequestBody body) { @@ -6257,7 +6259,9 @@ public class DefaultCodegen implements CodegenConfig { codegenServerVariable.value = value; if (enums != null && !enums.isEmpty() && !enums.contains(value)) { - LOGGER.warn("Variable override of '{}' is not listed in the enum of allowed values ({}).", value, StringUtils.join(enums, ",")); + if(LOGGER.isWarnEnabled()) { // prevents calculating StringUtils.join when debug isn't enabled + LOGGER.warn("Variable override of '{}' is not listed in the enum of allowed values ({}).", value, StringUtils.join(enums, ",")); + } } } else { codegenServerVariable.value = variable.getDefault(); @@ -6574,9 +6578,6 @@ public class DefaultCodegen implements CodegenConfig { return ModelUtils.getAdditionalProperties(openAPI, schema); } - final protected static Pattern JSON_MIME_PATTERN = Pattern.compile("(?i)application\\/json(;.*)?"); - final protected static Pattern JSON_VENDOR_MIME_PATTERN = Pattern.compile("(?i)application\\/vnd.(.*)+json(;.*)?"); - /** * Check if the given MIME is a JSON MIME. * JSON MIME examples: diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/DartJaguarClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/DartJaguarClientCodegen.java index 279bc4523b8..7bcc374d369 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/DartJaguarClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/DartJaguarClientCodegen.java @@ -42,26 +42,23 @@ public class DartJaguarClientCodegen extends AbstractDartCodegen { private static final String IS_FORMAT_PROTO = "protoFormat"; private static final String CLIENT_NAME = "clientName"; - private static Set modelToIgnore = new HashSet<>(); - private HashMap protoTypeMapping = new HashMap<>(); + private final Set modelToIgnore = new HashSet<>(); + private final HashMap protoTypeMapping = new HashMap<>(); + + private static final String SERIALIZATION_JSON = "json"; + private static final String SERIALIZATION_PROTO = "proto"; + + private boolean nullableFields = true; + + public DartJaguarClientCodegen() { + super(); - static { modelToIgnore.add("datetime"); modelToIgnore.add("map"); modelToIgnore.add("object"); modelToIgnore.add("list"); modelToIgnore.add("file"); modelToIgnore.add("list"); - } - - private static final String SERIALIZATION_JSON = "json"; - private static final String SERIALIZATION_PROTO = "proto"; - - private boolean nullableFields = true; - private String serialization = SERIALIZATION_JSON; - - public DartJaguarClientCodegen() { - super(); modifyFeatureSet(features -> features .includeDocumentationFeatures(DocumentationFeature.Readme) @@ -161,7 +158,7 @@ public class DartJaguarClientCodegen extends AbstractDartCodegen { } if (additionalProperties.containsKey(SERIALIZATION_FORMAT)) { - serialization = ((String) additionalProperties.get(SERIALIZATION_FORMAT)); + String serialization = ((String) additionalProperties.get(SERIALIZATION_FORMAT)); boolean isProto = serialization.equalsIgnoreCase(SERIALIZATION_PROTO); additionalProperties.put(IS_FORMAT_JSON, serialization.equalsIgnoreCase(SERIALIZATION_JSON)); additionalProperties.put(IS_FORMAT_PROTO, isProto); diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaCXFExtServerCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaCXFExtServerCodegen.java index 640c7b6915e..a02e91ad0f8 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaCXFExtServerCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaCXFExtServerCodegen.java @@ -306,7 +306,7 @@ public class JavaCXFExtServerCodegen extends JavaCXFServerCodegen implements CXF MAX_DATE = maxDate; } - private Map REGEX_GENERATORS = new HashMap<>(); + private final Map REGEX_GENERATORS = new HashMap<>(); protected boolean generateOperationBody = false;