forked from OpenAPITools/openapi-generator
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[C++][Pistache] Simplified model template (OpenAPITools#3417)
* [C++][Pistache] Simplified model template * [C++][Pistache] Fix for addExternalLibs option CMake would fail with addExternalLibs set to false since it'd try to add depenency to not-existing targets * [C++][Pistache] Update cpp-pistache-server-petstore.sh * [C++][Pistache] Update Petstore sample * [C++][Pistache] Update documentation
- Loading branch information
Showing
7 changed files
with
118 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
...les/openapi-generator/src/main/resources/cpp-pistache-server/model-struct-header.mustache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
{{>licenseInfo}} | ||
{{#models}}{{#model}}/* | ||
* {{classname}}.h | ||
* | ||
* {{description}} | ||
*/ | ||
|
||
#ifndef {{classname}}_H_ | ||
#define {{classname}}_H_ | ||
|
||
{{{defaultInclude}}} | ||
{{#imports}}{{{this}}} | ||
{{/imports}} | ||
#include <nlohmann/json.hpp> | ||
#include <pistache/optional.h> | ||
|
||
{{#modelNamespaceDeclarations}} | ||
namespace {{this}} { | ||
{{/modelNamespaceDeclarations}} | ||
|
||
struct {{classname}} | ||
{ | ||
{{#vars}} | ||
{{^required}}Pistache::Optional<{{/required}}{{{dataType}}}{{^required}}>{{/required}} {{baseName}}; | ||
{{/vars}} | ||
|
||
nlohmann::json to_json() const; | ||
static {{classname}} from_json(const nlohmann::json& j); | ||
}; | ||
|
||
void to_json(nlohmann::json& j, const {{classname}}& o); | ||
void from_json(const nlohmann::json& j, {{classname}}& o); | ||
|
||
{{#modelNamespaceDeclarations}} | ||
} // {{this}} | ||
{{/modelNamespaceDeclarations}} | ||
|
||
#endif /* {{classname}}_H_ */ | ||
{{/model}} | ||
{{/models}} |
49 changes: 49 additions & 0 deletions
49
...les/openapi-generator/src/main/resources/cpp-pistache-server/model-struct-source.mustache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
{{>licenseInfo}} | ||
{{#models}}{{#model}} | ||
|
||
#include "{{classname}}.h" | ||
|
||
{{#modelNamespaceDeclarations}} | ||
namespace {{this}} { | ||
{{/modelNamespaceDeclarations}} | ||
|
||
nlohmann::json {{classname}}::to_json() const | ||
{ | ||
nlohmann::json j; | ||
{{#modelNamespaceDeclarations}}::{{this}}{{/modelNamespaceDeclarations}}::to_json(j, *this); | ||
return j; | ||
} | ||
|
||
{{classname}} {{classname}}::from_json(const nlohmann::json& j) | ||
{ | ||
{{classname}} o{}; | ||
{{#modelNamespaceDeclarations}}::{{this}}{{/modelNamespaceDeclarations}}::from_json(j, o); | ||
return o; | ||
} | ||
|
||
void to_json(nlohmann::json& j, const {{classname}}& o) | ||
{ | ||
{{#vars}} | ||
{{^required}}if (!o.{{baseName}}.isEmpty()){{/required}} | ||
j["{{baseName}}"] = o.{{baseName}}{{^required}}.get(){{/required}}; | ||
{{/vars}} | ||
} | ||
|
||
void from_json(const nlohmann::json& j, {{classname}}& o) | ||
{ | ||
{{#vars}} | ||
{{#required}}j.at("{{baseName}}").get_to(o.{{baseName}});{{/required}} | ||
{{^required}}if (j.find("{{baseName}}") != j.end()) { | ||
{{{dataType}}} temporary_{{baseName}}; | ||
j.at("{{baseName}}").get_to(temporary_{{baseName}}); | ||
o.{{baseName}} = Pistache::Some(temporary_{{baseName}}); | ||
}{{/required}} | ||
{{/vars}} | ||
} | ||
|
||
{{#modelNamespaceDeclarations}} | ||
} // {{this}} | ||
{{/modelNamespaceDeclarations}} | ||
|
||
{{/model}} | ||
{{/models}} |
2 changes: 1 addition & 1 deletion
2
samples/server/petstore/cpp-pistache/.openapi-generator/VERSION
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
4.1.2-SNAPSHOT | ||
4.1.3-SNAPSHOT |