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
  • !1230

[cpp-pistache] Allow all Apis under a single endpoint to be hosted in one server

  • Review changes

  • Download
  • Email patches
  • Plain diff
Merged Administrator requested to merge github/fork/etherealjoy/cpp-pistache-single-server into master 6 years ago
  • Overview 0
  • Commits 1
  • Pipelines 0
  • Changes 26

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.4.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

  • Allow all APIs in the same endpoint to be hosted in a single server
  • Add include of json.hpp when no models are imported
  • small changes to simplify CMakeLists.txt and to be able to exit the server with a Ctrl+C

@stkrwork @MartinDelille @ravinikam @fvarose Fixes #1168 (closed) Fixes #548 (closed)

Compare
  • master (base)

and
  • latest version
    5787af2e
    1 commit, 2 years ago

26 files
+ 245
- 334

    Preferences

    File browser
    Compare changes
modules/openapi-g‎enerator/src/main‎
java/org/openapitoo‎ls/codegen/languages‎
CppPistacheSer‎verCodegen.java‎ +3 -6
resources/cpp-‎pistache-server‎
README.‎mustache‎ +1 -1
api-heade‎r.mustache‎ +4 -9
api-impl-hea‎der.mustache‎ +1 -1
api-impl-sou‎rce.mustache‎ +2 -2
api-sourc‎e.mustache‎ +6 -19
cmake.m‎ustache‎ +10 -41
main-api-ser‎ver.mustache‎ +60 -7
samples/server/pet‎store/cpp-pistache‎
a‎pi‎
PetAp‎i.cpp‎ +14 -27
PetA‎pi.h‎ +4 -9
StoreA‎pi.cpp‎ +10 -23
Store‎Api.h‎ +3 -8
UserA‎pi.cpp‎ +14 -27
User‎Api.h‎ +3 -8
im‎pl‎
PetApiI‎mpl.cpp‎ +2 -2
PetApi‎Impl.h‎ +1 -1
StoreApi‎Impl.cpp‎ +2 -2
StoreAp‎iImpl.h‎ +1 -1
UserApi‎Impl.cpp‎ +2 -2
UserAp‎iImpl.h‎ +1 -1
CMakeLi‎sts.txt‎ +10 -49
PetApiMain‎Server.cpp‎ +0 -29
READ‎ME.md‎ +1 -1
StoreApiMai‎nServer.cpp‎ +0 -29
UserApiMai‎nServer.cpp‎ +0 -29
main-api-‎server.cpp‎ +90 -0
modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppPistacheServerCodegen.java
+ 3
- 6
  • View file @ 5787af2e

  • Edit in single-file editor

  • Open in Web IDE


