Skip to content
GitLab
    • Explore Projects Groups Snippets
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Merge requests
  • !497

[cpp-pistache] Various fixes for Pistache

  • Review changes

  • Download
  • Email patches
  • Plain diff
Merged Administrator requested to merge github/fork/etherealjoy/cpp-pistache-fix-nocompilation into master 7 years ago
  • Overview 0
  • Commits 4
  • Pipelines 0
  • Changes 29

Created by: etherealjoy

PR checklist

  • Read the contribution guidelines.
  • Ran the shell script under ./bin/ to update Petstore sample so that CIs can verify the change. (For instance, only need to run ./bin/{LANG}-petstore.sh and ./bin/security/{LANG}-petstore.sh if updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} client's mustache templates). Windows batch files can be found in .\bin\windows\.
  • Filed the PR against the correct branch: master, 3.1.x, 4.0.x. Default: master.
  • Copied the technical committee to review the pull request if your PR is targeting a particular programming language.

Description of the PR

  • Add Map support
  • Add Array support
  • Add ByteArray support
  • Fixed function signatures

Fixes #482 (closed) Fixes #446 (closed) Fixes #414 (closed) Fixes #407 (closed) Fixes #258 (closed)

@stkrwork @MartinDelille @ravinikam

Compare
  • master (base)

and
  • latest version
    4098c7ae
    4 commits, 2 years ago

29 files
+ 284
- 68

    Preferences

    File browser
    Compare changes
modules/openapi-g‎enerator/src/main‎
java/org/openapitoo‎ls/codegen/languages‎
CppPistacheSer‎verCodegen.java‎ +12 -0
CppRestSdkClie‎ntCodegen.java‎ +1 -0
reso‎urces‎
cpp-pista‎che-server‎
api-sourc‎e.mustache‎ +4 -4
cmake.m‎ustache‎ +1 -1
model-sour‎ce.mustache‎ +7 -7
modelbase-he‎ader.mustache‎ +98 -1
modelbase-so‎urce.mustache‎ +1 -1
cpp-rest-‎sdk-client‎
model-sour‎ce.mustache‎ +23 -17
samples/server/pet‎store/cpp-pistache‎
a‎pi‎
PetAp‎i.cpp‎ +6 -0
PetA‎pi.h‎ +2 -2
StoreA‎pi.cpp‎ +3 -0
Store‎Api.h‎ +1 -1
UserA‎pi.cpp‎ +10 -4
User‎Api.h‎ +2 -2
im‎pl‎
PetApiI‎mpl.cpp‎ +2 -2
PetApi‎Impl.h‎ +2 -2
StoreApi‎Impl.cpp‎ +1 -1
StoreAp‎iImpl.h‎ +1 -1
UserApi‎Impl.cpp‎ +2 -2
UserAp‎iImpl.h‎ +2 -2
mo‎del‎
ApiResp‎onse.cpp‎ +0 -2
Catego‎ry.cpp‎ +0 -1
ModelB‎ase.cpp‎ +1 -1
Model‎Base.h‎ +98 -1
Orde‎r.cpp‎ +0 -1
Pet‎.cpp‎ +3 -4
Tag‎.cpp‎ +0 -1
User‎.cpp‎ +0 -6
CMakeLi‎sts.txt‎ +1 -1
modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppPistacheServerCodegen.java
+ 12
- 0
  • View file @ 4098c7ae

  • Edit in single-file editor

  • Open in Web IDE


