mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-05-12 12:40:53 +00:00
add cpp-oatpp-server generator (alpha)
This commit is contained in:
parent
eceac6a63c
commit
8a7472fd1c
4
bin/configs/other/cpp-oatpp-server.yaml
Normal file
4
bin/configs/other/cpp-oatpp-server.yaml
Normal file
@ -0,0 +1,4 @@
|
||||
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
|
@ -0,0 +1,438 @@
|
||||
/*
|
||||
* Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech)
|
||||
*
|
||||
* 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.utils.ModelUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
|
||||
import static org.openapitools.codegen.utils.StringUtils.underscore;
|
||||
|
||||
public class CppOatppServerCodegen extends AbstractCppCodegen {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(CppOatppServerCodegen.class);
|
||||
|
||||
protected String implFolder = "impl";
|
||||
protected boolean isAddExternalLibs = true;
|
||||
protected boolean isUseStructModel = false;
|
||||
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.";
|
||||
public static final String OPTION_USE_STRUCT_MODEL = "useStructModel";
|
||||
public static final String OPTION_USE_STRUCT_MODEL_DESC = "Use struct-based model template instead of get/set-based model template";
|
||||
public static final String HELPERS_PACKAGE_NAME = "helpersPackage";
|
||||
public static final String HELPERS_PACKAGE_NAME_DESC = "Specify the package name to be used for the helpers (e.g. org.openapitools.server.helpers).";
|
||||
protected final String PREFIX = "";
|
||||
protected String helpersPackage = "";
|
||||
|
||||
@Override
|
||||
public CodegenType getTag() {
|
||||
return CodegenType.SERVER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "cpp-oatpp-server";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelp() {
|
||||
// Ref: https://github.com/oatpp/oatpp
|
||||
return "Generates a C++ API server (based on Oat++)";
|
||||
}
|
||||
|
||||
public CppOatppServerCodegen() {
|
||||
super();
|
||||
|
||||
if (StringUtils.isEmpty(modelNamePrefix)) {
|
||||
modelNamePrefix = PREFIX;
|
||||
}
|
||||
|
||||
helpersPackage = "org.openapitools.server.helpers";
|
||||
apiPackage = "org.openapitools.server.api";
|
||||
modelPackage = "org.openapitools.server.model";
|
||||
|
||||
apiTemplateFiles.put("api-header.mustache", ".h");
|
||||
apiTemplateFiles.put("api-source.mustache", ".cpp");
|
||||
apiTemplateFiles.put("api-impl-header.mustache", ".h");
|
||||
apiTemplateFiles.put("api-impl-source.mustache", ".cpp");
|
||||
|
||||
embeddedTemplateDir = templateDir = "cpp-oatpp-server";
|
||||
|
||||
cliOptions.clear();
|
||||
addSwitch(OPTIONAL_EXTERNAL_LIB, OPTIONAL_EXTERNAL_LIB_DESC, this.isAddExternalLibs);
|
||||
addOption(HELPERS_PACKAGE_NAME, HELPERS_PACKAGE_NAME_DESC, this.helpersPackage);
|
||||
addOption(RESERVED_WORD_PREFIX_OPTION, RESERVED_WORD_PREFIX_DESC, this.reservedWordPrefix);
|
||||
addSwitch(OPTION_USE_STRUCT_MODEL, OPTION_USE_STRUCT_MODEL_DESC, this.isUseStructModel);
|
||||
addOption(VARIABLE_NAME_FIRST_CHARACTER_UPPERCASE_OPTION,
|
||||
VARIABLE_NAME_FIRST_CHARACTER_UPPERCASE_DESC,
|
||||
Boolean.toString(this.variableNameFirstCharacterUppercase));
|
||||
|
||||
supportingFiles.add(new SupportingFile("helpers-header.mustache", "model", modelNamePrefix + "Helpers.h"));
|
||||
supportingFiles.add(new SupportingFile("helpers-source.mustache", "model", modelNamePrefix + "Helpers.cpp"));
|
||||
supportingFiles.add(new SupportingFile("main-api-server.mustache", "", modelNamePrefix + "main-api-server.cpp"));
|
||||
supportingFiles.add(new SupportingFile("cmake.mustache", "", "CMakeLists.txt"));
|
||||
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
|
||||
|
||||
languageSpecificPrimitives = new HashSet<String>(
|
||||
Arrays.asList("int", "char", "bool", "long", "float", "double", "int32_t", "int64_t"));
|
||||
|
||||
typeMapping = new HashMap<String, String>();
|
||||
typeMapping.put("date", "std::string");
|
||||
typeMapping.put("DateTime", "std::string");
|
||||
typeMapping.put("string", "std::string");
|
||||
typeMapping.put("integer", "int32_t");
|
||||
typeMapping.put("long", "int64_t");
|
||||
typeMapping.put("boolean", "bool");
|
||||
typeMapping.put("array", "std::vector");
|
||||
typeMapping.put("map", "std::map");
|
||||
typeMapping.put("file", "std::string");
|
||||
typeMapping.put("object", "Object");
|
||||
typeMapping.put("binary", "std::string");
|
||||
typeMapping.put("number", "double");
|
||||
typeMapping.put("UUID", "std::string");
|
||||
typeMapping.put("URI", "std::string");
|
||||
typeMapping.put("ByteArray", "std::string");
|
||||
|
||||
importMapping = new HashMap<String, String>();
|
||||
importMapping.put("std::vector", "#include <vector>");
|
||||
importMapping.put("std::map", "#include <map>");
|
||||
importMapping.put("std::string", "#include <string>");
|
||||
importMapping.put("Object", "#include \"Object.h\"");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processOpts() {
|
||||
super.processOpts();
|
||||
if (additionalProperties.containsKey(HELPERS_PACKAGE_NAME)) {
|
||||
helpersPackage = (String) additionalProperties.get(HELPERS_PACKAGE_NAME);
|
||||
}
|
||||
if (additionalProperties.containsKey("modelNamePrefix")) {
|
||||
additionalProperties().put("prefix", modelNamePrefix);
|
||||
supportingFiles.clear();
|
||||
supportingFiles.add(new SupportingFile("helpers-header.mustache", "model", modelNamePrefix + "Helpers.h"));
|
||||
supportingFiles.add(new SupportingFile("helpers-source.mustache", "model", modelNamePrefix + "Helpers.cpp"));
|
||||
supportingFiles.add(new SupportingFile("main-api-server.mustache", "", modelNamePrefix + "main-api-server.cpp"));
|
||||
supportingFiles.add(new SupportingFile("cmake.mustache", "", "CMakeLists.txt"));
|
||||
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
|
||||
}
|
||||
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("helpersNamespaceDeclarations", helpersPackage.split("\\."));
|
||||
additionalProperties.put("helpersNamespace", helpersPackage.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);
|
||||
}
|
||||
|
||||
// setup model templates
|
||||
if (additionalProperties.containsKey(OPTION_USE_STRUCT_MODEL))
|
||||
isUseStructModel = convertPropertyToBooleanAndWriteBack(OPTION_USE_STRUCT_MODEL);
|
||||
|
||||
if (isUseStructModel) {
|
||||
LOGGER.info("Using struct-based model template");
|
||||
modelTemplateFiles.put("model-struct-header.mustache", ".h");
|
||||
modelTemplateFiles.put("model-struct-source.mustache", ".cpp");
|
||||
} else {
|
||||
LOGGER.info("Using get/set-based model template");
|
||||
modelTemplateFiles.put("model-header.mustache", ".h");
|
||||
modelTemplateFiles.put("model-source.mustache", ".cpp");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toModelImport(String name) {
|
||||
if (importMapping.containsKey(name)) {
|
||||
return importMapping.get(name);
|
||||
} else {
|
||||
return "#include \"" + name + ".h\"";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public CodegenModel fromModel(String name, Schema model) {
|
||||
CodegenModel codegenModel = super.fromModel(name, model);
|
||||
|
||||
Set<String> oldImports = codegenModel.imports;
|
||||
codegenModel.imports = new HashSet<>();
|
||||
for (String imp : oldImports) {
|
||||
String newImp = toModelImport(imp);
|
||||
if (!newImp.isEmpty()) {
|
||||
codegenModel.imports.add(newImp);
|
||||
}
|
||||
}
|
||||
|
||||
return codegenModel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CodegenOperation fromOperation(String path, String httpMethod, Operation operation, List<Server> servers) {
|
||||
CodegenOperation op = super.fromOperation(path, httpMethod, operation, servers);
|
||||
|
||||
if (operation.getResponses() != null && !operation.getResponses().isEmpty()) {
|
||||
ApiResponse apiResponse = findMethodResponse(operation.getResponses());
|
||||
|
||||
if (apiResponse != null) {
|
||||
Schema response = ModelUtils.getSchemaFromResponse(apiResponse);
|
||||
if (response != null) {
|
||||
CodegenProperty cm = fromProperty("response", response);
|
||||
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;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public Map<String, Object> postProcessOperationsWithModels(Map<String, Object> objs, List<Object> allModels) {
|
||||
Map<String, Object> operations = (Map<String, Object>) objs.get("operations");
|
||||
String classname = (String) operations.get("classname");
|
||||
operations.put("classnameSnakeUpperCase", underscore(classname).toUpperCase(Locale.ROOT));
|
||||
operations.put("classnameSnakeLowerCase", underscore(classname).toLowerCase(Locale.ROOT));
|
||||
List<CodegenOperation> operationList = (List<CodegenOperation>) operations.get("operation");
|
||||
for (CodegenOperation op : operationList) {
|
||||
boolean consumeJson = false;
|
||||
boolean isParsingSupported = true;
|
||||
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);
|
||||
}
|
||||
if (op.consumes != null) {
|
||||
for (Map<String, String> consume : op.consumes) {
|
||||
if (consume.get("mediaType") != null && consume.get("mediaType").equals("application/json")) {
|
||||
consumeJson = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
op.httpMethod = op.httpMethod.substring(0, 1).toUpperCase(Locale.ROOT) + op.httpMethod.substring(1).toLowerCase(Locale.ROOT);
|
||||
|
||||
for (CodegenParameter param : op.allParams) {
|
||||
if (param.isFormParam) isParsingSupported = false;
|
||||
if (param.isFile) isParsingSupported = false;
|
||||
if (param.isCookieParam) isParsingSupported = false;
|
||||
|
||||
//TODO: This changes the info about the real type but it is needed to parse the header params
|
||||
if (param.isHeaderParam) {
|
||||
param.dataType = "Oatpp::Optional<Oatpp::Http::Header::Raw>";
|
||||
param.baseType = "Oatpp::Optional<Oatpp::Http::Header::Raw>";
|
||||
} else if (param.isQueryParam) {
|
||||
if (param.isPrimitiveType) {
|
||||
param.dataType = "Oatpp::Optional<" + param.dataType + ">";
|
||||
} else {
|
||||
param.dataType = "Oatpp::Optional<" + param.dataType + ">";
|
||||
param.baseType = "Oatpp::Optional<" + param.baseType + ">";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (op.vendorExtensions == null) {
|
||||
op.vendorExtensions = new HashMap<>();
|
||||
}
|
||||
op.vendorExtensions.put("x-codegen-oatpp-consumes-json", consumeJson);
|
||||
op.vendorExtensions.put("x-codegen-oatpp-is-parsing-supported", isParsingSupported);
|
||||
|
||||
// Check if any one of the operations needs a model, then at API file level, at least one model has to be included.
|
||||
for (String hdr : op.imports) {
|
||||
if (importMapping.containsKey(hdr)) {
|
||||
continue;
|
||||
}
|
||||
operations.put("hasModelImport", true);
|
||||
}
|
||||
}
|
||||
|
||||
return objs;
|
||||
}
|
||||
|
||||
@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")) {
|
||||
int ix = result.lastIndexOf(File.separatorChar);
|
||||
result = result.substring(0, ix) + result.substring(ix, result.length() - 2) + "Impl.h";
|
||||
result = result.replace(apiFileFolder(), implFileFolder());
|
||||
} else if (templateName.endsWith("impl-source.mustache")) {
|
||||
int ix = result.lastIndexOf(File.separatorChar);
|
||||
result = result.substring(0, ix) + result.substring(ix, result.length() - 4) + "Impl.cpp";
|
||||
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();
|
||||
return getSchemaType(p) + "<" + getTypeDeclaration(inner) + ">";
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
Schema inner = getAdditionalProperties(p);
|
||||
return getSchemaType(p) + "<std::string, " + getTypeDeclaration(inner) + ">";
|
||||
} else if (ModelUtils.isByteArraySchema(p)) {
|
||||
return "std::string";
|
||||
} else if (ModelUtils.isStringSchema(p)
|
||||
|| ModelUtils.isDateSchema(p)
|
||||
|| ModelUtils.isDateTimeSchema(p) || ModelUtils.isFileSchema(p)
|
||||
|| languageSpecificPrimitives.contains(openAPIType)) {
|
||||
return toModelName(openAPIType);
|
||||
}
|
||||
|
||||
return openAPIType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toDefaultValue(Schema p) {
|
||||
if (ModelUtils.isBooleanSchema(p)) {
|
||||
return "false";
|
||||
} else if (ModelUtils.isDateSchema(p)) {
|
||||
return "\"\"";
|
||||
} else if (ModelUtils.isDateTimeSchema(p)) {
|
||||
return "\"\"";
|
||||
} else if (ModelUtils.isNumberSchema(p)) {
|
||||
if (ModelUtils.isFloatSchema(p)) {
|
||||
return "0.0f";
|
||||
}
|
||||
return "0.0";
|
||||
} else if (ModelUtils.isIntegerSchema(p)) {
|
||||
if (ModelUtils.isLongSchema(p)) {
|
||||
return "0L";
|
||||
}
|
||||
return "0";
|
||||
} else if (ModelUtils.isByteArraySchema(p)) {
|
||||
return "\"\"";
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
String inner = getSchemaType(getAdditionalProperties(p));
|
||||
return "std::map<std::string, " + inner + ">()";
|
||||
} else if (ModelUtils.isArraySchema(p)) {
|
||||
ArraySchema ap = (ArraySchema) p;
|
||||
String inner = getSchemaType(ap.getItems());
|
||||
return "std::vector<" + inner + ">()";
|
||||
} else if (!StringUtils.isEmpty(p.get$ref())) { // model
|
||||
return toModelName(ModelUtils.getSimpleRef(p.get$ref())) + "()";
|
||||
} else if (ModelUtils.isStringSchema(p)) {
|
||||
return "\"\"";
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* Location to write model files. You can use the modelPackage() as defined
|
||||
* when the class is instantiated
|
||||
*/
|
||||
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);
|
||||
if (languageSpecificPrimitives.contains(type))
|
||||
return toModelName(type);
|
||||
} 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;
|
||||
}
|
||||
}
|
@ -12,6 +12,7 @@ org.openapitools.codegen.languages.ClojureClientCodegen
|
||||
org.openapitools.codegen.languages.ConfluenceWikiCodegen
|
||||
org.openapitools.codegen.languages.CppQt5ClientCodegen
|
||||
org.openapitools.codegen.languages.CppQt5QHttpEngineServerCodegen
|
||||
org.openapitools.codegen.languages.CppOatppServerCodegen
|
||||
org.openapitools.codegen.languages.CppPistacheServerCodegen
|
||||
org.openapitools.codegen.languages.CppRestbedServerCodegen
|
||||
org.openapitools.codegen.languages.CppRestSdkClientCodegen
|
||||
|
48
modules/openapi-generator/src/main/resources/cpp-oatpp-server/README.mustache
vendored
Normal file
48
modules/openapi-generator/src/main/resources/cpp-oatpp-server/README.mustache
vendored
Normal file
@ -0,0 +1,48 @@
|
||||
# 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++](http://github.com/oatpp/oatpp)
|
||||
- [JSON for Modern C++](https://github.com/nlohmann/json/#integration): Please download the `json.hpp` file and
|
||||
put it under the model/nlohmann folder
|
||||
|
||||
## Namespaces
|
||||
{{{apiPackage}}}
|
||||
{{{modelPackage}}}
|
72
modules/openapi-generator/src/main/resources/cpp-oatpp-server/api-header.mustache
vendored
Normal file
72
modules/openapi-generator/src/main/resources/cpp-oatpp-server/api-header.mustache
vendored
Normal file
@ -0,0 +1,72 @@
|
||||
{{>licenseInfo}}
|
||||
{{#operations}}/*
|
||||
* {{classname}}.h
|
||||
*
|
||||
* {{description}}
|
||||
*/
|
||||
|
||||
#ifndef {{classname}}_H_
|
||||
#define {{classname}}_H_
|
||||
|
||||
{{{defaultInclude}}}
|
||||
#include <pistache/http.h>
|
||||
#include <pistache/router.h>
|
||||
#include <pistache/http_headers.h>
|
||||
#include <pistache/optional.h>
|
||||
{{^hasModelImport}}#include <nlohmann/json.hpp>{{/hasModelImport}}
|
||||
|
||||
{{#imports}}{{{import}}}
|
||||
{{/imports}}
|
||||
|
||||
{{#apiNamespaceDeclarations}}
|
||||
namespace {{this}} {
|
||||
{{/apiNamespaceDeclarations}}
|
||||
|
||||
{{#hasModelImport}}
|
||||
using namespace {{modelNamespace}};{{/hasModelImport}}
|
||||
|
||||
class {{declspec}} {{classname}} {
|
||||
public:
|
||||
{{classname}}(std::shared_ptr<Pistache::Rest::Router>);
|
||||
virtual ~{{classname}}() {}
|
||||
void init();
|
||||
|
||||
const std::string base = "{{basePathWithoutHost}}";
|
||||
|
||||
private:
|
||||
void setupRoutes();
|
||||
|
||||
{{#operation}}
|
||||
void {{operationIdSnakeCase}}_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response);
|
||||
{{/operation}}
|
||||
void {{classnameSnakeLowerCase}}_default_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response);
|
||||
|
||||
std::shared_ptr<Pistache::Rest::Router> router;
|
||||
{{#operation}}
|
||||
|
||||
/// <summary>
|
||||
/// {{summary}}
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// {{notes}}
|
||||
/// </remarks>
|
||||
{{#vendorExtensions.x-codegen-oatpp-is-parsing-supported}}
|
||||
{{#allParams}}
|
||||
/// <param name="{{paramName}}">{{description}}{{^required}} (optional{{#defaultValue}}, default to {{.}}{{/defaultValue}}){{/required}}</param>
|
||||
{{/allParams}}
|
||||
virtual void {{operationIdSnakeCase}}({{#allParams}}const {{{dataType}}} &{{paramName}}{{^-last}}, {{/-last}}{{/allParams}}{{#hasParams}}, {{/hasParams}}Pistache::Http::ResponseWriter &response) = 0;
|
||||
{{/vendorExtensions.x-codegen-oatpp-is-parsing-supported}}
|
||||
{{^vendorExtensions.x-codegen-oatpp-is-parsing-supported}}
|
||||
virtual void {{operationIdSnakeCase}}(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter &response) = 0;
|
||||
{{/vendorExtensions.x-codegen-oatpp-is-parsing-supported}}
|
||||
{{/operation}}
|
||||
|
||||
};
|
||||
|
||||
{{#apiNamespaceDeclarations}}
|
||||
}
|
||||
{{/apiNamespaceDeclarations}}
|
||||
|
||||
#endif /* {{classname}}_H_ */
|
||||
|
||||
{{/operations}}
|
55
modules/openapi-generator/src/main/resources/cpp-oatpp-server/api-impl-header.mustache
vendored
Normal file
55
modules/openapi-generator/src/main/resources/cpp-oatpp-server/api-impl-header.mustache
vendored
Normal file
@ -0,0 +1,55 @@
|
||||
{{>licenseInfo}}
|
||||
|
||||
{{#operations}}/*
|
||||
* {{classname}}Impl.h
|
||||
*
|
||||
* {{description}}
|
||||
*/
|
||||
|
||||
#ifndef {{classnameSnakeUpperCase}}_IMPL_H_
|
||||
#define {{classnameSnakeUpperCase}}_IMPL_H_
|
||||
|
||||
{{{defaultInclude}}}
|
||||
#include <pistache/endpoint.h>
|
||||
#include <pistache/http.h>
|
||||
#include <pistache/router.h>
|
||||
#include <memory>
|
||||
|
||||
#include <{{classname}}.h>
|
||||
|
||||
#include <pistache/optional.h>
|
||||
|
||||
{{#imports}}{{{import}}}
|
||||
{{/imports}}
|
||||
|
||||
{{#apiNamespaceDeclarations}}
|
||||
namespace {{this}} {
|
||||
{{/apiNamespaceDeclarations}}
|
||||
|
||||
{{#hasModelImport}}
|
||||
using namespace {{modelNamespace}};{{/hasModelImport}}
|
||||
|
||||
class {{classname}}Impl : public {{apiNamespace}}::{{classname}} {
|
||||
public:
|
||||
{{classname}}Impl(std::shared_ptr<Pistache::Rest::Router>);
|
||||
~{{classname}}Impl() {}
|
||||
|
||||
{{#operation}}
|
||||
{{#vendorExtensions.x-codegen-oatpp-is-parsing-supported}}
|
||||
void {{operationIdSnakeCase}}({{#allParams}}const {{{dataType}}} &{{paramName}}{{^-last}}, {{/-last}}{{/allParams}}{{#hasParams}}, {{/hasParams}}Pistache::Http::ResponseWriter &response);
|
||||
{{/vendorExtensions.x-codegen-oatpp-is-parsing-supported}}
|
||||
{{^vendorExtensions.x-codegen-oatpp-is-parsing-supported}}
|
||||
void {{operationIdSnakeCase}}(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter &response);
|
||||
{{/vendorExtensions.x-codegen-oatpp-is-parsing-supported}}
|
||||
{{/operation}}
|
||||
|
||||
};
|
||||
|
||||
{{#apiNamespaceDeclarations}}
|
||||
}
|
||||
{{/apiNamespaceDeclarations}}
|
||||
|
||||
{{/operations}}
|
||||
|
||||
|
||||
#endif
|
34
modules/openapi-generator/src/main/resources/cpp-oatpp-server/api-impl-source.mustache
vendored
Normal file
34
modules/openapi-generator/src/main/resources/cpp-oatpp-server/api-impl-source.mustache
vendored
Normal file
@ -0,0 +1,34 @@
|
||||
{{>licenseInfo}}
|
||||
{{#operations}}
|
||||
|
||||
#include "{{classname}}Impl.h"
|
||||
|
||||
{{#apiNamespaceDeclarations}}
|
||||
namespace {{this}} {
|
||||
{{/apiNamespaceDeclarations}}
|
||||
|
||||
{{#hasModelImport}}
|
||||
using namespace {{modelNamespace}};{{/hasModelImport}}
|
||||
|
||||
{{classname}}Impl::{{classname}}Impl(std::shared_ptr<Pistache::Rest::Router> rtr)
|
||||
: {{classname}}(rtr)
|
||||
{ }
|
||||
|
||||
{{#operation}}
|
||||
{{#vendorExtensions.x-codegen-oatpp-is-parsing-supported}}
|
||||
void {{classname}}Impl::{{operationIdSnakeCase}}({{#allParams}}const {{{dataType}}} &{{paramName}}{{^-last}}, {{/-last}}{{/allParams}}{{#hasParams}}, {{/hasParams}}Pistache::Http::ResponseWriter &response) {
|
||||
response.send(Pistache::Http::Code::Ok, "Do some magic\n");
|
||||
}
|
||||
{{/vendorExtensions.x-codegen-oatpp-is-parsing-supported}}
|
||||
{{^vendorExtensions.x-codegen-oatpp-is-parsing-supported}}
|
||||
void {{classname}}Impl::{{operationIdSnakeCase}}(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter &response){
|
||||
response.send(Pistache::Http::Code::Ok, "Do some magic\n");
|
||||
}
|
||||
{{/vendorExtensions.x-codegen-oatpp-is-parsing-supported}}
|
||||
{{/operation}}
|
||||
|
||||
{{#apiNamespaceDeclarations}}
|
||||
}
|
||||
{{/apiNamespaceDeclarations}}
|
||||
|
||||
{{/operations}}
|
111
modules/openapi-generator/src/main/resources/cpp-oatpp-server/api-source.mustache
vendored
Normal file
111
modules/openapi-generator/src/main/resources/cpp-oatpp-server/api-source.mustache
vendored
Normal file
@ -0,0 +1,111 @@
|
||||
{{>licenseInfo}}
|
||||
{{#operations}}
|
||||
|
||||
#include "{{classname}}.h"
|
||||
#include "{{prefix}}Helpers.h"
|
||||
|
||||
{{#apiNamespaceDeclarations}}
|
||||
namespace {{this}} {
|
||||
{{/apiNamespaceDeclarations}}
|
||||
|
||||
using namespace {{helpersNamespace}};
|
||||
{{#hasModelImport}}
|
||||
using namespace {{modelNamespace}};{{/hasModelImport}}
|
||||
|
||||
{{classname}}::{{classname}}(std::shared_ptr<Pistache::Rest::Router> rtr) {
|
||||
router = rtr;
|
||||
}
|
||||
|
||||
void {{classname}}::init() {
|
||||
setupRoutes();
|
||||
}
|
||||
|
||||
void {{classname}}::setupRoutes() {
|
||||
using namespace Pistache::Rest;
|
||||
|
||||
{{#operation}}
|
||||
Routes::{{httpMethod}}(*router, base + "{{{vendorExtensions.x-codegen-oatpp-path}}}", Routes::bind(&{{classname}}::{{operationIdSnakeCase}}_handler, this));
|
||||
{{/operation}}
|
||||
|
||||
// Default handler, called when a route is not found
|
||||
router->addCustomHandler(Routes::bind(&{{classname}}::{{classnameSnakeLowerCase}}_default_handler, this));
|
||||
}
|
||||
|
||||
{{#operation}}
|
||||
void {{classname}}::{{operationIdSnakeCase}}_handler(const Pistache::Rest::Request &{{#hasParams}}request{{/hasParams}}, Pistache::Http::ResponseWriter response) {
|
||||
{{#vendorExtensions.x-codegen-oatpp-is-parsing-supported}}
|
||||
{{#hasPathParams}}
|
||||
// Getting the path params
|
||||
{{#pathParams}}
|
||||
auto {{paramName}} = request.param(":{{paramName}}").as<{{dataType}}>();
|
||||
{{/pathParams}}
|
||||
{{/hasPathParams}}{{#hasBodyParam}}
|
||||
// Getting the body param
|
||||
{{#bodyParam}}
|
||||
{{^isPrimitiveType}}{{^isContainer}}
|
||||
{{baseType}} {{paramName}};{{/isContainer}}{{#isArray}}std::vector<{{items.baseType}}> {{paramName}};{{/isArray}}{{#isMap}}std::map<std::string, {{items.baseType}}> {{paramName}};{{/isMap}}{{/isPrimitiveType}}
|
||||
{{#isPrimitiveType}}
|
||||
{{dataType}} {{paramName}};
|
||||
{{/isPrimitiveType}}
|
||||
{{/bodyParam}}
|
||||
{{/hasBodyParam}}{{#hasQueryParams}}
|
||||
// Getting the query params
|
||||
{{#queryParams}}
|
||||
auto {{paramName}}Query = request.query().get("{{baseName}}");
|
||||
Pistache::Optional<{{^isContainer}}{{dataType}}{{/isContainer}}{{#isArray}}std::vector<{{items.baseType}}>{{/isArray}}> {{paramName}};
|
||||
if(!{{paramName}}Query.isEmpty()){
|
||||
{{^isContainer}}{{dataType}}{{/isContainer}}{{#isArray}}std::vector<{{items.baseType}}>{{/isArray}} valueQuery_instance;
|
||||
if(fromStringValue({{paramName}}Query.get(), valueQuery_instance)){
|
||||
{{paramName}} = Pistache::Some(valueQuery_instance);
|
||||
}
|
||||
}
|
||||
{{/queryParams}}
|
||||
{{/hasQueryParams}}{{#hasHeaderParams}}
|
||||
// Getting the header params
|
||||
{{#headerParams}}
|
||||
auto {{paramName}} = request.headers().tryGetRaw("{{baseName}}");
|
||||
{{/headerParams}}
|
||||
{{/hasHeaderParams}}
|
||||
|
||||
try {
|
||||
{{#hasBodyParam}}
|
||||
{{#bodyParam}}
|
||||
{{^isPrimitiveType}}
|
||||
nlohmann::json::parse(request.body()).get_to({{paramName}});
|
||||
{{/isPrimitiveType}}
|
||||
{{#isPrimitiveType}}
|
||||
{{paramName}} = request.body();
|
||||
{{/isPrimitiveType}}
|
||||
{{/bodyParam}}
|
||||
{{/hasBodyParam}}
|
||||
this->{{operationIdSnakeCase}}({{#allParams}}{{paramName}}{{^-last}}, {{/-last}}{{/allParams}}{{#hasParams}}, {{/hasParams}}response);
|
||||
{{/vendorExtensions.x-codegen-oatpp-is-parsing-supported}}
|
||||
{{^vendorExtensions.x-codegen-oatpp-is-parsing-supported}}
|
||||
try {
|
||||
this->{{operationIdSnakeCase}}(request, response);
|
||||
{{/vendorExtensions.x-codegen-oatpp-is-parsing-supported}}
|
||||
} catch (nlohmann::detail::exception &e) {
|
||||
//send a 400 error
|
||||
response.send(Pistache::Http::Code::Bad_Request, e.what());
|
||||
return;
|
||||
} catch (Pistache::Http::HttpError &e) {
|
||||
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
|
||||
return;
|
||||
} catch (std::exception &e) {
|
||||
//send a 500 error
|
||||
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
{{/operation}}
|
||||
|
||||
void {{classname}}::{{classnameSnakeLowerCase}}_default_handler(const Pistache::Rest::Request &, Pistache::Http::ResponseWriter response) {
|
||||
response.send(Pistache::Http::Code::Not_Found, "The requested method does not exist");
|
||||
}
|
||||
|
||||
{{#apiNamespaceDeclarations}}
|
||||
}
|
||||
{{/apiNamespaceDeclarations}}
|
||||
|
||||
{{/operations}}
|
39
modules/openapi-generator/src/main/resources/cpp-oatpp-server/cmake.mustache
vendored
Normal file
39
modules/openapi-generator/src/main/resources/cpp-oatpp-server/cmake.mustache
vendored
Normal file
@ -0,0 +1,39 @@
|
||||
cmake_minimum_required (VERSION 3.2)
|
||||
|
||||
project(api-server)
|
||||
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -pg -g3" )
|
||||
|
||||
{{#addExternalLibs}}
|
||||
include(ExternalProject)
|
||||
|
||||
set(EXTERNAL_INSTALL_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/external)
|
||||
|
||||
ExternalProject_Add(PISTACHE
|
||||
GIT_REPOSITORY https://github.com/oktal/pistache.git
|
||||
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${EXTERNAL_INSTALL_LOCATION}
|
||||
)
|
||||
|
||||
ExternalProject_Add(NLOHMANN
|
||||
GIT_REPOSITORY https://github.com/nlohmann/json.git
|
||||
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${EXTERNAL_INSTALL_LOCATION}
|
||||
|
||||
)
|
||||
include_directories(${EXTERNAL_INSTALL_LOCATION}/include)
|
||||
link_directories(${EXTERNAL_INSTALL_LOCATION}/lib)
|
||||
{{/addExternalLibs}}
|
||||
|
||||
include_directories(model)
|
||||
include_directories(api)
|
||||
include_directories(impl)
|
||||
|
||||
file(GLOB SRCS
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/api/*.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/impl/*.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/model/*.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/*.cpp
|
||||
)
|
||||
|
||||
add_executable(${PROJECT_NAME} ${SRCS} )
|
||||
{{#addExternalLibs}}add_dependencies(${PROJECT_NAME} PISTACHE NLOHMANN){{/addExternalLibs}}
|
||||
target_link_libraries(${PROJECT_NAME} pistache pthread)
|
64
modules/openapi-generator/src/main/resources/cpp-oatpp-server/helpers-header.mustache
vendored
Normal file
64
modules/openapi-generator/src/main/resources/cpp-oatpp-server/helpers-header.mustache
vendored
Normal file
@ -0,0 +1,64 @@
|
||||
{{>licenseInfo}}
|
||||
/*
|
||||
* {{prefix}}Helpers.h
|
||||
*
|
||||
* This is the helper class for models and primitives
|
||||
*/
|
||||
|
||||
#ifndef {{prefix}}Helpers_H_
|
||||
#define {{prefix}}Helpers_H_
|
||||
|
||||
#include <ctime>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
{{#helpersNamespaceDeclarations}}
|
||||
namespace {{this}} {
|
||||
{{/helpersNamespaceDeclarations}}
|
||||
|
||||
std::string toStringValue(const std::string &value);
|
||||
std::string toStringValue(const int32_t &value);
|
||||
std::string toStringValue(const int64_t &value);
|
||||
std::string toStringValue(const bool &value);
|
||||
std::string toStringValue(const float &value);
|
||||
std::string toStringValue(const double &value);
|
||||
|
||||
bool fromStringValue(const std::string &inStr, std::string &value);
|
||||
bool fromStringValue(const std::string &inStr, int32_t &value);
|
||||
bool fromStringValue(const std::string &inStr, int64_t &value);
|
||||
bool fromStringValue(const std::string &inStr, bool &value);
|
||||
bool fromStringValue(const std::string &inStr, float &value);
|
||||
bool fromStringValue(const std::string &inStr, double &value);
|
||||
template<typename T>
|
||||
bool fromStringValue(const std::vector<std::string> &inStr, std::vector<T> &value){
|
||||
try{
|
||||
for(auto & item : inStr){
|
||||
T itemValue;
|
||||
if(fromStringValue(item, itemValue)){
|
||||
value.push_back(itemValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(...){
|
||||
return false;
|
||||
}
|
||||
return value.size() > 0;
|
||||
}
|
||||
template<typename T>
|
||||
bool fromStringValue(const std::string &inStr, std::vector<T> &value, char separator = ','){
|
||||
std::vector<std::string> inStrings;
|
||||
std::istringstream f(inStr);
|
||||
std::string s;
|
||||
while (std::getline(f, s, separator)) {
|
||||
inStrings.push_back(s);
|
||||
}
|
||||
return fromStringValue(inStrings, value);
|
||||
}
|
||||
|
||||
{{#helpersNamespaceDeclarations}}
|
||||
}
|
||||
{{/helpersNamespaceDeclarations}}
|
||||
|
||||
#endif // {{prefix}}Helpers_H_
|
86
modules/openapi-generator/src/main/resources/cpp-oatpp-server/helpers-source.mustache
vendored
Normal file
86
modules/openapi-generator/src/main/resources/cpp-oatpp-server/helpers-source.mustache
vendored
Normal file
@ -0,0 +1,86 @@
|
||||
{{>licenseInfo}}
|
||||
#include "{{prefix}}Helpers.h"
|
||||
|
||||
{{#helpersNamespaceDeclarations}}
|
||||
namespace {{this}} {
|
||||
{{/helpersNamespaceDeclarations}}
|
||||
|
||||
|
||||
std::string toStringValue(const std::string &value){
|
||||
return std::string(value);
|
||||
}
|
||||
|
||||
std::string toStringValue(const int32_t &value){
|
||||
return std::to_string(value);
|
||||
}
|
||||
|
||||
std::string toStringValue(const int64_t &value){
|
||||
return std::to_string(value);
|
||||
}
|
||||
|
||||
std::string toStringValue(const bool &value){
|
||||
return value?std::string("true"):std::string("false");
|
||||
}
|
||||
|
||||
std::string toStringValue(const float &value){
|
||||
return std::to_string(value);
|
||||
}
|
||||
|
||||
std::string toStringValue(const double &value){
|
||||
return std::to_string(value);
|
||||
}
|
||||
|
||||
bool fromStringValue(const std::string &inStr, std::string &value){
|
||||
value = std::string(inStr);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool fromStringValue(const std::string &inStr, int32_t &value){
|
||||
try {
|
||||
value = std::stoi( inStr );
|
||||
}
|
||||
catch (const std::invalid_argument&) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool fromStringValue(const std::string &inStr, int64_t &value){
|
||||
try {
|
||||
value = std::stol( inStr );
|
||||
}
|
||||
catch (const std::invalid_argument&) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool fromStringValue(const std::string &inStr, bool &value){
|
||||
bool result = true;
|
||||
inStr == "true"?value = true: inStr == "false"?value = false: result = false;
|
||||
return result;
|
||||
}
|
||||
|
||||
bool fromStringValue(const std::string &inStr, float &value){
|
||||
try {
|
||||
value = std::stof( inStr );
|
||||
}
|
||||
catch (const std::invalid_argument&) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool fromStringValue(const std::string &inStr, double &value){
|
||||
try {
|
||||
value = std::stod( inStr );
|
||||
}
|
||||
catch (const std::invalid_argument&) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
{{#helpersNamespaceDeclarations}}
|
||||
}
|
||||
{{/helpersNamespaceDeclarations}}
|
11
modules/openapi-generator/src/main/resources/cpp-oatpp-server/licenseInfo.mustache
vendored
Normal file
11
modules/openapi-generator/src/main/resources/cpp-oatpp-server/licenseInfo.mustache
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
/**
|
||||
* {{{appName}}}
|
||||
* {{{appDescription}}}
|
||||
*
|
||||
* {{#version}}The version of the OpenAPI document: {{{version}}}{{/version}}
|
||||
* {{#infoEmail}}Contact: {{{infoEmail}}}{{/infoEmail}}
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
79
modules/openapi-generator/src/main/resources/cpp-oatpp-server/main-api-server.mustache
vendored
Normal file
79
modules/openapi-generator/src/main/resources/cpp-oatpp-server/main-api-server.mustache
vendored
Normal file
@ -0,0 +1,79 @@
|
||||
{{>licenseInfo}}
|
||||
|
||||
|
||||
#include "pistache/endpoint.h"
|
||||
#include "pistache/http.h"
|
||||
#include "pistache/router.h"
|
||||
#ifdef __linux__
|
||||
#include <vector>
|
||||
#include <signal.h>
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
{{#apiInfo}}{{#apis}}{{#operations}}
|
||||
#include "{{classname}}Impl.h"{{/operations}}{{/apis}}{{/apiInfo}}
|
||||
|
||||
#define PISTACHE_SERVER_THREADS 2
|
||||
#define PISTACHE_SERVER_MAX_REQUEST_SIZE 32768
|
||||
#define PISTACHE_SERVER_MAX_RESPONSE_SIZE 32768
|
||||
|
||||
static Pistache::Http::Endpoint *httpEndpoint;
|
||||
#ifdef __linux__
|
||||
static void sigHandler [[noreturn]] (int sig){
|
||||
switch(sig){
|
||||
case SIGINT:
|
||||
case SIGQUIT:
|
||||
case SIGTERM:
|
||||
case SIGHUP:
|
||||
default:
|
||||
httpEndpoint->shutdown();
|
||||
break;
|
||||
}
|
||||
exit(0);
|
||||
}
|
||||
|
||||
static void setUpUnixSignals(std::vector<int> quitSignals) {
|
||||
sigset_t blocking_mask;
|
||||
sigemptyset(&blocking_mask);
|
||||
for (auto sig : quitSignals)
|
||||
sigaddset(&blocking_mask, sig);
|
||||
|
||||
struct sigaction sa;
|
||||
sa.sa_handler = sigHandler;
|
||||
sa.sa_mask = blocking_mask;
|
||||
sa.sa_flags = 0;
|
||||
|
||||
for (auto sig : quitSignals)
|
||||
sigaction(sig, &sa, nullptr);
|
||||
}
|
||||
#endif
|
||||
|
||||
using namespace {{apiNamespace}};
|
||||
|
||||
int main() {
|
||||
#ifdef __linux__
|
||||
std::vector<int> sigs{SIGQUIT, SIGINT, SIGTERM, SIGHUP};
|
||||
setUpUnixSignals(sigs);
|
||||
#endif
|
||||
Pistache::Address addr(Pistache::Ipv4::any(), Pistache::Port({{#serverPort}}{{serverPort}}{{/serverPort}}{{^serverPort}}8080{{/serverPort}}));
|
||||
|
||||
httpEndpoint = new Pistache::Http::Endpoint((addr));
|
||||
auto router = std::make_shared<Pistache::Rest::Router>();
|
||||
|
||||
auto opts = Pistache::Http::Endpoint::options()
|
||||
.threads(PISTACHE_SERVER_THREADS);
|
||||
opts.flags(Pistache::Tcp::Options::ReuseAddr);
|
||||
opts.maxRequestSize(PISTACHE_SERVER_MAX_REQUEST_SIZE);
|
||||
opts.maxResponseSize(PISTACHE_SERVER_MAX_RESPONSE_SIZE);
|
||||
httpEndpoint->init(opts);
|
||||
|
||||
{{#apiInfo}}{{#apis}}{{#operations}}
|
||||
{{classname}}Impl {{classname}}server(router);
|
||||
{{classname}}server.init();{{/operations}}{{/apis}}{{/apiInfo}}
|
||||
|
||||
httpEndpoint->setHandler(router->handler());
|
||||
httpEndpoint->serve();
|
||||
|
||||
httpEndpoint->shutdown();
|
||||
|
||||
}
|
||||
|
60
modules/openapi-generator/src/main/resources/cpp-oatpp-server/model-header.mustache
vendored
Normal file
60
modules/openapi-generator/src/main/resources/cpp-oatpp-server/model-header.mustache
vendored
Normal file
@ -0,0 +1,60 @@
|
||||
{{>licenseInfo}}
|
||||
{{#models}}{{#model}}/*
|
||||
* {{classname}}.h
|
||||
*
|
||||
* {{description}}
|
||||
*/
|
||||
|
||||
#ifndef {{classname}}_H_
|
||||
#define {{classname}}_H_
|
||||
|
||||
{{{defaultInclude}}}
|
||||
{{#imports}}{{{this}}}
|
||||
{{/imports}}
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
{{#modelNamespaceDeclarations}}
|
||||
namespace {{this}} {
|
||||
{{/modelNamespaceDeclarations}}
|
||||
|
||||
/// <summary>
|
||||
/// {{description}}
|
||||
/// </summary>
|
||||
class {{declspec}} {{classname}}
|
||||
{
|
||||
public:
|
||||
{{classname}}();
|
||||
virtual ~{{classname}}();
|
||||
|
||||
void validate();
|
||||
|
||||
/////////////////////////////////////////////
|
||||
/// {{classname}} members
|
||||
|
||||
{{#vars}}
|
||||
/// <summary>
|
||||
/// {{description}}
|
||||
/// </summary>
|
||||
{{{dataType}}}{{#isContainer}}&{{/isContainer}} {{getter}}(){{^isContainer}} const{{/isContainer}};
|
||||
void {{setter}}({{{dataType}}} const{{^isPrimitiveType}}&{{/isPrimitiveType}} value);{{^required}}
|
||||
bool {{nameInCamelCase}}IsSet() const;
|
||||
void unset{{name}}();{{/required}}
|
||||
{{/vars}}
|
||||
|
||||
friend void to_json(nlohmann::json& j, const {{classname}}& o);
|
||||
friend void from_json(const nlohmann::json& j, {{classname}}& o);
|
||||
protected:
|
||||
{{#vars}}
|
||||
{{{dataType}}} m_{{name}};
|
||||
{{^required}}
|
||||
bool m_{{name}}IsSet;{{/required}}
|
||||
{{/vars}}
|
||||
};
|
||||
|
||||
{{#modelNamespaceDeclarations}}
|
||||
}
|
||||
{{/modelNamespaceDeclarations}}
|
||||
|
||||
#endif /* {{classname}}_H_ */
|
||||
{{/model}}
|
||||
{{/models}}
|
73
modules/openapi-generator/src/main/resources/cpp-oatpp-server/model-source.mustache
vendored
Normal file
73
modules/openapi-generator/src/main/resources/cpp-oatpp-server/model-source.mustache
vendored
Normal file
@ -0,0 +1,73 @@
|
||||
{{>licenseInfo}}
|
||||
{{#models}}{{#model}}
|
||||
|
||||
#include "{{classname}}.h"
|
||||
|
||||
{{#modelNamespaceDeclarations}}
|
||||
namespace {{this}} {
|
||||
{{/modelNamespaceDeclarations}}
|
||||
|
||||
{{classname}}::{{classname}}()
|
||||
{
|
||||
{{#vars}}{{^isContainer}}{{#isPrimitiveType}}m_{{name}} = {{{defaultValue}}};
|
||||
{{/isPrimitiveType}}{{^isPrimitiveType}}{{#isString}}m_{{name}} = {{{defaultValue}}};
|
||||
{{/isString}}{{#isDateTime}}m_{{name}} = {{{defaultValue}}};
|
||||
{{/isDateTime}}{{/isPrimitiveType}}{{/isContainer}}{{^required}}m_{{name}}IsSet = false;
|
||||
{{/required}}{{/vars}}
|
||||
}
|
||||
|
||||
{{classname}}::~{{classname}}()
|
||||
{
|
||||
}
|
||||
|
||||
void {{classname}}::validate()
|
||||
{
|
||||
// TODO: implement validation
|
||||
}
|
||||
|
||||
void to_json(nlohmann::json& j, const {{classname}}& o)
|
||||
{
|
||||
j = nlohmann::json();
|
||||
{{#vars}}
|
||||
{{#required}}j["{{baseName}}"] = o.m_{{name}};{{/required}}{{^required}}if(o.{{nameInCamelCase}}IsSet(){{#isContainer}} || !o.m_{{name}}.empty(){{/isContainer}})
|
||||
j["{{baseName}}"] = o.m_{{name}};{{/required}}
|
||||
{{/vars}}
|
||||
}
|
||||
|
||||
void from_json(const nlohmann::json& j, {{classname}}& o)
|
||||
{
|
||||
{{#vars}}
|
||||
{{#required}}j.at("{{baseName}}").get_to(o.m_{{name}});{{/required}}{{^required}}if(j.find("{{baseName}}") != j.end())
|
||||
{
|
||||
j.at("{{baseName}}").get_to(o.m_{{name}});
|
||||
o.m_{{name}}IsSet = true;
|
||||
} {{/required}}
|
||||
{{/vars}}
|
||||
}
|
||||
|
||||
{{#vars}}{{{dataType}}}{{#isContainer}}&{{/isContainer}} {{classname}}::{{getter}}(){{^isContainer}} const{{/isContainer}}
|
||||
{
|
||||
return m_{{name}};
|
||||
}
|
||||
void {{classname}}::{{setter}}({{{dataType}}} const{{^isPrimitiveType}}&{{/isPrimitiveType}} value)
|
||||
{
|
||||
m_{{name}} = value;{{^required}}
|
||||
m_{{name}}IsSet = true;{{/required}}
|
||||
}
|
||||
{{^required}}bool {{classname}}::{{nameInCamelCase}}IsSet() const
|
||||
{
|
||||
return m_{{name}}IsSet;
|
||||
}
|
||||
void {{classname}}::unset{{name}}()
|
||||
{
|
||||
m_{{name}}IsSet = false;
|
||||
}
|
||||
{{/required}}
|
||||
{{/vars}}
|
||||
|
||||
{{#modelNamespaceDeclarations}}
|
||||
}
|
||||
{{/modelNamespaceDeclarations}}
|
||||
|
||||
{{/model}}
|
||||
{{/models}}
|
43
modules/openapi-generator/src/main/resources/cpp-oatpp-server/model-struct-header.mustache
vendored
Normal file
43
modules/openapi-generator/src/main/resources/cpp-oatpp-server/model-struct-header.mustache
vendored
Normal file
@ -0,0 +1,43 @@
|
||||
{{>licenseInfo}}
|
||||
{{#models}}{{#model}}/*
|
||||
* {{classname}}.h
|
||||
*
|
||||
* {{description}}
|
||||
*/
|
||||
|
||||
#ifndef {{classname}}_H_
|
||||
#define {{classname}}_H_
|
||||
|
||||
{{{defaultInclude}}}
|
||||
{{#imports}}{{{this}}}
|
||||
{{/imports}}
|
||||
#include <nlohmann/json.hpp>
|
||||
{{#hasOptional}}#include <pistache/optional.h>{{/hasOptional}}
|
||||
|
||||
{{#modelNamespaceDeclarations}}
|
||||
namespace {{this}} {
|
||||
{{/modelNamespaceDeclarations}}
|
||||
|
||||
struct {{classname}}
|
||||
{
|
||||
{{#vars}}
|
||||
{{^required}}Pistache::Optional<{{/required}}{{{dataType}}}{{^required}}>{{/required}} {{name}};
|
||||
{{/vars}}
|
||||
|
||||
bool operator==(const {{classname}}& other) const;
|
||||
bool operator!=(const {{classname}}& other) const;
|
||||
|
||||
nlohmann::json to_json() const;
|
||||
static {{classname}} from_json(const nlohmann::json& j);
|
||||
};
|
||||
|
||||
void to_json(nlohmann::json& j, const {{classname}}& o);
|
||||
void from_json(const nlohmann::json& j, {{classname}}& o);
|
||||
|
||||
{{#modelNamespaceDeclarations}}
|
||||
} // {{this}}
|
||||
{{/modelNamespaceDeclarations}}
|
||||
|
||||
#endif /* {{classname}}_H_ */
|
||||
{{/model}}
|
||||
{{/models}}
|
59
modules/openapi-generator/src/main/resources/cpp-oatpp-server/model-struct-source.mustache
vendored
Normal file
59
modules/openapi-generator/src/main/resources/cpp-oatpp-server/model-struct-source.mustache
vendored
Normal file
@ -0,0 +1,59 @@
|
||||
{{>licenseInfo}}
|
||||
{{#models}}{{#model}}
|
||||
|
||||
#include "{{classname}}.h"
|
||||
|
||||
{{#modelNamespaceDeclarations}}
|
||||
namespace {{this}} {
|
||||
{{/modelNamespaceDeclarations}}
|
||||
|
||||
nlohmann::json {{classname}}::to_json() const
|
||||
{
|
||||
nlohmann::json j;
|
||||
{{#modelNamespaceDeclarations}}::{{this}}{{/modelNamespaceDeclarations}}::to_json(j, *this);
|
||||
return j;
|
||||
}
|
||||
|
||||
{{classname}} {{classname}}::from_json(const nlohmann::json& j)
|
||||
{
|
||||
{{classname}} o{};
|
||||
{{#modelNamespaceDeclarations}}::{{this}}{{/modelNamespaceDeclarations}}::from_json(j, o);
|
||||
return o;
|
||||
}
|
||||
|
||||
bool {{classname}}::operator==(const {{classname}}& other) const
|
||||
{
|
||||
return {{#vars}}{{name}} == other.{{name}}{{^-last}} && {{/-last}}{{/vars}};
|
||||
}
|
||||
|
||||
bool {{classname}}::operator!=(const {{classname}}& other) const
|
||||
{
|
||||
return !(*this == other);
|
||||
}
|
||||
|
||||
void to_json(nlohmann::json& j, const {{classname}}& o)
|
||||
{
|
||||
{{#vars}}
|
||||
{{^required}}if (!o.{{name}}.isEmpty()){{/required}}
|
||||
j["{{baseName}}"] = o.{{name}}{{^required}}.get(){{/required}};
|
||||
{{/vars}}
|
||||
}
|
||||
|
||||
void from_json(const nlohmann::json& j, {{classname}}& o)
|
||||
{
|
||||
{{#vars}}
|
||||
{{#required}}j.at("{{baseName}}").get_to(o.{{name}});{{/required}}
|
||||
{{^required}}if (j.find("{{baseName}}") != j.end()) {
|
||||
{{{dataType}}} temporary_{{name}};
|
||||
j.at("{{baseName}}").get_to(temporary_{{name}});
|
||||
o.{{name}} = Pistache::Some(temporary_{{name}});
|
||||
}{{/required}}
|
||||
{{/vars}}
|
||||
}
|
||||
|
||||
{{#modelNamespaceDeclarations}}
|
||||
} // {{this}}
|
||||
{{/modelNamespaceDeclarations}}
|
||||
|
||||
{{/model}}
|
||||
{{/models}}
|
23
samples/server/petstore/cpp-oatpp/.openapi-generator-ignore
Normal file
23
samples/server/petstore/cpp-oatpp/.openapi-generator-ignore
Normal file
@ -0,0 +1,23 @@
|
||||
# OpenAPI Generator Ignore
|
||||
# Generated by openapi-generator https://github.com/openapitools/openapi-generator
|
||||
|
||||
# Use this file to prevent files from being overwritten by the generator.
|
||||
# The patterns follow closely to .gitignore or .dockerignore.
|
||||
|
||||
# As an example, the C# client generator defines ApiClient.cs.
|
||||
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line:
|
||||
#ApiClient.cs
|
||||
|
||||
# You can match any string of characters against a directory, file or extension with a single asterisk (*):
|
||||
#foo/*/qux
|
||||
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux
|
||||
|
||||
# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
|
||||
#foo/**/qux
|
||||
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux
|
||||
|
||||
# You can also negate patterns with an exclamation (!).
|
||||
# For example, you can ignore all files in a docs folder with the file extension .md:
|
||||
#docs/*.md
|
||||
# Then explicitly reverse the ignore rule for a single file:
|
||||
#!docs/README.md
|
33
samples/server/petstore/cpp-oatpp/.openapi-generator/FILES
Normal file
33
samples/server/petstore/cpp-oatpp/.openapi-generator/FILES
Normal file
@ -0,0 +1,33 @@
|
||||
CMakeLists.txt
|
||||
README.md
|
||||
api/PetApi.cpp
|
||||
api/PetApi.h
|
||||
api/StoreApi.cpp
|
||||
api/StoreApi.h
|
||||
api/UserApi.cpp
|
||||
api/UserApi.h
|
||||
impl/PetApiImpl.cpp
|
||||
impl/PetApiImpl.h
|
||||
impl/StoreApiImpl.cpp
|
||||
impl/StoreApiImpl.h
|
||||
impl/UserApiImpl.cpp
|
||||
impl/UserApiImpl.h
|
||||
main-api-server.cpp
|
||||
model/ApiResponse.cpp
|
||||
model/ApiResponse.h
|
||||
model/Category.cpp
|
||||
model/Category.h
|
||||
model/Helpers.cpp
|
||||
model/Helpers.h
|
||||
model/Inline_object.cpp
|
||||
model/Inline_object.h
|
||||
model/Inline_object_1.cpp
|
||||
model/Inline_object_1.h
|
||||
model/Order.cpp
|
||||
model/Order.h
|
||||
model/Pet.cpp
|
||||
model/Pet.h
|
||||
model/Tag.cpp
|
||||
model/Tag.h
|
||||
model/User.cpp
|
||||
model/User.h
|
@ -0,0 +1 @@
|
||||
5.0.0-SNAPSHOT
|
37
samples/server/petstore/cpp-oatpp/CMakeLists.txt
Normal file
37
samples/server/petstore/cpp-oatpp/CMakeLists.txt
Normal file
@ -0,0 +1,37 @@
|
||||
cmake_minimum_required (VERSION 3.2)
|
||||
|
||||
project(api-server)
|
||||
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -pg -g3" )
|
||||
|
||||
include(ExternalProject)
|
||||
|
||||
set(EXTERNAL_INSTALL_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/external)
|
||||
|
||||
ExternalProject_Add(PISTACHE
|
||||
GIT_REPOSITORY https://github.com/oktal/pistache.git
|
||||
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${EXTERNAL_INSTALL_LOCATION}
|
||||
)
|
||||
|
||||
ExternalProject_Add(NLOHMANN
|
||||
GIT_REPOSITORY https://github.com/nlohmann/json.git
|
||||
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${EXTERNAL_INSTALL_LOCATION}
|
||||
|
||||
)
|
||||
include_directories(${EXTERNAL_INSTALL_LOCATION}/include)
|
||||
link_directories(${EXTERNAL_INSTALL_LOCATION}/lib)
|
||||
|
||||
include_directories(model)
|
||||
include_directories(api)
|
||||
include_directories(impl)
|
||||
|
||||
file(GLOB SRCS
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/api/*.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/impl/*.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/model/*.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/*.cpp
|
||||
)
|
||||
|
||||
add_executable(${PROJECT_NAME} ${SRCS} )
|
||||
add_dependencies(${PROJECT_NAME} PISTACHE NLOHMANN)
|
||||
target_link_libraries(${PROJECT_NAME} pistache pthread)
|
48
samples/server/petstore/cpp-oatpp/README.md
Normal file
48
samples/server/petstore/cpp-oatpp/README.md
Normal file
@ -0,0 +1,48 @@
|
||||
# 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++](http://github.com/oatpp/oatpp)
|
||||
- [JSON for Modern C++](https://github.com/nlohmann/json/#integration): Please download the `json.hpp` file and
|
||||
put it under the model/nlohmann folder
|
||||
|
||||
## Namespaces
|
||||
org.openapitools.server.api
|
||||
org.openapitools.server.model
|
236
samples/server/petstore/cpp-oatpp/api/PetApi.cpp
Normal file
236
samples/server/petstore/cpp-oatpp/api/PetApi.cpp
Normal file
@ -0,0 +1,236 @@
|
||||
/**
|
||||
* 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 "PetApi.h"
|
||||
#include "Helpers.h"
|
||||
|
||||
namespace org {
|
||||
namespace openapitools {
|
||||
namespace server {
|
||||
namespace api {
|
||||
|
||||
using namespace org::openapitools::server::helpers;
|
||||
using namespace org::openapitools::server::model;
|
||||
|
||||
PetApi::PetApi(std::shared_ptr<Pistache::Rest::Router> rtr) {
|
||||
router = rtr;
|
||||
}
|
||||
|
||||
void PetApi::init() {
|
||||
setupRoutes();
|
||||
}
|
||||
|
||||
void PetApi::setupRoutes() {
|
||||
using namespace Pistache::Rest;
|
||||
|
||||
Routes::Post(*router, base + "/pet", Routes::bind(&PetApi::add_pet_handler, this));
|
||||
Routes::Delete(*router, base + "/pet/:petId", Routes::bind(&PetApi::delete_pet_handler, this));
|
||||
Routes::Get(*router, base + "/pet/findByStatus", Routes::bind(&PetApi::find_pets_by_status_handler, this));
|
||||
Routes::Get(*router, base + "/pet/findByTags", Routes::bind(&PetApi::find_pets_by_tags_handler, this));
|
||||
Routes::Get(*router, base + "/pet/:petId", Routes::bind(&PetApi::get_pet_by_id_handler, this));
|
||||
Routes::Put(*router, base + "/pet", Routes::bind(&PetApi::update_pet_handler, this));
|
||||
Routes::Post(*router, base + "/pet/:petId", Routes::bind(&PetApi::update_pet_with_form_handler, this));
|
||||
Routes::Post(*router, base + "/pet/:petId/uploadImage", Routes::bind(&PetApi::upload_file_handler, this));
|
||||
|
||||
// Default handler, called when a route is not found
|
||||
router->addCustomHandler(Routes::bind(&PetApi::pet_api_default_handler, this));
|
||||
}
|
||||
|
||||
void PetApi::add_pet_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response) {
|
||||
|
||||
// Getting the body param
|
||||
|
||||
Pet pet;
|
||||
|
||||
try {
|
||||
nlohmann::json::parse(request.body()).get_to(pet);
|
||||
this->add_pet(pet, response);
|
||||
} catch (nlohmann::detail::exception &e) {
|
||||
//send a 400 error
|
||||
response.send(Pistache::Http::Code::Bad_Request, e.what());
|
||||
return;
|
||||
} catch (Pistache::Http::HttpError &e) {
|
||||
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
|
||||
return;
|
||||
} catch (std::exception &e) {
|
||||
//send a 500 error
|
||||
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
void PetApi::delete_pet_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response) {
|
||||
// Getting the path params
|
||||
auto petId = request.param(":petId").as<int64_t>();
|
||||
|
||||
// Getting the header params
|
||||
auto apiKey = request.headers().tryGetRaw("api_key");
|
||||
|
||||
try {
|
||||
this->delete_pet(petId, apiKey, response);
|
||||
} catch (nlohmann::detail::exception &e) {
|
||||
//send a 400 error
|
||||
response.send(Pistache::Http::Code::Bad_Request, e.what());
|
||||
return;
|
||||
} catch (Pistache::Http::HttpError &e) {
|
||||
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
|
||||
return;
|
||||
} catch (std::exception &e) {
|
||||
//send a 500 error
|
||||
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
void PetApi::find_pets_by_status_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response) {
|
||||
|
||||
// Getting the query params
|
||||
auto statusQuery = request.query().get("status");
|
||||
Pistache::Optional<std::vector<std::string>> status;
|
||||
if(!statusQuery.isEmpty()){
|
||||
std::vector<std::string> valueQuery_instance;
|
||||
if(fromStringValue(statusQuery.get(), valueQuery_instance)){
|
||||
status = Pistache::Some(valueQuery_instance);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
this->find_pets_by_status(status, response);
|
||||
} catch (nlohmann::detail::exception &e) {
|
||||
//send a 400 error
|
||||
response.send(Pistache::Http::Code::Bad_Request, e.what());
|
||||
return;
|
||||
} catch (Pistache::Http::HttpError &e) {
|
||||
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
|
||||
return;
|
||||
} catch (std::exception &e) {
|
||||
//send a 500 error
|
||||
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
void PetApi::find_pets_by_tags_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response) {
|
||||
|
||||
// Getting the query params
|
||||
auto tagsQuery = request.query().get("tags");
|
||||
Pistache::Optional<std::vector<std::string>> tags;
|
||||
if(!tagsQuery.isEmpty()){
|
||||
std::vector<std::string> valueQuery_instance;
|
||||
if(fromStringValue(tagsQuery.get(), valueQuery_instance)){
|
||||
tags = Pistache::Some(valueQuery_instance);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
this->find_pets_by_tags(tags, response);
|
||||
} catch (nlohmann::detail::exception &e) {
|
||||
//send a 400 error
|
||||
response.send(Pistache::Http::Code::Bad_Request, e.what());
|
||||
return;
|
||||
} catch (Pistache::Http::HttpError &e) {
|
||||
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
|
||||
return;
|
||||
} catch (std::exception &e) {
|
||||
//send a 500 error
|
||||
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
void PetApi::get_pet_by_id_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response) {
|
||||
// Getting the path params
|
||||
auto petId = request.param(":petId").as<int64_t>();
|
||||
|
||||
try {
|
||||
this->get_pet_by_id(petId, response);
|
||||
} catch (nlohmann::detail::exception &e) {
|
||||
//send a 400 error
|
||||
response.send(Pistache::Http::Code::Bad_Request, e.what());
|
||||
return;
|
||||
} catch (Pistache::Http::HttpError &e) {
|
||||
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
|
||||
return;
|
||||
} catch (std::exception &e) {
|
||||
//send a 500 error
|
||||
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
void PetApi::update_pet_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response) {
|
||||
|
||||
// Getting the body param
|
||||
|
||||
Pet pet;
|
||||
|
||||
try {
|
||||
nlohmann::json::parse(request.body()).get_to(pet);
|
||||
this->update_pet(pet, response);
|
||||
} catch (nlohmann::detail::exception &e) {
|
||||
//send a 400 error
|
||||
response.send(Pistache::Http::Code::Bad_Request, e.what());
|
||||
return;
|
||||
} catch (Pistache::Http::HttpError &e) {
|
||||
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
|
||||
return;
|
||||
} catch (std::exception &e) {
|
||||
//send a 500 error
|
||||
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
void PetApi::update_pet_with_form_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response) {
|
||||
try {
|
||||
this->update_pet_with_form(request, response);
|
||||
} catch (nlohmann::detail::exception &e) {
|
||||
//send a 400 error
|
||||
response.send(Pistache::Http::Code::Bad_Request, e.what());
|
||||
return;
|
||||
} catch (Pistache::Http::HttpError &e) {
|
||||
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
|
||||
return;
|
||||
} catch (std::exception &e) {
|
||||
//send a 500 error
|
||||
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
void PetApi::upload_file_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response) {
|
||||
try {
|
||||
this->upload_file(request, response);
|
||||
} catch (nlohmann::detail::exception &e) {
|
||||
//send a 400 error
|
||||
response.send(Pistache::Http::Code::Bad_Request, e.what());
|
||||
return;
|
||||
} catch (Pistache::Http::HttpError &e) {
|
||||
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
|
||||
return;
|
||||
} catch (std::exception &e) {
|
||||
//send a 500 error
|
||||
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void PetApi::pet_api_default_handler(const Pistache::Rest::Request &, Pistache::Http::ResponseWriter response) {
|
||||
response.send(Pistache::Http::Code::Not_Found, "The requested method does not exist");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
141
samples/server/petstore/cpp-oatpp/api/PetApi.h
Normal file
141
samples/server/petstore/cpp-oatpp/api/PetApi.h
Normal file
@ -0,0 +1,141 @@
|
||||
/**
|
||||
* 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 <pistache/http.h>
|
||||
#include <pistache/router.h>
|
||||
#include <pistache/http_headers.h>
|
||||
#include <pistache/optional.h>
|
||||
|
||||
|
||||
#include "ApiResponse.h"
|
||||
#include "Pet.h"
|
||||
#include <string>
|
||||
|
||||
namespace org {
|
||||
namespace openapitools {
|
||||
namespace server {
|
||||
namespace api {
|
||||
|
||||
using namespace org::openapitools::server::model;
|
||||
|
||||
class PetApi {
|
||||
public:
|
||||
PetApi(std::shared_ptr<Pistache::Rest::Router>);
|
||||
virtual ~PetApi() {}
|
||||
void init();
|
||||
|
||||
const std::string base = "/v2";
|
||||
|
||||
private:
|
||||
void setupRoutes();
|
||||
|
||||
void add_pet_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response);
|
||||
void delete_pet_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response);
|
||||
void find_pets_by_status_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response);
|
||||
void find_pets_by_tags_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response);
|
||||
void get_pet_by_id_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response);
|
||||
void update_pet_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response);
|
||||
void update_pet_with_form_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response);
|
||||
void upload_file_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response);
|
||||
void pet_api_default_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response);
|
||||
|
||||
std::shared_ptr<Pistache::Rest::Router> router;
|
||||
|
||||
/// <summary>
|
||||
/// Add a new pet to the store
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
///
|
||||
/// </remarks>
|
||||
/// <param name="pet">Pet object that needs to be added to the store</param>
|
||||
virtual void add_pet(const Pet &pet, Pistache::Http::ResponseWriter &response) = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Deletes a pet
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
///
|
||||
/// </remarks>
|
||||
/// <param name="petId">Pet id to delete</param>
|
||||
/// <param name="apiKey"> (optional, default to "")</param>
|
||||
virtual void delete_pet(const int64_t &petId, const Oatpp::Optional<Oatpp::Http::Header::Raw> &apiKey, Pistache::Http::ResponseWriter &response) = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Finds Pets by status
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Multiple status values can be provided with comma separated strings
|
||||
/// </remarks>
|
||||
/// <param name="status">Status values that need to be considered for filter</param>
|
||||
virtual void find_pets_by_status(const Oatpp::Optional<std::vector<std::string>> &status, Pistache::Http::ResponseWriter &response) = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Finds Pets by tags
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
|
||||
/// </remarks>
|
||||
/// <param name="tags">Tags to filter by</param>
|
||||
virtual void find_pets_by_tags(const Oatpp::Optional<std::vector<std::string>> &tags, Pistache::Http::ResponseWriter &response) = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Find pet by ID
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Returns a single pet
|
||||
/// </remarks>
|
||||
/// <param name="petId">ID of pet to return</param>
|
||||
virtual void get_pet_by_id(const int64_t &petId, Pistache::Http::ResponseWriter &response) = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Update an existing pet
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
///
|
||||
/// </remarks>
|
||||
/// <param name="pet">Pet object that needs to be added to the store</param>
|
||||
virtual void update_pet(const Pet &pet, Pistache::Http::ResponseWriter &response) = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Updates a pet in the store with form data
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
///
|
||||
/// </remarks>
|
||||
virtual void update_pet_with_form(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter &response) = 0;
|
||||
|
||||
/// <summary>
|
||||
/// uploads an image
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
///
|
||||
/// </remarks>
|
||||
virtual void upload_file(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter &response) = 0;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* PetApi_H_ */
|
||||
|
134
samples/server/petstore/cpp-oatpp/api/StoreApi.cpp
Normal file
134
samples/server/petstore/cpp-oatpp/api/StoreApi.cpp
Normal file
@ -0,0 +1,134 @@
|
||||
/**
|
||||
* 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 "StoreApi.h"
|
||||
#include "Helpers.h"
|
||||
|
||||
namespace org {
|
||||
namespace openapitools {
|
||||
namespace server {
|
||||
namespace api {
|
||||
|
||||
using namespace org::openapitools::server::helpers;
|
||||
using namespace org::openapitools::server::model;
|
||||
|
||||
StoreApi::StoreApi(std::shared_ptr<Pistache::Rest::Router> rtr) {
|
||||
router = rtr;
|
||||
}
|
||||
|
||||
void StoreApi::init() {
|
||||
setupRoutes();
|
||||
}
|
||||
|
||||
void StoreApi::setupRoutes() {
|
||||
using namespace Pistache::Rest;
|
||||
|
||||
Routes::Delete(*router, base + "/store/order/:orderId", Routes::bind(&StoreApi::delete_order_handler, this));
|
||||
Routes::Get(*router, base + "/store/inventory", Routes::bind(&StoreApi::get_inventory_handler, this));
|
||||
Routes::Get(*router, base + "/store/order/:orderId", Routes::bind(&StoreApi::get_order_by_id_handler, this));
|
||||
Routes::Post(*router, base + "/store/order", Routes::bind(&StoreApi::place_order_handler, this));
|
||||
|
||||
// Default handler, called when a route is not found
|
||||
router->addCustomHandler(Routes::bind(&StoreApi::store_api_default_handler, this));
|
||||
}
|
||||
|
||||
void StoreApi::delete_order_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response) {
|
||||
// Getting the path params
|
||||
auto orderId = request.param(":orderId").as<std::string>();
|
||||
|
||||
try {
|
||||
this->delete_order(orderId, response);
|
||||
} catch (nlohmann::detail::exception &e) {
|
||||
//send a 400 error
|
||||
response.send(Pistache::Http::Code::Bad_Request, e.what());
|
||||
return;
|
||||
} catch (Pistache::Http::HttpError &e) {
|
||||
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
|
||||
return;
|
||||
} catch (std::exception &e) {
|
||||
//send a 500 error
|
||||
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
void StoreApi::get_inventory_handler(const Pistache::Rest::Request &, Pistache::Http::ResponseWriter response) {
|
||||
|
||||
try {
|
||||
this->get_inventory(response);
|
||||
} catch (nlohmann::detail::exception &e) {
|
||||
//send a 400 error
|
||||
response.send(Pistache::Http::Code::Bad_Request, e.what());
|
||||
return;
|
||||
} catch (Pistache::Http::HttpError &e) {
|
||||
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
|
||||
return;
|
||||
} catch (std::exception &e) {
|
||||
//send a 500 error
|
||||
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
void StoreApi::get_order_by_id_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response) {
|
||||
// Getting the path params
|
||||
auto orderId = request.param(":orderId").as<int64_t>();
|
||||
|
||||
try {
|
||||
this->get_order_by_id(orderId, response);
|
||||
} catch (nlohmann::detail::exception &e) {
|
||||
//send a 400 error
|
||||
response.send(Pistache::Http::Code::Bad_Request, e.what());
|
||||
return;
|
||||
} catch (Pistache::Http::HttpError &e) {
|
||||
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
|
||||
return;
|
||||
} catch (std::exception &e) {
|
||||
//send a 500 error
|
||||
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
void StoreApi::place_order_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response) {
|
||||
|
||||
// Getting the body param
|
||||
|
||||
Order order;
|
||||
|
||||
try {
|
||||
nlohmann::json::parse(request.body()).get_to(order);
|
||||
this->place_order(order, response);
|
||||
} catch (nlohmann::detail::exception &e) {
|
||||
//send a 400 error
|
||||
response.send(Pistache::Http::Code::Bad_Request, e.what());
|
||||
return;
|
||||
} catch (Pistache::Http::HttpError &e) {
|
||||
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
|
||||
return;
|
||||
} catch (std::exception &e) {
|
||||
//send a 500 error
|
||||
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void StoreApi::store_api_default_handler(const Pistache::Rest::Request &, Pistache::Http::ResponseWriter response) {
|
||||
response.send(Pistache::Http::Code::Not_Found, "The requested method does not exist");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
101
samples/server/petstore/cpp-oatpp/api/StoreApi.h
Normal file
101
samples/server/petstore/cpp-oatpp/api/StoreApi.h
Normal file
@ -0,0 +1,101 @@
|
||||
/**
|
||||
* 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 <pistache/http.h>
|
||||
#include <pistache/router.h>
|
||||
#include <pistache/http_headers.h>
|
||||
#include <pistache/optional.h>
|
||||
|
||||
|
||||
#include "Order.h"
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
namespace org {
|
||||
namespace openapitools {
|
||||
namespace server {
|
||||
namespace api {
|
||||
|
||||
using namespace org::openapitools::server::model;
|
||||
|
||||
class StoreApi {
|
||||
public:
|
||||
StoreApi(std::shared_ptr<Pistache::Rest::Router>);
|
||||
virtual ~StoreApi() {}
|
||||
void init();
|
||||
|
||||
const std::string base = "/v2";
|
||||
|
||||
private:
|
||||
void setupRoutes();
|
||||
|
||||
void delete_order_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response);
|
||||
void get_inventory_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response);
|
||||
void get_order_by_id_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response);
|
||||
void place_order_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response);
|
||||
void store_api_default_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response);
|
||||
|
||||
std::shared_ptr<Pistache::Rest::Router> router;
|
||||
|
||||
/// <summary>
|
||||
/// Delete purchase order by ID
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors
|
||||
/// </remarks>
|
||||
/// <param name="orderId">ID of the order that needs to be deleted</param>
|
||||
virtual void delete_order(const std::string &orderId, Pistache::Http::ResponseWriter &response) = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Returns pet inventories by status
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Returns a map of status codes to quantities
|
||||
/// </remarks>
|
||||
virtual void get_inventory(Pistache::Http::ResponseWriter &response) = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Find purchase order by ID
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions
|
||||
/// </remarks>
|
||||
/// <param name="orderId">ID of pet that needs to be fetched</param>
|
||||
virtual void get_order_by_id(const int64_t &orderId, Pistache::Http::ResponseWriter &response) = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Place an order for a pet
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
///
|
||||
/// </remarks>
|
||||
/// <param name="order">order placed for purchasing the pet</param>
|
||||
virtual void place_order(const Order &order, Pistache::Http::ResponseWriter &response) = 0;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* StoreApi_H_ */
|
||||
|
243
samples/server/petstore/cpp-oatpp/api/UserApi.cpp
Normal file
243
samples/server/petstore/cpp-oatpp/api/UserApi.cpp
Normal file
@ -0,0 +1,243 @@
|
||||
/**
|
||||
* 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 "UserApi.h"
|
||||
#include "Helpers.h"
|
||||
|
||||
namespace org {
|
||||
namespace openapitools {
|
||||
namespace server {
|
||||
namespace api {
|
||||
|
||||
using namespace org::openapitools::server::helpers;
|
||||
using namespace org::openapitools::server::model;
|
||||
|
||||
UserApi::UserApi(std::shared_ptr<Pistache::Rest::Router> rtr) {
|
||||
router = rtr;
|
||||
}
|
||||
|
||||
void UserApi::init() {
|
||||
setupRoutes();
|
||||
}
|
||||
|
||||
void UserApi::setupRoutes() {
|
||||
using namespace Pistache::Rest;
|
||||
|
||||
Routes::Post(*router, base + "/user", Routes::bind(&UserApi::create_user_handler, this));
|
||||
Routes::Post(*router, base + "/user/createWithArray", Routes::bind(&UserApi::create_users_with_array_input_handler, this));
|
||||
Routes::Post(*router, base + "/user/createWithList", Routes::bind(&UserApi::create_users_with_list_input_handler, this));
|
||||
Routes::Delete(*router, base + "/user/:username", Routes::bind(&UserApi::delete_user_handler, this));
|
||||
Routes::Get(*router, base + "/user/:username", Routes::bind(&UserApi::get_user_by_name_handler, this));
|
||||
Routes::Get(*router, base + "/user/login", Routes::bind(&UserApi::login_user_handler, this));
|
||||
Routes::Get(*router, base + "/user/logout", Routes::bind(&UserApi::logout_user_handler, this));
|
||||
Routes::Put(*router, base + "/user/:username", Routes::bind(&UserApi::update_user_handler, this));
|
||||
|
||||
// Default handler, called when a route is not found
|
||||
router->addCustomHandler(Routes::bind(&UserApi::user_api_default_handler, this));
|
||||
}
|
||||
|
||||
void UserApi::create_user_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response) {
|
||||
|
||||
// Getting the body param
|
||||
|
||||
User user;
|
||||
|
||||
try {
|
||||
nlohmann::json::parse(request.body()).get_to(user);
|
||||
this->create_user(user, response);
|
||||
} catch (nlohmann::detail::exception &e) {
|
||||
//send a 400 error
|
||||
response.send(Pistache::Http::Code::Bad_Request, e.what());
|
||||
return;
|
||||
} catch (Pistache::Http::HttpError &e) {
|
||||
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
|
||||
return;
|
||||
} catch (std::exception &e) {
|
||||
//send a 500 error
|
||||
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
void UserApi::create_users_with_array_input_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response) {
|
||||
|
||||
// Getting the body param
|
||||
std::vector<User> user;
|
||||
|
||||
try {
|
||||
nlohmann::json::parse(request.body()).get_to(user);
|
||||
this->create_users_with_array_input(user, response);
|
||||
} catch (nlohmann::detail::exception &e) {
|
||||
//send a 400 error
|
||||
response.send(Pistache::Http::Code::Bad_Request, e.what());
|
||||
return;
|
||||
} catch (Pistache::Http::HttpError &e) {
|
||||
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
|
||||
return;
|
||||
} catch (std::exception &e) {
|
||||
//send a 500 error
|
||||
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
void UserApi::create_users_with_list_input_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response) {
|
||||
|
||||
// Getting the body param
|
||||
std::vector<User> user;
|
||||
|
||||
try {
|
||||
nlohmann::json::parse(request.body()).get_to(user);
|
||||
this->create_users_with_list_input(user, response);
|
||||
} catch (nlohmann::detail::exception &e) {
|
||||
//send a 400 error
|
||||
response.send(Pistache::Http::Code::Bad_Request, e.what());
|
||||
return;
|
||||
} catch (Pistache::Http::HttpError &e) {
|
||||
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
|
||||
return;
|
||||
} catch (std::exception &e) {
|
||||
//send a 500 error
|
||||
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
void UserApi::delete_user_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response) {
|
||||
// Getting the path params
|
||||
auto username = request.param(":username").as<std::string>();
|
||||
|
||||
try {
|
||||
this->delete_user(username, response);
|
||||
} catch (nlohmann::detail::exception &e) {
|
||||
//send a 400 error
|
||||
response.send(Pistache::Http::Code::Bad_Request, e.what());
|
||||
return;
|
||||
} catch (Pistache::Http::HttpError &e) {
|
||||
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
|
||||
return;
|
||||
} catch (std::exception &e) {
|
||||
//send a 500 error
|
||||
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
void UserApi::get_user_by_name_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response) {
|
||||
// Getting the path params
|
||||
auto username = request.param(":username").as<std::string>();
|
||||
|
||||
try {
|
||||
this->get_user_by_name(username, response);
|
||||
} catch (nlohmann::detail::exception &e) {
|
||||
//send a 400 error
|
||||
response.send(Pistache::Http::Code::Bad_Request, e.what());
|
||||
return;
|
||||
} catch (Pistache::Http::HttpError &e) {
|
||||
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
|
||||
return;
|
||||
} catch (std::exception &e) {
|
||||
//send a 500 error
|
||||
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
void UserApi::login_user_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response) {
|
||||
|
||||
// Getting the query params
|
||||
auto usernameQuery = request.query().get("username");
|
||||
Pistache::Optional<std::string> username;
|
||||
if(!usernameQuery.isEmpty()){
|
||||
std::string valueQuery_instance;
|
||||
if(fromStringValue(usernameQuery.get(), valueQuery_instance)){
|
||||
username = Pistache::Some(valueQuery_instance);
|
||||
}
|
||||
}
|
||||
auto passwordQuery = request.query().get("password");
|
||||
Pistache::Optional<std::string> password;
|
||||
if(!passwordQuery.isEmpty()){
|
||||
std::string valueQuery_instance;
|
||||
if(fromStringValue(passwordQuery.get(), valueQuery_instance)){
|
||||
password = Pistache::Some(valueQuery_instance);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
this->login_user(username, password, response);
|
||||
} catch (nlohmann::detail::exception &e) {
|
||||
//send a 400 error
|
||||
response.send(Pistache::Http::Code::Bad_Request, e.what());
|
||||
return;
|
||||
} catch (Pistache::Http::HttpError &e) {
|
||||
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
|
||||
return;
|
||||
} catch (std::exception &e) {
|
||||
//send a 500 error
|
||||
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
void UserApi::logout_user_handler(const Pistache::Rest::Request &, Pistache::Http::ResponseWriter response) {
|
||||
|
||||
try {
|
||||
this->logout_user(response);
|
||||
} catch (nlohmann::detail::exception &e) {
|
||||
//send a 400 error
|
||||
response.send(Pistache::Http::Code::Bad_Request, e.what());
|
||||
return;
|
||||
} catch (Pistache::Http::HttpError &e) {
|
||||
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
|
||||
return;
|
||||
} catch (std::exception &e) {
|
||||
//send a 500 error
|
||||
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
void UserApi::update_user_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response) {
|
||||
// Getting the path params
|
||||
auto username = request.param(":username").as<std::string>();
|
||||
|
||||
// Getting the body param
|
||||
|
||||
User user;
|
||||
|
||||
try {
|
||||
nlohmann::json::parse(request.body()).get_to(user);
|
||||
this->update_user(username, user, response);
|
||||
} catch (nlohmann::detail::exception &e) {
|
||||
//send a 400 error
|
||||
response.send(Pistache::Http::Code::Bad_Request, e.what());
|
||||
return;
|
||||
} catch (Pistache::Http::HttpError &e) {
|
||||
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
|
||||
return;
|
||||
} catch (std::exception &e) {
|
||||
//send a 500 error
|
||||
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void UserApi::user_api_default_handler(const Pistache::Rest::Request &, Pistache::Http::ResponseWriter response) {
|
||||
response.send(Pistache::Http::Code::Not_Found, "The requested method does not exist");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
143
samples/server/petstore/cpp-oatpp/api/UserApi.h
Normal file
143
samples/server/petstore/cpp-oatpp/api/UserApi.h
Normal file
@ -0,0 +1,143 @@
|
||||
/**
|
||||
* 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 <pistache/http.h>
|
||||
#include <pistache/router.h>
|
||||
#include <pistache/http_headers.h>
|
||||
#include <pistache/optional.h>
|
||||
|
||||
|
||||
#include "User.h"
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace org {
|
||||
namespace openapitools {
|
||||
namespace server {
|
||||
namespace api {
|
||||
|
||||
using namespace org::openapitools::server::model;
|
||||
|
||||
class UserApi {
|
||||
public:
|
||||
UserApi(std::shared_ptr<Pistache::Rest::Router>);
|
||||
virtual ~UserApi() {}
|
||||
void init();
|
||||
|
||||
const std::string base = "/v2";
|
||||
|
||||
private:
|
||||
void setupRoutes();
|
||||
|
||||
void create_user_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response);
|
||||
void create_users_with_array_input_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response);
|
||||
void create_users_with_list_input_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response);
|
||||
void delete_user_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response);
|
||||
void get_user_by_name_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response);
|
||||
void login_user_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response);
|
||||
void logout_user_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response);
|
||||
void update_user_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response);
|
||||
void user_api_default_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response);
|
||||
|
||||
std::shared_ptr<Pistache::Rest::Router> router;
|
||||
|
||||
/// <summary>
|
||||
/// Create user
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This can only be done by the logged in user.
|
||||
/// </remarks>
|
||||
/// <param name="user">Created user object</param>
|
||||
virtual void create_user(const User &user, Pistache::Http::ResponseWriter &response) = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Creates list of users with given input array
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
///
|
||||
/// </remarks>
|
||||
/// <param name="user">List of user object</param>
|
||||
virtual void create_users_with_array_input(const std::vector<User> &user, Pistache::Http::ResponseWriter &response) = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Creates list of users with given input array
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
///
|
||||
/// </remarks>
|
||||
/// <param name="user">List of user object</param>
|
||||
virtual void create_users_with_list_input(const std::vector<User> &user, Pistache::Http::ResponseWriter &response) = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Delete user
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This can only be done by the logged in user.
|
||||
/// </remarks>
|
||||
/// <param name="username">The name that needs to be deleted</param>
|
||||
virtual void delete_user(const std::string &username, Pistache::Http::ResponseWriter &response) = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Get user by user name
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
///
|
||||
/// </remarks>
|
||||
/// <param name="username">The name that needs to be fetched. Use user1 for testing.</param>
|
||||
virtual void get_user_by_name(const std::string &username, Pistache::Http::ResponseWriter &response) = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Logs user into the system
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
///
|
||||
/// </remarks>
|
||||
/// <param name="username">The user name for login</param>
|
||||
/// <param name="password">The password for login in clear text</param>
|
||||
virtual void login_user(const Oatpp::Optional<std::string> &username, const Oatpp::Optional<std::string> &password, Pistache::Http::ResponseWriter &response) = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Logs out current logged in user session
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
///
|
||||
/// </remarks>
|
||||
virtual void logout_user(Pistache::Http::ResponseWriter &response) = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Updated user
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This can only be done by the logged in user.
|
||||
/// </remarks>
|
||||
/// <param name="username">name that need to be deleted</param>
|
||||
/// <param name="user">Updated user object</param>
|
||||
virtual void update_user(const std::string &username, const User &user, Pistache::Http::ResponseWriter &response) = 0;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* UserApi_H_ */
|
||||
|
55
samples/server/petstore/cpp-oatpp/impl/PetApiImpl.cpp
Normal file
55
samples/server/petstore/cpp-oatpp/impl/PetApiImpl.cpp
Normal file
@ -0,0 +1,55 @@
|
||||
/**
|
||||
* 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 "PetApiImpl.h"
|
||||
|
||||
namespace org {
|
||||
namespace openapitools {
|
||||
namespace server {
|
||||
namespace api {
|
||||
|
||||
using namespace org::openapitools::server::model;
|
||||
|
||||
PetApiImpl::PetApiImpl(std::shared_ptr<Pistache::Rest::Router> rtr)
|
||||
: PetApi(rtr)
|
||||
{ }
|
||||
|
||||
void PetApiImpl::add_pet(const Pet &pet, Pistache::Http::ResponseWriter &response) {
|
||||
response.send(Pistache::Http::Code::Ok, "Do some magic\n");
|
||||
}
|
||||
void PetApiImpl::delete_pet(const int64_t &petId, const Oatpp::Optional<Oatpp::Http::Header::Raw> &apiKey, Pistache::Http::ResponseWriter &response) {
|
||||
response.send(Pistache::Http::Code::Ok, "Do some magic\n");
|
||||
}
|
||||
void PetApiImpl::find_pets_by_status(const Oatpp::Optional<std::vector<std::string>> &status, Pistache::Http::ResponseWriter &response) {
|
||||
response.send(Pistache::Http::Code::Ok, "Do some magic\n");
|
||||
}
|
||||
void PetApiImpl::find_pets_by_tags(const Oatpp::Optional<std::vector<std::string>> &tags, Pistache::Http::ResponseWriter &response) {
|
||||
response.send(Pistache::Http::Code::Ok, "Do some magic\n");
|
||||
}
|
||||
void PetApiImpl::get_pet_by_id(const int64_t &petId, Pistache::Http::ResponseWriter &response) {
|
||||
response.send(Pistache::Http::Code::Ok, "Do some magic\n");
|
||||
}
|
||||
void PetApiImpl::update_pet(const Pet &pet, Pistache::Http::ResponseWriter &response) {
|
||||
response.send(Pistache::Http::Code::Ok, "Do some magic\n");
|
||||
}
|
||||
void PetApiImpl::update_pet_with_form(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter &response){
|
||||
response.send(Pistache::Http::Code::Ok, "Do some magic\n");
|
||||
}
|
||||
void PetApiImpl::upload_file(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter &response){
|
||||
response.send(Pistache::Http::Code::Ok, "Do some magic\n");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
66
samples/server/petstore/cpp-oatpp/impl/PetApiImpl.h
Normal file
66
samples/server/petstore/cpp-oatpp/impl/PetApiImpl.h
Normal file
@ -0,0 +1,66 @@
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* PetApiImpl.h
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef PET_API_IMPL_H_
|
||||
#define PET_API_IMPL_H_
|
||||
|
||||
|
||||
#include <pistache/endpoint.h>
|
||||
#include <pistache/http.h>
|
||||
#include <pistache/router.h>
|
||||
#include <memory>
|
||||
|
||||
#include <PetApi.h>
|
||||
|
||||
#include <pistache/optional.h>
|
||||
|
||||
#include "ApiResponse.h"
|
||||
#include "Pet.h"
|
||||
#include <string>
|
||||
|
||||
namespace org {
|
||||
namespace openapitools {
|
||||
namespace server {
|
||||
namespace api {
|
||||
|
||||
using namespace org::openapitools::server::model;
|
||||
|
||||
class PetApiImpl : public org::openapitools::server::api::PetApi {
|
||||
public:
|
||||
PetApiImpl(std::shared_ptr<Pistache::Rest::Router>);
|
||||
~PetApiImpl() {}
|
||||
|
||||
void add_pet(const Pet &pet, Pistache::Http::ResponseWriter &response);
|
||||
void delete_pet(const int64_t &petId, const Oatpp::Optional<Oatpp::Http::Header::Raw> &apiKey, Pistache::Http::ResponseWriter &response);
|
||||
void find_pets_by_status(const Oatpp::Optional<std::vector<std::string>> &status, Pistache::Http::ResponseWriter &response);
|
||||
void find_pets_by_tags(const Oatpp::Optional<std::vector<std::string>> &tags, Pistache::Http::ResponseWriter &response);
|
||||
void get_pet_by_id(const int64_t &petId, Pistache::Http::ResponseWriter &response);
|
||||
void update_pet(const Pet &pet, Pistache::Http::ResponseWriter &response);
|
||||
void update_pet_with_form(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter &response);
|
||||
void upload_file(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter &response);
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif
|
43
samples/server/petstore/cpp-oatpp/impl/StoreApiImpl.cpp
Normal file
43
samples/server/petstore/cpp-oatpp/impl/StoreApiImpl.cpp
Normal file
@ -0,0 +1,43 @@
|
||||
/**
|
||||
* 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 "StoreApiImpl.h"
|
||||
|
||||
namespace org {
|
||||
namespace openapitools {
|
||||
namespace server {
|
||||
namespace api {
|
||||
|
||||
using namespace org::openapitools::server::model;
|
||||
|
||||
StoreApiImpl::StoreApiImpl(std::shared_ptr<Pistache::Rest::Router> rtr)
|
||||
: StoreApi(rtr)
|
||||
{ }
|
||||
|
||||
void StoreApiImpl::delete_order(const std::string &orderId, Pistache::Http::ResponseWriter &response) {
|
||||
response.send(Pistache::Http::Code::Ok, "Do some magic\n");
|
||||
}
|
||||
void StoreApiImpl::get_inventory(Pistache::Http::ResponseWriter &response) {
|
||||
response.send(Pistache::Http::Code::Ok, "Do some magic\n");
|
||||
}
|
||||
void StoreApiImpl::get_order_by_id(const int64_t &orderId, Pistache::Http::ResponseWriter &response) {
|
||||
response.send(Pistache::Http::Code::Ok, "Do some magic\n");
|
||||
}
|
||||
void StoreApiImpl::place_order(const Order &order, Pistache::Http::ResponseWriter &response) {
|
||||
response.send(Pistache::Http::Code::Ok, "Do some magic\n");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
62
samples/server/petstore/cpp-oatpp/impl/StoreApiImpl.h
Normal file
62
samples/server/petstore/cpp-oatpp/impl/StoreApiImpl.h
Normal file
@ -0,0 +1,62 @@
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
/*
|
||||
* StoreApiImpl.h
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef STORE_API_IMPL_H_
|
||||
#define STORE_API_IMPL_H_
|
||||
|
||||
|
||||
#include <pistache/endpoint.h>
|
||||
#include <pistache/http.h>
|
||||
#include <pistache/router.h>
|
||||
#include <memory>
|
||||
|
||||
#include <StoreApi.h>
|
||||
|
||||
#include <pistache/optional.h>
|
||||
|
||||
#include "Order.h"
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
namespace org {
|
||||
namespace openapitools {
|
||||
namespace server {
|
||||
namespace api {
|
||||
|
||||
using namespace org::openapitools::server::model;
|
||||
|
||||
class StoreApiImpl : public org::openapitools::server::api::StoreApi {
|
||||
public:
|
||||
StoreApiImpl(std::shared_ptr<Pistache::Rest::Router>);
|
||||
~StoreApiImpl() {}
|
||||
|
||||
void delete_order(const std::string &orderId, Pistache::Http::ResponseWriter &response);
|
||||
void get_inventory(Pistache::Http::ResponseWriter &response);
|
||||
void get_order_by_id(const int64_t &orderId, Pistache::Http::ResponseWriter &response);
|
||||
void place_order(const Order &order, Pistache::Http::ResponseWriter &response);
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif
|
55
samples/server/petstore/cpp-oatpp/impl/UserApiImpl.cpp
Normal file
55
samples/server/petstore/cpp-oatpp/impl/UserApiImpl.cpp
Normal file
@ -0,0 +1,55 @@
|
||||
/**
|
||||
* 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 "UserApiImpl.h"
|
||||
|
||||
namespace org {
|
||||
namespace openapitools {
|
||||
namespace server {
|
||||
namespace api {
|
||||
|
||||
using namespace org::openapitools::server::model;
|
||||
|
||||
UserApiImpl::UserApiImpl(std::shared_ptr<Pistache::Rest::Router> rtr)
|
||||
: UserApi(rtr)
|
||||
{ }
|
||||
|
||||
void UserApiImpl::create_user(const User &user, Pistache::Http::ResponseWriter &response) {
|
||||
response.send(Pistache::Http::Code::Ok, "Do some magic\n");
|
||||
}
|
||||
void UserApiImpl::create_users_with_array_input(const std::vector<User> &user, Pistache::Http::ResponseWriter &response) {
|
||||
response.send(Pistache::Http::Code::Ok, "Do some magic\n");
|
||||
}
|
||||
void UserApiImpl::create_users_with_list_input(const std::vector<User> &user, Pistache::Http::ResponseWriter &response) {
|
||||
response.send(Pistache::Http::Code::Ok, "Do some magic\n");
|
||||
}
|
||||
void UserApiImpl::delete_user(const std::string &username, Pistache::Http::ResponseWriter &response) {
|
||||
response.send(Pistache::Http::Code::Ok, "Do some magic\n");
|
||||
}
|
||||
void UserApiImpl::get_user_by_name(const std::string &username, Pistache::Http::ResponseWriter &response) {
|
||||
response.send(Pistache::Http::Code::Ok, "Do some magic\n");
|
||||
}
|
||||
void UserApiImpl::login_user(const Oatpp::Optional<std::string> &username, const Oatpp::Optional<std::string> &password, Pistache::Http::ResponseWriter &response) {
|
||||
response.send(Pistache::Http::Code::Ok, "Do some magic\n");
|
||||
}
|
||||
void UserApiImpl::logout_user(Pistache::Http::ResponseWriter &response) {
|
||||
response.send(Pistache::Http::Code::Ok, "Do some magic\n");
|
||||
}
|
||||
void UserApiImpl::update_user(const std::string &username, const User &user, Pistache::Http::ResponseWriter &response) {
|
||||
response.send(Pistache::Http::Code::Ok, "Do some magic\n");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
66
samples/server/petstore/cpp-oatpp/impl/UserApiImpl.h
Normal file
66
samples/server/petstore/cpp-oatpp/impl/UserApiImpl.h
Normal file
@ -0,0 +1,66 @@
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* UserApiImpl.h
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef USER_API_IMPL_H_
|
||||
#define USER_API_IMPL_H_
|
||||
|
||||
|
||||
#include <pistache/endpoint.h>
|
||||
#include <pistache/http.h>
|
||||
#include <pistache/router.h>
|
||||
#include <memory>
|
||||
|
||||
#include <UserApi.h>
|
||||
|
||||
#include <pistache/optional.h>
|
||||
|
||||
#include "User.h"
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace org {
|
||||
namespace openapitools {
|
||||
namespace server {
|
||||
namespace api {
|
||||
|
||||
using namespace org::openapitools::server::model;
|
||||
|
||||
class UserApiImpl : public org::openapitools::server::api::UserApi {
|
||||
public:
|
||||
UserApiImpl(std::shared_ptr<Pistache::Rest::Router>);
|
||||
~UserApiImpl() {}
|
||||
|
||||
void create_user(const User &user, Pistache::Http::ResponseWriter &response);
|
||||
void create_users_with_array_input(const std::vector<User> &user, Pistache::Http::ResponseWriter &response);
|
||||
void create_users_with_list_input(const std::vector<User> &user, Pistache::Http::ResponseWriter &response);
|
||||
void delete_user(const std::string &username, Pistache::Http::ResponseWriter &response);
|
||||
void get_user_by_name(const std::string &username, Pistache::Http::ResponseWriter &response);
|
||||
void login_user(const Oatpp::Optional<std::string> &username, const Oatpp::Optional<std::string> &password, Pistache::Http::ResponseWriter &response);
|
||||
void logout_user(Pistache::Http::ResponseWriter &response);
|
||||
void update_user(const std::string &username, const User &user, Pistache::Http::ResponseWriter &response);
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif
|
95
samples/server/petstore/cpp-oatpp/main-api-server.cpp
Normal file
95
samples/server/petstore/cpp-oatpp/main-api-server.cpp
Normal file
@ -0,0 +1,95 @@
|
||||
/**
|
||||
* 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 "pistache/endpoint.h"
|
||||
#include "pistache/http.h"
|
||||
#include "pistache/router.h"
|
||||
#ifdef __linux__
|
||||
#include <vector>
|
||||
#include <signal.h>
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include "PetApiImpl.h"
|
||||
#include "StoreApiImpl.h"
|
||||
#include "UserApiImpl.h"
|
||||
|
||||
#define PISTACHE_SERVER_THREADS 2
|
||||
#define PISTACHE_SERVER_MAX_REQUEST_SIZE 32768
|
||||
#define PISTACHE_SERVER_MAX_RESPONSE_SIZE 32768
|
||||
|
||||
static Pistache::Http::Endpoint *httpEndpoint;
|
||||
#ifdef __linux__
|
||||
static void sigHandler [[noreturn]] (int sig){
|
||||
switch(sig){
|
||||
case SIGINT:
|
||||
case SIGQUIT:
|
||||
case SIGTERM:
|
||||
case SIGHUP:
|
||||
default:
|
||||
httpEndpoint->shutdown();
|
||||
break;
|
||||
}
|
||||
exit(0);
|
||||
}
|
||||
|
||||
static void setUpUnixSignals(std::vector<int> quitSignals) {
|
||||
sigset_t blocking_mask;
|
||||
sigemptyset(&blocking_mask);
|
||||
for (auto sig : quitSignals)
|
||||
sigaddset(&blocking_mask, sig);
|
||||
|
||||
struct sigaction sa;
|
||||
sa.sa_handler = sigHandler;
|
||||
sa.sa_mask = blocking_mask;
|
||||
sa.sa_flags = 0;
|
||||
|
||||
for (auto sig : quitSignals)
|
||||
sigaction(sig, &sa, nullptr);
|
||||
}
|
||||
#endif
|
||||
|
||||
using namespace org::openapitools::server::api;
|
||||
|
||||
int main() {
|
||||
#ifdef __linux__
|
||||
std::vector<int> sigs{SIGQUIT, SIGINT, SIGTERM, SIGHUP};
|
||||
setUpUnixSignals(sigs);
|
||||
#endif
|
||||
Pistache::Address addr(Pistache::Ipv4::any(), Pistache::Port(8080));
|
||||
|
||||
httpEndpoint = new Pistache::Http::Endpoint((addr));
|
||||
auto router = std::make_shared<Pistache::Rest::Router>();
|
||||
|
||||
auto opts = Pistache::Http::Endpoint::options()
|
||||
.threads(PISTACHE_SERVER_THREADS);
|
||||
opts.flags(Pistache::Tcp::Options::ReuseAddr);
|
||||
opts.maxRequestSize(PISTACHE_SERVER_MAX_REQUEST_SIZE);
|
||||
opts.maxResponseSize(PISTACHE_SERVER_MAX_RESPONSE_SIZE);
|
||||
httpEndpoint->init(opts);
|
||||
|
||||
|
||||
PetApiImpl PetApiserver(router);
|
||||
PetApiserver.init();
|
||||
StoreApiImpl StoreApiserver(router);
|
||||
StoreApiserver.init();
|
||||
UserApiImpl UserApiserver(router);
|
||||
UserApiserver.init();
|
||||
|
||||
httpEndpoint->setHandler(router->handler());
|
||||
httpEndpoint->serve();
|
||||
|
||||
httpEndpoint->shutdown();
|
||||
|
||||
}
|
||||
|
127
samples/server/petstore/cpp-oatpp/model/ApiResponse.cpp
Normal file
127
samples/server/petstore/cpp-oatpp/model/ApiResponse.cpp
Normal file
@ -0,0 +1,127 @@
|
||||
/**
|
||||
* 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 "ApiResponse.h"
|
||||
|
||||
namespace org {
|
||||
namespace openapitools {
|
||||
namespace server {
|
||||
namespace model {
|
||||
|
||||
ApiResponse::ApiResponse()
|
||||
{
|
||||
m_Code = 0;
|
||||
m_CodeIsSet = false;
|
||||
m_Type = "";
|
||||
m_TypeIsSet = false;
|
||||
m_Message = "";
|
||||
m_MessageIsSet = false;
|
||||
|
||||
}
|
||||
|
||||
ApiResponse::~ApiResponse()
|
||||
{
|
||||
}
|
||||
|
||||
void ApiResponse::validate()
|
||||
{
|
||||
// TODO: implement validation
|
||||
}
|
||||
|
||||
void to_json(nlohmann::json& j, const ApiResponse& o)
|
||||
{
|
||||
j = nlohmann::json();
|
||||
if(o.codeIsSet())
|
||||
j["code"] = o.m_Code;
|
||||
if(o.typeIsSet())
|
||||
j["type"] = o.m_Type;
|
||||
if(o.messageIsSet())
|
||||
j["message"] = o.m_Message;
|
||||
}
|
||||
|
||||
void from_json(const nlohmann::json& j, ApiResponse& o)
|
||||
{
|
||||
if(j.find("code") != j.end())
|
||||
{
|
||||
j.at("code").get_to(o.m_Code);
|
||||
o.m_CodeIsSet = true;
|
||||
}
|
||||
if(j.find("type") != j.end())
|
||||
{
|
||||
j.at("type").get_to(o.m_Type);
|
||||
o.m_TypeIsSet = true;
|
||||
}
|
||||
if(j.find("message") != j.end())
|
||||
{
|
||||
j.at("message").get_to(o.m_Message);
|
||||
o.m_MessageIsSet = true;
|
||||
}
|
||||
}
|
||||
|
||||
int32_t ApiResponse::getCode() const
|
||||
{
|
||||
return m_Code;
|
||||
}
|
||||
void ApiResponse::setCode(int32_t const value)
|
||||
{
|
||||
m_Code = value;
|
||||
m_CodeIsSet = true;
|
||||
}
|
||||
bool ApiResponse::codeIsSet() const
|
||||
{
|
||||
return m_CodeIsSet;
|
||||
}
|
||||
void ApiResponse::unsetCode()
|
||||
{
|
||||
m_CodeIsSet = false;
|
||||
}
|
||||
std::string ApiResponse::getType() const
|
||||
{
|
||||
return m_Type;
|
||||
}
|
||||
void ApiResponse::setType(std::string const& value)
|
||||
{
|
||||
m_Type = value;
|
||||
m_TypeIsSet = true;
|
||||
}
|
||||
bool ApiResponse::typeIsSet() const
|
||||
{
|
||||
return m_TypeIsSet;
|
||||
}
|
||||
void ApiResponse::unsetType()
|
||||
{
|
||||
m_TypeIsSet = false;
|
||||
}
|
||||
std::string ApiResponse::getMessage() const
|
||||
{
|
||||
return m_Message;
|
||||
}
|
||||
void ApiResponse::setMessage(std::string const& value)
|
||||
{
|
||||
m_Message = value;
|
||||
m_MessageIsSet = true;
|
||||
}
|
||||
bool ApiResponse::messageIsSet() const
|
||||
{
|
||||
return m_MessageIsSet;
|
||||
}
|
||||
void ApiResponse::unsetMessage()
|
||||
{
|
||||
m_MessageIsSet = false;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
82
samples/server/petstore/cpp-oatpp/model/ApiResponse.h
Normal file
82
samples/server/petstore/cpp-oatpp/model/ApiResponse.h
Normal file
@ -0,0 +1,82 @@
|
||||
/**
|
||||
* 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 <string>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
namespace org {
|
||||
namespace openapitools {
|
||||
namespace server {
|
||||
namespace model {
|
||||
|
||||
/// <summary>
|
||||
/// Describes the result of uploading an image resource
|
||||
/// </summary>
|
||||
class ApiResponse
|
||||
{
|
||||
public:
|
||||
ApiResponse();
|
||||
virtual ~ApiResponse();
|
||||
|
||||
void validate();
|
||||
|
||||
/////////////////////////////////////////////
|
||||
/// ApiResponse members
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
int32_t getCode() const;
|
||||
void setCode(int32_t const value);
|
||||
bool codeIsSet() const;
|
||||
void unsetCode();
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
std::string getType() const;
|
||||
void setType(std::string const& value);
|
||||
bool typeIsSet() const;
|
||||
void unsetType();
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
std::string getMessage() const;
|
||||
void setMessage(std::string const& value);
|
||||
bool messageIsSet() const;
|
||||
void unsetMessage();
|
||||
|
||||
friend void to_json(nlohmann::json& j, const ApiResponse& o);
|
||||
friend void from_json(const nlohmann::json& j, ApiResponse& o);
|
||||
protected:
|
||||
int32_t m_Code;
|
||||
bool m_CodeIsSet;
|
||||
std::string m_Type;
|
||||
bool m_TypeIsSet;
|
||||
std::string m_Message;
|
||||
bool m_MessageIsSet;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* ApiResponse_H_ */
|
101
samples/server/petstore/cpp-oatpp/model/Category.cpp
Normal file
101
samples/server/petstore/cpp-oatpp/model/Category.cpp
Normal file
@ -0,0 +1,101 @@
|
||||
/**
|
||||
* 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 "Category.h"
|
||||
|
||||
namespace org {
|
||||
namespace openapitools {
|
||||
namespace server {
|
||||
namespace model {
|
||||
|
||||
Category::Category()
|
||||
{
|
||||
m_Id = 0L;
|
||||
m_IdIsSet = false;
|
||||
m_Name = "";
|
||||
m_NameIsSet = false;
|
||||
|
||||
}
|
||||
|
||||
Category::~Category()
|
||||
{
|
||||
}
|
||||
|
||||
void Category::validate()
|
||||
{
|
||||
// TODO: implement validation
|
||||
}
|
||||
|
||||
void to_json(nlohmann::json& j, const Category& o)
|
||||
{
|
||||
j = nlohmann::json();
|
||||
if(o.idIsSet())
|
||||
j["id"] = o.m_Id;
|
||||
if(o.nameIsSet())
|
||||
j["name"] = o.m_Name;
|
||||
}
|
||||
|
||||
void from_json(const nlohmann::json& j, Category& o)
|
||||
{
|
||||
if(j.find("id") != j.end())
|
||||
{
|
||||
j.at("id").get_to(o.m_Id);
|
||||
o.m_IdIsSet = true;
|
||||
}
|
||||
if(j.find("name") != j.end())
|
||||
{
|
||||
j.at("name").get_to(o.m_Name);
|
||||
o.m_NameIsSet = true;
|
||||
}
|
||||
}
|
||||
|
||||
int64_t Category::getId() const
|
||||
{
|
||||
return m_Id;
|
||||
}
|
||||
void Category::setId(int64_t const value)
|
||||
{
|
||||
m_Id = value;
|
||||
m_IdIsSet = true;
|
||||
}
|
||||
bool Category::idIsSet() const
|
||||
{
|
||||
return m_IdIsSet;
|
||||
}
|
||||
void Category::unsetId()
|
||||
{
|
||||
m_IdIsSet = false;
|
||||
}
|
||||
std::string Category::getName() const
|
||||
{
|
||||
return m_Name;
|
||||
}
|
||||
void Category::setName(std::string const& value)
|
||||
{
|
||||
m_Name = value;
|
||||
m_NameIsSet = true;
|
||||
}
|
||||
bool Category::nameIsSet() const
|
||||
{
|
||||
return m_NameIsSet;
|
||||
}
|
||||
void Category::unsetName()
|
||||
{
|
||||
m_NameIsSet = false;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
73
samples/server/petstore/cpp-oatpp/model/Category.h
Normal file
73
samples/server/petstore/cpp-oatpp/model/Category.h
Normal file
@ -0,0 +1,73 @@
|
||||
/**
|
||||
* 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 <string>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
namespace org {
|
||||
namespace openapitools {
|
||||
namespace server {
|
||||
namespace model {
|
||||
|
||||
/// <summary>
|
||||
/// A category for a pet
|
||||
/// </summary>
|
||||
class Category
|
||||
{
|
||||
public:
|
||||
Category();
|
||||
virtual ~Category();
|
||||
|
||||
void validate();
|
||||
|
||||
/////////////////////////////////////////////
|
||||
/// Category members
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
int64_t getId() const;
|
||||
void setId(int64_t const value);
|
||||
bool idIsSet() const;
|
||||
void unsetId();
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
std::string getName() const;
|
||||
void setName(std::string const& value);
|
||||
bool nameIsSet() const;
|
||||
void unsetName();
|
||||
|
||||
friend void to_json(nlohmann::json& j, const Category& o);
|
||||
friend void from_json(const nlohmann::json& j, Category& o);
|
||||
protected:
|
||||
int64_t m_Id;
|
||||
bool m_IdIsSet;
|
||||
std::string m_Name;
|
||||
bool m_NameIsSet;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* Category_H_ */
|
98
samples/server/petstore/cpp-oatpp/model/Helpers.cpp
Normal file
98
samples/server/petstore/cpp-oatpp/model/Helpers.cpp
Normal file
@ -0,0 +1,98 @@
|
||||
/**
|
||||
* 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 "Helpers.h"
|
||||
|
||||
namespace org {
|
||||
namespace openapitools {
|
||||
namespace server {
|
||||
namespace helpers {
|
||||
|
||||
|
||||
std::string toStringValue(const std::string &value){
|
||||
return std::string(value);
|
||||
}
|
||||
|
||||
std::string toStringValue(const int32_t &value){
|
||||
return std::to_string(value);
|
||||
}
|
||||
|
||||
std::string toStringValue(const int64_t &value){
|
||||
return std::to_string(value);
|
||||
}
|
||||
|
||||
std::string toStringValue(const bool &value){
|
||||
return value?std::string("true"):std::string("false");
|
||||
}
|
||||
|
||||
std::string toStringValue(const float &value){
|
||||
return std::to_string(value);
|
||||
}
|
||||
|
||||
std::string toStringValue(const double &value){
|
||||
return std::to_string(value);
|
||||
}
|
||||
|
||||
bool fromStringValue(const std::string &inStr, std::string &value){
|
||||
value = std::string(inStr);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool fromStringValue(const std::string &inStr, int32_t &value){
|
||||
try {
|
||||
value = std::stoi( inStr );
|
||||
}
|
||||
catch (const std::invalid_argument&) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool fromStringValue(const std::string &inStr, int64_t &value){
|
||||
try {
|
||||
value = std::stol( inStr );
|
||||
}
|
||||
catch (const std::invalid_argument&) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool fromStringValue(const std::string &inStr, bool &value){
|
||||
bool result = true;
|
||||
inStr == "true"?value = true: inStr == "false"?value = false: result = false;
|
||||
return result;
|
||||
}
|
||||
|
||||
bool fromStringValue(const std::string &inStr, float &value){
|
||||
try {
|
||||
value = std::stof( inStr );
|
||||
}
|
||||
catch (const std::invalid_argument&) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool fromStringValue(const std::string &inStr, double &value){
|
||||
try {
|
||||
value = std::stod( inStr );
|
||||
}
|
||||
catch (const std::invalid_argument&) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
76
samples/server/petstore/cpp-oatpp/model/Helpers.h
Normal file
76
samples/server/petstore/cpp-oatpp/model/Helpers.h
Normal file
@ -0,0 +1,76 @@
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
/*
|
||||
* Helpers.h
|
||||
*
|
||||
* This is the helper class for models and primitives
|
||||
*/
|
||||
|
||||
#ifndef Helpers_H_
|
||||
#define Helpers_H_
|
||||
|
||||
#include <ctime>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
namespace org {
|
||||
namespace openapitools {
|
||||
namespace server {
|
||||
namespace helpers {
|
||||
|
||||
std::string toStringValue(const std::string &value);
|
||||
std::string toStringValue(const int32_t &value);
|
||||
std::string toStringValue(const int64_t &value);
|
||||
std::string toStringValue(const bool &value);
|
||||
std::string toStringValue(const float &value);
|
||||
std::string toStringValue(const double &value);
|
||||
|
||||
bool fromStringValue(const std::string &inStr, std::string &value);
|
||||
bool fromStringValue(const std::string &inStr, int32_t &value);
|
||||
bool fromStringValue(const std::string &inStr, int64_t &value);
|
||||
bool fromStringValue(const std::string &inStr, bool &value);
|
||||
bool fromStringValue(const std::string &inStr, float &value);
|
||||
bool fromStringValue(const std::string &inStr, double &value);
|
||||
template<typename T>
|
||||
bool fromStringValue(const std::vector<std::string> &inStr, std::vector<T> &value){
|
||||
try{
|
||||
for(auto & item : inStr){
|
||||
T itemValue;
|
||||
if(fromStringValue(item, itemValue)){
|
||||
value.push_back(itemValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(...){
|
||||
return false;
|
||||
}
|
||||
return value.size() > 0;
|
||||
}
|
||||
template<typename T>
|
||||
bool fromStringValue(const std::string &inStr, std::vector<T> &value, char separator = ','){
|
||||
std::vector<std::string> inStrings;
|
||||
std::istringstream f(inStr);
|
||||
std::string s;
|
||||
while (std::getline(f, s, separator)) {
|
||||
inStrings.push_back(s);
|
||||
}
|
||||
return fromStringValue(inStrings, value);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif // Helpers_H_
|
101
samples/server/petstore/cpp-oatpp/model/Inline_object.cpp
Normal file
101
samples/server/petstore/cpp-oatpp/model/Inline_object.cpp
Normal file
@ -0,0 +1,101 @@
|
||||
/**
|
||||
* 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 "Inline_object.h"
|
||||
|
||||
namespace org {
|
||||
namespace openapitools {
|
||||
namespace server {
|
||||
namespace model {
|
||||
|
||||
Inline_object::Inline_object()
|
||||
{
|
||||
m_Name = "";
|
||||
m_NameIsSet = false;
|
||||
m_Status = "";
|
||||
m_StatusIsSet = false;
|
||||
|
||||
}
|
||||
|
||||
Inline_object::~Inline_object()
|
||||
{
|
||||
}
|
||||
|
||||
void Inline_object::validate()
|
||||
{
|
||||
// TODO: implement validation
|
||||
}
|
||||
|
||||
void to_json(nlohmann::json& j, const Inline_object& o)
|
||||
{
|
||||
j = nlohmann::json();
|
||||
if(o.nameIsSet())
|
||||
j["name"] = o.m_Name;
|
||||
if(o.statusIsSet())
|
||||
j["status"] = o.m_Status;
|
||||
}
|
||||
|
||||
void from_json(const nlohmann::json& j, Inline_object& o)
|
||||
{
|
||||
if(j.find("name") != j.end())
|
||||
{
|
||||
j.at("name").get_to(o.m_Name);
|
||||
o.m_NameIsSet = true;
|
||||
}
|
||||
if(j.find("status") != j.end())
|
||||
{
|
||||
j.at("status").get_to(o.m_Status);
|
||||
o.m_StatusIsSet = true;
|
||||
}
|
||||
}
|
||||
|
||||
std::string Inline_object::getName() const
|
||||
{
|
||||
return m_Name;
|
||||
}
|
||||
void Inline_object::setName(std::string const& value)
|
||||
{
|
||||
m_Name = value;
|
||||
m_NameIsSet = true;
|
||||
}
|
||||
bool Inline_object::nameIsSet() const
|
||||
{
|
||||
return m_NameIsSet;
|
||||
}
|
||||
void Inline_object::unsetName()
|
||||
{
|
||||
m_NameIsSet = false;
|
||||
}
|
||||
std::string Inline_object::getStatus() const
|
||||
{
|
||||
return m_Status;
|
||||
}
|
||||
void Inline_object::setStatus(std::string const& value)
|
||||
{
|
||||
m_Status = value;
|
||||
m_StatusIsSet = true;
|
||||
}
|
||||
bool Inline_object::statusIsSet() const
|
||||
{
|
||||
return m_StatusIsSet;
|
||||
}
|
||||
void Inline_object::unsetStatus()
|
||||
{
|
||||
m_StatusIsSet = false;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
73
samples/server/petstore/cpp-oatpp/model/Inline_object.h
Normal file
73
samples/server/petstore/cpp-oatpp/model/Inline_object.h
Normal file
@ -0,0 +1,73 @@
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
/*
|
||||
* Inline_object.h
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef Inline_object_H_
|
||||
#define Inline_object_H_
|
||||
|
||||
|
||||
#include <string>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
namespace org {
|
||||
namespace openapitools {
|
||||
namespace server {
|
||||
namespace model {
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
class Inline_object
|
||||
{
|
||||
public:
|
||||
Inline_object();
|
||||
virtual ~Inline_object();
|
||||
|
||||
void validate();
|
||||
|
||||
/////////////////////////////////////////////
|
||||
/// Inline_object members
|
||||
|
||||
/// <summary>
|
||||
/// Updated name of the pet
|
||||
/// </summary>
|
||||
std::string getName() const;
|
||||
void setName(std::string const& value);
|
||||
bool nameIsSet() const;
|
||||
void unsetName();
|
||||
/// <summary>
|
||||
/// Updated status of the pet
|
||||
/// </summary>
|
||||
std::string getStatus() const;
|
||||
void setStatus(std::string const& value);
|
||||
bool statusIsSet() const;
|
||||
void unsetStatus();
|
||||
|
||||
friend void to_json(nlohmann::json& j, const Inline_object& o);
|
||||
friend void from_json(const nlohmann::json& j, Inline_object& o);
|
||||
protected:
|
||||
std::string m_Name;
|
||||
bool m_NameIsSet;
|
||||
std::string m_Status;
|
||||
bool m_StatusIsSet;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* Inline_object_H_ */
|
100
samples/server/petstore/cpp-oatpp/model/Inline_object_1.cpp
Normal file
100
samples/server/petstore/cpp-oatpp/model/Inline_object_1.cpp
Normal file
@ -0,0 +1,100 @@
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
|
||||
#include "Inline_object_1.h"
|
||||
|
||||
namespace org {
|
||||
namespace openapitools {
|
||||
namespace server {
|
||||
namespace model {
|
||||
|
||||
Inline_object_1::Inline_object_1()
|
||||
{
|
||||
m_AdditionalMetadata = "";
|
||||
m_AdditionalMetadataIsSet = false;
|
||||
m_fileIsSet = false;
|
||||
|
||||
}
|
||||
|
||||
Inline_object_1::~Inline_object_1()
|
||||
{
|
||||
}
|
||||
|
||||
void Inline_object_1::validate()
|
||||
{
|
||||
// TODO: implement validation
|
||||
}
|
||||
|
||||
void to_json(nlohmann::json& j, const Inline_object_1& o)
|
||||
{
|
||||
j = nlohmann::json();
|
||||
if(o.additionalMetadataIsSet())
|
||||
j["additionalMetadata"] = o.m_AdditionalMetadata;
|
||||
if(o.fileIsSet())
|
||||
j["file"] = o.m_file;
|
||||
}
|
||||
|
||||
void from_json(const nlohmann::json& j, Inline_object_1& o)
|
||||
{
|
||||
if(j.find("additionalMetadata") != j.end())
|
||||
{
|
||||
j.at("additionalMetadata").get_to(o.m_AdditionalMetadata);
|
||||
o.m_AdditionalMetadataIsSet = true;
|
||||
}
|
||||
if(j.find("file") != j.end())
|
||||
{
|
||||
j.at("file").get_to(o.m_file);
|
||||
o.m_fileIsSet = true;
|
||||
}
|
||||
}
|
||||
|
||||
std::string Inline_object_1::getAdditionalMetadata() const
|
||||
{
|
||||
return m_AdditionalMetadata;
|
||||
}
|
||||
void Inline_object_1::setAdditionalMetadata(std::string const& value)
|
||||
{
|
||||
m_AdditionalMetadata = value;
|
||||
m_AdditionalMetadataIsSet = true;
|
||||
}
|
||||
bool Inline_object_1::additionalMetadataIsSet() const
|
||||
{
|
||||
return m_AdditionalMetadataIsSet;
|
||||
}
|
||||
void Inline_object_1::unsetAdditionalMetadata()
|
||||
{
|
||||
m_AdditionalMetadataIsSet = false;
|
||||
}
|
||||
std::string Inline_object_1::getFile() const
|
||||
{
|
||||
return m_file;
|
||||
}
|
||||
void Inline_object_1::setFile(std::string const& value)
|
||||
{
|
||||
m_file = value;
|
||||
m_fileIsSet = true;
|
||||
}
|
||||
bool Inline_object_1::fileIsSet() const
|
||||
{
|
||||
return m_fileIsSet;
|
||||
}
|
||||
void Inline_object_1::unsetfile()
|
||||
{
|
||||
m_fileIsSet = false;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
73
samples/server/petstore/cpp-oatpp/model/Inline_object_1.h
Normal file
73
samples/server/petstore/cpp-oatpp/model/Inline_object_1.h
Normal file
@ -0,0 +1,73 @@
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
/*
|
||||
* Inline_object_1.h
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef Inline_object_1_H_
|
||||
#define Inline_object_1_H_
|
||||
|
||||
|
||||
#include <string>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
namespace org {
|
||||
namespace openapitools {
|
||||
namespace server {
|
||||
namespace model {
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
class Inline_object_1
|
||||
{
|
||||
public:
|
||||
Inline_object_1();
|
||||
virtual ~Inline_object_1();
|
||||
|
||||
void validate();
|
||||
|
||||
/////////////////////////////////////////////
|
||||
/// Inline_object_1 members
|
||||
|
||||
/// <summary>
|
||||
/// Additional data to pass to server
|
||||
/// </summary>
|
||||
std::string getAdditionalMetadata() const;
|
||||
void setAdditionalMetadata(std::string const& value);
|
||||
bool additionalMetadataIsSet() const;
|
||||
void unsetAdditionalMetadata();
|
||||
/// <summary>
|
||||
/// file to upload
|
||||
/// </summary>
|
||||
std::string getFile() const;
|
||||
void setFile(std::string const& value);
|
||||
bool fileIsSet() const;
|
||||
void unsetfile();
|
||||
|
||||
friend void to_json(nlohmann::json& j, const Inline_object_1& o);
|
||||
friend void from_json(const nlohmann::json& j, Inline_object_1& o);
|
||||
protected:
|
||||
std::string m_AdditionalMetadata;
|
||||
bool m_AdditionalMetadataIsSet;
|
||||
std::string m_file;
|
||||
bool m_fileIsSet;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* Inline_object_1_H_ */
|
205
samples/server/petstore/cpp-oatpp/model/Order.cpp
Normal file
205
samples/server/petstore/cpp-oatpp/model/Order.cpp
Normal file
@ -0,0 +1,205 @@
|
||||
/**
|
||||
* 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 "Order.h"
|
||||
|
||||
namespace org {
|
||||
namespace openapitools {
|
||||
namespace server {
|
||||
namespace model {
|
||||
|
||||
Order::Order()
|
||||
{
|
||||
m_Id = 0L;
|
||||
m_IdIsSet = false;
|
||||
m_PetId = 0L;
|
||||
m_PetIdIsSet = false;
|
||||
m_Quantity = 0;
|
||||
m_QuantityIsSet = false;
|
||||
m_ShipDate = "";
|
||||
m_ShipDateIsSet = false;
|
||||
m_Status = "";
|
||||
m_StatusIsSet = false;
|
||||
m_Complete = false;
|
||||
m_CompleteIsSet = false;
|
||||
|
||||
}
|
||||
|
||||
Order::~Order()
|
||||
{
|
||||
}
|
||||
|
||||
void Order::validate()
|
||||
{
|
||||
// TODO: implement validation
|
||||
}
|
||||
|
||||
void to_json(nlohmann::json& j, const Order& o)
|
||||
{
|
||||
j = nlohmann::json();
|
||||
if(o.idIsSet())
|
||||
j["id"] = o.m_Id;
|
||||
if(o.petIdIsSet())
|
||||
j["petId"] = o.m_PetId;
|
||||
if(o.quantityIsSet())
|
||||
j["quantity"] = o.m_Quantity;
|
||||
if(o.shipDateIsSet())
|
||||
j["shipDate"] = o.m_ShipDate;
|
||||
if(o.statusIsSet())
|
||||
j["status"] = o.m_Status;
|
||||
if(o.completeIsSet())
|
||||
j["complete"] = o.m_Complete;
|
||||
}
|
||||
|
||||
void from_json(const nlohmann::json& j, Order& o)
|
||||
{
|
||||
if(j.find("id") != j.end())
|
||||
{
|
||||
j.at("id").get_to(o.m_Id);
|
||||
o.m_IdIsSet = true;
|
||||
}
|
||||
if(j.find("petId") != j.end())
|
||||
{
|
||||
j.at("petId").get_to(o.m_PetId);
|
||||
o.m_PetIdIsSet = true;
|
||||
}
|
||||
if(j.find("quantity") != j.end())
|
||||
{
|
||||
j.at("quantity").get_to(o.m_Quantity);
|
||||
o.m_QuantityIsSet = true;
|
||||
}
|
||||
if(j.find("shipDate") != j.end())
|
||||
{
|
||||
j.at("shipDate").get_to(o.m_ShipDate);
|
||||
o.m_ShipDateIsSet = true;
|
||||
}
|
||||
if(j.find("status") != j.end())
|
||||
{
|
||||
j.at("status").get_to(o.m_Status);
|
||||
o.m_StatusIsSet = true;
|
||||
}
|
||||
if(j.find("complete") != j.end())
|
||||
{
|
||||
j.at("complete").get_to(o.m_Complete);
|
||||
o.m_CompleteIsSet = true;
|
||||
}
|
||||
}
|
||||
|
||||
int64_t Order::getId() const
|
||||
{
|
||||
return m_Id;
|
||||
}
|
||||
void Order::setId(int64_t const value)
|
||||
{
|
||||
m_Id = value;
|
||||
m_IdIsSet = true;
|
||||
}
|
||||
bool Order::idIsSet() const
|
||||
{
|
||||
return m_IdIsSet;
|
||||
}
|
||||
void Order::unsetId()
|
||||
{
|
||||
m_IdIsSet = false;
|
||||
}
|
||||
int64_t Order::getPetId() const
|
||||
{
|
||||
return m_PetId;
|
||||
}
|
||||
void Order::setPetId(int64_t const value)
|
||||
{
|
||||
m_PetId = value;
|
||||
m_PetIdIsSet = true;
|
||||
}
|
||||
bool Order::petIdIsSet() const
|
||||
{
|
||||
return m_PetIdIsSet;
|
||||
}
|
||||
void Order::unsetPetId()
|
||||
{
|
||||
m_PetIdIsSet = false;
|
||||
}
|
||||
int32_t Order::getQuantity() const
|
||||
{
|
||||
return m_Quantity;
|
||||
}
|
||||
void Order::setQuantity(int32_t const value)
|
||||
{
|
||||
m_Quantity = value;
|
||||
m_QuantityIsSet = true;
|
||||
}
|
||||
bool Order::quantityIsSet() const
|
||||
{
|
||||
return m_QuantityIsSet;
|
||||
}
|
||||
void Order::unsetQuantity()
|
||||
{
|
||||
m_QuantityIsSet = false;
|
||||
}
|
||||
std::string Order::getShipDate() const
|
||||
{
|
||||
return m_ShipDate;
|
||||
}
|
||||
void Order::setShipDate(std::string const& value)
|
||||
{
|
||||
m_ShipDate = value;
|
||||
m_ShipDateIsSet = true;
|
||||
}
|
||||
bool Order::shipDateIsSet() const
|
||||
{
|
||||
return m_ShipDateIsSet;
|
||||
}
|
||||
void Order::unsetShipDate()
|
||||
{
|
||||
m_ShipDateIsSet = false;
|
||||
}
|
||||
std::string Order::getStatus() const
|
||||
{
|
||||
return m_Status;
|
||||
}
|
||||
void Order::setStatus(std::string const& value)
|
||||
{
|
||||
m_Status = value;
|
||||
m_StatusIsSet = true;
|
||||
}
|
||||
bool Order::statusIsSet() const
|
||||
{
|
||||
return m_StatusIsSet;
|
||||
}
|
||||
void Order::unsetStatus()
|
||||
{
|
||||
m_StatusIsSet = false;
|
||||
}
|
||||
bool Order::isComplete() const
|
||||
{
|
||||
return m_Complete;
|
||||
}
|
||||
void Order::setComplete(bool const value)
|
||||
{
|
||||
m_Complete = value;
|
||||
m_CompleteIsSet = true;
|
||||
}
|
||||
bool Order::completeIsSet() const
|
||||
{
|
||||
return m_CompleteIsSet;
|
||||
}
|
||||
void Order::unsetComplete()
|
||||
{
|
||||
m_CompleteIsSet = false;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
109
samples/server/petstore/cpp-oatpp/model/Order.h
Normal file
109
samples/server/petstore/cpp-oatpp/model/Order.h
Normal file
@ -0,0 +1,109 @@
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
/*
|
||||
* Order.h
|
||||
*
|
||||
* An order for a pets from the pet store
|
||||
*/
|
||||
|
||||
#ifndef Order_H_
|
||||
#define Order_H_
|
||||
|
||||
|
||||
#include <string>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
namespace org {
|
||||
namespace openapitools {
|
||||
namespace server {
|
||||
namespace model {
|
||||
|
||||
/// <summary>
|
||||
/// An order for a pets from the pet store
|
||||
/// </summary>
|
||||
class Order
|
||||
{
|
||||
public:
|
||||
Order();
|
||||
virtual ~Order();
|
||||
|
||||
void validate();
|
||||
|
||||
/////////////////////////////////////////////
|
||||
/// Order members
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
int64_t getId() const;
|
||||
void setId(int64_t const value);
|
||||
bool idIsSet() const;
|
||||
void unsetId();
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
int64_t getPetId() const;
|
||||
void setPetId(int64_t const value);
|
||||
bool petIdIsSet() const;
|
||||
void unsetPetId();
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
int32_t getQuantity() const;
|
||||
void setQuantity(int32_t const value);
|
||||
bool quantityIsSet() const;
|
||||
void unsetQuantity();
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
std::string getShipDate() const;
|
||||
void setShipDate(std::string const& value);
|
||||
bool shipDateIsSet() const;
|
||||
void unsetShipDate();
|
||||
/// <summary>
|
||||
/// Order Status
|
||||
/// </summary>
|
||||
std::string getStatus() const;
|
||||
void setStatus(std::string const& value);
|
||||
bool statusIsSet() const;
|
||||
void unsetStatus();
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
bool isComplete() const;
|
||||
void setComplete(bool const value);
|
||||
bool completeIsSet() const;
|
||||
void unsetComplete();
|
||||
|
||||
friend void to_json(nlohmann::json& j, const Order& o);
|
||||
friend void from_json(const nlohmann::json& j, Order& o);
|
||||
protected:
|
||||
int64_t m_Id;
|
||||
bool m_IdIsSet;
|
||||
int64_t m_PetId;
|
||||
bool m_PetIdIsSet;
|
||||
int32_t m_Quantity;
|
||||
bool m_QuantityIsSet;
|
||||
std::string m_ShipDate;
|
||||
bool m_ShipDateIsSet;
|
||||
std::string m_Status;
|
||||
bool m_StatusIsSet;
|
||||
bool m_Complete;
|
||||
bool m_CompleteIsSet;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* Order_H_ */
|
172
samples/server/petstore/cpp-oatpp/model/Pet.cpp
Normal file
172
samples/server/petstore/cpp-oatpp/model/Pet.cpp
Normal file
@ -0,0 +1,172 @@
|
||||
/**
|
||||
* 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 "Pet.h"
|
||||
|
||||
namespace org {
|
||||
namespace openapitools {
|
||||
namespace server {
|
||||
namespace model {
|
||||
|
||||
Pet::Pet()
|
||||
{
|
||||
m_Id = 0L;
|
||||
m_IdIsSet = false;
|
||||
m_CategoryIsSet = false;
|
||||
m_Name = "";
|
||||
m_TagsIsSet = false;
|
||||
m_Status = "";
|
||||
m_StatusIsSet = false;
|
||||
|
||||
}
|
||||
|
||||
Pet::~Pet()
|
||||
{
|
||||
}
|
||||
|
||||
void Pet::validate()
|
||||
{
|
||||
// TODO: implement validation
|
||||
}
|
||||
|
||||
void to_json(nlohmann::json& j, const Pet& o)
|
||||
{
|
||||
j = nlohmann::json();
|
||||
if(o.idIsSet())
|
||||
j["id"] = o.m_Id;
|
||||
if(o.categoryIsSet())
|
||||
j["category"] = o.m_Category;
|
||||
j["name"] = o.m_Name;
|
||||
j["photoUrls"] = o.m_PhotoUrls;
|
||||
if(o.tagsIsSet() || !o.m_Tags.empty())
|
||||
j["tags"] = o.m_Tags;
|
||||
if(o.statusIsSet())
|
||||
j["status"] = o.m_Status;
|
||||
}
|
||||
|
||||
void from_json(const nlohmann::json& j, Pet& o)
|
||||
{
|
||||
if(j.find("id") != j.end())
|
||||
{
|
||||
j.at("id").get_to(o.m_Id);
|
||||
o.m_IdIsSet = true;
|
||||
}
|
||||
if(j.find("category") != j.end())
|
||||
{
|
||||
j.at("category").get_to(o.m_Category);
|
||||
o.m_CategoryIsSet = true;
|
||||
}
|
||||
j.at("name").get_to(o.m_Name);
|
||||
j.at("photoUrls").get_to(o.m_PhotoUrls);
|
||||
if(j.find("tags") != j.end())
|
||||
{
|
||||
j.at("tags").get_to(o.m_Tags);
|
||||
o.m_TagsIsSet = true;
|
||||
}
|
||||
if(j.find("status") != j.end())
|
||||
{
|
||||
j.at("status").get_to(o.m_Status);
|
||||
o.m_StatusIsSet = true;
|
||||
}
|
||||
}
|
||||
|
||||
int64_t Pet::getId() const
|
||||
{
|
||||
return m_Id;
|
||||
}
|
||||
void Pet::setId(int64_t const value)
|
||||
{
|
||||
m_Id = value;
|
||||
m_IdIsSet = true;
|
||||
}
|
||||
bool Pet::idIsSet() const
|
||||
{
|
||||
return m_IdIsSet;
|
||||
}
|
||||
void Pet::unsetId()
|
||||
{
|
||||
m_IdIsSet = false;
|
||||
}
|
||||
Category Pet::getCategory() const
|
||||
{
|
||||
return m_Category;
|
||||
}
|
||||
void Pet::setCategory(Category const& value)
|
||||
{
|
||||
m_Category = value;
|
||||
m_CategoryIsSet = true;
|
||||
}
|
||||
bool Pet::categoryIsSet() const
|
||||
{
|
||||
return m_CategoryIsSet;
|
||||
}
|
||||
void Pet::unsetCategory()
|
||||
{
|
||||
m_CategoryIsSet = false;
|
||||
}
|
||||
std::string Pet::getName() const
|
||||
{
|
||||
return m_Name;
|
||||
}
|
||||
void Pet::setName(std::string const& value)
|
||||
{
|
||||
m_Name = value;
|
||||
}
|
||||
std::vector<std::string>& Pet::getPhotoUrls()
|
||||
{
|
||||
return m_PhotoUrls;
|
||||
}
|
||||
void Pet::setPhotoUrls(std::vector<std::string> const& value)
|
||||
{
|
||||
m_PhotoUrls = value;
|
||||
}
|
||||
std::vector<Tag>& Pet::getTags()
|
||||
{
|
||||
return m_Tags;
|
||||
}
|
||||
void Pet::setTags(std::vector<Tag> const& value)
|
||||
{
|
||||
m_Tags = value;
|
||||
m_TagsIsSet = true;
|
||||
}
|
||||
bool Pet::tagsIsSet() const
|
||||
{
|
||||
return m_TagsIsSet;
|
||||
}
|
||||
void Pet::unsetTags()
|
||||
{
|
||||
m_TagsIsSet = false;
|
||||
}
|
||||
std::string Pet::getStatus() const
|
||||
{
|
||||
return m_Status;
|
||||
}
|
||||
void Pet::setStatus(std::string const& value)
|
||||
{
|
||||
m_Status = value;
|
||||
m_StatusIsSet = true;
|
||||
}
|
||||
bool Pet::statusIsSet() const
|
||||
{
|
||||
return m_StatusIsSet;
|
||||
}
|
||||
void Pet::unsetStatus()
|
||||
{
|
||||
m_StatusIsSet = false;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
108
samples/server/petstore/cpp-oatpp/model/Pet.h
Normal file
108
samples/server/petstore/cpp-oatpp/model/Pet.h
Normal file
@ -0,0 +1,108 @@
|
||||
/**
|
||||
* 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 "Tag.h"
|
||||
#include <string>
|
||||
#include "Category.h"
|
||||
#include <vector>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
namespace org {
|
||||
namespace openapitools {
|
||||
namespace server {
|
||||
namespace model {
|
||||
|
||||
/// <summary>
|
||||
/// A pet for sale in the pet store
|
||||
/// </summary>
|
||||
class Pet
|
||||
{
|
||||
public:
|
||||
Pet();
|
||||
virtual ~Pet();
|
||||
|
||||
void validate();
|
||||
|
||||
/////////////////////////////////////////////
|
||||
/// Pet members
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
int64_t getId() const;
|
||||
void setId(int64_t const value);
|
||||
bool idIsSet() const;
|
||||
void unsetId();
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
Category getCategory() const;
|
||||
void setCategory(Category const& value);
|
||||
bool categoryIsSet() const;
|
||||
void unsetCategory();
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
std::string getName() const;
|
||||
void setName(std::string const& value);
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
std::vector<std::string>& getPhotoUrls();
|
||||
void setPhotoUrls(std::vector<std::string> const& value);
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
std::vector<Tag>& getTags();
|
||||
void setTags(std::vector<Tag> const& value);
|
||||
bool tagsIsSet() const;
|
||||
void unsetTags();
|
||||
/// <summary>
|
||||
/// pet status in the store
|
||||
/// </summary>
|
||||
std::string getStatus() const;
|
||||
void setStatus(std::string const& value);
|
||||
bool statusIsSet() const;
|
||||
void unsetStatus();
|
||||
|
||||
friend void to_json(nlohmann::json& j, const Pet& o);
|
||||
friend void from_json(const nlohmann::json& j, Pet& o);
|
||||
protected:
|
||||
int64_t m_Id;
|
||||
bool m_IdIsSet;
|
||||
Category m_Category;
|
||||
bool m_CategoryIsSet;
|
||||
std::string m_Name;
|
||||
|
||||
std::vector<std::string> m_PhotoUrls;
|
||||
|
||||
std::vector<Tag> m_Tags;
|
||||
bool m_TagsIsSet;
|
||||
std::string m_Status;
|
||||
bool m_StatusIsSet;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* Pet_H_ */
|
101
samples/server/petstore/cpp-oatpp/model/Tag.cpp
Normal file
101
samples/server/petstore/cpp-oatpp/model/Tag.cpp
Normal file
@ -0,0 +1,101 @@
|
||||
/**
|
||||
* 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 "Tag.h"
|
||||
|
||||
namespace org {
|
||||
namespace openapitools {
|
||||
namespace server {
|
||||
namespace model {
|
||||
|
||||
Tag::Tag()
|
||||
{
|
||||
m_Id = 0L;
|
||||
m_IdIsSet = false;
|
||||
m_Name = "";
|
||||
m_NameIsSet = false;
|
||||
|
||||
}
|
||||
|
||||
Tag::~Tag()
|
||||
{
|
||||
}
|
||||
|
||||
void Tag::validate()
|
||||
{
|
||||
// TODO: implement validation
|
||||
}
|
||||
|
||||
void to_json(nlohmann::json& j, const Tag& o)
|
||||
{
|
||||
j = nlohmann::json();
|
||||
if(o.idIsSet())
|
||||
j["id"] = o.m_Id;
|
||||
if(o.nameIsSet())
|
||||
j["name"] = o.m_Name;
|
||||
}
|
||||
|
||||
void from_json(const nlohmann::json& j, Tag& o)
|
||||
{
|
||||
if(j.find("id") != j.end())
|
||||
{
|
||||
j.at("id").get_to(o.m_Id);
|
||||
o.m_IdIsSet = true;
|
||||
}
|
||||
if(j.find("name") != j.end())
|
||||
{
|
||||
j.at("name").get_to(o.m_Name);
|
||||
o.m_NameIsSet = true;
|
||||
}
|
||||
}
|
||||
|
||||
int64_t Tag::getId() const
|
||||
{
|
||||
return m_Id;
|
||||
}
|
||||
void Tag::setId(int64_t const value)
|
||||
{
|
||||
m_Id = value;
|
||||
m_IdIsSet = true;
|
||||
}
|
||||
bool Tag::idIsSet() const
|
||||
{
|
||||
return m_IdIsSet;
|
||||
}
|
||||
void Tag::unsetId()
|
||||
{
|
||||
m_IdIsSet = false;
|
||||
}
|
||||
std::string Tag::getName() const
|
||||
{
|
||||
return m_Name;
|
||||
}
|
||||
void Tag::setName(std::string const& value)
|
||||
{
|
||||
m_Name = value;
|
||||
m_NameIsSet = true;
|
||||
}
|
||||
bool Tag::nameIsSet() const
|
||||
{
|
||||
return m_NameIsSet;
|
||||
}
|
||||
void Tag::unsetName()
|
||||
{
|
||||
m_NameIsSet = false;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
73
samples/server/petstore/cpp-oatpp/model/Tag.h
Normal file
73
samples/server/petstore/cpp-oatpp/model/Tag.h
Normal file
@ -0,0 +1,73 @@
|
||||
/**
|
||||
* 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 <string>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
namespace org {
|
||||
namespace openapitools {
|
||||
namespace server {
|
||||
namespace model {
|
||||
|
||||
/// <summary>
|
||||
/// A tag for a pet
|
||||
/// </summary>
|
||||
class Tag
|
||||
{
|
||||
public:
|
||||
Tag();
|
||||
virtual ~Tag();
|
||||
|
||||
void validate();
|
||||
|
||||
/////////////////////////////////////////////
|
||||
/// Tag members
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
int64_t getId() const;
|
||||
void setId(int64_t const value);
|
||||
bool idIsSet() const;
|
||||
void unsetId();
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
std::string getName() const;
|
||||
void setName(std::string const& value);
|
||||
bool nameIsSet() const;
|
||||
void unsetName();
|
||||
|
||||
friend void to_json(nlohmann::json& j, const Tag& o);
|
||||
friend void from_json(const nlohmann::json& j, Tag& o);
|
||||
protected:
|
||||
int64_t m_Id;
|
||||
bool m_IdIsSet;
|
||||
std::string m_Name;
|
||||
bool m_NameIsSet;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* Tag_H_ */
|
257
samples/server/petstore/cpp-oatpp/model/User.cpp
Normal file
257
samples/server/petstore/cpp-oatpp/model/User.cpp
Normal file
@ -0,0 +1,257 @@
|
||||
/**
|
||||
* 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 "User.h"
|
||||
|
||||
namespace org {
|
||||
namespace openapitools {
|
||||
namespace server {
|
||||
namespace model {
|
||||
|
||||
User::User()
|
||||
{
|
||||
m_Id = 0L;
|
||||
m_IdIsSet = false;
|
||||
m_Username = "";
|
||||
m_UsernameIsSet = false;
|
||||
m_FirstName = "";
|
||||
m_FirstNameIsSet = false;
|
||||
m_LastName = "";
|
||||
m_LastNameIsSet = false;
|
||||
m_Email = "";
|
||||
m_EmailIsSet = false;
|
||||
m_Password = "";
|
||||
m_PasswordIsSet = false;
|
||||
m_Phone = "";
|
||||
m_PhoneIsSet = false;
|
||||
m_UserStatus = 0;
|
||||
m_UserStatusIsSet = false;
|
||||
|
||||
}
|
||||
|
||||
User::~User()
|
||||
{
|
||||
}
|
||||
|
||||
void User::validate()
|
||||
{
|
||||
// TODO: implement validation
|
||||
}
|
||||
|
||||
void to_json(nlohmann::json& j, const User& o)
|
||||
{
|
||||
j = nlohmann::json();
|
||||
if(o.idIsSet())
|
||||
j["id"] = o.m_Id;
|
||||
if(o.usernameIsSet())
|
||||
j["username"] = o.m_Username;
|
||||
if(o.firstNameIsSet())
|
||||
j["firstName"] = o.m_FirstName;
|
||||
if(o.lastNameIsSet())
|
||||
j["lastName"] = o.m_LastName;
|
||||
if(o.emailIsSet())
|
||||
j["email"] = o.m_Email;
|
||||
if(o.passwordIsSet())
|
||||
j["password"] = o.m_Password;
|
||||
if(o.phoneIsSet())
|
||||
j["phone"] = o.m_Phone;
|
||||
if(o.userStatusIsSet())
|
||||
j["userStatus"] = o.m_UserStatus;
|
||||
}
|
||||
|
||||
void from_json(const nlohmann::json& j, User& o)
|
||||
{
|
||||
if(j.find("id") != j.end())
|
||||
{
|
||||
j.at("id").get_to(o.m_Id);
|
||||
o.m_IdIsSet = true;
|
||||
}
|
||||
if(j.find("username") != j.end())
|
||||
{
|
||||
j.at("username").get_to(o.m_Username);
|
||||
o.m_UsernameIsSet = true;
|
||||
}
|
||||
if(j.find("firstName") != j.end())
|
||||
{
|
||||
j.at("firstName").get_to(o.m_FirstName);
|
||||
o.m_FirstNameIsSet = true;
|
||||
}
|
||||
if(j.find("lastName") != j.end())
|
||||
{
|
||||
j.at("lastName").get_to(o.m_LastName);
|
||||
o.m_LastNameIsSet = true;
|
||||
}
|
||||
if(j.find("email") != j.end())
|
||||
{
|
||||
j.at("email").get_to(o.m_Email);
|
||||
o.m_EmailIsSet = true;
|
||||
}
|
||||
if(j.find("password") != j.end())
|
||||
{
|
||||
j.at("password").get_to(o.m_Password);
|
||||
o.m_PasswordIsSet = true;
|
||||
}
|
||||
if(j.find("phone") != j.end())
|
||||
{
|
||||
j.at("phone").get_to(o.m_Phone);
|
||||
o.m_PhoneIsSet = true;
|
||||
}
|
||||
if(j.find("userStatus") != j.end())
|
||||
{
|
||||
j.at("userStatus").get_to(o.m_UserStatus);
|
||||
o.m_UserStatusIsSet = true;
|
||||
}
|
||||
}
|
||||
|
||||
int64_t User::getId() const
|
||||
{
|
||||
return m_Id;
|
||||
}
|
||||
void User::setId(int64_t const value)
|
||||
{
|
||||
m_Id = value;
|
||||
m_IdIsSet = true;
|
||||
}
|
||||
bool User::idIsSet() const
|
||||
{
|
||||
return m_IdIsSet;
|
||||
}
|
||||
void User::unsetId()
|
||||
{
|
||||
m_IdIsSet = false;
|
||||
}
|
||||
std::string User::getUsername() const
|
||||
{
|
||||
return m_Username;
|
||||
}
|
||||
void User::setUsername(std::string const& value)
|
||||
{
|
||||
m_Username = value;
|
||||
m_UsernameIsSet = true;
|
||||
}
|
||||
bool User::usernameIsSet() const
|
||||
{
|
||||
return m_UsernameIsSet;
|
||||
}
|
||||
void User::unsetUsername()
|
||||
{
|
||||
m_UsernameIsSet = false;
|
||||
}
|
||||
std::string User::getFirstName() const
|
||||
{
|
||||
return m_FirstName;
|
||||
}
|
||||
void User::setFirstName(std::string const& value)
|
||||
{
|
||||
m_FirstName = value;
|
||||
m_FirstNameIsSet = true;
|
||||
}
|
||||
bool User::firstNameIsSet() const
|
||||
{
|
||||
return m_FirstNameIsSet;
|
||||
}
|
||||
void User::unsetFirstName()
|
||||
{
|
||||
m_FirstNameIsSet = false;
|
||||
}
|
||||
std::string User::getLastName() const
|
||||
{
|
||||
return m_LastName;
|
||||
}
|
||||
void User::setLastName(std::string const& value)
|
||||
{
|
||||
m_LastName = value;
|
||||
m_LastNameIsSet = true;
|
||||
}
|
||||
bool User::lastNameIsSet() const
|
||||
{
|
||||
return m_LastNameIsSet;
|
||||
}
|
||||
void User::unsetLastName()
|
||||
{
|
||||
m_LastNameIsSet = false;
|
||||
}
|
||||
std::string User::getEmail() const
|
||||
{
|
||||
return m_Email;
|
||||
}
|
||||
void User::setEmail(std::string const& value)
|
||||
{
|
||||
m_Email = value;
|
||||
m_EmailIsSet = true;
|
||||
}
|
||||
bool User::emailIsSet() const
|
||||
{
|
||||
return m_EmailIsSet;
|
||||
}
|
||||
void User::unsetEmail()
|
||||
{
|
||||
m_EmailIsSet = false;
|
||||
}
|
||||
std::string User::getPassword() const
|
||||
{
|
||||
return m_Password;
|
||||
}
|
||||
void User::setPassword(std::string const& value)
|
||||
{
|
||||
m_Password = value;
|
||||
m_PasswordIsSet = true;
|
||||
}
|
||||
bool User::passwordIsSet() const
|
||||
{
|
||||
return m_PasswordIsSet;
|
||||
}
|
||||
void User::unsetPassword()
|
||||
{
|
||||
m_PasswordIsSet = false;
|
||||
}
|
||||
std::string User::getPhone() const
|
||||
{
|
||||
return m_Phone;
|
||||
}
|
||||
void User::setPhone(std::string const& value)
|
||||
{
|
||||
m_Phone = value;
|
||||
m_PhoneIsSet = true;
|
||||
}
|
||||
bool User::phoneIsSet() const
|
||||
{
|
||||
return m_PhoneIsSet;
|
||||
}
|
||||
void User::unsetPhone()
|
||||
{
|
||||
m_PhoneIsSet = false;
|
||||
}
|
||||
int32_t User::getUserStatus() const
|
||||
{
|
||||
return m_UserStatus;
|
||||
}
|
||||
void User::setUserStatus(int32_t const value)
|
||||
{
|
||||
m_UserStatus = value;
|
||||
m_UserStatusIsSet = true;
|
||||
}
|
||||
bool User::userStatusIsSet() const
|
||||
{
|
||||
return m_UserStatusIsSet;
|
||||
}
|
||||
void User::unsetUserStatus()
|
||||
{
|
||||
m_UserStatusIsSet = false;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
127
samples/server/petstore/cpp-oatpp/model/User.h
Normal file
127
samples/server/petstore/cpp-oatpp/model/User.h
Normal file
@ -0,0 +1,127 @@
|
||||
/**
|
||||
* 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 <string>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
namespace org {
|
||||
namespace openapitools {
|
||||
namespace server {
|
||||
namespace model {
|
||||
|
||||
/// <summary>
|
||||
/// A User who is purchasing from the pet store
|
||||
/// </summary>
|
||||
class User
|
||||
{
|
||||
public:
|
||||
User();
|
||||
virtual ~User();
|
||||
|
||||
void validate();
|
||||
|
||||
/////////////////////////////////////////////
|
||||
/// User members
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
int64_t getId() const;
|
||||
void setId(int64_t const value);
|
||||
bool idIsSet() const;
|
||||
void unsetId();
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
std::string getUsername() const;
|
||||
void setUsername(std::string const& value);
|
||||
bool usernameIsSet() const;
|
||||
void unsetUsername();
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
std::string getFirstName() const;
|
||||
void setFirstName(std::string const& value);
|
||||
bool firstNameIsSet() const;
|
||||
void unsetFirstName();
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
std::string getLastName() const;
|
||||
void setLastName(std::string const& value);
|
||||
bool lastNameIsSet() const;
|
||||
void unsetLastName();
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
std::string getEmail() const;
|
||||
void setEmail(std::string const& value);
|
||||
bool emailIsSet() const;
|
||||
void unsetEmail();
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
std::string getPassword() const;
|
||||
void setPassword(std::string const& value);
|
||||
bool passwordIsSet() const;
|
||||
void unsetPassword();
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
std::string getPhone() const;
|
||||
void setPhone(std::string const& value);
|
||||
bool phoneIsSet() const;
|
||||
void unsetPhone();
|
||||
/// <summary>
|
||||
/// User Status
|
||||
/// </summary>
|
||||
int32_t getUserStatus() const;
|
||||
void setUserStatus(int32_t const value);
|
||||
bool userStatusIsSet() const;
|
||||
void unsetUserStatus();
|
||||
|
||||
friend void to_json(nlohmann::json& j, const User& o);
|
||||
friend void from_json(const nlohmann::json& j, User& o);
|
||||
protected:
|
||||
int64_t m_Id;
|
||||
bool m_IdIsSet;
|
||||
std::string m_Username;
|
||||
bool m_UsernameIsSet;
|
||||
std::string m_FirstName;
|
||||
bool m_FirstNameIsSet;
|
||||
std::string m_LastName;
|
||||
bool m_LastNameIsSet;
|
||||
std::string m_Email;
|
||||
bool m_EmailIsSet;
|
||||
std::string m_Password;
|
||||
bool m_PasswordIsSet;
|
||||
std::string m_Phone;
|
||||
bool m_PhoneIsSet;
|
||||
int32_t m_UserStatus;
|
||||
bool m_UserStatusIsSet;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* User_H_ */
|
Loading…
x
Reference in New Issue
Block a user