Merge remote-tracking branch 'origin/master' into 2.3.0

This commit is contained in:
wing328
2016-10-05 16:07:18 +08:00
31 changed files with 378 additions and 62 deletions

View File

@@ -100,6 +100,7 @@ public class DefaultCodegen {
protected List<CliOption> cliOptions = new ArrayList<CliOption>();
protected boolean skipOverwrite;
protected boolean supportsInheritance;
protected boolean supportsMixins;
protected Map<String, String> supportedLibraries = new LinkedHashMap<String, String>();
protected String library;
protected Boolean sortParamsByRequiredFlag = true;
@@ -1235,7 +1236,7 @@ public class DefaultCodegen {
List<String> required = new ArrayList<String>();
Map<String, Property> allProperties;
List<String> allRequired;
if (supportsInheritance) {
if (supportsInheritance || supportsMixins) {
allProperties = new LinkedHashMap<String, Property>();
allRequired = new ArrayList<String>();
m.allVars = new ArrayList<CodegenProperty>();
@@ -1256,17 +1257,20 @@ public class DefaultCodegen {
interfaceModel = allDefinitions.get(_interface.getSimpleRef());
}
// set first interface with discriminator found as parent
if (parent == null && interfaceModel instanceof ModelImpl && ((ModelImpl) interfaceModel).getDiscriminator() != null) {
if (parent == null
&& ((interfaceModel instanceof ModelImpl && ((ModelImpl) interfaceModel).getDiscriminator() != null)
|| (interfaceModel instanceof ComposedModel && isDiscriminatorInInterfaceTree((ComposedModel) interfaceModel, allDefinitions)))) {
parent = _interface;
} else {
final String interfaceRef = toModelName(_interface.getSimpleRef());
m.interfaces.add(interfaceRef);
addImport(m, interfaceRef);
if (allDefinitions != null) {
if (!supportsMixins) {
addProperties(properties, required, interfaceModel, allDefinitions);
}
if (supportsInheritance) {
addProperties(allProperties, allRequired, interfaceModel, allDefinitions);
} else {
addProperties(properties, required, interfaceModel, allDefinitions);
}
}
}
@@ -1325,6 +1329,30 @@ public class DefaultCodegen {
return m;
}
/**
* Recursively look for a discriminator in the interface tree
*/
private boolean isDiscriminatorInInterfaceTree(ComposedModel model, Map<String, Model> allDefinitions) {
if (model == null || allDefinitions == null)
return false;
Model child = ((ComposedModel) model).getChild();
if (child instanceof ModelImpl && ((ModelImpl) child).getDiscriminator() != null) {
return true;
}
for (RefModel _interface : model.getInterfaces()) {
Model interfaceModel = allDefinitions.get(_interface.getSimpleRef());
if (interfaceModel instanceof ModelImpl && ((ModelImpl) interfaceModel).getDiscriminator() != null) {
return true;
}
if (interfaceModel instanceof ComposedModel) {
return isDiscriminatorInInterfaceTree((ComposedModel) interfaceModel, allDefinitions);
}
}
return false;
}
protected void addAdditionPropertiesToCodeGenModel(CodegenModel codegenModel, ModelImpl swaggerModel) {
MapProperty mapProperty = new MapProperty(swaggerModel.getAdditionalProperties());
addParentContainer(codegenModel, codegenModel.name, mapProperty);

View File

@@ -145,10 +145,6 @@ public class FlaskConnexionCodegen extends DefaultCodegen implements CodegenConf
}
if(!new java.io.File(controllerPackage + File.separator + defaultController + ".py").exists()) {
//supportingFiles.add(new SupportingFile("controller.mustache",
// controllerPackage,
// defaultController + ".py")
//);
supportingFiles.add(new SupportingFile("__init__.mustache",
controllerPackage,
"__init__.py")
@@ -269,7 +265,7 @@ public class FlaskConnexionCodegen extends DefaultCodegen implements CodegenConf
}
else {
// no tag found, use "default_controller" as the default
String tag = "default_controller";
String tag = "default";
operation.setTags(Arrays.asList(tag));
controllerName = tag + "_controller";
}

View File

@@ -234,6 +234,7 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
setUseInheritance(Boolean.parseBoolean((String)additionalProperties.get(USE_INHERITANCE)));
} else {
supportsInheritance = true;
supportsMixins = true;
}
if (additionalProperties.containsKey(EMIT_MODEL_METHODS)) {
setEmitModelMethods(Boolean.parseBoolean((String)additionalProperties.get(EMIT_MODEL_METHODS)));
@@ -397,6 +398,7 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
public void setUseInheritance(boolean useInheritance) {
this.supportsInheritance = useInheritance;
this.supportsMixins = useInheritance;
}
public void setEmitModelMethods(boolean emitModelMethods) {
@@ -900,7 +902,7 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
// NOTE: can't use 'mandatory' as it is built from ModelImpl.getRequired(), which sorts names
// alphabetically and in any case the document order of 'required' and 'properties' can differ.
List<CodegenProperty> required = new ArrayList<>();
List<CodegenProperty> allRequired = supportsInheritance ? new ArrayList<CodegenProperty>() : required;
List<CodegenProperty> allRequired = supportsInheritance || supportsMixins ? new ArrayList<CodegenProperty>() : required;
cm.vendorExtensions.put("x-required", required);
cm.vendorExtensions.put("x-all-required", allRequired);
@@ -914,7 +916,7 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
}
}
if (supportsInheritance) {
if (supportsInheritance || supportsMixins) {
for (CodegenProperty var : cm.allVars) {
if (Boolean.TRUE.equals(var.required)) {
allRequired.add(var);

View File

@@ -281,8 +281,8 @@ public class Rails5ServerCodegen extends DefaultCodegen implements CodegenConfig
// replace - with _ e.g. created-at => created_at
name = name.replaceAll("-", "_"); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
// e.g. PhoneNumberApi.rb => phone_number_api.rb
return underscore(name) + "_controllers";
// e.g. DefaultController => defaults_controller.rb
return underscore(name) + "s_controller";
}
@Override