@@ -102,6 +102,7 @@ public class CppPistacheServerCodegen extends AbstractCppCodegen {
typeMapping.put("binary", "std::string");
typeMapping.put("number", "double");
typeMapping.put("UUID", "std::string");
typeMapping.put("ByteArray", "std::string");
super.importMapping = new HashMap<String, String>();
importMapping.put("std::vector", "#include <vector>");
@@ -292,6 +293,9 @@ public class CppPistacheServerCodegen extends AbstractCppCodegen {
Schema inner = (Schema) p.getAdditionalProperties();
return getSchemaType(p) + "<std::string, " + getTypeDeclaration(inner) + ">";
}
else if (ModelUtils.isByteArraySchema(p)) {
return "std::string";
}
if (ModelUtils.isStringSchema(p)
|| ModelUtils.isDateSchema(p)
|| ModelUtils.isDateTimeSchema(p) || ModelUtils.isFileSchema(p)
@@ -320,6 +324,9 @@ public class CppPistacheServerCodegen extends AbstractCppCodegen {
return "0L";
}
return "0";
}
else if (ModelUtils.isByteArraySchema(p)) {
return "";
} else if (ModelUtils.isMapSchema(p)) {
String inner = getSchemaType((Schema) p.getAdditionalProperties());
return "std::map<std::string, " + inner + ">()";
@@ -403,4 +410,9 @@ public class CppPistacheServerCodegen extends AbstractCppCodegen {
public String escapeUnsafeCharacters(String input) {
return input.replace("*/", "*_/").replace("/*", "/_*");
}
@Override
public String getTypeDeclaration(String str) {
return toModelName(str);
}
}
modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppRestSdkClientCodegen.java
+ 1
- 0
  • View file @ 4098c7ae

  • Edit in single-file editor

  • Open in Web IDE


@@ -153,6 +153,7 @@ public class CppRestSdkClientCodegen extends AbstractCppCodegen {
typeMapping.put("binary", "std::string");
typeMapping.put("number", "double");
typeMapping.put("UUID", "utility::string_t");
typeMapping.put("ByteArray", "utility::string_t");
super.importMapping = new HashMap<String, String>();
importMapping.put("std::vector", "#include <vector>");
modules/openapi-generator/src/main/resources/cpp-pistache-server/api-source.mustache
+ 4
- 4
  • View file @ 4098c7ae

  • Edit in single-file editor

  • Open in Web IDE


@@ -52,8 +52,8 @@ void {{classname}}::{{operationIdSnakeCase}}_handler(const Pistache::Rest::Reque
{{/hasPathParams}}{{#hasBodyParam}}
// Getting the body param
{{#bodyParam}}
{{^isPrimitiveType}}
{{baseType}} {{paramName}};{{/isPrimitiveType}}
{{^isPrimitiveType}}{{^isContainer}}
{{baseType}} {{paramName}};{{/isContainer}}{{#isListContainer}}std::vector<{{items.baseType}}> {{paramName}};{{/isListContainer}}{{#isMapContainer}}std::map<std::string, {{items.baseType}}> {{paramName}};{{/isMapContainer}}{{/isPrimitiveType}}
{{#isPrimitiveType}}
{{dataType}} {{paramName}};
{{/isPrimitiveType}}
@@ -74,9 +74,9 @@ void {{classname}}::{{operationIdSnakeCase}}_handler(const Pistache::Rest::Reque
{{#hasBodyParam}}
{{#bodyParam}}
nlohmann::json request_body = nlohmann::json::parse(request.body());
{{^isPrimitiveType}}
{{^isPrimitiveType}}{{^isContainer}}
{{paramName}}.fromJson(request_body);
{{/isPrimitiveType}}
{{/isContainer}}{{/isPrimitiveType}}{{#isContainer}} {{paramName}} = {{#isListContainer}} ModelArrayHelper{{/isListContainer}}{{#isMapContainer}} ModelMapHelper{{/isMapContainer}}::fromJson<{{items.baseType}}>(request_body);{{/isContainer}}
{{#isPrimitiveType}}
// The conversion is done automatically by the json library
{{paramName}} = request_body;
modules/openapi-generator/src/main/resources/cpp-pistache-server/cmake.mustache
+ 1
- 1
  • View file @ 4098c7ae

  • Edit in single-file editor

  • Open in Web IDE


@@ -2,7 +2,7 @@ cmake_minimum_required (VERSION 3.2)
project(server)
set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} -std=c++11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -pg -g3" )
link_directories(/usr/local/lib/)
modules/openapi-generator/src/main/resources/cpp-pistache-server/model-source.mustache
+ 7
- 7
  • View file @ 4098c7ae

  • Edit in single-file editor

  • Open in Web IDE


@@ -79,11 +79,11 @@ void {{classname}}::fromJson(nlohmann::json& val)
{{/items.isDateTime}}{{^items.isDateTime}}
if(item.is_null())
{
m_{{name}}.push_back( {{{items.datatype}}}(nullptr) );
m_{{name}}.push_back( {{{items.datatype}}}() );
}
else
{
{{{items.datatype}}} newItem({{{items.defaultValue}}});
{{{items.datatype}}} newItem;
newItem.fromJson(item);
m_{{name}}.push_back( newItem );
}
@@ -95,15 +95,15 @@ void {{classname}}::fromJson(nlohmann::json& val)
}
{{/isListContainer}}{{^isListContainer}}{{^isPrimitiveType}}{{^required}}if(val.find("{{baseName}}") != val.end())
{
{{#isString}}{{setter}}(val.at("{{baseName}}"));
{{/isString}}{{^isString}}{{#isDateTime}}{{setter}}(val.at("{{baseName}}"));
{{/isDateTime}}{{^isDateTime}}if(!val["{{baseName}}"].is_null())
{{#isString}}{{setter}}(val.at("{{baseName}}"));{{/isString}}{{#isByteArray}}{{setter}}(val.at("{{baseName}}"));
{{/isByteArray}}{{^isString}}{{#isDateTime}}{{setter}}(val.at("{{baseName}}"));
{{/isDateTime}}{{^isDateTime}}{{^isByteArray}}if(!val["{{baseName}}"].is_null())
{
{{{dataType}}} newItem({{{defaultValue}}});
{{{dataType}}} newItem;
newItem.fromJson(val["{{baseName}}"]);
{{setter}}( newItem );
}
{{/isDateTime}}{{/isString}}
{{/isByteArray}}{{/isDateTime}}{{/isString}}
}
{{/required}}{{#required}}{{#isString}}{{setter}}(val.at("{{baseName}}"));
{{/isString}}{{^isString}}{{#isDateTime}}{{setter}}(val.at("{{baseName}}"));
0 Assignees
None
Assign to
0 Reviewers
None
Request review from
Labels
2
Enhancement: Feature Feature: Documentation
2
Enhancement: Feature Feature: Documentation
    Assign labels
  • Manage project labels

Milestone
5.0.0
5.0.0 (expired)
None
Time tracking
No estimate or time spent
Lock merge request
Unlocked
0
0 participants
Reference: OpenAPITools/openapi-generator!8127
Source branch: github/fork/etherealjoy/cpp-pistache-fix-nocompilation

Menu

Explore Projects Groups Snippets