Rename datatype to dataType in CodegenProperty (#69)

This commit is contained in:
Jérémie Bresson
2018-05-18 18:06:37 +02:00
committed by GitHub
parent 9b05bd60d5
commit a1ff502411
150 changed files with 459 additions and 444 deletions

View File

@@ -24,7 +24,7 @@ import java.util.Map;
import java.util.Objects;
public class CodegenProperty implements Cloneable {
public String baseName, complexType, getter, setter, description, datatype,
public String baseName, complexType, getter, setter, description, dataType,
datatypeWithEnum, dataFormat, name, min, max, defaultValue, defaultValueWithParam,
baseType, containerType, title;
@@ -121,12 +121,21 @@ public class CodegenProperty implements Cloneable {
this.description = description;
}
/**
* @deprecated since version 3.0.0, use {@link #getDataType()} instead.<br>
* May be removed with the next major release (4.0)
*/
@Deprecated
public String getDatatype() {
return datatype;
return getDataType();
}
public String getDataType() {
return dataType;
}
public void setDatatype(String datatype) {
this.datatype = datatype;
this.dataType = datatype;
}
public String getDatatypeWithEnum() {
@@ -408,7 +417,7 @@ public class CodegenProperty implements Cloneable {
result = prime * result + ((baseType == null) ? 0 : baseType.hashCode());
result = prime * result + ((complexType == null) ? 0 : complexType.hashCode());
result = prime * result + ((containerType == null) ? 0 : containerType.hashCode());
result = prime * result + ((datatype == null) ? 0 : datatype.hashCode());
result = prime * result + ((dataType == null) ? 0 : dataType.hashCode());
result = prime * result + ((datatypeWithEnum == null) ? 0 : datatypeWithEnum.hashCode());
result = prime * result + ((dataFormat == null) ? 0 : dataFormat.hashCode());
result = prime * result + ((defaultValue == null) ? 0 : defaultValue.hashCode());
@@ -500,7 +509,7 @@ public class CodegenProperty implements Cloneable {
if ((this.title == null) ? (other.title != null) : !this.title.equals(other.title)) {
return false;
}
if ((this.datatype == null) ? (other.datatype != null) : !this.datatype.equals(other.datatype)) {
if ((this.dataType == null) ? (other.dataType != null) : !this.dataType.equals(other.dataType)) {
return false;
}
if ((this.datatypeWithEnum == null) ? (other.datatypeWithEnum != null) : !this.datatypeWithEnum.equals(other.datatypeWithEnum)) {
@@ -708,7 +717,7 @@ public class CodegenProperty implements Cloneable {
", getter='" + getter + '\'' +
", setter='" + setter + '\'' +
", description='" + description + '\'' +
", datatype='" + datatype + '\'' +
", datatype='" + dataType + '\'' +
", datatypeWithEnum='" + datatypeWithEnum + '\'' +
", dataFormat='" + dataFormat + '\'' +
", name='" + name + '\'' +

View File

@@ -1820,7 +1820,7 @@ public class DefaultCodegen implements CodegenConfig {
}
}
property.datatype = getTypeDeclaration(p);
property.dataType = getTypeDeclaration(p);
property.dataFormat = p.getFormat();
property.baseType = getSchemaType(p);
@@ -1829,7 +1829,7 @@ public class DefaultCodegen implements CodegenConfig {
property.datatypeWithEnum = toEnumName(property);
property.enumName = toEnumName(property);
} else {
property.datatypeWithEnum = property.datatype;
property.datatypeWithEnum = property.dataType;
}
if (ModelUtils.isArraySchema(p)) {
@@ -2166,7 +2166,7 @@ public class DefaultCodegen implements CodegenConfig {
// generate examples
op.examples = new ExampleGenerator(schemas, openAPI).generateFromResponseSchema(responseSchema, getProducesInfo(openAPI, operation));
op.defaultResponse = toDefaultValue(responseSchema);
op.returnType = cm.datatype;
op.returnType = cm.dataType;
op.hasReference = schemas != null && schemas.containsKey(op.returnBaseType);
// lookup discriminator
@@ -2418,7 +2418,7 @@ public class DefaultCodegen implements CodegenConfig {
}
}
r.dataType = cp.datatype;
r.dataType = cp.dataType;
if (Boolean.TRUE.equals(cp.isString) && Boolean.TRUE.equals(cp.isUuid)) {
r.isUuid = true;
@@ -2453,7 +2453,7 @@ public class DefaultCodegen implements CodegenConfig {
} else if (Boolean.TRUE.equals(cp.isDateTime)) {
r.isDateTime = true;
} else {
LOGGER.debug("Property type is not primitive: " + cp.datatype);
LOGGER.debug("Property type is not primitive: " + cp.dataType);
}
if (cp.isContainer) {
@@ -2530,7 +2530,7 @@ public class DefaultCodegen implements CodegenConfig {
collectionFormat = StringUtils.isEmpty(collectionFormat) ? "csv" : collectionFormat;
CodegenProperty codegenProperty = fromProperty("inner", inner);
codegenParameter.items = codegenProperty;
codegenParameter.baseType = codegenProperty.datatype;
codegenParameter.baseType = codegenProperty.dataType;
codegenParameter.isContainer = true;
codegenParameter.isListContainer = true;
@@ -2544,7 +2544,7 @@ public class DefaultCodegen implements CodegenConfig {
} else if (ModelUtils.isMapSchema(parameterSchema)) { // for map parameter
CodegenProperty codegenProperty = fromProperty("inner", (Schema) parameterSchema.getAdditionalProperties());
codegenParameter.items = codegenProperty;
codegenParameter.baseType = codegenProperty.datatype;
codegenParameter.baseType = codegenProperty.dataType;
codegenParameter.isContainer = true;
codegenParameter.isMapContainer = true;
@@ -2578,7 +2578,7 @@ public class DefaultCodegen implements CodegenConfig {
if (parameterDataType != null) {
codegenParameter.dataType = parameterDataType;
} else {
codegenParameter.dataType = codegenProperty.datatype;
codegenParameter.dataType = codegenProperty.dataType;
}
codegenParameter.dataFormat = codegenProperty.dataFormat;
codegenParameter.required = codegenProperty.required;
@@ -3674,7 +3674,7 @@ public class DefaultCodegen implements CodegenConfig {
parameter.isDateTime = true;
parameter.isPrimitiveType = 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)) {
@@ -3720,8 +3720,8 @@ public class DefaultCodegen implements CodegenConfig {
enumName = value.toString();
}
}
enumVar.put("name", toEnumVarName(enumName, var.datatype));
enumVar.put("value", toEnumValue(value.toString(), var.datatype));
enumVar.put("name", toEnumVarName(enumName, var.dataType));
enumVar.put("value", toEnumValue(value.toString(), var.dataType));
enumVars.add(enumVar);
}
allowableValues.put("enumVars", enumVars);
@@ -3730,7 +3730,7 @@ public class DefaultCodegen implements CodegenConfig {
if (var.defaultValue != null) {
String enumName = null;
for (Map<String, String> enumVar : enumVars) {
if (toEnumValue(var.defaultValue, var.datatype).equals(enumVar.get("value"))) {
if (toEnumValue(var.defaultValue, var.dataType).equals(enumVar.get("value"))) {
enumName = enumVar.get("name");
break;
}
@@ -4084,7 +4084,7 @@ public class DefaultCodegen implements CodegenConfig {
codegenParameter = fromFormProperty(entry.getKey(), inner, imports);
CodegenProperty codegenProperty = fromProperty("inner", inner);
codegenParameter.items = codegenProperty;
codegenParameter.baseType = codegenProperty.datatype;
codegenParameter.baseType = codegenProperty.dataType;
codegenParameter.isPrimitiveType = false;
codegenParameter.isContainer = true;
codegenParameter.isListContainer = true;
@@ -4131,7 +4131,7 @@ public class DefaultCodegen implements CodegenConfig {
codegenParameter.baseName = codegenProperty.baseName;
codegenParameter.paramName = toParamName((codegenParameter.baseName));
codegenParameter.baseType = codegenProperty.baseType;
codegenParameter.dataType = codegenProperty.datatype;
codegenParameter.dataType = codegenProperty.dataType;
codegenParameter.dataFormat = codegenProperty.dataFormat;
codegenParameter.description = escapeText(codegenProperty.description);
codegenParameter.unescapedDescription = codegenProperty.getDescription();
@@ -4317,7 +4317,7 @@ public class DefaultCodegen implements CodegenConfig {
codegenParameter.baseName = codegenProperty.baseType;
codegenParameter.baseType = codegenProperty.baseType;
codegenParameter.dataType = codegenProperty.datatype;
codegenParameter.dataType = codegenProperty.dataType;
codegenParameter.description = codegenProperty.description;
codegenParameter.paramName = toParamName(codegenProperty.baseType);
@@ -4339,7 +4339,7 @@ public class DefaultCodegen implements CodegenConfig {
}
codegenParameter.isPrimitiveType = true;
codegenParameter.baseType = codegenProperty.baseType;
codegenParameter.dataType = codegenProperty.datatype;
codegenParameter.dataType = codegenProperty.dataType;
codegenParameter.description = codegenProperty.description;
codegenParameter.paramName = toParamName(codegenParameter.baseName);

View File

@@ -413,7 +413,7 @@ abstract public class AbstractAdaCodegen extends DefaultCodegen implements Codeg
if (methodResponse != null && ModelUtils.getSchemaFromResponse(methodResponse) != null) {
CodegenProperty cm = fromProperty("response", ModelUtils.getSchemaFromResponse(methodResponse));
op.vendorExtensions.put("x-codegen-response", cm);
if ("HttpContent".equals(cm.datatype)) {
if ("HttpContent".equals(cm.dataType)) {
op.vendorExtensions.put("x-codegen-response-ishttpcontent", true);
}
}
@@ -498,9 +498,9 @@ abstract public class AbstractAdaCodegen extends DefaultCodegen implements Codeg
item = p.items;
}
if (item != null && !item.isString && !item.isPrimitiveType && !item.isContainer && !item.isInteger) {
if (!d.contains(item.datatype)) {
if (!d.contains(item.dataType)) {
// LOGGER.info("Model " + m.name + " uses " + p.datatype);
d.add(item.datatype);
d.add(item.dataType);
}
isModel = true;
}

View File

@@ -412,11 +412,11 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen implements Co
CodegenModel model = ModelUtils.getModelByName(swaggerName, models);
if (model != null) {
for (CodegenProperty var : model.allVars) {
if (enumRefs.containsKey(var.datatype)) {
if (enumRefs.containsKey(var.dataType)) {
// Handle any enum properties referred to by $ref.
// This is different in C# than most other generators, because enums in C# are compiled to integral types,
// while enums in many other languages are true objects.
CodegenModel refModel = enumRefs.get(var.datatype);
CodegenModel refModel = enumRefs.get(var.dataType);
var.allowableValues = refModel.allowableValues;
var.isEnum = true;

View File

@@ -302,7 +302,7 @@ public class ApexClientCodegen extends AbstractJavaCodegen {
String type = p.baseType;
if (type == null) {
type = p.datatype;
type = p.dataType;
}
if (Boolean.TRUE.equals(p.isInteger)) {
@@ -607,7 +607,7 @@ public class ApexClientCodegen extends AbstractJavaCodegen {
super.updateCodegenPropertyEnum(var);
if (var.isEnum && var.example != null) {
String example = var.example.replace("'", "");
example = toEnumVarName(example, var.datatype);
example = toEnumVarName(example, var.dataType);
var.example = toEnumDefaultValue(example, var.datatypeWithEnum);
}
}

View File

@@ -170,7 +170,7 @@ public class CppPistacheServerCodegen extends AbstractCppCodegen {
if (response != null) {
CodegenProperty cm = fromProperty("response", response);
op.vendorExtensions.put("x-codegen-response", cm);
if ("HttpContent".equals(cm.datatype)) {
if ("HttpContent".equals(cm.dataType)) {
op.vendorExtensions.put("x-codegen-response-ishttpcontent", true);
}
}

View File

@@ -241,7 +241,7 @@ public class CppRestClientCodegen extends AbstractCppCodegen {
if (response != null) {
CodegenProperty cm = fromProperty("response", response);
op.vendorExtensions.put("x-codegen-response", cm);
if ("HttpContent".equals(cm.datatype)) {
if ("HttpContent".equals(cm.dataType)) {
op.vendorExtensions.put("x-codegen-response-ishttpcontent", true);
}
}

View File

@@ -496,7 +496,7 @@ public class ElmClientCodegen extends DefaultCodegen implements CodegenConfig {
public CodegenProperty fromProperty(String name, Schema p) {
final CodegenProperty property = super.fromProperty(name, p);
final String dataType = property.isEnum ? property.baseName : property.datatype;
final String dataType = property.isEnum ? property.baseName : property.dataType;
addEncoderAndDecoder(property.vendorExtensions, dataType, property.isMapContainer, property.isPrimitiveType && !property.isEnum);
if (property.isEnum) {
property.vendorExtensions.put(X_UNION_TYPE, property.datatypeWithEnum);

View File

@@ -1202,7 +1202,7 @@ public class HaskellHttpClientCodegen extends DefaultCodegen implements CodegenC
for (CodegenProperty var : cm.vars) {
String datatype = genEnums && !StringUtils.isBlank(var.datatypeWithEnum)
? var.datatypeWithEnum
: var.datatype;
: var.dataType;
var.vendorExtensions.put(X_DATA_TYPE, datatype);
}
}
@@ -1261,7 +1261,7 @@ public class HaskellHttpClientCodegen extends DefaultCodegen implements CodegenC
paramNameType = toDedupedModelName(paramNameType, enumValues, false);
var.datatypeWithEnum = paramNameType;
updateCodegenPropertyEnum(var);
addEnumToUniques(paramNameType, var.datatype, enumValues, var.allowableValues, var.description);
addEnumToUniques(paramNameType, var.dataType, enumValues, var.allowableValues, var.description);
}
return paramNameType;

View File

@@ -711,7 +711,7 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
String type = p.baseType;
if (type == null) {
type = p.datatype;
type = p.dataType;
}
if (Boolean.TRUE.equals(p.isInteger)) {
@@ -877,7 +877,7 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
private boolean isModelledType(CodegenProperty cp) {
// N.B. enums count as modelled types, file is not modelled (SuperAgent uses some 3rd party library).
return cp.isEnum || !languageSpecificPrimitives.contains(cp.baseType == null ? cp.datatype : cp.baseType);
return cp.isEnum || !languageSpecificPrimitives.contains(cp.baseType == null ? cp.dataType : cp.baseType);
}
private String getJSDocType(CodegenParameter cp) {

View File

@@ -493,7 +493,7 @@ public class PerlClientCodegen extends DefaultCodegen implements CodegenConfig {
String type = p.baseType;
if (type == null) {
type = p.datatype;
type = p.dataType;
}
if (Boolean.TRUE.equals(p.isInteger)) {

View File

@@ -422,18 +422,18 @@ public class PhpSymfonyServerCodegen extends AbstractPhpCodegen implements Codeg
// Simplify model var type
for (CodegenProperty var : model.vars) {
if (var.datatype != null) {
if (var.dataType != null) {
// Determine if the parameter type is supported as a type hint and make it available
// to the templating engine
String typeHint = getTypeHint(var.datatype);
String typeHint = getTypeHint(var.dataType);
if (!typeHint.isEmpty()) {
var.vendorExtensions.put("x-parameterType", typeHint);
}
// Create a variable to display the correct data type in comments for models
var.vendorExtensions.put("x-commentType", var.datatype);
var.vendorExtensions.put("x-commentType", var.dataType);
if (var.isContainer) {
var.vendorExtensions.put("x-commentType", var.datatype + "[]");
var.vendorExtensions.put("x-commentType", var.dataType + "[]");
}
}
}

View File

@@ -698,14 +698,14 @@ public class RustServerCodegen extends DefaultCodegen implements CodegenConfig {
}
}
for (CodegenProperty header : rsp.headers) {
if (header.datatype.equals("uuid::Uuid")) {
if (header.dataType.equals("uuid::Uuid")) {
additionalProperties.put("apiUsesUuid", true);
}
header.nameInCamelCase = toModelName(header.baseName);
}
}
for (CodegenProperty header : op.responseHeaders) {
if (header.datatype.equals("uuid::Uuid")) {
if (header.dataType.equals("uuid::Uuid")) {
additionalProperties.put("apiUsesUuid", true);
}
header.nameInCamelCase = toModelName(header.baseName);
@@ -873,7 +873,7 @@ public class RustServerCodegen extends DefaultCodegen implements CodegenConfig {
CodegenModel model = entry.getValue();
for (CodegenProperty prop : model.vars) {
String xmlName = modelXmlNames.get(prop.datatype);
String xmlName = modelXmlNames.get(prop.dataType);
if (xmlName != null) {
prop.vendorExtensions.put("itemXmlName", xmlName);
}
@@ -939,22 +939,22 @@ public class RustServerCodegen extends DefaultCodegen implements CodegenConfig {
@Override
public void postProcessModelProperty(CodegenModel model, CodegenProperty property) {
super.postProcessModelProperty(model, property);
if (!languageSpecificPrimitives.contains(property.datatype)) {
if (!languageSpecificPrimitives.contains(property.dataType)) {
// If we use a more qualified model name, then only camelize the actual type, not the qualifier.
if (property.datatype.contains(":")) {
int position = property.datatype.lastIndexOf(":");
property.datatype = property.datatype.substring(0, position) + camelize(property.datatype.substring(position));
if (property.dataType.contains(":")) {
int position = property.dataType.lastIndexOf(":");
property.dataType = property.dataType.substring(0, position) + camelize(property.dataType.substring(position));
} else {
property.datatype = camelize(property.datatype, false);
property.dataType = camelize(property.dataType, false);
}
}
if ("integer".equals(property.baseType)) {
// custom integer formats (legacy)
if ("uint32".equals(property.dataFormat)) {
property.datatype = "u32";
property.dataType = "u32";
} else if ("uint64".equals(property.dataFormat)) {
property.datatype = "u64";
property.dataType = "u64";
} else {
// match int type to schema constraints
@@ -974,21 +974,21 @@ public class RustServerCodegen extends DefaultCodegen implements CodegenConfig {
switch (property.dataFormat == null ? NO_FORMAT : property.dataFormat) {
// standard swagger formats
case "int32":
property.datatype = unsigned ? "u32" : "i32";
property.dataType = unsigned ? "u32" : "i32";
break;
case "int64":
property.datatype = unsigned ? "u64" : "i64";
property.dataType = unsigned ? "u64" : "i64";
break;
case NO_FORMAT:
property.datatype = matchingIntType(unsigned, inclusiveMinimum, inclusiveMaximum);
property.dataType = matchingIntType(unsigned, inclusiveMinimum, inclusiveMaximum);
break;
default:
// unknown format
LOGGER.warn("The integer format '{}' is not recognized and will be ignored.", property.dataFormat);
property.datatype = matchingIntType(unsigned, inclusiveMinimum, inclusiveMaximum);
property.dataType = matchingIntType(unsigned, inclusiveMinimum, inclusiveMaximum);
}
}
}