Skip to content

[C++][Restbed] Fix default value for Restbed #1186

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Oct 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,19 @@
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 org.slf4j.LoggerFactory;

import io.swagger.v3.oas.models.media.*;

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";

Expand Down Expand Up @@ -287,25 +291,63 @@ public String getTypeDeclaration(Schema p) {
@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 + ">()";
Expand All @@ -319,6 +361,7 @@ public String toDefaultValue(Schema p) {
} else if (!StringUtils.isEmpty(p.get$ref())) {
return "new " + toModelName(ModelUtils.getSimpleRef(p.get$ref())) + "()";
}

return "nullptr";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ void {{classname}}{{vendorExtensions.x-codegen-resourceName}}Resource::{{httpMet
// Getting the path params
{{#pathParams}}
{{#isPrimitiveType}}
const {{{dataType}}} {{{paramName}}} = request->get_path_parameter("{{paramName}}", {{#isString}}""{{/isString}}{{#isInteger}}0{{/isInteger}}{{#isLong}}0L{{/isLong}}{{#isFloat}}0.0f{{/isFloat}}{{#isDouble}}0.0{{/isDouble}});
const {{{dataType}}} {{{paramName}}} = request->get_path_parameter("{{paramName}}", {{{defaultValue}}});
{{/isPrimitiveType}}
{{/pathParams}}
{{/hasPathParams}}
Expand All @@ -84,7 +84,7 @@ void {{classname}}{{vendorExtensions.x-codegen-resourceName}}Resource::{{httpMet
// Getting the query params
{{#queryParams}}
{{#isPrimitiveType}}
const {{{dataType}}} {{{paramName}}} = request->get_query_parameter("{{paramName}}", {{#isString}}""{{/isString}}{{#isInteger}}0{{/isInteger}}{{#isLong}}0L{{/isLong}}{{#isFloat}}0.0f{{/isFloat}}{{#isDouble}}0.0{{/isDouble}});
const {{{dataType}}} {{{paramName}}} = request->get_query_parameter("{{paramName}}", {{{defaultValue}}});
{{/isPrimitiveType}}
{{/queryParams}}
{{/hasQueryParams}}
Expand All @@ -93,7 +93,7 @@ void {{classname}}{{vendorExtensions.x-codegen-resourceName}}Resource::{{httpMet
// Getting the headers
{{#headerParams}}
{{#isPrimitiveType}}
const {{{dataType}}} {{{paramName}}} = request->get_header("{{paramName}}", {{#isString}}""{{/isString}}{{#isInteger}}0{{/isInteger}}{{#isLong}}0L{{/isLong}}{{#isFloat}}0.0f{{/isFloat}}{{#isDouble}}0.0{{/isDouble}});
const {{{dataType}}} {{{paramName}}} = request->get_header("{{paramName}}", {{{defaultValue}}});
{{/isPrimitiveType}}
{{/headerParams}}
{{/hasHeaderParams}}
Expand Down Expand Up @@ -140,7 +140,7 @@ void {{classname}}{{vendorExtensions.x-codegen-resourceName}}Resource::{{httpMet
// Getting the path params
{{#pathParams}}
{{#isPrimitiveType}}
const {{dataType}} {{paramName}} = request->get_path_parameter("{{paramName}}", {{#isString}}""{{/isString}}{{#isInteger}}0{{/isInteger}}{{#isLong}}0L{{/isLong}}{{#isFloat}}0.0f{{/isFloat}}{{#isDouble}}0.0{{/isDouble}});
const {{{dataType}}} {{{paramName}}} = request->get_path_parameter("{{paramName}}", {{{defaultValue}}});
{{/isPrimitiveType}}
{{/pathParams}}
{{/hasPathParams}}
Expand All @@ -149,16 +149,16 @@ void {{classname}}{{vendorExtensions.x-codegen-resourceName}}Resource::{{httpMet
// Getting the query params
{{#queryParams}}
{{#isPrimitiveType}}
const {{dataType}} {{paramName}} = request->get_query_parameter("{{paramName}}", {{#isString}}""{{/isString}}{{#isInteger}}0{{/isInteger}}{{#isLong}}0L{{/isLong}}{{#isFloat}}0.0f{{/isFloat}}{{#isDouble}}0.0{{/isDouble}});
const {{{dataType}}} {{{paramName}}} = request->get_query_parameter("{{paramName}}", {{{defaultValue}}});
{{/isPrimitiveType}}
{{/queryParams}}
{{/hasQueryParams}}

{{#hasHeaderParams}}
// Getting the headers
{{#headerParams}}
{{#isPrimitiveType}}
const {{dataType}} {{paramName}} = request->get_header("{{paramName}}", {{#isString}}""{{/isString}}{{#isInteger}}0{{/isInteger}}{{#isLong}}0L{{/isLong}}{{#isFloat}}0.0f{{/isFloat}}{{#isDouble}}0.0{{/isDouble}});
const {{{dataType}}} {{{paramName}}} = request->get_header("{{paramName}}", {{{defaultValue}}});
{{/isPrimitiveType}}
{{/headerParams}}
{{/hasHeaderParams}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.3.0-SNAPSHOT
3.3.1-SNAPSHOT
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-restsdk/ApiClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.3.0-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 3.3.1-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-restsdk/ApiClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.3.0-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 3.3.1-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-restsdk/ApiConfiguration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.3.0-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 3.3.1-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-restsdk/ApiConfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.3.0-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 3.3.1-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-restsdk/ApiException.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.3.0-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 3.3.1-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-restsdk/ApiException.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.3.0-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 3.3.1-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-restsdk/HttpContent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.3.0-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 3.3.1-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-restsdk/HttpContent.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.3.0-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 3.3.1-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-restsdk/IHttpBody.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.3.0-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 3.3.1-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-restsdk/JsonBody.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.3.0-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 3.3.1-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-restsdk/JsonBody.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.3.0-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 3.3.1-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-restsdk/ModelBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.3.0-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 3.3.1-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-restsdk/ModelBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.3.0-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 3.3.1-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-restsdk/MultipartFormData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.3.0-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 3.3.1-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-restsdk/MultipartFormData.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.3.0-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 3.3.1-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-restsdk/Object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.3.0-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 3.3.1-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-restsdk/Object.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.3.0-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 3.3.1-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-restsdk/api/PetApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.3.0-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 3.3.1-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
Expand Down
4 changes: 2 additions & 2 deletions samples/client/petstore/cpp-restsdk/api/PetApi.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.3.0-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 3.3.1-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
Expand Down Expand Up @@ -62,7 +62,7 @@ class PetApi
///
/// </remarks>
/// <param name="petId">Pet id to delete</param>
/// <param name="apiKey"> (optional)</param>
/// <param name="apiKey"> (optional, default to utility::conversions::to_string_t(&quot;&quot;))</param>
pplx::task<void> deletePet(
int64_t petId,
boost::optional<utility::string_t> apiKey
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-restsdk/api/StoreApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.3.0-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 3.3.1-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-restsdk/api/StoreApi.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.3.0-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 3.3.1-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-restsdk/api/UserApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.3.0-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 3.3.1-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-restsdk/api/UserApi.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.3.0-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 3.3.1-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-restsdk/model/ApiResponse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.3.0-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 3.3.1-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-restsdk/model/ApiResponse.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.3.0-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 3.3.1-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
Expand Down
Loading