diff --git a/.github/workflows/samples-cpp-oatpp-server.yaml b/.github/workflows/samples-cpp-oatpp-server.yaml new file mode 100644 index 00000000000..12ad210e587 --- /dev/null +++ b/.github/workflows/samples-cpp-oatpp-server.yaml @@ -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 diff --git a/README.md b/README.md index 5fdc6b19f1a..724760d8a07 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/bin/configs/cpp-oatpp-server-cpp-oatpp.yaml b/bin/configs/cpp-oatpp-server-cpp-oatpp.yaml new file mode 100644 index 00000000000..cc328b503fd --- /dev/null +++ b/bin/configs/cpp-oatpp-server-cpp-oatpp.yaml @@ -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" diff --git a/docs/generators.md b/docs/generators.md index 4c968c0f87a..753014a50b9 100644 --- a/docs/generators.md +++ b/docs/generators.md @@ -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) diff --git a/docs/generators/README.md b/docs/generators/README.md index c9c48556912..d61f00351d5 100644 --- a/docs/generators/README.md +++ b/docs/generators/README.md @@ -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) diff --git a/docs/generators/cpp-oatpp-server.md b/docs/generators/cpp-oatpp-server.md new file mode 100644 index 00000000000..72bb7de1fc1 --- /dev/null +++ b/docs/generators/cpp-oatpp-server.md @@ -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 + + + +## RESERVED WORDS + + + +## 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 diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppOatppServerCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppOatppServerCodegen.java new file mode 100644 index 00000000000..548cb503ae4 --- /dev/null +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppOatppServerCodegen.java @@ -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 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 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 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 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> 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 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) + ">"; + } + if (ModelUtils.isMapSchema(p)) { + Schema inner = ModelUtils.getAdditionalProperties(p); + return getSchemaType(p) + ""; + } 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()"; + } 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; + } +} diff --git a/modules/openapi-generator/src/main/resources/META-INF/services/org.openapitools.codegen.CodegenConfig b/modules/openapi-generator/src/main/resources/META-INF/services/org.openapitools.codegen.CodegenConfig index 80c9c105b64..92e428f0b85 100644 --- a/modules/openapi-generator/src/main/resources/META-INF/services/org.openapitools.codegen.CodegenConfig +++ b/modules/openapi-generator/src/main/resources/META-INF/services/org.openapitools.codegen.CodegenConfig @@ -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 diff --git a/modules/openapi-generator/src/main/resources/cpp-oatpp-server/README.mustache b/modules/openapi-generator/src/main/resources/cpp-oatpp-server/README.mustache new file mode 100644 index 00000000000..04b92947a48 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/cpp-oatpp-server/README.mustache @@ -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}}} diff --git a/modules/openapi-generator/src/main/resources/cpp-oatpp-server/api-header.mustache b/modules/openapi-generator/src/main/resources/cpp-oatpp-server/api-header.mustache new file mode 100644 index 00000000000..d5d4fcfd613 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/cpp-oatpp-server/api-header.mustache @@ -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) /* Inject object mapper */) + : oatpp::web::server::api::ApiController(objectMapper) + {} + + {{#operation}} + /// + /// {{summary}} + /// + /// + /// {{notes}} + /// + /// HTTP Request + {{#allParams}} + {{#isPathParam}}/// {{description}}{{^required}} (optional{{#defaultValue}}, default to {{.}}{{/defaultValue}}){{/required}}{{/isPathParam}}{{#isQueryParam}}/// {{description}}{{^required}} (optional{{#defaultValue}}, default to {{.}}{{/defaultValue}}){{/required}}{{/isQueryParam}}{{#isBodyParam}}/// {{description}}{{^required}} (optional{{#defaultValue}}, default to {{.}}{{/defaultValue}}){{/required}}{{/isBodyParam}}{{#isHeaderParam}}/// {{description}}{{^required}} (optional{{#defaultValue}}, default to {{.}}{{/defaultValue}}){{/required}}{{/isHeaderParam}} + {{/allParams}} + virtual std::shared_ptr {{operationIdSnakeCase}}(const std::shared_ptr &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, 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}} diff --git a/modules/openapi-generator/src/main/resources/cpp-oatpp-server/api-impl-header.mustache b/modules/openapi-generator/src/main/resources/cpp-oatpp-server/api-impl-header.mustache new file mode 100644 index 00000000000..6fecca42bc4 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/cpp-oatpp-server/api-impl-header.mustache @@ -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}} + /// + /// + /// {{notes}} + /// + /// HTTP Request + {{#allParams}} + {{#isPathParam}}/// {{description}}{{^required}} (optional{{#defaultValue}}, default to {{.}}{{/defaultValue}}){{/required}}{{/isPathParam}}{{#isQueryParam}}/// {{description}}{{^required}} (optional{{#defaultValue}}, default to {{.}}{{/defaultValue}}){{/required}}{{/isQueryParam}}{{#isBodyParam}}/// {{description}}{{^required}} (optional{{#defaultValue}}, default to {{.}}{{/defaultValue}}){{/required}}{{/isBodyParam}}{{#isHeaderParam}}/// {{description}}{{^required}} (optional{{#defaultValue}}, default to {{.}}{{/defaultValue}}){{/required}}{{/isHeaderParam}} + {{/allParams}} + virtual std::shared_ptr {{operationIdSnakeCase}}(const std::shared_ptr &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 diff --git a/modules/openapi-generator/src/main/resources/cpp-oatpp-server/api-impl-source.mustache b/modules/openapi-generator/src/main/resources/cpp-oatpp-server/api-impl-source.mustache new file mode 100644 index 00000000000..6a3196abbfd --- /dev/null +++ b/modules/openapi-generator/src/main/resources/cpp-oatpp-server/api-impl-source.mustache @@ -0,0 +1,27 @@ +{{>licenseInfo}} +{{#operations}} + +#include "{{classname}}Controller.hpp" + +{{#apiNamespaceDeclarations}} +namespace {{this}} { +{{/apiNamespaceDeclarations}} + +{{#operation}} +std::shared_ptr {{classname}}Controller::{{operationIdSnakeCase}}(const std::shared_ptr &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}} diff --git a/modules/openapi-generator/src/main/resources/cpp-oatpp-server/cmake.mustache b/modules/openapi-generator/src/main/resources/cpp-oatpp-server/cmake.mustache new file mode 100644 index 00000000000..3c66faa118e --- /dev/null +++ b/modules/openapi-generator/src/main/resources/cpp-oatpp-server/cmake.mustache @@ -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}} diff --git a/modules/openapi-generator/src/main/resources/cpp-oatpp-server/licenseInfo.mustache b/modules/openapi-generator/src/main/resources/cpp-oatpp-server/licenseInfo.mustache new file mode 100644 index 00000000000..8d5259173a1 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/cpp-oatpp-server/licenseInfo.mustache @@ -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. +*/ \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/cpp-oatpp-server/main-api-server.mustache b/modules/openapi-generator/src/main/resources/cpp-oatpp-server/main-api-server.mustache new file mode 100644 index 00000000000..6ee93b4dd41 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/cpp-oatpp-server/main-api-server.mustache @@ -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, 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, httpRouter)([] { + return oatpp::web::server::HttpRouter::createShared(); + }()); + + /** + * Create ConnectionHandler component which uses Router component to route requests + */ + OATPP_CREATE_COMPONENT(std::shared_ptr, serverConnectionHandler)([] { + OATPP_COMPONENT(std::shared_ptr, 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, 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, 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, connectionHandler); + + /* Get connection provider component */ + OATPP_COMPONENT(std::shared_ptr, 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; +} diff --git a/modules/openapi-generator/src/main/resources/cpp-oatpp-server/model-header.mustache b/modules/openapi-generator/src/main/resources/cpp-oatpp-server/model-header.mustache new file mode 100644 index 00000000000..9c1126ac878 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/cpp-oatpp-server/model-header.mustache @@ -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}} diff --git a/samples/server/petstore/cpp-oatpp/.openapi-generator-ignore b/samples/server/petstore/cpp-oatpp/.openapi-generator-ignore new file mode 100644 index 00000000000..7484ee590a3 --- /dev/null +++ b/samples/server/petstore/cpp-oatpp/.openapi-generator-ignore @@ -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 diff --git a/samples/server/petstore/cpp-oatpp/.openapi-generator/FILES b/samples/server/petstore/cpp-oatpp/.openapi-generator/FILES new file mode 100644 index 00000000000..3a57695f6e1 --- /dev/null +++ b/samples/server/petstore/cpp-oatpp/.openapi-generator/FILES @@ -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 diff --git a/samples/server/petstore/cpp-oatpp/.openapi-generator/VERSION b/samples/server/petstore/cpp-oatpp/.openapi-generator/VERSION new file mode 100644 index 00000000000..fc74d6ceba8 --- /dev/null +++ b/samples/server/petstore/cpp-oatpp/.openapi-generator/VERSION @@ -0,0 +1 @@ +7.15.0-SNAPSHOT diff --git a/samples/server/petstore/cpp-oatpp/CMakeLists.txt b/samples/server/petstore/cpp-oatpp/CMakeLists.txt new file mode 100644 index 00000000000..292f613abaf --- /dev/null +++ b/samples/server/petstore/cpp-oatpp/CMakeLists.txt @@ -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) diff --git a/samples/server/petstore/cpp-oatpp/README.md b/samples/server/petstore/cpp-oatpp/README.md new file mode 100644 index 00000000000..ad113ac214a --- /dev/null +++ b/samples/server/petstore/cpp-oatpp/README.md @@ -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 diff --git a/samples/server/petstore/cpp-oatpp/api/PetApi.hpp b/samples/server/petstore/cpp-oatpp/api/PetApi.hpp new file mode 100644 index 00000000000..578c276ebd6 --- /dev/null +++ b/samples/server/petstore/cpp-oatpp/api/PetApi.hpp @@ -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) /* Inject object mapper */) + : oatpp::web::server::api::ApiController(objectMapper) + {} + + /// + /// Add a new pet to the store + /// + /// + /// + /// + /// HTTP Request + /// Pet object that needs to be added to the store + virtual std::shared_ptr add_pet(const std::shared_ptr &request, const oatpp::Object &pet) = 0; + + ENDPOINT("POST", "/pet", add_pet_handler, REQUEST(std::shared_ptr, request), BODY_DTO(oatpp::Object, pet)) { + return add_pet(request, pet); + } + /// + /// Deletes a pet + /// + /// + /// + /// + /// HTTP Request + /// Pet id to delete + /// (optional, default to "") + virtual std::shared_ptr delete_pet(const std::shared_ptr &request, const oatpp::Int64 &petId, const oatpp::String &apiKey) = 0; + + ENDPOINT("DELETE", "/pet/{petId}", delete_pet_handler, REQUEST(std::shared_ptr, request), PATH(oatpp::Int64, petId), HEADER(oatpp::String, apiKey, "apiKey")) { + return delete_pet(request, petId, apiKey); + } + /// + /// Finds Pets by status + /// + /// + /// Multiple status values can be provided with comma separated strings + /// + /// HTTP Request + /// Status values that need to be considered for filter + virtual std::shared_ptr find_pets_by_status(const std::shared_ptr &request, const oatpp::Vector &status) = 0; + + ENDPOINT("GET", "/pet/findByStatus", find_pets_by_status_handler, REQUEST(std::shared_ptr, request), QUERY(oatpp::Vector, status)) { + return find_pets_by_status(request, status); + } + /// + /// Finds Pets by tags + /// + /// + /// Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. + /// + /// HTTP Request + /// Tags to filter by + virtual std::shared_ptr find_pets_by_tags(const std::shared_ptr &request, const oatpp::Vector &tags) = 0; + + ENDPOINT("GET", "/pet/findByTags", find_pets_by_tags_handler, REQUEST(std::shared_ptr, request), QUERY(oatpp::Vector, tags)) { + return find_pets_by_tags(request, tags); + } + /// + /// Find pet by ID + /// + /// + /// Returns a single pet + /// + /// HTTP Request + /// ID of pet to return + virtual std::shared_ptr get_pet_by_id(const std::shared_ptr &request, const oatpp::Int64 &petId) = 0; + + ENDPOINT("GET", "/pet/{petId}", get_pet_by_id_handler, REQUEST(std::shared_ptr, request), PATH(oatpp::Int64, petId)) { + return get_pet_by_id(request, petId); + } + /// + /// Update an existing pet + /// + /// + /// + /// + /// HTTP Request + /// Pet object that needs to be added to the store + virtual std::shared_ptr update_pet(const std::shared_ptr &request, const oatpp::Object &pet) = 0; + + ENDPOINT("PUT", "/pet", update_pet_handler, REQUEST(std::shared_ptr, request), BODY_DTO(oatpp::Object, pet)) { + return update_pet(request, pet); + } + /// + /// Updates a pet in the store with form data + /// + /// + /// + /// + /// HTTP Request + /// ID of pet that needs to be updated + + + virtual std::shared_ptr update_pet_with_form(const std::shared_ptr &request, const oatpp::Int64 &petId) = 0; + + ENDPOINT("POST", "/pet/{petId}", update_pet_with_form_handler, REQUEST(std::shared_ptr, request), PATH(oatpp::Int64, petId)) { + return update_pet_with_form(request, petId); + } + /// + /// uploads an image + /// + /// + /// + /// + /// HTTP Request + /// ID of pet to update + + + virtual std::shared_ptr upload_file(const std::shared_ptr &request, const oatpp::Int64 &petId) = 0; + + ENDPOINT("POST", "/pet/{petId}/uploadImage", upload_file_handler, REQUEST(std::shared_ptr, 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_ */ + diff --git a/samples/server/petstore/cpp-oatpp/api/StoreApi.hpp b/samples/server/petstore/cpp-oatpp/api/StoreApi.hpp new file mode 100644 index 00000000000..be81e623178 --- /dev/null +++ b/samples/server/petstore/cpp-oatpp/api/StoreApi.hpp @@ -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) /* Inject object mapper */) + : oatpp::web::server::api::ApiController(objectMapper) + {} + + /// + /// Delete purchase order by ID + /// + /// + /// For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors + /// + /// HTTP Request + /// ID of the order that needs to be deleted + virtual std::shared_ptr delete_order(const std::shared_ptr &request, const oatpp::String &orderId) = 0; + + ENDPOINT("DELETE", "/store/order/{orderId}", delete_order_handler, REQUEST(std::shared_ptr, request), PATH(oatpp::String, orderId)) { + return delete_order(request, orderId); + } + /// + /// Returns pet inventories by status + /// + /// + /// Returns a map of status codes to quantities + /// + /// HTTP Request + virtual std::shared_ptr get_inventory(const std::shared_ptr &request) = 0; + + ENDPOINT("GET", "/store/inventory", get_inventory_handler, REQUEST(std::shared_ptr, request)) { + return get_inventory(request); + } + /// + /// Find purchase order by ID + /// + /// + /// For valid response try integer IDs with value <= 5 or > 10. Other values will generate exceptions + /// + /// HTTP Request + /// ID of pet that needs to be fetched + virtual std::shared_ptr get_order_by_id(const std::shared_ptr &request, const oatpp::Int64 &orderId) = 0; + + ENDPOINT("GET", "/store/order/{orderId}", get_order_by_id_handler, REQUEST(std::shared_ptr, request), PATH(oatpp::Int64, orderId)) { + return get_order_by_id(request, orderId); + } + /// + /// Place an order for a pet + /// + /// + /// + /// + /// HTTP Request + /// order placed for purchasing the pet + virtual std::shared_ptr place_order(const std::shared_ptr &request, const oatpp::Object &order) = 0; + + ENDPOINT("POST", "/store/order", place_order_handler, REQUEST(std::shared_ptr, request), BODY_DTO(oatpp::Object, order)) { + return place_order(request, order); + } +}; + +#include OATPP_CODEGEN_END(ApiController) ///< End ApiController codegen section + +} // namespace org::openapitools::server::api + +#endif /* StoreApi_H_ */ + diff --git a/samples/server/petstore/cpp-oatpp/api/UserApi.hpp b/samples/server/petstore/cpp-oatpp/api/UserApi.hpp new file mode 100644 index 00000000000..891cf8be13f --- /dev/null +++ b/samples/server/petstore/cpp-oatpp/api/UserApi.hpp @@ -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) /* Inject object mapper */) + : oatpp::web::server::api::ApiController(objectMapper) + {} + + /// + /// Create user + /// + /// + /// This can only be done by the logged in user. + /// + /// HTTP Request + /// Created user object + virtual std::shared_ptr create_user(const std::shared_ptr &request, const oatpp::Object &user) = 0; + + ENDPOINT("POST", "/user", create_user_handler, REQUEST(std::shared_ptr, request), BODY_DTO(oatpp::Object, user)) { + return create_user(request, user); + } + /// + /// Creates list of users with given input array + /// + /// + /// + /// + /// HTTP Request + /// List of user object + virtual std::shared_ptr create_users_with_array_input(const std::shared_ptr &request, const oatpp::Vector> &user) = 0; + + ENDPOINT("POST", "/user/createWithArray", create_users_with_array_input_handler, REQUEST(std::shared_ptr, request), BODY_DTO(oatpp::Vector>, user)) { + return create_users_with_array_input(request, user); + } + /// + /// Creates list of users with given input array + /// + /// + /// + /// + /// HTTP Request + /// List of user object + virtual std::shared_ptr create_users_with_list_input(const std::shared_ptr &request, const oatpp::Vector> &user) = 0; + + ENDPOINT("POST", "/user/createWithList", create_users_with_list_input_handler, REQUEST(std::shared_ptr, request), BODY_DTO(oatpp::Vector>, user)) { + return create_users_with_list_input(request, user); + } + /// + /// Delete user + /// + /// + /// This can only be done by the logged in user. + /// + /// HTTP Request + /// The name that needs to be deleted + virtual std::shared_ptr delete_user(const std::shared_ptr &request, const oatpp::String &username) = 0; + + ENDPOINT("DELETE", "/user/{username}", delete_user_handler, REQUEST(std::shared_ptr, request), PATH(oatpp::String, username)) { + return delete_user(request, username); + } + /// + /// Get user by user name + /// + /// + /// + /// + /// HTTP Request + /// The name that needs to be fetched. Use user1 for testing. + virtual std::shared_ptr get_user_by_name(const std::shared_ptr &request, const oatpp::String &username) = 0; + + ENDPOINT("GET", "/user/{username}", get_user_by_name_handler, REQUEST(std::shared_ptr, request), PATH(oatpp::String, username)) { + return get_user_by_name(request, username); + } + /// + /// Logs user into the system + /// + /// + /// + /// + /// HTTP Request + /// The user name for login + /// The password for login in clear text + virtual std::shared_ptr login_user(const std::shared_ptr &request, const oatpp::String &username, const oatpp::String &password) = 0; + + ENDPOINT("GET", "/user/login", login_user_handler, REQUEST(std::shared_ptr, request), QUERY(oatpp::String, username), QUERY(oatpp::String, password)) { + return login_user(request, username, password); + } + /// + /// Logs out current logged in user session + /// + /// + /// + /// + /// HTTP Request + virtual std::shared_ptr logout_user(const std::shared_ptr &request) = 0; + + ENDPOINT("GET", "/user/logout", logout_user_handler, REQUEST(std::shared_ptr, request)) { + return logout_user(request); + } + /// + /// Updated user + /// + /// + /// This can only be done by the logged in user. + /// + /// HTTP Request + /// name that need to be deleted + /// Updated user object + virtual std::shared_ptr update_user(const std::shared_ptr &request, const oatpp::String &username, const oatpp::Object &user) = 0; + + ENDPOINT("PUT", "/user/{username}", update_user_handler, REQUEST(std::shared_ptr, request), PATH(oatpp::String, username), BODY_DTO(oatpp::Object, user)) { + return update_user(request, username, user); + } +}; + +#include OATPP_CODEGEN_END(ApiController) ///< End ApiController codegen section + +} // namespace org::openapitools::server::api + +#endif /* UserApi_H_ */ + diff --git a/samples/server/petstore/cpp-oatpp/impl/PetApiController.cpp b/samples/server/petstore/cpp-oatpp/impl/PetApiController.cpp new file mode 100644 index 00000000000..0a5ee99111a --- /dev/null +++ b/samples/server/petstore/cpp-oatpp/impl/PetApiController.cpp @@ -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 PetApiController::add_pet(const std::shared_ptr &request, const oatpp::Object &pet) { + (void)request; + + + (void)pet; + + return createResponse(Status::CODE_501, "TODO: Implement API Handler"); +} +std::shared_ptr PetApiController::delete_pet(const std::shared_ptr &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 PetApiController::find_pets_by_status(const std::shared_ptr &request, const oatpp::Vector &status) { + (void)request; + + (void)status; + + + return createResponse(Status::CODE_501, "TODO: Implement API Handler"); +} +std::shared_ptr PetApiController::find_pets_by_tags(const std::shared_ptr &request, const oatpp::Vector &tags) { + (void)request; + + (void)tags; + + + return createResponse(Status::CODE_501, "TODO: Implement API Handler"); +} +std::shared_ptr PetApiController::get_pet_by_id(const std::shared_ptr &request, const oatpp::Int64 &petId) { + (void)request; + (void)petId; + + + + return createResponse(Status::CODE_501, "TODO: Implement API Handler"); +} +std::shared_ptr PetApiController::update_pet(const std::shared_ptr &request, const oatpp::Object &pet) { + (void)request; + + + (void)pet; + + return createResponse(Status::CODE_501, "TODO: Implement API Handler"); +} +std::shared_ptr PetApiController::update_pet_with_form(const std::shared_ptr &request, const oatpp::Int64 &petId) { + (void)request; + (void)petId; + + + + + + + + + + + + return createResponse(Status::CODE_501, "TODO: Implement API Handler"); +} +std::shared_ptr PetApiController::upload_file(const std::shared_ptr &request, const oatpp::Int64 &petId) { + (void)request; + (void)petId; + + + + + + + + + + + + return createResponse(Status::CODE_501, "TODO: Implement API Handler"); +} + +} +} +} +} + diff --git a/samples/server/petstore/cpp-oatpp/impl/PetApiController.hpp b/samples/server/petstore/cpp-oatpp/impl/PetApiController.hpp new file mode 100644 index 00000000000..3cce77da90e --- /dev/null +++ b/samples/server/petstore/cpp-oatpp/impl/PetApiController.hpp @@ -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 +#include "oatpp/core/Types.hpp" + + +#include "ApiResponse.hpp" +#include "Pet.hpp" + +namespace org::openapitools::server::api +{ + +class PetApiController : public PetApi { +public: + /// + /// Add a new pet to the store + /// + /// + /// + /// + /// HTTP Request + /// Pet object that needs to be added to the store + virtual std::shared_ptr add_pet(const std::shared_ptr &request, const oatpp::Object &pet); + /// + /// Deletes a pet + /// + /// + /// + /// + /// HTTP Request + /// Pet id to delete + /// (optional, default to "") + virtual std::shared_ptr delete_pet(const std::shared_ptr &request, const oatpp::Int64 &petId, const oatpp::String &apiKey); + /// + /// Finds Pets by status + /// + /// + /// Multiple status values can be provided with comma separated strings + /// + /// HTTP Request + /// Status values that need to be considered for filter + virtual std::shared_ptr find_pets_by_status(const std::shared_ptr &request, const oatpp::Vector &status); + /// + /// Finds Pets by tags + /// + /// + /// Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. + /// + /// HTTP Request + /// Tags to filter by + virtual std::shared_ptr find_pets_by_tags(const std::shared_ptr &request, const oatpp::Vector &tags); + /// + /// Find pet by ID + /// + /// + /// Returns a single pet + /// + /// HTTP Request + /// ID of pet to return + virtual std::shared_ptr get_pet_by_id(const std::shared_ptr &request, const oatpp::Int64 &petId); + /// + /// Update an existing pet + /// + /// + /// + /// + /// HTTP Request + /// Pet object that needs to be added to the store + virtual std::shared_ptr update_pet(const std::shared_ptr &request, const oatpp::Object &pet); + /// + /// Updates a pet in the store with form data + /// + /// + /// + /// + /// HTTP Request + /// ID of pet that needs to be updated + + + virtual std::shared_ptr update_pet_with_form(const std::shared_ptr &request, const oatpp::Int64 &petId); + /// + /// uploads an image + /// + /// + /// + /// + /// HTTP Request + /// ID of pet to update + + + virtual std::shared_ptr upload_file(const std::shared_ptr &request, const oatpp::Int64 &petId); +}; + +} // namespace org::openapitools::server::api + + + +#endif diff --git a/samples/server/petstore/cpp-oatpp/impl/StoreApiController.cpp b/samples/server/petstore/cpp-oatpp/impl/StoreApiController.cpp new file mode 100644 index 00000000000..e381dcc4033 --- /dev/null +++ b/samples/server/petstore/cpp-oatpp/impl/StoreApiController.cpp @@ -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 StoreApiController::delete_order(const std::shared_ptr &request, const oatpp::String &orderId) { + (void)request; + (void)orderId; + + + + return createResponse(Status::CODE_501, "TODO: Implement API Handler"); +} +std::shared_ptr StoreApiController::get_inventory(const std::shared_ptr &request) { + (void)request; + return createResponse(Status::CODE_501, "TODO: Implement API Handler"); +} +std::shared_ptr StoreApiController::get_order_by_id(const std::shared_ptr &request, const oatpp::Int64 &orderId) { + (void)request; + (void)orderId; + + + + return createResponse(Status::CODE_501, "TODO: Implement API Handler"); +} +std::shared_ptr StoreApiController::place_order(const std::shared_ptr &request, const oatpp::Object &order) { + (void)request; + + + (void)order; + + return createResponse(Status::CODE_501, "TODO: Implement API Handler"); +} + +} +} +} +} + diff --git a/samples/server/petstore/cpp-oatpp/impl/StoreApiController.hpp b/samples/server/petstore/cpp-oatpp/impl/StoreApiController.hpp new file mode 100644 index 00000000000..78bb35296a4 --- /dev/null +++ b/samples/server/petstore/cpp-oatpp/impl/StoreApiController.hpp @@ -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 +#include "oatpp/core/Types.hpp" + + +#include "Order.hpp" + +namespace org::openapitools::server::api +{ + +class StoreApiController : public StoreApi { +public: + /// + /// Delete purchase order by ID + /// + /// + /// For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors + /// + /// HTTP Request + /// ID of the order that needs to be deleted + virtual std::shared_ptr delete_order(const std::shared_ptr &request, const oatpp::String &orderId); + /// + /// Returns pet inventories by status + /// + /// + /// Returns a map of status codes to quantities + /// + /// HTTP Request + virtual std::shared_ptr get_inventory(const std::shared_ptr &request); + /// + /// Find purchase order by ID + /// + /// + /// For valid response try integer IDs with value <= 5 or > 10. Other values will generate exceptions + /// + /// HTTP Request + /// ID of pet that needs to be fetched + virtual std::shared_ptr get_order_by_id(const std::shared_ptr &request, const oatpp::Int64 &orderId); + /// + /// Place an order for a pet + /// + /// + /// + /// + /// HTTP Request + /// order placed for purchasing the pet + virtual std::shared_ptr place_order(const std::shared_ptr &request, const oatpp::Object &order); +}; + +} // namespace org::openapitools::server::api + + + +#endif diff --git a/samples/server/petstore/cpp-oatpp/impl/UserApiController.cpp b/samples/server/petstore/cpp-oatpp/impl/UserApiController.cpp new file mode 100644 index 00000000000..657eb7dfe3c --- /dev/null +++ b/samples/server/petstore/cpp-oatpp/impl/UserApiController.cpp @@ -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 UserApiController::create_user(const std::shared_ptr &request, const oatpp::Object &user) { + (void)request; + + + (void)user; + + return createResponse(Status::CODE_501, "TODO: Implement API Handler"); +} +std::shared_ptr UserApiController::create_users_with_array_input(const std::shared_ptr &request, const oatpp::Vector> &user) { + (void)request; + + + (void)user; + + return createResponse(Status::CODE_501, "TODO: Implement API Handler"); +} +std::shared_ptr UserApiController::create_users_with_list_input(const std::shared_ptr &request, const oatpp::Vector> &user) { + (void)request; + + + (void)user; + + return createResponse(Status::CODE_501, "TODO: Implement API Handler"); +} +std::shared_ptr UserApiController::delete_user(const std::shared_ptr &request, const oatpp::String &username) { + (void)request; + (void)username; + + + + return createResponse(Status::CODE_501, "TODO: Implement API Handler"); +} +std::shared_ptr UserApiController::get_user_by_name(const std::shared_ptr &request, const oatpp::String &username) { + (void)request; + (void)username; + + + + return createResponse(Status::CODE_501, "TODO: Implement API Handler"); +} +std::shared_ptr UserApiController::login_user(const std::shared_ptr &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 UserApiController::logout_user(const std::shared_ptr &request) { + (void)request; + return createResponse(Status::CODE_501, "TODO: Implement API Handler"); +} +std::shared_ptr UserApiController::update_user(const std::shared_ptr &request, const oatpp::String &username, const oatpp::Object &user) { + (void)request; + (void)username; + + + + + + (void)user; + + return createResponse(Status::CODE_501, "TODO: Implement API Handler"); +} + +} +} +} +} + diff --git a/samples/server/petstore/cpp-oatpp/impl/UserApiController.hpp b/samples/server/petstore/cpp-oatpp/impl/UserApiController.hpp new file mode 100644 index 00000000000..5b1e62a0ab9 --- /dev/null +++ b/samples/server/petstore/cpp-oatpp/impl/UserApiController.hpp @@ -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 +#include "oatpp/core/Types.hpp" + + +#include "User.hpp" + +namespace org::openapitools::server::api +{ + +class UserApiController : public UserApi { +public: + /// + /// Create user + /// + /// + /// This can only be done by the logged in user. + /// + /// HTTP Request + /// Created user object + virtual std::shared_ptr create_user(const std::shared_ptr &request, const oatpp::Object &user); + /// + /// Creates list of users with given input array + /// + /// + /// + /// + /// HTTP Request + /// List of user object + virtual std::shared_ptr create_users_with_array_input(const std::shared_ptr &request, const oatpp::Vector> &user); + /// + /// Creates list of users with given input array + /// + /// + /// + /// + /// HTTP Request + /// List of user object + virtual std::shared_ptr create_users_with_list_input(const std::shared_ptr &request, const oatpp::Vector> &user); + /// + /// Delete user + /// + /// + /// This can only be done by the logged in user. + /// + /// HTTP Request + /// The name that needs to be deleted + virtual std::shared_ptr delete_user(const std::shared_ptr &request, const oatpp::String &username); + /// + /// Get user by user name + /// + /// + /// + /// + /// HTTP Request + /// The name that needs to be fetched. Use user1 for testing. + virtual std::shared_ptr get_user_by_name(const std::shared_ptr &request, const oatpp::String &username); + /// + /// Logs user into the system + /// + /// + /// + /// + /// HTTP Request + /// The user name for login + /// The password for login in clear text + virtual std::shared_ptr login_user(const std::shared_ptr &request, const oatpp::String &username, const oatpp::String &password); + /// + /// Logs out current logged in user session + /// + /// + /// + /// + /// HTTP Request + virtual std::shared_ptr logout_user(const std::shared_ptr &request); + /// + /// Updated user + /// + /// + /// This can only be done by the logged in user. + /// + /// HTTP Request + /// name that need to be deleted + /// Updated user object + virtual std::shared_ptr update_user(const std::shared_ptr &request, const oatpp::String &username, const oatpp::Object &user); +}; + +} // namespace org::openapitools::server::api + + + +#endif diff --git a/samples/server/petstore/cpp-oatpp/main-api-server.cpp b/samples/server/petstore/cpp-oatpp/main-api-server.cpp new file mode 100644 index 00000000000..7a87ccb7f61 --- /dev/null +++ b/samples/server/petstore/cpp-oatpp/main-api-server.cpp @@ -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, serverConnectionProvider)([] { + return oatpp::network::tcp::server::ConnectionProvider::createShared({"localhost", 8080, oatpp::network::Address::IP_4}); + }()); + + /** + * Create Router component + */ + OATPP_CREATE_COMPONENT(std::shared_ptr, httpRouter)([] { + return oatpp::web::server::HttpRouter::createShared(); + }()); + + /** + * Create ConnectionHandler component which uses Router component to route requests + */ + OATPP_CREATE_COMPONENT(std::shared_ptr, serverConnectionHandler)([] { + OATPP_COMPONENT(std::shared_ptr, 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, 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, router); + + + /* Create PetApiController and add all of its endpoints to router */ + auto PetApiController = std::make_shared(); + router->addController(PetApiController); + + /* Create StoreApiController and add all of its endpoints to router */ + auto StoreApiController = std::make_shared(); + router->addController(StoreApiController); + + /* Create UserApiController and add all of its endpoints to router */ + auto UserApiController = std::make_shared(); + router->addController(UserApiController); + + + + /* Get connection handler component */ + OATPP_COMPONENT(std::shared_ptr, connectionHandler); + + /* Get connection provider component */ + OATPP_COMPONENT(std::shared_ptr, 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; +} diff --git a/samples/server/petstore/cpp-oatpp/model/ApiResponse.hpp b/samples/server/petstore/cpp-oatpp/model/ApiResponse.hpp new file mode 100644 index 00000000000..62f9ff35dab --- /dev/null +++ b/samples/server/petstore/cpp-oatpp/model/ApiResponse.hpp @@ -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_ */ diff --git a/samples/server/petstore/cpp-oatpp/model/Category.hpp b/samples/server/petstore/cpp-oatpp/model/Category.hpp new file mode 100644 index 00000000000..1b55023dcfa --- /dev/null +++ b/samples/server/petstore/cpp-oatpp/model/Category.hpp @@ -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_ */ diff --git a/samples/server/petstore/cpp-oatpp/model/Order.hpp b/samples/server/petstore/cpp-oatpp/model/Order.hpp new file mode 100644 index 00000000000..a7816394f98 --- /dev/null +++ b/samples/server/petstore/cpp-oatpp/model/Order.hpp @@ -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_ */ diff --git a/samples/server/petstore/cpp-oatpp/model/Pet.hpp b/samples/server/petstore/cpp-oatpp/model/Pet.hpp new file mode 100644 index 00000000000..adfc608a160 --- /dev/null +++ b/samples/server/petstore/cpp-oatpp/model/Pet.hpp @@ -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, Category); + DTO_FIELD(oatpp::Boolean, CategoryIsSet); + DTO_FIELD(oatpp::String, Name); + + DTO_FIELD(oatpp::Vector, PhotoUrls); + + DTO_FIELD(oatpp::Vector>, 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_ */ diff --git a/samples/server/petstore/cpp-oatpp/model/Tag.hpp b/samples/server/petstore/cpp-oatpp/model/Tag.hpp new file mode 100644 index 00000000000..b74619eebad --- /dev/null +++ b/samples/server/petstore/cpp-oatpp/model/Tag.hpp @@ -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_ */ diff --git a/samples/server/petstore/cpp-oatpp/model/User.hpp b/samples/server/petstore/cpp-oatpp/model/User.hpp new file mode 100644 index 00000000000..cd3d0b4ad54 --- /dev/null +++ b/samples/server/petstore/cpp-oatpp/model/User.hpp @@ -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_ */ diff --git a/website/i18n/en.json b/website/i18n/en.json index e6eaca7b372..9f06b9b90e6 100644 --- a/website/i18n/en.json +++ b/website/i18n/en.json @@ -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"