@@ -82,8 +82,7 @@ public class CppPistacheServerCodegen extends AbstractCppCodegen {
apiTemplateFiles.put("api-header.mustache", ".h");
apiTemplateFiles.put("api-source.mustache", ".cpp");
apiTemplateFiles.put("api-impl-header.mustache", ".h");
apiTemplateFiles.put("api-impl-source.mustache", ".cpp");
apiTemplateFiles.put("main-api-server.mustache", ".cpp");
apiTemplateFiles.put("api-impl-source.mustache", ".cpp");
embeddedTemplateDir = templateDir = "cpp-pistache-server";
@@ -97,6 +96,7 @@ public class CppPistacheServerCodegen extends AbstractCppCodegen {
supportingFiles.add(new SupportingFile("modelbase-source.mustache", "model", modelNamePrefix + "ModelBase.cpp"));
supportingFiles.add(new SupportingFile("helpers-header.mustache", "model", modelNamePrefix + "Helpers.h"));
supportingFiles.add(new SupportingFile("helpers-source.mustache", "model", modelNamePrefix + "Helpers.cpp"));
supportingFiles.add(new SupportingFile("main-api-server.mustache", "", modelNamePrefix + "main-api-server.cpp"));
supportingFiles.add(new SupportingFile("cmake.mustache", "", "CMakeLists.txt"));
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
@@ -139,6 +139,7 @@ public class CppPistacheServerCodegen extends AbstractCppCodegen {
supportingFiles.add(new SupportingFile("modelbase-source.mustache", "model", modelNamePrefix + "ModelBase.cpp"));
supportingFiles.add(new SupportingFile("helpers-header.mustache", "model", modelNamePrefix + "Helpers.h"));
supportingFiles.add(new SupportingFile("helpers-source.mustache", "model", modelNamePrefix + "Helpers.cpp"));
supportingFiles.add(new SupportingFile("main-api-server.mustache", "", modelNamePrefix + "main-api-server.cpp"));
supportingFiles.add(new SupportingFile("cmake.mustache", "", "CMakeLists.txt"));
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
}
@@ -291,10 +292,6 @@ public class CppPistacheServerCodegen extends AbstractCppCodegen {
int ix = result.lastIndexOf(File.separatorChar);
result = result.substring(0, ix) + result.substring(ix, result.length() - 4) + "Impl.cpp";
result = result.replace(apiFileFolder(), implFileFolder());
} else if (templateName.endsWith("api-server.mustache")) {
int ix = result.lastIndexOf(File.separatorChar);
result = result.substring(0, ix) + result.substring(ix, result.length() - 4) + "MainServer.cpp";
result = result.replace(apiFileFolder(), outputFolder);
}
return result;
}
modules/openapi-generator/src/main/resources/cpp-pistache-server/README.mustache
+ 1
- 1
  • View file @ 5787af2e

  • Edit in single-file editor

  • Open in Web IDE


@@ -35,7 +35,7 @@ Once compiled run the server:
```bash
cd build
./server
./api-server
```
## Libraries required
modules/openapi-generator/src/main/resources/cpp-pistache-server/api-header.mustache
+ 4
- 9
  • View file @ 5787af2e

  • Edit in single-file editor

  • Open in Web IDE


@@ -9,12 +9,11 @@
#define {{classname}}_H_
{{{defaultInclude}}}
#include <pistache/endpoint.h>
#include <pistache/http.h>
#include <pistache/router.h>
#include <pistache/http_headers.h>
#include <pistache/optional.h>
{{^hasModelImport}}#include "json.hpp"{{/hasModelImport}}
{{#imports}}{{{import}}}
{{/imports}}
@@ -28,11 +27,9 @@ using namespace {{modelNamespace}};{{/hasModelImport}}
class {{declspec}} {{classname}} {
public:
{{classname}}(Pistache::Address addr);
{{classname}}(std::shared_ptr<Pistache::Rest::Router>);
virtual ~{{classname}}() {}
void init(size_t thr);
void start();
void shutdown();
void init();
const std::string base = "{{basePathWithoutHost}}";
@@ -44,9 +41,7 @@ private:
{{/operation}}
void {{classnameSnakeLowerCase}}_default_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response);
Pistache::Http::Endpoint httpEndpoint;
Pistache::Rest::Router router;
std::shared_ptr<Pistache::Rest::Router> router;
{{#operation}}
/// <summary>
modules/openapi-generator/src/main/resources/cpp-pistache-server/api-impl-header.mustache
+ 1
- 1
  • View file @ 5787af2e

  • Edit in single-file editor

  • Open in Web IDE


@@ -31,7 +31,7 @@ using namespace {{modelNamespace}};{{/hasModelImport}}
class {{classname}}Impl : public {{apiNamespace}}::{{classname}} {
public:
{{classname}}Impl(Pistache::Address addr);
{{classname}}Impl(std::shared_ptr<Pistache::Rest::Router>);
~{{classname}}Impl() {}
{{#operation}}
modules/openapi-generator/src/main/resources/cpp-pistache-server/api-impl-source.mustache
+ 2
- 2
  • View file @ 5787af2e

  • Edit in single-file editor

  • Open in Web IDE


@@ -10,8 +10,8 @@ namespace {{this}} {
{{#hasModelImport}}
using namespace {{modelNamespace}};{{/hasModelImport}}
{{classname}}Impl::{{classname}}Impl(Pistache::Address addr)
: {{classname}}(addr)
{{classname}}Impl::{{classname}}Impl(std::shared_ptr<Pistache::Rest::Router> rtr)
: {{classname}}(rtr)
{ }
{{#operation}}
0 Assignees
None
Assign to
0 Reviewers
None
Request review from
Labels
2
Enhancement: General Server: C++
2
Enhancement: General Server: C++
    Assign labels
  • Manage project labels

Milestone
3.3.2
3.3.2 (expired)
None
Time tracking
No estimate or time spent
Lock merge request
Unlocked
2
2 participants
Administrator
Martin Delille
Reference: OpenAPITools/openapi-generator!1230
Source branch: github/fork/etherealjoy/cpp-pistache-single-server

Menu

Explore Projects Groups Snippets