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
This commit is contained in:
agilob 2021-03-02 09:24:25 +00:00 committed by GitHub
parent 5ce64756a6
commit a34569f065
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 94 additions and 96 deletions

View File

@ -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<String, String> instantiationTypes;
private ImmutableMap<String, String> typeMappings;
private ImmutableMap<String, Object> additionalProperties;
private ImmutableMap<String, String> importMappings;
private ImmutableSet<String> languageSpecificPrimitives;
private ImmutableMap<String, String> reservedWordMappings;
private ImmutableMap<String, String> serverVariables;
private final ImmutableMap<String, String> instantiationTypes;
private final ImmutableMap<String, String> typeMappings;
private final ImmutableMap<String, Object> additionalProperties;
private final ImmutableMap<String, String> importMappings;
private final ImmutableSet<String> languageSpecificPrimitives;
private final ImmutableMap<String, String> reservedWordMappings;
private final ImmutableMap<String, String> serverVariables;
private String gitHost;
private String gitUserId;

View File

@ -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;

View File

@ -142,10 +142,10 @@ public class DefaultCodegen implements CodegenConfig {
protected GeneratorMetadata generatorMetadata;
protected String inputSpec;
protected String outputFolder = "";
protected Set<String> defaultIncludes = new HashSet<String>();
protected Map<String, String> typeMapping = new HashMap<String, String>();
protected Map<String, String> instantiationTypes = new HashMap<String, String>();
protected Set<String> reservedWords = new HashSet<String>();
protected Set<String> defaultIncludes;
protected Map<String, String> typeMapping;
protected Map<String, String> instantiationTypes;
protected Set<String> reservedWords;
protected Set<String> languageSpecificPrimitives = new HashSet<String>();
protected Map<String, String> importMapping = new HashMap<String, String>();
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<String, Object> modelValue = new HashMap<>(additionalProperties());
modelValue.put("model", cm);
List<Object> modelsValue = Arrays.asList(modelValue);
List<Map<String, String>> importsValue = new ArrayList<Map<String, String>>();
List<Map<String, String>> importsValue = new ArrayList<>();
Map<String, Object> 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<String, OneOfImplementorAdditionalData> additionalDataMap = new HashMap<String, OneOfImplementorAdditionalData>();
for (Map.Entry modelsEntry : objs.entrySet()) {
for (Map.Entry<String, Object> modelsEntry : objs.entrySet()) {
Map<String, Object> modelsAttrs = (Map<String, Object>) modelsEntry.getValue();
List<Object> models = (List<Object>) modelsAttrs.get("models");
List<Map<String, String>> modelsImports = (List<Map<String, String>>) modelsAttrs.getOrDefault("imports", new ArrayList<Map<String, String>>());
@ -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<String, Object> modelsEntry : objs.entrySet()) {
Map<String, Object> modelsAttrs = (Map<String, Object>) modelsEntry.getValue();
List<Object> models = (List<Object>) modelsAttrs.get("models");
List<Map<String, String>> imports = (List<Map<String, String>>) modelsAttrs.get("imports");
@ -464,10 +467,8 @@ public class DefaultCodegen implements CodegenConfig {
protected Map<String, Schema> getModelNameToSchemaCache() {
if (modelNameToSchemaCache == null) {
// Create a cache to efficiently lookup schema based on model name.
Map<String, Schema> m = new HashMap<String, Schema>();
ModelUtils.getSchemas(openAPI).forEach((key, schema) -> {
m.put(toModelName(key), schema);
});
Map<String, Schema> 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<CodegenModel>(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<CodegenModel>());
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<String, List<CodegenProperty>> dependencyMap) {
dependencyMap.getOrDefault(root, new ArrayList<>()).stream()
dependencyMap.getOrDefault(root, new ArrayList<>())
.forEach(prop -> {
final List<String> 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<MappedModel> getOneOfAnyOfDescendants(String composedSchemaName, String discPropName, ComposedSchema c, OpenAPI openAPI) {
ArrayList<List<Schema>> listOLists = new ArrayList<List<Schema>>();
ArrayList<List<Schema>> listOLists = new ArrayList<>();
listOLists.add(c.getOneOf());
listOLists.add(c.getAnyOf());
List<MappedModel> descendentSchemas = new ArrayList();
List<MappedModel> descendentSchemas = new ArrayList<>();
for (List<Schema> 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<String, Object> getInnerEnumAllowableValues(CodegenProperty property) {
CodegenProperty currentProperty = getMostInnerItems(property);
return currentProperty == null ? new HashMap<String, Object>() : currentProperty.allowableValues;
return currentProperty == null ? new HashMap<>() : currentProperty.allowableValues;
}
/**
@ -3614,7 +3620,7 @@ public class DefaultCodegen implements CodegenConfig {
String httpMethod,
Operation operation,
List<Server> 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.<String, String>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<Map<String, Object>> scopes = new ArrayList<>();
int count = 0, numScopes = flow.getScopes().size();
for (Map.Entry<String, String> scopeEntry : flow.getScopes().entrySet()) {
Map<String, Object> scope = new HashMap<>();
scope.put("scope", scopeEntry.getKey());
@ -5555,7 +5560,6 @@ public class DefaultCodegen implements CodegenConfig {
Set<String> consumes = requestBody.getContent().keySet();
List<Map<String, String>> mediaTypeList = new ArrayList<>();
int count = 0;
for (String key : consumes) {
Map<String, String> 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<String, String> mediaType = new HashMap<String, String>();
Map<String, String> 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<CodegenParameter> fromRequestBodyToFormParameters(RequestBody body, Set<String> imports) {
List<CodegenParameter> parameters = new ArrayList<CodegenParameter>();
LOGGER.debug("debugging fromRequestBodyToFormParameters= " + body);
List<CodegenParameter> parameters = new ArrayList<>();
LOGGER.debug("debugging fromRequestBodyToFormParameters= {}", body);
Schema schema = ModelUtils.getSchemaFromRequestBody(body);
schema = ModelUtils.getReferencedSchema(this.openAPI, schema);
List<String> allRequired = new ArrayList<String>();
@ -5706,7 +5709,7 @@ public class DefaultCodegen implements CodegenConfig {
if (!properties.isEmpty()) {
for (Map.Entry<String, Schema> 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,8 +6259,10 @@ public class DefaultCodegen implements CodegenConfig {
codegenServerVariable.value = value;
if (enums != null && !enums.isEmpty() && !enums.contains(value)) {
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:

View File

@ -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<String> modelToIgnore = new HashSet<>();
private HashMap<String, String> protoTypeMapping = new HashMap<>();
private final Set<String> modelToIgnore = new HashSet<>();
private final HashMap<String, String> 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<int>");
}
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);

View File

@ -306,7 +306,7 @@ public class JavaCXFExtServerCodegen extends JavaCXFServerCodegen implements CXF
MAX_DATE = maxDate;
}
private Map<String, Generex> REGEX_GENERATORS = new HashMap<>();
private final Map<String, Generex> REGEX_GENERATORS = new HashMap<>();
protected boolean generateOperationBody = false;