diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/AbstractGenerator.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/AbstractGenerator.java index 5ed07851338..cadd7a1d85f 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/AbstractGenerator.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/AbstractGenerator.java @@ -66,6 +66,9 @@ public abstract class AbstractGenerator { /** * Get the template file path with template dir prepended, and use the * library template if exists. + * + * @param config Codegen config + * @param templateFile Template file */ public String getFullTemplateFile(CodegenConfig config, String templateFile) { String library = config.getLibrary(); diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenConfig.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenConfig.java index 84f7fc50fb8..bf79a3b7270 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenConfig.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenConfig.java @@ -147,6 +147,8 @@ public interface CodegenConfig { /** * Library template (sub-template). + * + * @return libray template */ String getLibrary(); } diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenParameter.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenParameter.java index 9bf2858161d..55e21b7c421 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenParameter.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenParameter.java @@ -7,10 +7,13 @@ import java.util.List; public class CodegenParameter { public Boolean isFormParam, isQueryParam, isPathParam, isHeaderParam, - isCookieParam, isBodyParam, isFile, notFile, hasMore, isContainer, - secondaryParam, isBinary, isCollectionFormatMulti; + isCookieParam, isBodyParam, hasMore, isContainer, + secondaryParam, isCollectionFormatMulti; public String baseName, paramName, dataType, collectionFormat, description, baseType, defaultValue; public String jsonSchema; + public Boolean isString, isInteger, isLong, isFloat, isDouble, isByteArray, isBinary, isBoolean, isDate, isDateTime; + public Boolean isListContainer, isMapContainer; + public Boolean isFile, notFile; public boolean isEnum; public List _enum; public Map allowableValues; @@ -111,6 +114,17 @@ public class CodegenParameter { } output.vendorExtensions = this.vendorExtensions; output.isBinary = this.isBinary; + output.isByteArray = this.isByteArray; + output.isString = this.isString; + output.isInteger = this.isInteger; + output.isLong = this.isLong; + output.isDouble = this.isDouble; + output.isFloat = this.isFloat; + output.isBoolean = this.isBoolean; + output.isDate = this.isDate; + output.isDateTime = this.isDateTime; + output.isListContainer = this.isListContainer; + output.isMapContainer = this.isMapContainer; return output; } diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenProperty.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenProperty.java index 2808c9dcc2a..0091204a0ab 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenProperty.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenProperty.java @@ -33,6 +33,8 @@ public class CodegenProperty { public Boolean exclusiveMaximum; public Boolean hasMore, required, secondaryParam; public Boolean isPrimitiveType, isContainer, isNotContainer; + public Boolean isString, isInteger, isLong, isFloat, isDouble, isByteArray, isBinary, isBoolean, isDate, isDateTime; + public Boolean isListContainer, isMapContainer; public boolean isEnum; public Boolean isReadOnly = false; public List _enum; @@ -81,6 +83,18 @@ public class CodegenProperty { result = prime * result + ((setter == null) ? 0 : setter.hashCode()); result = prime * result + ((unescapedDescription == null) ? 0 : unescapedDescription.hashCode()); result = prime * result + ((vendorExtensions == null) ? 0 : vendorExtensions.hashCode()); + result = prime * result + ((isString == null) ? 0 : isString.hashCode()); + result = prime * result + ((isInteger == null) ? 0 : isInteger.hashCode()); + result = prime * result + ((isLong == null) ? 0 : isLong.hashCode()); + result = prime * result + ((isFloat == null) ? 0 : isFloat.hashCode()); + result = prime * result + ((isDouble == null) ? 0 : isDouble.hashCode()); + result = prime * result + ((isByteArray == null) ? 0 : isByteArray.hashCode()); + result = prime * result + ((isBinary == null) ? 0 : isBinary.hashCode()); + result = prime * result + ((isBoolean == null) ? 0 : isBoolean.hashCode()); + result = prime * result + ((isDate == null) ? 0 : isDate.hashCode()); + result = prime * result + ((isDateTime == null) ? 0 : isDateTime.hashCode()); + result = prime * result + ((isMapContainer == null) ? 0 : isMapContainer.hashCode()); + result = prime * result + ((isListContainer == null) ? 0 : isListContainer.hashCode()); return result; } @@ -189,6 +203,42 @@ public class CodegenProperty { if (this.vendorExtensions != other.vendorExtensions && (this.vendorExtensions == null || !this.vendorExtensions.equals(other.vendorExtensions))) { return false; } + if (this.isString != other.isString && (this.isString == null || !this.isString.equals(other.isString))) { + return false; + } + if (this.isInteger != other.isInteger && (this.isInteger == null || !this.isInteger.equals(other.isInteger))) { + return false; + } + if (this.isLong != other.isLong && (this.isLong == null || !this.isLong.equals(other.isLong))) { + return false; + } + if (this.isFloat != other.isFloat && (this.isFloat == null || !this.isFloat.equals(other.isFloat))) { + return false; + } + if (this.isDouble != other.isDouble && (this.isDouble == null || !this.isDouble.equals(other.isDouble))) { + return false; + } + if (this.isByteArray != other.isByteArray && (this.isByteArray == null || !this.isByteArray.equals(other.isByteArray))) { + return false; + } + if (this.isBoolean != other.isBoolean && (this.isBoolean == null || !this.isBoolean.equals(other.isBoolean))) { + return false; + } + if (this.isDate != other.isDate && (this.isDate == null || !this.isDate.equals(other.isDate))) { + return false; + } + if (this.isDateTime != other.isDateTime && (this.isDateTime == null || !this.isDateTime.equals(other.isDateTime))) { + return false; + } + if (this.isBinary != other.isBinary && (this.isBinary == null || !this.isBinary.equals(other.isBinary))) { + return false; + } + if (this.isListContainer != other.isListContainer && (this.isListContainer == null || !this.isListContainer.equals(other.isListContainer))) { + return false; + } + if (this.isMapContainer != other.isMapContainer && (this.isMapContainer == null || !this.isMapContainer.equals(other.isMapContainer))) { + return false; + } return true; } } diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java index 0ad30ed8459..7bfbb6374eb 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java @@ -1020,6 +1020,7 @@ public class DefaultCodegen { property.maxLength = sp.getMaxLength(); property.minLength = sp.getMinLength(); property.pattern = sp.getPattern(); + property.isString = true; if (sp.getEnum() != null) { List _enum = sp.getEnum(); property._enum = _enum; @@ -1034,6 +1035,7 @@ public class DefaultCodegen { if (p instanceof IntegerProperty) { IntegerProperty sp = (IntegerProperty) p; + property.isInteger = true; if (sp.getEnum() != null) { List _enum = sp.getEnum(); property._enum = new ArrayList(); @@ -1051,6 +1053,7 @@ public class DefaultCodegen { if (p instanceof LongProperty) { LongProperty sp = (LongProperty) p; + property.isLong = true; if (sp.getEnum() != null) { List _enum = sp.getEnum(); property._enum = new ArrayList(); @@ -1066,8 +1069,21 @@ public class DefaultCodegen { } } + if (p instanceof BooleanProperty) { + property.isBoolean = true; + } + + if (p instanceof BinaryProperty) { + property.isBinary = true; + } + + if (p instanceof ByteArrayProperty) { + property.isByteArray = true; + } + if (p instanceof DoubleProperty) { DoubleProperty sp = (DoubleProperty) p; + property.isDouble = true; if (sp.getEnum() != null) { List _enum = sp.getEnum(); property._enum = new ArrayList(); @@ -1085,6 +1101,7 @@ public class DefaultCodegen { if (p instanceof FloatProperty) { FloatProperty sp = (FloatProperty) p; + property.isFloat = true; if (sp.getEnum() != null) { List _enum = sp.getEnum(); property._enum = new ArrayList(); @@ -1102,6 +1119,7 @@ public class DefaultCodegen { if (p instanceof DateProperty) { DateProperty sp = (DateProperty) p; + property.isDate = true; if (sp.getEnum() != null) { List _enum = sp.getEnum(); property._enum = new ArrayList(); @@ -1119,6 +1137,7 @@ public class DefaultCodegen { if (p instanceof DateTimeProperty) { DateTimeProperty sp = (DateTimeProperty) p; + property.isDateTime = true; if (sp.getEnum() != null) { List _enum = sp.getEnum(); property._enum = new ArrayList(); @@ -1146,6 +1165,7 @@ public class DefaultCodegen { if (p instanceof ArrayProperty) { property.isContainer = true; + property.isListContainer = true; property.containerType = "array"; ArrayProperty ap = (ArrayProperty) p; CodegenProperty cp = fromProperty(property.name, ap.getItems()); @@ -1168,6 +1188,7 @@ public class DefaultCodegen { } } else if (p instanceof MapProperty) { property.isContainer = true; + property.isMapContainer = true; property.containerType = "map"; MapProperty ap = (MapProperty) p; CodegenProperty cp = fromProperty("inner", ap.getAdditionalProperties()); @@ -1575,7 +1596,7 @@ public class DefaultCodegen { if (null == type) { LOGGER.warn("Type is NULL for Serializable Parameter: " + param); } - if ("array".equals(type)) { + if ("array".equals(type)) { // for array parameter Property inner = qp.getItems(); if (inner == null) { LOGGER.warn("warning! No inner type supplied for array parameter \"" + qp.getName() + "\", using String"); @@ -1589,8 +1610,9 @@ public class DefaultCodegen { CodegenProperty pr = fromProperty("inner", inner); p.baseType = pr.datatype; p.isContainer = true; + p.isListContainer = true; imports.add(pr.baseType); - } else if ("object".equals(type)) { + } else if ("object".equals(type)) { // for map parameter Property inner = qp.getItems(); if (inner == null) { LOGGER.warn("warning! No inner type supplied for map parameter \"" + qp.getName() + "\", using String"); @@ -1600,6 +1622,8 @@ public class DefaultCodegen { collectionFormat = qp.getCollectionFormat(); CodegenProperty pr = fromProperty("inner", inner); p.baseType = pr.datatype; + p.isContainer = true; + p.isMapContainer = true; imports.add(pr.baseType); } else { Map args = new HashMap(); @@ -1607,12 +1631,17 @@ public class DefaultCodegen { args.put(PropertyId.ENUM, qp.getEnum()); property = PropertyBuilder.build(type, format, args); } + if (property == null) { LOGGER.warn("warning! Property type \"" + type + "\" not found for parameter \"" + param.getName() + "\", using String"); property = new StringProperty().description("//TODO automatically added by swagger-codegen. Type was " + type + " but not supported"); } property.setRequired(param.getRequired()); CodegenProperty model = fromProperty(qp.getName(), property); + + // set boolean flag (e.g. isString) + setParameterBooleanFlagWithCodegenProperty(p, model); + p.dataType = model.datatype; p.isEnum = model.isEnum; p._enum = model._enum; @@ -1663,6 +1692,9 @@ public class DefaultCodegen { p.dataType = cp.datatype; p.isBinary = cp.datatype.toLowerCase().startsWith("byte"); } + + // set boolean flag (e.g. isString) + setParameterBooleanFlagWithCodegenProperty(p, cp); } } else if (model instanceof ArrayModel) { // to use the built-in model parsing, we unwrap the ArrayModel @@ -1678,6 +1710,10 @@ public class DefaultCodegen { imports.add(cp.baseType); p.dataType = cp.datatype; p.isContainer = true; + p.isListContainer = true; + + // set boolean flag (e.g. isString) + setParameterBooleanFlagWithCodegenProperty(p, cp); } else { Model sub = bp.getSchema(); if (sub instanceof RefModel) { @@ -2157,6 +2193,8 @@ public class DefaultCodegen { /** * Library template (sub-template). + * + * @return Library template */ public String getLibrary() { return library; @@ -2221,10 +2259,10 @@ public class DefaultCodegen { } /** - * only write if the file doesn't exist + * Only write if the file doesn't exist * - * @param outputFolder - * @param supportingFile + * @param outputFolder Output folder + * @param supportingFile Supporting file */ public void writeOptional(String outputFolder, SupportingFile supportingFile) { String folder = ""; @@ -2243,4 +2281,46 @@ public class DefaultCodegen { supportingFiles.add(supportingFile); } } + + /** + * Set CodegenParameter boolean flag using CodegenProperty. + * + * @param parameter Codegen Parameter + * @param property Codegen property + */ + public void setParameterBooleanFlagWithCodegenProperty(CodegenParameter parameter, CodegenProperty property) { + if (parameter == null) { + LOGGER.error("Codegen Parameter cannnot be null."); + return; + } + + if (property == null) { + LOGGER.error("Codegen Property cannot be null."); + return; + } + + if (Boolean.TRUE.equals(property.isString)) { + parameter.isString = true; + } else if (Boolean.TRUE.equals(property.isBoolean)) { + parameter.isBoolean = true; + } else if (Boolean.TRUE.equals(property.isLong)) { + parameter.isLong = true; + } else if (Boolean.TRUE.equals(property.isInteger)) { + parameter.isInteger = true; + } else if (Boolean.TRUE.equals(property.isDouble)) { + parameter.isDouble = true; + } else if (Boolean.TRUE.equals(property.isFloat)) { + parameter.isFloat = true; + } else if (Boolean.TRUE.equals(property.isByteArray)) { + parameter.isByteArray = true; + } else if (Boolean.TRUE.equals(property.isBinary)) { + parameter.isByteArray = true; + } else if (Boolean.TRUE.equals(property.isDate)) { + parameter.isDate = true; + } else if (Boolean.TRUE.equals(property.isDateTime)) { + parameter.isDateTime = true; + } else { + LOGGER.debug("Property type is not primitive: " + property.datatype); + } + } } diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JavascriptClientCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JavascriptClientCodegen.java index 0b56ffbbe81..11f04346381 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JavascriptClientCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JavascriptClientCodegen.java @@ -385,6 +385,9 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo /** * Normalize type by wrapping primitive types with single quotes. + * + * @param type Primitive type + * @return Normalized type */ public String normalizeType(String type) { return type.replaceAll("\\b(Boolean|Integer|Number|String|Date)\\b", "'$1'"); diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/PythonClientCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/PythonClientCodegen.java index dd99a7035fb..40d8bca49dc 100755 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/PythonClientCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/PythonClientCodegen.java @@ -293,6 +293,9 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig * * (PEP 0008) Python packages should also have short, all-lowercase names, * although the use of underscores is discouraged. + * + * @param packageName Package name + * @return Python package name that conforms to PEP 0008 */ @SuppressWarnings("static-method") public String generatePackageName(String packageName) { diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/RubyClientCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/RubyClientCodegen.java index a557872c805..da8221b676c 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/RubyClientCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/RubyClientCodegen.java @@ -211,6 +211,9 @@ public class RubyClientCodegen extends DefaultCodegen implements CodegenConfig { /** * Generate Ruby module name from the gem name, e.g. use "SwaggerClient" for "swagger_client". + * + * @param gemName Ruby gem name + * @return Ruby module naame */ @SuppressWarnings("static-method") public String generateModuleName(String gemName) { @@ -219,6 +222,9 @@ public class RubyClientCodegen extends DefaultCodegen implements CodegenConfig { /** * Generate Ruby gem name from the module name, e.g. use "swagger_client" for "SwaggerClient". + * + * @param moduleName Ruby module naame + * @return Ruby gem name */ @SuppressWarnings("static-method") public String generateGemName(String moduleName) {