Add cpp-oatpp-server generator (alpha) (#21547)

* Oat++ Server Generator (C++)

* Fixed for support for newest OpenAPI version.

* ALPHA not STABLE.

* Fixed for support for newest OpenAPI version.

* Added github workflow & changed to OA3 Petstore.

* Good catch on adding the Workflow.

* Might help to update the samples.

* Set C++ Standard the CMake way.

* Would be easier if there was a .pc file.

* oatpp.lib.

* Add ws2.

* This probably doesn't work, need to take a time out.
This commit is contained in:
Kraust 2025-07-16 03:32:28 -04:00 committed by GitHub
parent 64ab13a790
commit 8862b960f8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
38 changed files with 2736 additions and 1 deletions

View File

@ -0,0 +1,30 @@
name: Samples cpp oat++ server
on:
push:
branches:
- "samples/server/petstore/cpp-oatpp/**"
pull_request:
paths:
- "samples/server/petstore/cpp-oatpp/**"
env:
GRADLE_VERSION: 6.9
jobs:
build:
name: Build cpp qt client
strategy:
matrix:
sample:
- samples/server/petstore/cpp-oatpp
os:
- ubuntu-latest
- macOS-latest
- windows-latest
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- name: Build
working-directory: ${{ matrix.sample }}
run: cmake -B build && cmake --build build --verbose

View File

@ -92,7 +92,7 @@ OpenAPI Generator allows generation of API client libraries (SDK generation), se
| | Languages/Frameworks |
| -------------------------------- |--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| **API clients** | **ActionScript**, **Ada**, **Apex**, **Bash**, **C**, **C#** (.net 2.0, 3.5 or later, .NET Standard 1.3 - 2.1, .NET Core 3.1, .NET 5.0. Libraries: RestSharp, GenericHost, HttpClient), **C++** (Arduino, cpp-restsdk, Qt5, Tizen, Unreal Engine 4), **Clojure**, **Crystal**, **Dart**, **Elixir**, **Elm**, **Eiffel**, **Erlang**, **Go**, **Groovy**, **Haskell** (http-client, Servant), **Java** (Apache HttpClient 4.x, Apache HttpClient 5.x, Jersey2.x, OkHttp, Retrofit1.x, Retrofit2.x, Feign, RestTemplate, RESTEasy, Vertx, Google API Client Library for Java, Rest-assured, Spring 5 Web Client, Spring 6 RestClient, MicroProfile Rest Client, Helidon), **Jetbrains HTTP Client**, **Julia**, **k6**, **Kotlin**, **Lua**, **N4JS**, **Nim**, **Node.js/JavaScript** (ES5, ES6, AngularJS with Google Closure Compiler annotations, Flow types, Apollo GraphQL DataStore), **Objective-C**, **OCaml**, **Perl**, **PHP**, **PowerShell**, **Python**, **R**, **Ruby**, **Rust** (hyper, reqwest, rust-server), **Scala** (akka, http4s, scalaz, sttp, swagger-async-httpclient, pekko), **Swift** (2.x, 3.x, 4.x, 5.x, 6.x), **Typescript** (AngularJS, Angular (9.x - 19.x), Aurelia, Axios, Fetch, Inversify, jQuery, Nestjs, Node, redux-query, Rxjs), **XoJo**, **Zapier** |
| **Server stubs** | **Ada**, **C#** (ASP.NET Core, Azure Functions), **C++** (Pistache, Restbed, Qt5 QHTTPEngine), **Erlang**, **F#** (Giraffe), **Go** (net/http, Gin, Echo), **Haskell** (Servant, Yesod), **Java** (MSF4J, Spring, Undertow, JAX-RS: CDI, CXF, Inflector, Jersey, RestEasy, Play Framework, [PKMST](https://github.com/ProKarma-Inc/pkmst-getting-started-examples), [Vert.x](https://vertx.io/), [Apache Camel](https://camel.apache.org/), [Helidon](https://helidon.io/)), **Julia**, **Kotlin** (Spring Boot, [Ktor](https://github.com/ktorio/ktor), [Vert.x](https://vertx.io/)), **PHP** ([Flight](https://docs.flightphp.com/), Laravel, Lumen, [Mezzio (fka Zend Expressive)](https://github.com/mezzio/mezzio), Slim, Silex, [Symfony](https://symfony.com/)), **Python** (FastAPI, Flask), **NodeJS**, **Ruby** (Sinatra, Rails5), **Rust** ([rust-server](https://openapi-generator.tech/docs/generators/rust-server/)), **Scala** (Akka, [Finch](https://github.com/finagle/finch), [Lagom](https://github.com/lagom/lagom), [Play](https://www.playframework.com/), [Cask](https://github.com/com-lihaoyi/cask), Scalatra) |
| **Server stubs** | **Ada**, **C#** (ASP.NET Core, Azure Functions), **C++** (Oat++, Pistache, Restbed, Qt5 QHTTPEngine), **Erlang**, **F#** (Giraffe), **Go** (net/http, Gin, Echo), **Haskell** (Servant, Yesod), **Java** (MSF4J, Spring, Undertow, JAX-RS: CDI, CXF, Inflector, Jersey, RestEasy, Play Framework, [PKMST](https://github.com/ProKarma-Inc/pkmst-getting-started-examples), [Vert.x](https://vertx.io/), [Apache Camel](https://camel.apache.org/), [Helidon](https://helidon.io/)), **Julia**, **Kotlin** (Spring Boot, [Ktor](https://github.com/ktorio/ktor), [Vert.x](https://vertx.io/)), **PHP** ([Flight](https://docs.flightphp.com/), Laravel, Lumen, [Mezzio (fka Zend Expressive)](https://github.com/mezzio/mezzio), Slim, Silex, [Symfony](https://symfony.com/)), **Python** (FastAPI, Flask), **NodeJS**, **Ruby** (Sinatra, Rails5), **Rust** ([rust-server](https://openapi-generator.tech/docs/generators/rust-server/)), **Scala** (Akka, [Finch](https://github.com/finagle/finch), [Lagom](https://github.com/lagom/lagom), [Play](https://www.playframework.com/), [Cask](https://github.com/com-lihaoyi/cask), Scalatra) |
| **API documentation generators** | **HTML**, **Confluence Wiki**, **Asciidoc**, **Markdown**, **PlantUML** |
| **Configuration files** | [**Apache2**](https://httpd.apache.org/) |
| **Others** | **GraphQL**, **JMeter**, **Ktorm**, **MySQL Schema**, **Postman Collection**, **Protocol Buffer**, **WSDL** |
@ -1128,6 +1128,7 @@ Here is a list of template creators:
* C# Azure functions: @Abrhm7786
* C# NancyFX: @mstefaniuk
* C++ (Qt5 QHttpEngine): @etherealjoy
* C++ Oat++: @Kraust
* C++ Pistache: @sebymiano
* C++ Restbed: @stkrwork
* Erlang Server: @galaxie @nelsonvides

View File

@ -0,0 +1,6 @@
generatorName: cpp-oatpp-server
outputDir: samples/server/petstore/cpp-oatpp
inputSpec: modules/openapi-generator/src/test/resources/3_0/petstore.yaml
templateDir: modules/openapi-generator/src/main/resources/cpp-oatpp-server
additionalProperties:
addExternalLibs: "true"

View File

@ -87,6 +87,7 @@ The following generators are available:
* [ada-server](generators/ada-server.md)
* [aspnet-fastendpoints](generators/aspnet-fastendpoints.md)
* [aspnetcore](generators/aspnetcore.md)
* [cpp-oatpp-server](generators/cpp-oatpp-server.md)
* [cpp-pistache-server](generators/cpp-pistache-server.md)
* [cpp-qt-qhttpengine-server](generators/cpp-qt-qhttpengine-server.md)
* [cpp-restbed-server](generators/cpp-restbed-server.md)

View File

@ -65,6 +65,7 @@ The following generators are available:
## SERVER generators
* [ada-server](ada-server.md)
* [aspnetcore](aspnetcore.md)
* [cpp-oatpp-server](cpp-oatpp-server.md)
* [cpp-pistache-server](cpp-pistache-server.md)
* [cpp-qt5-qhttpengine-server](cpp-qt5-qhttpengine-server.md)
* [cpp-restbed-server](cpp-restbed-server.md)

View File

@ -0,0 +1,262 @@
---
title: Documentation for the cpp-oatpp-server Generator
---
## METADATA
| Property | Value | Notes |
| -------- | ----- | ----- |
| generator name | cpp-oatpp-server | pass this to the generate command after -g |
| generator stability | STABLE | |
| generator type | SERVER | |
| generator language | C++ | |
| generator default templating engine | mustache | |
| helpTxt | Generates a C++ API server (based on Oat++) | |
## CONFIG OPTIONS
These options may be applied as additional-properties (cli) or configOptions (plugins). Refer to [configuration docs](https://openapi-generator.tech/docs/configuration) for more details.
| Option | Description | Values | Default |
| ------ | ----------- | ------ | ------- |
|addExternalLibs|Add the Possibility to fetch and compile external Libraries needed by this Framework.| |true|
|reservedWordPrefix|Prefix to prepend to reserved words in order to avoid conflicts| |r_|
|variableNameFirstCharacterUppercase|Make first character of variable name uppercase (eg. value -> Value)| |true|
## IMPORT MAPPING
| Type/Alias | Imports |
| ---------- | ------- |
## INSTANTIATION TYPES
| Type/Alias | Instantiated By |
| ---------- | --------------- |
## LANGUAGE PRIMITIVES
<ul class="column-ul">
<li>oatpp::Any</li>
<li>oatpp::Boolean</li>
<li>oatpp::Fields</li>
<li>oatpp::Float64</li>
<li>oatpp::Int32</li>
<li>oatpp::Int64</li>
<li>oatpp::Object</li>
<li>oatpp::String</li>
<li>oatpp::UnorderedSet</li>
<li>oatpp::Vector</li>
</ul>
## RESERVED WORDS
<ul class="column-ul">
<li>NULL</li>
<li>alignas</li>
<li>alignof</li>
<li>and</li>
<li>and_eq</li>
<li>asm</li>
<li>auto</li>
<li>bitand</li>
<li>bitor</li>
<li>bool</li>
<li>break</li>
<li>case</li>
<li>catch</li>
<li>char</li>
<li>char16_t</li>
<li>char32_t</li>
<li>class</li>
<li>compl</li>
<li>concept</li>
<li>const</li>
<li>const_cast</li>
<li>constexpr</li>
<li>continue</li>
<li>decltype</li>
<li>default</li>
<li>delete</li>
<li>do</li>
<li>double</li>
<li>dynamic_cast</li>
<li>else</li>
<li>enum</li>
<li>explicit</li>
<li>export</li>
<li>extern</li>
<li>false</li>
<li>float</li>
<li>for</li>
<li>friend</li>
<li>goto</li>
<li>if</li>
<li>inline</li>
<li>int</li>
<li>linux</li>
<li>long</li>
<li>mutable</li>
<li>namespace</li>
<li>new</li>
<li>noexcept</li>
<li>not</li>
<li>not_eq</li>
<li>nullptr</li>
<li>operator</li>
<li>or</li>
<li>or_eq</li>
<li>private</li>
<li>protected</li>
<li>public</li>
<li>register</li>
<li>reinterpret_cast</li>
<li>requires</li>
<li>return</li>
<li>short</li>
<li>signed</li>
<li>sizeof</li>
<li>static</li>
<li>static_assert</li>
<li>static_cast</li>
<li>struct</li>
<li>switch</li>
<li>template</li>
<li>this</li>
<li>thread_local</li>
<li>throw</li>
<li>true</li>
<li>try</li>
<li>typedef</li>
<li>typeid</li>
<li>typename</li>
<li>union</li>
<li>unsigned</li>
<li>using</li>
<li>virtual</li>
<li>void</li>
<li>volatile</li>
<li>wchar_t</li>
<li>while</li>
<li>xor</li>
<li>xor_eq</li>
</ul>
## FEATURE SET
### Client Modification Feature
| Name | Supported | Defined By |
| ---- | --------- | ---------- |
|BasePath|✗|ToolingExtension
|Authorizations|✗|ToolingExtension
|UserAgent|✗|ToolingExtension
|MockServer|✗|ToolingExtension
### Data Type Feature
| Name | Supported | Defined By |
| ---- | --------- | ---------- |
|Custom|✗|OAS2,OAS3
|Int32|✓|OAS2,OAS3
|Int64|✓|OAS2,OAS3
|Float|✓|OAS2,OAS3
|Double|✓|OAS2,OAS3
|Decimal|✓|ToolingExtension
|String|✓|OAS2,OAS3
|Byte|✓|OAS2,OAS3
|Binary|✓|OAS2,OAS3
|Boolean|✓|OAS2,OAS3
|Date|✓|OAS2,OAS3
|DateTime|✓|OAS2,OAS3
|Password|✓|OAS2,OAS3
|File|✓|OAS2
|Uuid|✗|
|Array|✓|OAS2,OAS3
|Null|✗|OAS3
|AnyType|✗|OAS2,OAS3
|Object|✓|OAS2,OAS3
|Maps|✓|ToolingExtension
|CollectionFormat|✓|OAS2
|CollectionFormatMulti|✓|OAS2
|Enum|✓|OAS2,OAS3
|ArrayOfEnum|✓|ToolingExtension
|ArrayOfModel|✓|ToolingExtension
|ArrayOfCollectionOfPrimitives|✓|ToolingExtension
|ArrayOfCollectionOfModel|✓|ToolingExtension
|ArrayOfCollectionOfEnum|✓|ToolingExtension
|MapOfEnum|✓|ToolingExtension
|MapOfModel|✓|ToolingExtension
|MapOfCollectionOfPrimitives|✓|ToolingExtension
|MapOfCollectionOfModel|✓|ToolingExtension
|MapOfCollectionOfEnum|✓|ToolingExtension
### Documentation Feature
| Name | Supported | Defined By |
| ---- | --------- | ---------- |
|Readme|✓|ToolingExtension
|Model|✓|ToolingExtension
|Api|✓|ToolingExtension
### Global Feature
| Name | Supported | Defined By |
| ---- | --------- | ---------- |
|Host|✓|OAS2,OAS3
|BasePath|✓|OAS2,OAS3
|Info|✓|OAS2,OAS3
|Schemes|✗|OAS2,OAS3
|PartialSchemes|✓|OAS2,OAS3
|Consumes|✓|OAS2
|Produces|✓|OAS2
|ExternalDocumentation|✓|OAS2,OAS3
|Examples|✓|OAS2,OAS3
|XMLStructureDefinitions|✗|OAS2,OAS3
|MultiServer|✗|OAS3
|ParameterizedServer|✗|OAS3
|ParameterStyling|✗|OAS3
|Callbacks|✗|OAS3
|LinkObjects|✗|OAS3
### Parameter Feature
| Name | Supported | Defined By |
| ---- | --------- | ---------- |
|Path|✓|OAS2,OAS3
|Query|✓|OAS2,OAS3
|Header|✓|OAS2,OAS3
|Body|✓|OAS2
|FormUnencoded|✓|OAS2
|FormMultipart|✓|OAS2
|Cookie|✗|OAS3
### Schema Support Feature
| Name | Supported | Defined By |
| ---- | --------- | ---------- |
|Simple|✓|OAS2,OAS3
|Composite|✓|OAS2,OAS3
|Polymorphism|✗|OAS2,OAS3
|Union|✗|OAS3
|allOf|✗|OAS2,OAS3
|anyOf|✗|OAS3
|oneOf|✗|OAS3
|not|✗|OAS3
### Security Feature
| Name | Supported | Defined By |
| ---- | --------- | ---------- |
|BasicAuth|✗|OAS2,OAS3
|ApiKey|✗|OAS2,OAS3
|OpenIDConnect|✗|OAS3
|BearerToken|✗|OAS3
|OAuth2_Implicit|✗|OAS2,OAS3
|OAuth2_Password|✗|OAS2,OAS3
|OAuth2_ClientCredentials|✗|OAS2,OAS3
|OAuth2_AuthorizationCode|✗|OAS2,OAS3
|SignatureAuth|✗|OAS3
|AWSV4Signature|✗|ToolingExtension
### Wire Format Feature
| Name | Supported | Defined By |
| ---- | --------- | ---------- |
|JSON|✓|OAS2,OAS3
|XML|✓|OAS2,OAS3
|PROTOBUF|✗|ToolingExtension
|Custom|✗|OAS2,OAS3

View File

@ -0,0 +1,503 @@
/*
* Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech)
* Copyright 2018 SmartBear Software
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.openapitools.codegen.languages;
import io.swagger.v3.oas.models.Operation;
import io.swagger.v3.oas.models.media.ArraySchema;
import io.swagger.v3.oas.models.media.Schema;
import io.swagger.v3.oas.models.responses.ApiResponse;
import io.swagger.v3.oas.models.servers.Server;
import org.apache.commons.lang3.StringUtils;
import org.openapitools.codegen.*;
import org.openapitools.codegen.meta.features.*;
import org.openapitools.codegen.model.ModelMap;
import org.openapitools.codegen.model.OperationMap;
import org.openapitools.codegen.model.OperationsMap;
import org.openapitools.codegen.utils.ModelUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;
import java.util.*;
import java.util.function.Predicate;
import static org.openapitools.codegen.utils.StringUtils.underscore;
public class CppOatppServerCodegen extends AbstractCppCodegen {
private final Logger LOGGER = LoggerFactory.getLogger(CppOatppServerCodegen.class);
protected String implFolder = "impl";
protected boolean isAddExternalLibs = true;
public static final String OPTIONAL_EXTERNAL_LIB = "addExternalLibs";
public static final String OPTIONAL_EXTERNAL_LIB_DESC = "Add the Possibility to fetch and compile external Libraries needed by this Framework.";
protected final String PREFIX = "";
@Override
public CodegenType getTag() {
return CodegenType.SERVER;
}
@Override
public String getName() {
return "cpp-oatpp-server";
}
@Override
public String getHelp() {
return "Generates a C++ API server (based on Oat++)";
}
public CppOatppServerCodegen() {
super();
// TODO: cpp-oatpp-server maintainer review
modifyFeatureSet(features -> features
.includeDocumentationFeatures(DocumentationFeature.Readme)
.securityFeatures(EnumSet.noneOf(SecurityFeature.class))
.excludeGlobalFeatures(
GlobalFeature.XMLStructureDefinitions,
GlobalFeature.Callbacks,
GlobalFeature.LinkObjects,
GlobalFeature.ParameterStyling,
GlobalFeature.MultiServer)
.excludeSchemaSupportFeatures(
SchemaSupportFeature.Polymorphism)
.excludeParameterFeatures(
ParameterFeature.Cookie));
if (StringUtils.isEmpty(modelNamePrefix)) {
modelNamePrefix = PREFIX;
}
apiPackage = "org.openapitools.server.api";
modelPackage = "org.openapitools.server.model";
apiTemplateFiles.put("api-header.mustache", ".hpp");
apiTemplateFiles.put("api-impl-header.mustache", ".hpp");
apiTemplateFiles.put("api-impl-source.mustache", ".cpp");
modelTemplateFiles.put("model-header.mustache", ".hpp");
embeddedTemplateDir = templateDir = "cpp-oatpp-server";
cliOptions.clear();
addSwitch(OPTIONAL_EXTERNAL_LIB, OPTIONAL_EXTERNAL_LIB_DESC, this.isAddExternalLibs);
addOption(RESERVED_WORD_PREFIX_OPTION, RESERVED_WORD_PREFIX_DESC, this.reservedWordPrefix);
addOption(VARIABLE_NAME_FIRST_CHARACTER_UPPERCASE_OPTION,
VARIABLE_NAME_FIRST_CHARACTER_UPPERCASE_DESC,
Boolean.toString(this.variableNameFirstCharacterUppercase));
setupSupportingFiles();
languageSpecificPrimitives = new HashSet<>(
Arrays.asList(
"oatpp::String",
"oatpp::Boolean",
"oatpp::Int32",
"oatpp::Int64",
"oatpp::Vector",
"oatpp::Fields",
"oatpp::UnorderedSet",
"oatpp::Object",
"oatpp::Float64",
"oatpp::Any"
));
typeMapping = new HashMap<>();
typeMapping.put("date", "oatpp::String");
typeMapping.put("DateTime", "oatpp::String");
typeMapping.put("string", "oatpp::String");
typeMapping.put("integer", "oatpp::Int32");
typeMapping.put("long", "oatpp::Int64");
typeMapping.put("boolean", "oatpp::Boolean");
typeMapping.put("array", "oatpp::Vector");
typeMapping.put("map", "oatpp::Fields");
typeMapping.put("set", "oatpp::UnorderedSet");
typeMapping.put("file", "oatpp::String");
typeMapping.put("object", "oatpp::Object");
typeMapping.put("binary", "oatpp::String");
typeMapping.put("number", "oatpp::Float64");
typeMapping.put("UUID", "oatpp::String");
typeMapping.put("URI", "oatpp::String");
typeMapping.put("ByteArray", "oatpp::String");
typeMapping.put("AnyType", "oatpp::Any");
super.importMapping = new HashMap<>();
}
private void setupSupportingFiles() {
supportingFiles.clear();
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"));
}
@Override
public void processOpts() {
super.processOpts();
if (additionalProperties.containsKey("modelNamePrefix")) {
additionalProperties().put("prefix", modelNamePrefix);
setupSupportingFiles();
}
if (additionalProperties.containsKey(RESERVED_WORD_PREFIX_OPTION)) {
reservedWordPrefix = (String) additionalProperties.get(RESERVED_WORD_PREFIX_OPTION);
}
additionalProperties.put("modelNamespaceDeclarations", modelPackage.split("\\."));
additionalProperties.put("modelNamespace", modelPackage.replaceAll("\\.", "::"));
additionalProperties.put("apiNamespaceDeclarations", apiPackage.split("\\."));
additionalProperties.put("apiNamespace", apiPackage.replaceAll("\\.", "::"));
additionalProperties.put(RESERVED_WORD_PREFIX_OPTION, reservedWordPrefix);
if (additionalProperties.containsKey(OPTIONAL_EXTERNAL_LIB)) {
setAddExternalLibs(convertPropertyToBooleanAndWriteBack(OPTIONAL_EXTERNAL_LIB));
} else {
additionalProperties.put(OPTIONAL_EXTERNAL_LIB, isAddExternalLibs);
}
}
@Override
public String toModelImport(String name) {
if (importMapping.containsKey(name)) {
return importMapping.get(name);
} else {
return "#include \"" + name + ".hpp\"";
}
}
@Override
public CodegenModel fromModel(String name, Schema model) {
CodegenModel codegenModel = super.fromModel(name, model);
Set<String> oldImports = codegenModel.imports;
codegenModel.imports = new HashSet<>();
for (String imp : oldImports) {
String newImp = toModelImport(imp);
if (!newImp.isEmpty()) {
codegenModel.imports.add(newImp);
}
}
if (!codegenModel.isEnum
&& codegenModel.anyOf.size() > 1
&& codegenModel.anyOf.contains("std::string")
&& !codegenModel.anyOf.contains("AnyType")
&& codegenModel.interfaces.size() == 1) {
codegenModel.vendorExtensions.put("x-is-string-enum-container", true);
}
return codegenModel;
}
@Override
public CodegenOperation fromOperation(String path, String httpMethod, Operation operation, List<Server> servers) {
CodegenOperation op = super.fromOperation(path, httpMethod, operation, servers);
if (operation.getResponses() != null && !operation.getResponses().isEmpty()) {
ApiResponse apiResponse = findMethodResponse(operation.getResponses());
if (apiResponse != null) {
Schema response = ModelUtils.getSchemaFromResponse(openAPI, apiResponse);
if (response != null) {
CodegenProperty cm = fromProperty("response", response, false);
op.vendorExtensions.put("x-codegen-response", cm);
if ("HttpContent".equals(cm.dataType)) {
op.vendorExtensions.put("x-codegen-response-ishttpcontent", true);
}
}
}
}
String pathForOatpp = path.replaceAll("\\{(.*?)}", "{$1}");
op.vendorExtensions.put("x-codegen-oatpp-path", pathForOatpp);
return op;
}
@Override
public OperationsMap postProcessOperationsWithModels(OperationsMap objs, List<ModelMap> allModels) {
OperationMap operations = objs.getOperations();
String classname = operations.getClassname();
operations.put("classnameSnakeUpperCase", underscore(classname).toUpperCase(Locale.ROOT));
operations.put("classnameSnakeLowerCase", underscore(classname).toLowerCase(Locale.ROOT));
List<CodegenOperation> operationList = operations.getOperation();
for (CodegenOperation op : operationList) {
postProcessSingleOperation(operations, op);
}
return objs;
}
private void postProcessSingleOperation(OperationMap operations, CodegenOperation op) {
if (op.vendorExtensions == null) {
op.vendorExtensions = new HashMap<>();
}
if (op.bodyParam != null) {
if (op.bodyParam.vendorExtensions == null) {
op.bodyParam.vendorExtensions = new HashMap<>();
}
boolean isStringOrDate = op.bodyParam.isString || op.bodyParam.isDate;
op.bodyParam.vendorExtensions.put("x-codegen-oatpp-is-string-or-date", isStringOrDate);
}
boolean consumeJson = false;
if (op.consumes != null) {
Predicate<Map<String, String>> isMediaTypeJson = consume -> (consume.get("mediaType") != null
&& consume.get("mediaType").equals("application/json"));
consumeJson = op.consumes.stream().anyMatch(isMediaTypeJson);
}
op.vendorExtensions.put("x-codegen-oatpp-consumes-json", consumeJson);
// Check if any one of the operations needs a model, then at API file level, at
// least one model has to be included.
Predicate<String> importNotInImportMapping = hdr -> !importMapping.containsKey(hdr);
if (op.imports.stream().anyMatch(importNotInImportMapping)) {
operations.put("hasModelImport", true);
}
}
/**
* postProcessSingleParam - Modifies a single parameter, adjusting generated
* data types for Header and Query parameters.
*
* @param param CodegenParameter to be modified.
*/
private static void postProcessSingleParam(CodegenParameter param) {
if (param.isQueryParam) {
param.dataType = "std::optional<" + param.dataType + ">";
if (!param.isPrimitiveType) {
param.baseType = "std::optional<" + param.baseType + ">";
}
}
}
@Override
public String toModelFilename(String name) {
return toModelName(name);
}
@Override
public String apiFilename(String templateName, String tag) {
String result = super.apiFilename(templateName, tag);
if (templateName.endsWith("impl-header.mustache")) {
result = implFilenameFromApiFilename(result, ".hpp");
} else if (templateName.endsWith("impl-source.mustache")) {
result = implFilenameFromApiFilename(result, ".cpp");
}
return result;
}
/**
* implFilenameFromApiFilename - Inserts the string "Controller" in front of the
* suffix and replace "api" with "impl" directory prefix.
*
* @param filename Filename of the api-file to be modified
* @param suffix Suffix of the file (usually ".cpp" or ".hpp")
* @return a filename string of impl file.
*/
private String implFilenameFromApiFilename(String filename, String suffix) {
String result = filename.substring(0, filename.length() - suffix.length()) + "Controller" + suffix;
result = result.replace(apiFileFolder(), implFileFolder());
return result;
}
@Override
public String toApiFilename(String name) {
return toApiName(name);
}
/**
* Optional - type declaration. This is a String which is used by the
* templates to instantiate your types. There is typically special handling
* for different property types
*
* @return a string value used as the `dataType` field for model templates,
* `returnType` for api templates
*/
@Override
public String getTypeDeclaration(Schema p) {
String openAPIType = getSchemaType(p);
if (ModelUtils.isArraySchema(p)) {
ArraySchema ap = (ArraySchema) p;
Schema inner = ap.getItems();
if (languageSpecificPrimitives.contains(getSchemaType(inner))) {
return getSchemaType(p) + "<" + getTypeDeclaration(inner) + ">";
}
return getSchemaType(p) + "<oatpp::Object<" + getTypeDeclaration(inner) + ">>";
}
if (ModelUtils.isMapSchema(p)) {
Schema inner = ModelUtils.getAdditionalProperties(p);
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)
|| languageSpecificPrimitives.contains(openAPIType)) {
return toModelName(openAPIType);
}
String namespace = (String)additionalProperties.get("modelNamespace");
return namespace + "::" + openAPIType;
}
@Override
public String toDefaultValue(Schema 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)) { // float
if (p.getDefault() != null) {
// We have to ensure that our default value has a decimal point,
// because in C++ the 'f' suffix is not valid on integer literals
// i.e. 374.0f is a valid float but 374 isn't.
String defaultStr = p.getDefault().toString();
if (defaultStr.indexOf('.') < 0) {
return defaultStr + ".0f";
} else {
return defaultStr + "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)) { // 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(ModelUtils.getAdditionalProperties(p));
return "std::map<std::string, " + inner + ">()";
} else if (ModelUtils.isArraySchema(p)) {
ArraySchema ap = (ArraySchema) p;
String inner = getSchemaType(ap.getItems());
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 "nullptr";
}
/**
* Location to write model files. You can use the modelPackage() as defined
* when the class is instantiated
*/
@Override
public String modelFileFolder() {
return (outputFolder + "/model").replace("/", File.separator);
}
/**
* Location to write api files. You can use the apiPackage() as defined when
* the class is instantiated
*/
@Override
public String apiFileFolder() {
return (outputFolder + "/api").replace("/", File.separator);
}
private String implFileFolder() {
return (outputFolder + "/" + implFolder).replace("/", File.separator);
}
/**
* Optional - OpenAPI type conversion. This is used to map OpenAPI types in
* a `Schema` into either language specific types via `typeMapping` or
* into complex models if there is not a mapping.
*
* @return a string value of the type or complex model for this property
*/
@Override
public String getSchemaType(Schema p) {
String openAPIType = super.getSchemaType(p);
String type = null;
if (typeMapping.containsKey(openAPIType)) {
type = typeMapping.get(openAPIType);
} else {
type = openAPIType;
}
return toModelName(type);
}
@Override
public String getTypeDeclaration(String str) {
return toModelName(str);
}
/**
* Specify whether external libraries will be added during the generation
*
* @param value the value to be set
*/
public void setAddExternalLibs(boolean value) {
isAddExternalLibs = value;
}
}

View File

@ -14,6 +14,7 @@ org.openapitools.codegen.languages.ClojureClientCodegen
org.openapitools.codegen.languages.ConfluenceWikiCodegen
org.openapitools.codegen.languages.CppQtClientCodegen
org.openapitools.codegen.languages.CppQtQHttpEngineServerCodegen
org.openapitools.codegen.languages.CppOatppServerCodegen
org.openapitools.codegen.languages.CppPistacheServerCodegen
org.openapitools.codegen.languages.CppRestbedServerCodegen
org.openapitools.codegen.languages.CppRestbedServerDeprecatedCodegen

View File

@ -0,0 +1,46 @@
# REST API Server for {{appName}}
## Overview
This API Server was generated by the [OpenAPI Generator](https://openapi-generator.tech) project.
It uses the [Oat++](https://github.com/oatpp/oatpp) Framework.
## Files organization
The Oat++ C++ REST server generator creates three folders:
- `api`: This folder contains the handlers for each method specified in the OpenAPI definition. Every handler extracts
the path and body parameters (if any) from the requests and tries to parse and possibly validate them.
Once this step is completed, the main API class calls the corresponding abstract method that should be implemented
by the developer (a basic implementation is provided under the `impl` folder)
- `impl`: As written above, the implementation folder contains, for each API, the corresponding implementation class,
which extends the main API class and implements the abstract methods.
Every method receives the path and body parameters as constant reference variables and a reference to the response
object, that should be filled with the right response and sent at the end of the method with the command:
response.send(returnCode, responseBody, [mimeType])
- `model`: This folder contains the corresponding class for every object schema found in the OpenAPI specification.
The main folder contains also a file with a main that can be used to start the server.
Of course, is you should customize this file based on your needs
## Installation
First of all, you need to download and install the libraries listed [here](#libraries-required).
Once the libraries are installed, in order to compile and run the server please follow the steps below:
```bash
mkdir build
cd build
cmake ..
make
```
Once compiled run the server:
```bash
cd build
./api-server
```
## Libraries required
- [Oat++](https://oatpp.io/)
## Namespaces
{{{apiPackage}}}
{{{modelPackage}}}

View File

@ -0,0 +1,58 @@
{{>licenseInfo}}
{{#operations}}/*
* {{classname}}.h
*
* {{description}}
*/
#ifndef {{classname}}_H_
#define {{classname}}_H_
{{{defaultInclude}}}
#include "oatpp/web/server/api/ApiController.hpp"
#include "oatpp/core/macro/codegen.hpp"
#include "oatpp/core/macro/component.hpp"
#include "oatpp/core/Types.hpp"
{{#imports}}{{{import}}}
{{/imports}}
#include OATPP_CODEGEN_BEGIN(ApiController) ///< Begin ApiController codegen section
namespace {{apiNamespace}}
{
class {{classname}} : public oatpp::web::server::api::ApiController {
public:
{{classname}}(OATPP_COMPONENT(std::shared_ptr<ObjectMapper>, objectMapper) /* Inject object mapper */)
: oatpp::web::server::api::ApiController(objectMapper)
{}
{{#operation}}
/// <summary>
/// {{summary}}
/// </summary>
/// <remarks>
/// {{notes}}
/// </remarks>
/// <param name="request">HTTP Request</param>
{{#allParams}}
{{#isPathParam}}/// <param name="{{paramName}}">{{description}}{{^required}} (optional{{#defaultValue}}, default to {{.}}{{/defaultValue}}){{/required}}</param>{{/isPathParam}}{{#isQueryParam}}/// <param name="{{paramName}}">{{description}}{{^required}} (optional{{#defaultValue}}, default to {{.}}{{/defaultValue}}){{/required}}</param>{{/isQueryParam}}{{#isBodyParam}}/// <param name="{{paramName}}">{{description}}{{^required}} (optional{{#defaultValue}}, default to {{.}}{{/defaultValue}}){{/required}}</param>{{/isBodyParam}}{{#isHeaderParam}}/// <param name="{{paramName}}">{{description}}{{^required}} (optional{{#defaultValue}}, default to {{.}}{{/defaultValue}}){{/required}}</param>{{/isHeaderParam}}
{{/allParams}}
virtual std::shared_ptr<oatpp::web::protocol::http::outgoing::Response> {{operationIdSnakeCase}}(const std::shared_ptr<IncomingRequest> &request{{#allParams}}{{#isPathParam}}, const {{#isModel}}{{modelNamespace}}::{{/isModel}}{{{dataType}}} &{{paramName}}{{/isPathParam}}{{#isQueryParam}}, const {{#isModel}}{{modelNamespace}}::{{/isModel}}{{{dataType}}} &{{paramName}}{{/isQueryParam}}{{#isBodyParam}}, const {{#isModel}}oatpp::Object<{{#isModel}}{{modelNamespace}}::{{/isModel}}{{{dataType}}}>{{/isModel}}{{^isModel}}{{#isModel}}{{modelNamespace}}::{{/isModel}}{{{dataType}}}{{/isModel}} &{{paramName}}{{/isBodyParam}}{{#isHeaderParam}}, const {{#isModel}}{{modelNamespace}}::{{/isModel}}{{{dataType}}} &{{paramName}}{{/isHeaderParam}}{{/allParams}}) = 0;
ENDPOINT("{{httpMethod}}", "{{{vendorExtensions.x-codegen-oatpp-path}}}", {{operationIdSnakeCase}}_handler, REQUEST(std::shared_ptr<IncomingRequest>, request){{#allParams}}{{#isPathParam}}, PATH({{#isModel}}{{modelNamespace}}::{{/isModel}}{{&dataType}}, {{paramName}}){{/isPathParam}}{{#isQueryParam}}, QUERY({{#isModel}}{{modelNamespace}}::{{/isModel}}{{&dataType}}, {{paramName}}){{/isQueryParam}}{{#isBodyParam}}, BODY_DTO({{#isModel}}oatpp::Object<{{#isModel}}{{modelNamespace}}::{{/isModel}}{{{dataType}}}>{{/isModel}}{{^isModel}}{{#isModel}}{{modelNamespace}}::{{/isModel}}{{{dataType}}}{{/isModel}}, {{paramName}}){{/isBodyParam}}{{#isHeaderParam}}, HEADER({{{dataType}}}, {{paramName}}, "{{paramName}}"){{/isHeaderParam}}{{/allParams}}) {
return {{operationIdSnakeCase}}(request{{#allParams}}{{#isPathParam}}, {{paramName}}{{/isPathParam}}{{#isQueryParam}}, {{paramName}}{{/isQueryParam}}{{#isBodyParam}}, {{paramName}}{{/isBodyParam}}{{#isHeaderParam}}, {{paramName}}{{/isHeaderParam}}{{/allParams}});
}
{{/operation}}
};
#include OATPP_CODEGEN_END(ApiController) ///< End ApiController codegen section
} // namespace {{apiNamespace}}
#endif /* {{classname}}_H_ */
{{/operations}}

View File

@ -0,0 +1,45 @@
{{>licenseInfo}}
{{#operations}}/*
* {{classname}}Controller.hpp
*
* {{description}}
*/
#ifndef {{classnameSnakeUpperCase}}_IMPL_H_
#define {{classnameSnakeUpperCase}}_IMPL_H_
{{{defaultInclude}}}
#include <{{classname}}.hpp>
#include "oatpp/core/Types.hpp"
{{#imports}}{{{import}}}
{{/imports}}
namespace {{apiNamespace}}
{
class {{declspec}} {{classname}}Controller : public {{classname}} {
public:
{{#operation}}
/// <summary>
/// {{summary}}
/// </summary>
/// <remarks>
/// {{notes}}
/// </remarks>
/// <param name="request">HTTP Request</param>
{{#allParams}}
{{#isPathParam}}/// <param name="{{paramName}}">{{description}}{{^required}} (optional{{#defaultValue}}, default to {{.}}{{/defaultValue}}){{/required}}</param>{{/isPathParam}}{{#isQueryParam}}/// <param name="{{paramName}}">{{description}}{{^required}} (optional{{#defaultValue}}, default to {{.}}{{/defaultValue}}){{/required}}</param>{{/isQueryParam}}{{#isBodyParam}}/// <param name="{{paramName}}">{{description}}{{^required}} (optional{{#defaultValue}}, default to {{.}}{{/defaultValue}}){{/required}}</param>{{/isBodyParam}}{{#isHeaderParam}}/// <param name="{{paramName}}">{{description}}{{^required}} (optional{{#defaultValue}}, default to {{.}}{{/defaultValue}}){{/required}}</param>{{/isHeaderParam}}
{{/allParams}}
virtual std::shared_ptr<oatpp::web::protocol::http::outgoing::Response> {{operationIdSnakeCase}}(const std::shared_ptr<IncomingRequest> &request{{#allParams}}{{#isPathParam}}, const {{#isModel}}{{modelNamespace}}::{{/isModel}}{{{dataType}}} &{{paramName}}{{/isPathParam}}{{#isQueryParam}}, const {{#isModel}}{{modelNamespace}}::{{/isModel}}{{{dataType}}} &{{paramName}}{{/isQueryParam}}{{#isBodyParam}}, const {{#isModel}}oatpp::Object<{{#isModel}}{{modelNamespace}}::{{/isModel}}{{{dataType}}}>{{/isModel}}{{^isModel}}{{#isModel}}{{modelNamespace}}::{{/isModel}}{{{dataType}}}{{/isModel}} &{{paramName}}{{/isBodyParam}}{{#isHeaderParam}}, const {{#isModel}}{{modelNamespace}}::{{/isModel}}{{{dataType}}} &{{paramName}}{{/isHeaderParam}}{{/allParams}});
{{/operation}}
};
} // namespace {{apiNamespace}}
{{/operations}}
#endif

View File

@ -0,0 +1,27 @@
{{>licenseInfo}}
{{#operations}}
#include "{{classname}}Controller.hpp"
{{#apiNamespaceDeclarations}}
namespace {{this}} {
{{/apiNamespaceDeclarations}}
{{#operation}}
std::shared_ptr<oatpp::web::protocol::http::outgoing::Response> {{classname}}Controller::{{operationIdSnakeCase}}(const std::shared_ptr<IncomingRequest> &request{{#allParams}}{{#isPathParam}}, const {{#isModel}}{{modelNamespace}}::{{/isModel}}{{{dataType}}} &{{paramName}}{{/isPathParam}}{{#isQueryParam}}, const {{#isModel}}{{modelNamespace}}::{{/isModel}}{{{dataType}}} &{{paramName}}{{/isQueryParam}}{{#isBodyParam}}, const {{#isModel}}oatpp::Object<{{#isModel}}{{modelNamespace}}::{{/isModel}}{{{dataType}}}>{{/isModel}}{{^isModel}}{{#isModel}}{{modelNamespace}}::{{/isModel}}{{{dataType}}}{{/isModel}} &{{paramName}}{{/isBodyParam}}{{#isHeaderParam}}, const {{#isModel}}{{modelNamespace}}::{{/isModel}}{{{dataType}}} &{{paramName}}{{/isHeaderParam}}{{/allParams}}) {
(void)request;
{{#allParams}}
{{#isPathParam}}(void){{paramName}};{{/isPathParam}}
{{#isQueryParam}}(void){{paramName}};{{/isQueryParam}}
{{#isBodyParam}}(void){{paramName}};{{/isBodyParam}}
{{#isHeaderParam}}(void){{paramName}};{{/isHeaderParam}}
{{/allParams}}
return createResponse(Status::CODE_501, "TODO: Implement API Handler");
}
{{/operation}}
{{#apiNamespaceDeclarations}}
}
{{/apiNamespaceDeclarations}}
{{/operations}}

View File

@ -0,0 +1,38 @@
cmake_minimum_required (VERSION 3.2)
project(api-server)
{{#addExternalLibs}}
include(ExternalProject)
set(EXTERNAL_INSTALL_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/external)
ExternalProject_Add(OATPP
GIT_REPOSITORY https://github.com/oatpp/oatpp.git
BUILD_IN_SOURCE true
GIT_TAG 1.3.1
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${EXTERNAL_INSTALL_LOCATION}
)
include_directories(${EXTERNAL_INSTALL_LOCATION}/include/oatpp-1.3.0/oatpp)
{{/addExternalLibs}}
include_directories(model)
include_directories(api)
include_directories(impl)
file(GLOB SRCS
${CMAKE_CURRENT_SOURCE_DIR}/impl/*.cpp
${CMAKE_CURRENT_SOURCE_DIR}/*.cpp
)
add_executable(${PROJECT_NAME} ${SRCS})
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17)
{{#addExternalLibs}}add_dependencies(${PROJECT_NAME} OATPP)
if(WIN32)
target_link_libraries(${PROJECT_NAME} ${EXTERNAL_INSTALL_LOCATION}/lib/oatpp-1.3.0/oatpp.lib)
target_link_libraries(${PROJECT_NAME} ws2_32)
else()
target_link_libraries(${PROJECT_NAME} ${EXTERNAL_INSTALL_LOCATION}/lib/oatpp-1.3.0/liboatpp.a)
endif(WIN32){{/addExternalLibs}}

View File

@ -0,0 +1,11 @@
/**
* {{{appName}}}
* {{{appDescription}}}
*
* {{#version}}The version of the OpenAPI document: {{{.}}}{{/version}}
* {{#infoEmail}}Contact: {{{.}}}{{/infoEmail}}
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/

View File

@ -0,0 +1,95 @@
{{>licenseInfo}}
#include "oatpp/web/server/HttpConnectionHandler.hpp"
#include "oatpp/network/Server.hpp"
#include "oatpp/network/tcp/server/ConnectionProvider.hpp"
#include "oatpp/parser/json/mapping/ObjectMapper.hpp"
#include "oatpp/parser/json/Utils.hpp"
{{#apiInfo}}{{#apis}}{{#operations}}
#include "{{classname}}Controller.hpp"{{/operations}}{{/apis}}{{/apiInfo}}
/**
* Class which creates and holds Application components and registers components in oatpp::base::Environment
* Order of components initialization is from top to bottom
*/
class AppComponent {
public:
/**
* Create ConnectionProvider component which listens on the port
*/
OATPP_CREATE_COMPONENT(std::shared_ptr<oatpp::network::ServerConnectionProvider>, serverConnectionProvider)([] {
return oatpp::network::tcp::server::ConnectionProvider::createShared({"localhost", {{serverPort}}{{^serverPort}}8080{{/serverPort}}, oatpp::network::Address::IP_4});
}());
/**
* Create Router component
*/
OATPP_CREATE_COMPONENT(std::shared_ptr<oatpp::web::server::HttpRouter>, httpRouter)([] {
return oatpp::web::server::HttpRouter::createShared();
}());
/**
* Create ConnectionHandler component which uses Router component to route requests
*/
OATPP_CREATE_COMPONENT(std::shared_ptr<oatpp::network::ConnectionHandler>, serverConnectionHandler)([] {
OATPP_COMPONENT(std::shared_ptr<oatpp::web::server::HttpRouter>, router); // get Router component
return oatpp::web::server::HttpConnectionHandler::createShared(router);
}());
/**
* Create ObjectMapper component to serialize/deserialize DTOs in Contoller's API
*/
OATPP_CREATE_COMPONENT(std::shared_ptr<oatpp::data::mapping::ObjectMapper>, apiObjectMapper)([] {
return oatpp::parser::json::mapping::ObjectMapper::createShared();
}());
};
static int _main_app(void) {
/* Register Components in scope of run() method */
AppComponent components;
/* Get router component */
OATPP_COMPONENT(std::shared_ptr<oatpp::web::server::HttpRouter>, router);
{{#apiInfo}}{{#apis}}{{#operations}}
/* Create {{classname}}Controller and add all of its endpoints to router */
auto {{classname}}Controller = std::make_shared<{{apiNamespace}}::{{classname}}Controller>();
router->addController({{classname}}Controller);
{{/operations}}{{/apis}}{{/apiInfo}}
/* Get connection handler component */
OATPP_COMPONENT(std::shared_ptr<oatpp::network::ConnectionHandler>, connectionHandler);
/* Get connection provider component */
OATPP_COMPONENT(std::shared_ptr<oatpp::network::ServerConnectionProvider>, connectionProvider);
/* Create server which takes provided TCP connections and passes them to HTTP connection handler */
oatpp::network::Server server(connectionProvider, connectionHandler);
/* Print info about server port */
OATPP_LOGI("MyApp", "Server running on port %s", connectionProvider->getProperty("port").getData());
/* Run server */
server.run();
return 0;
}
int main(int argc, char **argv) {
/* Init oatpp Environment */
oatpp::base::Environment::init();
int ret = _main_app();
/* Destroy oatpp Environment */
oatpp::base::Environment::destroy();
return ret;
}

View File

@ -0,0 +1,49 @@
{{>licenseInfo}}
{{#models}}{{#model}}/*
* {{classname}}.h
*
* {{description}}
*/
#ifndef {{classname}}_H_
#define {{classname}}_H_
{{{defaultInclude}}}
{{#imports}}{{{this}}}
{{/imports}}
#include "oatpp/core/macro/codegen.hpp"
#include "oatpp/core/Types.hpp"
namespace {{modelNamespace}}
{
/* Begin DTO code-generation */
#include OATPP_CODEGEN_BEGIN(DTO)
/**
* Message Data-Transfer-Object
*/
class {{classname}} : public oatpp::DTO {
DTO_INIT({{classname}}, DTO /* Extends */)
{{#vars}}
DTO_FIELD({{#isModel}}oatpp::Object<{{{dataType}}}>{{/isModel}}{{^isModel}}{{{dataType}}}{{/isModel}}, {{name}});
{{^required}}
DTO_FIELD(oatpp::Boolean, {{name}}IsSet);{{/required}}
{{/vars}}
{{#isEnum}} // TODO:
{{classname}}::e{{classname}} m_value = {{classname}}::e{{classname}}::INVALID_VALUE_OPENAPI_GENERATED;{{/isEnum}}
{{#vendorExtensions.x-is-string-enum-container}} // TODO:
{{#anyOf}}{{#-first}}{{{this}}} m_value;{{/-first}}{{/anyOf}}{{/vendorExtensions.x-is-string-enum-container}}
};
/* End DTO code-generation */
#include OATPP_CODEGEN_END(DTO)
} // namespace {{modelNamespace}}
#endif /* {{classname}}_H_ */
{{/model}}
{{/models}}

View File

@ -0,0 +1,23 @@
# OpenAPI Generator Ignore
# Generated by openapi-generator https://github.com/openapitools/openapi-generator
# Use this file to prevent files from being overwritten by the generator.
# The patterns follow closely to .gitignore or .dockerignore.
# As an example, the C# client generator defines ApiClient.cs.
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line:
#ApiClient.cs
# You can match any string of characters against a directory, file or extension with a single asterisk (*):
#foo/*/qux
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux
# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
#foo/**/qux
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux
# You can also negate patterns with an exclamation (!).
# For example, you can ignore all files in a docs folder with the file extension .md:
#docs/*.md
# Then explicitly reverse the ignore rule for a single file:
#!docs/README.md

View File

@ -0,0 +1,18 @@
CMakeLists.txt
README.md
api/PetApi.hpp
api/StoreApi.hpp
api/UserApi.hpp
impl/PetApiController.cpp
impl/PetApiController.hpp
impl/StoreApiController.cpp
impl/StoreApiController.hpp
impl/UserApiController.cpp
impl/UserApiController.hpp
main-api-server.cpp
model/ApiResponse.hpp
model/Category.hpp
model/Order.hpp
model/Pet.hpp
model/Tag.hpp
model/User.hpp

View File

@ -0,0 +1 @@
7.15.0-SNAPSHOT

View File

@ -0,0 +1,36 @@
cmake_minimum_required (VERSION 3.2)
project(api-server)
include(ExternalProject)
set(EXTERNAL_INSTALL_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/external)
ExternalProject_Add(OATPP
GIT_REPOSITORY https://github.com/oatpp/oatpp.git
BUILD_IN_SOURCE true
GIT_TAG 1.3.1
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${EXTERNAL_INSTALL_LOCATION}
)
include_directories(${EXTERNAL_INSTALL_LOCATION}/include/oatpp-1.3.0/oatpp)
include_directories(model)
include_directories(api)
include_directories(impl)
file(GLOB SRCS
${CMAKE_CURRENT_SOURCE_DIR}/impl/*.cpp
${CMAKE_CURRENT_SOURCE_DIR}/*.cpp
)
add_executable(${PROJECT_NAME} ${SRCS})
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17)
add_dependencies(${PROJECT_NAME} OATPP)
if(WIN32)
target_link_libraries(${PROJECT_NAME} ${EXTERNAL_INSTALL_LOCATION}/lib/oatpp-1.3.0/oatpp.lib)
target_link_libraries(${PROJECT_NAME} ws2_32)
else()
target_link_libraries(${PROJECT_NAME} ${EXTERNAL_INSTALL_LOCATION}/lib/oatpp-1.3.0/liboatpp.a)
endif(WIN32)

View File

@ -0,0 +1,46 @@
# REST API Server for OpenAPI Petstore
## Overview
This API Server was generated by the [OpenAPI Generator](https://openapi-generator.tech) project.
It uses the [Oat++](https://github.com/oatpp/oatpp) Framework.
## Files organization
The Oat++ C++ REST server generator creates three folders:
- `api`: This folder contains the handlers for each method specified in the OpenAPI definition. Every handler extracts
the path and body parameters (if any) from the requests and tries to parse and possibly validate them.
Once this step is completed, the main API class calls the corresponding abstract method that should be implemented
by the developer (a basic implementation is provided under the `impl` folder)
- `impl`: As written above, the implementation folder contains, for each API, the corresponding implementation class,
which extends the main API class and implements the abstract methods.
Every method receives the path and body parameters as constant reference variables and a reference to the response
object, that should be filled with the right response and sent at the end of the method with the command:
response.send(returnCode, responseBody, [mimeType])
- `model`: This folder contains the corresponding class for every object schema found in the OpenAPI specification.
The main folder contains also a file with a main that can be used to start the server.
Of course, is you should customize this file based on your needs
## Installation
First of all, you need to download and install the libraries listed [here](#libraries-required).
Once the libraries are installed, in order to compile and run the server please follow the steps below:
```bash
mkdir build
cd build
cmake ..
make
```
Once compiled run the server:
```bash
cd build
./api-server
```
## Libraries required
- [Oat++](https://oatpp.io/)
## Namespaces
org.openapitools.server.api
org.openapitools.server.model

View File

@ -0,0 +1,159 @@
/**
* OpenAPI Petstore
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
*
* The version of the OpenAPI document: 1.0.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
/*
* PetApi.h
*
*
*/
#ifndef PetApi_H_
#define PetApi_H_
#include "oatpp/web/server/api/ApiController.hpp"
#include "oatpp/core/macro/codegen.hpp"
#include "oatpp/core/macro/component.hpp"
#include "oatpp/core/Types.hpp"
#include "ApiResponse.hpp"
#include "Pet.hpp"
#include OATPP_CODEGEN_BEGIN(ApiController) ///< Begin ApiController codegen section
namespace org::openapitools::server::api
{
class PetApi : public oatpp::web::server::api::ApiController {
public:
PetApi(OATPP_COMPONENT(std::shared_ptr<ObjectMapper>, objectMapper) /* Inject object mapper */)
: oatpp::web::server::api::ApiController(objectMapper)
{}
/// <summary>
/// Add a new pet to the store
/// </summary>
/// <remarks>
///
/// </remarks>
/// <param name="request">HTTP Request</param>
/// <param name="pet">Pet object that needs to be added to the store</param>
virtual std::shared_ptr<oatpp::web::protocol::http::outgoing::Response> add_pet(const std::shared_ptr<IncomingRequest> &request, const oatpp::Object<org::openapitools::server::model::Pet> &pet) = 0;
ENDPOINT("POST", "/pet", add_pet_handler, REQUEST(std::shared_ptr<IncomingRequest>, request), BODY_DTO(oatpp::Object<org::openapitools::server::model::Pet>, pet)) {
return add_pet(request, pet);
}
/// <summary>
/// Deletes a pet
/// </summary>
/// <remarks>
///
/// </remarks>
/// <param name="request">HTTP Request</param>
/// <param name="petId">Pet id to delete</param>
/// <param name="apiKey"> (optional, default to &quot;&quot;)</param>
virtual std::shared_ptr<oatpp::web::protocol::http::outgoing::Response> delete_pet(const std::shared_ptr<IncomingRequest> &request, const oatpp::Int64 &petId, const oatpp::String &apiKey) = 0;
ENDPOINT("DELETE", "/pet/{petId}", delete_pet_handler, REQUEST(std::shared_ptr<IncomingRequest>, request), PATH(oatpp::Int64, petId), HEADER(oatpp::String, apiKey, "apiKey")) {
return delete_pet(request, petId, apiKey);
}
/// <summary>
/// Finds Pets by status
/// </summary>
/// <remarks>
/// Multiple status values can be provided with comma separated strings
/// </remarks>
/// <param name="request">HTTP Request</param>
/// <param name="status">Status values that need to be considered for filter</param>
virtual std::shared_ptr<oatpp::web::protocol::http::outgoing::Response> find_pets_by_status(const std::shared_ptr<IncomingRequest> &request, const oatpp::Vector<oatpp::String> &status) = 0;
ENDPOINT("GET", "/pet/findByStatus", find_pets_by_status_handler, REQUEST(std::shared_ptr<IncomingRequest>, request), QUERY(oatpp::Vector<oatpp::String>, status)) {
return find_pets_by_status(request, status);
}
/// <summary>
/// Finds Pets by tags
/// </summary>
/// <remarks>
/// Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
/// </remarks>
/// <param name="request">HTTP Request</param>
/// <param name="tags">Tags to filter by</param>
virtual std::shared_ptr<oatpp::web::protocol::http::outgoing::Response> find_pets_by_tags(const std::shared_ptr<IncomingRequest> &request, const oatpp::Vector<oatpp::String> &tags) = 0;
ENDPOINT("GET", "/pet/findByTags", find_pets_by_tags_handler, REQUEST(std::shared_ptr<IncomingRequest>, request), QUERY(oatpp::Vector<oatpp::String>, tags)) {
return find_pets_by_tags(request, tags);
}
/// <summary>
/// Find pet by ID
/// </summary>
/// <remarks>
/// Returns a single pet
/// </remarks>
/// <param name="request">HTTP Request</param>
/// <param name="petId">ID of pet to return</param>
virtual std::shared_ptr<oatpp::web::protocol::http::outgoing::Response> get_pet_by_id(const std::shared_ptr<IncomingRequest> &request, const oatpp::Int64 &petId) = 0;
ENDPOINT("GET", "/pet/{petId}", get_pet_by_id_handler, REQUEST(std::shared_ptr<IncomingRequest>, request), PATH(oatpp::Int64, petId)) {
return get_pet_by_id(request, petId);
}
/// <summary>
/// Update an existing pet
/// </summary>
/// <remarks>
///
/// </remarks>
/// <param name="request">HTTP Request</param>
/// <param name="pet">Pet object that needs to be added to the store</param>
virtual std::shared_ptr<oatpp::web::protocol::http::outgoing::Response> update_pet(const std::shared_ptr<IncomingRequest> &request, const oatpp::Object<org::openapitools::server::model::Pet> &pet) = 0;
ENDPOINT("PUT", "/pet", update_pet_handler, REQUEST(std::shared_ptr<IncomingRequest>, request), BODY_DTO(oatpp::Object<org::openapitools::server::model::Pet>, pet)) {
return update_pet(request, pet);
}
/// <summary>
/// Updates a pet in the store with form data
/// </summary>
/// <remarks>
///
/// </remarks>
/// <param name="request">HTTP Request</param>
/// <param name="petId">ID of pet that needs to be updated</param>
virtual std::shared_ptr<oatpp::web::protocol::http::outgoing::Response> update_pet_with_form(const std::shared_ptr<IncomingRequest> &request, const oatpp::Int64 &petId) = 0;
ENDPOINT("POST", "/pet/{petId}", update_pet_with_form_handler, REQUEST(std::shared_ptr<IncomingRequest>, request), PATH(oatpp::Int64, petId)) {
return update_pet_with_form(request, petId);
}
/// <summary>
/// uploads an image
/// </summary>
/// <remarks>
///
/// </remarks>
/// <param name="request">HTTP Request</param>
/// <param name="petId">ID of pet to update</param>
virtual std::shared_ptr<oatpp::web::protocol::http::outgoing::Response> upload_file(const std::shared_ptr<IncomingRequest> &request, const oatpp::Int64 &petId) = 0;
ENDPOINT("POST", "/pet/{petId}/uploadImage", upload_file_handler, REQUEST(std::shared_ptr<IncomingRequest>, request), PATH(oatpp::Int64, petId)) {
return upload_file(request, petId);
}
};
#include OATPP_CODEGEN_END(ApiController) ///< End ApiController codegen section
} // namespace org::openapitools::server::api
#endif /* PetApi_H_ */

View File

@ -0,0 +1,100 @@
/**
* OpenAPI Petstore
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
*
* The version of the OpenAPI document: 1.0.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
/*
* StoreApi.h
*
*
*/
#ifndef StoreApi_H_
#define StoreApi_H_
#include "oatpp/web/server/api/ApiController.hpp"
#include "oatpp/core/macro/codegen.hpp"
#include "oatpp/core/macro/component.hpp"
#include "oatpp/core/Types.hpp"
#include "Order.hpp"
#include OATPP_CODEGEN_BEGIN(ApiController) ///< Begin ApiController codegen section
namespace org::openapitools::server::api
{
class StoreApi : public oatpp::web::server::api::ApiController {
public:
StoreApi(OATPP_COMPONENT(std::shared_ptr<ObjectMapper>, objectMapper) /* Inject object mapper */)
: oatpp::web::server::api::ApiController(objectMapper)
{}
/// <summary>
/// Delete purchase order by ID
/// </summary>
/// <remarks>
/// For valid response try integer IDs with value &lt; 1000. Anything above 1000 or nonintegers will generate API errors
/// </remarks>
/// <param name="request">HTTP Request</param>
/// <param name="orderId">ID of the order that needs to be deleted</param>
virtual std::shared_ptr<oatpp::web::protocol::http::outgoing::Response> delete_order(const std::shared_ptr<IncomingRequest> &request, const oatpp::String &orderId) = 0;
ENDPOINT("DELETE", "/store/order/{orderId}", delete_order_handler, REQUEST(std::shared_ptr<IncomingRequest>, request), PATH(oatpp::String, orderId)) {
return delete_order(request, orderId);
}
/// <summary>
/// Returns pet inventories by status
/// </summary>
/// <remarks>
/// Returns a map of status codes to quantities
/// </remarks>
/// <param name="request">HTTP Request</param>
virtual std::shared_ptr<oatpp::web::protocol::http::outgoing::Response> get_inventory(const std::shared_ptr<IncomingRequest> &request) = 0;
ENDPOINT("GET", "/store/inventory", get_inventory_handler, REQUEST(std::shared_ptr<IncomingRequest>, request)) {
return get_inventory(request);
}
/// <summary>
/// Find purchase order by ID
/// </summary>
/// <remarks>
/// For valid response try integer IDs with value &lt;&#x3D; 5 or &gt; 10. Other values will generate exceptions
/// </remarks>
/// <param name="request">HTTP Request</param>
/// <param name="orderId">ID of pet that needs to be fetched</param>
virtual std::shared_ptr<oatpp::web::protocol::http::outgoing::Response> get_order_by_id(const std::shared_ptr<IncomingRequest> &request, const oatpp::Int64 &orderId) = 0;
ENDPOINT("GET", "/store/order/{orderId}", get_order_by_id_handler, REQUEST(std::shared_ptr<IncomingRequest>, request), PATH(oatpp::Int64, orderId)) {
return get_order_by_id(request, orderId);
}
/// <summary>
/// Place an order for a pet
/// </summary>
/// <remarks>
///
/// </remarks>
/// <param name="request">HTTP Request</param>
/// <param name="order">order placed for purchasing the pet</param>
virtual std::shared_ptr<oatpp::web::protocol::http::outgoing::Response> place_order(const std::shared_ptr<IncomingRequest> &request, const oatpp::Object<org::openapitools::server::model::Order> &order) = 0;
ENDPOINT("POST", "/store/order", place_order_handler, REQUEST(std::shared_ptr<IncomingRequest>, request), BODY_DTO(oatpp::Object<org::openapitools::server::model::Order>, order)) {
return place_order(request, order);
}
};
#include OATPP_CODEGEN_END(ApiController) ///< End ApiController codegen section
} // namespace org::openapitools::server::api
#endif /* StoreApi_H_ */

View File

@ -0,0 +1,154 @@
/**
* OpenAPI Petstore
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
*
* The version of the OpenAPI document: 1.0.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
/*
* UserApi.h
*
*
*/
#ifndef UserApi_H_
#define UserApi_H_
#include "oatpp/web/server/api/ApiController.hpp"
#include "oatpp/core/macro/codegen.hpp"
#include "oatpp/core/macro/component.hpp"
#include "oatpp/core/Types.hpp"
#include "User.hpp"
#include OATPP_CODEGEN_BEGIN(ApiController) ///< Begin ApiController codegen section
namespace org::openapitools::server::api
{
class UserApi : public oatpp::web::server::api::ApiController {
public:
UserApi(OATPP_COMPONENT(std::shared_ptr<ObjectMapper>, objectMapper) /* Inject object mapper */)
: oatpp::web::server::api::ApiController(objectMapper)
{}
/// <summary>
/// Create user
/// </summary>
/// <remarks>
/// This can only be done by the logged in user.
/// </remarks>
/// <param name="request">HTTP Request</param>
/// <param name="user">Created user object</param>
virtual std::shared_ptr<oatpp::web::protocol::http::outgoing::Response> create_user(const std::shared_ptr<IncomingRequest> &request, const oatpp::Object<org::openapitools::server::model::User> &user) = 0;
ENDPOINT("POST", "/user", create_user_handler, REQUEST(std::shared_ptr<IncomingRequest>, request), BODY_DTO(oatpp::Object<org::openapitools::server::model::User>, user)) {
return create_user(request, user);
}
/// <summary>
/// Creates list of users with given input array
/// </summary>
/// <remarks>
///
/// </remarks>
/// <param name="request">HTTP Request</param>
/// <param name="user">List of user object</param>
virtual std::shared_ptr<oatpp::web::protocol::http::outgoing::Response> create_users_with_array_input(const std::shared_ptr<IncomingRequest> &request, const oatpp::Vector<oatpp::Object<org::openapitools::server::model::User>> &user) = 0;
ENDPOINT("POST", "/user/createWithArray", create_users_with_array_input_handler, REQUEST(std::shared_ptr<IncomingRequest>, request), BODY_DTO(oatpp::Vector<oatpp::Object<org::openapitools::server::model::User>>, user)) {
return create_users_with_array_input(request, user);
}
/// <summary>
/// Creates list of users with given input array
/// </summary>
/// <remarks>
///
/// </remarks>
/// <param name="request">HTTP Request</param>
/// <param name="user">List of user object</param>
virtual std::shared_ptr<oatpp::web::protocol::http::outgoing::Response> create_users_with_list_input(const std::shared_ptr<IncomingRequest> &request, const oatpp::Vector<oatpp::Object<org::openapitools::server::model::User>> &user) = 0;
ENDPOINT("POST", "/user/createWithList", create_users_with_list_input_handler, REQUEST(std::shared_ptr<IncomingRequest>, request), BODY_DTO(oatpp::Vector<oatpp::Object<org::openapitools::server::model::User>>, user)) {
return create_users_with_list_input(request, user);
}
/// <summary>
/// Delete user
/// </summary>
/// <remarks>
/// This can only be done by the logged in user.
/// </remarks>
/// <param name="request">HTTP Request</param>
/// <param name="username">The name that needs to be deleted</param>
virtual std::shared_ptr<oatpp::web::protocol::http::outgoing::Response> delete_user(const std::shared_ptr<IncomingRequest> &request, const oatpp::String &username) = 0;
ENDPOINT("DELETE", "/user/{username}", delete_user_handler, REQUEST(std::shared_ptr<IncomingRequest>, request), PATH(oatpp::String, username)) {
return delete_user(request, username);
}
/// <summary>
/// Get user by user name
/// </summary>
/// <remarks>
///
/// </remarks>
/// <param name="request">HTTP Request</param>
/// <param name="username">The name that needs to be fetched. Use user1 for testing.</param>
virtual std::shared_ptr<oatpp::web::protocol::http::outgoing::Response> get_user_by_name(const std::shared_ptr<IncomingRequest> &request, const oatpp::String &username) = 0;
ENDPOINT("GET", "/user/{username}", get_user_by_name_handler, REQUEST(std::shared_ptr<IncomingRequest>, request), PATH(oatpp::String, username)) {
return get_user_by_name(request, username);
}
/// <summary>
/// Logs user into the system
/// </summary>
/// <remarks>
///
/// </remarks>
/// <param name="request">HTTP Request</param>
/// <param name="username">The user name for login</param>
/// <param name="password">The password for login in clear text</param>
virtual std::shared_ptr<oatpp::web::protocol::http::outgoing::Response> login_user(const std::shared_ptr<IncomingRequest> &request, const oatpp::String &username, const oatpp::String &password) = 0;
ENDPOINT("GET", "/user/login", login_user_handler, REQUEST(std::shared_ptr<IncomingRequest>, request), QUERY(oatpp::String, username), QUERY(oatpp::String, password)) {
return login_user(request, username, password);
}
/// <summary>
/// Logs out current logged in user session
/// </summary>
/// <remarks>
///
/// </remarks>
/// <param name="request">HTTP Request</param>
virtual std::shared_ptr<oatpp::web::protocol::http::outgoing::Response> logout_user(const std::shared_ptr<IncomingRequest> &request) = 0;
ENDPOINT("GET", "/user/logout", logout_user_handler, REQUEST(std::shared_ptr<IncomingRequest>, request)) {
return logout_user(request);
}
/// <summary>
/// Updated user
/// </summary>
/// <remarks>
/// This can only be done by the logged in user.
/// </remarks>
/// <param name="request">HTTP Request</param>
/// <param name="username">name that need to be deleted</param>
/// <param name="user">Updated user object</param>
virtual std::shared_ptr<oatpp::web::protocol::http::outgoing::Response> update_user(const std::shared_ptr<IncomingRequest> &request, const oatpp::String &username, const oatpp::Object<org::openapitools::server::model::User> &user) = 0;
ENDPOINT("PUT", "/user/{username}", update_user_handler, REQUEST(std::shared_ptr<IncomingRequest>, request), PATH(oatpp::String, username), BODY_DTO(oatpp::Object<org::openapitools::server::model::User>, user)) {
return update_user(request, username, user);
}
};
#include OATPP_CODEGEN_END(ApiController) ///< End ApiController codegen section
} // namespace org::openapitools::server::api
#endif /* UserApi_H_ */

View File

@ -0,0 +1,109 @@
/**
* OpenAPI Petstore
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
*
* The version of the OpenAPI document: 1.0.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
#include "PetApiController.hpp"
namespace org {
namespace openapitools {
namespace server {
namespace api {
std::shared_ptr<oatpp::web::protocol::http::outgoing::Response> PetApiController::add_pet(const std::shared_ptr<IncomingRequest> &request, const oatpp::Object<org::openapitools::server::model::Pet> &pet) {
(void)request;
(void)pet;
return createResponse(Status::CODE_501, "TODO: Implement API Handler");
}
std::shared_ptr<oatpp::web::protocol::http::outgoing::Response> PetApiController::delete_pet(const std::shared_ptr<IncomingRequest> &request, const oatpp::Int64 &petId, const oatpp::String &apiKey) {
(void)request;
(void)petId;
(void)apiKey;
return createResponse(Status::CODE_501, "TODO: Implement API Handler");
}
std::shared_ptr<oatpp::web::protocol::http::outgoing::Response> PetApiController::find_pets_by_status(const std::shared_ptr<IncomingRequest> &request, const oatpp::Vector<oatpp::String> &status) {
(void)request;
(void)status;
return createResponse(Status::CODE_501, "TODO: Implement API Handler");
}
std::shared_ptr<oatpp::web::protocol::http::outgoing::Response> PetApiController::find_pets_by_tags(const std::shared_ptr<IncomingRequest> &request, const oatpp::Vector<oatpp::String> &tags) {
(void)request;
(void)tags;
return createResponse(Status::CODE_501, "TODO: Implement API Handler");
}
std::shared_ptr<oatpp::web::protocol::http::outgoing::Response> PetApiController::get_pet_by_id(const std::shared_ptr<IncomingRequest> &request, const oatpp::Int64 &petId) {
(void)request;
(void)petId;
return createResponse(Status::CODE_501, "TODO: Implement API Handler");
}
std::shared_ptr<oatpp::web::protocol::http::outgoing::Response> PetApiController::update_pet(const std::shared_ptr<IncomingRequest> &request, const oatpp::Object<org::openapitools::server::model::Pet> &pet) {
(void)request;
(void)pet;
return createResponse(Status::CODE_501, "TODO: Implement API Handler");
}
std::shared_ptr<oatpp::web::protocol::http::outgoing::Response> PetApiController::update_pet_with_form(const std::shared_ptr<IncomingRequest> &request, const oatpp::Int64 &petId) {
(void)request;
(void)petId;
return createResponse(Status::CODE_501, "TODO: Implement API Handler");
}
std::shared_ptr<oatpp::web::protocol::http::outgoing::Response> PetApiController::upload_file(const std::shared_ptr<IncomingRequest> &request, const oatpp::Int64 &petId) {
(void)request;
(void)petId;
return createResponse(Status::CODE_501, "TODO: Implement API Handler");
}
}
}
}
}

View File

@ -0,0 +1,118 @@
/**
* OpenAPI Petstore
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
*
* The version of the OpenAPI document: 1.0.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
/*
* PetApiController.hpp
*
*
*/
#ifndef PET_API_IMPL_H_
#define PET_API_IMPL_H_
#include <PetApi.hpp>
#include "oatpp/core/Types.hpp"
#include "ApiResponse.hpp"
#include "Pet.hpp"
namespace org::openapitools::server::api
{
class PetApiController : public PetApi {
public:
/// <summary>
/// Add a new pet to the store
/// </summary>
/// <remarks>
///
/// </remarks>
/// <param name="request">HTTP Request</param>
/// <param name="pet">Pet object that needs to be added to the store</param>
virtual std::shared_ptr<oatpp::web::protocol::http::outgoing::Response> add_pet(const std::shared_ptr<IncomingRequest> &request, const oatpp::Object<org::openapitools::server::model::Pet> &pet);
/// <summary>
/// Deletes a pet
/// </summary>
/// <remarks>
///
/// </remarks>
/// <param name="request">HTTP Request</param>
/// <param name="petId">Pet id to delete</param>
/// <param name="apiKey"> (optional, default to &quot;&quot;)</param>
virtual std::shared_ptr<oatpp::web::protocol::http::outgoing::Response> delete_pet(const std::shared_ptr<IncomingRequest> &request, const oatpp::Int64 &petId, const oatpp::String &apiKey);
/// <summary>
/// Finds Pets by status
/// </summary>
/// <remarks>
/// Multiple status values can be provided with comma separated strings
/// </remarks>
/// <param name="request">HTTP Request</param>
/// <param name="status">Status values that need to be considered for filter</param>
virtual std::shared_ptr<oatpp::web::protocol::http::outgoing::Response> find_pets_by_status(const std::shared_ptr<IncomingRequest> &request, const oatpp::Vector<oatpp::String> &status);
/// <summary>
/// Finds Pets by tags
/// </summary>
/// <remarks>
/// Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
/// </remarks>
/// <param name="request">HTTP Request</param>
/// <param name="tags">Tags to filter by</param>
virtual std::shared_ptr<oatpp::web::protocol::http::outgoing::Response> find_pets_by_tags(const std::shared_ptr<IncomingRequest> &request, const oatpp::Vector<oatpp::String> &tags);
/// <summary>
/// Find pet by ID
/// </summary>
/// <remarks>
/// Returns a single pet
/// </remarks>
/// <param name="request">HTTP Request</param>
/// <param name="petId">ID of pet to return</param>
virtual std::shared_ptr<oatpp::web::protocol::http::outgoing::Response> get_pet_by_id(const std::shared_ptr<IncomingRequest> &request, const oatpp::Int64 &petId);
/// <summary>
/// Update an existing pet
/// </summary>
/// <remarks>
///
/// </remarks>
/// <param name="request">HTTP Request</param>
/// <param name="pet">Pet object that needs to be added to the store</param>
virtual std::shared_ptr<oatpp::web::protocol::http::outgoing::Response> update_pet(const std::shared_ptr<IncomingRequest> &request, const oatpp::Object<org::openapitools::server::model::Pet> &pet);
/// <summary>
/// Updates a pet in the store with form data
/// </summary>
/// <remarks>
///
/// </remarks>
/// <param name="request">HTTP Request</param>
/// <param name="petId">ID of pet that needs to be updated</param>
virtual std::shared_ptr<oatpp::web::protocol::http::outgoing::Response> update_pet_with_form(const std::shared_ptr<IncomingRequest> &request, const oatpp::Int64 &petId);
/// <summary>
/// uploads an image
/// </summary>
/// <remarks>
///
/// </remarks>
/// <param name="request">HTTP Request</param>
/// <param name="petId">ID of pet to update</param>
virtual std::shared_ptr<oatpp::web::protocol::http::outgoing::Response> upload_file(const std::shared_ptr<IncomingRequest> &request, const oatpp::Int64 &petId);
};
} // namespace org::openapitools::server::api
#endif

View File

@ -0,0 +1,53 @@
/**
* OpenAPI Petstore
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
*
* The version of the OpenAPI document: 1.0.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
#include "StoreApiController.hpp"
namespace org {
namespace openapitools {
namespace server {
namespace api {
std::shared_ptr<oatpp::web::protocol::http::outgoing::Response> StoreApiController::delete_order(const std::shared_ptr<IncomingRequest> &request, const oatpp::String &orderId) {
(void)request;
(void)orderId;
return createResponse(Status::CODE_501, "TODO: Implement API Handler");
}
std::shared_ptr<oatpp::web::protocol::http::outgoing::Response> StoreApiController::get_inventory(const std::shared_ptr<IncomingRequest> &request) {
(void)request;
return createResponse(Status::CODE_501, "TODO: Implement API Handler");
}
std::shared_ptr<oatpp::web::protocol::http::outgoing::Response> StoreApiController::get_order_by_id(const std::shared_ptr<IncomingRequest> &request, const oatpp::Int64 &orderId) {
(void)request;
(void)orderId;
return createResponse(Status::CODE_501, "TODO: Implement API Handler");
}
std::shared_ptr<oatpp::web::protocol::http::outgoing::Response> StoreApiController::place_order(const std::shared_ptr<IncomingRequest> &request, const oatpp::Object<org::openapitools::server::model::Order> &order) {
(void)request;
(void)order;
return createResponse(Status::CODE_501, "TODO: Implement API Handler");
}
}
}
}
}

View File

@ -0,0 +1,75 @@
/**
* OpenAPI Petstore
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
*
* The version of the OpenAPI document: 1.0.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
/*
* StoreApiController.hpp
*
*
*/
#ifndef STORE_API_IMPL_H_
#define STORE_API_IMPL_H_
#include <StoreApi.hpp>
#include "oatpp/core/Types.hpp"
#include "Order.hpp"
namespace org::openapitools::server::api
{
class StoreApiController : public StoreApi {
public:
/// <summary>
/// Delete purchase order by ID
/// </summary>
/// <remarks>
/// For valid response try integer IDs with value &lt; 1000. Anything above 1000 or nonintegers will generate API errors
/// </remarks>
/// <param name="request">HTTP Request</param>
/// <param name="orderId">ID of the order that needs to be deleted</param>
virtual std::shared_ptr<oatpp::web::protocol::http::outgoing::Response> delete_order(const std::shared_ptr<IncomingRequest> &request, const oatpp::String &orderId);
/// <summary>
/// Returns pet inventories by status
/// </summary>
/// <remarks>
/// Returns a map of status codes to quantities
/// </remarks>
/// <param name="request">HTTP Request</param>
virtual std::shared_ptr<oatpp::web::protocol::http::outgoing::Response> get_inventory(const std::shared_ptr<IncomingRequest> &request);
/// <summary>
/// Find purchase order by ID
/// </summary>
/// <remarks>
/// For valid response try integer IDs with value &lt;&#x3D; 5 or &gt; 10. Other values will generate exceptions
/// </remarks>
/// <param name="request">HTTP Request</param>
/// <param name="orderId">ID of pet that needs to be fetched</param>
virtual std::shared_ptr<oatpp::web::protocol::http::outgoing::Response> get_order_by_id(const std::shared_ptr<IncomingRequest> &request, const oatpp::Int64 &orderId);
/// <summary>
/// Place an order for a pet
/// </summary>
/// <remarks>
///
/// </remarks>
/// <param name="request">HTTP Request</param>
/// <param name="order">order placed for purchasing the pet</param>
virtual std::shared_ptr<oatpp::web::protocol::http::outgoing::Response> place_order(const std::shared_ptr<IncomingRequest> &request, const oatpp::Object<org::openapitools::server::model::Order> &order);
};
} // namespace org::openapitools::server::api
#endif

View File

@ -0,0 +1,93 @@
/**
* OpenAPI Petstore
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
*
* The version of the OpenAPI document: 1.0.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
#include "UserApiController.hpp"
namespace org {
namespace openapitools {
namespace server {
namespace api {
std::shared_ptr<oatpp::web::protocol::http::outgoing::Response> UserApiController::create_user(const std::shared_ptr<IncomingRequest> &request, const oatpp::Object<org::openapitools::server::model::User> &user) {
(void)request;
(void)user;
return createResponse(Status::CODE_501, "TODO: Implement API Handler");
}
std::shared_ptr<oatpp::web::protocol::http::outgoing::Response> UserApiController::create_users_with_array_input(const std::shared_ptr<IncomingRequest> &request, const oatpp::Vector<oatpp::Object<org::openapitools::server::model::User>> &user) {
(void)request;
(void)user;
return createResponse(Status::CODE_501, "TODO: Implement API Handler");
}
std::shared_ptr<oatpp::web::protocol::http::outgoing::Response> UserApiController::create_users_with_list_input(const std::shared_ptr<IncomingRequest> &request, const oatpp::Vector<oatpp::Object<org::openapitools::server::model::User>> &user) {
(void)request;
(void)user;
return createResponse(Status::CODE_501, "TODO: Implement API Handler");
}
std::shared_ptr<oatpp::web::protocol::http::outgoing::Response> UserApiController::delete_user(const std::shared_ptr<IncomingRequest> &request, const oatpp::String &username) {
(void)request;
(void)username;
return createResponse(Status::CODE_501, "TODO: Implement API Handler");
}
std::shared_ptr<oatpp::web::protocol::http::outgoing::Response> UserApiController::get_user_by_name(const std::shared_ptr<IncomingRequest> &request, const oatpp::String &username) {
(void)request;
(void)username;
return createResponse(Status::CODE_501, "TODO: Implement API Handler");
}
std::shared_ptr<oatpp::web::protocol::http::outgoing::Response> UserApiController::login_user(const std::shared_ptr<IncomingRequest> &request, const oatpp::String &username, const oatpp::String &password) {
(void)request;
(void)username;
(void)password;
return createResponse(Status::CODE_501, "TODO: Implement API Handler");
}
std::shared_ptr<oatpp::web::protocol::http::outgoing::Response> UserApiController::logout_user(const std::shared_ptr<IncomingRequest> &request) {
(void)request;
return createResponse(Status::CODE_501, "TODO: Implement API Handler");
}
std::shared_ptr<oatpp::web::protocol::http::outgoing::Response> UserApiController::update_user(const std::shared_ptr<IncomingRequest> &request, const oatpp::String &username, const oatpp::Object<org::openapitools::server::model::User> &user) {
(void)request;
(void)username;
(void)user;
return createResponse(Status::CODE_501, "TODO: Implement API Handler");
}
}
}
}
}

View File

@ -0,0 +1,113 @@
/**
* OpenAPI Petstore
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
*
* The version of the OpenAPI document: 1.0.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
/*
* UserApiController.hpp
*
*
*/
#ifndef USER_API_IMPL_H_
#define USER_API_IMPL_H_
#include <UserApi.hpp>
#include "oatpp/core/Types.hpp"
#include "User.hpp"
namespace org::openapitools::server::api
{
class UserApiController : public UserApi {
public:
/// <summary>
/// Create user
/// </summary>
/// <remarks>
/// This can only be done by the logged in user.
/// </remarks>
/// <param name="request">HTTP Request</param>
/// <param name="user">Created user object</param>
virtual std::shared_ptr<oatpp::web::protocol::http::outgoing::Response> create_user(const std::shared_ptr<IncomingRequest> &request, const oatpp::Object<org::openapitools::server::model::User> &user);
/// <summary>
/// Creates list of users with given input array
/// </summary>
/// <remarks>
///
/// </remarks>
/// <param name="request">HTTP Request</param>
/// <param name="user">List of user object</param>
virtual std::shared_ptr<oatpp::web::protocol::http::outgoing::Response> create_users_with_array_input(const std::shared_ptr<IncomingRequest> &request, const oatpp::Vector<oatpp::Object<org::openapitools::server::model::User>> &user);
/// <summary>
/// Creates list of users with given input array
/// </summary>
/// <remarks>
///
/// </remarks>
/// <param name="request">HTTP Request</param>
/// <param name="user">List of user object</param>
virtual std::shared_ptr<oatpp::web::protocol::http::outgoing::Response> create_users_with_list_input(const std::shared_ptr<IncomingRequest> &request, const oatpp::Vector<oatpp::Object<org::openapitools::server::model::User>> &user);
/// <summary>
/// Delete user
/// </summary>
/// <remarks>
/// This can only be done by the logged in user.
/// </remarks>
/// <param name="request">HTTP Request</param>
/// <param name="username">The name that needs to be deleted</param>
virtual std::shared_ptr<oatpp::web::protocol::http::outgoing::Response> delete_user(const std::shared_ptr<IncomingRequest> &request, const oatpp::String &username);
/// <summary>
/// Get user by user name
/// </summary>
/// <remarks>
///
/// </remarks>
/// <param name="request">HTTP Request</param>
/// <param name="username">The name that needs to be fetched. Use user1 for testing.</param>
virtual std::shared_ptr<oatpp::web::protocol::http::outgoing::Response> get_user_by_name(const std::shared_ptr<IncomingRequest> &request, const oatpp::String &username);
/// <summary>
/// Logs user into the system
/// </summary>
/// <remarks>
///
/// </remarks>
/// <param name="request">HTTP Request</param>
/// <param name="username">The user name for login</param>
/// <param name="password">The password for login in clear text</param>
virtual std::shared_ptr<oatpp::web::protocol::http::outgoing::Response> login_user(const std::shared_ptr<IncomingRequest> &request, const oatpp::String &username, const oatpp::String &password);
/// <summary>
/// Logs out current logged in user session
/// </summary>
/// <remarks>
///
/// </remarks>
/// <param name="request">HTTP Request</param>
virtual std::shared_ptr<oatpp::web::protocol::http::outgoing::Response> logout_user(const std::shared_ptr<IncomingRequest> &request);
/// <summary>
/// Updated user
/// </summary>
/// <remarks>
/// This can only be done by the logged in user.
/// </remarks>
/// <param name="request">HTTP Request</param>
/// <param name="username">name that need to be deleted</param>
/// <param name="user">Updated user object</param>
virtual std::shared_ptr<oatpp::web::protocol::http::outgoing::Response> update_user(const std::shared_ptr<IncomingRequest> &request, const oatpp::String &username, const oatpp::Object<org::openapitools::server::model::User> &user);
};
} // namespace org::openapitools::server::api
#endif

View File

@ -0,0 +1,115 @@
/**
* OpenAPI Petstore
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
*
* The version of the OpenAPI document: 1.0.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
#include "oatpp/web/server/HttpConnectionHandler.hpp"
#include "oatpp/network/Server.hpp"
#include "oatpp/network/tcp/server/ConnectionProvider.hpp"
#include "oatpp/parser/json/mapping/ObjectMapper.hpp"
#include "oatpp/parser/json/Utils.hpp"
#include "PetApiController.hpp"
#include "StoreApiController.hpp"
#include "UserApiController.hpp"
/**
* Class which creates and holds Application components and registers components in oatpp::base::Environment
* Order of components initialization is from top to bottom
*/
class AppComponent {
public:
/**
* Create ConnectionProvider component which listens on the port
*/
OATPP_CREATE_COMPONENT(std::shared_ptr<oatpp::network::ServerConnectionProvider>, serverConnectionProvider)([] {
return oatpp::network::tcp::server::ConnectionProvider::createShared({"localhost", 8080, oatpp::network::Address::IP_4});
}());
/**
* Create Router component
*/
OATPP_CREATE_COMPONENT(std::shared_ptr<oatpp::web::server::HttpRouter>, httpRouter)([] {
return oatpp::web::server::HttpRouter::createShared();
}());
/**
* Create ConnectionHandler component which uses Router component to route requests
*/
OATPP_CREATE_COMPONENT(std::shared_ptr<oatpp::network::ConnectionHandler>, serverConnectionHandler)([] {
OATPP_COMPONENT(std::shared_ptr<oatpp::web::server::HttpRouter>, router); // get Router component
return oatpp::web::server::HttpConnectionHandler::createShared(router);
}());
/**
* Create ObjectMapper component to serialize/deserialize DTOs in Contoller's API
*/
OATPP_CREATE_COMPONENT(std::shared_ptr<oatpp::data::mapping::ObjectMapper>, apiObjectMapper)([] {
return oatpp::parser::json::mapping::ObjectMapper::createShared();
}());
};
static int _main_app(void) {
/* Register Components in scope of run() method */
AppComponent components;
/* Get router component */
OATPP_COMPONENT(std::shared_ptr<oatpp::web::server::HttpRouter>, router);
/* Create PetApiController and add all of its endpoints to router */
auto PetApiController = std::make_shared<org::openapitools::server::api::PetApiController>();
router->addController(PetApiController);
/* Create StoreApiController and add all of its endpoints to router */
auto StoreApiController = std::make_shared<org::openapitools::server::api::StoreApiController>();
router->addController(StoreApiController);
/* Create UserApiController and add all of its endpoints to router */
auto UserApiController = std::make_shared<org::openapitools::server::api::UserApiController>();
router->addController(UserApiController);
/* Get connection handler component */
OATPP_COMPONENT(std::shared_ptr<oatpp::network::ConnectionHandler>, connectionHandler);
/* Get connection provider component */
OATPP_COMPONENT(std::shared_ptr<oatpp::network::ServerConnectionProvider>, connectionProvider);
/* Create server which takes provided TCP connections and passes them to HTTP connection handler */
oatpp::network::Server server(connectionProvider, connectionHandler);
/* Print info about server port */
OATPP_LOGI("MyApp", "Server running on port %s", connectionProvider->getProperty("port").getData());
/* Run server */
server.run();
return 0;
}
int main(int argc, char **argv) {
/* Init oatpp Environment */
oatpp::base::Environment::init();
int ret = _main_app();
/* Destroy oatpp Environment */
oatpp::base::Environment::destroy();
return ret;
}

View File

@ -0,0 +1,54 @@
/**
* OpenAPI Petstore
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
*
* The version of the OpenAPI document: 1.0.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
/*
* ApiResponse.h
*
* Describes the result of uploading an image resource
*/
#ifndef ApiResponse_H_
#define ApiResponse_H_
#include "oatpp/core/macro/codegen.hpp"
#include "oatpp/core/Types.hpp"
namespace org::openapitools::server::model
{
/* Begin DTO code-generation */
#include OATPP_CODEGEN_BEGIN(DTO)
/**
* Message Data-Transfer-Object
*/
class ApiResponse : public oatpp::DTO {
DTO_INIT(ApiResponse, DTO /* Extends */)
DTO_FIELD(oatpp::Int32, Code);
DTO_FIELD(oatpp::Boolean, CodeIsSet);
DTO_FIELD(oatpp::String, Type);
DTO_FIELD(oatpp::Boolean, TypeIsSet);
DTO_FIELD(oatpp::String, Message);
DTO_FIELD(oatpp::Boolean, MessageIsSet);
};
/* End DTO code-generation */
#include OATPP_CODEGEN_END(DTO)
} // namespace org::openapitools::server::model
#endif /* ApiResponse_H_ */

View File

@ -0,0 +1,52 @@
/**
* OpenAPI Petstore
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
*
* The version of the OpenAPI document: 1.0.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
/*
* Category.h
*
* A category for a pet
*/
#ifndef Category_H_
#define Category_H_
#include "oatpp/core/macro/codegen.hpp"
#include "oatpp/core/Types.hpp"
namespace org::openapitools::server::model
{
/* Begin DTO code-generation */
#include OATPP_CODEGEN_BEGIN(DTO)
/**
* Message Data-Transfer-Object
*/
class Category : public oatpp::DTO {
DTO_INIT(Category, DTO /* Extends */)
DTO_FIELD(oatpp::Int64, Id);
DTO_FIELD(oatpp::Boolean, IdIsSet);
DTO_FIELD(oatpp::String, Name);
DTO_FIELD(oatpp::Boolean, NameIsSet);
};
/* End DTO code-generation */
#include OATPP_CODEGEN_END(DTO)
} // namespace org::openapitools::server::model
#endif /* Category_H_ */

View File

@ -0,0 +1,60 @@
/**
* OpenAPI Petstore
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
*
* The version of the OpenAPI document: 1.0.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
/*
* Order.h
*
* An order for a pets from the pet store
*/
#ifndef Order_H_
#define Order_H_
#include "oatpp/core/macro/codegen.hpp"
#include "oatpp/core/Types.hpp"
namespace org::openapitools::server::model
{
/* Begin DTO code-generation */
#include OATPP_CODEGEN_BEGIN(DTO)
/**
* Message Data-Transfer-Object
*/
class Order : public oatpp::DTO {
DTO_INIT(Order, DTO /* Extends */)
DTO_FIELD(oatpp::Int64, Id);
DTO_FIELD(oatpp::Boolean, IdIsSet);
DTO_FIELD(oatpp::Int64, PetId);
DTO_FIELD(oatpp::Boolean, PetIdIsSet);
DTO_FIELD(oatpp::Int32, Quantity);
DTO_FIELD(oatpp::Boolean, QuantityIsSet);
DTO_FIELD(oatpp::String, ShipDate);
DTO_FIELD(oatpp::Boolean, ShipDateIsSet);
DTO_FIELD(oatpp::String, Status);
DTO_FIELD(oatpp::Boolean, StatusIsSet);
DTO_FIELD(oatpp::Boolean, Complete);
DTO_FIELD(oatpp::Boolean, CompleteIsSet);
};
/* End DTO code-generation */
#include OATPP_CODEGEN_END(DTO)
} // namespace org::openapitools::server::model
#endif /* Order_H_ */

View File

@ -0,0 +1,62 @@
/**
* OpenAPI Petstore
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
*
* The version of the OpenAPI document: 1.0.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
/*
* Pet.h
*
* A pet for sale in the pet store
*/
#ifndef Pet_H_
#define Pet_H_
#include "Category.hpp"
#include "Tag.hpp"
#include "oatpp/core/macro/codegen.hpp"
#include "oatpp/core/Types.hpp"
namespace org::openapitools::server::model
{
/* Begin DTO code-generation */
#include OATPP_CODEGEN_BEGIN(DTO)
/**
* Message Data-Transfer-Object
*/
class Pet : public oatpp::DTO {
DTO_INIT(Pet, DTO /* Extends */)
DTO_FIELD(oatpp::Int64, Id);
DTO_FIELD(oatpp::Boolean, IdIsSet);
DTO_FIELD(oatpp::Object<org::openapitools::server::model::Category>, Category);
DTO_FIELD(oatpp::Boolean, CategoryIsSet);
DTO_FIELD(oatpp::String, Name);
DTO_FIELD(oatpp::Vector<oatpp::String>, PhotoUrls);
DTO_FIELD(oatpp::Vector<oatpp::Object<org::openapitools::server::model::Tag>>, Tags);
DTO_FIELD(oatpp::Boolean, TagsIsSet);
DTO_FIELD(oatpp::String, Status);
DTO_FIELD(oatpp::Boolean, StatusIsSet);
};
/* End DTO code-generation */
#include OATPP_CODEGEN_END(DTO)
} // namespace org::openapitools::server::model
#endif /* Pet_H_ */

View File

@ -0,0 +1,52 @@
/**
* OpenAPI Petstore
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
*
* The version of the OpenAPI document: 1.0.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
/*
* Tag.h
*
* A tag for a pet
*/
#ifndef Tag_H_
#define Tag_H_
#include "oatpp/core/macro/codegen.hpp"
#include "oatpp/core/Types.hpp"
namespace org::openapitools::server::model
{
/* Begin DTO code-generation */
#include OATPP_CODEGEN_BEGIN(DTO)
/**
* Message Data-Transfer-Object
*/
class Tag : public oatpp::DTO {
DTO_INIT(Tag, DTO /* Extends */)
DTO_FIELD(oatpp::Int64, Id);
DTO_FIELD(oatpp::Boolean, IdIsSet);
DTO_FIELD(oatpp::String, Name);
DTO_FIELD(oatpp::Boolean, NameIsSet);
};
/* End DTO code-generation */
#include OATPP_CODEGEN_END(DTO)
} // namespace org::openapitools::server::model
#endif /* Tag_H_ */

View File

@ -0,0 +1,64 @@
/**
* OpenAPI Petstore
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
*
* The version of the OpenAPI document: 1.0.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
/*
* User.h
*
* A User who is purchasing from the pet store
*/
#ifndef User_H_
#define User_H_
#include "oatpp/core/macro/codegen.hpp"
#include "oatpp/core/Types.hpp"
namespace org::openapitools::server::model
{
/* Begin DTO code-generation */
#include OATPP_CODEGEN_BEGIN(DTO)
/**
* Message Data-Transfer-Object
*/
class User : public oatpp::DTO {
DTO_INIT(User, DTO /* Extends */)
DTO_FIELD(oatpp::Int64, Id);
DTO_FIELD(oatpp::Boolean, IdIsSet);
DTO_FIELD(oatpp::String, Username);
DTO_FIELD(oatpp::Boolean, UsernameIsSet);
DTO_FIELD(oatpp::String, FirstName);
DTO_FIELD(oatpp::Boolean, FirstNameIsSet);
DTO_FIELD(oatpp::String, LastName);
DTO_FIELD(oatpp::Boolean, LastNameIsSet);
DTO_FIELD(oatpp::String, Email);
DTO_FIELD(oatpp::Boolean, EmailIsSet);
DTO_FIELD(oatpp::String, Password);
DTO_FIELD(oatpp::Boolean, PasswordIsSet);
DTO_FIELD(oatpp::String, Phone);
DTO_FIELD(oatpp::Boolean, PhoneIsSet);
DTO_FIELD(oatpp::Int32, UserStatus);
DTO_FIELD(oatpp::Boolean, UserStatusIsSet);
};
/* End DTO code-generation */
#include OATPP_CODEGEN_END(DTO)
} // namespace org::openapitools::server::model
#endif /* User_H_ */

View File

@ -87,6 +87,10 @@
"title": "Config Options for clojure",
"sidebar_label": "clojure"
},
"generators/cpp-oatpp-server": {
"title": "Config Options for cpp-oatpp-server",
"sidebar_label": "cpp-oatpp-server"
},
"generators/cpp-pistache-server": {
"title": "Config Options for cpp-pistache-server",
"sidebar_label": "cpp-pistache-server"