forked from loafle/openapi-generator-original
Merge branch 'empty_classes' of https://github.com/bbdouglas/swagger-codegen into bbdouglas-empty_classes
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) {
|
||||
@@ -2527,6 +2545,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;
|
||||
|
||||
@@ -574,6 +574,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) {
|
||||
@@ -723,6 +731,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);
|
||||
|
||||
Reference in New Issue
Block a user