mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2026-03-18 18:29:25 +00:00
[C++][Restbed] Fix default values for Restbed Server generator (#761)
* Start working on fixing default value in Restbed Server Api Template * fix default value in DefaultCodegen
This commit is contained in:
@@ -2742,9 +2742,8 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
}
|
||||
|
||||
// set default value
|
||||
if (parameterSchema.getDefault() != null) {
|
||||
codegenParameter.defaultValue = toDefaultValue(parameterSchema);
|
||||
}
|
||||
codegenParameter.defaultValue = toDefaultValue(parameterSchema);
|
||||
|
||||
// TDOO revise collectionFormat
|
||||
String collectionFormat = null;
|
||||
if (ModelUtils.isArraySchema(parameterSchema)) { // for array parameter
|
||||
|
||||
@@ -25,15 +25,19 @@ import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.openapitools.codegen.*;
|
||||
import org.openapitools.codegen.utils.ModelUtils;
|
||||
|
||||
import io.swagger.v3.oas.models.media.*;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class CppRestbedServerCodegen extends AbstractCppCodegen {
|
||||
|
||||
private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(CppRestbedServerCodegen.class);
|
||||
|
||||
public static final String DECLSPEC = "declspec";
|
||||
public static final String DEFAULT_INCLUDE = "defaultInclude";
|
||||
|
||||
@@ -287,25 +291,63 @@ public class CppRestbedServerCodegen extends AbstractCppCodegen {
|
||||
@Override
|
||||
public String toDefaultValue(Schema p) {
|
||||
if (ModelUtils.isStringSchema(p)) {
|
||||
return "\"\"";
|
||||
if (p.getDefault() != null) {
|
||||
return "\"" + p.getDefault().toString() + "\"";
|
||||
} else {
|
||||
return "\"\"";
|
||||
}
|
||||
} else if (ModelUtils.isBooleanSchema(p)) {
|
||||
return "false";
|
||||
if (p.getDefault() != null) {
|
||||
return p.getDefault().toString();
|
||||
} else {
|
||||
return "false";
|
||||
}
|
||||
} else if (ModelUtils.isDateSchema(p)) {
|
||||
return "\"\"";
|
||||
if (p.getDefault() != null) {
|
||||
return "\"" + p.getDefault().toString() + "\"";
|
||||
} else {
|
||||
return "\"\"";
|
||||
}
|
||||
} else if (ModelUtils.isDateTimeSchema(p)) {
|
||||
return "\"\"";
|
||||
if (p.getDefault() != null) {
|
||||
return "\"" + p.getDefault().toString() + "\"";
|
||||
} else {
|
||||
return "\"\"";
|
||||
}
|
||||
} else if (ModelUtils.isNumberSchema(p)) {
|
||||
if (ModelUtils.isFloatSchema(p)) {
|
||||
return "0.0f";
|
||||
if (ModelUtils.isFloatSchema(p)) { // float
|
||||
if (p.getDefault() != null) {
|
||||
return p.getDefault().toString() + "f";
|
||||
} else {
|
||||
return "0.0f";
|
||||
}
|
||||
} else { // double
|
||||
if (p.getDefault() != null) {
|
||||
return p.getDefault().toString();
|
||||
} else {
|
||||
return "0.0";
|
||||
}
|
||||
}
|
||||
return "0.0";
|
||||
} else if (ModelUtils.isIntegerSchema(p)) {
|
||||
if (ModelUtils.isLongSchema(p)) {
|
||||
return "0L";
|
||||
if (ModelUtils.isLongSchema(p)) { // long
|
||||
if (p.getDefault() != null) {
|
||||
return p.getDefault().toString() + "L";
|
||||
} else {
|
||||
return "0L";
|
||||
}
|
||||
} else { // integer
|
||||
if (p.getDefault() != null) {
|
||||
return p.getDefault().toString();
|
||||
} else {
|
||||
return "0";
|
||||
}
|
||||
}
|
||||
return "0";
|
||||
} else if (ModelUtils.isByteArraySchema(p)) {
|
||||
return "\"\"";
|
||||
if (p.getDefault() != null) {
|
||||
return "\"" + p.getDefault().toString() + "\"";
|
||||
} else {
|
||||
return "\"\"";
|
||||
}
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
String inner = getSchemaType(ModelUtils.getAdditionalProperties(p));
|
||||
return "std::map<std::string, " + inner + ">()";
|
||||
@@ -319,6 +361,7 @@ public class CppRestbedServerCodegen extends AbstractCppCodegen {
|
||||
} else if (!StringUtils.isEmpty(p.get$ref())) {
|
||||
return "new " + toModelName(ModelUtils.getSimpleRef(p.get$ref())) + "()";
|
||||
}
|
||||
|
||||
return "nullptr";
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user