[cpp-pistache-server] Fix missing semicolon in template and missing code to set default values of model schema (#10136)

* BUG FIX: A missing semicolon in cpp-pistache-server generated code.

* BUG FIX: Provide default values of schema in cpp-pistache-server generated code.

* BUG FIX: Provide default values of schema in cpp-pistache-server generated code.
This commit is contained in:
shayan-eftekhari 2021-08-14 18:32:14 +02:00 committed by GitHub
parent 55ff5a0807
commit 8569ff8203
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 61 additions and 24 deletions

View File

@ -381,42 +381,79 @@ public class CppPistacheServerCodegen extends AbstractCppCodegen {
@Override
public String toDefaultValue(Schema p) {
if (ModelUtils.isBooleanSchema(p)) {
if (ModelUtils.isStringSchema(p)) {
if (p.getDefault() != null) {
return "\"" + p.getDefault().toString() + "\"";
} else {
return "\"\"";
}
} else if (ModelUtils.isBooleanSchema(p)) {
if (p.getDefault() != null) {
return p.getDefault().toString();
} else {
return "false";
}
} else if (ModelUtils.isDateSchema(p)) {
if (p.getDefault() != null) {
return "\"" + p.getDefault().toString() + "\"";
} else {
return "\"\"";
}
} else if (ModelUtils.isDateTimeSchema(p)) {
if (p.getDefault() != null) {
return "\"" + p.getDefault().toString() + "\"";
} else {
return "\"\"";
}
} else if (ModelUtils.isNumberSchema(p)) {
if (ModelUtils.isFloatSchema(p)) {
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";
}
}
} else if (ModelUtils.isIntegerSchema(p)) {
if (ModelUtils.isLongSchema(p)) {
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";
}
}
} else if (ModelUtils.isByteArraySchema(p)) {
if (p.getDefault() != null) {
return "\"" + p.getDefault().toString() + "\"";
} else {
return "\"\"";
}
} else if (ModelUtils.isMapSchema(p)) {
String inner = getSchemaType(getAdditionalProperties(p));
return "std::map<std::string, " + inner + ">()";
} else if (ModelUtils.isArraySchema(p)) {
ArraySchema ap = (ArraySchema) p;
String inner = getSchemaType(ap.getItems());
return "std::vector<" + inner + ">()";
} else if (!StringUtils.isEmpty(p.get$ref())) { // model
return toModelName(ModelUtils.getSimpleRef(p.get$ref())) + "()";
} else if (ModelUtils.isStringSchema(p)) {
if (p.getDefault() == null) {
return "\"\"";
} else {
return "\"" + p.getDefault().toString() + "\"";
if (!languageSpecificPrimitives.contains(inner)) {
inner = "std::shared_ptr<" + inner + ">";
}
return "std::vector<" + inner + ">()";
} else if (!StringUtils.isEmpty(p.get$ref())) {
return "std::make_shared<" + toModelName(ModelUtils.getSimpleRef(p.get$ref())) + ">()";
}
return "";
return "nullptr";
}
/**

View File

@ -42,7 +42,7 @@ std::pair<Pistache::Http::Code, std::string> {{classname}}::handleParsingExcepti
} catch ({{helpersNamespace}}::ValidationException &e) {
return std::make_pair(Pistache::Http::Code::Bad_Request, e.what());
} catch (std::exception &e) {
return std::make_pair(Pistache::Http::Code::Internal_Server_Error, e.what())
return std::make_pair(Pistache::Http::Code::Internal_Server_Error, e.what());
}
}

View File

@ -55,7 +55,7 @@ std::pair<Pistache::Http::Code, std::string> PetApi::handleParsingException(cons
} catch (org::openapitools::server::helpers::ValidationException &e) {
return std::make_pair(Pistache::Http::Code::Bad_Request, e.what());
} catch (std::exception &e) {
return std::make_pair(Pistache::Http::Code::Internal_Server_Error, e.what())
return std::make_pair(Pistache::Http::Code::Internal_Server_Error, e.what());
}
}

View File

@ -51,7 +51,7 @@ std::pair<Pistache::Http::Code, std::string> StoreApi::handleParsingException(co
} catch (org::openapitools::server::helpers::ValidationException &e) {
return std::make_pair(Pistache::Http::Code::Bad_Request, e.what());
} catch (std::exception &e) {
return std::make_pair(Pistache::Http::Code::Internal_Server_Error, e.what())
return std::make_pair(Pistache::Http::Code::Internal_Server_Error, e.what());
}
}

View File

@ -55,7 +55,7 @@ std::pair<Pistache::Http::Code, std::string> UserApi::handleParsingException(con
} catch (org::openapitools::server::helpers::ValidationException &e) {
return std::make_pair(Pistache::Http::Code::Bad_Request, e.what());
} catch (std::exception &e) {
return std::make_pair(Pistache::Http::Code::Internal_Server_Error, e.what())
return std::make_pair(Pistache::Http::Code::Internal_Server_Error, e.what());
}
}