forked from loafle/openapi-generator-original
Merge remote-tracking branch 'origin/master' into 2.3.0
This commit is contained in:
@@ -25,6 +25,7 @@ public class CodegenModel {
|
||||
public String discriminator;
|
||||
public String defaultValue;
|
||||
public String arrayModelType;
|
||||
public boolean isAlias; // Is this effectively an alias of another simple type
|
||||
public List<CodegenProperty> vars = new ArrayList<CodegenProperty>();
|
||||
public List<CodegenProperty> requiredVars = new ArrayList<CodegenProperty>(); // a list of required properties
|
||||
public List<CodegenProperty> optionalVars = new ArrayList<CodegenProperty>(); // a list of optional properties
|
||||
|
||||
@@ -116,6 +116,8 @@ public class DefaultCodegen {
|
||||
// They are translated to words like "Dollar" and prefixed with '
|
||||
// Then translated back during JSON encoding and decoding
|
||||
protected Map<String, String> specialCharReplacements = new HashMap<String, String>();
|
||||
// When a model is an alias for a simple type
|
||||
protected Map<String, String> typeAliases = new HashMap<>();
|
||||
|
||||
protected String ignoreFilePathOverride;
|
||||
|
||||
@@ -1210,6 +1212,18 @@ public class DefaultCodegen {
|
||||
return swaggerType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine the type alias for the given type if it exists. This feature
|
||||
* is only used for Java, because the language does not have a aliasing
|
||||
* mechanism of its own.
|
||||
* @param name The type name.
|
||||
* @return The alias of the given type, if it exists. If there is no alias
|
||||
* for this type, then returns the input type name.
|
||||
*/
|
||||
public String getAlias(String name) {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Output the API (class) name (capitalized) ending with "Api"
|
||||
* Return DefaultApi if name is empty
|
||||
@@ -1374,6 +1388,10 @@ public class DefaultCodegen {
|
||||
ModelImpl impl = (ModelImpl) model;
|
||||
if (impl.getType() != null) {
|
||||
Property p = PropertyBuilder.build(impl.getType(), impl.getFormat(), null);
|
||||
if (!impl.getType().equals("object") && impl.getEnum() == null) {
|
||||
typeAliases.put(name, impl.getType());
|
||||
m.isAlias = true;
|
||||
}
|
||||
m.dataType = getSwaggerType(p);
|
||||
}
|
||||
if(impl.getEnum() != null && impl.getEnum().size() > 0) {
|
||||
@@ -2526,6 +2544,7 @@ public class DefaultCodegen {
|
||||
Model sub = bp.getSchema();
|
||||
if (sub instanceof RefModel) {
|
||||
String name = ((RefModel) sub).getSimpleRef();
|
||||
name = getAlias(name);
|
||||
if (typeMapping.containsKey(name)) {
|
||||
name = typeMapping.get(name);
|
||||
} else {
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.samskivert.mustache.Mustache;
|
||||
import com.samskivert.mustache.Template;
|
||||
import io.swagger.codegen.ignore.CodegenIgnoreProcessor;
|
||||
import io.swagger.codegen.utils.ImplementationVersion;
|
||||
import io.swagger.codegen.languages.AbstractJavaCodegen;
|
||||
import io.swagger.models.*;
|
||||
import io.swagger.models.auth.OAuth2Definition;
|
||||
import io.swagger.models.auth.SecuritySchemeDefinition;
|
||||
@@ -327,7 +328,17 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
|
||||
if(config.importMapping().containsKey(modelName)) {
|
||||
continue;
|
||||
}
|
||||
allModels.add(((List<Object>) models.get("models")).get(0));
|
||||
Map<String, Object> modelTemplate = (Map<String, Object>) ((List<Object>) models.get("models")).get(0);
|
||||
if (config instanceof AbstractJavaCodegen) {
|
||||
// Special handling of aliases only applies to Java
|
||||
if (modelTemplate != null && modelTemplate.containsKey("model")) {
|
||||
CodegenModel m = (CodegenModel) modelTemplate.get("model");
|
||||
if (m.isAlias) {
|
||||
continue; // Don't create user-defined classes for aliases
|
||||
}
|
||||
}
|
||||
}
|
||||
allModels.add(modelTemplate);
|
||||
for (String templateName : config.modelTemplateFiles().keySet()) {
|
||||
String suffix = config.modelTemplateFiles().get(templateName);
|
||||
String filename = config.modelFileFolder() + File.separator + config.toModelFilename(modelName) + suffix;
|
||||
|
||||
@@ -581,6 +581,14 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
||||
return super.getTypeDeclaration(p);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAlias(String name) {
|
||||
if (typeAliases.containsKey(name)) {
|
||||
return typeAliases.get(name);
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toDefaultValue(Property p) {
|
||||
if (p instanceof ArrayProperty) {
|
||||
@@ -730,6 +738,8 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
||||
public String getSwaggerType(Property p) {
|
||||
String swaggerType = super.getSwaggerType(p);
|
||||
|
||||
swaggerType = getAlias(swaggerType);
|
||||
|
||||
// don't apply renaming on types from the typeMapping
|
||||
if (typeMapping.containsKey(swaggerType)) {
|
||||
return typeMapping.get(swaggerType);
|
||||
|
||||
@@ -64,7 +64,7 @@ public class AndroidClientCodegen extends DefaultCodegen implements CodegenConfi
|
||||
"import", "public", "throws", "case", "enum", "instanceof", "return", "transient",
|
||||
"catch", "extends", "int", "short", "try", "char", "final", "interface", "static",
|
||||
"void", "class", "finally", "long", "strictfp", "volatile", "const", "float",
|
||||
"native", "super", "while")
|
||||
"native", "super", "while", "null")
|
||||
);
|
||||
|
||||
languageSpecificPrimitives = new HashSet<String>(
|
||||
|
||||
@@ -69,6 +69,17 @@ public class FlaskConnexionCodegen extends DefaultCodegen implements CodegenConf
|
||||
typeMapping.put("file", "file");
|
||||
typeMapping.put("UUID", "str");
|
||||
|
||||
// from https://docs.python.org/release/2.5.4/ref/keywords.html
|
||||
setReservedWordsLowerCase(
|
||||
Arrays.asList(
|
||||
// @property
|
||||
"property",
|
||||
// python reserved words
|
||||
"and", "del", "from", "not", "while", "as", "elif", "global", "or", "with",
|
||||
"assert", "else", "if", "pass", "yield", "break", "except", "import",
|
||||
"print", "class", "exec", "in", "raise", "continue", "finally", "is",
|
||||
"return", "def", "for", "lambda", "try", "self", "None"));
|
||||
|
||||
// set the output folder here
|
||||
outputFolder = "generated-code/connexion";
|
||||
|
||||
|
||||
@@ -56,7 +56,8 @@ public class GoClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
"case", "defer", "go", "map", "struct",
|
||||
"chan", "else", "goto", "package", "switch",
|
||||
"const", "fallthrough", "if", "range", "type",
|
||||
"continue", "for", "import", "return", "var", "error", "ApiResponse")
|
||||
"continue", "for", "import", "return", "var", "error", "ApiResponse",
|
||||
"nil")
|
||||
// Added "error" as it's used so frequently that it may as well be a keyword
|
||||
);
|
||||
|
||||
|
||||
@@ -78,7 +78,8 @@ public class GoServerCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
"case", "defer", "go", "map", "struct",
|
||||
"chan", "else", "goto", "package", "switch",
|
||||
"const", "fallthrough", "if", "range", "type",
|
||||
"continue", "for", "import", "return", "var", "error", "ApiResponse")
|
||||
"continue", "for", "import", "return", "var", "error", "ApiResponse",
|
||||
"nil")
|
||||
// Added "error" as it's used so frequently that it may as well be a keyword
|
||||
);
|
||||
|
||||
|
||||
@@ -101,7 +101,7 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
"and", "del", "from", "not", "while", "as", "elif", "global", "or", "with",
|
||||
"assert", "else", "if", "pass", "yield", "break", "except", "import",
|
||||
"print", "class", "exec", "in", "raise", "continue", "finally", "is",
|
||||
"return", "def", "for", "lambda", "try", "self"));
|
||||
"return", "def", "for", "lambda", "try", "self", "None"));
|
||||
|
||||
regexModifiers = new HashMap<Character, String>();
|
||||
regexModifiers.put('i', "IGNORECASE");
|
||||
|
||||
Reference in New Issue
Block a user