forked from loafle/openapi-generator-original
Cpp restbed server improvements (#13030)
* Keep old implementation of cpp-restbed generator as cpp-restbed-server-deprecated * Refactor operation path processing * Restructure samples directory to better allow writing tests * Improve templates for cpp-restbed-server Improve templates * Add integration tests * Improvement in templates for cpp-restbed-server * Fix tests * Improve cpp-restbed generator * Improve cpp-restbed-server * Add more tests * Add suppoert for arrays of enums in query params * Generate CMakeLists.txt * Small improvements and example in Readme * Add integration tests to maven project * Update doc
This commit is contained in:
parent
40044a3007
commit
d2e60f59b3
@ -111,6 +111,8 @@ before_install:
|
||||
- cmake --version
|
||||
# install Qt5
|
||||
#- sudo apt install -y --no-install-recommends qt5-default
|
||||
# install boost
|
||||
- sudo apt install -y --no-install-recommends libboost-all-dev
|
||||
# perl dep
|
||||
- cpanm --local-lib=~/perl5 local::lib && eval $(perl -I ~/perl5/lib/perl5/ -Mlocal::lib)
|
||||
- cpanm --quiet --no-interactive Test::Exception Test::More Log::Any LWP::UserAgent URI::Query Module::Runtime DateTime Module::Find Moose::Role JSON || echo "Ignored failure from cpanm"
|
||||
|
@ -1,4 +1,4 @@
|
||||
generatorName: cpp-restbed-server
|
||||
outputDir: samples/server/petstore/cpp-restbed
|
||||
outputDir: samples/server/petstore/cpp-restbed/generated/2_0
|
||||
inputSpec: modules/openapi-generator/src/test/resources/2_0/petstore.yaml
|
||||
templateDir: modules/openapi-generator/src/main/resources/cpp-restbed-server
|
||||
|
4
bin/configs/unmaintained/cpp-restbed-server.yaml
Normal file
4
bin/configs/unmaintained/cpp-restbed-server.yaml
Normal file
@ -0,0 +1,4 @@
|
||||
generatorName: cpp-restbed-server
|
||||
outputDir: samples/server/petstore/cpp-restbed/generated/2_0
|
||||
inputSpec: modules/openapi-generator/src/test/resources/2_0/petstore.yaml
|
||||
templateDir: modules/openapi-generator/src/main/resources/cpp-restbed-server
|
@ -0,0 +1,4 @@
|
||||
generatorName: cpp-restbed-server-deprecated
|
||||
outputDir: samples/server/petstore/cpp-restbed-deprecated
|
||||
inputSpec: modules/openapi-generator/src/test/resources/3_0/petstore.yaml
|
||||
templateDir: modules/openapi-generator/src/main/resources/cpp-restbed-server-deprecated
|
@ -1,4 +1,4 @@
|
||||
generatorName: cpp-restbed-server
|
||||
outputDir: samples/server/petstore/cpp-restbed
|
||||
inputSpec: modules/openapi-generator/src/test/resources/3_0/petstore.yaml
|
||||
outputDir: samples/server/petstore/cpp-restbed/generated/3_0
|
||||
inputSpec: modules/openapi-generator/src/test/resources/3_0/petstore-with-fake-endpoints-models-for-testing.yaml
|
||||
templateDir: modules/openapi-generator/src/main/resources/cpp-restbed-server
|
||||
|
@ -29,9 +29,10 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|
||||
|
||||
| Type/Alias | Imports |
|
||||
| ---------- | ------- |
|
||||
|Object|#include "Object.h"|
|
||||
|file|#include <string>|
|
||||
|restbed::Bytes|#include <corvusoft/restbed/byte.hpp>|
|
||||
|std::map|#include <map>|
|
||||
|std::set|#include <set>|
|
||||
|std::string|#include <string>|
|
||||
|std::vector|#include <vector>|
|
||||
|
||||
|
@ -160,6 +160,14 @@ abstract public class AbstractCppCodegen extends DefaultCodegen implements Codeg
|
||||
Boolean.toString(this.variableNameFirstCharacterUppercase));
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("static-method")
|
||||
public String sanitizeName(String name) {
|
||||
String sanitizedName = super.sanitizeName(name);
|
||||
sanitizedName = sanitizedName.replaceAll("-", "");
|
||||
return sanitizedName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String escapeQuotationMark(String input) {
|
||||
// remove " to avoid code injection
|
||||
@ -188,7 +196,9 @@ abstract public class AbstractCppCodegen extends DefaultCodegen implements Codeg
|
||||
|| languageSpecificPrimitives.contains(type)) {
|
||||
return type;
|
||||
} else {
|
||||
return sanitizeName(modelNamePrefix + Character.toUpperCase(type.charAt(0)) + type.substring(1));
|
||||
String sanitizedName = sanitizeName(modelNamePrefix + Character.toUpperCase(type.charAt(0)) + type.substring(1));
|
||||
sanitizedName = sanitizedName.replaceFirst("^([^_a-zA-Z])", reservedWordPrefix + "$1");
|
||||
return sanitizedName;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -38,6 +38,8 @@ public class CppRestbedServerCodegen extends AbstractCppCodegen {
|
||||
|
||||
public static final String DECLSPEC = "declspec";
|
||||
public static final String DEFAULT_INCLUDE = "defaultInclude";
|
||||
private static final String OPEN_API_PATH_PARAM_PATTERN = "^\\{(.*)\\}$";
|
||||
private static final String X_CODEGEN_OTHER_METHODS = "x-codegen-other-methods";
|
||||
|
||||
protected String packageVersion = "1.0.0";
|
||||
protected String declspec = "";
|
||||
@ -74,7 +76,7 @@ public class CppRestbedServerCodegen extends AbstractCppCodegen {
|
||||
apiTemplateFiles.put("api-header.mustache", ".h");
|
||||
apiTemplateFiles.put("api-source.mustache", ".cpp");
|
||||
|
||||
embeddedTemplateDir = templateDir = "cpp-restbed-server";
|
||||
embeddedTemplateDir = templateDir = "cpp-restbed-server-deprecated";
|
||||
|
||||
cliOptions.clear();
|
||||
|
||||
@ -96,6 +98,9 @@ public class CppRestbedServerCodegen extends AbstractCppCodegen {
|
||||
supportingFiles.add(new SupportingFile("gitignore.mustache", "", ".gitignore"));
|
||||
supportingFiles.add(new SupportingFile("git_push.sh.mustache", "", "git_push.sh"));
|
||||
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
|
||||
supportingFiles.add(new SupportingFile("model-helpers-header.mustache", modelFileFolder(), "helpers.h"));
|
||||
supportingFiles.add(new SupportingFile("CMakeLists.txt.mustache", "", "CMakeLists.txt"));
|
||||
supportingFiles.add(new SupportingFile("FindRestbedAndBoost.cmake", "", "FindRestbedAndBoost.cmake"));
|
||||
|
||||
languageSpecificPrimitives = new HashSet<>(
|
||||
Arrays.asList("int", "char", "bool", "long", "float", "double", "int32_t", "int64_t"));
|
||||
@ -109,10 +114,12 @@ public class CppRestbedServerCodegen extends AbstractCppCodegen {
|
||||
typeMapping.put("boolean", "bool");
|
||||
typeMapping.put("array", "std::vector");
|
||||
typeMapping.put("map", "std::map");
|
||||
typeMapping.put("set", "std::set");
|
||||
typeMapping.put("file", "std::string");
|
||||
typeMapping.put("object", "Object");
|
||||
typeMapping.put("object", "std::string");
|
||||
typeMapping.put("binary", "restbed::Bytes");
|
||||
typeMapping.put("number", "double");
|
||||
typeMapping.put("decimal", "std::string");
|
||||
typeMapping.put("UUID", "std::string");
|
||||
typeMapping.put("URI", "std::string");
|
||||
typeMapping.put("ByteArray", "std::string");
|
||||
@ -120,8 +127,9 @@ public class CppRestbedServerCodegen extends AbstractCppCodegen {
|
||||
super.importMapping = new HashMap<>();
|
||||
importMapping.put("std::vector", "#include <vector>");
|
||||
importMapping.put("std::map", "#include <map>");
|
||||
importMapping.put("std::set", "#include <set>");
|
||||
importMapping.put("file", "#include <string>");
|
||||
importMapping.put("std::string", "#include <string>");
|
||||
importMapping.put("Object", "#include \"Object.h\"");
|
||||
importMapping.put("restbed::Bytes", "#include <corvusoft/restbed/byte.hpp>");
|
||||
}
|
||||
|
||||
@ -189,7 +197,7 @@ public class CppRestbedServerCodegen extends AbstractCppCodegen {
|
||||
*/
|
||||
@Override
|
||||
public String getName() {
|
||||
return "cpp-restbed-server";
|
||||
return "cpp-restbed-server-deprecated";
|
||||
}
|
||||
|
||||
/**
|
||||
@ -203,6 +211,11 @@ public class CppRestbedServerCodegen extends AbstractCppCodegen {
|
||||
return "Generates a C++ API Server with Restbed (https://github.com/Corvusoft/restbed).";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTypeDeclaration(String str) {
|
||||
return toModelName(str);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processOpts() {
|
||||
super.processOpts();
|
||||
@ -267,10 +280,6 @@ public class CppRestbedServerCodegen extends AbstractCppCodegen {
|
||||
codegenModel.imports.add(newImp);
|
||||
}
|
||||
}
|
||||
// Import vector if an enum is present
|
||||
if (codegenModel.hasEnums) {
|
||||
codegenModel.imports.add("#include <vector>");
|
||||
}
|
||||
return codegenModel;
|
||||
}
|
||||
|
||||
@ -284,6 +293,32 @@ public class CppRestbedServerCodegen extends AbstractCppCodegen {
|
||||
return toApiName(name);
|
||||
}
|
||||
|
||||
|
||||
private String capitalizeFirstChar(String str) {
|
||||
if (str.length() > 1) {
|
||||
return Character.toUpperCase(str.charAt(0)) + str.substring(1);
|
||||
} else {
|
||||
return str.toUpperCase(Locale.ENGLISH);
|
||||
}
|
||||
}
|
||||
|
||||
private String convertPathSegmentToResourceNamePart(String pathSegment) {
|
||||
String convertedSegnemt = pathSegment;
|
||||
if (pathSegment.matches(OPEN_API_PATH_PARAM_PATTERN)) {
|
||||
convertedSegnemt = pathSegment.substring(1, pathSegment.length() - 1);
|
||||
}
|
||||
return capitalizeFirstChar(sanitizeName(convertedSegnemt));
|
||||
}
|
||||
|
||||
private String convertPathParamPattern(String pathSegment) {
|
||||
if (pathSegment.matches(OPEN_API_PATH_PARAM_PATTERN)) {
|
||||
String pattern = pathSegment.substring(0, pathSegment.length() - 1);
|
||||
pattern += ": .*}";
|
||||
return pattern;
|
||||
}
|
||||
return pathSegment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OperationsMap postProcessOperationsWithModels(OperationsMap objs, List<ModelMap> allModels) {
|
||||
OperationMap operations = objs.getOperations();
|
||||
@ -291,46 +326,31 @@ public class CppRestbedServerCodegen extends AbstractCppCodegen {
|
||||
List<CodegenOperation> newOpList = new ArrayList<>();
|
||||
|
||||
for (CodegenOperation op : operationList) {
|
||||
String path = op.path;
|
||||
|
||||
String[] items = path.split("/", -1);
|
||||
String[] pathSegments = op.path.split("/", -1);
|
||||
String resourceNameCamelCase = "";
|
||||
op.path = "";
|
||||
for (String item : items) {
|
||||
if (item.length() > 1) {
|
||||
if (item.matches("^\\{(.*)\\}$")) {
|
||||
String tmpResourceName = item.substring(1, item.length() - 1);
|
||||
resourceNameCamelCase += Character.toUpperCase(tmpResourceName.charAt(0)) + tmpResourceName.substring(1);
|
||||
item = item.substring(0, item.length() - 1);
|
||||
item += ": .*}";
|
||||
} else {
|
||||
resourceNameCamelCase += Character.toUpperCase(item.charAt(0)) + item.substring(1);
|
||||
}
|
||||
} else if (item.length() == 1) {
|
||||
resourceNameCamelCase += Character.toUpperCase(item.charAt(0));
|
||||
}
|
||||
op.path += item + "/";
|
||||
StringJoiner joiner = new StringJoiner("/");
|
||||
for (String pathSegment : pathSegments) {
|
||||
resourceNameCamelCase += convertPathSegmentToResourceNamePart(pathSegment);
|
||||
String convertedPathSegment = convertPathParamPattern(pathSegment);
|
||||
joiner.add(convertedPathSegment);
|
||||
}
|
||||
|
||||
op.path = joiner.toString();
|
||||
op.vendorExtensions.put("x-codegen-resource-name", resourceNameCamelCase);
|
||||
|
||||
boolean foundInNewList = false;
|
||||
for (CodegenOperation op1 : newOpList) {
|
||||
if (!foundInNewList) {
|
||||
if (op1.path.equals(op.path)) {
|
||||
foundInNewList = true;
|
||||
final String X_CODEGEN_OTHER_METHODS = "x-codegen-other-methods";
|
||||
@SuppressWarnings("unchecked")
|
||||
List<CodegenOperation> currentOtherMethodList = (List<CodegenOperation>) op1.vendorExtensions.get(X_CODEGEN_OTHER_METHODS);
|
||||
if (currentOtherMethodList == null) {
|
||||
currentOtherMethodList = new ArrayList<>();
|
||||
}
|
||||
|
||||
CodegenOperation op1 = newOpList.stream()
|
||||
.filter(opInList -> opInList.path.equals(op.path))
|
||||
.findAny()
|
||||
.orElse(null);
|
||||
|
||||
if (op1 != null) {
|
||||
List<CodegenOperation> currentOtherMethodList = getCodegenXCodegenOtherMethodsOperations(op1);
|
||||
op.operationIdCamelCase = op1.operationIdCamelCase;
|
||||
currentOtherMethodList.add(op);
|
||||
op1.vendorExtensions.put(X_CODEGEN_OTHER_METHODS, currentOtherMethodList);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!foundInNewList) {
|
||||
else {
|
||||
newOpList.add(op);
|
||||
}
|
||||
}
|
||||
@ -338,6 +358,14 @@ public class CppRestbedServerCodegen extends AbstractCppCodegen {
|
||||
return objs;
|
||||
}
|
||||
|
||||
private List<CodegenOperation> getCodegenXCodegenOtherMethodsOperations(CodegenOperation newOperation) {
|
||||
List<CodegenOperation> currentOtherMethodList = (List<CodegenOperation>) newOperation.vendorExtensions.get(X_CODEGEN_OTHER_METHODS);
|
||||
if (currentOtherMethodList == null) {
|
||||
currentOtherMethodList = new ArrayList<>();
|
||||
}
|
||||
return currentOtherMethodList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Optional - type declaration. This is a String which is used by the
|
||||
* templates to instantiate your types. There is typically special handling
|
||||
@ -359,14 +387,16 @@ public class CppRestbedServerCodegen extends AbstractCppCodegen {
|
||||
return getSchemaType(p) + "<std::string, " + getTypeDeclaration(inner) + ">";
|
||||
} else if (ModelUtils.isByteArraySchema(p)) {
|
||||
return "std::string";
|
||||
} else if (ModelUtils.isFileSchema(p)) {
|
||||
return "std::string";
|
||||
} else if (ModelUtils.isStringSchema(p)
|
||||
|| ModelUtils.isDateSchema(p)
|
||||
|| ModelUtils.isDateTimeSchema(p) || ModelUtils.isFileSchema(p)
|
||||
|| ModelUtils.isDateTimeSchema(p)
|
||||
|| languageSpecificPrimitives.contains(openAPIType)) {
|
||||
return toModelName(openAPIType);
|
||||
}
|
||||
|
||||
return "std::shared_ptr<" + openAPIType + ">";
|
||||
return openAPIType;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -395,6 +425,12 @@ public class CppRestbedServerCodegen extends AbstractCppCodegen {
|
||||
} else {
|
||||
return "\"\"";
|
||||
}
|
||||
} else if (ModelUtils.isFileSchema(p)) {
|
||||
if (p.getDefault() != null) {
|
||||
return p.getDefault().toString();
|
||||
} else {
|
||||
return "std::string{}";
|
||||
}
|
||||
} else if (ModelUtils.isNumberSchema(p)) {
|
||||
if (ModelUtils.isFloatSchema(p)) { // float
|
||||
if (p.getDefault() != null) {
|
||||
@ -432,15 +468,19 @@ public class CppRestbedServerCodegen extends AbstractCppCodegen {
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
String inner = getSchemaType(getAdditionalProperties(p));
|
||||
return "std::map<std::string, " + inner + ">()";
|
||||
} else if (ModelUtils.isSet(p)) {
|
||||
ArraySchema ap = (ArraySchema) p;
|
||||
String inner = getSchemaType(ap.getItems());
|
||||
return "std::set<" + inner + ">()";
|
||||
} else if (ModelUtils.isArraySchema(p)) {
|
||||
ArraySchema ap = (ArraySchema) p;
|
||||
String inner = getSchemaType(ap.getItems());
|
||||
if (!languageSpecificPrimitives.contains(inner)) {
|
||||
inner = "std::shared_ptr<" + inner + ">";
|
||||
}
|
||||
return "std::vector<" + inner + ">()";
|
||||
} else if (ModelUtils.isModel(p)) {
|
||||
String modelName = getTypeDeclaration(p);
|
||||
return modelName + "{}";
|
||||
} else if (!StringUtils.isEmpty(p.get$ref())) {
|
||||
return "std::make_shared<" + toModelName(ModelUtils.getSimpleRef(p.get$ref())) + ">()";
|
||||
return toModelName(ModelUtils.getSimpleRef(p.get$ref())) + "{}";
|
||||
}
|
||||
|
||||
return "nullptr";
|
||||
@ -455,8 +495,7 @@ public class CppRestbedServerCodegen extends AbstractCppCodegen {
|
||||
boolean isString = parameter.isString == Boolean.TRUE;
|
||||
|
||||
if (!isPrimitiveType && !isArray && !isString && !parameter.dataType.startsWith("std::shared_ptr")) {
|
||||
parameter.dataType = "std::shared_ptr<" + parameter.dataType + ">";
|
||||
parameter.defaultValue = "std::make_shared<" + parameter.dataType + ">()";
|
||||
parameter.defaultValue = parameter.dataType + "{}";
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,490 @@
|
||||
/*
|
||||
* Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech)
|
||||
* Copyright 2018 SmartBear Software
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.openapitools.codegen.languages;
|
||||
|
||||
import io.swagger.v3.oas.models.media.ArraySchema;
|
||||
import io.swagger.v3.oas.models.media.Schema;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.openapitools.codegen.*;
|
||||
import org.openapitools.codegen.meta.features.*;
|
||||
import org.openapitools.codegen.model.ModelMap;
|
||||
import org.openapitools.codegen.model.ModelsMap;
|
||||
import org.openapitools.codegen.model.OperationMap;
|
||||
import org.openapitools.codegen.model.OperationsMap;
|
||||
import org.openapitools.codegen.utils.ModelUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import static org.openapitools.codegen.utils.StringUtils.camelize;
|
||||
|
||||
public class CppRestbedServerDeprecatedCodegen extends AbstractCppCodegen {
|
||||
|
||||
public static final String DECLSPEC = "declspec";
|
||||
public static final String DEFAULT_INCLUDE = "defaultInclude";
|
||||
|
||||
protected String packageVersion = "1.0.0";
|
||||
protected String declspec = "";
|
||||
protected String defaultInclude = "";
|
||||
|
||||
public CppRestbedServerDeprecatedCodegen() {
|
||||
super();
|
||||
|
||||
// TODO: cpp-restbed-server maintainer review
|
||||
modifyFeatureSet(features -> features
|
||||
.includeDocumentationFeatures(DocumentationFeature.Readme)
|
||||
.securityFeatures(EnumSet.noneOf(SecurityFeature.class))
|
||||
.excludeGlobalFeatures(
|
||||
GlobalFeature.XMLStructureDefinitions,
|
||||
GlobalFeature.Callbacks,
|
||||
GlobalFeature.LinkObjects,
|
||||
GlobalFeature.ParameterStyling,
|
||||
GlobalFeature.MultiServer
|
||||
)
|
||||
.excludeSchemaSupportFeatures(
|
||||
SchemaSupportFeature.Polymorphism
|
||||
)
|
||||
.excludeParameterFeatures(
|
||||
ParameterFeature.Cookie
|
||||
)
|
||||
);
|
||||
|
||||
apiPackage = "org.openapitools.server.api";
|
||||
modelPackage = "org.openapitools.server.model";
|
||||
|
||||
modelTemplateFiles.put("model-header.mustache", ".h");
|
||||
modelTemplateFiles.put("model-source.mustache", ".cpp");
|
||||
|
||||
apiTemplateFiles.put("api-header.mustache", ".h");
|
||||
apiTemplateFiles.put("api-source.mustache", ".cpp");
|
||||
|
||||
embeddedTemplateDir = templateDir = "cpp-restbed-server-deprecated";
|
||||
|
||||
cliOptions.clear();
|
||||
|
||||
// CLI options
|
||||
addOption(CodegenConstants.MODEL_PACKAGE, "C++ namespace for models (convention: name.space.model).",
|
||||
this.modelPackage);
|
||||
addOption(CodegenConstants.API_PACKAGE, "C++ namespace for apis (convention: name.space.api).",
|
||||
this.apiPackage);
|
||||
addOption(CodegenConstants.PACKAGE_VERSION, "C++ package version.", this.packageVersion);
|
||||
addOption(DECLSPEC, "C++ preprocessor to place before the class name for handling dllexport/dllimport.",
|
||||
this.declspec);
|
||||
addOption(DEFAULT_INCLUDE,
|
||||
"The default include statement that should be placed in all headers for including things like the declspec (convention: #include \"Commons.h\" ",
|
||||
this.defaultInclude);
|
||||
addOption(RESERVED_WORD_PREFIX_OPTION,
|
||||
RESERVED_WORD_PREFIX_DESC,
|
||||
this.reservedWordPrefix);
|
||||
|
||||
supportingFiles.add(new SupportingFile("gitignore.mustache", "", ".gitignore"));
|
||||
supportingFiles.add(new SupportingFile("git_push.sh.mustache", "", "git_push.sh"));
|
||||
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
|
||||
|
||||
languageSpecificPrimitives = new HashSet<>(
|
||||
Arrays.asList("int", "char", "bool", "long", "float", "double", "int32_t", "int64_t"));
|
||||
|
||||
typeMapping = new HashMap<>();
|
||||
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", "restbed::Bytes");
|
||||
typeMapping.put("number", "double");
|
||||
typeMapping.put("UUID", "std::string");
|
||||
typeMapping.put("URI", "std::string");
|
||||
typeMapping.put("ByteArray", "std::string");
|
||||
|
||||
super.importMapping = new HashMap<>();
|
||||
importMapping.put("std::vector", "#include <vector>");
|
||||
importMapping.put("std::map", "#include <map>");
|
||||
importMapping.put("std::string", "#include <string>");
|
||||
importMapping.put("Object", "#include \"Object.h\"");
|
||||
importMapping.put("restbed::Bytes", "#include <corvusoft/restbed/byte.hpp>");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, ModelsMap> updateAllModels(Map<String, ModelsMap> objs) {
|
||||
// Index all CodegenModels by model name.
|
||||
Map<String, CodegenModel> allModels = getAllModels(objs);
|
||||
|
||||
// Clean interfaces of ambiguity
|
||||
for (Entry<String, CodegenModel> cm : allModels.entrySet()) {
|
||||
if (cm.getValue().getInterfaces() != null && !cm.getValue().getInterfaces().isEmpty()) {
|
||||
List<String> newIntf = new ArrayList<>(cm.getValue().getInterfaces());
|
||||
|
||||
for (String intf : allModels.get(cm.getKey()).getInterfaces()) {
|
||||
if (allModels.get(intf).getInterfaces() != null && !allModels.get(intf).getInterfaces().isEmpty()) {
|
||||
for (String intfInner : allModels.get(intf).getInterfaces()) {
|
||||
newIntf.remove(intfInner);
|
||||
}
|
||||
}
|
||||
}
|
||||
cm.getValue().setInterfaces(newIntf);
|
||||
}
|
||||
}
|
||||
|
||||
objs = super.updateAllModels(objs);
|
||||
return objs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Camelize the method name of the getter and setter, but keep underscores at the front
|
||||
*
|
||||
* @param name string to be camelized
|
||||
* @return Camelized string
|
||||
*/
|
||||
@Override
|
||||
public String getterAndSetterCapitalize(String name) {
|
||||
if (name == null || name.length() == 0) {
|
||||
return name;
|
||||
}
|
||||
|
||||
name = toVarName(name);
|
||||
|
||||
if (name.startsWith("_")) {
|
||||
return "_" + camelize(name);
|
||||
}
|
||||
|
||||
return camelize(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures the type of generator.
|
||||
*
|
||||
* @return the CodegenType for this generator
|
||||
*/
|
||||
@Override
|
||||
public CodegenType getTag() {
|
||||
return CodegenType.SERVER;
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures a friendly name for the generator. This will be used by the
|
||||
* generator to select the library with the -g flag.
|
||||
*
|
||||
* @return the friendly name for the generator
|
||||
*/
|
||||
@Override
|
||||
public String getName() {
|
||||
return "cpp-restbed-server-deprecated";
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns human-friendly help for the generator. Provide the consumer with
|
||||
* help tips, parameters here
|
||||
*
|
||||
* @return A string value for the help message
|
||||
*/
|
||||
@Override
|
||||
public String getHelp() {
|
||||
return "Generates a C++ API Server with Restbed (https://github.com/Corvusoft/restbed).";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processOpts() {
|
||||
super.processOpts();
|
||||
|
||||
if (additionalProperties.containsKey(DECLSPEC)) {
|
||||
declspec = additionalProperties.get(DECLSPEC).toString();
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(DEFAULT_INCLUDE)) {
|
||||
defaultInclude = additionalProperties.get(DEFAULT_INCLUDE).toString();
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(RESERVED_WORD_PREFIX_OPTION)) {
|
||||
reservedWordPrefix = additionalProperties.get(RESERVED_WORD_PREFIX_OPTION).toString();
|
||||
}
|
||||
|
||||
additionalProperties.put("modelNamespaceDeclarations", modelPackage.split("\\."));
|
||||
additionalProperties.put("modelNamespace", modelPackage.replaceAll("\\.", "::"));
|
||||
additionalProperties.put("apiNamespaceDeclarations", apiPackage.split("\\."));
|
||||
additionalProperties.put("apiNamespace", apiPackage.replaceAll("\\.", "::"));
|
||||
additionalProperties.put("declspec", declspec);
|
||||
additionalProperties.put("defaultInclude", defaultInclude);
|
||||
additionalProperties.put(RESERVED_WORD_PREFIX_OPTION, reservedWordPrefix);
|
||||
}
|
||||
|
||||
/**
|
||||
* Location to write model files. You can use the modelPackage() as defined
|
||||
* when the class is instantiated
|
||||
*/
|
||||
@Override
|
||||
public String modelFileFolder() {
|
||||
return (outputFolder + "/model").replace("/", File.separator);
|
||||
}
|
||||
|
||||
/**
|
||||
* Location to write api files. You can use the apiPackage() as defined when
|
||||
* the class is instantiated
|
||||
*/
|
||||
@Override
|
||||
public String apiFileFolder() {
|
||||
return (outputFolder + "/api").replace("/", File.separator);
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
||||
// Import vector if an enum is present
|
||||
if (codegenModel.hasEnums) {
|
||||
codegenModel.imports.add("#include <vector>");
|
||||
}
|
||||
return codegenModel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toModelFilename(String name) {
|
||||
return toModelName(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toApiFilename(String name) {
|
||||
return toApiName(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public OperationsMap postProcessOperationsWithModels(OperationsMap objs, List<ModelMap> allModels) {
|
||||
OperationMap operations = objs.getOperations();
|
||||
List<CodegenOperation> operationList = operations.getOperation();
|
||||
List<CodegenOperation> newOpList = new ArrayList<>();
|
||||
|
||||
for (CodegenOperation op : operationList) {
|
||||
String path = op.path;
|
||||
|
||||
String[] items = path.split("/", -1);
|
||||
String resourceNameCamelCase = "";
|
||||
op.path = "";
|
||||
for (String item : items) {
|
||||
if (item.length() > 1) {
|
||||
if (item.matches("^\\{(.*)\\}$")) {
|
||||
String tmpResourceName = item.substring(1, item.length() - 1);
|
||||
resourceNameCamelCase += Character.toUpperCase(tmpResourceName.charAt(0)) + tmpResourceName.substring(1);
|
||||
item = item.substring(0, item.length() - 1);
|
||||
item += ": .*}";
|
||||
} else {
|
||||
resourceNameCamelCase += Character.toUpperCase(item.charAt(0)) + item.substring(1);
|
||||
}
|
||||
} else if (item.length() == 1) {
|
||||
resourceNameCamelCase += Character.toUpperCase(item.charAt(0));
|
||||
}
|
||||
op.path += item + "/";
|
||||
}
|
||||
op.vendorExtensions.put("x-codegen-resource-name", resourceNameCamelCase);
|
||||
|
||||
boolean foundInNewList = false;
|
||||
for (CodegenOperation op1 : newOpList) {
|
||||
if (!foundInNewList) {
|
||||
if (op1.path.equals(op.path)) {
|
||||
foundInNewList = true;
|
||||
final String X_CODEGEN_OTHER_METHODS = "x-codegen-other-methods";
|
||||
@SuppressWarnings("unchecked")
|
||||
List<CodegenOperation> currentOtherMethodList = (List<CodegenOperation>) op1.vendorExtensions.get(X_CODEGEN_OTHER_METHODS);
|
||||
if (currentOtherMethodList == null) {
|
||||
currentOtherMethodList = new ArrayList<>();
|
||||
}
|
||||
op.operationIdCamelCase = op1.operationIdCamelCase;
|
||||
currentOtherMethodList.add(op);
|
||||
op1.vendorExtensions.put(X_CODEGEN_OTHER_METHODS, currentOtherMethodList);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!foundInNewList) {
|
||||
newOpList.add(op);
|
||||
}
|
||||
}
|
||||
operations.setOperation(newOpList);
|
||||
return objs;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 "std::shared_ptr<" + openAPIType + ">";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toDefaultValue(Schema p) {
|
||||
if (ModelUtils.isStringSchema(p)) {
|
||||
if (p.getDefault() != null) {
|
||||
return "\"" + p.getDefault().toString() + "\"";
|
||||
} else {
|
||||
return "\"\"";
|
||||
}
|
||||
} else if (ModelUtils.isBooleanSchema(p)) {
|
||||
if (p.getDefault() != null) {
|
||||
return p.getDefault().toString();
|
||||
} else {
|
||||
return "false";
|
||||
}
|
||||
} else if (ModelUtils.isDateSchema(p)) {
|
||||
if (p.getDefault() != null) {
|
||||
return "\"" + p.getDefault().toString() + "\"";
|
||||
} else {
|
||||
return "\"\"";
|
||||
}
|
||||
} else if (ModelUtils.isDateTimeSchema(p)) {
|
||||
if (p.getDefault() != null) {
|
||||
return "\"" + p.getDefault().toString() + "\"";
|
||||
} else {
|
||||
return "\"\"";
|
||||
}
|
||||
} else if (ModelUtils.isNumberSchema(p)) {
|
||||
if (ModelUtils.isFloatSchema(p)) { // float
|
||||
if (p.getDefault() != null) {
|
||||
return p.getDefault().toString() + "f";
|
||||
} else {
|
||||
return "0.0f";
|
||||
}
|
||||
} else { // double
|
||||
if (p.getDefault() != null) {
|
||||
return p.getDefault().toString();
|
||||
} else {
|
||||
return "0.0";
|
||||
}
|
||||
}
|
||||
} else if (ModelUtils.isIntegerSchema(p)) {
|
||||
if (ModelUtils.isLongSchema(p)) { // long
|
||||
if (p.getDefault() != null) {
|
||||
return p.getDefault().toString() + "L";
|
||||
} else {
|
||||
return "0L";
|
||||
}
|
||||
} else { // integer
|
||||
if (p.getDefault() != null) {
|
||||
return p.getDefault().toString();
|
||||
} else {
|
||||
return "0";
|
||||
}
|
||||
}
|
||||
} else if (ModelUtils.isByteArraySchema(p)) {
|
||||
if (p.getDefault() != null) {
|
||||
return "\"" + p.getDefault().toString() + "\"";
|
||||
} else {
|
||||
return "\"\"";
|
||||
}
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
String inner = getSchemaType(getAdditionalProperties(p));
|
||||
return "std::map<std::string, " + inner + ">()";
|
||||
} else if (ModelUtils.isArraySchema(p)) {
|
||||
ArraySchema ap = (ArraySchema) p;
|
||||
String inner = getSchemaType(ap.getItems());
|
||||
if (!languageSpecificPrimitives.contains(inner)) {
|
||||
inner = "std::shared_ptr<" + inner + ">";
|
||||
}
|
||||
return "std::vector<" + inner + ">()";
|
||||
} else if (!StringUtils.isEmpty(p.get$ref())) {
|
||||
return "std::make_shared<" + toModelName(ModelUtils.getSimpleRef(p.get$ref())) + ">()";
|
||||
}
|
||||
|
||||
return "nullptr";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postProcessParameter(CodegenParameter parameter) {
|
||||
super.postProcessParameter(parameter);
|
||||
|
||||
boolean isPrimitiveType = parameter.isPrimitiveType == Boolean.TRUE;
|
||||
boolean isArray = parameter.isArray == Boolean.TRUE;
|
||||
boolean isString = parameter.isString == Boolean.TRUE;
|
||||
|
||||
if (!isPrimitiveType && !isArray && !isString && !parameter.dataType.startsWith("std::shared_ptr")) {
|
||||
parameter.dataType = "std::shared_ptr<" + parameter.dataType + ">";
|
||||
parameter.defaultValue = "std::make_shared<" + parameter.dataType + ">()";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 void updateCodegenPropertyEnum(CodegenProperty var) {
|
||||
// Remove prefix added by DefaultCodegen
|
||||
String originalDefaultValue = var.defaultValue;
|
||||
super.updateCodegenPropertyEnum(var);
|
||||
var.defaultValue = originalDefaultValue;
|
||||
}
|
||||
}
|
@ -15,6 +15,7 @@ org.openapitools.codegen.languages.CppQtClientCodegen
|
||||
org.openapitools.codegen.languages.CppQtQHttpEngineServerCodegen
|
||||
org.openapitools.codegen.languages.CppPistacheServerCodegen
|
||||
org.openapitools.codegen.languages.CppRestbedServerCodegen
|
||||
org.openapitools.codegen.languages.CppRestbedServerDeprecatedCodegen
|
||||
org.openapitools.codegen.languages.CppRestSdkClientCodegen
|
||||
org.openapitools.codegen.languages.CppTinyClientCodegen
|
||||
org.openapitools.codegen.languages.CppTizenClientCodegen
|
||||
|
23
modules/openapi-generator/src/main/resources/cpp-restbed-server-deprecated/README.mustache
vendored
Normal file
23
modules/openapi-generator/src/main/resources/cpp-restbed-server-deprecated/README.mustache
vendored
Normal file
@ -0,0 +1,23 @@
|
||||
# REST API Server for {{appName}}
|
||||
|
||||
## Overview
|
||||
This API Server was generated by the [OpenAPI Generator](https://openapi-generator.tech) project.
|
||||
It uses the [Restbed](https://github.com/Corvusoft/restbed) Framework.
|
||||
|
||||
|
||||
## Installation
|
||||
Put the package under your project folder and import the API stubs.
|
||||
You need to complete the server stub, as it needs to be connected to a source.
|
||||
|
||||
|
||||
## Libraries required
|
||||
boost_system
|
||||
ssl (if Restbed was built with SSL Support)
|
||||
crypto
|
||||
pthread
|
||||
restbed
|
||||
|
||||
|
||||
## Namespaces
|
||||
{{{apiPackage}}}
|
||||
{{{modelPackage}}}
|
203
modules/openapi-generator/src/main/resources/cpp-restbed-server-deprecated/api-header.mustache
vendored
Normal file
203
modules/openapi-generator/src/main/resources/cpp-restbed-server-deprecated/api-header.mustache
vendored
Normal file
@ -0,0 +1,203 @@
|
||||
{{>licenseInfo}}
|
||||
{{#operations}}/*
|
||||
* {{classname}}.h
|
||||
*
|
||||
* {{description}}
|
||||
*/
|
||||
|
||||
#ifndef {{classname}}_H_
|
||||
#define {{classname}}_H_
|
||||
|
||||
{{{defaultInclude}}}
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
#include <exception>
|
||||
|
||||
#include <corvusoft/restbed/session.hpp>
|
||||
#include <corvusoft/restbed/resource.hpp>
|
||||
#include <corvusoft/restbed/request.hpp>
|
||||
#include <corvusoft/restbed/service.hpp>
|
||||
#include <corvusoft/restbed/settings.hpp>
|
||||
|
||||
{{#imports}}{{{import}}}
|
||||
{{/imports}}
|
||||
|
||||
{{#apiNamespaceDeclarations}}
|
||||
namespace {{this}} {
|
||||
{{/apiNamespaceDeclarations}}
|
||||
|
||||
using namespace {{modelNamespace}};
|
||||
|
||||
///
|
||||
/// Exception to flag problems in the handlers
|
||||
///
|
||||
class {{declspec}} {{classname}}Exception: public std::exception
|
||||
{
|
||||
public:
|
||||
{{classname}}Exception(int status_code, std::string what);
|
||||
|
||||
int getStatus() const;
|
||||
const char* what() const noexcept override;
|
||||
|
||||
private:
|
||||
int m_status;
|
||||
std::string m_what;
|
||||
};
|
||||
|
||||
{{#operation}}
|
||||
/// <summary>
|
||||
/// {{summary}}
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// {{notes}}
|
||||
/// </remarks>
|
||||
class {{declspec}} {{classname}}{{vendorExtensions.x-codegen-resource-name}}Resource: public restbed::Resource
|
||||
{
|
||||
public:
|
||||
{{classname}}{{vendorExtensions.x-codegen-resource-name}}Resource(const std::string& context = "{{contextPath}}");
|
||||
virtual ~{{classname}}{{vendorExtensions.x-codegen-resource-name}}Resource();
|
||||
|
||||
protected:
|
||||
//////////////////////////////////////////////////////////
|
||||
// Override these to implement the server functionality //
|
||||
//////////////////////////////////////////////////////////
|
||||
|
||||
virtual {{#returnType}}std::pair<int, {{{.}}}>{{/returnType}}{{^returnType}}int{{/returnType}} handler_{{httpMethod}}(
|
||||
{{#allParams}}{{{dataType}}} const & {{{paramName}}}{{^-last}}, {{/-last}}{{/allParams}});
|
||||
|
||||
{{#vendorExtensions.x-codegen-other-methods}}
|
||||
virtual {{#returnType}}std::pair<int, {{{.}}}>{{/returnType}}{{^returnType}}int{{/returnType}} handler_{{httpMethod}}(
|
||||
{{#allParams}}{{{dataType}}} const & {{{paramName}}}{{^-last}}, {{/-last}}{{/allParams}});
|
||||
{{/vendorExtensions.x-codegen-other-methods}}
|
||||
|
||||
protected:
|
||||
//////////////////////////////////////
|
||||
// Override these for customization //
|
||||
//////////////////////////////////////
|
||||
|
||||
virtual std::string extractBodyContent(const std::shared_ptr<restbed::Session>& session);
|
||||
|
||||
{{#hasPathParams}}
|
||||
{{#pathParams}}
|
||||
{{#isPrimitiveType}}
|
||||
virtual {{{dataType}}} getPathParam_{{{paramName}}}(const std::shared_ptr<const restbed::Request>& request)
|
||||
{
|
||||
return request->get_path_parameter("{{{paramName}}}", {{{defaultValue}}});
|
||||
}
|
||||
|
||||
{{/isPrimitiveType}}
|
||||
{{/pathParams}}
|
||||
{{/hasPathParams}}
|
||||
{{#hasQueryParams}}
|
||||
{{#queryParams}}
|
||||
{{#isPrimitiveType}}
|
||||
virtual {{{dataType}}} getQueryParam_{{{paramName}}}(const std::shared_ptr<const restbed::Request>& request)
|
||||
{
|
||||
return request->get_query_parameter("{{{paramName}}}", {{{defaultValue}}});
|
||||
}
|
||||
|
||||
{{/isPrimitiveType}}
|
||||
{{/queryParams}}
|
||||
{{/hasQueryParams}}
|
||||
{{#hasHeaderParams}}
|
||||
{{#headerParams}}
|
||||
{{#isPrimitiveType}}
|
||||
virtual {{{dataType}}} getHeader_{{{baseName}}}(const std::shared_ptr<const restbed::Request>& request)
|
||||
{
|
||||
return request->get_header("{{baseName}}", {{{defaultValue}}});
|
||||
}
|
||||
|
||||
{{/isPrimitiveType}}
|
||||
{{/headerParams}}
|
||||
{{/hasHeaderParams}}
|
||||
|
||||
{{#vendorExtensions.x-codegen-other-methods}}
|
||||
{{#hasPathParams}}
|
||||
{{#pathParams}}
|
||||
{{#isPrimitiveType}}
|
||||
virtual {{{dataType}}} getPathParam_{{{paramName}}}_x_extension(const std::shared_ptr<const restbed::Request>& request)
|
||||
{
|
||||
return request->get_path_parameter("{{{paramName}}}", {{{defaultValue}}});
|
||||
}
|
||||
{{/isPrimitiveType}}
|
||||
{{/pathParams}}
|
||||
{{/hasPathParams}}
|
||||
{{#hasQueryParams}}
|
||||
{{#queryParams}}
|
||||
{{#isPrimitiveType}}
|
||||
virtual {{{dataType}}} getQueryParam_{{{paramName}}}_x_extension(const std::shared_ptr<const restbed::Request>& request)
|
||||
{
|
||||
return request->get_query_parameter("{{{paramName}}}", {{{defaultValue}}});
|
||||
}
|
||||
{{/isPrimitiveType}}
|
||||
{{/queryParams}}
|
||||
{{/hasQueryParams}}
|
||||
{{#hasHeaderParams}}
|
||||
{{#headerParams}}
|
||||
{{#isPrimitiveType}}
|
||||
virtual {{{dataType}}} getHeader_{{{baseName}}}_x_extension(const std::shared_ptr<const restbed::Request>& request)
|
||||
{
|
||||
return request->get_header("{{baseName}}", {{{defaultValue}}});
|
||||
}
|
||||
{{/isPrimitiveType}}
|
||||
{{/headerParams}}
|
||||
{{/hasHeaderParams}}
|
||||
{{/vendorExtensions.x-codegen-other-methods}}
|
||||
|
||||
virtual std::pair<int, std::string> handle{{classname}}Exception(const {{classname}}Exception& e);
|
||||
virtual std::pair<int, std::string> handleStdException(const std::exception& e);
|
||||
virtual std::pair<int, std::string> handleUnspecifiedException();
|
||||
|
||||
virtual void setResponseHeader(const std::shared_ptr<restbed::Session>& session,
|
||||
const std::string& header);
|
||||
|
||||
|
||||
virtual void returnResponse(const std::shared_ptr<restbed::Session>& session,
|
||||
const int status, const std::string& result, const std::string& contentType);
|
||||
virtual void defaultSessionClose(const std::shared_ptr<restbed::Session>& session,
|
||||
const int status, const std::string& result);
|
||||
|
||||
private:
|
||||
void handler_{{httpMethod}}_internal(const std::shared_ptr<restbed::Session> session);
|
||||
{{#vendorExtensions.x-codegen-other-methods}}
|
||||
void handler_{{httpMethod}}_internal(const std::shared_ptr<restbed::Session> session);
|
||||
{{/vendorExtensions.x-codegen-other-methods}}
|
||||
};
|
||||
|
||||
|
||||
{{/operation}}
|
||||
|
||||
//
|
||||
// The restbed service to actually implement the REST server
|
||||
//
|
||||
class {{declspec}} {{classname}}
|
||||
{
|
||||
public:
|
||||
explicit {{classname}}(std::shared_ptr<restbed::Service> const& restbedService);
|
||||
virtual ~{{classname}}();
|
||||
|
||||
{{#operation}}
|
||||
virtual void set{{classname}}{{vendorExtensions.x-codegen-resource-name}}Resource(std::shared_ptr<{{classname}}{{vendorExtensions.x-codegen-resource-name}}Resource> sp{{classname}}{{vendorExtensions.x-codegen-resource-name}}Resource);
|
||||
{{/operation}}
|
||||
|
||||
virtual void publishDefaultResources();
|
||||
|
||||
virtual std::shared_ptr<restbed::Service> service();
|
||||
|
||||
protected:
|
||||
{{#operation}}
|
||||
std::shared_ptr<{{classname}}{{vendorExtensions.x-codegen-resource-name}}Resource> m_sp{{classname}}{{vendorExtensions.x-codegen-resource-name}}Resource;
|
||||
{{/operation}}
|
||||
|
||||
private:
|
||||
std::shared_ptr<restbed::Service> m_service;
|
||||
};
|
||||
|
||||
|
||||
{{#apiNamespaceDeclarations}}
|
||||
}
|
||||
{{/apiNamespaceDeclarations}}
|
||||
|
||||
#endif /* {{classname}}_H_ */
|
||||
|
||||
{{/operations}}
|
400
modules/openapi-generator/src/main/resources/cpp-restbed-server-deprecated/api-source.mustache
vendored
Normal file
400
modules/openapi-generator/src/main/resources/cpp-restbed-server-deprecated/api-source.mustache
vendored
Normal file
@ -0,0 +1,400 @@
|
||||
{{>licenseInfo}}
|
||||
{{#operations}}
|
||||
|
||||
#include <corvusoft/restbed/byte.hpp>
|
||||
#include <corvusoft/restbed/string.hpp>
|
||||
#include <corvusoft/restbed/settings.hpp>
|
||||
#include <corvusoft/restbed/request.hpp>
|
||||
#include <corvusoft/restbed/uri.hpp>
|
||||
#include <boost/property_tree/ptree.hpp>
|
||||
#include <boost/property_tree/json_parser.hpp>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <boost/algorithm/string.hpp>
|
||||
|
||||
#include "{{classname}}.h"
|
||||
|
||||
{{#apiNamespaceDeclarations}}
|
||||
namespace {{this}} {
|
||||
{{/apiNamespaceDeclarations}}
|
||||
|
||||
using namespace {{modelNamespace}};
|
||||
|
||||
{{classname}}Exception::{{classname}}Exception(int status_code, std::string what)
|
||||
: m_status(status_code),
|
||||
m_what(what)
|
||||
{
|
||||
|
||||
}
|
||||
int {{classname}}Exception::getStatus() const
|
||||
{
|
||||
return m_status;
|
||||
}
|
||||
const char* {{classname}}Exception::what() const noexcept
|
||||
{
|
||||
return m_what.c_str();
|
||||
}
|
||||
|
||||
|
||||
template<class MODEL_T>
|
||||
std::shared_ptr<MODEL_T> extractJsonModelBodyParam(const std::string& bodyContent)
|
||||
{
|
||||
std::stringstream sstream(bodyContent);
|
||||
boost::property_tree::ptree pt;
|
||||
boost::property_tree::json_parser::read_json(sstream, pt);
|
||||
|
||||
auto model = std::make_shared<MODEL_T>(pt);
|
||||
return model;
|
||||
}
|
||||
|
||||
template<class MODEL_T>
|
||||
std::vector<std::shared_ptr<MODEL_T>> extractJsonArrayBodyParam(const std::string& bodyContent)
|
||||
{
|
||||
std::stringstream sstream(bodyContent);
|
||||
boost::property_tree::ptree pt;
|
||||
boost::property_tree::json_parser::read_json(sstream, pt);
|
||||
|
||||
auto arrayRet = std::vector<std::shared_ptr<MODEL_T>>();
|
||||
for (const auto& child: pt) {
|
||||
arrayRet.emplace_back(std::make_shared<MODEL_T>(child.second));
|
||||
}
|
||||
return arrayRet;
|
||||
}
|
||||
|
||||
template <class KEY_T, class VAL_T>
|
||||
std::string convertMapResponse(const std::map<KEY_T, VAL_T>& map)
|
||||
{
|
||||
boost::property_tree::ptree pt;
|
||||
for(const auto &kv: map) {
|
||||
pt.push_back(boost::property_tree::ptree::value_type(
|
||||
boost::lexical_cast<std::string>(kv.first),
|
||||
boost::property_tree::ptree(
|
||||
boost::lexical_cast<std::string>(kv.second))));
|
||||
}
|
||||
std::stringstream sstream;
|
||||
write_json(sstream, pt);
|
||||
std::string result = sstream.str();
|
||||
return result;
|
||||
}
|
||||
|
||||
{{#operation}}
|
||||
{{classname}}{{vendorExtensions.x-codegen-resource-name}}Resource::{{classname}}{{vendorExtensions.x-codegen-resource-name}}Resource(const std::string& context /* = "{{contextPath}}" */)
|
||||
{
|
||||
this->set_path(context + "{{path}}");
|
||||
this->set_method_handler("{{httpMethod}}",
|
||||
std::bind(&{{classname}}{{vendorExtensions.x-codegen-resource-name}}Resource::handler_{{httpMethod}}_internal, this,
|
||||
std::placeholders::_1));
|
||||
{{#vendorExtensions.x-codegen-other-methods}}
|
||||
this->set_method_handler("{{httpMethod}}",
|
||||
std::bind(&{{classname}}{{vendorExtensions.x-codegen-resource-name}}Resource::handler_{{httpMethod}}_internal, this,
|
||||
std::placeholders::_1));
|
||||
{{/vendorExtensions.x-codegen-other-methods}}
|
||||
}
|
||||
|
||||
{{classname}}{{vendorExtensions.x-codegen-resource-name}}Resource::~{{classname}}{{vendorExtensions.x-codegen-resource-name}}Resource()
|
||||
{
|
||||
}
|
||||
|
||||
std::pair<int, std::string> {{classname}}{{vendorExtensions.x-codegen-resource-name}}Resource::handle{{classname}}Exception(const {{classname}}Exception& e)
|
||||
{
|
||||
return std::make_pair<int, std::string>(e.getStatus(), e.what());
|
||||
}
|
||||
|
||||
std::pair<int, std::string> {{classname}}{{vendorExtensions.x-codegen-resource-name}}Resource::handleStdException(const std::exception& e)
|
||||
{
|
||||
return std::make_pair<int, std::string>(500, e.what());
|
||||
}
|
||||
|
||||
std::pair<int, std::string> {{classname}}{{vendorExtensions.x-codegen-resource-name}}Resource::handleUnspecifiedException()
|
||||
{
|
||||
return std::make_pair<int, std::string>(500, "Unknown exception occurred");
|
||||
}
|
||||
|
||||
void {{classname}}{{vendorExtensions.x-codegen-resource-name}}Resource::setResponseHeader(const std::shared_ptr<restbed::Session>& session, const std::string& header)
|
||||
{
|
||||
session->set_header(header, "");
|
||||
}
|
||||
|
||||
void {{classname}}{{vendorExtensions.x-codegen-resource-name}}Resource::returnResponse(const std::shared_ptr<restbed::Session>& session, const int status, const std::string& result, const std::string& contentType)
|
||||
{
|
||||
session->close(status, result, { {"Connection", "close"}, {"Content-Type", contentType} });
|
||||
}
|
||||
|
||||
void {{classname}}{{vendorExtensions.x-codegen-resource-name}}Resource::defaultSessionClose(const std::shared_ptr<restbed::Session>& session, const int status, const std::string& result)
|
||||
{
|
||||
session->close(status, result, { {"Connection", "close"} });
|
||||
}
|
||||
|
||||
void {{classname}}{{vendorExtensions.x-codegen-resource-name}}Resource::handler_{{httpMethod}}_internal(const std::shared_ptr<restbed::Session> session)
|
||||
{
|
||||
const auto request = session->get_request();
|
||||
{{#hasBodyParam}}
|
||||
std::string bodyContent = extractBodyContent(session);
|
||||
|
||||
// Get body params or form params here from the body content string
|
||||
{{#allParams}}
|
||||
{{#isModel}}
|
||||
auto {{paramName}} = extractJsonModelBodyParam<{{{baseType}}}>(bodyContent);
|
||||
{{/isModel}}
|
||||
{{#isArray}}
|
||||
auto {{paramName}} = extractJsonArrayBodyParam<{{{baseType}}}>(bodyContent);
|
||||
{{/isArray}}
|
||||
{{/allParams}}
|
||||
{{/hasBodyParam}}
|
||||
|
||||
{{#hasPathParams}}
|
||||
// Getting the path params
|
||||
{{#pathParams}}
|
||||
{{#isPrimitiveType}}
|
||||
const {{{dataType}}} {{{paramName}}} = getPathParam_{{paramName}}(request);
|
||||
{{/isPrimitiveType}}
|
||||
{{/pathParams}}
|
||||
{{/hasPathParams}}
|
||||
|
||||
{{#hasQueryParams}}
|
||||
// Getting the query params
|
||||
{{#queryParams}}
|
||||
{{#isPrimitiveType}}
|
||||
const {{{dataType}}} {{{paramName}}} = getQueryParam_{{paramName}}(request);
|
||||
{{/isPrimitiveType}}
|
||||
{{/queryParams}}
|
||||
{{/hasQueryParams}}
|
||||
|
||||
{{#hasHeaderParams}}
|
||||
// Getting the headers
|
||||
{{#headerParams}}
|
||||
{{#isPrimitiveType}}
|
||||
const {{{dataType}}} {{{paramName}}} = getHeader_{{baseName}}(request);
|
||||
{{/isPrimitiveType}}
|
||||
{{/headerParams}}
|
||||
{{/hasHeaderParams}}
|
||||
|
||||
int status_code = 500;
|
||||
{{#returnType}}
|
||||
{{{.}}} resultObject = {{{defaultResponse}}};
|
||||
{{/returnType}}
|
||||
std::string result = "";
|
||||
|
||||
try {
|
||||
{{#returnType}}
|
||||
std::tie(status_code, resultObject) =
|
||||
{{/returnType}}
|
||||
{{^returnType}}
|
||||
status_code =
|
||||
{{/returnType}}
|
||||
handler_{{httpMethod}}({{#allParams}}{{paramName}}{{^-last}}, {{ / -last}}{{ / allParams}});
|
||||
}
|
||||
catch(const {{classname}}Exception& e) {
|
||||
std::tie(status_code, result) = handle{{classname}}Exception(e);
|
||||
}
|
||||
catch(const std::exception& e) {
|
||||
std::tie(status_code, result) = handleStdException(e);
|
||||
}
|
||||
catch(...) {
|
||||
std::tie(status_code, result) = handleUnspecifiedException();
|
||||
}
|
||||
|
||||
{{#responses}}
|
||||
if (status_code == {{code}}) {
|
||||
{{#returnType}}
|
||||
{{#isModel}}
|
||||
{{#isString}}
|
||||
result = resultObject;
|
||||
{{/isString}}
|
||||
{{^isString}}
|
||||
result = resultObject->toJsonString();
|
||||
{{/isString}}
|
||||
{{/isModel}}
|
||||
{{#isMap}}
|
||||
result = convertMapResponse(resultObject);
|
||||
{{/isMap}}
|
||||
{{/returnType}}
|
||||
{{#headers}}
|
||||
// Description: {{{description}}}
|
||||
setResponseHeader(session, "{{baseName}}");
|
||||
{{/headers}}
|
||||
|
||||
{{#primitiveType}}
|
||||
const constexpr auto contentType = "text/plain";
|
||||
{{/primitiveType}}
|
||||
{{^primitiveType}}
|
||||
const constexpr auto contentType = "application/json";
|
||||
{{/primitiveType}}
|
||||
returnResponse(session, {{code}}, result.empty() ? "{{message}}" : result, contentType);
|
||||
return;
|
||||
}
|
||||
{{/responses}}
|
||||
defaultSessionClose(session, status_code, result);
|
||||
}
|
||||
|
||||
{{#vendorExtensions.x-codegen-other-methods}}
|
||||
// x-extension
|
||||
void {{classname}}{{vendorExtensions.x-codegen-resource-name}}Resource::handler_{{httpMethod}}_internal(const std::shared_ptr<restbed::Session> session) {
|
||||
|
||||
const auto request = session->get_request();
|
||||
{{#hasBodyParam}}
|
||||
std::string bodyContent = extractBodyContent(session);
|
||||
|
||||
// body params or form params here from the body content string
|
||||
{{#allParams}}
|
||||
{{#isModel}}
|
||||
auto {{paramName}} = extractJsonModelBodyParam<{{{baseType}}}>(bodyContent);
|
||||
{{/isModel}}
|
||||
{{#isArray}}
|
||||
auto {{paramName}} = extractJsonArrayBodyParam<{{{baseType}}}>(bodyContent);
|
||||
{{/isArray}}
|
||||
{{^isModel}}
|
||||
{{^isArray}}
|
||||
auto {{paramName}} = std::make_shared<{{{baseType}}}>(bodyContent);
|
||||
{{/isArray}}
|
||||
{{/isModel}}
|
||||
{{/allParams}}
|
||||
{{/hasBodyParam}}
|
||||
|
||||
{{#hasPathParams}}
|
||||
// Getting the path params
|
||||
{{#pathParams}}
|
||||
{{#isPrimitiveType}}
|
||||
const {{{dataType}}} {{{paramName}}} = getPathParam_{{paramName}}_x_extension(request);
|
||||
|
||||
{{/isPrimitiveType}}
|
||||
{{/pathParams}}
|
||||
{{/hasPathParams}}
|
||||
{{#hasQueryParams}}
|
||||
// Getting the query params
|
||||
{{#queryParams}}
|
||||
{{#isPrimitiveType}}
|
||||
const {{{dataType}}} {{{paramName}}} = getQueryParam_{{paramName}}_x_extension(request);
|
||||
|
||||
{{/isPrimitiveType}}
|
||||
{{/queryParams}}
|
||||
{{/hasQueryParams}}
|
||||
{{#hasHeaderParams}}
|
||||
// Getting the headers
|
||||
{{#headerParams}}
|
||||
{{#isPrimitiveType}}
|
||||
const {{{dataType}}} {{{paramName}}} = getHeader_{{baseName}}_x_extension(request);
|
||||
|
||||
{{/isPrimitiveType}}
|
||||
{{/headerParams}}
|
||||
{{/hasHeaderParams}}
|
||||
|
||||
int status_code = 500;
|
||||
{{#returnType}}
|
||||
{{{.}}} resultObject = {{{defaultResponse}}};
|
||||
{{/returnType}}
|
||||
std::string result = "";
|
||||
|
||||
try {
|
||||
{{#returnType}}
|
||||
std::tie(status_code, resultObject) =
|
||||
{{/returnType}}
|
||||
{{^returnType}}
|
||||
status_code =
|
||||
{{/returnType}}
|
||||
handler_{{httpMethod}}({{#allParams}}{{paramName}}{{^-last}}, {{/-last}}{{/allParams}});
|
||||
}
|
||||
catch(const {{classname}}Exception& e) {
|
||||
std::tie(status_code, result) = handle{{classname}}Exception(e);
|
||||
}
|
||||
catch(const std::exception& e) {
|
||||
std::tie(status_code, result) = handleStdException(e);
|
||||
}
|
||||
catch(...) {
|
||||
std::tie(status_code, result) = handleUnspecifiedException();
|
||||
}
|
||||
|
||||
{{#responses}}
|
||||
if (status_code == {{code}}) {
|
||||
{{#returnType}}
|
||||
{{#isModel}}
|
||||
{{#isString}}
|
||||
result = resultObject;
|
||||
{{/isString}}
|
||||
{{^isString}}
|
||||
result = resultObject->toJsonString();
|
||||
{{/isString}}
|
||||
{{/isModel}}
|
||||
{{#isMap}}
|
||||
result = convertMapResponse(resultObject);
|
||||
{{/isMap}}
|
||||
{{/returnType}}
|
||||
{{#headers}}
|
||||
// Description: {{{description}}}
|
||||
setResponseHeader(session, "{{baseName}}");
|
||||
{{/headers}}
|
||||
|
||||
{{#primitiveType}}
|
||||
const constexpr auto contentType = "text/plain";
|
||||
{{/primitiveType}}
|
||||
{{^primitiveType}}
|
||||
const constexpr auto contentType = "application/json";
|
||||
{{/primitiveType}}
|
||||
returnResponse(session, {{code}}, result.empty() ? "{{message}}" : result, contentType);
|
||||
return;
|
||||
}
|
||||
{{/responses}}
|
||||
defaultSessionClose(session, status_code, result);
|
||||
}
|
||||
{{/vendorExtensions.x-codegen-other-methods}}
|
||||
|
||||
{{#returnType}}std::pair<int, {{{.}}}>{{/returnType}}{{^returnType}}int{{/returnType}} {{classname}}{{vendorExtensions.x-codegen-resource-name}}Resource::handler_{{httpMethod}}(
|
||||
{{#allParams}}{{{dataType}}} const & {{{paramName}}}{{^-last}}, {{/-last}}{{/allParams}})
|
||||
{
|
||||
throw {{classname}}Exception(501, "Not implemented");
|
||||
}
|
||||
|
||||
{{#vendorExtensions.x-codegen-other-methods}}
|
||||
{{#returnType}}std::pair<int, {{{.}}}>{{/returnType}}{{^returnType}}int{{/returnType}} {{classname}}{{vendorExtensions.x-codegen-resource-name}}Resource::handler_{{httpMethod}}(
|
||||
{{#allParams}}{{{dataType}}} const & {{{paramName}}}{{^-last}}, {{/-last}}{{/allParams}})
|
||||
{
|
||||
throw {{classname}}Exception(501, "Not implemented");
|
||||
}
|
||||
{{/vendorExtensions.x-codegen-other-methods}}
|
||||
|
||||
std::string {{classname}}{{vendorExtensions.x-codegen-resource-name}}Resource::extractBodyContent(const std::shared_ptr<restbed::Session>& session) {
|
||||
const auto request = session->get_request();
|
||||
int content_length = request->get_header("Content-Length", 0);
|
||||
std::string bodyContent;
|
||||
session->fetch(content_length,
|
||||
[&bodyContent](const std::shared_ptr<restbed::Session> session,
|
||||
const restbed::Bytes &body) {
|
||||
bodyContent = restbed::String::format(
|
||||
"%.*s\n", (int)body.size(), body.data());
|
||||
});
|
||||
return bodyContent;
|
||||
}
|
||||
{{/operation}}
|
||||
|
||||
{{classname}}::{{classname}}(std::shared_ptr<restbed::Service> const& restbedService)
|
||||
: m_service(restbedService)
|
||||
{
|
||||
}
|
||||
|
||||
{{classname}}::~{{classname}}() {}
|
||||
|
||||
{{#operation}}
|
||||
void {{classname}}::set{{classname}}{{vendorExtensions.x-codegen-resource-name}}Resource(std::shared_ptr<{{classname}}{{vendorExtensions.x-codegen-resource-name}}Resource> sp{{classname}}{{vendorExtensions.x-codegen-resource-name}}Resource) {
|
||||
m_sp{{classname}}{{vendorExtensions.x-codegen-resource-name}}Resource = sp{{classname}}{{vendorExtensions.x-codegen-resource-name}}Resource;
|
||||
m_service->publish(m_sp{{classname}}{{vendorExtensions.x-codegen-resource-name}}Resource);
|
||||
}
|
||||
{{/operation}}
|
||||
|
||||
|
||||
void {{classname}}::publishDefaultResources() {
|
||||
{{#operation}}
|
||||
if (!m_sp{{classname}}{{vendorExtensions.x-codegen-resource-name}}Resource) {
|
||||
set{{classname}}{{vendorExtensions.x-codegen-resource-name}}Resource(std::make_shared<{{classname}}{{vendorExtensions.x-codegen-resource-name}}Resource>());
|
||||
}
|
||||
{{/operation}}
|
||||
}
|
||||
|
||||
std::shared_ptr<restbed::Service> {{classname}}::service() {
|
||||
return m_service;
|
||||
}
|
||||
|
||||
|
||||
{{#apiNamespaceDeclarations}}
|
||||
}
|
||||
{{/apiNamespaceDeclarations}}
|
||||
|
||||
{{/operations}}
|
57
modules/openapi-generator/src/main/resources/cpp-restbed-server-deprecated/git_push.sh.mustache
vendored
Normal file
57
modules/openapi-generator/src/main/resources/cpp-restbed-server-deprecated/git_push.sh.mustache
vendored
Normal file
@ -0,0 +1,57 @@
|
||||
#!/bin/sh
|
||||
# ref: https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/
|
||||
#
|
||||
# Usage example: /bin/sh ./git_push.sh wing328 openapi-petstore-perl "minor update" "gitlab.com"
|
||||
|
||||
git_user_id=$1
|
||||
git_repo_id=$2
|
||||
release_note=$3
|
||||
git_host=$4
|
||||
|
||||
if [ "$git_host" = "" ]; then
|
||||
git_host="{{{gitHost}}}"
|
||||
echo "[INFO] No command line input provided. Set \$git_host to $git_host"
|
||||
fi
|
||||
|
||||
if [ "$git_user_id" = "" ]; then
|
||||
git_user_id="{{{gitUserId}}}"
|
||||
echo "[INFO] No command line input provided. Set \$git_user_id to $git_user_id"
|
||||
fi
|
||||
|
||||
if [ "$git_repo_id" = "" ]; then
|
||||
git_repo_id="{{{gitRepoId}}}"
|
||||
echo "[INFO] No command line input provided. Set \$git_repo_id to $git_repo_id"
|
||||
fi
|
||||
|
||||
if [ "$release_note" = "" ]; then
|
||||
release_note="{{{releaseNote}}}"
|
||||
echo "[INFO] No command line input provided. Set \$release_note to $release_note"
|
||||
fi
|
||||
|
||||
# Initialize the local directory as a Git repository
|
||||
git init
|
||||
|
||||
# Adds the files in the local repository and stages them for commit.
|
||||
git add .
|
||||
|
||||
# Commits the tracked changes and prepares them to be pushed to a remote repository.
|
||||
git commit -m "$release_note"
|
||||
|
||||
# Sets the new remote
|
||||
git_remote=$(git remote)
|
||||
if [ "$git_remote" = "" ]; then # git remote not defined
|
||||
|
||||
if [ "$GIT_TOKEN" = "" ]; then
|
||||
echo "[INFO] \$GIT_TOKEN (environment variable) is not set. Using the git credential in your environment."
|
||||
git remote add origin https://${git_host}/${git_user_id}/${git_repo_id}.git
|
||||
else
|
||||
git remote add origin https://${git_user_id}:"${GIT_TOKEN}"@${git_host}/${git_user_id}/${git_repo_id}.git
|
||||
fi
|
||||
|
||||
fi
|
||||
|
||||
git pull origin master
|
||||
|
||||
# Pushes (Forces) the changes in the local repository up to the remote repository
|
||||
echo "Git pushing to https://${git_host}/${git_user_id}/${git_repo_id}.git"
|
||||
git push origin master 2>&1 | grep -v 'To https'
|
29
modules/openapi-generator/src/main/resources/cpp-restbed-server-deprecated/gitignore.mustache
vendored
Normal file
29
modules/openapi-generator/src/main/resources/cpp-restbed-server-deprecated/gitignore.mustache
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
# Compiled Object files
|
||||
*.slo
|
||||
*.lo
|
||||
*.o
|
||||
*.obj
|
||||
|
||||
# Precompiled Headers
|
||||
*.gch
|
||||
*.pch
|
||||
|
||||
# Compiled Dynamic libraries
|
||||
*.so
|
||||
*.dylib
|
||||
*.dll
|
||||
|
||||
# Fortran module files
|
||||
*.mod
|
||||
*.smod
|
||||
|
||||
# Compiled Static libraries
|
||||
*.lai
|
||||
*.la
|
||||
*.a
|
||||
*.lib
|
||||
|
||||
# Executables
|
||||
*.exe
|
||||
*.out
|
||||
*.app
|
11
modules/openapi-generator/src/main/resources/cpp-restbed-server-deprecated/licenseInfo.mustache
vendored
Normal file
11
modules/openapi-generator/src/main/resources/cpp-restbed-server-deprecated/licenseInfo.mustache
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
/**
|
||||
* {{{appName}}}
|
||||
* {{{appDescription}}}
|
||||
*
|
||||
* {{#version}}The version of the OpenAPI document: {{{.}}}{{/version}}
|
||||
* {{#infoEmail}}Contact: {{{.}}}{{/infoEmail}}
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator {{{generatorVersion}}}.
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
98
modules/openapi-generator/src/main/resources/cpp-restbed-server-deprecated/model-header.mustache
vendored
Normal file
98
modules/openapi-generator/src/main/resources/cpp-restbed-server-deprecated/model-header.mustache
vendored
Normal file
@ -0,0 +1,98 @@
|
||||
{{>licenseInfo}}
|
||||
{{#models}}{{#model}}/*
|
||||
* {{classname}}.h
|
||||
*
|
||||
* {{description}}
|
||||
*/
|
||||
|
||||
#ifndef {{classname}}_H_
|
||||
#define {{classname}}_H_
|
||||
|
||||
{{{defaultInclude}}}
|
||||
|
||||
{{#imports}}{{{this}}}
|
||||
{{/imports}}
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
{{#hasEnums}}
|
||||
#include <array>
|
||||
{{/hasEnums}}
|
||||
#include <boost/property_tree/ptree.hpp>
|
||||
|
||||
{{#modelNamespaceDeclarations}}
|
||||
namespace {{this}} {
|
||||
{{/modelNamespaceDeclarations}}
|
||||
|
||||
/// <summary>
|
||||
/// {{description}}
|
||||
/// </summary>
|
||||
{{#circularReferences}}
|
||||
class {{{this}}};
|
||||
{{/circularReferences}}
|
||||
class {{declspec}} {{classname}} {{#interfaces}}{{#-first}}:{{/-first}}{{^-first}},{{/-first}} public {{{this}}}{{/interfaces}}
|
||||
{
|
||||
public:
|
||||
{{classname}}() = default;
|
||||
explicit {{classname}}(boost::property_tree::ptree const& pt);
|
||||
virtual ~{{classname}}() = default;
|
||||
|
||||
std::string toJsonString(bool prettyJson = false);
|
||||
void fromJsonString(std::string const& jsonString);
|
||||
boost::property_tree::ptree toPropertyTree();
|
||||
void fromPropertyTree(boost::property_tree::ptree const& pt);
|
||||
|
||||
/////////////////////////////////////////////
|
||||
/// {{classname}} members
|
||||
{{#vars}}
|
||||
|
||||
/// <summary>
|
||||
/// {{description}}
|
||||
/// </summary>
|
||||
{{{dataType}}} {{getter}}() const;
|
||||
void {{setter}}({{{dataType}}} value);
|
||||
{{/vars}}
|
||||
|
||||
protected:
|
||||
//////////////////////////////////////
|
||||
// Override these for customization //
|
||||
//////////////////////////////////////
|
||||
|
||||
virtual std::string toJsonString_internal(bool prettyJson = false);
|
||||
virtual void fromJsonString_internal(std::string const& jsonString);
|
||||
virtual boost::property_tree::ptree toPropertyTree_internal();
|
||||
virtual void fromPropertyTree_internal(boost::property_tree::ptree const& pt);
|
||||
|
||||
|
||||
protected:
|
||||
{{#vars}}
|
||||
{{^isContainer}}
|
||||
{{^isModel}}
|
||||
{{{dataType}}} m_{{name}} = {{{defaultValue}}};
|
||||
{{/isModel}}
|
||||
{{#isModel}}
|
||||
{{{dataType}}} m_{{name}};
|
||||
{{/isModel}}
|
||||
{{/isContainer}}
|
||||
{{#isContainer}}
|
||||
{{{dataType}}} m_{{name}};
|
||||
{{/isContainer}}
|
||||
{{/vars}}
|
||||
{{#vars}}
|
||||
{{#isEnum}}
|
||||
const std::array<std::string, {{#allowableValues}}{{#enumVars}}{{#-last}}{{-index}}{{/-last}}{{/enumVars}}{{/allowableValues}}> m_{{enumName}} = {
|
||||
{{#allowableValues}}{{#enumVars}}"{{{value}}}"{{^-last}},{{/-last}}{{/enumVars}}{{/allowableValues}}
|
||||
};
|
||||
|
||||
{{/isEnum}}
|
||||
{{/vars}}
|
||||
};
|
||||
|
||||
std::vector<{{classname}}> create{{classname}}VectorFromJsonString(const std::string& json);
|
||||
|
||||
{{#modelNamespaceDeclarations}}
|
||||
}
|
||||
{{/modelNamespaceDeclarations}}
|
||||
|
||||
#endif /* {{classname}}_H_ */
|
||||
{{/model}}
|
||||
{{/models}}
|
233
modules/openapi-generator/src/main/resources/cpp-restbed-server-deprecated/model-source.mustache
vendored
Normal file
233
modules/openapi-generator/src/main/resources/cpp-restbed-server-deprecated/model-source.mustache
vendored
Normal file
@ -0,0 +1,233 @@
|
||||
{{>licenseInfo}}
|
||||
{{#models}}{{#model}}
|
||||
|
||||
#include "{{classname}}.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <sstream>
|
||||
#include <stdexcept>
|
||||
{{#hasEnums}}
|
||||
#include <algorithm>
|
||||
{{/hasEnums}}
|
||||
#include <boost/property_tree/ptree.hpp>
|
||||
#include <boost/property_tree/json_parser.hpp>
|
||||
|
||||
using boost::property_tree::ptree;
|
||||
using boost::property_tree::read_json;
|
||||
using boost::property_tree::write_json;
|
||||
|
||||
{{#modelNamespaceDeclarations}}
|
||||
namespace {{this}} {
|
||||
{{/modelNamespaceDeclarations}}
|
||||
|
||||
{{classname}}::{{classname}}(boost::property_tree::ptree const& pt)
|
||||
{
|
||||
fromPropertyTree(pt);
|
||||
}
|
||||
|
||||
std::string {{classname}}::toJsonString(bool prettyJson /* = false */)
|
||||
{
|
||||
return toJsonString_internal(prettyJson);
|
||||
}
|
||||
|
||||
void {{classname}}::fromJsonString(std::string const& jsonString)
|
||||
{
|
||||
fromJsonString_internal(jsonString);
|
||||
}
|
||||
|
||||
boost::property_tree::ptree {{classname}}::toPropertyTree()
|
||||
{
|
||||
return toPropertyTree_internal();
|
||||
}
|
||||
|
||||
void {{classname}}::fromPropertyTree(boost::property_tree::ptree const& pt)
|
||||
{
|
||||
fromPropertyTree_internal(pt);
|
||||
}
|
||||
|
||||
std::string {{classname}}::toJsonString_internal(bool prettyJson)
|
||||
{
|
||||
std::stringstream ss;
|
||||
write_json(ss, this->toPropertyTree(), prettyJson);
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
void {{classname}}::fromJsonString_internal(std::string const& jsonString)
|
||||
{
|
||||
std::stringstream ss(jsonString);
|
||||
ptree pt;
|
||||
read_json(ss,pt);
|
||||
this->fromPropertyTree(pt);
|
||||
}
|
||||
|
||||
ptree {{classname}}::toPropertyTree_internal()
|
||||
{
|
||||
ptree pt;
|
||||
ptree tmp_node;
|
||||
{{#vars}}
|
||||
{{^isContainer}}
|
||||
{{#isPrimitiveType}}
|
||||
pt.put("{{baseName}}", m_{{name}});
|
||||
{{/isPrimitiveType}}
|
||||
{{^isPrimitiveType}}
|
||||
{{#isString}}
|
||||
pt.put("{{baseName}}", m_{{name}});
|
||||
{{/isString}}
|
||||
{{#isDate}}
|
||||
pt.put("{{baseName}}", m_{{name}});
|
||||
{{/isDate}}
|
||||
{{#isDateTime}}
|
||||
pt.put("{{baseName}}", m_{{name}});
|
||||
{{/isDateTime}}
|
||||
{{#isModel}}
|
||||
if (m_{{name}} != nullptr) {
|
||||
pt.add_child("{{baseName}}", m_{{name}}->toPropertyTree());
|
||||
}
|
||||
{{/isModel}}
|
||||
{{/isPrimitiveType}}
|
||||
{{/isContainer}}
|
||||
{{#isContainer}}
|
||||
// generate tree for {{name}}
|
||||
if (!m_{{name}}.empty()) {
|
||||
for (const auto &childEntry : m_{{name}}) {
|
||||
{{#items}}
|
||||
{{#isModel}}
|
||||
tmp_node.push_back(std::make_pair("", childEntry->toPropertyTree()));
|
||||
{{/isModel}}
|
||||
{{^isModel}}
|
||||
ptree {{name}}_node;
|
||||
{{name}}_node.put("", childEntry);
|
||||
tmp_node.push_back(std::make_pair("", {{name}}_node));
|
||||
{{/isModel}}
|
||||
{{/items}}
|
||||
}
|
||||
pt.add_child("{{baseName}}", tmp_node);
|
||||
tmp_node.clear();
|
||||
}
|
||||
{{/isContainer}}
|
||||
{{/vars}}
|
||||
return pt;
|
||||
}
|
||||
|
||||
void {{classname}}::fromPropertyTree_internal(ptree const &pt)
|
||||
{
|
||||
ptree tmp_node;
|
||||
{{#vars}}
|
||||
{{^isContainer}}
|
||||
{{^isEnum}}
|
||||
{{#isPrimitiveType}}
|
||||
m_{{name}} = pt.get("{{baseName}}", {{{defaultValue}}});
|
||||
{{/isPrimitiveType}}
|
||||
{{^isPrimitiveType}}
|
||||
{{#isString}}
|
||||
m_{{name}} = pt.get("{{baseName}}", {{{defaultValue}}});
|
||||
{{/isString}}
|
||||
{{#isDate}}
|
||||
m_{{name}} = pt.get("{{baseName}}", {{{defaultValue}}});
|
||||
{{/isDate}}
|
||||
{{#isDateTime}}
|
||||
m_{{name}} = pt.get("{{baseName}}", {{{defaultValue}}});
|
||||
{{/isDateTime}}
|
||||
{{/isPrimitiveType}}
|
||||
{{/isEnum}}
|
||||
{{#isEnum}}
|
||||
{{setter}}(pt.get("{{baseName}}", {{{defaultValue}}}));
|
||||
{{/isEnum}}
|
||||
{{#isModel}}
|
||||
if (pt.get_child_optional("{{baseName}}")) {
|
||||
m_{{name}} = {{{defaultValue}}};
|
||||
m_{{name}}->fromPropertyTree(pt.get_child("{{baseName}}"));
|
||||
}
|
||||
{{/isModel}}
|
||||
{{/isContainer}}
|
||||
{{#isContainer}}
|
||||
{{^isModelContainer}}
|
||||
// push all items of {{name}} into member vector
|
||||
if (pt.get_child_optional("{{baseName}}")) {
|
||||
for (const auto &childTree : pt.get_child("{{baseName}}")) {
|
||||
{{#mostInnerItems}}
|
||||
{{{dataType}}} val =
|
||||
{{#isNumeric}}
|
||||
{{^isFloat}}
|
||||
{{^isLong}}
|
||||
{{^isInteger}}
|
||||
std::stod(childTree.second.data());
|
||||
{{/isInteger}}
|
||||
{{/isLong}}
|
||||
{{/isFloat}}
|
||||
{{#isDouble}}
|
||||
std::stod(childTree.second.data());
|
||||
{{/isDouble}}
|
||||
{{#isFloat}}
|
||||
std::stof(childTree.second.data());
|
||||
{{/isFloat}}
|
||||
{{#isInteger}}
|
||||
std::stoi(childTree.second.data());
|
||||
{{/isInteger}}
|
||||
{{#isLong}}
|
||||
std::stol(childTree.second.data());
|
||||
{{/isLong}}
|
||||
{{/isNumeric}}
|
||||
{{#isString}}
|
||||
childTree.second.data();
|
||||
{{/isString}}
|
||||
{{#isModel}}
|
||||
std::make_shared<{{baseType}}>(childTree.second);
|
||||
{{/isModel}}
|
||||
m_{{name}}.emplace_back(std::move(val));
|
||||
{{/mostInnerItems}}
|
||||
}
|
||||
}
|
||||
{{/isModelContainer}}
|
||||
{{#isModelContainer}}
|
||||
// generate new {{complexType}} Object for each item and assign it to the current
|
||||
if (pt.get_child_optional("{{baseName}}")) {
|
||||
for (const auto &childTree : pt.get_child("{{baseName}}")) {
|
||||
{{#mostInnerItems}}
|
||||
m_{{name}}.emplace_back({{{defaultValue}}});
|
||||
m_{{name}}.back()->fromPropertyTree(childTree.second);
|
||||
{{/mostInnerItems}}
|
||||
}
|
||||
}
|
||||
{{/isModelContainer}}
|
||||
{{/isContainer}}
|
||||
{{/vars}}
|
||||
}
|
||||
|
||||
{{#vars}}
|
||||
{{{dataType}}} {{classname}}::{{getter}}() const
|
||||
{
|
||||
return m_{{name}};
|
||||
}
|
||||
|
||||
void {{classname}}::{{setter}}({{{dataType}}} value)
|
||||
{
|
||||
{{#isEnum}}if (std::find(m_{{enumName}}.begin(), m_{{enumName}}.end(), value) != m_{{enumName}}.end()) {
|
||||
{{/isEnum}}m_{{name}} = value;{{#isEnum}}
|
||||
} else {
|
||||
throw std::runtime_error("Value " + value + " not allowed");
|
||||
}{{/isEnum}}
|
||||
}
|
||||
{{/vars}}
|
||||
|
||||
std::vector<{{classname}}> create{{classname}}VectorFromJsonString(const std::string& json)
|
||||
{
|
||||
std::stringstream sstream(json);
|
||||
boost::property_tree::ptree pt;
|
||||
boost::property_tree::json_parser::read_json(sstream,pt);
|
||||
|
||||
auto vec = std::vector<{{{classname}}}>();
|
||||
for (const auto& child: pt) {
|
||||
vec.emplace_back({{{classname}}}(child.second));
|
||||
}
|
||||
|
||||
return vec;
|
||||
}
|
||||
|
||||
{{#modelNamespaceDeclarations}}
|
||||
}
|
||||
{{/modelNamespaceDeclarations}}
|
||||
|
||||
{{/model}}
|
||||
{{/models}}
|
34
modules/openapi-generator/src/main/resources/cpp-restbed-server/CMakeLists.txt.mustache
vendored
Normal file
34
modules/openapi-generator/src/main/resources/cpp-restbed-server/CMakeLists.txt.mustache
vendored
Normal file
@ -0,0 +1,34 @@
|
||||
set(TARGET_NAME {{{apiPackage}}}Stubs)
|
||||
|
||||
# Get generated filenames
|
||||
file(STRINGS "${CMAKE_CURRENT_LIST_DIR}/.openapi-generator/FILES" GENERATED_SOURCES)
|
||||
list(FILTER GENERATED_SOURCES INCLUDE REGEX ".*cpp$")
|
||||
|
||||
set(GENERATED_SOURCES_INCLUDE_DIRS
|
||||
${CMAKE_CURRENT_LIST_DIR}/model
|
||||
${CMAKE_CURRENT_LIST_DIR}/api
|
||||
${CMAKE_CURRENT_LIST_DIR}
|
||||
)
|
||||
|
||||
|
||||
add_library(${TARGET_NAME} SHARED)
|
||||
|
||||
target_sources(${TARGET_NAME}
|
||||
PRIVATE
|
||||
${GENERATED_SOURCES})
|
||||
|
||||
target_include_directories(${TARGET_NAME}
|
||||
PUBLIC
|
||||
${GENERATED_SOURCES_INCLUDE_DIRS}
|
||||
)
|
||||
|
||||
|
||||
target_include_directories(${TARGET_NAME}
|
||||
SYSTEM PUBLIC
|
||||
${restbed_SOURCE_DIR}/source)
|
||||
|
||||
target_link_libraries(${TARGET_NAME}
|
||||
PUBLIC
|
||||
Boost::system
|
||||
restbed-shared
|
||||
-lpthread)
|
@ -0,0 +1,22 @@
|
||||
|
||||
include(FetchContent)
|
||||
|
||||
## Restbed
|
||||
FetchContent_Declare(
|
||||
restbed
|
||||
GIT_REPOSITORY https://github.com/Corvusoft/restbed
|
||||
GIT_TAG 4.7
|
||||
)
|
||||
|
||||
FetchContent_MakeAvailable(restbed)
|
||||
|
||||
FetchContent_GetProperties(restbed)
|
||||
if(NOT restbed_POPULATED)
|
||||
|
||||
FetchContent_Populate(restbed)
|
||||
add_subdirectory(${restbed_SOURCE_DIR} ${restbed_BINARY_DIR})
|
||||
endif()
|
||||
|
||||
|
||||
## Boost
|
||||
find_package(Boost 1.7.0 COMPONENTS system REQUIRED)
|
@ -21,3 +21,50 @@ restbed
|
||||
## Namespaces
|
||||
{{{apiPackage}}}
|
||||
{{{modelPackage}}}
|
||||
|
||||
|
||||
## Example
|
||||
|
||||
The handler functionality can be implemented in two different ways.
|
||||
Either inherit the given resource and override the handler methods.
|
||||
Or set a handler lambda to a resource.
|
||||
|
||||
This example shows how this can be done with the pet store API.
|
||||
|
||||
```
|
||||
#include "api/StoreApi.h"
|
||||
#include "api/UserApi.h"
|
||||
|
||||
using namespace org::openapitools::server::api;
|
||||
using namespace org::openapitools::server::api::StoreApiResources;
|
||||
using namespace org::openapitools::server::api::UserApiResources;
|
||||
|
||||
/* 1. variant: inherit from the resource and override handler method */
|
||||
class MyStoreApiStoreOrderResource : public StoreOrderResource {
|
||||
public:
|
||||
std::pair<int, Order>
|
||||
handler_POST(Order &order) override {
|
||||
auto ret = Order();
|
||||
/* ... add your implementation here .... */
|
||||
return std::make_pair(200, ret);
|
||||
}
|
||||
};
|
||||
|
||||
int main() {
|
||||
const auto service = std::make_shared<restbed::Service>();
|
||||
|
||||
auto storeApi = StoreApi(service);
|
||||
storeApi.setResource(std::make_shared<MyStoreApiStoreOrderResource>());
|
||||
|
||||
auto userApi = UserApi(service);
|
||||
/* 2. variant: implement handler as lambda */
|
||||
userApi.getUserResource()->handler_POST_func = [](auto& user) {
|
||||
/* ... add your implementation here .... */
|
||||
return 200;};
|
||||
|
||||
const auto settings = std::make_shared<restbed::Settings>();
|
||||
settings->set_port(1236);
|
||||
|
||||
service->start(settings);
|
||||
}
|
||||
```
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
#include <exception>
|
||||
#include <functional>
|
||||
|
||||
#include <corvusoft/restbed/session.hpp>
|
||||
#include <corvusoft/restbed/resource.hpp>
|
||||
@ -44,6 +45,7 @@ private:
|
||||
std::string m_what;
|
||||
};
|
||||
|
||||
namespace {{classname}}Resources {
|
||||
{{#operation}}
|
||||
/// <summary>
|
||||
/// {{summary}}
|
||||
@ -51,23 +53,47 @@ private:
|
||||
/// <remarks>
|
||||
/// {{notes}}
|
||||
/// </remarks>
|
||||
class {{declspec}} {{classname}}{{vendorExtensions.x-codegen-resource-name}}Resource: public restbed::Resource
|
||||
class {{declspec}} {{vendorExtensions.x-codegen-resource-name}}Resource: public restbed::Resource
|
||||
{
|
||||
public:
|
||||
{{classname}}{{vendorExtensions.x-codegen-resource-name}}Resource(const std::string& context = "{{contextPath}}");
|
||||
virtual ~{{classname}}{{vendorExtensions.x-codegen-resource-name}}Resource();
|
||||
{{vendorExtensions.x-codegen-resource-name}}Resource(const std::string& context = "{{contextPath}}");
|
||||
virtual ~{{vendorExtensions.x-codegen-resource-name}}Resource() = default;
|
||||
|
||||
{{vendorExtensions.x-codegen-resource-name}}Resource(
|
||||
const {{vendorExtensions.x-codegen-resource-name}}Resource& other) = default; // copy constructor
|
||||
{{vendorExtensions.x-codegen-resource-name}}Resource({{vendorExtensions.x-codegen-resource-name}}Resource&& other) noexcept = default; // move constructor
|
||||
|
||||
{{vendorExtensions.x-codegen-resource-name}}Resource& operator=(const {{vendorExtensions.x-codegen-resource-name}}Resource& other) = default; // copy assignment
|
||||
{{vendorExtensions.x-codegen-resource-name}}Resource& operator=({{vendorExtensions.x-codegen-resource-name}}Resource&& other) noexcept = default; // move assignment
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
// Set these to implement the server functionality //
|
||||
/////////////////////////////////////////////////////
|
||||
std::function<{{#returnType}}std::pair<int, {{{.}}}>{{/returnType}}{{^returnType}}int{{/returnType}}(
|
||||
{{#allParams}}{{{dataType}}} & {{{paramName}}}{{^-last}}, {{/-last}}{{/allParams}})> handler_{{httpMethod}}_func =
|
||||
[]({{#allParams}}{{{dataType}}} &{{^-last}}, {{/-last}}{{/allParams}}) -> {{#returnType}}std::pair<int, {{{.}}}>{{/returnType}}{{^returnType}}int{{/returnType}}
|
||||
{ throw {{classname}}Exception(501, "Not implemented"); };
|
||||
|
||||
{{#vendorExtensions.x-codegen-other-methods}}
|
||||
std::function<{{#returnType}}std::pair<int, {{{.}}}>{{/returnType}}{{^returnType}}int{{/returnType}}(
|
||||
{{#allParams}}{{{dataType}}} & {{{paramName}}}{{^-last}}, {{/-last}}{{/allParams}})> handler_{{httpMethod}}_func =
|
||||
[]({{#allParams}}{{{dataType}}} &{{^-last}}, {{/-last}}{{/allParams}}) -> {{#returnType}}std::pair<int, {{{.}}}>{{/returnType}}{{^returnType}}int{{/returnType}}
|
||||
{ throw {{classname}}Exception(501, "Not implemented"); };
|
||||
|
||||
{{/vendorExtensions.x-codegen-other-methods}}
|
||||
|
||||
protected:
|
||||
//////////////////////////////////////////////////////////
|
||||
// Override these to implement the server functionality //
|
||||
// As an alternative to setting the `std::function`s //
|
||||
// override these to implement the server functionality //
|
||||
//////////////////////////////////////////////////////////
|
||||
|
||||
virtual {{#returnType}}std::pair<int, {{{.}}}>{{/returnType}}{{^returnType}}int{{/returnType}} handler_{{httpMethod}}(
|
||||
{{#allParams}}{{{dataType}}} const & {{{paramName}}}{{^-last}}, {{/-last}}{{/allParams}});
|
||||
{{#allParams}}{{{dataType}}} & {{{paramName}}}{{^-last}}, {{/-last}}{{/allParams}});
|
||||
|
||||
{{#vendorExtensions.x-codegen-other-methods}}
|
||||
virtual {{#returnType}}std::pair<int, {{{.}}}>{{/returnType}}{{^returnType}}int{{/returnType}} handler_{{httpMethod}}(
|
||||
{{#allParams}}{{{dataType}}} const & {{{paramName}}}{{^-last}}, {{/-last}}{{/allParams}});
|
||||
{{#allParams}}{{{dataType}}} & {{{paramName}}}{{^-last}}, {{/-last}}{{/allParams}});
|
||||
{{/vendorExtensions.x-codegen-other-methods}}
|
||||
|
||||
protected:
|
||||
@ -75,72 +101,8 @@ protected:
|
||||
// Override these for customization //
|
||||
//////////////////////////////////////
|
||||
|
||||
{{#hasPathParams}}
|
||||
{{#pathParams}}
|
||||
{{#isPrimitiveType}}
|
||||
virtual {{{dataType}}} getPathParam_{{{paramName}}}(const std::shared_ptr<const restbed::Request>& request)
|
||||
{
|
||||
return request->get_path_parameter("{{{paramName}}}", {{{defaultValue}}});
|
||||
}
|
||||
|
||||
{{/isPrimitiveType}}
|
||||
{{/pathParams}}
|
||||
{{/hasPathParams}}
|
||||
{{#hasQueryParams}}
|
||||
{{#queryParams}}
|
||||
{{#isPrimitiveType}}
|
||||
virtual {{{dataType}}} getQueryParam_{{{paramName}}}(const std::shared_ptr<const restbed::Request>& request)
|
||||
{
|
||||
return request->get_query_parameter("{{{paramName}}}", {{{defaultValue}}});
|
||||
}
|
||||
|
||||
{{/isPrimitiveType}}
|
||||
{{/queryParams}}
|
||||
{{/hasQueryParams}}
|
||||
{{#hasHeaderParams}}
|
||||
{{#headerParams}}
|
||||
{{#isPrimitiveType}}
|
||||
virtual {{{dataType}}} getHeader_{{{baseName}}}(const std::shared_ptr<const restbed::Request>& request)
|
||||
{
|
||||
return request->get_header("{{baseName}}", {{{defaultValue}}});
|
||||
}
|
||||
|
||||
{{/isPrimitiveType}}
|
||||
{{/headerParams}}
|
||||
{{/hasHeaderParams}}
|
||||
|
||||
{{#vendorExtensions.x-codegen-other-methods}}
|
||||
{{#hasPathParams}}
|
||||
{{#pathParams}}
|
||||
{{#isPrimitiveType}}
|
||||
virtual {{{dataType}}} getPathParam_{{{paramName}}}_x_extension(const std::shared_ptr<const restbed::Request>& request)
|
||||
{
|
||||
return request->get_path_parameter("{{{paramName}}}", {{{defaultValue}}});
|
||||
}
|
||||
{{/isPrimitiveType}}
|
||||
{{/pathParams}}
|
||||
{{/hasPathParams}}
|
||||
{{#hasQueryParams}}
|
||||
{{#queryParams}}
|
||||
{{#isPrimitiveType}}
|
||||
virtual {{{dataType}}} getQueryParam_{{{paramName}}}_x_extension(const std::shared_ptr<const restbed::Request>& request)
|
||||
{
|
||||
return request->get_query_parameter("{{{paramName}}}", {{{defaultValue}}});
|
||||
}
|
||||
{{/isPrimitiveType}}
|
||||
{{/queryParams}}
|
||||
{{/hasQueryParams}}
|
||||
{{#hasHeaderParams}}
|
||||
{{#headerParams}}
|
||||
{{#isPrimitiveType}}
|
||||
virtual {{{dataType}}} getHeader_{{{baseName}}}_x_extension(const std::shared_ptr<const restbed::Request>& request)
|
||||
{
|
||||
return request->get_header("{{baseName}}", {{{defaultValue}}});
|
||||
}
|
||||
{{/isPrimitiveType}}
|
||||
{{/headerParams}}
|
||||
{{/hasHeaderParams}}
|
||||
{{/vendorExtensions.x-codegen-other-methods}}
|
||||
virtual std::string extractBodyContent(const std::shared_ptr<restbed::Session>& session);
|
||||
virtual std::string extractFormParamsFromBody(const std::string& paramName, const std::string& body);
|
||||
|
||||
virtual std::pair<int, std::string> handle{{classname}}Exception(const {{classname}}Exception& e);
|
||||
virtual std::pair<int, std::string> handleStdException(const std::exception& e);
|
||||
@ -149,9 +111,8 @@ protected:
|
||||
virtual void setResponseHeader(const std::shared_ptr<restbed::Session>& session,
|
||||
const std::string& header);
|
||||
|
||||
|
||||
virtual void returnResponse(const std::shared_ptr<restbed::Session>& session,
|
||||
const int status, const std::string& result, const std::string& contentType);
|
||||
const int status, const std::string& result, std::multimap<std::string, std::string>& contentType);
|
||||
virtual void defaultSessionClose(const std::shared_ptr<restbed::Session>& session,
|
||||
const int status, const std::string& result);
|
||||
|
||||
@ -162,7 +123,11 @@ private:
|
||||
{{/vendorExtensions.x-codegen-other-methods}}
|
||||
};
|
||||
|
||||
{{/operation}}
|
||||
} /* namespace {{classname}}Resources */
|
||||
|
||||
{{#operation}}
|
||||
using {{classname}}{{vendorExtensions.x-codegen-resource-name}}Resource [[deprecated]] = {{classname}}Resources::{{vendorExtensions.x-codegen-resource-name}}Resource;
|
||||
{{/operation}}
|
||||
|
||||
//
|
||||
@ -175,7 +140,15 @@ public:
|
||||
virtual ~{{classname}}();
|
||||
|
||||
{{#operation}}
|
||||
virtual void set{{classname}}{{vendorExtensions.x-codegen-resource-name}}Resource(std::shared_ptr<{{classname}}{{vendorExtensions.x-codegen-resource-name}}Resource> sp{{classname}}{{vendorExtensions.x-codegen-resource-name}}Resource);
|
||||
std::shared_ptr<{{classname}}Resources::{{vendorExtensions.x-codegen-resource-name}}Resource> get{{vendorExtensions.x-codegen-resource-name}}Resource();
|
||||
{{/operation}}
|
||||
|
||||
{{#operation}}
|
||||
void setResource(std::shared_ptr<{{classname}}Resources::{{vendorExtensions.x-codegen-resource-name}}Resource> resource);
|
||||
{{/operation}}
|
||||
{{#operation}}
|
||||
[[deprecated("use setResource()")]]
|
||||
virtual void set{{classname}}{{vendorExtensions.x-codegen-resource-name}}Resource(std::shared_ptr<{{classname}}Resources::{{vendorExtensions.x-codegen-resource-name}}Resource> sp{{classname}}{{vendorExtensions.x-codegen-resource-name}}Resource);
|
||||
{{/operation}}
|
||||
|
||||
virtual void publishDefaultResources();
|
||||
@ -184,7 +157,7 @@ public:
|
||||
|
||||
protected:
|
||||
{{#operation}}
|
||||
std::shared_ptr<{{classname}}{{vendorExtensions.x-codegen-resource-name}}Resource> m_sp{{classname}}{{vendorExtensions.x-codegen-resource-name}}Resource;
|
||||
std::shared_ptr<{{classname}}Resources::{{vendorExtensions.x-codegen-resource-name}}Resource> m_sp{{vendorExtensions.x-codegen-resource-name}}Resource;
|
||||
{{/operation}}
|
||||
|
||||
private:
|
||||
|
172
modules/openapi-generator/src/main/resources/cpp-restbed-server/api-source-HandlerBody.mustache
vendored
Normal file
172
modules/openapi-generator/src/main/resources/cpp-restbed-server/api-source-HandlerBody.mustache
vendored
Normal file
@ -0,0 +1,172 @@
|
||||
const auto request = session->get_request();
|
||||
{{#hasBodyParam}}
|
||||
// body params or form params here from the body content string
|
||||
std::string bodyContent = extractBodyContent(session);
|
||||
{{#bodyParams}}
|
||||
{{#isModel}}
|
||||
auto {{paramName}} = extractJsonModelBodyParam<{{{baseType}}}>(bodyContent);
|
||||
{{/isModel}}
|
||||
{{#isArray}}
|
||||
auto {{paramName}} = extractJsonArrayBodyParam<{{{baseType}}}>(bodyContent);
|
||||
{{/isArray}}
|
||||
{{#isMap}}
|
||||
{{{dataType}}} {{paramName}}; // TODO
|
||||
{{/isMap}}
|
||||
{{^isModel}}
|
||||
{{^isArray}}
|
||||
{{^isMap}}
|
||||
auto {{paramName}} = boost::lexical_cast<{{{dataType}}}>(bodyContent);
|
||||
{{/isMap}}
|
||||
{{/isArray}}
|
||||
{{/isModel}}
|
||||
{{/bodyParams}}
|
||||
{{/hasBodyParam}}
|
||||
{{#hasFormParams}}
|
||||
{{#formParams}}
|
||||
{{#isContainer}}
|
||||
std::string {{{paramName}}}_raw = extractFormParamsFromBody("{{paramName}}", extractBodyContent(session));
|
||||
{{{dataType}}} {{{paramName}}};
|
||||
boost::split({{{paramName}}}, {{{paramName}}}_raw, boost::is_any_of(","));
|
||||
{{/isContainer}}
|
||||
{{^isContainer}}
|
||||
auto {{paramName}} = boost::lexical_cast<{{{dataType}}}>(extractFormParamsFromBody("{{paramName}}", extractBodyContent(session)));
|
||||
{{/isContainer}}
|
||||
{{/formParams}}
|
||||
{{/hasFormParams}}
|
||||
{{#hasPathParams}}
|
||||
// Getting the path params
|
||||
{{#pathParams}}
|
||||
{{#isPrimitiveType}}
|
||||
{{{dataType}}} {{{paramName}}} = request->get_path_parameter("{{{baseName}}}", {{{defaultValue}}});
|
||||
{{/isPrimitiveType}}
|
||||
{{/pathParams}}
|
||||
{{/hasPathParams}}
|
||||
{{#hasQueryParams}}
|
||||
// Getting the query params
|
||||
{{#queryParams}}
|
||||
{{#isPrimitiveType}}
|
||||
{{{dataType}}} {{{paramName}}} = request->get_query_parameter("{{{paramName}}}", {{{defaultValue}}});
|
||||
{{/isPrimitiveType}}
|
||||
{{^isPrimitiveType}}
|
||||
{{#isArray}}
|
||||
std::string {{{paramName}}}_raw = request->get_query_parameter("{{{paramName}}}");
|
||||
{{{dataType}}} {{{paramName}}};
|
||||
std::vector<std::string> {{{paramName}}}_temp;
|
||||
boost::split({{{paramName}}}_temp, {{{paramName}}}_raw, boost::is_any_of(","));
|
||||
{{#items}}
|
||||
{{#isString}}
|
||||
std::copy({{{paramName}}}_temp.begin(), {{{paramName}}}_temp.end(), std::inserter({{{paramName}}}, std::next({{{paramName}}}.begin())));
|
||||
{{/isString}}
|
||||
{{^isString}}
|
||||
#if 0
|
||||
/*
|
||||
{{{.}}}
|
||||
*/
|
||||
#endif
|
||||
std::transform({{{paramName}}}_temp.begin(), {{{paramName}}}_temp.end(), std::back_inserter({{{paramName}}}), [](const auto& i){ {{{dataType}}} ret; ret.fromString(i); return ret;});
|
||||
{{/isString}}
|
||||
{{/items}}
|
||||
{{/isArray}}
|
||||
{{#isMap}}
|
||||
std::stringstream {{{paramName}}}_raw(request->get_query_parameter("{{{paramName}}}"));
|
||||
boost::property_tree::ptree {{{paramName}}}_pt;
|
||||
boost::property_tree::json_parser::read_json({{{paramName}}}_raw,{{{paramName}}}_pt);
|
||||
{{{dataType}}} {{{paramName}}} = {{{defaultValue}}};
|
||||
for (auto& item: {{{paramName}}}_pt) {
|
||||
{{{paramName}}}.emplace(item.first, item.second.get_value<{{{baseType}}}>());
|
||||
}
|
||||
{{/isMap}}
|
||||
{{/isPrimitiveType}}
|
||||
{{/queryParams}}
|
||||
{{/hasQueryParams}}
|
||||
{{#hasHeaderParams}}
|
||||
// Getting the headers
|
||||
{{#headerParams}}
|
||||
{{#isPrimitiveType}}
|
||||
{{{dataType}}} {{{paramName}}} = request->get_header("{{{baseName}}}", {{{defaultValue}}});
|
||||
{{/isPrimitiveType}}
|
||||
{{#isContainer}}
|
||||
std::string {{{paramName}}}_raw = request->get_header("{{{paramName}}}");
|
||||
{{{dataType}}} {{{paramName}}};
|
||||
boost::split({{{paramName}}}, {{{paramName}}}_raw, boost::is_any_of(","));
|
||||
{{/isContainer}}
|
||||
{{/headerParams}}
|
||||
{{/hasHeaderParams}}
|
||||
|
||||
int status_code = 500;
|
||||
{{#returnType}}
|
||||
{{{.}}} resultObject = {{{defaultResponse}}};
|
||||
{{/returnType}}
|
||||
std::string result = "";
|
||||
|
||||
try {
|
||||
{{#returnType}}
|
||||
std::tie(status_code, resultObject) =
|
||||
{{/returnType}}
|
||||
{{^returnType}}
|
||||
status_code =
|
||||
{{/returnType}}
|
||||
handler_{{httpMethod}}({{#allParams}}{{paramName}}{{^-last}}, {{/-last}}{{/allParams}});
|
||||
}
|
||||
catch(const {{classname}}Exception& e) {
|
||||
std::tie(status_code, result) = handle{{classname}}Exception(e);
|
||||
}
|
||||
catch(const std::exception& e) {
|
||||
std::tie(status_code, result) = handleStdException(e);
|
||||
}
|
||||
catch(...) {
|
||||
std::tie(status_code, result) = handleUnspecifiedException();
|
||||
}
|
||||
|
||||
std::multimap< std::string, std::string > responseHeaders {};
|
||||
static const std::vector<std::string> contentTypes{
|
||||
{{#hasProduces}}
|
||||
{{#produces}}"{{{mediaType}}}",{{/produces}}
|
||||
{{/hasProduces}}
|
||||
{{^hasProduces}}
|
||||
"application/json"
|
||||
{{/hasProduces}}
|
||||
};
|
||||
static const std::string acceptTypes{
|
||||
{{#hasConsumes}}
|
||||
"{{#consumes}}{{{mediaType}}}, {{/consumes}}"
|
||||
{{/hasConsumes}}
|
||||
};
|
||||
|
||||
{{#responses}}
|
||||
if (status_code == {{code}}) {
|
||||
{{#is2xx}}
|
||||
responseHeaders.insert(std::make_pair("Content-Type", selectPreferredContentType(contentTypes)));
|
||||
if (!acceptTypes.empty()) {
|
||||
responseHeaders.insert(std::make_pair("Accept", acceptTypes));
|
||||
}
|
||||
{{/is2xx}}
|
||||
{{^is2xx}}
|
||||
responseHeaders.insert(std::make_pair("Content-Type", "text/plain"));
|
||||
result = "{{message}}";
|
||||
{{/is2xx}}
|
||||
|
||||
{{#returnType}}
|
||||
{{#isModel}}
|
||||
{{#isString}}
|
||||
result = resultObject;
|
||||
{{/isString}}
|
||||
{{^isString}}
|
||||
{{^isMap}}
|
||||
result = resultObject.toJsonString();
|
||||
{{/isMap}}
|
||||
{{/isString}}
|
||||
{{/isModel}}
|
||||
{{#isMap}}
|
||||
result = convertMapResponse(resultObject);
|
||||
{{/isMap}}
|
||||
{{/returnType}}
|
||||
{{#headers}}
|
||||
// Description: {{{description}}}
|
||||
setResponseHeader(session, "{{baseName}}");
|
||||
{{/headers}}
|
||||
returnResponse(session, {{code}}, result.empty() ? "{}" : result, responseHeaders);
|
||||
return;
|
||||
}
|
||||
{{/responses}}
|
||||
defaultSessionClose(session, status_code, result);
|
@ -19,6 +19,32 @@ namespace {{this}} {
|
||||
|
||||
using namespace {{modelNamespace}};
|
||||
|
||||
namespace {
|
||||
[[maybe_unused]]
|
||||
std::string selectPreferredContentType(const std::vector<std::string>& contentTypes) {
|
||||
if (contentTypes.size() == 0) {
|
||||
return "application/json";
|
||||
}
|
||||
|
||||
if (contentTypes.size() == 1) {
|
||||
return contentTypes.at(0);
|
||||
}
|
||||
|
||||
static const std::array<std::string, 2> preferredTypes = {"json", "xml"};
|
||||
for (const auto& preferredType: preferredTypes) {
|
||||
const auto ret = std::find_if(contentTypes.cbegin(),
|
||||
contentTypes.cend(),
|
||||
[preferredType](const std::string& str) {
|
||||
return str.find(preferredType) != std::string::npos;});
|
||||
if (ret != contentTypes.cend()) {
|
||||
return *ret;
|
||||
}
|
||||
}
|
||||
|
||||
return contentTypes.at(0);
|
||||
}
|
||||
}
|
||||
|
||||
{{classname}}Exception::{{classname}}Exception(int status_code, std::string what)
|
||||
: m_status(status_code),
|
||||
m_what(what)
|
||||
@ -36,26 +62,26 @@ const char* {{classname}}Exception::what() const noexcept
|
||||
|
||||
|
||||
template<class MODEL_T>
|
||||
std::shared_ptr<MODEL_T> extractJsonModelBodyParam(const std::string& bodyContent)
|
||||
MODEL_T extractJsonModelBodyParam(const std::string& bodyContent)
|
||||
{
|
||||
std::stringstream sstream(bodyContent);
|
||||
boost::property_tree::ptree pt;
|
||||
boost::property_tree::json_parser::read_json(sstream, pt);
|
||||
|
||||
auto model = std::make_shared<MODEL_T>(pt);
|
||||
auto model = MODEL_T(pt);
|
||||
return model;
|
||||
}
|
||||
|
||||
template<class MODEL_T>
|
||||
std::vector<std::shared_ptr<MODEL_T>> extractJsonArrayBodyParam(const std::string& bodyContent)
|
||||
std::vector<MODEL_T> extractJsonArrayBodyParam(const std::string& bodyContent)
|
||||
{
|
||||
std::stringstream sstream(bodyContent);
|
||||
boost::property_tree::ptree pt;
|
||||
boost::property_tree::json_parser::read_json(sstream, pt);
|
||||
|
||||
auto arrayRet = std::vector<std::shared_ptr<MODEL_T>>();
|
||||
auto arrayRet = std::vector<MODEL_T>();
|
||||
for (const auto& child: pt) {
|
||||
arrayRet.emplace_back(std::make_shared<MODEL_T>(child.second));
|
||||
arrayRet.emplace_back(MODEL_T(child.second));
|
||||
}
|
||||
return arrayRet;
|
||||
}
|
||||
@ -76,160 +102,58 @@ std::string convertMapResponse(const std::map<KEY_T, VAL_T>& map)
|
||||
return result;
|
||||
}
|
||||
|
||||
namespace {{classname}}Resources {
|
||||
{{#operation}}
|
||||
{{classname}}{{vendorExtensions.x-codegen-resource-name}}Resource::{{classname}}{{vendorExtensions.x-codegen-resource-name}}Resource(const std::string& context /* = "{{contextPath}}" */)
|
||||
{{vendorExtensions.x-codegen-resource-name}}Resource::{{vendorExtensions.x-codegen-resource-name}}Resource(const std::string& context /* = "{{contextPath}}" */)
|
||||
{
|
||||
this->set_path(context + "{{path}}");
|
||||
this->set_method_handler("{{httpMethod}}",
|
||||
std::bind(&{{classname}}{{vendorExtensions.x-codegen-resource-name}}Resource::handler_{{httpMethod}}_internal, this,
|
||||
std::bind(&{{vendorExtensions.x-codegen-resource-name}}Resource::handler_{{httpMethod}}_internal, this,
|
||||
std::placeholders::_1));
|
||||
{{#vendorExtensions.x-codegen-other-methods}}
|
||||
this->set_method_handler("{{httpMethod}}",
|
||||
std::bind(&{{classname}}{{vendorExtensions.x-codegen-resource-name}}Resource::handler_{{httpMethod}}_internal, this,
|
||||
std::bind(&{{vendorExtensions.x-codegen-resource-name}}Resource::handler_{{httpMethod}}_internal, this,
|
||||
std::placeholders::_1));
|
||||
{{/vendorExtensions.x-codegen-other-methods}}
|
||||
}
|
||||
|
||||
{{classname}}{{vendorExtensions.x-codegen-resource-name}}Resource::~{{classname}}{{vendorExtensions.x-codegen-resource-name}}Resource()
|
||||
{
|
||||
}
|
||||
|
||||
std::pair<int, std::string> {{classname}}{{vendorExtensions.x-codegen-resource-name}}Resource::handle{{classname}}Exception(const {{classname}}Exception& e)
|
||||
std::pair<int, std::string> {{vendorExtensions.x-codegen-resource-name}}Resource::handle{{classname}}Exception(const {{classname}}Exception& e)
|
||||
{
|
||||
return std::make_pair<int, std::string>(e.getStatus(), e.what());
|
||||
}
|
||||
|
||||
std::pair<int, std::string> {{classname}}{{vendorExtensions.x-codegen-resource-name}}Resource::handleStdException(const std::exception& e)
|
||||
std::pair<int, std::string> {{vendorExtensions.x-codegen-resource-name}}Resource::handleStdException(const std::exception& e)
|
||||
{
|
||||
return std::make_pair<int, std::string>(500, e.what());
|
||||
}
|
||||
|
||||
std::pair<int, std::string> {{classname}}{{vendorExtensions.x-codegen-resource-name}}Resource::handleUnspecifiedException()
|
||||
std::pair<int, std::string> {{vendorExtensions.x-codegen-resource-name}}Resource::handleUnspecifiedException()
|
||||
{
|
||||
return std::make_pair<int, std::string>(500, "Unknown exception occurred");
|
||||
}
|
||||
|
||||
void {{classname}}{{vendorExtensions.x-codegen-resource-name}}Resource::setResponseHeader(const std::shared_ptr<restbed::Session>& session, const std::string& header)
|
||||
void {{vendorExtensions.x-codegen-resource-name}}Resource::setResponseHeader(const std::shared_ptr<restbed::Session>& session, const std::string& header)
|
||||
{
|
||||
session->set_header(header, "");
|
||||
}
|
||||
|
||||
void {{classname}}{{vendorExtensions.x-codegen-resource-name}}Resource::returnResponse(const std::shared_ptr<restbed::Session>& session, const int status, const std::string& result, const std::string& contentType)
|
||||
void {{vendorExtensions.x-codegen-resource-name}}Resource::returnResponse(const std::shared_ptr<restbed::Session>& session, const int status, const std::string& result, std::multimap<std::string, std::string>& responseHeaders)
|
||||
{
|
||||
session->close(status, result, { {"Connection", "close"}, {"Content-Type", contentType} });
|
||||
responseHeaders.insert(std::make_pair("Connection", "close"));
|
||||
session->close(status, result, responseHeaders);
|
||||
}
|
||||
|
||||
void {{classname}}{{vendorExtensions.x-codegen-resource-name}}Resource::defaultSessionClose(const std::shared_ptr<restbed::Session>& session, const int status, const std::string& result)
|
||||
void {{vendorExtensions.x-codegen-resource-name}}Resource::defaultSessionClose(const std::shared_ptr<restbed::Session>& session, const int status, const std::string& result)
|
||||
{
|
||||
session->close(status, result, { {"Connection", "close"} });
|
||||
}
|
||||
|
||||
void {{classname}}{{vendorExtensions.x-codegen-resource-name}}Resource::handler_{{httpMethod}}_internal(const std::shared_ptr<restbed::Session> session)
|
||||
void {{vendorExtensions.x-codegen-resource-name}}Resource::handler_{{httpMethod}}_internal(const std::shared_ptr<restbed::Session> session)
|
||||
{
|
||||
const auto request = session->get_request();
|
||||
{{#hasBodyParam}}
|
||||
int content_length = request->get_header("Content-Length", 0);
|
||||
session->fetch(content_length,
|
||||
[this](const std::shared_ptr<restbed::Session> session,
|
||||
const restbed::Bytes& body) {
|
||||
{{#lambda.indented}}
|
||||
{{>api-source-HandlerBody}}
|
||||
{{/lambda.indented}}
|
||||
|
||||
std::string bodyContent = restbed::String::format(
|
||||
"%.*s\n", (int)body.size(), body.data());
|
||||
|
||||
// Get body params or form params here from the body content string
|
||||
{{#allParams}}
|
||||
{{#isModel}}
|
||||
auto {{paramName}} = extractJsonModelBodyParam<{{{baseType}}}>(bodyContent);
|
||||
{{/isModel}}
|
||||
{{#isArray}}
|
||||
auto {{paramName}} = extractJsonArrayBodyParam<{{{baseType}}}>(bodyContent);
|
||||
{{/isArray}}
|
||||
{{/allParams}}
|
||||
{{/hasBodyParam}}
|
||||
|
||||
{{#hasPathParams}}
|
||||
// Getting the path params
|
||||
{{#pathParams}}
|
||||
{{#isPrimitiveType}}
|
||||
const {{{dataType}}} {{{paramName}}} = getPathParam_{{paramName}}(request);
|
||||
{{/isPrimitiveType}}
|
||||
{{/pathParams}}
|
||||
{{/hasPathParams}}
|
||||
|
||||
{{#hasQueryParams}}
|
||||
// Getting the query params
|
||||
{{#queryParams}}
|
||||
{{#isPrimitiveType}}
|
||||
const {{{dataType}}} {{{paramName}}} = getQueryParam_{{paramName}}(request);
|
||||
{{/isPrimitiveType}}
|
||||
{{/queryParams}}
|
||||
{{/hasQueryParams}}
|
||||
|
||||
{{#hasHeaderParams}}
|
||||
// Getting the headers
|
||||
{{#headerParams}}
|
||||
{{#isPrimitiveType}}
|
||||
const {{{dataType}}} {{{paramName}}} = getHeader_{{baseName}}(request);
|
||||
{{/isPrimitiveType}}
|
||||
{{/headerParams}}
|
||||
{{/hasHeaderParams}}
|
||||
|
||||
int status_code = 500;
|
||||
{{#returnType}}
|
||||
{{{.}}} resultObject = {{{defaultResponse}}};
|
||||
{{/returnType}}
|
||||
std::string result = "";
|
||||
|
||||
try {
|
||||
{{#returnType}}
|
||||
std::tie(status_code, resultObject) =
|
||||
{{/returnType}}
|
||||
{{^returnType}}
|
||||
status_code =
|
||||
{{/returnType}}
|
||||
handler_{{httpMethod}}({{#allParams}}{{paramName}}{{^-last}}, {{ / -last}}{{ / allParams}});
|
||||
}
|
||||
catch(const {{classname}}Exception& e) {
|
||||
std::tie(status_code, result) = handle{{classname}}Exception(e);
|
||||
}
|
||||
catch(const std::exception& e) {
|
||||
std::tie(status_code, result) = handleStdException(e);
|
||||
}
|
||||
catch(...) {
|
||||
std::tie(status_code, result) = handleUnspecifiedException();
|
||||
}
|
||||
|
||||
{{#responses}}
|
||||
if (status_code == {{code}}) {
|
||||
{{#returnType}}
|
||||
{{#isModel}}
|
||||
{{#isString}}
|
||||
result = resultObject;
|
||||
{{/isString}}
|
||||
{{^isString}}
|
||||
result = resultObject->toJsonString();
|
||||
{{/isString}}
|
||||
{{/isModel}}
|
||||
{{#isMap}}
|
||||
result = convertMapResponse(resultObject);
|
||||
{{/isMap}}
|
||||
{{/returnType}}
|
||||
{{#headers}}
|
||||
// Description: {{{description}}}
|
||||
setResponseHeader(session, "{{baseName}}");
|
||||
{{/headers}}
|
||||
|
||||
{{#primitiveType}}
|
||||
const constexpr auto contentType = "text/plain";
|
||||
{{/primitiveType}}
|
||||
{{^primitiveType}}
|
||||
const constexpr auto contentType = "application/json";
|
||||
{{/primitiveType}}
|
||||
returnResponse(session, {{code}}, result.empty() ? "{{message}}" : result, contentType);
|
||||
return;
|
||||
}
|
||||
{{/responses}}
|
||||
defaultSessionClose(session, status_code, result);
|
||||
{{#hasBodyParam}}
|
||||
});
|
||||
{{/hasBodyParam}}
|
||||
@ -238,139 +162,54 @@ void {{classname}}{{vendorExtensions.x-codegen-resource-name}}Resource::handler_
|
||||
|
||||
{{#vendorExtensions.x-codegen-other-methods}}
|
||||
// x-extension
|
||||
void {{classname}}{{vendorExtensions.x-codegen-resource-name}}Resource::handler_{{httpMethod}}_internal(const std::shared_ptr<restbed::Session> session) {
|
||||
void {{vendorExtensions.x-codegen-resource-name}}Resource::handler_{{httpMethod}}_internal(const std::shared_ptr<restbed::Session> session) {
|
||||
{{#lambda.indented}}
|
||||
{{>api-source-HandlerBody}}
|
||||
{{/lambda.indented}}
|
||||
|
||||
const auto request = session->get_request();
|
||||
{{#hasBodyParam}}
|
||||
int content_length = request->get_header("Content-Length", 0);
|
||||
session->fetch(content_length,
|
||||
[this](const std::shared_ptr<restbed::Session> session,
|
||||
const restbed::Bytes& body) {
|
||||
|
||||
std::string bodyContent = restbed::String::format(
|
||||
"%.*s\n", (int)body.size(), body.data());
|
||||
|
||||
// body params or form params here from the body content string
|
||||
{{#allParams}}
|
||||
{{#isModel}}
|
||||
auto {{paramName}} = extractJsonModelBodyParam<{{{baseType}}}>(bodyContent);
|
||||
{{/isModel}}
|
||||
{{#isArray}}
|
||||
auto {{paramName}} = extractJsonArrayBodyParam<{{{baseType}}}>(bodyContent);
|
||||
{{/isArray}}
|
||||
{{^isModel}}
|
||||
{{^isArray}}
|
||||
auto {{paramName}} = std::make_shared<{{{baseType}}}>(bodyContent);
|
||||
{{/isArray}}
|
||||
{{/isModel}}
|
||||
{{/allParams}}
|
||||
{{/hasBodyParam}}
|
||||
|
||||
{{#hasPathParams}}
|
||||
// Getting the path params
|
||||
{{#pathParams}}
|
||||
{{#isPrimitiveType}}
|
||||
const {{{dataType}}} {{{paramName}}} = getPathParam_{{paramName}}_x_extension(request);
|
||||
|
||||
{{/isPrimitiveType}}
|
||||
{{/pathParams}}
|
||||
{{/hasPathParams}}
|
||||
{{#hasQueryParams}}
|
||||
// Getting the query params
|
||||
{{#queryParams}}
|
||||
{{#isPrimitiveType}}
|
||||
const {{{dataType}}} {{{paramName}}} = getQueryParam_{{paramName}}_x_extension(request);
|
||||
|
||||
{{/isPrimitiveType}}
|
||||
{{/queryParams}}
|
||||
{{/hasQueryParams}}
|
||||
{{#hasHeaderParams}}
|
||||
// Getting the headers
|
||||
{{#headerParams}}
|
||||
{{#isPrimitiveType}}
|
||||
const {{{dataType}}} {{{paramName}}} = getHeader_{{baseName}}_x_extension(request);
|
||||
|
||||
{{/isPrimitiveType}}
|
||||
{{/headerParams}}
|
||||
{{/hasHeaderParams}}
|
||||
|
||||
int status_code = 500;
|
||||
{{#returnType}}
|
||||
{{{.}}} resultObject = {{{defaultResponse}}};
|
||||
{{/returnType}}
|
||||
std::string result = "";
|
||||
|
||||
try {
|
||||
{{#returnType}}
|
||||
std::tie(status_code, resultObject) =
|
||||
{{/returnType}}
|
||||
{{^returnType}}
|
||||
status_code =
|
||||
{{/returnType}}
|
||||
handler_{{httpMethod}}({{#allParams}}{{paramName}}{{^-last}}, {{/-last}}{{/allParams}});
|
||||
}
|
||||
catch(const {{classname}}Exception& e) {
|
||||
std::tie(status_code, result) = handle{{classname}}Exception(e);
|
||||
}
|
||||
catch(const std::exception& e) {
|
||||
std::tie(status_code, result) = handleStdException(e);
|
||||
}
|
||||
catch(...) {
|
||||
std::tie(status_code, result) = handleUnspecifiedException();
|
||||
}
|
||||
|
||||
{{#responses}}
|
||||
if (status_code == {{code}}) {
|
||||
{{#returnType}}
|
||||
{{#isModel}}
|
||||
{{#isString}}
|
||||
result = resultObject;
|
||||
{{/isString}}
|
||||
{{^isString}}
|
||||
result = resultObject->toJsonString();
|
||||
{{/isString}}
|
||||
{{/isModel}}
|
||||
{{#isMap}}
|
||||
result = convertMapResponse(resultObject);
|
||||
{{/isMap}}
|
||||
{{/returnType}}
|
||||
{{#headers}}
|
||||
// Description: {{{description}}}
|
||||
setResponseHeader(session, "{{baseName}}");
|
||||
{{/headers}}
|
||||
|
||||
{{#primitiveType}}
|
||||
const constexpr auto contentType = "text/plain";
|
||||
{{/primitiveType}}
|
||||
{{^primitiveType}}
|
||||
const constexpr auto contentType = "application/json";
|
||||
{{/primitiveType}}
|
||||
returnResponse(session, {{code}}, result.empty() ? "{{message}}" : result, contentType);
|
||||
return;
|
||||
}
|
||||
{{/responses}}
|
||||
defaultSessionClose(session, status_code, result);
|
||||
{{#hasBodyParam}}
|
||||
});
|
||||
{{/hasBodyParam}}
|
||||
}
|
||||
{{/vendorExtensions.x-codegen-other-methods}}
|
||||
|
||||
{{#returnType}}std::pair<int, {{{.}}}>{{/returnType}}{{^returnType}}int{{/returnType}} {{classname}}{{vendorExtensions.x-codegen-resource-name}}Resource::handler_{{httpMethod}}(
|
||||
{{#allParams}}{{{dataType}}} const & {{{paramName}}}{{^-last}}, {{/-last}}{{/allParams}})
|
||||
{{#returnType}}std::pair<int, {{{.}}}>{{/returnType}}{{^returnType}}int{{/returnType}} {{vendorExtensions.x-codegen-resource-name}}Resource::handler_{{httpMethod}}(
|
||||
{{#allParams}}{{{dataType}}} & {{{paramName}}}{{^-last}}, {{/-last}}{{/allParams}})
|
||||
{
|
||||
throw {{classname}}Exception(501, "Not implemented");
|
||||
return handler_{{httpMethod}}_func({{#allParams}}{{{paramName}}}{{^-last}}, {{/-last}}{{/allParams}});
|
||||
}
|
||||
|
||||
{{#vendorExtensions.x-codegen-other-methods}}
|
||||
{{#returnType}}std::pair<int, {{{.}}}>{{/returnType}}{{^returnType}}int{{/returnType}} {{classname}}{{vendorExtensions.x-codegen-resource-name}}Resource::handler_{{httpMethod}}(
|
||||
{{#allParams}}{{{dataType}}} const & {{{paramName}}}{{^-last}}, {{/-last}}{{/allParams}})
|
||||
{{#returnType}}std::pair<int, {{{.}}}>{{/returnType}}{{^returnType}}int{{/returnType}} {{vendorExtensions.x-codegen-resource-name}}Resource::handler_{{httpMethod}}(
|
||||
{{#allParams}}{{{dataType}}} & {{{paramName}}}{{^-last}}, {{/-last}}{{/allParams}})
|
||||
{
|
||||
throw {{classname}}Exception(501, "Not implemented");
|
||||
return handler_{{httpMethod}}_func({{#allParams}}{{{paramName}}}{{^-last}}, {{/-last}}{{/allParams}});
|
||||
}
|
||||
{{/vendorExtensions.x-codegen-other-methods}}
|
||||
|
||||
std::string {{vendorExtensions.x-codegen-resource-name}}Resource::extractBodyContent(const std::shared_ptr<restbed::Session>& session) {
|
||||
const auto request = session->get_request();
|
||||
int content_length = request->get_header("Content-Length", 0);
|
||||
std::string bodyContent;
|
||||
session->fetch(content_length,
|
||||
[&bodyContent](const std::shared_ptr<restbed::Session> session,
|
||||
const restbed::Bytes &body) {
|
||||
bodyContent = restbed::String::format(
|
||||
"%.*s\n", (int)body.size(), body.data());
|
||||
});
|
||||
return bodyContent;
|
||||
}
|
||||
|
||||
std::string {{vendorExtensions.x-codegen-resource-name}}Resource::extractFormParamsFromBody(const std::string& paramName, const std::string& body) {
|
||||
const auto uri = restbed::Uri("urlencoded?" + body, true);
|
||||
const auto params = uri.get_query_parameters();
|
||||
const auto result = params.find(paramName);
|
||||
if (result != params.cend()) {
|
||||
return result->second;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
{{/operation}}
|
||||
|
||||
} /* namespace {{classname}}Resources */
|
||||
|
||||
{{classname}}::{{classname}}(std::shared_ptr<restbed::Service> const& restbedService)
|
||||
: m_service(restbedService)
|
||||
{
|
||||
@ -379,17 +218,31 @@ void {{classname}}{{vendorExtensions.x-codegen-resource-name}}Resource::handler_
|
||||
{{classname}}::~{{classname}}() {}
|
||||
|
||||
{{#operation}}
|
||||
void {{classname}}::set{{classname}}{{vendorExtensions.x-codegen-resource-name}}Resource(std::shared_ptr<{{classname}}{{vendorExtensions.x-codegen-resource-name}}Resource> sp{{classname}}{{vendorExtensions.x-codegen-resource-name}}Resource) {
|
||||
m_sp{{classname}}{{vendorExtensions.x-codegen-resource-name}}Resource = sp{{classname}}{{vendorExtensions.x-codegen-resource-name}}Resource;
|
||||
m_service->publish(m_sp{{classname}}{{vendorExtensions.x-codegen-resource-name}}Resource);
|
||||
std::shared_ptr<{{classname}}Resources::{{vendorExtensions.x-codegen-resource-name}}Resource> {{classname}}::get{{vendorExtensions.x-codegen-resource-name}}Resource() {
|
||||
if (!m_sp{{vendorExtensions.x-codegen-resource-name}}Resource) {
|
||||
setResource(std::make_shared<{{classname}}Resources::{{vendorExtensions.x-codegen-resource-name}}Resource>());
|
||||
}
|
||||
return m_sp{{vendorExtensions.x-codegen-resource-name}}Resource;
|
||||
}
|
||||
{{/operation}}
|
||||
{{#operation}}
|
||||
void {{classname}}::setResource(std::shared_ptr<{{classname}}Resources::{{vendorExtensions.x-codegen-resource-name}}Resource> resource) {
|
||||
m_sp{{vendorExtensions.x-codegen-resource-name}}Resource = resource;
|
||||
m_service->publish(m_sp{{vendorExtensions.x-codegen-resource-name}}Resource);
|
||||
}
|
||||
{{/operation}}
|
||||
{{#operation}}
|
||||
void {{classname}}::set{{classname}}{{vendorExtensions.x-codegen-resource-name}}Resource(std::shared_ptr<{{classname}}Resources::{{vendorExtensions.x-codegen-resource-name}}Resource> sp{{vendorExtensions.x-codegen-resource-name}}Resource) {
|
||||
m_sp{{vendorExtensions.x-codegen-resource-name}}Resource = sp{{vendorExtensions.x-codegen-resource-name}}Resource;
|
||||
m_service->publish(m_sp{{vendorExtensions.x-codegen-resource-name}}Resource);
|
||||
}
|
||||
{{/operation}}
|
||||
|
||||
|
||||
void {{classname}}::publishDefaultResources() {
|
||||
{{#operation}}
|
||||
if (!m_sp{{classname}}{{vendorExtensions.x-codegen-resource-name}}Resource) {
|
||||
set{{classname}}{{vendorExtensions.x-codegen-resource-name}}Resource(std::make_shared<{{classname}}{{vendorExtensions.x-codegen-resource-name}}Resource>());
|
||||
if (!m_sp{{vendorExtensions.x-codegen-resource-name}}Resource) {
|
||||
setResource(std::make_shared<{{classname}}Resources::{{vendorExtensions.x-codegen-resource-name}}Resource>());
|
||||
}
|
||||
{{/operation}}
|
||||
}
|
||||
|
@ -18,6 +18,10 @@
|
||||
#include <array>
|
||||
{{/hasEnums}}
|
||||
#include <boost/property_tree/ptree.hpp>
|
||||
{{#interfaces}}
|
||||
#include "{{{this}}}.h"
|
||||
{{/interfaces}}
|
||||
#include "helpers.h"
|
||||
|
||||
{{#modelNamespaceDeclarations}}
|
||||
namespace {{this}} {
|
||||
@ -36,13 +40,28 @@ public:
|
||||
explicit {{classname}}(boost::property_tree::ptree const& pt);
|
||||
virtual ~{{classname}}() = default;
|
||||
|
||||
std::string toJsonString(bool prettyJson = false);
|
||||
{{classname}}(const {{classname}}& other) = default; // copy constructor
|
||||
{{classname}}({{classname}}&& other) noexcept = default; // move constructor
|
||||
|
||||
{{classname}}& operator=(const {{classname}}& other) = default; // copy assignment
|
||||
{{classname}}& operator=({{classname}}&& other) noexcept = default; // move assignment
|
||||
|
||||
std::string toJsonString(bool prettyJson = false) const;
|
||||
void fromJsonString(std::string const& jsonString);
|
||||
boost::property_tree::ptree toPropertyTree();
|
||||
boost::property_tree::ptree toPropertyTree() const;
|
||||
void fromPropertyTree(boost::property_tree::ptree const& pt);
|
||||
|
||||
{{#isEnum}}
|
||||
std::string toString() const;
|
||||
void fromString(const std::string& str);
|
||||
{{/isEnum}}
|
||||
|
||||
/////////////////////////////////////////////
|
||||
/// {{classname}} members
|
||||
{{#isEnum}}
|
||||
{{{dataType}}} getEnumValue() const;
|
||||
void setEnumValue(const {{{dataType}}}& val);
|
||||
{{/isEnum}}
|
||||
{{#vars}}
|
||||
|
||||
/// <summary>
|
||||
@ -53,17 +72,9 @@ public:
|
||||
{{/vars}}
|
||||
|
||||
protected:
|
||||
//////////////////////////////////////
|
||||
// Override these for customization //
|
||||
//////////////////////////////////////
|
||||
|
||||
virtual std::string toJsonString_internal(bool prettyJson = false);
|
||||
virtual void fromJsonString_internal(std::string const& jsonString);
|
||||
virtual boost::property_tree::ptree toPropertyTree_internal();
|
||||
virtual void fromPropertyTree_internal(boost::property_tree::ptree const& pt);
|
||||
|
||||
|
||||
protected:
|
||||
{{#isEnum}}
|
||||
{{{dataType}}} m_{{{name}}}EnumValue;
|
||||
{{/isEnum}}
|
||||
{{#vars}}
|
||||
{{^isContainer}}
|
||||
{{^isModel}}
|
||||
@ -77,18 +88,22 @@ protected:
|
||||
{{{dataType}}} m_{{name}};
|
||||
{{/isContainer}}
|
||||
{{/vars}}
|
||||
{{#vars}}
|
||||
{{#isEnum}}
|
||||
const std::array<std::string, {{#allowableValues}}{{#enumVars}}{{#-last}}{{-index}}{{/-last}}{{/enumVars}}{{/allowableValues}}> m_{{enumName}} = {
|
||||
{{#allowableValues}}{{#enumVars}}"{{{value}}}"{{^-last}},{{/-last}}{{/enumVars}}{{/allowableValues}}
|
||||
};
|
||||
|
||||
{{/isEnum}}
|
||||
{{/vars}}
|
||||
};
|
||||
|
||||
std::vector<{{classname}}> create{{classname}}VectorFromJsonString(const std::string& json);
|
||||
|
||||
template<>
|
||||
inline boost::property_tree::ptree toPt<{{classname}}>(const {{classname}}& val) {
|
||||
return val.toPropertyTree();
|
||||
}
|
||||
|
||||
template<>
|
||||
inline {{classname}} fromPt<{{classname}}>(const boost::property_tree::ptree& pt) {
|
||||
{{classname}} ret;
|
||||
ret.fromPropertyTree(pt);
|
||||
return ret;
|
||||
}
|
||||
|
||||
{{#modelNamespaceDeclarations}}
|
||||
}
|
||||
{{/modelNamespaceDeclarations}}
|
||||
|
136
modules/openapi-generator/src/main/resources/cpp-restbed-server/model-helpers-header.mustache
vendored
Normal file
136
modules/openapi-generator/src/main/resources/cpp-restbed-server/model-helpers-header.mustache
vendored
Normal file
@ -0,0 +1,136 @@
|
||||
{{>licenseInfo}}
|
||||
|
||||
#ifndef OPENAPI_MODELS_HELPER_H_
|
||||
#define OPENAPI_MODELS_HELPER_H_
|
||||
|
||||
{{{defaultInclude}}}
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <set>
|
||||
|
||||
{{#modelNamespaceDeclarations}}
|
||||
namespace {{this}} {
|
||||
{{/modelNamespaceDeclarations}}
|
||||
|
||||
template<class T>
|
||||
boost::property_tree::ptree toPt(const T& val) {
|
||||
boost::property_tree::ptree pt;
|
||||
pt.put_value(val);
|
||||
return pt;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
boost::property_tree::ptree toPt(const std::vector<T> & vec) {
|
||||
boost::property_tree::ptree pt;
|
||||
for (auto &childEntry : vec) {
|
||||
boost::property_tree::ptree childNode = toPt(childEntry);
|
||||
pt.push_back(std::make_pair("", childNode));
|
||||
}
|
||||
return pt;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
boost::property_tree::ptree toPt(const std::map<std::string, T> & map) {
|
||||
boost::property_tree::ptree pt;
|
||||
for (auto &childEntry : map) {
|
||||
boost::property_tree::ptree childNode = toPt(childEntry.second);
|
||||
pt.push_back(boost::property_tree::ptree::value_type(childEntry.first, childNode));
|
||||
}
|
||||
return pt;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
boost::property_tree::ptree toPt(const std::set<T> & set) {
|
||||
boost::property_tree::ptree pt;
|
||||
for (auto &childEntry : set) {
|
||||
boost::property_tree::ptree childNode = toPt(childEntry);
|
||||
pt.push_back(std::make_pair("", childNode));
|
||||
}
|
||||
return pt;
|
||||
}
|
||||
|
||||
|
||||
template<typename T>
|
||||
struct is_vector
|
||||
{
|
||||
static constexpr bool value = false;
|
||||
};
|
||||
|
||||
template<typename... C>
|
||||
struct is_vector<std::vector<C...>>
|
||||
{
|
||||
static constexpr bool value = true;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct is_map
|
||||
{
|
||||
static constexpr bool value = false;
|
||||
};
|
||||
|
||||
template<typename... C>
|
||||
struct is_map<std::map<C...>>
|
||||
{
|
||||
static constexpr bool value = true;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct is_set
|
||||
{
|
||||
static constexpr bool value = false;
|
||||
};
|
||||
|
||||
template<typename... C>
|
||||
struct is_set<std::set<C...>>
|
||||
{
|
||||
static constexpr bool value = true;
|
||||
};
|
||||
|
||||
|
||||
template<class T>
|
||||
std::enable_if_t<!is_vector<T>::value && !is_map<T>::value && !is_set<T>::value, T>
|
||||
fromPt(const boost::property_tree::ptree& pt) {
|
||||
return pt.get_value<T>();
|
||||
}
|
||||
|
||||
template<class T>
|
||||
std::enable_if_t<is_vector<T>::value,T>
|
||||
fromPt(const boost::property_tree::ptree& pt) {
|
||||
T vec;
|
||||
for (const auto &child: pt) {
|
||||
typename T::value_type childElement = fromPt<typename T::value_type>(child.second);
|
||||
vec.emplace_back(childElement);
|
||||
}
|
||||
return vec;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
std::enable_if_t<is_map<T>::value,T>
|
||||
fromPt(const boost::property_tree::ptree &pt) {
|
||||
T map;
|
||||
for (const auto &child: pt) {
|
||||
using ChildType = typename T::mapped_type;
|
||||
ChildType childElement = fromPt<ChildType>(child.second);
|
||||
map.insert(std::make_pair(child.first, childElement));
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
std::enable_if_t<is_set<T>::value,T>
|
||||
fromPt(const boost::property_tree::ptree& pt) {
|
||||
T set;
|
||||
for (const auto &child: pt) {
|
||||
typename T::value_type childElement = fromPt<typename T::value_type>(child.second);
|
||||
set.insert(childElement);
|
||||
}
|
||||
return set;
|
||||
}
|
||||
|
||||
{{#modelNamespaceDeclarations}}
|
||||
}
|
||||
{{/modelNamespaceDeclarations}}
|
||||
|
||||
#endif /* OPENAPI_MODELS_HELPER_H_ */
|
@ -5,13 +5,17 @@
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <sstream>
|
||||
#include <stdexcept>
|
||||
#include <regex>
|
||||
{{#hasEnums}}
|
||||
#include <algorithm>
|
||||
{{/hasEnums}}
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <boost/property_tree/ptree.hpp>
|
||||
#include <boost/property_tree/json_parser.hpp>
|
||||
#include "helpers.h"
|
||||
|
||||
using boost::property_tree::ptree;
|
||||
using boost::property_tree::read_json;
|
||||
@ -26,34 +30,18 @@ namespace {{this}} {
|
||||
fromPropertyTree(pt);
|
||||
}
|
||||
|
||||
std::string {{classname}}::toJsonString(bool prettyJson /* = false */)
|
||||
{
|
||||
return toJsonString_internal(prettyJson);
|
||||
}
|
||||
|
||||
void {{classname}}::fromJsonString(std::string const& jsonString)
|
||||
{
|
||||
fromJsonString_internal(jsonString);
|
||||
}
|
||||
|
||||
boost::property_tree::ptree {{classname}}::toPropertyTree()
|
||||
{
|
||||
return toPropertyTree_internal();
|
||||
}
|
||||
|
||||
void {{classname}}::fromPropertyTree(boost::property_tree::ptree const& pt)
|
||||
{
|
||||
fromPropertyTree_internal(pt);
|
||||
}
|
||||
|
||||
std::string {{classname}}::toJsonString_internal(bool prettyJson)
|
||||
std::string {{classname}}::toJsonString(bool prettyJson /* = false */) const
|
||||
{
|
||||
std::stringstream ss;
|
||||
write_json(ss, this->toPropertyTree(), prettyJson);
|
||||
return ss.str();
|
||||
// workaround inspired by: https://stackoverflow.com/a/56395440
|
||||
std::regex reg("\\\"([0-9]+\\.{0,1}[0-9]*)\\\"");
|
||||
std::string result = std::regex_replace(ss.str(), reg, "$1");
|
||||
return result;
|
||||
}
|
||||
|
||||
void {{classname}}::fromJsonString_internal(std::string const& jsonString)
|
||||
void {{classname}}::fromJsonString(std::string const& jsonString)
|
||||
{
|
||||
std::stringstream ss(jsonString);
|
||||
ptree pt;
|
||||
@ -61,7 +49,7 @@ void {{classname}}::fromJsonString_internal(std::string const& jsonString)
|
||||
this->fromPropertyTree(pt);
|
||||
}
|
||||
|
||||
ptree {{classname}}::toPropertyTree_internal()
|
||||
ptree {{classname}}::toPropertyTree() const
|
||||
{
|
||||
ptree pt;
|
||||
ptree tmp_node;
|
||||
@ -81,36 +69,34 @@ ptree {{classname}}::toPropertyTree_internal()
|
||||
pt.put("{{baseName}}", m_{{name}});
|
||||
{{/isDateTime}}
|
||||
{{#isModel}}
|
||||
if (m_{{name}} != nullptr) {
|
||||
pt.add_child("{{baseName}}", m_{{name}}->toPropertyTree());
|
||||
}
|
||||
pt.add_child("{{baseName}}", m_{{name}}.toPropertyTree());
|
||||
{{/isModel}}
|
||||
{{/isPrimitiveType}}
|
||||
{{/isContainer}}
|
||||
{{#isContainer}}
|
||||
// generate tree for {{name}}
|
||||
if (!m_{{name}}.empty()) {
|
||||
for (const auto &childEntry : m_{{name}}) {
|
||||
{{#items}}
|
||||
{{#isModel}}
|
||||
tmp_node.push_back(std::make_pair("", childEntry->toPropertyTree()));
|
||||
{{/isModel}}
|
||||
{{#isMap}}
|
||||
{{^isModel}}
|
||||
ptree {{name}}_node;
|
||||
{{name}}_node.put("", childEntry);
|
||||
tmp_node.push_back(std::make_pair("", {{name}}_node));
|
||||
{{/isModel}}
|
||||
{{/items}}
|
||||
if (!m_{{name}}.empty()) {
|
||||
tmp_node = toPt(m_{{name}});
|
||||
pt.add_child("{{baseName}}", tmp_node);
|
||||
}
|
||||
{{/isModel}}
|
||||
{{/isMap}}
|
||||
tmp_node.clear();
|
||||
{{^isMap}}
|
||||
if (!m_{{name}}.empty()) {
|
||||
tmp_node = toPt(m_{{name}});
|
||||
pt.add_child("{{baseName}}", tmp_node);
|
||||
tmp_node.clear();
|
||||
}
|
||||
{{/isMap}}
|
||||
{{/isContainer}}
|
||||
{{/vars}}
|
||||
return pt;
|
||||
}
|
||||
|
||||
void {{classname}}::fromPropertyTree_internal(ptree const &pt)
|
||||
void {{classname}}::fromPropertyTree(ptree const &pt)
|
||||
{
|
||||
ptree tmp_node;
|
||||
{{#vars}}
|
||||
@ -136,65 +122,58 @@ void {{classname}}::fromPropertyTree_internal(ptree const &pt)
|
||||
{{/isEnum}}
|
||||
{{#isModel}}
|
||||
if (pt.get_child_optional("{{baseName}}")) {
|
||||
m_{{name}} = {{{defaultValue}}};
|
||||
m_{{name}}->fromPropertyTree(pt.get_child("{{baseName}}"));
|
||||
m_{{{name}}} = fromPt<{{{dataType}}}>(pt.get_child("{{baseName}}"));
|
||||
}
|
||||
{{/isModel}}
|
||||
{{/isContainer}}
|
||||
{{#isContainer}}
|
||||
{{^isModelContainer}}
|
||||
// push all items of {{name}} into member vector
|
||||
{{#isMap}}
|
||||
if (pt.get_child_optional("{{baseName}}")) {
|
||||
for (const auto &childTree : pt.get_child("{{baseName}}")) {
|
||||
{{#mostInnerItems}}
|
||||
{{{dataType}}} val =
|
||||
{{#isNumeric}}
|
||||
{{^isFloat}}
|
||||
{{^isLong}}
|
||||
{{^isInteger}}
|
||||
std::stod(childTree.second.data());
|
||||
{{/isInteger}}
|
||||
{{/isLong}}
|
||||
{{/isFloat}}
|
||||
{{#isDouble}}
|
||||
std::stod(childTree.second.data());
|
||||
{{/isDouble}}
|
||||
{{#isFloat}}
|
||||
std::stof(childTree.second.data());
|
||||
{{/isFloat}}
|
||||
{{#isInteger}}
|
||||
std::stoi(childTree.second.data());
|
||||
{{/isInteger}}
|
||||
{{#isLong}}
|
||||
std::stol(childTree.second.data());
|
||||
{{/isLong}}
|
||||
{{/isNumeric}}
|
||||
{{#isString}}
|
||||
childTree.second.data();
|
||||
{{/isString}}
|
||||
{{#isModel}}
|
||||
std::make_shared<{{baseType}}>(childTree.second);
|
||||
{{/isModel}}
|
||||
m_{{name}}.emplace_back(std::move(val));
|
||||
{{/mostInnerItems}}
|
||||
m_{{{name}}} = fromPt<{{{dataType}}}>(pt.get_child("{{baseName}}"));
|
||||
}
|
||||
{{/isMap}}
|
||||
{{^isMap}}
|
||||
{{^isModelContainer}}
|
||||
// push all items of {{name}} into member
|
||||
if (pt.get_child_optional("{{baseName}}")) {
|
||||
m_{{{name}}} = fromPt<{{{dataType}}}>(pt.get_child("{{baseName}}"));
|
||||
}
|
||||
{{/isModelContainer}}
|
||||
{{#isModelContainer}}
|
||||
// generate new {{complexType}} Object for each item and assign it to the current
|
||||
if (pt.get_child_optional("{{baseName}}")) {
|
||||
for (const auto &childTree : pt.get_child("{{baseName}}")) {
|
||||
{{#mostInnerItems}}
|
||||
m_{{name}}.emplace_back({{{defaultValue}}});
|
||||
m_{{name}}.back()->fromPropertyTree(childTree.second);
|
||||
{{/mostInnerItems}}
|
||||
}
|
||||
m_{{{name}}} = fromPt<{{{dataType}}}>(pt.get_child("{{baseName}}"));
|
||||
}
|
||||
{{/isModelContainer}}
|
||||
{{/isMap}}
|
||||
{{/isContainer}}
|
||||
{{/vars}}
|
||||
}
|
||||
|
||||
{{#isEnum}}
|
||||
std::string {{classname}}::toString() const {
|
||||
return boost::lexical_cast<std::string>(getEnumValue());
|
||||
}
|
||||
|
||||
void {{classname}}::fromString(const std::string& str) {
|
||||
setEnumValue(boost::lexical_cast<{{{dataType}}}>(str));
|
||||
}
|
||||
|
||||
{{{dataType}}} {{classname}}::getEnumValue() const {
|
||||
return m_{{{name}}}EnumValue;
|
||||
}
|
||||
|
||||
void {{classname}}::setEnumValue(const {{{dataType}}}& val) {
|
||||
static const std::array<{{#complexType}}{{{.}}}{{/complexType}}{{^complexType}}{{{dataType}}}{{/complexType}}, {{#allowableValues}}{{#enumVars}}{{#-last}}{{-index}}{{/-last}}{{/enumVars}}{{/allowableValues}}> allowedValues = {
|
||||
{{#allowableValues}}{{#enumVars}}{{^isNumeric}}"{{/isNumeric}}{{{value}}}{{^isNumeric}}"{{/isNumeric}}{{^-last}}, {{/-last}}{{/enumVars}}{{/allowableValues}}
|
||||
};
|
||||
if (std::find(allowedValues.begin(), allowedValues.end(), val) != allowedValues.end()) {
|
||||
m_{{{name}}}EnumValue = val;
|
||||
} else {
|
||||
throw std::runtime_error("Value " + boost::lexical_cast<std::string>(val) + " not allowed");
|
||||
}
|
||||
}
|
||||
{{/isEnum}}
|
||||
{{#vars}}
|
||||
{{{dataType}}} {{classname}}::{{getter}}() const
|
||||
{
|
||||
@ -203,12 +182,42 @@ void {{classname}}::fromPropertyTree_internal(ptree const &pt)
|
||||
|
||||
void {{classname}}::{{setter}}({{{dataType}}} value)
|
||||
{
|
||||
{{#isEnum}}if (std::find(m_{{enumName}}.begin(), m_{{enumName}}.end(), value) != m_{{enumName}}.end()) {
|
||||
{{/isEnum}}m_{{name}} = value;{{#isEnum}}
|
||||
} else {
|
||||
throw std::runtime_error("Value " + value + " not allowed");
|
||||
}{{/isEnum}}
|
||||
{{#isEnum}}
|
||||
static const std::array<{{#complexType}}{{{.}}}{{/complexType}}{{^complexType}}{{{dataType}}}{{/complexType}}, {{#allowableValues}}{{#enumVars}}{{#-last}}{{-index}}{{/-last}}{{/enumVars}}{{/allowableValues}}> allowedValues = {
|
||||
{{#allowableValues}}{{#enumVars}}{{^isNumeric}}"{{/isNumeric}}{{{value}}}{{^isNumeric}}"{{/isNumeric}}{{^-last}}, {{/-last}}{{/enumVars}}{{/allowableValues}}
|
||||
};
|
||||
|
||||
{{#isContainer}}
|
||||
{{#isMap}}
|
||||
for (const auto &v: value) {
|
||||
if (std::find(allowedValues.begin(), allowedValues.end(), v.first) == allowedValues.end()) {
|
||||
throw std::runtime_error("Value " + boost::lexical_cast<std::string>(v.first) + " not allowed");
|
||||
}
|
||||
}
|
||||
m_{{name}} = value;
|
||||
{{/isMap}}
|
||||
{{^isMap}}
|
||||
for (const auto &v: value) {
|
||||
if (std::find(allowedValues.begin(), allowedValues.end(), v) == allowedValues.end()) {
|
||||
throw std::runtime_error("Value " + boost::lexical_cast<std::string>(v) + " not allowed");
|
||||
}
|
||||
}
|
||||
{{/isMap}}
|
||||
{{/isContainer}}
|
||||
{{^isContainer}}
|
||||
if (std::find(allowedValues.begin(), allowedValues.end(), value) != allowedValues.end()) {
|
||||
m_{{name}} = value;
|
||||
} else {
|
||||
throw std::runtime_error("Value " + boost::lexical_cast<std::string>(value) + " not allowed");
|
||||
}
|
||||
{{/isContainer}}
|
||||
{{/isEnum}}
|
||||
{{^isEnum}}
|
||||
m_{{name}} = value;
|
||||
{{/isEnum}}
|
||||
}
|
||||
|
||||
|
||||
{{/vars}}
|
||||
|
||||
std::vector<{{classname}}> create{{classname}}VectorFromJsonString(const std::string& json)
|
||||
|
@ -0,0 +1,71 @@
|
||||
package org.openapitools.codegen.cpprestbed;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.openapitools.codegen.CodegenOperation;
|
||||
import org.openapitools.codegen.languages.CppRestbedServerCodegen;
|
||||
import org.openapitools.codegen.model.OperationMap;
|
||||
import org.openapitools.codegen.model.OperationsMap;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class CppRestbedServerTest {
|
||||
|
||||
@DataProvider(name = "providedPaths")
|
||||
public Object[][] providedPaths() {
|
||||
Object[][] data = new Object[3][2];
|
||||
data[0][0] = "/abc/{id}";
|
||||
data[0][1] = "/abc/{id: .*}";
|
||||
|
||||
data[1][0] = "/{Foo}/";
|
||||
data[1][1] = "/{Foo: .*}/";
|
||||
|
||||
data[2][0] = "xyz/";
|
||||
data[2][1] = "xyz/";
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
@Test(dataProvider = "providedPaths")
|
||||
void testPathProcessing(String providedPath, String expectedPath) {
|
||||
// Arrange
|
||||
CppRestbedServerCodegen codegen = new CppRestbedServerCodegen();
|
||||
OperationsMap objs = setupOperationWithPath(providedPath);
|
||||
|
||||
// Act
|
||||
OperationsMap processedObjs = codegen.postProcessOperationsWithModels(objs, new ArrayList<>());
|
||||
|
||||
// Assert
|
||||
List<CodegenOperation> processedObjsOperationList = extractOperationsList(processedObjs);
|
||||
|
||||
Assert.assertEquals(processedObjsOperationList.size(), 1);
|
||||
Assert.assertEquals(processedObjsOperationList.get(0).path, expectedPath);
|
||||
}
|
||||
|
||||
private static List<CodegenOperation> extractOperationsList(Map<String, Object> processedObjs) {
|
||||
Map<String, Object> processedOperations = (Map<String, Object>) processedObjs.get("operations");
|
||||
List<CodegenOperation> processedObjsOperationList = (List<CodegenOperation>) processedOperations.get("operation");
|
||||
return processedObjsOperationList;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static OperationsMap setupOperationWithPath(String path) {
|
||||
CodegenOperation op = new CodegenOperation();
|
||||
op.path = path;
|
||||
|
||||
List<CodegenOperation> operationsList = new ArrayList<>();
|
||||
operationsList.add(op);
|
||||
|
||||
OperationMap operations = new OperationMap();
|
||||
operations.put("operation", operationsList);
|
||||
|
||||
OperationsMap objs = new OperationsMap();
|
||||
objs.put("operations", operations);
|
||||
return objs;
|
||||
}
|
||||
}
|
29
samples/server/petstore/cpp-restbed-deprecated/.gitignore
vendored
Normal file
29
samples/server/petstore/cpp-restbed-deprecated/.gitignore
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
# Compiled Object files
|
||||
*.slo
|
||||
*.lo
|
||||
*.o
|
||||
*.obj
|
||||
|
||||
# Precompiled Headers
|
||||
*.gch
|
||||
*.pch
|
||||
|
||||
# Compiled Dynamic libraries
|
||||
*.so
|
||||
*.dylib
|
||||
*.dll
|
||||
|
||||
# Fortran module files
|
||||
*.mod
|
||||
*.smod
|
||||
|
||||
# Compiled Static libraries
|
||||
*.lai
|
||||
*.la
|
||||
*.a
|
||||
*.lib
|
||||
|
||||
# Executables
|
||||
*.exe
|
||||
*.out
|
||||
*.app
|
@ -1,4 +1,5 @@
|
||||
.gitignore
|
||||
.openapi-generator-ignore
|
||||
README.md
|
||||
api/PetApi.cpp
|
||||
api/PetApi.h
|
@ -138,17 +138,18 @@ void PetApiPetResource::handler_POST_internal(const std::shared_ptr<restbed::Ses
|
||||
std::string bodyContent = extractBodyContent(session);
|
||||
|
||||
// Get body params or form params here from the body content string
|
||||
auto body = extractJsonModelBodyParam<Pet>(bodyContent);
|
||||
auto pet = extractJsonModelBodyParam<Pet>(bodyContent);
|
||||
|
||||
|
||||
|
||||
|
||||
int status_code = 500;
|
||||
std::shared_ptr<Pet> resultObject = std::make_shared<Pet>();
|
||||
std::string result = "";
|
||||
|
||||
try {
|
||||
status_code =
|
||||
handler_POST(body);
|
||||
std::tie(status_code, resultObject) =
|
||||
handler_POST(pet);
|
||||
}
|
||||
catch(const PetApiException& e) {
|
||||
std::tie(status_code, result) = handlePetApiException(e);
|
||||
@ -160,6 +161,13 @@ void PetApiPetResource::handler_POST_internal(const std::shared_ptr<restbed::Ses
|
||||
std::tie(status_code, result) = handleUnspecifiedException();
|
||||
}
|
||||
|
||||
if (status_code == 200) {
|
||||
result = resultObject->toJsonString();
|
||||
|
||||
const constexpr auto contentType = "application/json";
|
||||
returnResponse(session, 200, result.empty() ? "successful operation" : result, contentType);
|
||||
return;
|
||||
}
|
||||
if (status_code == 405) {
|
||||
|
||||
const constexpr auto contentType = "text/plain";
|
||||
@ -176,15 +184,16 @@ void PetApiPetResource::handler_PUT_internal(const std::shared_ptr<restbed::Sess
|
||||
std::string bodyContent = extractBodyContent(session);
|
||||
|
||||
// body params or form params here from the body content string
|
||||
auto body = extractJsonModelBodyParam<Pet>(bodyContent);
|
||||
auto pet = extractJsonModelBodyParam<Pet>(bodyContent);
|
||||
|
||||
|
||||
int status_code = 500;
|
||||
std::shared_ptr<Pet> resultObject = std::make_shared<Pet>();
|
||||
std::string result = "";
|
||||
|
||||
try {
|
||||
status_code =
|
||||
handler_PUT(body);
|
||||
std::tie(status_code, resultObject) =
|
||||
handler_PUT(pet);
|
||||
}
|
||||
catch(const PetApiException& e) {
|
||||
std::tie(status_code, result) = handlePetApiException(e);
|
||||
@ -196,6 +205,13 @@ void PetApiPetResource::handler_PUT_internal(const std::shared_ptr<restbed::Sess
|
||||
std::tie(status_code, result) = handleUnspecifiedException();
|
||||
}
|
||||
|
||||
if (status_code == 200) {
|
||||
result = resultObject->toJsonString();
|
||||
|
||||
const constexpr auto contentType = "application/json";
|
||||
returnResponse(session, 200, result.empty() ? "successful operation" : result, contentType);
|
||||
return;
|
||||
}
|
||||
if (status_code == 400) {
|
||||
|
||||
const constexpr auto contentType = "text/plain";
|
||||
@ -217,14 +233,14 @@ void PetApiPetResource::handler_PUT_internal(const std::shared_ptr<restbed::Sess
|
||||
defaultSessionClose(session, status_code, result);
|
||||
}
|
||||
|
||||
int PetApiPetResource::handler_POST(
|
||||
std::shared_ptr<Pet> const & body)
|
||||
std::pair<int, std::shared_ptr<Pet>> PetApiPetResource::handler_POST(
|
||||
std::shared_ptr<Pet> const & pet)
|
||||
{
|
||||
throw PetApiException(501, "Not implemented");
|
||||
}
|
||||
|
||||
int PetApiPetResource::handler_PUT(
|
||||
std::shared_ptr<Pet> const & body)
|
||||
std::pair<int, std::shared_ptr<Pet>> PetApiPetResource::handler_PUT(
|
||||
std::shared_ptr<Pet> const & pet)
|
||||
{
|
||||
throw PetApiException(501, "Not implemented");
|
||||
}
|
@ -74,11 +74,11 @@ protected:
|
||||
// Override these to implement the server functionality //
|
||||
//////////////////////////////////////////////////////////
|
||||
|
||||
virtual int handler_POST(
|
||||
std::shared_ptr<Pet> const & body);
|
||||
virtual std::pair<int, std::shared_ptr<Pet>> handler_POST(
|
||||
std::shared_ptr<Pet> const & pet);
|
||||
|
||||
virtual int handler_PUT(
|
||||
std::shared_ptr<Pet> const & body);
|
||||
virtual std::pair<int, std::shared_ptr<Pet>> handler_PUT(
|
||||
std::shared_ptr<Pet> const & pet);
|
||||
|
||||
protected:
|
||||
//////////////////////////////////////
|
@ -314,6 +314,7 @@ void StoreApiStoreInventoryResource::handler_GET_internal(const std::shared_ptr<
|
||||
}
|
||||
|
||||
if (status_code == 200) {
|
||||
result = resultObject->toJsonString();
|
||||
result = convertMapResponse(resultObject);
|
||||
|
||||
const constexpr auto contentType = "application/json";
|
||||
@ -391,7 +392,7 @@ void StoreApiStoreOrderResource::handler_POST_internal(const std::shared_ptr<res
|
||||
std::string bodyContent = extractBodyContent(session);
|
||||
|
||||
// Get body params or form params here from the body content string
|
||||
auto body = extractJsonModelBodyParam<Order>(bodyContent);
|
||||
auto order = extractJsonModelBodyParam<Order>(bodyContent);
|
||||
|
||||
|
||||
|
||||
@ -402,7 +403,7 @@ void StoreApiStoreOrderResource::handler_POST_internal(const std::shared_ptr<res
|
||||
|
||||
try {
|
||||
std::tie(status_code, resultObject) =
|
||||
handler_POST(body);
|
||||
handler_POST(order);
|
||||
}
|
||||
catch(const StoreApiException& e) {
|
||||
std::tie(status_code, result) = handleStoreApiException(e);
|
||||
@ -432,7 +433,7 @@ void StoreApiStoreOrderResource::handler_POST_internal(const std::shared_ptr<res
|
||||
|
||||
|
||||
std::pair<int, std::shared_ptr<Order>> StoreApiStoreOrderResource::handler_POST(
|
||||
std::shared_ptr<Order> const & body)
|
||||
std::shared_ptr<Order> const & order)
|
||||
{
|
||||
throw StoreApiException(501, "Not implemented");
|
||||
}
|
@ -183,7 +183,7 @@ protected:
|
||||
//////////////////////////////////////////////////////////
|
||||
|
||||
virtual std::pair<int, std::shared_ptr<Order>> handler_POST(
|
||||
std::shared_ptr<Order> const & body);
|
||||
std::shared_ptr<Order> const & order);
|
||||
|
||||
|
||||
protected:
|
@ -135,7 +135,7 @@ void UserApiUserResource::handler_POST_internal(const std::shared_ptr<restbed::S
|
||||
std::string bodyContent = extractBodyContent(session);
|
||||
|
||||
// Get body params or form params here from the body content string
|
||||
auto body = extractJsonModelBodyParam<User>(bodyContent);
|
||||
auto user = extractJsonModelBodyParam<User>(bodyContent);
|
||||
|
||||
|
||||
|
||||
@ -145,7 +145,7 @@ void UserApiUserResource::handler_POST_internal(const std::shared_ptr<restbed::S
|
||||
|
||||
try {
|
||||
status_code =
|
||||
handler_POST(body);
|
||||
handler_POST(user);
|
||||
}
|
||||
catch(const UserApiException& e) {
|
||||
std::tie(status_code, result) = handleUserApiException(e);
|
||||
@ -168,7 +168,7 @@ void UserApiUserResource::handler_POST_internal(const std::shared_ptr<restbed::S
|
||||
|
||||
|
||||
int UserApiUserResource::handler_POST(
|
||||
std::shared_ptr<User> const & body)
|
||||
std::shared_ptr<User> const & user)
|
||||
{
|
||||
throw UserApiException(501, "Not implemented");
|
||||
}
|
||||
@ -234,7 +234,7 @@ void UserApiUserCreateWithArrayResource::handler_POST_internal(const std::shared
|
||||
std::string bodyContent = extractBodyContent(session);
|
||||
|
||||
// Get body params or form params here from the body content string
|
||||
auto body = extractJsonArrayBodyParam<User>(bodyContent);
|
||||
auto user = extractJsonArrayBodyParam<User>(bodyContent);
|
||||
|
||||
|
||||
|
||||
@ -244,7 +244,7 @@ void UserApiUserCreateWithArrayResource::handler_POST_internal(const std::shared
|
||||
|
||||
try {
|
||||
status_code =
|
||||
handler_POST(body);
|
||||
handler_POST(user);
|
||||
}
|
||||
catch(const UserApiException& e) {
|
||||
std::tie(status_code, result) = handleUserApiException(e);
|
||||
@ -267,7 +267,7 @@ void UserApiUserCreateWithArrayResource::handler_POST_internal(const std::shared
|
||||
|
||||
|
||||
int UserApiUserCreateWithArrayResource::handler_POST(
|
||||
std::vector<std::shared_ptr<User>> const & body)
|
||||
std::vector<std::shared_ptr<User>> const & user)
|
||||
{
|
||||
throw UserApiException(501, "Not implemented");
|
||||
}
|
||||
@ -333,7 +333,7 @@ void UserApiUserCreateWithListResource::handler_POST_internal(const std::shared_
|
||||
std::string bodyContent = extractBodyContent(session);
|
||||
|
||||
// Get body params or form params here from the body content string
|
||||
auto body = extractJsonArrayBodyParam<User>(bodyContent);
|
||||
auto user = extractJsonArrayBodyParam<User>(bodyContent);
|
||||
|
||||
|
||||
|
||||
@ -343,7 +343,7 @@ void UserApiUserCreateWithListResource::handler_POST_internal(const std::shared_
|
||||
|
||||
try {
|
||||
status_code =
|
||||
handler_POST(body);
|
||||
handler_POST(user);
|
||||
}
|
||||
catch(const UserApiException& e) {
|
||||
std::tie(status_code, result) = handleUserApiException(e);
|
||||
@ -366,7 +366,7 @@ void UserApiUserCreateWithListResource::handler_POST_internal(const std::shared_
|
||||
|
||||
|
||||
int UserApiUserCreateWithListResource::handler_POST(
|
||||
std::vector<std::shared_ptr<User>> const & body)
|
||||
std::vector<std::shared_ptr<User>> const & user)
|
||||
{
|
||||
throw UserApiException(501, "Not implemented");
|
||||
}
|
||||
@ -529,7 +529,7 @@ void UserApiUserUsernameResource::handler_PUT_internal(const std::shared_ptr<res
|
||||
|
||||
// body params or form params here from the body content string
|
||||
auto username = std::make_shared<>(bodyContent);
|
||||
auto body = extractJsonModelBodyParam<User>(bodyContent);
|
||||
auto user = extractJsonModelBodyParam<User>(bodyContent);
|
||||
|
||||
// Getting the path params
|
||||
const std::string username = getPathParam_username_x_extension(request);
|
||||
@ -540,7 +540,7 @@ void UserApiUserUsernameResource::handler_PUT_internal(const std::shared_ptr<res
|
||||
|
||||
try {
|
||||
status_code =
|
||||
handler_PUT(username, body);
|
||||
handler_PUT(username, user);
|
||||
}
|
||||
catch(const UserApiException& e) {
|
||||
std::tie(status_code, result) = handleUserApiException(e);
|
||||
@ -579,7 +579,7 @@ std::pair<int, std::shared_ptr<User>> UserApiUserUsernameResource::handler_GET(
|
||||
throw UserApiException(501, "Not implemented");
|
||||
}
|
||||
int UserApiUserUsernameResource::handler_PUT(
|
||||
std::string const & username, std::shared_ptr<User> const & body)
|
||||
std::string const & username, std::shared_ptr<User> const & user)
|
||||
{
|
||||
throw UserApiException(501, "Not implemented");
|
||||
}
|
||||
@ -668,9 +668,11 @@ void UserApiUserLoginResource::handler_GET_internal(const std::shared_ptr<restbe
|
||||
|
||||
if (status_code == 200) {
|
||||
result = resultObject;
|
||||
// Description: Cookie authentication key for use with the `api_key` apiKey authentication.
|
||||
setResponseHeader(session, "Set-Cookie");
|
||||
// Description: calls per hour allowed by the user
|
||||
setResponseHeader(session, "X-Rate-Limit");
|
||||
// Description: date in UTC when toekn expires
|
||||
// Description: date in UTC when token expires
|
||||
setResponseHeader(session, "X-Expires-After");
|
||||
|
||||
const constexpr auto contentType = "application/json";
|
@ -75,7 +75,7 @@ protected:
|
||||
//////////////////////////////////////////////////////////
|
||||
|
||||
virtual int handler_POST(
|
||||
std::shared_ptr<User> const & body);
|
||||
std::shared_ptr<User> const & user);
|
||||
|
||||
|
||||
protected:
|
||||
@ -123,7 +123,7 @@ protected:
|
||||
//////////////////////////////////////////////////////////
|
||||
|
||||
virtual int handler_POST(
|
||||
std::vector<std::shared_ptr<User>> const & body);
|
||||
std::vector<std::shared_ptr<User>> const & user);
|
||||
|
||||
|
||||
protected:
|
||||
@ -171,7 +171,7 @@ protected:
|
||||
//////////////////////////////////////////////////////////
|
||||
|
||||
virtual int handler_POST(
|
||||
std::vector<std::shared_ptr<User>> const & body);
|
||||
std::vector<std::shared_ptr<User>> const & user);
|
||||
|
||||
|
||||
protected:
|
||||
@ -224,7 +224,7 @@ protected:
|
||||
virtual std::pair<int, std::shared_ptr<User>> handler_GET(
|
||||
std::string const & username);
|
||||
virtual int handler_PUT(
|
||||
std::string const & username, std::shared_ptr<User> const & body);
|
||||
std::string const & username, std::shared_ptr<User> const & user);
|
||||
|
||||
protected:
|
||||
//////////////////////////////////////
|
@ -1,7 +1,7 @@
|
||||
#!/bin/sh
|
||||
# ref: https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/
|
||||
#
|
||||
# Usage example: /bin/sh ./git_push.sh wing328 openapi-pestore-perl "minor update" "gitlab.com"
|
||||
# Usage example: /bin/sh ./git_push.sh wing328 openapi-petstore-perl "minor update" "gitlab.com"
|
||||
|
||||
git_user_id=$1
|
||||
git_repo_id=$2
|
||||
@ -38,14 +38,14 @@ git add .
|
||||
git commit -m "$release_note"
|
||||
|
||||
# Sets the new remote
|
||||
git_remote=`git remote`
|
||||
git_remote=$(git remote)
|
||||
if [ "$git_remote" = "" ]; then # git remote not defined
|
||||
|
||||
if [ "$GIT_TOKEN" = "" ]; then
|
||||
echo "[INFO] \$GIT_TOKEN (environment variable) is not set. Using the git credential in your environment."
|
||||
git remote add origin https://${git_host}/${git_user_id}/${git_repo_id}.git
|
||||
else
|
||||
git remote add origin https://${git_user_id}:${GIT_TOKEN}@${git_host}/${git_user_id}/${git_repo_id}.git
|
||||
git remote add origin https://${git_user_id}:"${GIT_TOKEN}"@${git_host}/${git_user_id}/${git_repo_id}.git
|
||||
fi
|
||||
|
||||
fi
|
||||
@ -55,4 +55,3 @@ git pull origin master
|
||||
# Pushes (Forces) the changes in the local repository up to the remote repository
|
||||
echo "Git pushing to https://${git_host}/${git_user_id}/${git_repo_id}.git"
|
||||
git push origin master 2>&1 | grep -v 'To https'
|
||||
|
33
samples/server/petstore/cpp-restbed/.gitignore
vendored
33
samples/server/petstore/cpp-restbed/.gitignore
vendored
@ -1,29 +1,4 @@
|
||||
# Compiled Object files
|
||||
*.slo
|
||||
*.lo
|
||||
*.o
|
||||
*.obj
|
||||
|
||||
# Precompiled Headers
|
||||
*.gch
|
||||
*.pch
|
||||
|
||||
# Compiled Dynamic libraries
|
||||
*.so
|
||||
*.dylib
|
||||
*.dll
|
||||
|
||||
# Fortran module files
|
||||
*.mod
|
||||
*.smod
|
||||
|
||||
# Compiled Static libraries
|
||||
*.lai
|
||||
*.la
|
||||
*.a
|
||||
*.lib
|
||||
|
||||
# Executables
|
||||
*.exe
|
||||
*.out
|
||||
*.app
|
||||
build/
|
||||
.idea/
|
||||
cmake-build-*/
|
||||
*.received.txt
|
||||
|
33
samples/server/petstore/cpp-restbed/CMakeLists.txt
Normal file
33
samples/server/petstore/cpp-restbed/CMakeLists.txt
Normal file
@ -0,0 +1,33 @@
|
||||
cmake_policy(SET CMP0048 NEW)
|
||||
|
||||
project(cpp-restped-server-open-api VERSION 1)
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})
|
||||
message(${CMAKE_MODULE_PATH})
|
||||
|
||||
include(dependencies)
|
||||
include(JavaClientTests)
|
||||
|
||||
|
||||
set(CMAKE_CXX_STANDARD 14)
|
||||
|
||||
# Coverage
|
||||
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-instr-generate -fcoverage-mapping")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-instr-generate -fcoverage-mapping")
|
||||
message("Using clang coverage")
|
||||
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --coverage")
|
||||
endif()
|
||||
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
|
||||
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
|
||||
set(CMAKE_EXE_LINKER_FLAGS ${CMAKE_EXE_LINKER_FLAGS} -lpthread)
|
||||
|
||||
enable_testing()
|
||||
|
||||
add_subdirectory(generated/3_0)
|
||||
add_subdirectory(test)
|
21
samples/server/petstore/cpp-restbed/build_and_test.sh
Executable file
21
samples/server/petstore/cpp-restbed/build_and_test.sh
Executable file
@ -0,0 +1,21 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -u
|
||||
set -e
|
||||
|
||||
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
|
||||
|
||||
cd ${SCRIPT_DIR}
|
||||
|
||||
rm -rf build
|
||||
|
||||
cmake -S . -B build
|
||||
cd build
|
||||
make
|
||||
|
||||
# pure C++ tests
|
||||
make test -j4
|
||||
|
||||
# tests with Java client
|
||||
# run them during development
|
||||
#make run_all_java_client_test_for_cpp_server
|
@ -0,0 +1,35 @@
|
||||
|
||||
add_custom_target(run_all_java_client_test_for_cpp_server)
|
||||
|
||||
define_property(GLOBAL
|
||||
PROPERTY LAST_JAVA_CLIENT_TEST
|
||||
BRIEF_DOCS Used to order the tests to run after each other
|
||||
FULL_DOCS The tests are ordered by defining a dependency chain)
|
||||
set_property(GLOBAL
|
||||
PROPERTY LAST_JAVA_CLIENT_TEST run_all_java_client_test_for_cpp_server)
|
||||
|
||||
set(RUN_CLIENT_TESTS_SHELL_TEMPLATE "run_java_client_tests_template.txt")
|
||||
|
||||
function(run_java_client_test_for_cpp_server TARGET_NAME)
|
||||
set(TEST_SERVER_EXECUTABLE "${CMAKE_CURRENT_BINARY_DIR}/${TARGET_NAME}")
|
||||
|
||||
set(RUN_TESTS_TARGET run_${TARGET_NAME}_test)
|
||||
configure_file(${CMAKE_SOURCE_DIR}/cmake/${RUN_CLIENT_TESTS_SHELL_TEMPLATE}
|
||||
${CMAKE_CURRENT_BINARY_DIR}/${RUN_TESTS_TARGET}.sh
|
||||
@ONLY)
|
||||
|
||||
add_custom_target(${RUN_TESTS_TARGET}
|
||||
COMMAND ${CMAKE_CURRENT_BINARY_DIR}/${RUN_TESTS_TARGET}.sh
|
||||
DEPENDS ${TARGET_NAME}
|
||||
USES_TERMINAL
|
||||
COMMENT "Running tests: ${TARGET_NAME}")
|
||||
|
||||
get_property(LAST_TEST
|
||||
GLOBAL
|
||||
PROPERTY LAST_JAVA_CLIENT_TEST)
|
||||
add_dependencies(run_all_java_client_test_for_cpp_server ${RUN_TESTS_TARGET})
|
||||
add_dependencies(${LAST_TEST} ${RUN_TESTS_TARGET})
|
||||
set_property(GLOBAL
|
||||
PROPERTY LAST_JAVA_CLIENT_TEST ${RUN_TESTS_TARGET})
|
||||
|
||||
endfunction()
|
25
samples/server/petstore/cpp-restbed/cmake/dependencies.cmake
Normal file
25
samples/server/petstore/cpp-restbed/cmake/dependencies.cmake
Normal file
@ -0,0 +1,25 @@
|
||||
|
||||
|
||||
include(FetchContent)
|
||||
|
||||
## Restbed
|
||||
FetchContent_Declare(
|
||||
restbed
|
||||
GIT_REPOSITORY https://github.com/Corvusoft/restbed
|
||||
GIT_TAG 4.7
|
||||
)
|
||||
|
||||
set(BUILD_TESTS OFF CACHE BOOL "Disable internal restbed tests")
|
||||
set(BUILD_SSL OFF CACHE BOOL "Disable SSL")
|
||||
FetchContent_MakeAvailable(restbed)
|
||||
|
||||
FetchContent_GetProperties(restbed)
|
||||
if(NOT restbed_POPULATED)
|
||||
|
||||
FetchContent_Populate(restbed)
|
||||
add_subdirectory(${restbed_SOURCE_DIR} ${restbed_BINARY_DIR})
|
||||
endif()
|
||||
|
||||
|
||||
## Boost
|
||||
find_package(Boost 1.7.0 COMPONENTS system unit_test_framework REQUIRED)
|
28
samples/server/petstore/cpp-restbed/cmake/run_java_client_tests_template.txt
Executable file
28
samples/server/petstore/cpp-restbed/cmake/run_java_client_tests_template.txt
Executable file
@ -0,0 +1,28 @@
|
||||
#!/bin/bash
|
||||
set -u
|
||||
set -e
|
||||
#set -x
|
||||
|
||||
SCRIPTPATH="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
|
||||
echo "Running ${SCRIPTPATH}"
|
||||
|
||||
echo Running @TEST_SERVER_EXECUTABLE@
|
||||
@TEST_SERVER_EXECUTABLE@ &
|
||||
pid=$!
|
||||
|
||||
|
||||
function kill_test_server()
|
||||
{
|
||||
kill -9 $pid
|
||||
}
|
||||
|
||||
trap kill_test_server EXIT
|
||||
|
||||
echo Running Java client tests
|
||||
cd "@CMAKE_CURRENT_LIST_DIR@/../../java_client"
|
||||
./gradlew --no-daemon clean test --tests "test_@TARGET_NAME@.*" -i
|
||||
|
||||
set +e
|
||||
kill $pid
|
||||
|
||||
echo Done running @TEST_SERVER_EXECUTABLE@
|
29
samples/server/petstore/cpp-restbed/generated/3_0/.gitignore
vendored
Normal file
29
samples/server/petstore/cpp-restbed/generated/3_0/.gitignore
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
# Compiled Object files
|
||||
*.slo
|
||||
*.lo
|
||||
*.o
|
||||
*.obj
|
||||
|
||||
# Precompiled Headers
|
||||
*.gch
|
||||
*.pch
|
||||
|
||||
# Compiled Dynamic libraries
|
||||
*.so
|
||||
*.dylib
|
||||
*.dll
|
||||
|
||||
# Fortran module files
|
||||
*.mod
|
||||
*.smod
|
||||
|
||||
# Compiled Static libraries
|
||||
*.lai
|
||||
*.la
|
||||
*.a
|
||||
*.lib
|
||||
|
||||
# Executables
|
||||
*.exe
|
||||
*.out
|
||||
*.app
|
@ -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
|
@ -0,0 +1,116 @@
|
||||
.gitignore
|
||||
CMakeLists.txt
|
||||
FindRestbedAndBoost.cmake
|
||||
README.md
|
||||
api/AnotherFakeApi.cpp
|
||||
api/AnotherFakeApi.h
|
||||
api/DefaultApi.cpp
|
||||
api/DefaultApi.h
|
||||
api/FakeApi.cpp
|
||||
api/FakeApi.h
|
||||
api/FakeClassnameTags123Api.cpp
|
||||
api/FakeClassnameTags123Api.h
|
||||
api/PetApi.cpp
|
||||
api/PetApi.h
|
||||
api/StoreApi.cpp
|
||||
api/StoreApi.h
|
||||
api/UserApi.cpp
|
||||
api/UserApi.h
|
||||
git_push.sh
|
||||
model/AdditionalPropertiesClass.cpp
|
||||
model/AdditionalPropertiesClass.h
|
||||
model/AllOfWithSingleRef.cpp
|
||||
model/AllOfWithSingleRef.h
|
||||
model/Animal.cpp
|
||||
model/Animal.h
|
||||
model/ApiResponse.cpp
|
||||
model/ApiResponse.h
|
||||
model/ArrayOfArrayOfNumberOnly.cpp
|
||||
model/ArrayOfArrayOfNumberOnly.h
|
||||
model/ArrayOfNumberOnly.cpp
|
||||
model/ArrayOfNumberOnly.h
|
||||
model/ArrayTest.cpp
|
||||
model/ArrayTest.h
|
||||
model/Capitalization.cpp
|
||||
model/Capitalization.h
|
||||
model/Cat.cpp
|
||||
model/Cat.h
|
||||
model/Cat_allOf.cpp
|
||||
model/Cat_allOf.h
|
||||
model/Category.cpp
|
||||
model/Category.h
|
||||
model/ClassModel.cpp
|
||||
model/ClassModel.h
|
||||
model/Client.cpp
|
||||
model/Client.h
|
||||
model/DeprecatedObject.cpp
|
||||
model/DeprecatedObject.h
|
||||
model/Dog.cpp
|
||||
model/Dog.h
|
||||
model/Dog_allOf.cpp
|
||||
model/Dog_allOf.h
|
||||
model/EnumArrays.cpp
|
||||
model/EnumArrays.h
|
||||
model/EnumClass.cpp
|
||||
model/EnumClass.h
|
||||
model/Enum_Test.cpp
|
||||
model/Enum_Test.h
|
||||
model/File.cpp
|
||||
model/File.h
|
||||
model/FileSchemaTestClass.cpp
|
||||
model/FileSchemaTestClass.h
|
||||
model/Foo.cpp
|
||||
model/Foo.h
|
||||
model/Format_test.cpp
|
||||
model/Format_test.h
|
||||
model/HasOnlyReadOnly.cpp
|
||||
model/HasOnlyReadOnly.h
|
||||
model/HealthCheckResult.cpp
|
||||
model/HealthCheckResult.h
|
||||
model/List.cpp
|
||||
model/List.h
|
||||
model/MapTest.cpp
|
||||
model/MapTest.h
|
||||
model/MixedPropertiesAndAdditionalPropertiesClass.cpp
|
||||
model/MixedPropertiesAndAdditionalPropertiesClass.h
|
||||
model/Name.cpp
|
||||
model/Name.h
|
||||
model/NullableClass.cpp
|
||||
model/NullableClass.h
|
||||
model/NumberOnly.cpp
|
||||
model/NumberOnly.h
|
||||
model/ObjectWithDeprecatedFields.cpp
|
||||
model/ObjectWithDeprecatedFields.h
|
||||
model/Order.cpp
|
||||
model/Order.h
|
||||
model/OuterComposite.cpp
|
||||
model/OuterComposite.h
|
||||
model/OuterEnum.cpp
|
||||
model/OuterEnum.h
|
||||
model/OuterEnumDefaultValue.cpp
|
||||
model/OuterEnumDefaultValue.h
|
||||
model/OuterEnumInteger.cpp
|
||||
model/OuterEnumInteger.h
|
||||
model/OuterEnumIntegerDefaultValue.cpp
|
||||
model/OuterEnumIntegerDefaultValue.h
|
||||
model/OuterObjectWithEnumProperty.cpp
|
||||
model/OuterObjectWithEnumProperty.h
|
||||
model/Pet.cpp
|
||||
model/Pet.h
|
||||
model/ReadOnlyFirst.cpp
|
||||
model/ReadOnlyFirst.h
|
||||
model/Return.cpp
|
||||
model/Return.h
|
||||
model/SingleRefType.cpp
|
||||
model/SingleRefType.h
|
||||
model/Tag.cpp
|
||||
model/Tag.h
|
||||
model/User.cpp
|
||||
model/User.h
|
||||
model/_foo_get_default_response.cpp
|
||||
model/_foo_get_default_response.h
|
||||
model/_special_model_name_.cpp
|
||||
model/_special_model_name_.h
|
||||
model/helpers.h
|
||||
model/r_200_response.cpp
|
||||
model/r_200_response.h
|
@ -0,0 +1 @@
|
||||
unset
|
@ -0,0 +1,34 @@
|
||||
set(TARGET_NAME org.openapitools.server.apiStubs)
|
||||
|
||||
# Get generated filenames
|
||||
file(STRINGS "${CMAKE_CURRENT_LIST_DIR}/.openapi-generator/FILES" GENERATED_SOURCES)
|
||||
list(FILTER GENERATED_SOURCES INCLUDE REGEX ".*cpp$")
|
||||
|
||||
set(GENERATED_SOURCES_INCLUDE_DIRS
|
||||
${CMAKE_CURRENT_LIST_DIR}/model
|
||||
${CMAKE_CURRENT_LIST_DIR}/api
|
||||
${CMAKE_CURRENT_LIST_DIR}
|
||||
)
|
||||
|
||||
|
||||
add_library(${TARGET_NAME} SHARED)
|
||||
|
||||
target_sources(${TARGET_NAME}
|
||||
PRIVATE
|
||||
${GENERATED_SOURCES})
|
||||
|
||||
target_include_directories(${TARGET_NAME}
|
||||
PUBLIC
|
||||
${GENERATED_SOURCES_INCLUDE_DIRS}
|
||||
)
|
||||
|
||||
|
||||
target_include_directories(${TARGET_NAME}
|
||||
SYSTEM PUBLIC
|
||||
${restbed_SOURCE_DIR}/source)
|
||||
|
||||
target_link_libraries(${TARGET_NAME}
|
||||
PUBLIC
|
||||
Boost::system
|
||||
restbed-shared
|
||||
-lpthread)
|
@ -0,0 +1,22 @@
|
||||
|
||||
include(FetchContent)
|
||||
|
||||
## Restbed
|
||||
FetchContent_Declare(
|
||||
restbed
|
||||
GIT_REPOSITORY https://github.com/Corvusoft/restbed
|
||||
GIT_TAG 4.7
|
||||
)
|
||||
|
||||
FetchContent_MakeAvailable(restbed)
|
||||
|
||||
FetchContent_GetProperties(restbed)
|
||||
if(NOT restbed_POPULATED)
|
||||
|
||||
FetchContent_Populate(restbed)
|
||||
add_subdirectory(${restbed_SOURCE_DIR} ${restbed_BINARY_DIR})
|
||||
endif()
|
||||
|
||||
|
||||
## Boost
|
||||
find_package(Boost 1.7.0 COMPONENTS system REQUIRED)
|
70
samples/server/petstore/cpp-restbed/generated/3_0/README.md
Normal file
70
samples/server/petstore/cpp-restbed/generated/3_0/README.md
Normal file
@ -0,0 +1,70 @@
|
||||
# REST API Server for OpenAPI Petstore
|
||||
|
||||
## Overview
|
||||
This API Server was generated by the [OpenAPI Generator](https://openapi-generator.tech) project.
|
||||
It uses the [Restbed](https://github.com/Corvusoft/restbed) Framework.
|
||||
|
||||
|
||||
## Installation
|
||||
Put the package under your project folder and import the API stubs.
|
||||
You need to complete the server stub, as it needs to be connected to a source.
|
||||
|
||||
|
||||
## Libraries required
|
||||
boost_system
|
||||
ssl (if Restbed was built with SSL Support)
|
||||
crypto
|
||||
pthread
|
||||
restbed
|
||||
|
||||
|
||||
## Namespaces
|
||||
org.openapitools.server.api
|
||||
org.openapitools.server.model
|
||||
|
||||
|
||||
## Example
|
||||
|
||||
The handler functionality can be implemented in two different ways.
|
||||
Either inherit the given resource and override the handler methods.
|
||||
Or set a handler lambda to a resource.
|
||||
|
||||
This example shows how this can be done with the pet store API.
|
||||
|
||||
```
|
||||
#include "api/StoreApi.h"
|
||||
#include "api/UserApi.h"
|
||||
|
||||
using namespace org::openapitools::server::api;
|
||||
using namespace org::openapitools::server::api::StoreApiResources;
|
||||
using namespace org::openapitools::server::api::UserApiResources;
|
||||
|
||||
/* 1. variant: inherit from the resource and override handler method */
|
||||
class MyStoreApiStoreOrderResource : public StoreOrderResource {
|
||||
public:
|
||||
std::pair<int, Order>
|
||||
handler_POST(Order &order) override {
|
||||
auto ret = Order();
|
||||
/* ... add your implementation here .... */
|
||||
return std::make_pair(200, ret);
|
||||
}
|
||||
};
|
||||
|
||||
int main() {
|
||||
const auto service = std::make_shared<restbed::Service>();
|
||||
|
||||
auto storeApi = StoreApi(service);
|
||||
storeApi.setResource(std::make_shared<MyStoreApiStoreOrderResource>());
|
||||
|
||||
auto userApi = UserApi(service);
|
||||
/* 2. variant: implement handler as lambda */
|
||||
userApi.getUserResource()->handler_POST_func = [](auto& user) {
|
||||
/* ... add your implementation here .... */
|
||||
return 200;};
|
||||
|
||||
const auto settings = std::make_shared<restbed::Settings>();
|
||||
settings->set_port(1236);
|
||||
|
||||
service->start(settings);
|
||||
}
|
||||
```
|
@ -0,0 +1,273 @@
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
|
||||
*
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator unset.
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
|
||||
#include <corvusoft/restbed/byte.hpp>
|
||||
#include <corvusoft/restbed/string.hpp>
|
||||
#include <corvusoft/restbed/settings.hpp>
|
||||
#include <corvusoft/restbed/request.hpp>
|
||||
#include <corvusoft/restbed/uri.hpp>
|
||||
#include <boost/property_tree/ptree.hpp>
|
||||
#include <boost/property_tree/json_parser.hpp>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <boost/algorithm/string.hpp>
|
||||
|
||||
#include "AnotherFakeApi.h"
|
||||
|
||||
namespace org {
|
||||
namespace openapitools {
|
||||
namespace server {
|
||||
namespace api {
|
||||
|
||||
using namespace org::openapitools::server::model;
|
||||
|
||||
namespace {
|
||||
[[maybe_unused]]
|
||||
std::string selectPreferredContentType(const std::vector<std::string>& contentTypes) {
|
||||
if (contentTypes.size() == 0) {
|
||||
return "application/json";
|
||||
}
|
||||
|
||||
if (contentTypes.size() == 1) {
|
||||
return contentTypes.at(0);
|
||||
}
|
||||
|
||||
static const std::array<std::string, 2> preferredTypes = {"json", "xml"};
|
||||
for (const auto& preferredType: preferredTypes) {
|
||||
const auto ret = std::find_if(contentTypes.cbegin(),
|
||||
contentTypes.cend(),
|
||||
[preferredType](const std::string& str) {
|
||||
return str.find(preferredType) != std::string::npos;});
|
||||
if (ret != contentTypes.cend()) {
|
||||
return *ret;
|
||||
}
|
||||
}
|
||||
|
||||
return contentTypes.at(0);
|
||||
}
|
||||
}
|
||||
|
||||
AnotherFakeApiException::AnotherFakeApiException(int status_code, std::string what)
|
||||
: m_status(status_code),
|
||||
m_what(what)
|
||||
{
|
||||
|
||||
}
|
||||
int AnotherFakeApiException::getStatus() const
|
||||
{
|
||||
return m_status;
|
||||
}
|
||||
const char* AnotherFakeApiException::what() const noexcept
|
||||
{
|
||||
return m_what.c_str();
|
||||
}
|
||||
|
||||
|
||||
template<class MODEL_T>
|
||||
MODEL_T extractJsonModelBodyParam(const std::string& bodyContent)
|
||||
{
|
||||
std::stringstream sstream(bodyContent);
|
||||
boost::property_tree::ptree pt;
|
||||
boost::property_tree::json_parser::read_json(sstream, pt);
|
||||
|
||||
auto model = MODEL_T(pt);
|
||||
return model;
|
||||
}
|
||||
|
||||
template<class MODEL_T>
|
||||
std::vector<MODEL_T> extractJsonArrayBodyParam(const std::string& bodyContent)
|
||||
{
|
||||
std::stringstream sstream(bodyContent);
|
||||
boost::property_tree::ptree pt;
|
||||
boost::property_tree::json_parser::read_json(sstream, pt);
|
||||
|
||||
auto arrayRet = std::vector<MODEL_T>();
|
||||
for (const auto& child: pt) {
|
||||
arrayRet.emplace_back(MODEL_T(child.second));
|
||||
}
|
||||
return arrayRet;
|
||||
}
|
||||
|
||||
template <class KEY_T, class VAL_T>
|
||||
std::string convertMapResponse(const std::map<KEY_T, VAL_T>& map)
|
||||
{
|
||||
boost::property_tree::ptree pt;
|
||||
for(const auto &kv: map) {
|
||||
pt.push_back(boost::property_tree::ptree::value_type(
|
||||
boost::lexical_cast<std::string>(kv.first),
|
||||
boost::property_tree::ptree(
|
||||
boost::lexical_cast<std::string>(kv.second))));
|
||||
}
|
||||
std::stringstream sstream;
|
||||
write_json(sstream, pt);
|
||||
std::string result = sstream.str();
|
||||
return result;
|
||||
}
|
||||
|
||||
namespace AnotherFakeApiResources {
|
||||
Another_fakeDummyResource::Another_fakeDummyResource(const std::string& context /* = "/v2" */)
|
||||
{
|
||||
this->set_path(context + "/another-fake/dummy");
|
||||
this->set_method_handler("PATCH",
|
||||
std::bind(&Another_fakeDummyResource::handler_PATCH_internal, this,
|
||||
std::placeholders::_1));
|
||||
}
|
||||
|
||||
std::pair<int, std::string> Another_fakeDummyResource::handleAnotherFakeApiException(const AnotherFakeApiException& e)
|
||||
{
|
||||
return std::make_pair<int, std::string>(e.getStatus(), e.what());
|
||||
}
|
||||
|
||||
std::pair<int, std::string> Another_fakeDummyResource::handleStdException(const std::exception& e)
|
||||
{
|
||||
return std::make_pair<int, std::string>(500, e.what());
|
||||
}
|
||||
|
||||
std::pair<int, std::string> Another_fakeDummyResource::handleUnspecifiedException()
|
||||
{
|
||||
return std::make_pair<int, std::string>(500, "Unknown exception occurred");
|
||||
}
|
||||
|
||||
void Another_fakeDummyResource::setResponseHeader(const std::shared_ptr<restbed::Session>& session, const std::string& header)
|
||||
{
|
||||
session->set_header(header, "");
|
||||
}
|
||||
|
||||
void Another_fakeDummyResource::returnResponse(const std::shared_ptr<restbed::Session>& session, const int status, const std::string& result, std::multimap<std::string, std::string>& responseHeaders)
|
||||
{
|
||||
responseHeaders.insert(std::make_pair("Connection", "close"));
|
||||
session->close(status, result, responseHeaders);
|
||||
}
|
||||
|
||||
void Another_fakeDummyResource::defaultSessionClose(const std::shared_ptr<restbed::Session>& session, const int status, const std::string& result)
|
||||
{
|
||||
session->close(status, result, { {"Connection", "close"} });
|
||||
}
|
||||
|
||||
void Another_fakeDummyResource::handler_PATCH_internal(const std::shared_ptr<restbed::Session> session)
|
||||
{
|
||||
const auto request = session->get_request();
|
||||
// body params or form params here from the body content string
|
||||
std::string bodyContent = extractBodyContent(session);
|
||||
auto client = extractJsonModelBodyParam<Client>(bodyContent);
|
||||
|
||||
int status_code = 500;
|
||||
Client resultObject = Client{};
|
||||
std::string result = "";
|
||||
|
||||
try {
|
||||
std::tie(status_code, resultObject) =
|
||||
handler_PATCH(client);
|
||||
}
|
||||
catch(const AnotherFakeApiException& e) {
|
||||
std::tie(status_code, result) = handleAnotherFakeApiException(e);
|
||||
}
|
||||
catch(const std::exception& e) {
|
||||
std::tie(status_code, result) = handleStdException(e);
|
||||
}
|
||||
catch(...) {
|
||||
std::tie(status_code, result) = handleUnspecifiedException();
|
||||
}
|
||||
|
||||
std::multimap< std::string, std::string > responseHeaders {};
|
||||
static const std::vector<std::string> contentTypes{
|
||||
"application/json",
|
||||
};
|
||||
static const std::string acceptTypes{
|
||||
"application/json, "
|
||||
};
|
||||
|
||||
if (status_code == 200) {
|
||||
responseHeaders.insert(std::make_pair("Content-Type", selectPreferredContentType(contentTypes)));
|
||||
if (!acceptTypes.empty()) {
|
||||
responseHeaders.insert(std::make_pair("Accept", acceptTypes));
|
||||
}
|
||||
|
||||
result = resultObject.toJsonString();
|
||||
returnResponse(session, 200, result.empty() ? "{}" : result, responseHeaders);
|
||||
return;
|
||||
}
|
||||
defaultSessionClose(session, status_code, result);
|
||||
}
|
||||
|
||||
|
||||
std::pair<int, Client> Another_fakeDummyResource::handler_PATCH(
|
||||
Client & client)
|
||||
{
|
||||
return handler_PATCH_func(client);
|
||||
}
|
||||
|
||||
|
||||
std::string Another_fakeDummyResource::extractBodyContent(const std::shared_ptr<restbed::Session>& session) {
|
||||
const auto request = session->get_request();
|
||||
int content_length = request->get_header("Content-Length", 0);
|
||||
std::string bodyContent;
|
||||
session->fetch(content_length,
|
||||
[&bodyContent](const std::shared_ptr<restbed::Session> session,
|
||||
const restbed::Bytes &body) {
|
||||
bodyContent = restbed::String::format(
|
||||
"%.*s\n", (int)body.size(), body.data());
|
||||
});
|
||||
return bodyContent;
|
||||
}
|
||||
|
||||
std::string Another_fakeDummyResource::extractFormParamsFromBody(const std::string& paramName, const std::string& body) {
|
||||
const auto uri = restbed::Uri("urlencoded?" + body, true);
|
||||
const auto params = uri.get_query_parameters();
|
||||
const auto result = params.find(paramName);
|
||||
if (result != params.cend()) {
|
||||
return result->second;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
} /* namespace AnotherFakeApiResources */
|
||||
|
||||
AnotherFakeApi::AnotherFakeApi(std::shared_ptr<restbed::Service> const& restbedService)
|
||||
: m_service(restbedService)
|
||||
{
|
||||
}
|
||||
|
||||
AnotherFakeApi::~AnotherFakeApi() {}
|
||||
|
||||
std::shared_ptr<AnotherFakeApiResources::Another_fakeDummyResource> AnotherFakeApi::getAnother_fakeDummyResource() {
|
||||
if (!m_spAnother_fakeDummyResource) {
|
||||
setResource(std::make_shared<AnotherFakeApiResources::Another_fakeDummyResource>());
|
||||
}
|
||||
return m_spAnother_fakeDummyResource;
|
||||
}
|
||||
void AnotherFakeApi::setResource(std::shared_ptr<AnotherFakeApiResources::Another_fakeDummyResource> resource) {
|
||||
m_spAnother_fakeDummyResource = resource;
|
||||
m_service->publish(m_spAnother_fakeDummyResource);
|
||||
}
|
||||
void AnotherFakeApi::setAnotherFakeApiAnother_fakeDummyResource(std::shared_ptr<AnotherFakeApiResources::Another_fakeDummyResource> spAnother_fakeDummyResource) {
|
||||
m_spAnother_fakeDummyResource = spAnother_fakeDummyResource;
|
||||
m_service->publish(m_spAnother_fakeDummyResource);
|
||||
}
|
||||
|
||||
|
||||
void AnotherFakeApi::publishDefaultResources() {
|
||||
if (!m_spAnother_fakeDummyResource) {
|
||||
setResource(std::make_shared<AnotherFakeApiResources::Another_fakeDummyResource>());
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<restbed::Service> AnotherFakeApi::service() {
|
||||
return m_service;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,159 @@
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
|
||||
*
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator unset.
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
/*
|
||||
* AnotherFakeApi.h
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef AnotherFakeApi_H_
|
||||
#define AnotherFakeApi_H_
|
||||
|
||||
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
#include <exception>
|
||||
#include <functional>
|
||||
|
||||
#include <corvusoft/restbed/session.hpp>
|
||||
#include <corvusoft/restbed/resource.hpp>
|
||||
#include <corvusoft/restbed/request.hpp>
|
||||
#include <corvusoft/restbed/service.hpp>
|
||||
#include <corvusoft/restbed/settings.hpp>
|
||||
|
||||
#include "Client.h"
|
||||
|
||||
namespace org {
|
||||
namespace openapitools {
|
||||
namespace server {
|
||||
namespace api {
|
||||
|
||||
using namespace org::openapitools::server::model;
|
||||
|
||||
///
|
||||
/// Exception to flag problems in the handlers
|
||||
///
|
||||
class AnotherFakeApiException: public std::exception
|
||||
{
|
||||
public:
|
||||
AnotherFakeApiException(int status_code, std::string what);
|
||||
|
||||
int getStatus() const;
|
||||
const char* what() const noexcept override;
|
||||
|
||||
private:
|
||||
int m_status;
|
||||
std::string m_what;
|
||||
};
|
||||
|
||||
namespace AnotherFakeApiResources {
|
||||
/// <summary>
|
||||
/// To test special tags
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// To test special tags and operation ID starting with number
|
||||
/// </remarks>
|
||||
class Another_fakeDummyResource: public restbed::Resource
|
||||
{
|
||||
public:
|
||||
Another_fakeDummyResource(const std::string& context = "/v2");
|
||||
virtual ~Another_fakeDummyResource() = default;
|
||||
|
||||
Another_fakeDummyResource(
|
||||
const Another_fakeDummyResource& other) = default; // copy constructor
|
||||
Another_fakeDummyResource(Another_fakeDummyResource&& other) noexcept = default; // move constructor
|
||||
|
||||
Another_fakeDummyResource& operator=(const Another_fakeDummyResource& other) = default; // copy assignment
|
||||
Another_fakeDummyResource& operator=(Another_fakeDummyResource&& other) noexcept = default; // move assignment
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
// Set these to implement the server functionality //
|
||||
/////////////////////////////////////////////////////
|
||||
std::function<std::pair<int, Client>(
|
||||
Client & client)> handler_PATCH_func =
|
||||
[](Client &) -> std::pair<int, Client>
|
||||
{ throw AnotherFakeApiException(501, "Not implemented"); };
|
||||
|
||||
|
||||
protected:
|
||||
//////////////////////////////////////////////////////////
|
||||
// As an alternative to setting the `std::function`s //
|
||||
// override these to implement the server functionality //
|
||||
//////////////////////////////////////////////////////////
|
||||
|
||||
virtual std::pair<int, Client> handler_PATCH(
|
||||
Client & client);
|
||||
|
||||
|
||||
protected:
|
||||
//////////////////////////////////////
|
||||
// Override these for customization //
|
||||
//////////////////////////////////////
|
||||
|
||||
virtual std::string extractBodyContent(const std::shared_ptr<restbed::Session>& session);
|
||||
virtual std::string extractFormParamsFromBody(const std::string& paramName, const std::string& body);
|
||||
|
||||
virtual std::pair<int, std::string> handleAnotherFakeApiException(const AnotherFakeApiException& e);
|
||||
virtual std::pair<int, std::string> handleStdException(const std::exception& e);
|
||||
virtual std::pair<int, std::string> handleUnspecifiedException();
|
||||
|
||||
virtual void setResponseHeader(const std::shared_ptr<restbed::Session>& session,
|
||||
const std::string& header);
|
||||
|
||||
virtual void returnResponse(const std::shared_ptr<restbed::Session>& session,
|
||||
const int status, const std::string& result, std::multimap<std::string, std::string>& contentType);
|
||||
virtual void defaultSessionClose(const std::shared_ptr<restbed::Session>& session,
|
||||
const int status, const std::string& result);
|
||||
|
||||
private:
|
||||
void handler_PATCH_internal(const std::shared_ptr<restbed::Session> session);
|
||||
};
|
||||
|
||||
} /* namespace AnotherFakeApiResources */
|
||||
|
||||
using AnotherFakeApiAnother_fakeDummyResource [[deprecated]] = AnotherFakeApiResources::Another_fakeDummyResource;
|
||||
|
||||
//
|
||||
// The restbed service to actually implement the REST server
|
||||
//
|
||||
class AnotherFakeApi
|
||||
{
|
||||
public:
|
||||
explicit AnotherFakeApi(std::shared_ptr<restbed::Service> const& restbedService);
|
||||
virtual ~AnotherFakeApi();
|
||||
|
||||
std::shared_ptr<AnotherFakeApiResources::Another_fakeDummyResource> getAnother_fakeDummyResource();
|
||||
|
||||
void setResource(std::shared_ptr<AnotherFakeApiResources::Another_fakeDummyResource> resource);
|
||||
[[deprecated("use setResource()")]]
|
||||
virtual void setAnotherFakeApiAnother_fakeDummyResource(std::shared_ptr<AnotherFakeApiResources::Another_fakeDummyResource> spAnotherFakeApiAnother_fakeDummyResource);
|
||||
|
||||
virtual void publishDefaultResources();
|
||||
|
||||
virtual std::shared_ptr<restbed::Service> service();
|
||||
|
||||
protected:
|
||||
std::shared_ptr<AnotherFakeApiResources::Another_fakeDummyResource> m_spAnother_fakeDummyResource;
|
||||
|
||||
private:
|
||||
std::shared_ptr<restbed::Service> m_service;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* AnotherFakeApi_H_ */
|
||||
|
@ -0,0 +1,267 @@
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
|
||||
*
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator unset.
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
|
||||
#include <corvusoft/restbed/byte.hpp>
|
||||
#include <corvusoft/restbed/string.hpp>
|
||||
#include <corvusoft/restbed/settings.hpp>
|
||||
#include <corvusoft/restbed/request.hpp>
|
||||
#include <corvusoft/restbed/uri.hpp>
|
||||
#include <boost/property_tree/ptree.hpp>
|
||||
#include <boost/property_tree/json_parser.hpp>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <boost/algorithm/string.hpp>
|
||||
|
||||
#include "DefaultApi.h"
|
||||
|
||||
namespace org {
|
||||
namespace openapitools {
|
||||
namespace server {
|
||||
namespace api {
|
||||
|
||||
using namespace org::openapitools::server::model;
|
||||
|
||||
namespace {
|
||||
[[maybe_unused]]
|
||||
std::string selectPreferredContentType(const std::vector<std::string>& contentTypes) {
|
||||
if (contentTypes.size() == 0) {
|
||||
return "application/json";
|
||||
}
|
||||
|
||||
if (contentTypes.size() == 1) {
|
||||
return contentTypes.at(0);
|
||||
}
|
||||
|
||||
static const std::array<std::string, 2> preferredTypes = {"json", "xml"};
|
||||
for (const auto& preferredType: preferredTypes) {
|
||||
const auto ret = std::find_if(contentTypes.cbegin(),
|
||||
contentTypes.cend(),
|
||||
[preferredType](const std::string& str) {
|
||||
return str.find(preferredType) != std::string::npos;});
|
||||
if (ret != contentTypes.cend()) {
|
||||
return *ret;
|
||||
}
|
||||
}
|
||||
|
||||
return contentTypes.at(0);
|
||||
}
|
||||
}
|
||||
|
||||
DefaultApiException::DefaultApiException(int status_code, std::string what)
|
||||
: m_status(status_code),
|
||||
m_what(what)
|
||||
{
|
||||
|
||||
}
|
||||
int DefaultApiException::getStatus() const
|
||||
{
|
||||
return m_status;
|
||||
}
|
||||
const char* DefaultApiException::what() const noexcept
|
||||
{
|
||||
return m_what.c_str();
|
||||
}
|
||||
|
||||
|
||||
template<class MODEL_T>
|
||||
MODEL_T extractJsonModelBodyParam(const std::string& bodyContent)
|
||||
{
|
||||
std::stringstream sstream(bodyContent);
|
||||
boost::property_tree::ptree pt;
|
||||
boost::property_tree::json_parser::read_json(sstream, pt);
|
||||
|
||||
auto model = MODEL_T(pt);
|
||||
return model;
|
||||
}
|
||||
|
||||
template<class MODEL_T>
|
||||
std::vector<MODEL_T> extractJsonArrayBodyParam(const std::string& bodyContent)
|
||||
{
|
||||
std::stringstream sstream(bodyContent);
|
||||
boost::property_tree::ptree pt;
|
||||
boost::property_tree::json_parser::read_json(sstream, pt);
|
||||
|
||||
auto arrayRet = std::vector<MODEL_T>();
|
||||
for (const auto& child: pt) {
|
||||
arrayRet.emplace_back(MODEL_T(child.second));
|
||||
}
|
||||
return arrayRet;
|
||||
}
|
||||
|
||||
template <class KEY_T, class VAL_T>
|
||||
std::string convertMapResponse(const std::map<KEY_T, VAL_T>& map)
|
||||
{
|
||||
boost::property_tree::ptree pt;
|
||||
for(const auto &kv: map) {
|
||||
pt.push_back(boost::property_tree::ptree::value_type(
|
||||
boost::lexical_cast<std::string>(kv.first),
|
||||
boost::property_tree::ptree(
|
||||
boost::lexical_cast<std::string>(kv.second))));
|
||||
}
|
||||
std::stringstream sstream;
|
||||
write_json(sstream, pt);
|
||||
std::string result = sstream.str();
|
||||
return result;
|
||||
}
|
||||
|
||||
namespace DefaultApiResources {
|
||||
FooResource::FooResource(const std::string& context /* = "/v2" */)
|
||||
{
|
||||
this->set_path(context + "/foo");
|
||||
this->set_method_handler("GET",
|
||||
std::bind(&FooResource::handler_GET_internal, this,
|
||||
std::placeholders::_1));
|
||||
}
|
||||
|
||||
std::pair<int, std::string> FooResource::handleDefaultApiException(const DefaultApiException& e)
|
||||
{
|
||||
return std::make_pair<int, std::string>(e.getStatus(), e.what());
|
||||
}
|
||||
|
||||
std::pair<int, std::string> FooResource::handleStdException(const std::exception& e)
|
||||
{
|
||||
return std::make_pair<int, std::string>(500, e.what());
|
||||
}
|
||||
|
||||
std::pair<int, std::string> FooResource::handleUnspecifiedException()
|
||||
{
|
||||
return std::make_pair<int, std::string>(500, "Unknown exception occurred");
|
||||
}
|
||||
|
||||
void FooResource::setResponseHeader(const std::shared_ptr<restbed::Session>& session, const std::string& header)
|
||||
{
|
||||
session->set_header(header, "");
|
||||
}
|
||||
|
||||
void FooResource::returnResponse(const std::shared_ptr<restbed::Session>& session, const int status, const std::string& result, std::multimap<std::string, std::string>& responseHeaders)
|
||||
{
|
||||
responseHeaders.insert(std::make_pair("Connection", "close"));
|
||||
session->close(status, result, responseHeaders);
|
||||
}
|
||||
|
||||
void FooResource::defaultSessionClose(const std::shared_ptr<restbed::Session>& session, const int status, const std::string& result)
|
||||
{
|
||||
session->close(status, result, { {"Connection", "close"} });
|
||||
}
|
||||
|
||||
void FooResource::handler_GET_internal(const std::shared_ptr<restbed::Session> session)
|
||||
{
|
||||
const auto request = session->get_request();
|
||||
|
||||
int status_code = 500;
|
||||
_foo_get_default_response resultObject = _foo_get_default_response{};
|
||||
std::string result = "";
|
||||
|
||||
try {
|
||||
std::tie(status_code, resultObject) =
|
||||
handler_GET();
|
||||
}
|
||||
catch(const DefaultApiException& e) {
|
||||
std::tie(status_code, result) = handleDefaultApiException(e);
|
||||
}
|
||||
catch(const std::exception& e) {
|
||||
std::tie(status_code, result) = handleStdException(e);
|
||||
}
|
||||
catch(...) {
|
||||
std::tie(status_code, result) = handleUnspecifiedException();
|
||||
}
|
||||
|
||||
std::multimap< std::string, std::string > responseHeaders {};
|
||||
static const std::vector<std::string> contentTypes{
|
||||
"application/json",
|
||||
};
|
||||
static const std::string acceptTypes{
|
||||
};
|
||||
|
||||
if (status_code == 0) {
|
||||
responseHeaders.insert(std::make_pair("Content-Type", "text/plain"));
|
||||
result = "response";
|
||||
|
||||
result = resultObject.toJsonString();
|
||||
returnResponse(session, 0, result.empty() ? "{}" : result, responseHeaders);
|
||||
return;
|
||||
}
|
||||
defaultSessionClose(session, status_code, result);
|
||||
}
|
||||
|
||||
|
||||
std::pair<int, _foo_get_default_response> FooResource::handler_GET(
|
||||
)
|
||||
{
|
||||
return handler_GET_func();
|
||||
}
|
||||
|
||||
|
||||
std::string FooResource::extractBodyContent(const std::shared_ptr<restbed::Session>& session) {
|
||||
const auto request = session->get_request();
|
||||
int content_length = request->get_header("Content-Length", 0);
|
||||
std::string bodyContent;
|
||||
session->fetch(content_length,
|
||||
[&bodyContent](const std::shared_ptr<restbed::Session> session,
|
||||
const restbed::Bytes &body) {
|
||||
bodyContent = restbed::String::format(
|
||||
"%.*s\n", (int)body.size(), body.data());
|
||||
});
|
||||
return bodyContent;
|
||||
}
|
||||
|
||||
std::string FooResource::extractFormParamsFromBody(const std::string& paramName, const std::string& body) {
|
||||
const auto uri = restbed::Uri("urlencoded?" + body, true);
|
||||
const auto params = uri.get_query_parameters();
|
||||
const auto result = params.find(paramName);
|
||||
if (result != params.cend()) {
|
||||
return result->second;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
} /* namespace DefaultApiResources */
|
||||
|
||||
DefaultApi::DefaultApi(std::shared_ptr<restbed::Service> const& restbedService)
|
||||
: m_service(restbedService)
|
||||
{
|
||||
}
|
||||
|
||||
DefaultApi::~DefaultApi() {}
|
||||
|
||||
std::shared_ptr<DefaultApiResources::FooResource> DefaultApi::getFooResource() {
|
||||
if (!m_spFooResource) {
|
||||
setResource(std::make_shared<DefaultApiResources::FooResource>());
|
||||
}
|
||||
return m_spFooResource;
|
||||
}
|
||||
void DefaultApi::setResource(std::shared_ptr<DefaultApiResources::FooResource> resource) {
|
||||
m_spFooResource = resource;
|
||||
m_service->publish(m_spFooResource);
|
||||
}
|
||||
void DefaultApi::setDefaultApiFooResource(std::shared_ptr<DefaultApiResources::FooResource> spFooResource) {
|
||||
m_spFooResource = spFooResource;
|
||||
m_service->publish(m_spFooResource);
|
||||
}
|
||||
|
||||
|
||||
void DefaultApi::publishDefaultResources() {
|
||||
if (!m_spFooResource) {
|
||||
setResource(std::make_shared<DefaultApiResources::FooResource>());
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<restbed::Service> DefaultApi::service() {
|
||||
return m_service;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,159 @@
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
|
||||
*
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator unset.
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
/*
|
||||
* DefaultApi.h
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef DefaultApi_H_
|
||||
#define DefaultApi_H_
|
||||
|
||||
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
#include <exception>
|
||||
#include <functional>
|
||||
|
||||
#include <corvusoft/restbed/session.hpp>
|
||||
#include <corvusoft/restbed/resource.hpp>
|
||||
#include <corvusoft/restbed/request.hpp>
|
||||
#include <corvusoft/restbed/service.hpp>
|
||||
#include <corvusoft/restbed/settings.hpp>
|
||||
|
||||
#include "_foo_get_default_response.h"
|
||||
|
||||
namespace org {
|
||||
namespace openapitools {
|
||||
namespace server {
|
||||
namespace api {
|
||||
|
||||
using namespace org::openapitools::server::model;
|
||||
|
||||
///
|
||||
/// Exception to flag problems in the handlers
|
||||
///
|
||||
class DefaultApiException: public std::exception
|
||||
{
|
||||
public:
|
||||
DefaultApiException(int status_code, std::string what);
|
||||
|
||||
int getStatus() const;
|
||||
const char* what() const noexcept override;
|
||||
|
||||
private:
|
||||
int m_status;
|
||||
std::string m_what;
|
||||
};
|
||||
|
||||
namespace DefaultApiResources {
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
///
|
||||
/// </remarks>
|
||||
class FooResource: public restbed::Resource
|
||||
{
|
||||
public:
|
||||
FooResource(const std::string& context = "/v2");
|
||||
virtual ~FooResource() = default;
|
||||
|
||||
FooResource(
|
||||
const FooResource& other) = default; // copy constructor
|
||||
FooResource(FooResource&& other) noexcept = default; // move constructor
|
||||
|
||||
FooResource& operator=(const FooResource& other) = default; // copy assignment
|
||||
FooResource& operator=(FooResource&& other) noexcept = default; // move assignment
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
// Set these to implement the server functionality //
|
||||
/////////////////////////////////////////////////////
|
||||
std::function<std::pair<int, _foo_get_default_response>(
|
||||
)> handler_GET_func =
|
||||
[]() -> std::pair<int, _foo_get_default_response>
|
||||
{ throw DefaultApiException(501, "Not implemented"); };
|
||||
|
||||
|
||||
protected:
|
||||
//////////////////////////////////////////////////////////
|
||||
// As an alternative to setting the `std::function`s //
|
||||
// override these to implement the server functionality //
|
||||
//////////////////////////////////////////////////////////
|
||||
|
||||
virtual std::pair<int, _foo_get_default_response> handler_GET(
|
||||
);
|
||||
|
||||
|
||||
protected:
|
||||
//////////////////////////////////////
|
||||
// Override these for customization //
|
||||
//////////////////////////////////////
|
||||
|
||||
virtual std::string extractBodyContent(const std::shared_ptr<restbed::Session>& session);
|
||||
virtual std::string extractFormParamsFromBody(const std::string& paramName, const std::string& body);
|
||||
|
||||
virtual std::pair<int, std::string> handleDefaultApiException(const DefaultApiException& e);
|
||||
virtual std::pair<int, std::string> handleStdException(const std::exception& e);
|
||||
virtual std::pair<int, std::string> handleUnspecifiedException();
|
||||
|
||||
virtual void setResponseHeader(const std::shared_ptr<restbed::Session>& session,
|
||||
const std::string& header);
|
||||
|
||||
virtual void returnResponse(const std::shared_ptr<restbed::Session>& session,
|
||||
const int status, const std::string& result, std::multimap<std::string, std::string>& contentType);
|
||||
virtual void defaultSessionClose(const std::shared_ptr<restbed::Session>& session,
|
||||
const int status, const std::string& result);
|
||||
|
||||
private:
|
||||
void handler_GET_internal(const std::shared_ptr<restbed::Session> session);
|
||||
};
|
||||
|
||||
} /* namespace DefaultApiResources */
|
||||
|
||||
using DefaultApiFooResource [[deprecated]] = DefaultApiResources::FooResource;
|
||||
|
||||
//
|
||||
// The restbed service to actually implement the REST server
|
||||
//
|
||||
class DefaultApi
|
||||
{
|
||||
public:
|
||||
explicit DefaultApi(std::shared_ptr<restbed::Service> const& restbedService);
|
||||
virtual ~DefaultApi();
|
||||
|
||||
std::shared_ptr<DefaultApiResources::FooResource> getFooResource();
|
||||
|
||||
void setResource(std::shared_ptr<DefaultApiResources::FooResource> resource);
|
||||
[[deprecated("use setResource()")]]
|
||||
virtual void setDefaultApiFooResource(std::shared_ptr<DefaultApiResources::FooResource> spDefaultApiFooResource);
|
||||
|
||||
virtual void publishDefaultResources();
|
||||
|
||||
virtual std::shared_ptr<restbed::Service> service();
|
||||
|
||||
protected:
|
||||
std::shared_ptr<DefaultApiResources::FooResource> m_spFooResource;
|
||||
|
||||
private:
|
||||
std::shared_ptr<restbed::Service> m_service;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* DefaultApi_H_ */
|
||||
|
2207
samples/server/petstore/cpp-restbed/generated/3_0/api/FakeApi.cpp
Normal file
2207
samples/server/petstore/cpp-restbed/generated/3_0/api/FakeApi.cpp
Normal file
File diff suppressed because it is too large
Load Diff
1076
samples/server/petstore/cpp-restbed/generated/3_0/api/FakeApi.h
Normal file
1076
samples/server/petstore/cpp-restbed/generated/3_0/api/FakeApi.h
Normal file
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,273 @@
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
|
||||
*
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator unset.
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
|
||||
#include <corvusoft/restbed/byte.hpp>
|
||||
#include <corvusoft/restbed/string.hpp>
|
||||
#include <corvusoft/restbed/settings.hpp>
|
||||
#include <corvusoft/restbed/request.hpp>
|
||||
#include <corvusoft/restbed/uri.hpp>
|
||||
#include <boost/property_tree/ptree.hpp>
|
||||
#include <boost/property_tree/json_parser.hpp>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <boost/algorithm/string.hpp>
|
||||
|
||||
#include "FakeClassnameTags123Api.h"
|
||||
|
||||
namespace org {
|
||||
namespace openapitools {
|
||||
namespace server {
|
||||
namespace api {
|
||||
|
||||
using namespace org::openapitools::server::model;
|
||||
|
||||
namespace {
|
||||
[[maybe_unused]]
|
||||
std::string selectPreferredContentType(const std::vector<std::string>& contentTypes) {
|
||||
if (contentTypes.size() == 0) {
|
||||
return "application/json";
|
||||
}
|
||||
|
||||
if (contentTypes.size() == 1) {
|
||||
return contentTypes.at(0);
|
||||
}
|
||||
|
||||
static const std::array<std::string, 2> preferredTypes = {"json", "xml"};
|
||||
for (const auto& preferredType: preferredTypes) {
|
||||
const auto ret = std::find_if(contentTypes.cbegin(),
|
||||
contentTypes.cend(),
|
||||
[preferredType](const std::string& str) {
|
||||
return str.find(preferredType) != std::string::npos;});
|
||||
if (ret != contentTypes.cend()) {
|
||||
return *ret;
|
||||
}
|
||||
}
|
||||
|
||||
return contentTypes.at(0);
|
||||
}
|
||||
}
|
||||
|
||||
FakeClassnameTags123ApiException::FakeClassnameTags123ApiException(int status_code, std::string what)
|
||||
: m_status(status_code),
|
||||
m_what(what)
|
||||
{
|
||||
|
||||
}
|
||||
int FakeClassnameTags123ApiException::getStatus() const
|
||||
{
|
||||
return m_status;
|
||||
}
|
||||
const char* FakeClassnameTags123ApiException::what() const noexcept
|
||||
{
|
||||
return m_what.c_str();
|
||||
}
|
||||
|
||||
|
||||
template<class MODEL_T>
|
||||
MODEL_T extractJsonModelBodyParam(const std::string& bodyContent)
|
||||
{
|
||||
std::stringstream sstream(bodyContent);
|
||||
boost::property_tree::ptree pt;
|
||||
boost::property_tree::json_parser::read_json(sstream, pt);
|
||||
|
||||
auto model = MODEL_T(pt);
|
||||
return model;
|
||||
}
|
||||
|
||||
template<class MODEL_T>
|
||||
std::vector<MODEL_T> extractJsonArrayBodyParam(const std::string& bodyContent)
|
||||
{
|
||||
std::stringstream sstream(bodyContent);
|
||||
boost::property_tree::ptree pt;
|
||||
boost::property_tree::json_parser::read_json(sstream, pt);
|
||||
|
||||
auto arrayRet = std::vector<MODEL_T>();
|
||||
for (const auto& child: pt) {
|
||||
arrayRet.emplace_back(MODEL_T(child.second));
|
||||
}
|
||||
return arrayRet;
|
||||
}
|
||||
|
||||
template <class KEY_T, class VAL_T>
|
||||
std::string convertMapResponse(const std::map<KEY_T, VAL_T>& map)
|
||||
{
|
||||
boost::property_tree::ptree pt;
|
||||
for(const auto &kv: map) {
|
||||
pt.push_back(boost::property_tree::ptree::value_type(
|
||||
boost::lexical_cast<std::string>(kv.first),
|
||||
boost::property_tree::ptree(
|
||||
boost::lexical_cast<std::string>(kv.second))));
|
||||
}
|
||||
std::stringstream sstream;
|
||||
write_json(sstream, pt);
|
||||
std::string result = sstream.str();
|
||||
return result;
|
||||
}
|
||||
|
||||
namespace FakeClassnameTags123ApiResources {
|
||||
Fake_classname_testResource::Fake_classname_testResource(const std::string& context /* = "/v2" */)
|
||||
{
|
||||
this->set_path(context + "/fake_classname_test");
|
||||
this->set_method_handler("PATCH",
|
||||
std::bind(&Fake_classname_testResource::handler_PATCH_internal, this,
|
||||
std::placeholders::_1));
|
||||
}
|
||||
|
||||
std::pair<int, std::string> Fake_classname_testResource::handleFakeClassnameTags123ApiException(const FakeClassnameTags123ApiException& e)
|
||||
{
|
||||
return std::make_pair<int, std::string>(e.getStatus(), e.what());
|
||||
}
|
||||
|
||||
std::pair<int, std::string> Fake_classname_testResource::handleStdException(const std::exception& e)
|
||||
{
|
||||
return std::make_pair<int, std::string>(500, e.what());
|
||||
}
|
||||
|
||||
std::pair<int, std::string> Fake_classname_testResource::handleUnspecifiedException()
|
||||
{
|
||||
return std::make_pair<int, std::string>(500, "Unknown exception occurred");
|
||||
}
|
||||
|
||||
void Fake_classname_testResource::setResponseHeader(const std::shared_ptr<restbed::Session>& session, const std::string& header)
|
||||
{
|
||||
session->set_header(header, "");
|
||||
}
|
||||
|
||||
void Fake_classname_testResource::returnResponse(const std::shared_ptr<restbed::Session>& session, const int status, const std::string& result, std::multimap<std::string, std::string>& responseHeaders)
|
||||
{
|
||||
responseHeaders.insert(std::make_pair("Connection", "close"));
|
||||
session->close(status, result, responseHeaders);
|
||||
}
|
||||
|
||||
void Fake_classname_testResource::defaultSessionClose(const std::shared_ptr<restbed::Session>& session, const int status, const std::string& result)
|
||||
{
|
||||
session->close(status, result, { {"Connection", "close"} });
|
||||
}
|
||||
|
||||
void Fake_classname_testResource::handler_PATCH_internal(const std::shared_ptr<restbed::Session> session)
|
||||
{
|
||||
const auto request = session->get_request();
|
||||
// body params or form params here from the body content string
|
||||
std::string bodyContent = extractBodyContent(session);
|
||||
auto client = extractJsonModelBodyParam<Client>(bodyContent);
|
||||
|
||||
int status_code = 500;
|
||||
Client resultObject = Client{};
|
||||
std::string result = "";
|
||||
|
||||
try {
|
||||
std::tie(status_code, resultObject) =
|
||||
handler_PATCH(client);
|
||||
}
|
||||
catch(const FakeClassnameTags123ApiException& e) {
|
||||
std::tie(status_code, result) = handleFakeClassnameTags123ApiException(e);
|
||||
}
|
||||
catch(const std::exception& e) {
|
||||
std::tie(status_code, result) = handleStdException(e);
|
||||
}
|
||||
catch(...) {
|
||||
std::tie(status_code, result) = handleUnspecifiedException();
|
||||
}
|
||||
|
||||
std::multimap< std::string, std::string > responseHeaders {};
|
||||
static const std::vector<std::string> contentTypes{
|
||||
"application/json",
|
||||
};
|
||||
static const std::string acceptTypes{
|
||||
"application/json, "
|
||||
};
|
||||
|
||||
if (status_code == 200) {
|
||||
responseHeaders.insert(std::make_pair("Content-Type", selectPreferredContentType(contentTypes)));
|
||||
if (!acceptTypes.empty()) {
|
||||
responseHeaders.insert(std::make_pair("Accept", acceptTypes));
|
||||
}
|
||||
|
||||
result = resultObject.toJsonString();
|
||||
returnResponse(session, 200, result.empty() ? "{}" : result, responseHeaders);
|
||||
return;
|
||||
}
|
||||
defaultSessionClose(session, status_code, result);
|
||||
}
|
||||
|
||||
|
||||
std::pair<int, Client> Fake_classname_testResource::handler_PATCH(
|
||||
Client & client)
|
||||
{
|
||||
return handler_PATCH_func(client);
|
||||
}
|
||||
|
||||
|
||||
std::string Fake_classname_testResource::extractBodyContent(const std::shared_ptr<restbed::Session>& session) {
|
||||
const auto request = session->get_request();
|
||||
int content_length = request->get_header("Content-Length", 0);
|
||||
std::string bodyContent;
|
||||
session->fetch(content_length,
|
||||
[&bodyContent](const std::shared_ptr<restbed::Session> session,
|
||||
const restbed::Bytes &body) {
|
||||
bodyContent = restbed::String::format(
|
||||
"%.*s\n", (int)body.size(), body.data());
|
||||
});
|
||||
return bodyContent;
|
||||
}
|
||||
|
||||
std::string Fake_classname_testResource::extractFormParamsFromBody(const std::string& paramName, const std::string& body) {
|
||||
const auto uri = restbed::Uri("urlencoded?" + body, true);
|
||||
const auto params = uri.get_query_parameters();
|
||||
const auto result = params.find(paramName);
|
||||
if (result != params.cend()) {
|
||||
return result->second;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
} /* namespace FakeClassnameTags123ApiResources */
|
||||
|
||||
FakeClassnameTags123Api::FakeClassnameTags123Api(std::shared_ptr<restbed::Service> const& restbedService)
|
||||
: m_service(restbedService)
|
||||
{
|
||||
}
|
||||
|
||||
FakeClassnameTags123Api::~FakeClassnameTags123Api() {}
|
||||
|
||||
std::shared_ptr<FakeClassnameTags123ApiResources::Fake_classname_testResource> FakeClassnameTags123Api::getFake_classname_testResource() {
|
||||
if (!m_spFake_classname_testResource) {
|
||||
setResource(std::make_shared<FakeClassnameTags123ApiResources::Fake_classname_testResource>());
|
||||
}
|
||||
return m_spFake_classname_testResource;
|
||||
}
|
||||
void FakeClassnameTags123Api::setResource(std::shared_ptr<FakeClassnameTags123ApiResources::Fake_classname_testResource> resource) {
|
||||
m_spFake_classname_testResource = resource;
|
||||
m_service->publish(m_spFake_classname_testResource);
|
||||
}
|
||||
void FakeClassnameTags123Api::setFakeClassnameTags123ApiFake_classname_testResource(std::shared_ptr<FakeClassnameTags123ApiResources::Fake_classname_testResource> spFake_classname_testResource) {
|
||||
m_spFake_classname_testResource = spFake_classname_testResource;
|
||||
m_service->publish(m_spFake_classname_testResource);
|
||||
}
|
||||
|
||||
|
||||
void FakeClassnameTags123Api::publishDefaultResources() {
|
||||
if (!m_spFake_classname_testResource) {
|
||||
setResource(std::make_shared<FakeClassnameTags123ApiResources::Fake_classname_testResource>());
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<restbed::Service> FakeClassnameTags123Api::service() {
|
||||
return m_service;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,159 @@
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
|
||||
*
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator unset.
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
/*
|
||||
* FakeClassnameTags123Api.h
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef FakeClassnameTags123Api_H_
|
||||
#define FakeClassnameTags123Api_H_
|
||||
|
||||
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
#include <exception>
|
||||
#include <functional>
|
||||
|
||||
#include <corvusoft/restbed/session.hpp>
|
||||
#include <corvusoft/restbed/resource.hpp>
|
||||
#include <corvusoft/restbed/request.hpp>
|
||||
#include <corvusoft/restbed/service.hpp>
|
||||
#include <corvusoft/restbed/settings.hpp>
|
||||
|
||||
#include "Client.h"
|
||||
|
||||
namespace org {
|
||||
namespace openapitools {
|
||||
namespace server {
|
||||
namespace api {
|
||||
|
||||
using namespace org::openapitools::server::model;
|
||||
|
||||
///
|
||||
/// Exception to flag problems in the handlers
|
||||
///
|
||||
class FakeClassnameTags123ApiException: public std::exception
|
||||
{
|
||||
public:
|
||||
FakeClassnameTags123ApiException(int status_code, std::string what);
|
||||
|
||||
int getStatus() const;
|
||||
const char* what() const noexcept override;
|
||||
|
||||
private:
|
||||
int m_status;
|
||||
std::string m_what;
|
||||
};
|
||||
|
||||
namespace FakeClassnameTags123ApiResources {
|
||||
/// <summary>
|
||||
/// To test class name in snake case
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// To test class name in snake case
|
||||
/// </remarks>
|
||||
class Fake_classname_testResource: public restbed::Resource
|
||||
{
|
||||
public:
|
||||
Fake_classname_testResource(const std::string& context = "/v2");
|
||||
virtual ~Fake_classname_testResource() = default;
|
||||
|
||||
Fake_classname_testResource(
|
||||
const Fake_classname_testResource& other) = default; // copy constructor
|
||||
Fake_classname_testResource(Fake_classname_testResource&& other) noexcept = default; // move constructor
|
||||
|
||||
Fake_classname_testResource& operator=(const Fake_classname_testResource& other) = default; // copy assignment
|
||||
Fake_classname_testResource& operator=(Fake_classname_testResource&& other) noexcept = default; // move assignment
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
// Set these to implement the server functionality //
|
||||
/////////////////////////////////////////////////////
|
||||
std::function<std::pair<int, Client>(
|
||||
Client & client)> handler_PATCH_func =
|
||||
[](Client &) -> std::pair<int, Client>
|
||||
{ throw FakeClassnameTags123ApiException(501, "Not implemented"); };
|
||||
|
||||
|
||||
protected:
|
||||
//////////////////////////////////////////////////////////
|
||||
// As an alternative to setting the `std::function`s //
|
||||
// override these to implement the server functionality //
|
||||
//////////////////////////////////////////////////////////
|
||||
|
||||
virtual std::pair<int, Client> handler_PATCH(
|
||||
Client & client);
|
||||
|
||||
|
||||
protected:
|
||||
//////////////////////////////////////
|
||||
// Override these for customization //
|
||||
//////////////////////////////////////
|
||||
|
||||
virtual std::string extractBodyContent(const std::shared_ptr<restbed::Session>& session);
|
||||
virtual std::string extractFormParamsFromBody(const std::string& paramName, const std::string& body);
|
||||
|
||||
virtual std::pair<int, std::string> handleFakeClassnameTags123ApiException(const FakeClassnameTags123ApiException& e);
|
||||
virtual std::pair<int, std::string> handleStdException(const std::exception& e);
|
||||
virtual std::pair<int, std::string> handleUnspecifiedException();
|
||||
|
||||
virtual void setResponseHeader(const std::shared_ptr<restbed::Session>& session,
|
||||
const std::string& header);
|
||||
|
||||
virtual void returnResponse(const std::shared_ptr<restbed::Session>& session,
|
||||
const int status, const std::string& result, std::multimap<std::string, std::string>& contentType);
|
||||
virtual void defaultSessionClose(const std::shared_ptr<restbed::Session>& session,
|
||||
const int status, const std::string& result);
|
||||
|
||||
private:
|
||||
void handler_PATCH_internal(const std::shared_ptr<restbed::Session> session);
|
||||
};
|
||||
|
||||
} /* namespace FakeClassnameTags123ApiResources */
|
||||
|
||||
using FakeClassnameTags123ApiFake_classname_testResource [[deprecated]] = FakeClassnameTags123ApiResources::Fake_classname_testResource;
|
||||
|
||||
//
|
||||
// The restbed service to actually implement the REST server
|
||||
//
|
||||
class FakeClassnameTags123Api
|
||||
{
|
||||
public:
|
||||
explicit FakeClassnameTags123Api(std::shared_ptr<restbed::Service> const& restbedService);
|
||||
virtual ~FakeClassnameTags123Api();
|
||||
|
||||
std::shared_ptr<FakeClassnameTags123ApiResources::Fake_classname_testResource> getFake_classname_testResource();
|
||||
|
||||
void setResource(std::shared_ptr<FakeClassnameTags123ApiResources::Fake_classname_testResource> resource);
|
||||
[[deprecated("use setResource()")]]
|
||||
virtual void setFakeClassnameTags123ApiFake_classname_testResource(std::shared_ptr<FakeClassnameTags123ApiResources::Fake_classname_testResource> spFakeClassnameTags123ApiFake_classname_testResource);
|
||||
|
||||
virtual void publishDefaultResources();
|
||||
|
||||
virtual std::shared_ptr<restbed::Service> service();
|
||||
|
||||
protected:
|
||||
std::shared_ptr<FakeClassnameTags123ApiResources::Fake_classname_testResource> m_spFake_classname_testResource;
|
||||
|
||||
private:
|
||||
std::shared_ptr<restbed::Service> m_service;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* FakeClassnameTags123Api_H_ */
|
||||
|
1157
samples/server/petstore/cpp-restbed/generated/3_0/api/PetApi.cpp
Normal file
1157
samples/server/petstore/cpp-restbed/generated/3_0/api/PetApi.cpp
Normal file
File diff suppressed because it is too large
Load Diff
526
samples/server/petstore/cpp-restbed/generated/3_0/api/PetApi.h
Normal file
526
samples/server/petstore/cpp-restbed/generated/3_0/api/PetApi.h
Normal file
@ -0,0 +1,526 @@
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
|
||||
*
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator unset.
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
/*
|
||||
* PetApi.h
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef PetApi_H_
|
||||
#define PetApi_H_
|
||||
|
||||
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
#include <exception>
|
||||
#include <functional>
|
||||
|
||||
#include <corvusoft/restbed/session.hpp>
|
||||
#include <corvusoft/restbed/resource.hpp>
|
||||
#include <corvusoft/restbed/request.hpp>
|
||||
#include <corvusoft/restbed/service.hpp>
|
||||
#include <corvusoft/restbed/settings.hpp>
|
||||
|
||||
#include "ApiResponse.h"
|
||||
#include "Pet.h"
|
||||
#include <set>
|
||||
#include <string>
|
||||
|
||||
namespace org {
|
||||
namespace openapitools {
|
||||
namespace server {
|
||||
namespace api {
|
||||
|
||||
using namespace org::openapitools::server::model;
|
||||
|
||||
///
|
||||
/// Exception to flag problems in the handlers
|
||||
///
|
||||
class PetApiException: public std::exception
|
||||
{
|
||||
public:
|
||||
PetApiException(int status_code, std::string what);
|
||||
|
||||
int getStatus() const;
|
||||
const char* what() const noexcept override;
|
||||
|
||||
private:
|
||||
int m_status;
|
||||
std::string m_what;
|
||||
};
|
||||
|
||||
namespace PetApiResources {
|
||||
/// <summary>
|
||||
/// Add a new pet to the store
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
///
|
||||
/// </remarks>
|
||||
class PetResource: public restbed::Resource
|
||||
{
|
||||
public:
|
||||
PetResource(const std::string& context = "/v2");
|
||||
virtual ~PetResource() = default;
|
||||
|
||||
PetResource(
|
||||
const PetResource& other) = default; // copy constructor
|
||||
PetResource(PetResource&& other) noexcept = default; // move constructor
|
||||
|
||||
PetResource& operator=(const PetResource& other) = default; // copy assignment
|
||||
PetResource& operator=(PetResource&& other) noexcept = default; // move assignment
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
// Set these to implement the server functionality //
|
||||
/////////////////////////////////////////////////////
|
||||
std::function<int(
|
||||
Pet & pet)> handler_POST_func =
|
||||
[](Pet &) -> int
|
||||
{ throw PetApiException(501, "Not implemented"); };
|
||||
|
||||
std::function<int(
|
||||
Pet & pet)> handler_PUT_func =
|
||||
[](Pet &) -> int
|
||||
{ throw PetApiException(501, "Not implemented"); };
|
||||
|
||||
|
||||
protected:
|
||||
//////////////////////////////////////////////////////////
|
||||
// As an alternative to setting the `std::function`s //
|
||||
// override these to implement the server functionality //
|
||||
//////////////////////////////////////////////////////////
|
||||
|
||||
virtual int handler_POST(
|
||||
Pet & pet);
|
||||
|
||||
virtual int handler_PUT(
|
||||
Pet & pet);
|
||||
|
||||
protected:
|
||||
//////////////////////////////////////
|
||||
// Override these for customization //
|
||||
//////////////////////////////////////
|
||||
|
||||
virtual std::string extractBodyContent(const std::shared_ptr<restbed::Session>& session);
|
||||
virtual std::string extractFormParamsFromBody(const std::string& paramName, const std::string& body);
|
||||
|
||||
virtual std::pair<int, std::string> handlePetApiException(const PetApiException& e);
|
||||
virtual std::pair<int, std::string> handleStdException(const std::exception& e);
|
||||
virtual std::pair<int, std::string> handleUnspecifiedException();
|
||||
|
||||
virtual void setResponseHeader(const std::shared_ptr<restbed::Session>& session,
|
||||
const std::string& header);
|
||||
|
||||
virtual void returnResponse(const std::shared_ptr<restbed::Session>& session,
|
||||
const int status, const std::string& result, std::multimap<std::string, std::string>& contentType);
|
||||
virtual void defaultSessionClose(const std::shared_ptr<restbed::Session>& session,
|
||||
const int status, const std::string& result);
|
||||
|
||||
private:
|
||||
void handler_POST_internal(const std::shared_ptr<restbed::Session> session);
|
||||
void handler_PUT_internal(const std::shared_ptr<restbed::Session> session);
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Deletes a pet
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
///
|
||||
/// </remarks>
|
||||
class PetPetIdResource: public restbed::Resource
|
||||
{
|
||||
public:
|
||||
PetPetIdResource(const std::string& context = "/v2");
|
||||
virtual ~PetPetIdResource() = default;
|
||||
|
||||
PetPetIdResource(
|
||||
const PetPetIdResource& other) = default; // copy constructor
|
||||
PetPetIdResource(PetPetIdResource&& other) noexcept = default; // move constructor
|
||||
|
||||
PetPetIdResource& operator=(const PetPetIdResource& other) = default; // copy assignment
|
||||
PetPetIdResource& operator=(PetPetIdResource&& other) noexcept = default; // move assignment
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
// Set these to implement the server functionality //
|
||||
/////////////////////////////////////////////////////
|
||||
std::function<int(
|
||||
int64_t & petId, std::string & apiKey)> handler_DELETE_func =
|
||||
[](int64_t &, std::string &) -> int
|
||||
{ throw PetApiException(501, "Not implemented"); };
|
||||
|
||||
std::function<std::pair<int, Pet>(
|
||||
int64_t & petId)> handler_GET_func =
|
||||
[](int64_t &) -> std::pair<int, Pet>
|
||||
{ throw PetApiException(501, "Not implemented"); };
|
||||
|
||||
std::function<int(
|
||||
int64_t & petId, std::string & name, std::string & status)> handler_POST_func =
|
||||
[](int64_t &, std::string &, std::string &) -> int
|
||||
{ throw PetApiException(501, "Not implemented"); };
|
||||
|
||||
|
||||
protected:
|
||||
//////////////////////////////////////////////////////////
|
||||
// As an alternative to setting the `std::function`s //
|
||||
// override these to implement the server functionality //
|
||||
//////////////////////////////////////////////////////////
|
||||
|
||||
virtual int handler_DELETE(
|
||||
int64_t & petId, std::string & apiKey);
|
||||
|
||||
virtual std::pair<int, Pet> handler_GET(
|
||||
int64_t & petId);
|
||||
virtual int handler_POST(
|
||||
int64_t & petId, std::string & name, std::string & status);
|
||||
|
||||
protected:
|
||||
//////////////////////////////////////
|
||||
// Override these for customization //
|
||||
//////////////////////////////////////
|
||||
|
||||
virtual std::string extractBodyContent(const std::shared_ptr<restbed::Session>& session);
|
||||
virtual std::string extractFormParamsFromBody(const std::string& paramName, const std::string& body);
|
||||
|
||||
virtual std::pair<int, std::string> handlePetApiException(const PetApiException& e);
|
||||
virtual std::pair<int, std::string> handleStdException(const std::exception& e);
|
||||
virtual std::pair<int, std::string> handleUnspecifiedException();
|
||||
|
||||
virtual void setResponseHeader(const std::shared_ptr<restbed::Session>& session,
|
||||
const std::string& header);
|
||||
|
||||
virtual void returnResponse(const std::shared_ptr<restbed::Session>& session,
|
||||
const int status, const std::string& result, std::multimap<std::string, std::string>& contentType);
|
||||
virtual void defaultSessionClose(const std::shared_ptr<restbed::Session>& session,
|
||||
const int status, const std::string& result);
|
||||
|
||||
private:
|
||||
void handler_DELETE_internal(const std::shared_ptr<restbed::Session> session);
|
||||
void handler_GET_internal(const std::shared_ptr<restbed::Session> session);
|
||||
void handler_POST_internal(const std::shared_ptr<restbed::Session> session);
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Finds Pets by status
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Multiple status values can be provided with comma separated strings
|
||||
/// </remarks>
|
||||
class PetFindByStatusResource: public restbed::Resource
|
||||
{
|
||||
public:
|
||||
PetFindByStatusResource(const std::string& context = "/v2");
|
||||
virtual ~PetFindByStatusResource() = default;
|
||||
|
||||
PetFindByStatusResource(
|
||||
const PetFindByStatusResource& other) = default; // copy constructor
|
||||
PetFindByStatusResource(PetFindByStatusResource&& other) noexcept = default; // move constructor
|
||||
|
||||
PetFindByStatusResource& operator=(const PetFindByStatusResource& other) = default; // copy assignment
|
||||
PetFindByStatusResource& operator=(PetFindByStatusResource&& other) noexcept = default; // move assignment
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
// Set these to implement the server functionality //
|
||||
/////////////////////////////////////////////////////
|
||||
std::function<std::pair<int, std::vector<Pet>>(
|
||||
std::vector<std::string> & status)> handler_GET_func =
|
||||
[](std::vector<std::string> &) -> std::pair<int, std::vector<Pet>>
|
||||
{ throw PetApiException(501, "Not implemented"); };
|
||||
|
||||
|
||||
protected:
|
||||
//////////////////////////////////////////////////////////
|
||||
// As an alternative to setting the `std::function`s //
|
||||
// override these to implement the server functionality //
|
||||
//////////////////////////////////////////////////////////
|
||||
|
||||
virtual std::pair<int, std::vector<Pet>> handler_GET(
|
||||
std::vector<std::string> & status);
|
||||
|
||||
|
||||
protected:
|
||||
//////////////////////////////////////
|
||||
// Override these for customization //
|
||||
//////////////////////////////////////
|
||||
|
||||
virtual std::string extractBodyContent(const std::shared_ptr<restbed::Session>& session);
|
||||
virtual std::string extractFormParamsFromBody(const std::string& paramName, const std::string& body);
|
||||
|
||||
virtual std::pair<int, std::string> handlePetApiException(const PetApiException& e);
|
||||
virtual std::pair<int, std::string> handleStdException(const std::exception& e);
|
||||
virtual std::pair<int, std::string> handleUnspecifiedException();
|
||||
|
||||
virtual void setResponseHeader(const std::shared_ptr<restbed::Session>& session,
|
||||
const std::string& header);
|
||||
|
||||
virtual void returnResponse(const std::shared_ptr<restbed::Session>& session,
|
||||
const int status, const std::string& result, std::multimap<std::string, std::string>& contentType);
|
||||
virtual void defaultSessionClose(const std::shared_ptr<restbed::Session>& session,
|
||||
const int status, const std::string& result);
|
||||
|
||||
private:
|
||||
void handler_GET_internal(const std::shared_ptr<restbed::Session> session);
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Finds Pets by tags
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
|
||||
/// </remarks>
|
||||
class PetFindByTagsResource: public restbed::Resource
|
||||
{
|
||||
public:
|
||||
PetFindByTagsResource(const std::string& context = "/v2");
|
||||
virtual ~PetFindByTagsResource() = default;
|
||||
|
||||
PetFindByTagsResource(
|
||||
const PetFindByTagsResource& other) = default; // copy constructor
|
||||
PetFindByTagsResource(PetFindByTagsResource&& other) noexcept = default; // move constructor
|
||||
|
||||
PetFindByTagsResource& operator=(const PetFindByTagsResource& other) = default; // copy assignment
|
||||
PetFindByTagsResource& operator=(PetFindByTagsResource&& other) noexcept = default; // move assignment
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
// Set these to implement the server functionality //
|
||||
/////////////////////////////////////////////////////
|
||||
std::function<std::pair<int, std::set<Pet>>(
|
||||
std::set<std::string> & tags)> handler_GET_func =
|
||||
[](std::set<std::string> &) -> std::pair<int, std::set<Pet>>
|
||||
{ throw PetApiException(501, "Not implemented"); };
|
||||
|
||||
|
||||
protected:
|
||||
//////////////////////////////////////////////////////////
|
||||
// As an alternative to setting the `std::function`s //
|
||||
// override these to implement the server functionality //
|
||||
//////////////////////////////////////////////////////////
|
||||
|
||||
virtual std::pair<int, std::set<Pet>> handler_GET(
|
||||
std::set<std::string> & tags);
|
||||
|
||||
|
||||
protected:
|
||||
//////////////////////////////////////
|
||||
// Override these for customization //
|
||||
//////////////////////////////////////
|
||||
|
||||
virtual std::string extractBodyContent(const std::shared_ptr<restbed::Session>& session);
|
||||
virtual std::string extractFormParamsFromBody(const std::string& paramName, const std::string& body);
|
||||
|
||||
virtual std::pair<int, std::string> handlePetApiException(const PetApiException& e);
|
||||
virtual std::pair<int, std::string> handleStdException(const std::exception& e);
|
||||
virtual std::pair<int, std::string> handleUnspecifiedException();
|
||||
|
||||
virtual void setResponseHeader(const std::shared_ptr<restbed::Session>& session,
|
||||
const std::string& header);
|
||||
|
||||
virtual void returnResponse(const std::shared_ptr<restbed::Session>& session,
|
||||
const int status, const std::string& result, std::multimap<std::string, std::string>& contentType);
|
||||
virtual void defaultSessionClose(const std::shared_ptr<restbed::Session>& session,
|
||||
const int status, const std::string& result);
|
||||
|
||||
private:
|
||||
void handler_GET_internal(const std::shared_ptr<restbed::Session> session);
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// uploads an image
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
///
|
||||
/// </remarks>
|
||||
class PetPetIdUploadImageResource: public restbed::Resource
|
||||
{
|
||||
public:
|
||||
PetPetIdUploadImageResource(const std::string& context = "/v2");
|
||||
virtual ~PetPetIdUploadImageResource() = default;
|
||||
|
||||
PetPetIdUploadImageResource(
|
||||
const PetPetIdUploadImageResource& other) = default; // copy constructor
|
||||
PetPetIdUploadImageResource(PetPetIdUploadImageResource&& other) noexcept = default; // move constructor
|
||||
|
||||
PetPetIdUploadImageResource& operator=(const PetPetIdUploadImageResource& other) = default; // copy assignment
|
||||
PetPetIdUploadImageResource& operator=(PetPetIdUploadImageResource&& other) noexcept = default; // move assignment
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
// Set these to implement the server functionality //
|
||||
/////////////////////////////////////////////////////
|
||||
std::function<std::pair<int, ApiResponse>(
|
||||
int64_t & petId, std::string & additionalMetadata, std::string & file)> handler_POST_func =
|
||||
[](int64_t &, std::string &, std::string &) -> std::pair<int, ApiResponse>
|
||||
{ throw PetApiException(501, "Not implemented"); };
|
||||
|
||||
|
||||
protected:
|
||||
//////////////////////////////////////////////////////////
|
||||
// As an alternative to setting the `std::function`s //
|
||||
// override these to implement the server functionality //
|
||||
//////////////////////////////////////////////////////////
|
||||
|
||||
virtual std::pair<int, ApiResponse> handler_POST(
|
||||
int64_t & petId, std::string & additionalMetadata, std::string & file);
|
||||
|
||||
|
||||
protected:
|
||||
//////////////////////////////////////
|
||||
// Override these for customization //
|
||||
//////////////////////////////////////
|
||||
|
||||
virtual std::string extractBodyContent(const std::shared_ptr<restbed::Session>& session);
|
||||
virtual std::string extractFormParamsFromBody(const std::string& paramName, const std::string& body);
|
||||
|
||||
virtual std::pair<int, std::string> handlePetApiException(const PetApiException& e);
|
||||
virtual std::pair<int, std::string> handleStdException(const std::exception& e);
|
||||
virtual std::pair<int, std::string> handleUnspecifiedException();
|
||||
|
||||
virtual void setResponseHeader(const std::shared_ptr<restbed::Session>& session,
|
||||
const std::string& header);
|
||||
|
||||
virtual void returnResponse(const std::shared_ptr<restbed::Session>& session,
|
||||
const int status, const std::string& result, std::multimap<std::string, std::string>& contentType);
|
||||
virtual void defaultSessionClose(const std::shared_ptr<restbed::Session>& session,
|
||||
const int status, const std::string& result);
|
||||
|
||||
private:
|
||||
void handler_POST_internal(const std::shared_ptr<restbed::Session> session);
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// uploads an image (required)
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
///
|
||||
/// </remarks>
|
||||
class FakePetIdUploadImageWithRequiredFileResource: public restbed::Resource
|
||||
{
|
||||
public:
|
||||
FakePetIdUploadImageWithRequiredFileResource(const std::string& context = "/v2");
|
||||
virtual ~FakePetIdUploadImageWithRequiredFileResource() = default;
|
||||
|
||||
FakePetIdUploadImageWithRequiredFileResource(
|
||||
const FakePetIdUploadImageWithRequiredFileResource& other) = default; // copy constructor
|
||||
FakePetIdUploadImageWithRequiredFileResource(FakePetIdUploadImageWithRequiredFileResource&& other) noexcept = default; // move constructor
|
||||
|
||||
FakePetIdUploadImageWithRequiredFileResource& operator=(const FakePetIdUploadImageWithRequiredFileResource& other) = default; // copy assignment
|
||||
FakePetIdUploadImageWithRequiredFileResource& operator=(FakePetIdUploadImageWithRequiredFileResource&& other) noexcept = default; // move assignment
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
// Set these to implement the server functionality //
|
||||
/////////////////////////////////////////////////////
|
||||
std::function<std::pair<int, ApiResponse>(
|
||||
int64_t & petId, std::string & requiredFile, std::string & additionalMetadata)> handler_POST_func =
|
||||
[](int64_t &, std::string &, std::string &) -> std::pair<int, ApiResponse>
|
||||
{ throw PetApiException(501, "Not implemented"); };
|
||||
|
||||
|
||||
protected:
|
||||
//////////////////////////////////////////////////////////
|
||||
// As an alternative to setting the `std::function`s //
|
||||
// override these to implement the server functionality //
|
||||
//////////////////////////////////////////////////////////
|
||||
|
||||
virtual std::pair<int, ApiResponse> handler_POST(
|
||||
int64_t & petId, std::string & requiredFile, std::string & additionalMetadata);
|
||||
|
||||
|
||||
protected:
|
||||
//////////////////////////////////////
|
||||
// Override these for customization //
|
||||
//////////////////////////////////////
|
||||
|
||||
virtual std::string extractBodyContent(const std::shared_ptr<restbed::Session>& session);
|
||||
virtual std::string extractFormParamsFromBody(const std::string& paramName, const std::string& body);
|
||||
|
||||
virtual std::pair<int, std::string> handlePetApiException(const PetApiException& e);
|
||||
virtual std::pair<int, std::string> handleStdException(const std::exception& e);
|
||||
virtual std::pair<int, std::string> handleUnspecifiedException();
|
||||
|
||||
virtual void setResponseHeader(const std::shared_ptr<restbed::Session>& session,
|
||||
const std::string& header);
|
||||
|
||||
virtual void returnResponse(const std::shared_ptr<restbed::Session>& session,
|
||||
const int status, const std::string& result, std::multimap<std::string, std::string>& contentType);
|
||||
virtual void defaultSessionClose(const std::shared_ptr<restbed::Session>& session,
|
||||
const int status, const std::string& result);
|
||||
|
||||
private:
|
||||
void handler_POST_internal(const std::shared_ptr<restbed::Session> session);
|
||||
};
|
||||
|
||||
} /* namespace PetApiResources */
|
||||
|
||||
using PetApiPetResource [[deprecated]] = PetApiResources::PetResource;
|
||||
using PetApiPetPetIdResource [[deprecated]] = PetApiResources::PetPetIdResource;
|
||||
using PetApiPetFindByStatusResource [[deprecated]] = PetApiResources::PetFindByStatusResource;
|
||||
using PetApiPetFindByTagsResource [[deprecated]] = PetApiResources::PetFindByTagsResource;
|
||||
using PetApiPetPetIdUploadImageResource [[deprecated]] = PetApiResources::PetPetIdUploadImageResource;
|
||||
using PetApiFakePetIdUploadImageWithRequiredFileResource [[deprecated]] = PetApiResources::FakePetIdUploadImageWithRequiredFileResource;
|
||||
|
||||
//
|
||||
// The restbed service to actually implement the REST server
|
||||
//
|
||||
class PetApi
|
||||
{
|
||||
public:
|
||||
explicit PetApi(std::shared_ptr<restbed::Service> const& restbedService);
|
||||
virtual ~PetApi();
|
||||
|
||||
std::shared_ptr<PetApiResources::PetResource> getPetResource();
|
||||
std::shared_ptr<PetApiResources::PetPetIdResource> getPetPetIdResource();
|
||||
std::shared_ptr<PetApiResources::PetFindByStatusResource> getPetFindByStatusResource();
|
||||
std::shared_ptr<PetApiResources::PetFindByTagsResource> getPetFindByTagsResource();
|
||||
std::shared_ptr<PetApiResources::PetPetIdUploadImageResource> getPetPetIdUploadImageResource();
|
||||
std::shared_ptr<PetApiResources::FakePetIdUploadImageWithRequiredFileResource> getFakePetIdUploadImageWithRequiredFileResource();
|
||||
|
||||
void setResource(std::shared_ptr<PetApiResources::PetResource> resource);
|
||||
void setResource(std::shared_ptr<PetApiResources::PetPetIdResource> resource);
|
||||
void setResource(std::shared_ptr<PetApiResources::PetFindByStatusResource> resource);
|
||||
void setResource(std::shared_ptr<PetApiResources::PetFindByTagsResource> resource);
|
||||
void setResource(std::shared_ptr<PetApiResources::PetPetIdUploadImageResource> resource);
|
||||
void setResource(std::shared_ptr<PetApiResources::FakePetIdUploadImageWithRequiredFileResource> resource);
|
||||
[[deprecated("use setResource()")]]
|
||||
virtual void setPetApiPetResource(std::shared_ptr<PetApiResources::PetResource> spPetApiPetResource);
|
||||
[[deprecated("use setResource()")]]
|
||||
virtual void setPetApiPetPetIdResource(std::shared_ptr<PetApiResources::PetPetIdResource> spPetApiPetPetIdResource);
|
||||
[[deprecated("use setResource()")]]
|
||||
virtual void setPetApiPetFindByStatusResource(std::shared_ptr<PetApiResources::PetFindByStatusResource> spPetApiPetFindByStatusResource);
|
||||
[[deprecated("use setResource()")]]
|
||||
virtual void setPetApiPetFindByTagsResource(std::shared_ptr<PetApiResources::PetFindByTagsResource> spPetApiPetFindByTagsResource);
|
||||
[[deprecated("use setResource()")]]
|
||||
virtual void setPetApiPetPetIdUploadImageResource(std::shared_ptr<PetApiResources::PetPetIdUploadImageResource> spPetApiPetPetIdUploadImageResource);
|
||||
[[deprecated("use setResource()")]]
|
||||
virtual void setPetApiFakePetIdUploadImageWithRequiredFileResource(std::shared_ptr<PetApiResources::FakePetIdUploadImageWithRequiredFileResource> spPetApiFakePetIdUploadImageWithRequiredFileResource);
|
||||
|
||||
virtual void publishDefaultResources();
|
||||
|
||||
virtual std::shared_ptr<restbed::Service> service();
|
||||
|
||||
protected:
|
||||
std::shared_ptr<PetApiResources::PetResource> m_spPetResource;
|
||||
std::shared_ptr<PetApiResources::PetPetIdResource> m_spPetPetIdResource;
|
||||
std::shared_ptr<PetApiResources::PetFindByStatusResource> m_spPetFindByStatusResource;
|
||||
std::shared_ptr<PetApiResources::PetFindByTagsResource> m_spPetFindByTagsResource;
|
||||
std::shared_ptr<PetApiResources::PetPetIdUploadImageResource> m_spPetPetIdUploadImageResource;
|
||||
std::shared_ptr<PetApiResources::FakePetIdUploadImageWithRequiredFileResource> m_spFakePetIdUploadImageWithRequiredFileResource;
|
||||
|
||||
private:
|
||||
std::shared_ptr<restbed::Service> m_service;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* PetApi_H_ */
|
||||
|
@ -0,0 +1,606 @@
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
|
||||
*
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator unset.
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
|
||||
#include <corvusoft/restbed/byte.hpp>
|
||||
#include <corvusoft/restbed/string.hpp>
|
||||
#include <corvusoft/restbed/settings.hpp>
|
||||
#include <corvusoft/restbed/request.hpp>
|
||||
#include <corvusoft/restbed/uri.hpp>
|
||||
#include <boost/property_tree/ptree.hpp>
|
||||
#include <boost/property_tree/json_parser.hpp>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <boost/algorithm/string.hpp>
|
||||
|
||||
#include "StoreApi.h"
|
||||
|
||||
namespace org {
|
||||
namespace openapitools {
|
||||
namespace server {
|
||||
namespace api {
|
||||
|
||||
using namespace org::openapitools::server::model;
|
||||
|
||||
namespace {
|
||||
[[maybe_unused]]
|
||||
std::string selectPreferredContentType(const std::vector<std::string>& contentTypes) {
|
||||
if (contentTypes.size() == 0) {
|
||||
return "application/json";
|
||||
}
|
||||
|
||||
if (contentTypes.size() == 1) {
|
||||
return contentTypes.at(0);
|
||||
}
|
||||
|
||||
static const std::array<std::string, 2> preferredTypes = {"json", "xml"};
|
||||
for (const auto& preferredType: preferredTypes) {
|
||||
const auto ret = std::find_if(contentTypes.cbegin(),
|
||||
contentTypes.cend(),
|
||||
[preferredType](const std::string& str) {
|
||||
return str.find(preferredType) != std::string::npos;});
|
||||
if (ret != contentTypes.cend()) {
|
||||
return *ret;
|
||||
}
|
||||
}
|
||||
|
||||
return contentTypes.at(0);
|
||||
}
|
||||
}
|
||||
|
||||
StoreApiException::StoreApiException(int status_code, std::string what)
|
||||
: m_status(status_code),
|
||||
m_what(what)
|
||||
{
|
||||
|
||||
}
|
||||
int StoreApiException::getStatus() const
|
||||
{
|
||||
return m_status;
|
||||
}
|
||||
const char* StoreApiException::what() const noexcept
|
||||
{
|
||||
return m_what.c_str();
|
||||
}
|
||||
|
||||
|
||||
template<class MODEL_T>
|
||||
MODEL_T extractJsonModelBodyParam(const std::string& bodyContent)
|
||||
{
|
||||
std::stringstream sstream(bodyContent);
|
||||
boost::property_tree::ptree pt;
|
||||
boost::property_tree::json_parser::read_json(sstream, pt);
|
||||
|
||||
auto model = MODEL_T(pt);
|
||||
return model;
|
||||
}
|
||||
|
||||
template<class MODEL_T>
|
||||
std::vector<MODEL_T> extractJsonArrayBodyParam(const std::string& bodyContent)
|
||||
{
|
||||
std::stringstream sstream(bodyContent);
|
||||
boost::property_tree::ptree pt;
|
||||
boost::property_tree::json_parser::read_json(sstream, pt);
|
||||
|
||||
auto arrayRet = std::vector<MODEL_T>();
|
||||
for (const auto& child: pt) {
|
||||
arrayRet.emplace_back(MODEL_T(child.second));
|
||||
}
|
||||
return arrayRet;
|
||||
}
|
||||
|
||||
template <class KEY_T, class VAL_T>
|
||||
std::string convertMapResponse(const std::map<KEY_T, VAL_T>& map)
|
||||
{
|
||||
boost::property_tree::ptree pt;
|
||||
for(const auto &kv: map) {
|
||||
pt.push_back(boost::property_tree::ptree::value_type(
|
||||
boost::lexical_cast<std::string>(kv.first),
|
||||
boost::property_tree::ptree(
|
||||
boost::lexical_cast<std::string>(kv.second))));
|
||||
}
|
||||
std::stringstream sstream;
|
||||
write_json(sstream, pt);
|
||||
std::string result = sstream.str();
|
||||
return result;
|
||||
}
|
||||
|
||||
namespace StoreApiResources {
|
||||
StoreOrderOrder_idResource::StoreOrderOrder_idResource(const std::string& context /* = "/v2" */)
|
||||
{
|
||||
this->set_path(context + "/store/order/{order_id: .*}");
|
||||
this->set_method_handler("DELETE",
|
||||
std::bind(&StoreOrderOrder_idResource::handler_DELETE_internal, this,
|
||||
std::placeholders::_1));
|
||||
this->set_method_handler("GET",
|
||||
std::bind(&StoreOrderOrder_idResource::handler_GET_internal, this,
|
||||
std::placeholders::_1));
|
||||
}
|
||||
|
||||
std::pair<int, std::string> StoreOrderOrder_idResource::handleStoreApiException(const StoreApiException& e)
|
||||
{
|
||||
return std::make_pair<int, std::string>(e.getStatus(), e.what());
|
||||
}
|
||||
|
||||
std::pair<int, std::string> StoreOrderOrder_idResource::handleStdException(const std::exception& e)
|
||||
{
|
||||
return std::make_pair<int, std::string>(500, e.what());
|
||||
}
|
||||
|
||||
std::pair<int, std::string> StoreOrderOrder_idResource::handleUnspecifiedException()
|
||||
{
|
||||
return std::make_pair<int, std::string>(500, "Unknown exception occurred");
|
||||
}
|
||||
|
||||
void StoreOrderOrder_idResource::setResponseHeader(const std::shared_ptr<restbed::Session>& session, const std::string& header)
|
||||
{
|
||||
session->set_header(header, "");
|
||||
}
|
||||
|
||||
void StoreOrderOrder_idResource::returnResponse(const std::shared_ptr<restbed::Session>& session, const int status, const std::string& result, std::multimap<std::string, std::string>& responseHeaders)
|
||||
{
|
||||
responseHeaders.insert(std::make_pair("Connection", "close"));
|
||||
session->close(status, result, responseHeaders);
|
||||
}
|
||||
|
||||
void StoreOrderOrder_idResource::defaultSessionClose(const std::shared_ptr<restbed::Session>& session, const int status, const std::string& result)
|
||||
{
|
||||
session->close(status, result, { {"Connection", "close"} });
|
||||
}
|
||||
|
||||
void StoreOrderOrder_idResource::handler_DELETE_internal(const std::shared_ptr<restbed::Session> session)
|
||||
{
|
||||
const auto request = session->get_request();
|
||||
// Getting the path params
|
||||
std::string orderId = request->get_path_parameter("order_id", "");
|
||||
|
||||
int status_code = 500;
|
||||
std::string result = "";
|
||||
|
||||
try {
|
||||
status_code =
|
||||
handler_DELETE(orderId);
|
||||
}
|
||||
catch(const StoreApiException& e) {
|
||||
std::tie(status_code, result) = handleStoreApiException(e);
|
||||
}
|
||||
catch(const std::exception& e) {
|
||||
std::tie(status_code, result) = handleStdException(e);
|
||||
}
|
||||
catch(...) {
|
||||
std::tie(status_code, result) = handleUnspecifiedException();
|
||||
}
|
||||
|
||||
std::multimap< std::string, std::string > responseHeaders {};
|
||||
static const std::vector<std::string> contentTypes{
|
||||
"application/json"
|
||||
};
|
||||
static const std::string acceptTypes{
|
||||
};
|
||||
|
||||
if (status_code == 400) {
|
||||
responseHeaders.insert(std::make_pair("Content-Type", "text/plain"));
|
||||
result = "Invalid ID supplied";
|
||||
|
||||
returnResponse(session, 400, result.empty() ? "{}" : result, responseHeaders);
|
||||
return;
|
||||
}
|
||||
if (status_code == 404) {
|
||||
responseHeaders.insert(std::make_pair("Content-Type", "text/plain"));
|
||||
result = "Order not found";
|
||||
|
||||
returnResponse(session, 404, result.empty() ? "{}" : result, responseHeaders);
|
||||
return;
|
||||
}
|
||||
defaultSessionClose(session, status_code, result);
|
||||
}
|
||||
|
||||
// x-extension
|
||||
void StoreOrderOrder_idResource::handler_GET_internal(const std::shared_ptr<restbed::Session> session) {
|
||||
const auto request = session->get_request();
|
||||
// Getting the path params
|
||||
int64_t orderId = request->get_path_parameter("order_id", 0L);
|
||||
|
||||
int status_code = 500;
|
||||
Order resultObject = Order{};
|
||||
std::string result = "";
|
||||
|
||||
try {
|
||||
std::tie(status_code, resultObject) =
|
||||
handler_GET(orderId);
|
||||
}
|
||||
catch(const StoreApiException& e) {
|
||||
std::tie(status_code, result) = handleStoreApiException(e);
|
||||
}
|
||||
catch(const std::exception& e) {
|
||||
std::tie(status_code, result) = handleStdException(e);
|
||||
}
|
||||
catch(...) {
|
||||
std::tie(status_code, result) = handleUnspecifiedException();
|
||||
}
|
||||
|
||||
std::multimap< std::string, std::string > responseHeaders {};
|
||||
static const std::vector<std::string> contentTypes{
|
||||
"application/xml","application/json",
|
||||
};
|
||||
static const std::string acceptTypes{
|
||||
};
|
||||
|
||||
if (status_code == 200) {
|
||||
responseHeaders.insert(std::make_pair("Content-Type", selectPreferredContentType(contentTypes)));
|
||||
if (!acceptTypes.empty()) {
|
||||
responseHeaders.insert(std::make_pair("Accept", acceptTypes));
|
||||
}
|
||||
|
||||
result = resultObject.toJsonString();
|
||||
returnResponse(session, 200, result.empty() ? "{}" : result, responseHeaders);
|
||||
return;
|
||||
}
|
||||
if (status_code == 400) {
|
||||
responseHeaders.insert(std::make_pair("Content-Type", "text/plain"));
|
||||
result = "Invalid ID supplied";
|
||||
|
||||
returnResponse(session, 400, result.empty() ? "{}" : result, responseHeaders);
|
||||
return;
|
||||
}
|
||||
if (status_code == 404) {
|
||||
responseHeaders.insert(std::make_pair("Content-Type", "text/plain"));
|
||||
result = "Order not found";
|
||||
|
||||
returnResponse(session, 404, result.empty() ? "{}" : result, responseHeaders);
|
||||
return;
|
||||
}
|
||||
defaultSessionClose(session, status_code, result);
|
||||
}
|
||||
|
||||
int StoreOrderOrder_idResource::handler_DELETE(
|
||||
std::string & orderId)
|
||||
{
|
||||
return handler_DELETE_func(orderId);
|
||||
}
|
||||
|
||||
std::pair<int, Order> StoreOrderOrder_idResource::handler_GET(
|
||||
int64_t & orderId)
|
||||
{
|
||||
return handler_GET_func(orderId);
|
||||
}
|
||||
|
||||
std::string StoreOrderOrder_idResource::extractBodyContent(const std::shared_ptr<restbed::Session>& session) {
|
||||
const auto request = session->get_request();
|
||||
int content_length = request->get_header("Content-Length", 0);
|
||||
std::string bodyContent;
|
||||
session->fetch(content_length,
|
||||
[&bodyContent](const std::shared_ptr<restbed::Session> session,
|
||||
const restbed::Bytes &body) {
|
||||
bodyContent = restbed::String::format(
|
||||
"%.*s\n", (int)body.size(), body.data());
|
||||
});
|
||||
return bodyContent;
|
||||
}
|
||||
|
||||
std::string StoreOrderOrder_idResource::extractFormParamsFromBody(const std::string& paramName, const std::string& body) {
|
||||
const auto uri = restbed::Uri("urlencoded?" + body, true);
|
||||
const auto params = uri.get_query_parameters();
|
||||
const auto result = params.find(paramName);
|
||||
if (result != params.cend()) {
|
||||
return result->second;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
StoreInventoryResource::StoreInventoryResource(const std::string& context /* = "/v2" */)
|
||||
{
|
||||
this->set_path(context + "/store/inventory");
|
||||
this->set_method_handler("GET",
|
||||
std::bind(&StoreInventoryResource::handler_GET_internal, this,
|
||||
std::placeholders::_1));
|
||||
}
|
||||
|
||||
std::pair<int, std::string> StoreInventoryResource::handleStoreApiException(const StoreApiException& e)
|
||||
{
|
||||
return std::make_pair<int, std::string>(e.getStatus(), e.what());
|
||||
}
|
||||
|
||||
std::pair<int, std::string> StoreInventoryResource::handleStdException(const std::exception& e)
|
||||
{
|
||||
return std::make_pair<int, std::string>(500, e.what());
|
||||
}
|
||||
|
||||
std::pair<int, std::string> StoreInventoryResource::handleUnspecifiedException()
|
||||
{
|
||||
return std::make_pair<int, std::string>(500, "Unknown exception occurred");
|
||||
}
|
||||
|
||||
void StoreInventoryResource::setResponseHeader(const std::shared_ptr<restbed::Session>& session, const std::string& header)
|
||||
{
|
||||
session->set_header(header, "");
|
||||
}
|
||||
|
||||
void StoreInventoryResource::returnResponse(const std::shared_ptr<restbed::Session>& session, const int status, const std::string& result, std::multimap<std::string, std::string>& responseHeaders)
|
||||
{
|
||||
responseHeaders.insert(std::make_pair("Connection", "close"));
|
||||
session->close(status, result, responseHeaders);
|
||||
}
|
||||
|
||||
void StoreInventoryResource::defaultSessionClose(const std::shared_ptr<restbed::Session>& session, const int status, const std::string& result)
|
||||
{
|
||||
session->close(status, result, { {"Connection", "close"} });
|
||||
}
|
||||
|
||||
void StoreInventoryResource::handler_GET_internal(const std::shared_ptr<restbed::Session> session)
|
||||
{
|
||||
const auto request = session->get_request();
|
||||
|
||||
int status_code = 500;
|
||||
std::map<std::string, int32_t> resultObject = std::map<std::string, int32_t>();
|
||||
std::string result = "";
|
||||
|
||||
try {
|
||||
std::tie(status_code, resultObject) =
|
||||
handler_GET();
|
||||
}
|
||||
catch(const StoreApiException& e) {
|
||||
std::tie(status_code, result) = handleStoreApiException(e);
|
||||
}
|
||||
catch(const std::exception& e) {
|
||||
std::tie(status_code, result) = handleStdException(e);
|
||||
}
|
||||
catch(...) {
|
||||
std::tie(status_code, result) = handleUnspecifiedException();
|
||||
}
|
||||
|
||||
std::multimap< std::string, std::string > responseHeaders {};
|
||||
static const std::vector<std::string> contentTypes{
|
||||
"application/json",
|
||||
};
|
||||
static const std::string acceptTypes{
|
||||
};
|
||||
|
||||
if (status_code == 200) {
|
||||
responseHeaders.insert(std::make_pair("Content-Type", selectPreferredContentType(contentTypes)));
|
||||
if (!acceptTypes.empty()) {
|
||||
responseHeaders.insert(std::make_pair("Accept", acceptTypes));
|
||||
}
|
||||
|
||||
result = convertMapResponse(resultObject);
|
||||
returnResponse(session, 200, result.empty() ? "{}" : result, responseHeaders);
|
||||
return;
|
||||
}
|
||||
defaultSessionClose(session, status_code, result);
|
||||
}
|
||||
|
||||
|
||||
std::pair<int, std::map<std::string, int32_t>> StoreInventoryResource::handler_GET(
|
||||
)
|
||||
{
|
||||
return handler_GET_func();
|
||||
}
|
||||
|
||||
|
||||
std::string StoreInventoryResource::extractBodyContent(const std::shared_ptr<restbed::Session>& session) {
|
||||
const auto request = session->get_request();
|
||||
int content_length = request->get_header("Content-Length", 0);
|
||||
std::string bodyContent;
|
||||
session->fetch(content_length,
|
||||
[&bodyContent](const std::shared_ptr<restbed::Session> session,
|
||||
const restbed::Bytes &body) {
|
||||
bodyContent = restbed::String::format(
|
||||
"%.*s\n", (int)body.size(), body.data());
|
||||
});
|
||||
return bodyContent;
|
||||
}
|
||||
|
||||
std::string StoreInventoryResource::extractFormParamsFromBody(const std::string& paramName, const std::string& body) {
|
||||
const auto uri = restbed::Uri("urlencoded?" + body, true);
|
||||
const auto params = uri.get_query_parameters();
|
||||
const auto result = params.find(paramName);
|
||||
if (result != params.cend()) {
|
||||
return result->second;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
StoreOrderResource::StoreOrderResource(const std::string& context /* = "/v2" */)
|
||||
{
|
||||
this->set_path(context + "/store/order");
|
||||
this->set_method_handler("POST",
|
||||
std::bind(&StoreOrderResource::handler_POST_internal, this,
|
||||
std::placeholders::_1));
|
||||
}
|
||||
|
||||
std::pair<int, std::string> StoreOrderResource::handleStoreApiException(const StoreApiException& e)
|
||||
{
|
||||
return std::make_pair<int, std::string>(e.getStatus(), e.what());
|
||||
}
|
||||
|
||||
std::pair<int, std::string> StoreOrderResource::handleStdException(const std::exception& e)
|
||||
{
|
||||
return std::make_pair<int, std::string>(500, e.what());
|
||||
}
|
||||
|
||||
std::pair<int, std::string> StoreOrderResource::handleUnspecifiedException()
|
||||
{
|
||||
return std::make_pair<int, std::string>(500, "Unknown exception occurred");
|
||||
}
|
||||
|
||||
void StoreOrderResource::setResponseHeader(const std::shared_ptr<restbed::Session>& session, const std::string& header)
|
||||
{
|
||||
session->set_header(header, "");
|
||||
}
|
||||
|
||||
void StoreOrderResource::returnResponse(const std::shared_ptr<restbed::Session>& session, const int status, const std::string& result, std::multimap<std::string, std::string>& responseHeaders)
|
||||
{
|
||||
responseHeaders.insert(std::make_pair("Connection", "close"));
|
||||
session->close(status, result, responseHeaders);
|
||||
}
|
||||
|
||||
void StoreOrderResource::defaultSessionClose(const std::shared_ptr<restbed::Session>& session, const int status, const std::string& result)
|
||||
{
|
||||
session->close(status, result, { {"Connection", "close"} });
|
||||
}
|
||||
|
||||
void StoreOrderResource::handler_POST_internal(const std::shared_ptr<restbed::Session> session)
|
||||
{
|
||||
const auto request = session->get_request();
|
||||
// body params or form params here from the body content string
|
||||
std::string bodyContent = extractBodyContent(session);
|
||||
auto order = extractJsonModelBodyParam<Order>(bodyContent);
|
||||
|
||||
int status_code = 500;
|
||||
Order resultObject = Order{};
|
||||
std::string result = "";
|
||||
|
||||
try {
|
||||
std::tie(status_code, resultObject) =
|
||||
handler_POST(order);
|
||||
}
|
||||
catch(const StoreApiException& e) {
|
||||
std::tie(status_code, result) = handleStoreApiException(e);
|
||||
}
|
||||
catch(const std::exception& e) {
|
||||
std::tie(status_code, result) = handleStdException(e);
|
||||
}
|
||||
catch(...) {
|
||||
std::tie(status_code, result) = handleUnspecifiedException();
|
||||
}
|
||||
|
||||
std::multimap< std::string, std::string > responseHeaders {};
|
||||
static const std::vector<std::string> contentTypes{
|
||||
"application/xml","application/json",
|
||||
};
|
||||
static const std::string acceptTypes{
|
||||
"application/json, "
|
||||
};
|
||||
|
||||
if (status_code == 200) {
|
||||
responseHeaders.insert(std::make_pair("Content-Type", selectPreferredContentType(contentTypes)));
|
||||
if (!acceptTypes.empty()) {
|
||||
responseHeaders.insert(std::make_pair("Accept", acceptTypes));
|
||||
}
|
||||
|
||||
result = resultObject.toJsonString();
|
||||
returnResponse(session, 200, result.empty() ? "{}" : result, responseHeaders);
|
||||
return;
|
||||
}
|
||||
if (status_code == 400) {
|
||||
responseHeaders.insert(std::make_pair("Content-Type", "text/plain"));
|
||||
result = "Invalid Order";
|
||||
|
||||
returnResponse(session, 400, result.empty() ? "{}" : result, responseHeaders);
|
||||
return;
|
||||
}
|
||||
defaultSessionClose(session, status_code, result);
|
||||
}
|
||||
|
||||
|
||||
std::pair<int, Order> StoreOrderResource::handler_POST(
|
||||
Order & order)
|
||||
{
|
||||
return handler_POST_func(order);
|
||||
}
|
||||
|
||||
|
||||
std::string StoreOrderResource::extractBodyContent(const std::shared_ptr<restbed::Session>& session) {
|
||||
const auto request = session->get_request();
|
||||
int content_length = request->get_header("Content-Length", 0);
|
||||
std::string bodyContent;
|
||||
session->fetch(content_length,
|
||||
[&bodyContent](const std::shared_ptr<restbed::Session> session,
|
||||
const restbed::Bytes &body) {
|
||||
bodyContent = restbed::String::format(
|
||||
"%.*s\n", (int)body.size(), body.data());
|
||||
});
|
||||
return bodyContent;
|
||||
}
|
||||
|
||||
std::string StoreOrderResource::extractFormParamsFromBody(const std::string& paramName, const std::string& body) {
|
||||
const auto uri = restbed::Uri("urlencoded?" + body, true);
|
||||
const auto params = uri.get_query_parameters();
|
||||
const auto result = params.find(paramName);
|
||||
if (result != params.cend()) {
|
||||
return result->second;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
} /* namespace StoreApiResources */
|
||||
|
||||
StoreApi::StoreApi(std::shared_ptr<restbed::Service> const& restbedService)
|
||||
: m_service(restbedService)
|
||||
{
|
||||
}
|
||||
|
||||
StoreApi::~StoreApi() {}
|
||||
|
||||
std::shared_ptr<StoreApiResources::StoreOrderOrder_idResource> StoreApi::getStoreOrderOrder_idResource() {
|
||||
if (!m_spStoreOrderOrder_idResource) {
|
||||
setResource(std::make_shared<StoreApiResources::StoreOrderOrder_idResource>());
|
||||
}
|
||||
return m_spStoreOrderOrder_idResource;
|
||||
}
|
||||
std::shared_ptr<StoreApiResources::StoreInventoryResource> StoreApi::getStoreInventoryResource() {
|
||||
if (!m_spStoreInventoryResource) {
|
||||
setResource(std::make_shared<StoreApiResources::StoreInventoryResource>());
|
||||
}
|
||||
return m_spStoreInventoryResource;
|
||||
}
|
||||
std::shared_ptr<StoreApiResources::StoreOrderResource> StoreApi::getStoreOrderResource() {
|
||||
if (!m_spStoreOrderResource) {
|
||||
setResource(std::make_shared<StoreApiResources::StoreOrderResource>());
|
||||
}
|
||||
return m_spStoreOrderResource;
|
||||
}
|
||||
void StoreApi::setResource(std::shared_ptr<StoreApiResources::StoreOrderOrder_idResource> resource) {
|
||||
m_spStoreOrderOrder_idResource = resource;
|
||||
m_service->publish(m_spStoreOrderOrder_idResource);
|
||||
}
|
||||
void StoreApi::setResource(std::shared_ptr<StoreApiResources::StoreInventoryResource> resource) {
|
||||
m_spStoreInventoryResource = resource;
|
||||
m_service->publish(m_spStoreInventoryResource);
|
||||
}
|
||||
void StoreApi::setResource(std::shared_ptr<StoreApiResources::StoreOrderResource> resource) {
|
||||
m_spStoreOrderResource = resource;
|
||||
m_service->publish(m_spStoreOrderResource);
|
||||
}
|
||||
void StoreApi::setStoreApiStoreOrderOrder_idResource(std::shared_ptr<StoreApiResources::StoreOrderOrder_idResource> spStoreOrderOrder_idResource) {
|
||||
m_spStoreOrderOrder_idResource = spStoreOrderOrder_idResource;
|
||||
m_service->publish(m_spStoreOrderOrder_idResource);
|
||||
}
|
||||
void StoreApi::setStoreApiStoreInventoryResource(std::shared_ptr<StoreApiResources::StoreInventoryResource> spStoreInventoryResource) {
|
||||
m_spStoreInventoryResource = spStoreInventoryResource;
|
||||
m_service->publish(m_spStoreInventoryResource);
|
||||
}
|
||||
void StoreApi::setStoreApiStoreOrderResource(std::shared_ptr<StoreApiResources::StoreOrderResource> spStoreOrderResource) {
|
||||
m_spStoreOrderResource = spStoreOrderResource;
|
||||
m_service->publish(m_spStoreOrderResource);
|
||||
}
|
||||
|
||||
|
||||
void StoreApi::publishDefaultResources() {
|
||||
if (!m_spStoreOrderOrder_idResource) {
|
||||
setResource(std::make_shared<StoreApiResources::StoreOrderOrder_idResource>());
|
||||
}
|
||||
if (!m_spStoreInventoryResource) {
|
||||
setResource(std::make_shared<StoreApiResources::StoreInventoryResource>());
|
||||
}
|
||||
if (!m_spStoreOrderResource) {
|
||||
setResource(std::make_shared<StoreApiResources::StoreOrderResource>());
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<restbed::Service> StoreApi::service() {
|
||||
return m_service;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
305
samples/server/petstore/cpp-restbed/generated/3_0/api/StoreApi.h
Normal file
305
samples/server/petstore/cpp-restbed/generated/3_0/api/StoreApi.h
Normal file
@ -0,0 +1,305 @@
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
|
||||
*
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator unset.
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
/*
|
||||
* StoreApi.h
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef StoreApi_H_
|
||||
#define StoreApi_H_
|
||||
|
||||
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
#include <exception>
|
||||
#include <functional>
|
||||
|
||||
#include <corvusoft/restbed/session.hpp>
|
||||
#include <corvusoft/restbed/resource.hpp>
|
||||
#include <corvusoft/restbed/request.hpp>
|
||||
#include <corvusoft/restbed/service.hpp>
|
||||
#include <corvusoft/restbed/settings.hpp>
|
||||
|
||||
#include "Order.h"
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
namespace org {
|
||||
namespace openapitools {
|
||||
namespace server {
|
||||
namespace api {
|
||||
|
||||
using namespace org::openapitools::server::model;
|
||||
|
||||
///
|
||||
/// Exception to flag problems in the handlers
|
||||
///
|
||||
class StoreApiException: public std::exception
|
||||
{
|
||||
public:
|
||||
StoreApiException(int status_code, std::string what);
|
||||
|
||||
int getStatus() const;
|
||||
const char* what() const noexcept override;
|
||||
|
||||
private:
|
||||
int m_status;
|
||||
std::string m_what;
|
||||
};
|
||||
|
||||
namespace StoreApiResources {
|
||||
/// <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>
|
||||
class StoreOrderOrder_idResource: public restbed::Resource
|
||||
{
|
||||
public:
|
||||
StoreOrderOrder_idResource(const std::string& context = "/v2");
|
||||
virtual ~StoreOrderOrder_idResource() = default;
|
||||
|
||||
StoreOrderOrder_idResource(
|
||||
const StoreOrderOrder_idResource& other) = default; // copy constructor
|
||||
StoreOrderOrder_idResource(StoreOrderOrder_idResource&& other) noexcept = default; // move constructor
|
||||
|
||||
StoreOrderOrder_idResource& operator=(const StoreOrderOrder_idResource& other) = default; // copy assignment
|
||||
StoreOrderOrder_idResource& operator=(StoreOrderOrder_idResource&& other) noexcept = default; // move assignment
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
// Set these to implement the server functionality //
|
||||
/////////////////////////////////////////////////////
|
||||
std::function<int(
|
||||
std::string & orderId)> handler_DELETE_func =
|
||||
[](std::string &) -> int
|
||||
{ throw StoreApiException(501, "Not implemented"); };
|
||||
|
||||
std::function<std::pair<int, Order>(
|
||||
int64_t & orderId)> handler_GET_func =
|
||||
[](int64_t &) -> std::pair<int, Order>
|
||||
{ throw StoreApiException(501, "Not implemented"); };
|
||||
|
||||
|
||||
protected:
|
||||
//////////////////////////////////////////////////////////
|
||||
// As an alternative to setting the `std::function`s //
|
||||
// override these to implement the server functionality //
|
||||
//////////////////////////////////////////////////////////
|
||||
|
||||
virtual int handler_DELETE(
|
||||
std::string & orderId);
|
||||
|
||||
virtual std::pair<int, Order> handler_GET(
|
||||
int64_t & orderId);
|
||||
|
||||
protected:
|
||||
//////////////////////////////////////
|
||||
// Override these for customization //
|
||||
//////////////////////////////////////
|
||||
|
||||
virtual std::string extractBodyContent(const std::shared_ptr<restbed::Session>& session);
|
||||
virtual std::string extractFormParamsFromBody(const std::string& paramName, const std::string& body);
|
||||
|
||||
virtual std::pair<int, std::string> handleStoreApiException(const StoreApiException& e);
|
||||
virtual std::pair<int, std::string> handleStdException(const std::exception& e);
|
||||
virtual std::pair<int, std::string> handleUnspecifiedException();
|
||||
|
||||
virtual void setResponseHeader(const std::shared_ptr<restbed::Session>& session,
|
||||
const std::string& header);
|
||||
|
||||
virtual void returnResponse(const std::shared_ptr<restbed::Session>& session,
|
||||
const int status, const std::string& result, std::multimap<std::string, std::string>& contentType);
|
||||
virtual void defaultSessionClose(const std::shared_ptr<restbed::Session>& session,
|
||||
const int status, const std::string& result);
|
||||
|
||||
private:
|
||||
void handler_DELETE_internal(const std::shared_ptr<restbed::Session> session);
|
||||
void handler_GET_internal(const std::shared_ptr<restbed::Session> session);
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Returns pet inventories by status
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Returns a map of status codes to quantities
|
||||
/// </remarks>
|
||||
class StoreInventoryResource: public restbed::Resource
|
||||
{
|
||||
public:
|
||||
StoreInventoryResource(const std::string& context = "/v2");
|
||||
virtual ~StoreInventoryResource() = default;
|
||||
|
||||
StoreInventoryResource(
|
||||
const StoreInventoryResource& other) = default; // copy constructor
|
||||
StoreInventoryResource(StoreInventoryResource&& other) noexcept = default; // move constructor
|
||||
|
||||
StoreInventoryResource& operator=(const StoreInventoryResource& other) = default; // copy assignment
|
||||
StoreInventoryResource& operator=(StoreInventoryResource&& other) noexcept = default; // move assignment
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
// Set these to implement the server functionality //
|
||||
/////////////////////////////////////////////////////
|
||||
std::function<std::pair<int, std::map<std::string, int32_t>>(
|
||||
)> handler_GET_func =
|
||||
[]() -> std::pair<int, std::map<std::string, int32_t>>
|
||||
{ throw StoreApiException(501, "Not implemented"); };
|
||||
|
||||
|
||||
protected:
|
||||
//////////////////////////////////////////////////////////
|
||||
// As an alternative to setting the `std::function`s //
|
||||
// override these to implement the server functionality //
|
||||
//////////////////////////////////////////////////////////
|
||||
|
||||
virtual std::pair<int, std::map<std::string, int32_t>> handler_GET(
|
||||
);
|
||||
|
||||
|
||||
protected:
|
||||
//////////////////////////////////////
|
||||
// Override these for customization //
|
||||
//////////////////////////////////////
|
||||
|
||||
virtual std::string extractBodyContent(const std::shared_ptr<restbed::Session>& session);
|
||||
virtual std::string extractFormParamsFromBody(const std::string& paramName, const std::string& body);
|
||||
|
||||
virtual std::pair<int, std::string> handleStoreApiException(const StoreApiException& e);
|
||||
virtual std::pair<int, std::string> handleStdException(const std::exception& e);
|
||||
virtual std::pair<int, std::string> handleUnspecifiedException();
|
||||
|
||||
virtual void setResponseHeader(const std::shared_ptr<restbed::Session>& session,
|
||||
const std::string& header);
|
||||
|
||||
virtual void returnResponse(const std::shared_ptr<restbed::Session>& session,
|
||||
const int status, const std::string& result, std::multimap<std::string, std::string>& contentType);
|
||||
virtual void defaultSessionClose(const std::shared_ptr<restbed::Session>& session,
|
||||
const int status, const std::string& result);
|
||||
|
||||
private:
|
||||
void handler_GET_internal(const std::shared_ptr<restbed::Session> session);
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Place an order for a pet
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
///
|
||||
/// </remarks>
|
||||
class StoreOrderResource: public restbed::Resource
|
||||
{
|
||||
public:
|
||||
StoreOrderResource(const std::string& context = "/v2");
|
||||
virtual ~StoreOrderResource() = default;
|
||||
|
||||
StoreOrderResource(
|
||||
const StoreOrderResource& other) = default; // copy constructor
|
||||
StoreOrderResource(StoreOrderResource&& other) noexcept = default; // move constructor
|
||||
|
||||
StoreOrderResource& operator=(const StoreOrderResource& other) = default; // copy assignment
|
||||
StoreOrderResource& operator=(StoreOrderResource&& other) noexcept = default; // move assignment
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
// Set these to implement the server functionality //
|
||||
/////////////////////////////////////////////////////
|
||||
std::function<std::pair<int, Order>(
|
||||
Order & order)> handler_POST_func =
|
||||
[](Order &) -> std::pair<int, Order>
|
||||
{ throw StoreApiException(501, "Not implemented"); };
|
||||
|
||||
|
||||
protected:
|
||||
//////////////////////////////////////////////////////////
|
||||
// As an alternative to setting the `std::function`s //
|
||||
// override these to implement the server functionality //
|
||||
//////////////////////////////////////////////////////////
|
||||
|
||||
virtual std::pair<int, Order> handler_POST(
|
||||
Order & order);
|
||||
|
||||
|
||||
protected:
|
||||
//////////////////////////////////////
|
||||
// Override these for customization //
|
||||
//////////////////////////////////////
|
||||
|
||||
virtual std::string extractBodyContent(const std::shared_ptr<restbed::Session>& session);
|
||||
virtual std::string extractFormParamsFromBody(const std::string& paramName, const std::string& body);
|
||||
|
||||
virtual std::pair<int, std::string> handleStoreApiException(const StoreApiException& e);
|
||||
virtual std::pair<int, std::string> handleStdException(const std::exception& e);
|
||||
virtual std::pair<int, std::string> handleUnspecifiedException();
|
||||
|
||||
virtual void setResponseHeader(const std::shared_ptr<restbed::Session>& session,
|
||||
const std::string& header);
|
||||
|
||||
virtual void returnResponse(const std::shared_ptr<restbed::Session>& session,
|
||||
const int status, const std::string& result, std::multimap<std::string, std::string>& contentType);
|
||||
virtual void defaultSessionClose(const std::shared_ptr<restbed::Session>& session,
|
||||
const int status, const std::string& result);
|
||||
|
||||
private:
|
||||
void handler_POST_internal(const std::shared_ptr<restbed::Session> session);
|
||||
};
|
||||
|
||||
} /* namespace StoreApiResources */
|
||||
|
||||
using StoreApiStoreOrderOrder_idResource [[deprecated]] = StoreApiResources::StoreOrderOrder_idResource;
|
||||
using StoreApiStoreInventoryResource [[deprecated]] = StoreApiResources::StoreInventoryResource;
|
||||
using StoreApiStoreOrderResource [[deprecated]] = StoreApiResources::StoreOrderResource;
|
||||
|
||||
//
|
||||
// The restbed service to actually implement the REST server
|
||||
//
|
||||
class StoreApi
|
||||
{
|
||||
public:
|
||||
explicit StoreApi(std::shared_ptr<restbed::Service> const& restbedService);
|
||||
virtual ~StoreApi();
|
||||
|
||||
std::shared_ptr<StoreApiResources::StoreOrderOrder_idResource> getStoreOrderOrder_idResource();
|
||||
std::shared_ptr<StoreApiResources::StoreInventoryResource> getStoreInventoryResource();
|
||||
std::shared_ptr<StoreApiResources::StoreOrderResource> getStoreOrderResource();
|
||||
|
||||
void setResource(std::shared_ptr<StoreApiResources::StoreOrderOrder_idResource> resource);
|
||||
void setResource(std::shared_ptr<StoreApiResources::StoreInventoryResource> resource);
|
||||
void setResource(std::shared_ptr<StoreApiResources::StoreOrderResource> resource);
|
||||
[[deprecated("use setResource()")]]
|
||||
virtual void setStoreApiStoreOrderOrder_idResource(std::shared_ptr<StoreApiResources::StoreOrderOrder_idResource> spStoreApiStoreOrderOrder_idResource);
|
||||
[[deprecated("use setResource()")]]
|
||||
virtual void setStoreApiStoreInventoryResource(std::shared_ptr<StoreApiResources::StoreInventoryResource> spStoreApiStoreInventoryResource);
|
||||
[[deprecated("use setResource()")]]
|
||||
virtual void setStoreApiStoreOrderResource(std::shared_ptr<StoreApiResources::StoreOrderResource> spStoreApiStoreOrderResource);
|
||||
|
||||
virtual void publishDefaultResources();
|
||||
|
||||
virtual std::shared_ptr<restbed::Service> service();
|
||||
|
||||
protected:
|
||||
std::shared_ptr<StoreApiResources::StoreOrderOrder_idResource> m_spStoreOrderOrder_idResource;
|
||||
std::shared_ptr<StoreApiResources::StoreInventoryResource> m_spStoreInventoryResource;
|
||||
std::shared_ptr<StoreApiResources::StoreOrderResource> m_spStoreOrderResource;
|
||||
|
||||
private:
|
||||
std::shared_ptr<restbed::Service> m_service;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* StoreApi_H_ */
|
||||
|
1047
samples/server/petstore/cpp-restbed/generated/3_0/api/UserApi.cpp
Normal file
1047
samples/server/petstore/cpp-restbed/generated/3_0/api/UserApi.cpp
Normal file
File diff suppressed because it is too large
Load Diff
517
samples/server/petstore/cpp-restbed/generated/3_0/api/UserApi.h
Normal file
517
samples/server/petstore/cpp-restbed/generated/3_0/api/UserApi.h
Normal file
@ -0,0 +1,517 @@
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
|
||||
*
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator unset.
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
/*
|
||||
* UserApi.h
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef UserApi_H_
|
||||
#define UserApi_H_
|
||||
|
||||
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
#include <exception>
|
||||
#include <functional>
|
||||
|
||||
#include <corvusoft/restbed/session.hpp>
|
||||
#include <corvusoft/restbed/resource.hpp>
|
||||
#include <corvusoft/restbed/request.hpp>
|
||||
#include <corvusoft/restbed/service.hpp>
|
||||
#include <corvusoft/restbed/settings.hpp>
|
||||
|
||||
#include "User.h"
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace org {
|
||||
namespace openapitools {
|
||||
namespace server {
|
||||
namespace api {
|
||||
|
||||
using namespace org::openapitools::server::model;
|
||||
|
||||
///
|
||||
/// Exception to flag problems in the handlers
|
||||
///
|
||||
class UserApiException: public std::exception
|
||||
{
|
||||
public:
|
||||
UserApiException(int status_code, std::string what);
|
||||
|
||||
int getStatus() const;
|
||||
const char* what() const noexcept override;
|
||||
|
||||
private:
|
||||
int m_status;
|
||||
std::string m_what;
|
||||
};
|
||||
|
||||
namespace UserApiResources {
|
||||
/// <summary>
|
||||
/// Create user
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This can only be done by the logged in user.
|
||||
/// </remarks>
|
||||
class UserResource: public restbed::Resource
|
||||
{
|
||||
public:
|
||||
UserResource(const std::string& context = "/v2");
|
||||
virtual ~UserResource() = default;
|
||||
|
||||
UserResource(
|
||||
const UserResource& other) = default; // copy constructor
|
||||
UserResource(UserResource&& other) noexcept = default; // move constructor
|
||||
|
||||
UserResource& operator=(const UserResource& other) = default; // copy assignment
|
||||
UserResource& operator=(UserResource&& other) noexcept = default; // move assignment
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
// Set these to implement the server functionality //
|
||||
/////////////////////////////////////////////////////
|
||||
std::function<int(
|
||||
User & user)> handler_POST_func =
|
||||
[](User &) -> int
|
||||
{ throw UserApiException(501, "Not implemented"); };
|
||||
|
||||
|
||||
protected:
|
||||
//////////////////////////////////////////////////////////
|
||||
// As an alternative to setting the `std::function`s //
|
||||
// override these to implement the server functionality //
|
||||
//////////////////////////////////////////////////////////
|
||||
|
||||
virtual int handler_POST(
|
||||
User & user);
|
||||
|
||||
|
||||
protected:
|
||||
//////////////////////////////////////
|
||||
// Override these for customization //
|
||||
//////////////////////////////////////
|
||||
|
||||
virtual std::string extractBodyContent(const std::shared_ptr<restbed::Session>& session);
|
||||
virtual std::string extractFormParamsFromBody(const std::string& paramName, const std::string& body);
|
||||
|
||||
virtual std::pair<int, std::string> handleUserApiException(const UserApiException& e);
|
||||
virtual std::pair<int, std::string> handleStdException(const std::exception& e);
|
||||
virtual std::pair<int, std::string> handleUnspecifiedException();
|
||||
|
||||
virtual void setResponseHeader(const std::shared_ptr<restbed::Session>& session,
|
||||
const std::string& header);
|
||||
|
||||
virtual void returnResponse(const std::shared_ptr<restbed::Session>& session,
|
||||
const int status, const std::string& result, std::multimap<std::string, std::string>& contentType);
|
||||
virtual void defaultSessionClose(const std::shared_ptr<restbed::Session>& session,
|
||||
const int status, const std::string& result);
|
||||
|
||||
private:
|
||||
void handler_POST_internal(const std::shared_ptr<restbed::Session> session);
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Creates list of users with given input array
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
///
|
||||
/// </remarks>
|
||||
class UserCreateWithArrayResource: public restbed::Resource
|
||||
{
|
||||
public:
|
||||
UserCreateWithArrayResource(const std::string& context = "/v2");
|
||||
virtual ~UserCreateWithArrayResource() = default;
|
||||
|
||||
UserCreateWithArrayResource(
|
||||
const UserCreateWithArrayResource& other) = default; // copy constructor
|
||||
UserCreateWithArrayResource(UserCreateWithArrayResource&& other) noexcept = default; // move constructor
|
||||
|
||||
UserCreateWithArrayResource& operator=(const UserCreateWithArrayResource& other) = default; // copy assignment
|
||||
UserCreateWithArrayResource& operator=(UserCreateWithArrayResource&& other) noexcept = default; // move assignment
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
// Set these to implement the server functionality //
|
||||
/////////////////////////////////////////////////////
|
||||
std::function<int(
|
||||
std::vector<User> & user)> handler_POST_func =
|
||||
[](std::vector<User> &) -> int
|
||||
{ throw UserApiException(501, "Not implemented"); };
|
||||
|
||||
|
||||
protected:
|
||||
//////////////////////////////////////////////////////////
|
||||
// As an alternative to setting the `std::function`s //
|
||||
// override these to implement the server functionality //
|
||||
//////////////////////////////////////////////////////////
|
||||
|
||||
virtual int handler_POST(
|
||||
std::vector<User> & user);
|
||||
|
||||
|
||||
protected:
|
||||
//////////////////////////////////////
|
||||
// Override these for customization //
|
||||
//////////////////////////////////////
|
||||
|
||||
virtual std::string extractBodyContent(const std::shared_ptr<restbed::Session>& session);
|
||||
virtual std::string extractFormParamsFromBody(const std::string& paramName, const std::string& body);
|
||||
|
||||
virtual std::pair<int, std::string> handleUserApiException(const UserApiException& e);
|
||||
virtual std::pair<int, std::string> handleStdException(const std::exception& e);
|
||||
virtual std::pair<int, std::string> handleUnspecifiedException();
|
||||
|
||||
virtual void setResponseHeader(const std::shared_ptr<restbed::Session>& session,
|
||||
const std::string& header);
|
||||
|
||||
virtual void returnResponse(const std::shared_ptr<restbed::Session>& session,
|
||||
const int status, const std::string& result, std::multimap<std::string, std::string>& contentType);
|
||||
virtual void defaultSessionClose(const std::shared_ptr<restbed::Session>& session,
|
||||
const int status, const std::string& result);
|
||||
|
||||
private:
|
||||
void handler_POST_internal(const std::shared_ptr<restbed::Session> session);
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Creates list of users with given input array
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
///
|
||||
/// </remarks>
|
||||
class UserCreateWithListResource: public restbed::Resource
|
||||
{
|
||||
public:
|
||||
UserCreateWithListResource(const std::string& context = "/v2");
|
||||
virtual ~UserCreateWithListResource() = default;
|
||||
|
||||
UserCreateWithListResource(
|
||||
const UserCreateWithListResource& other) = default; // copy constructor
|
||||
UserCreateWithListResource(UserCreateWithListResource&& other) noexcept = default; // move constructor
|
||||
|
||||
UserCreateWithListResource& operator=(const UserCreateWithListResource& other) = default; // copy assignment
|
||||
UserCreateWithListResource& operator=(UserCreateWithListResource&& other) noexcept = default; // move assignment
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
// Set these to implement the server functionality //
|
||||
/////////////////////////////////////////////////////
|
||||
std::function<int(
|
||||
std::vector<User> & user)> handler_POST_func =
|
||||
[](std::vector<User> &) -> int
|
||||
{ throw UserApiException(501, "Not implemented"); };
|
||||
|
||||
|
||||
protected:
|
||||
//////////////////////////////////////////////////////////
|
||||
// As an alternative to setting the `std::function`s //
|
||||
// override these to implement the server functionality //
|
||||
//////////////////////////////////////////////////////////
|
||||
|
||||
virtual int handler_POST(
|
||||
std::vector<User> & user);
|
||||
|
||||
|
||||
protected:
|
||||
//////////////////////////////////////
|
||||
// Override these for customization //
|
||||
//////////////////////////////////////
|
||||
|
||||
virtual std::string extractBodyContent(const std::shared_ptr<restbed::Session>& session);
|
||||
virtual std::string extractFormParamsFromBody(const std::string& paramName, const std::string& body);
|
||||
|
||||
virtual std::pair<int, std::string> handleUserApiException(const UserApiException& e);
|
||||
virtual std::pair<int, std::string> handleStdException(const std::exception& e);
|
||||
virtual std::pair<int, std::string> handleUnspecifiedException();
|
||||
|
||||
virtual void setResponseHeader(const std::shared_ptr<restbed::Session>& session,
|
||||
const std::string& header);
|
||||
|
||||
virtual void returnResponse(const std::shared_ptr<restbed::Session>& session,
|
||||
const int status, const std::string& result, std::multimap<std::string, std::string>& contentType);
|
||||
virtual void defaultSessionClose(const std::shared_ptr<restbed::Session>& session,
|
||||
const int status, const std::string& result);
|
||||
|
||||
private:
|
||||
void handler_POST_internal(const std::shared_ptr<restbed::Session> session);
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Delete user
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This can only be done by the logged in user.
|
||||
/// </remarks>
|
||||
class UserUsernameResource: public restbed::Resource
|
||||
{
|
||||
public:
|
||||
UserUsernameResource(const std::string& context = "/v2");
|
||||
virtual ~UserUsernameResource() = default;
|
||||
|
||||
UserUsernameResource(
|
||||
const UserUsernameResource& other) = default; // copy constructor
|
||||
UserUsernameResource(UserUsernameResource&& other) noexcept = default; // move constructor
|
||||
|
||||
UserUsernameResource& operator=(const UserUsernameResource& other) = default; // copy assignment
|
||||
UserUsernameResource& operator=(UserUsernameResource&& other) noexcept = default; // move assignment
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
// Set these to implement the server functionality //
|
||||
/////////////////////////////////////////////////////
|
||||
std::function<int(
|
||||
std::string & username)> handler_DELETE_func =
|
||||
[](std::string &) -> int
|
||||
{ throw UserApiException(501, "Not implemented"); };
|
||||
|
||||
std::function<std::pair<int, User>(
|
||||
std::string & username)> handler_GET_func =
|
||||
[](std::string &) -> std::pair<int, User>
|
||||
{ throw UserApiException(501, "Not implemented"); };
|
||||
|
||||
std::function<int(
|
||||
std::string & username, User & user)> handler_PUT_func =
|
||||
[](std::string &, User &) -> int
|
||||
{ throw UserApiException(501, "Not implemented"); };
|
||||
|
||||
|
||||
protected:
|
||||
//////////////////////////////////////////////////////////
|
||||
// As an alternative to setting the `std::function`s //
|
||||
// override these to implement the server functionality //
|
||||
//////////////////////////////////////////////////////////
|
||||
|
||||
virtual int handler_DELETE(
|
||||
std::string & username);
|
||||
|
||||
virtual std::pair<int, User> handler_GET(
|
||||
std::string & username);
|
||||
virtual int handler_PUT(
|
||||
std::string & username, User & user);
|
||||
|
||||
protected:
|
||||
//////////////////////////////////////
|
||||
// Override these for customization //
|
||||
//////////////////////////////////////
|
||||
|
||||
virtual std::string extractBodyContent(const std::shared_ptr<restbed::Session>& session);
|
||||
virtual std::string extractFormParamsFromBody(const std::string& paramName, const std::string& body);
|
||||
|
||||
virtual std::pair<int, std::string> handleUserApiException(const UserApiException& e);
|
||||
virtual std::pair<int, std::string> handleStdException(const std::exception& e);
|
||||
virtual std::pair<int, std::string> handleUnspecifiedException();
|
||||
|
||||
virtual void setResponseHeader(const std::shared_ptr<restbed::Session>& session,
|
||||
const std::string& header);
|
||||
|
||||
virtual void returnResponse(const std::shared_ptr<restbed::Session>& session,
|
||||
const int status, const std::string& result, std::multimap<std::string, std::string>& contentType);
|
||||
virtual void defaultSessionClose(const std::shared_ptr<restbed::Session>& session,
|
||||
const int status, const std::string& result);
|
||||
|
||||
private:
|
||||
void handler_DELETE_internal(const std::shared_ptr<restbed::Session> session);
|
||||
void handler_GET_internal(const std::shared_ptr<restbed::Session> session);
|
||||
void handler_PUT_internal(const std::shared_ptr<restbed::Session> session);
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Logs user into the system
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
///
|
||||
/// </remarks>
|
||||
class UserLoginResource: public restbed::Resource
|
||||
{
|
||||
public:
|
||||
UserLoginResource(const std::string& context = "/v2");
|
||||
virtual ~UserLoginResource() = default;
|
||||
|
||||
UserLoginResource(
|
||||
const UserLoginResource& other) = default; // copy constructor
|
||||
UserLoginResource(UserLoginResource&& other) noexcept = default; // move constructor
|
||||
|
||||
UserLoginResource& operator=(const UserLoginResource& other) = default; // copy assignment
|
||||
UserLoginResource& operator=(UserLoginResource&& other) noexcept = default; // move assignment
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
// Set these to implement the server functionality //
|
||||
/////////////////////////////////////////////////////
|
||||
std::function<std::pair<int, std::string>(
|
||||
std::string & username, std::string & password)> handler_GET_func =
|
||||
[](std::string &, std::string &) -> std::pair<int, std::string>
|
||||
{ throw UserApiException(501, "Not implemented"); };
|
||||
|
||||
|
||||
protected:
|
||||
//////////////////////////////////////////////////////////
|
||||
// As an alternative to setting the `std::function`s //
|
||||
// override these to implement the server functionality //
|
||||
//////////////////////////////////////////////////////////
|
||||
|
||||
virtual std::pair<int, std::string> handler_GET(
|
||||
std::string & username, std::string & password);
|
||||
|
||||
|
||||
protected:
|
||||
//////////////////////////////////////
|
||||
// Override these for customization //
|
||||
//////////////////////////////////////
|
||||
|
||||
virtual std::string extractBodyContent(const std::shared_ptr<restbed::Session>& session);
|
||||
virtual std::string extractFormParamsFromBody(const std::string& paramName, const std::string& body);
|
||||
|
||||
virtual std::pair<int, std::string> handleUserApiException(const UserApiException& e);
|
||||
virtual std::pair<int, std::string> handleStdException(const std::exception& e);
|
||||
virtual std::pair<int, std::string> handleUnspecifiedException();
|
||||
|
||||
virtual void setResponseHeader(const std::shared_ptr<restbed::Session>& session,
|
||||
const std::string& header);
|
||||
|
||||
virtual void returnResponse(const std::shared_ptr<restbed::Session>& session,
|
||||
const int status, const std::string& result, std::multimap<std::string, std::string>& contentType);
|
||||
virtual void defaultSessionClose(const std::shared_ptr<restbed::Session>& session,
|
||||
const int status, const std::string& result);
|
||||
|
||||
private:
|
||||
void handler_GET_internal(const std::shared_ptr<restbed::Session> session);
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Logs out current logged in user session
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
///
|
||||
/// </remarks>
|
||||
class UserLogoutResource: public restbed::Resource
|
||||
{
|
||||
public:
|
||||
UserLogoutResource(const std::string& context = "/v2");
|
||||
virtual ~UserLogoutResource() = default;
|
||||
|
||||
UserLogoutResource(
|
||||
const UserLogoutResource& other) = default; // copy constructor
|
||||
UserLogoutResource(UserLogoutResource&& other) noexcept = default; // move constructor
|
||||
|
||||
UserLogoutResource& operator=(const UserLogoutResource& other) = default; // copy assignment
|
||||
UserLogoutResource& operator=(UserLogoutResource&& other) noexcept = default; // move assignment
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
// Set these to implement the server functionality //
|
||||
/////////////////////////////////////////////////////
|
||||
std::function<int(
|
||||
)> handler_GET_func =
|
||||
[]() -> int
|
||||
{ throw UserApiException(501, "Not implemented"); };
|
||||
|
||||
|
||||
protected:
|
||||
//////////////////////////////////////////////////////////
|
||||
// As an alternative to setting the `std::function`s //
|
||||
// override these to implement the server functionality //
|
||||
//////////////////////////////////////////////////////////
|
||||
|
||||
virtual int handler_GET(
|
||||
);
|
||||
|
||||
|
||||
protected:
|
||||
//////////////////////////////////////
|
||||
// Override these for customization //
|
||||
//////////////////////////////////////
|
||||
|
||||
virtual std::string extractBodyContent(const std::shared_ptr<restbed::Session>& session);
|
||||
virtual std::string extractFormParamsFromBody(const std::string& paramName, const std::string& body);
|
||||
|
||||
virtual std::pair<int, std::string> handleUserApiException(const UserApiException& e);
|
||||
virtual std::pair<int, std::string> handleStdException(const std::exception& e);
|
||||
virtual std::pair<int, std::string> handleUnspecifiedException();
|
||||
|
||||
virtual void setResponseHeader(const std::shared_ptr<restbed::Session>& session,
|
||||
const std::string& header);
|
||||
|
||||
virtual void returnResponse(const std::shared_ptr<restbed::Session>& session,
|
||||
const int status, const std::string& result, std::multimap<std::string, std::string>& contentType);
|
||||
virtual void defaultSessionClose(const std::shared_ptr<restbed::Session>& session,
|
||||
const int status, const std::string& result);
|
||||
|
||||
private:
|
||||
void handler_GET_internal(const std::shared_ptr<restbed::Session> session);
|
||||
};
|
||||
|
||||
} /* namespace UserApiResources */
|
||||
|
||||
using UserApiUserResource [[deprecated]] = UserApiResources::UserResource;
|
||||
using UserApiUserCreateWithArrayResource [[deprecated]] = UserApiResources::UserCreateWithArrayResource;
|
||||
using UserApiUserCreateWithListResource [[deprecated]] = UserApiResources::UserCreateWithListResource;
|
||||
using UserApiUserUsernameResource [[deprecated]] = UserApiResources::UserUsernameResource;
|
||||
using UserApiUserLoginResource [[deprecated]] = UserApiResources::UserLoginResource;
|
||||
using UserApiUserLogoutResource [[deprecated]] = UserApiResources::UserLogoutResource;
|
||||
|
||||
//
|
||||
// The restbed service to actually implement the REST server
|
||||
//
|
||||
class UserApi
|
||||
{
|
||||
public:
|
||||
explicit UserApi(std::shared_ptr<restbed::Service> const& restbedService);
|
||||
virtual ~UserApi();
|
||||
|
||||
std::shared_ptr<UserApiResources::UserResource> getUserResource();
|
||||
std::shared_ptr<UserApiResources::UserCreateWithArrayResource> getUserCreateWithArrayResource();
|
||||
std::shared_ptr<UserApiResources::UserCreateWithListResource> getUserCreateWithListResource();
|
||||
std::shared_ptr<UserApiResources::UserUsernameResource> getUserUsernameResource();
|
||||
std::shared_ptr<UserApiResources::UserLoginResource> getUserLoginResource();
|
||||
std::shared_ptr<UserApiResources::UserLogoutResource> getUserLogoutResource();
|
||||
|
||||
void setResource(std::shared_ptr<UserApiResources::UserResource> resource);
|
||||
void setResource(std::shared_ptr<UserApiResources::UserCreateWithArrayResource> resource);
|
||||
void setResource(std::shared_ptr<UserApiResources::UserCreateWithListResource> resource);
|
||||
void setResource(std::shared_ptr<UserApiResources::UserUsernameResource> resource);
|
||||
void setResource(std::shared_ptr<UserApiResources::UserLoginResource> resource);
|
||||
void setResource(std::shared_ptr<UserApiResources::UserLogoutResource> resource);
|
||||
[[deprecated("use setResource()")]]
|
||||
virtual void setUserApiUserResource(std::shared_ptr<UserApiResources::UserResource> spUserApiUserResource);
|
||||
[[deprecated("use setResource()")]]
|
||||
virtual void setUserApiUserCreateWithArrayResource(std::shared_ptr<UserApiResources::UserCreateWithArrayResource> spUserApiUserCreateWithArrayResource);
|
||||
[[deprecated("use setResource()")]]
|
||||
virtual void setUserApiUserCreateWithListResource(std::shared_ptr<UserApiResources::UserCreateWithListResource> spUserApiUserCreateWithListResource);
|
||||
[[deprecated("use setResource()")]]
|
||||
virtual void setUserApiUserUsernameResource(std::shared_ptr<UserApiResources::UserUsernameResource> spUserApiUserUsernameResource);
|
||||
[[deprecated("use setResource()")]]
|
||||
virtual void setUserApiUserLoginResource(std::shared_ptr<UserApiResources::UserLoginResource> spUserApiUserLoginResource);
|
||||
[[deprecated("use setResource()")]]
|
||||
virtual void setUserApiUserLogoutResource(std::shared_ptr<UserApiResources::UserLogoutResource> spUserApiUserLogoutResource);
|
||||
|
||||
virtual void publishDefaultResources();
|
||||
|
||||
virtual std::shared_ptr<restbed::Service> service();
|
||||
|
||||
protected:
|
||||
std::shared_ptr<UserApiResources::UserResource> m_spUserResource;
|
||||
std::shared_ptr<UserApiResources::UserCreateWithArrayResource> m_spUserCreateWithArrayResource;
|
||||
std::shared_ptr<UserApiResources::UserCreateWithListResource> m_spUserCreateWithListResource;
|
||||
std::shared_ptr<UserApiResources::UserUsernameResource> m_spUserUsernameResource;
|
||||
std::shared_ptr<UserApiResources::UserLoginResource> m_spUserLoginResource;
|
||||
std::shared_ptr<UserApiResources::UserLogoutResource> m_spUserLogoutResource;
|
||||
|
||||
private:
|
||||
std::shared_ptr<restbed::Service> m_service;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* UserApi_H_ */
|
||||
|
@ -0,0 +1,57 @@
|
||||
#!/bin/sh
|
||||
# ref: https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/
|
||||
#
|
||||
# Usage example: /bin/sh ./git_push.sh wing328 openapi-petstore-perl "minor update" "gitlab.com"
|
||||
|
||||
git_user_id=$1
|
||||
git_repo_id=$2
|
||||
release_note=$3
|
||||
git_host=$4
|
||||
|
||||
if [ "$git_host" = "" ]; then
|
||||
git_host="github.com"
|
||||
echo "[INFO] No command line input provided. Set \$git_host to $git_host"
|
||||
fi
|
||||
|
||||
if [ "$git_user_id" = "" ]; then
|
||||
git_user_id="GIT_USER_ID"
|
||||
echo "[INFO] No command line input provided. Set \$git_user_id to $git_user_id"
|
||||
fi
|
||||
|
||||
if [ "$git_repo_id" = "" ]; then
|
||||
git_repo_id="GIT_REPO_ID"
|
||||
echo "[INFO] No command line input provided. Set \$git_repo_id to $git_repo_id"
|
||||
fi
|
||||
|
||||
if [ "$release_note" = "" ]; then
|
||||
release_note="Minor update"
|
||||
echo "[INFO] No command line input provided. Set \$release_note to $release_note"
|
||||
fi
|
||||
|
||||
# Initialize the local directory as a Git repository
|
||||
git init
|
||||
|
||||
# Adds the files in the local repository and stages them for commit.
|
||||
git add .
|
||||
|
||||
# Commits the tracked changes and prepares them to be pushed to a remote repository.
|
||||
git commit -m "$release_note"
|
||||
|
||||
# Sets the new remote
|
||||
git_remote=$(git remote)
|
||||
if [ "$git_remote" = "" ]; then # git remote not defined
|
||||
|
||||
if [ "$GIT_TOKEN" = "" ]; then
|
||||
echo "[INFO] \$GIT_TOKEN (environment variable) is not set. Using the git credential in your environment."
|
||||
git remote add origin https://${git_host}/${git_user_id}/${git_repo_id}.git
|
||||
else
|
||||
git remote add origin https://${git_user_id}:"${GIT_TOKEN}"@${git_host}/${git_user_id}/${git_repo_id}.git
|
||||
fi
|
||||
|
||||
fi
|
||||
|
||||
git pull origin master
|
||||
|
||||
# Pushes (Forces) the changes in the local repository up to the remote repository
|
||||
echo "Git pushing to https://${git_host}/${git_user_id}/${git_repo_id}.git"
|
||||
git push origin master 2>&1 | grep -v 'To https'
|
@ -0,0 +1,132 @@
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
|
||||
*
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator unset.
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#include "AdditionalPropertiesClass.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <sstream>
|
||||
#include <stdexcept>
|
||||
#include <regex>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <boost/property_tree/ptree.hpp>
|
||||
#include <boost/property_tree/json_parser.hpp>
|
||||
#include "helpers.h"
|
||||
|
||||
using boost::property_tree::ptree;
|
||||
using boost::property_tree::read_json;
|
||||
using boost::property_tree::write_json;
|
||||
|
||||
namespace org {
|
||||
namespace openapitools {
|
||||
namespace server {
|
||||
namespace model {
|
||||
|
||||
AdditionalPropertiesClass::AdditionalPropertiesClass(boost::property_tree::ptree const& pt)
|
||||
{
|
||||
fromPropertyTree(pt);
|
||||
}
|
||||
|
||||
|
||||
std::string AdditionalPropertiesClass::toJsonString(bool prettyJson /* = false */) const
|
||||
{
|
||||
std::stringstream ss;
|
||||
write_json(ss, this->toPropertyTree(), prettyJson);
|
||||
// workaround inspired by: https://stackoverflow.com/a/56395440
|
||||
std::regex reg("\\\"([0-9]+\\.{0,1}[0-9]*)\\\"");
|
||||
std::string result = std::regex_replace(ss.str(), reg, "$1");
|
||||
return result;
|
||||
}
|
||||
|
||||
void AdditionalPropertiesClass::fromJsonString(std::string const& jsonString)
|
||||
{
|
||||
std::stringstream ss(jsonString);
|
||||
ptree pt;
|
||||
read_json(ss,pt);
|
||||
this->fromPropertyTree(pt);
|
||||
}
|
||||
|
||||
ptree AdditionalPropertiesClass::toPropertyTree() const
|
||||
{
|
||||
ptree pt;
|
||||
ptree tmp_node;
|
||||
// generate tree for Map_property
|
||||
if (!m_Map_property.empty()) {
|
||||
tmp_node = toPt(m_Map_property);
|
||||
pt.add_child("map_property", tmp_node);
|
||||
}
|
||||
tmp_node.clear();
|
||||
// generate tree for Map_of_map_property
|
||||
if (!m_Map_of_map_property.empty()) {
|
||||
tmp_node = toPt(m_Map_of_map_property);
|
||||
pt.add_child("map_of_map_property", tmp_node);
|
||||
}
|
||||
tmp_node.clear();
|
||||
return pt;
|
||||
}
|
||||
|
||||
void AdditionalPropertiesClass::fromPropertyTree(ptree const &pt)
|
||||
{
|
||||
ptree tmp_node;
|
||||
if (pt.get_child_optional("map_property")) {
|
||||
m_Map_property = fromPt<std::map<std::string, std::string>>(pt.get_child("map_property"));
|
||||
}
|
||||
if (pt.get_child_optional("map_of_map_property")) {
|
||||
m_Map_of_map_property = fromPt<std::map<std::string, std::map<std::string, std::string>>>(pt.get_child("map_of_map_property"));
|
||||
}
|
||||
}
|
||||
|
||||
std::map<std::string, std::string> AdditionalPropertiesClass::getMapProperty() const
|
||||
{
|
||||
return m_Map_property;
|
||||
}
|
||||
|
||||
void AdditionalPropertiesClass::setMapProperty(std::map<std::string, std::string> value)
|
||||
{
|
||||
m_Map_property = value;
|
||||
}
|
||||
|
||||
|
||||
std::map<std::string, std::map<std::string, std::string>> AdditionalPropertiesClass::getMapOfMapProperty() const
|
||||
{
|
||||
return m_Map_of_map_property;
|
||||
}
|
||||
|
||||
void AdditionalPropertiesClass::setMapOfMapProperty(std::map<std::string, std::map<std::string, std::string>> value)
|
||||
{
|
||||
m_Map_of_map_property = value;
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::vector<AdditionalPropertiesClass> createAdditionalPropertiesClassVectorFromJsonString(const std::string& json)
|
||||
{
|
||||
std::stringstream sstream(json);
|
||||
boost::property_tree::ptree pt;
|
||||
boost::property_tree::json_parser::read_json(sstream,pt);
|
||||
|
||||
auto vec = std::vector<AdditionalPropertiesClass>();
|
||||
for (const auto& child: pt) {
|
||||
vec.emplace_back(AdditionalPropertiesClass(child.second));
|
||||
}
|
||||
|
||||
return vec;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,97 @@
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
|
||||
*
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator unset.
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
/*
|
||||
* AdditionalPropertiesClass.h
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef AdditionalPropertiesClass_H_
|
||||
#define AdditionalPropertiesClass_H_
|
||||
|
||||
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <boost/property_tree/ptree.hpp>
|
||||
#include "helpers.h"
|
||||
|
||||
namespace org {
|
||||
namespace openapitools {
|
||||
namespace server {
|
||||
namespace model {
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
class AdditionalPropertiesClass
|
||||
{
|
||||
public:
|
||||
AdditionalPropertiesClass() = default;
|
||||
explicit AdditionalPropertiesClass(boost::property_tree::ptree const& pt);
|
||||
virtual ~AdditionalPropertiesClass() = default;
|
||||
|
||||
AdditionalPropertiesClass(const AdditionalPropertiesClass& other) = default; // copy constructor
|
||||
AdditionalPropertiesClass(AdditionalPropertiesClass&& other) noexcept = default; // move constructor
|
||||
|
||||
AdditionalPropertiesClass& operator=(const AdditionalPropertiesClass& other) = default; // copy assignment
|
||||
AdditionalPropertiesClass& operator=(AdditionalPropertiesClass&& other) noexcept = default; // move assignment
|
||||
|
||||
std::string toJsonString(bool prettyJson = false) const;
|
||||
void fromJsonString(std::string const& jsonString);
|
||||
boost::property_tree::ptree toPropertyTree() const;
|
||||
void fromPropertyTree(boost::property_tree::ptree const& pt);
|
||||
|
||||
|
||||
/////////////////////////////////////////////
|
||||
/// AdditionalPropertiesClass members
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
std::map<std::string, std::string> getMapProperty() const;
|
||||
void setMapProperty(std::map<std::string, std::string> value);
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
std::map<std::string, std::map<std::string, std::string>> getMapOfMapProperty() const;
|
||||
void setMapOfMapProperty(std::map<std::string, std::map<std::string, std::string>> value);
|
||||
|
||||
protected:
|
||||
std::map<std::string, std::string> m_Map_property;
|
||||
std::map<std::string, std::map<std::string, std::string>> m_Map_of_map_property;
|
||||
};
|
||||
|
||||
std::vector<AdditionalPropertiesClass> createAdditionalPropertiesClassVectorFromJsonString(const std::string& json);
|
||||
|
||||
template<>
|
||||
inline boost::property_tree::ptree toPt<AdditionalPropertiesClass>(const AdditionalPropertiesClass& val) {
|
||||
return val.toPropertyTree();
|
||||
}
|
||||
|
||||
template<>
|
||||
inline AdditionalPropertiesClass fromPt<AdditionalPropertiesClass>(const boost::property_tree::ptree& pt) {
|
||||
AdditionalPropertiesClass ret;
|
||||
ret.fromPropertyTree(pt);
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* AdditionalPropertiesClass_H_ */
|
@ -0,0 +1,120 @@
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
|
||||
*
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator unset.
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#include "AllOfWithSingleRef.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <sstream>
|
||||
#include <stdexcept>
|
||||
#include <regex>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <boost/property_tree/ptree.hpp>
|
||||
#include <boost/property_tree/json_parser.hpp>
|
||||
#include "helpers.h"
|
||||
|
||||
using boost::property_tree::ptree;
|
||||
using boost::property_tree::read_json;
|
||||
using boost::property_tree::write_json;
|
||||
|
||||
namespace org {
|
||||
namespace openapitools {
|
||||
namespace server {
|
||||
namespace model {
|
||||
|
||||
AllOfWithSingleRef::AllOfWithSingleRef(boost::property_tree::ptree const& pt)
|
||||
{
|
||||
fromPropertyTree(pt);
|
||||
}
|
||||
|
||||
|
||||
std::string AllOfWithSingleRef::toJsonString(bool prettyJson /* = false */) const
|
||||
{
|
||||
std::stringstream ss;
|
||||
write_json(ss, this->toPropertyTree(), prettyJson);
|
||||
// workaround inspired by: https://stackoverflow.com/a/56395440
|
||||
std::regex reg("\\\"([0-9]+\\.{0,1}[0-9]*)\\\"");
|
||||
std::string result = std::regex_replace(ss.str(), reg, "$1");
|
||||
return result;
|
||||
}
|
||||
|
||||
void AllOfWithSingleRef::fromJsonString(std::string const& jsonString)
|
||||
{
|
||||
std::stringstream ss(jsonString);
|
||||
ptree pt;
|
||||
read_json(ss,pt);
|
||||
this->fromPropertyTree(pt);
|
||||
}
|
||||
|
||||
ptree AllOfWithSingleRef::toPropertyTree() const
|
||||
{
|
||||
ptree pt;
|
||||
ptree tmp_node;
|
||||
pt.put("username", m_Username);
|
||||
pt.add_child("SingleRefType", m_SingleRefType.toPropertyTree());
|
||||
return pt;
|
||||
}
|
||||
|
||||
void AllOfWithSingleRef::fromPropertyTree(ptree const &pt)
|
||||
{
|
||||
ptree tmp_node;
|
||||
m_Username = pt.get("username", "");
|
||||
if (pt.get_child_optional("SingleRefType")) {
|
||||
m_SingleRefType = fromPt<SingleRefType>(pt.get_child("SingleRefType"));
|
||||
}
|
||||
}
|
||||
|
||||
std::string AllOfWithSingleRef::getUsername() const
|
||||
{
|
||||
return m_Username;
|
||||
}
|
||||
|
||||
void AllOfWithSingleRef::setUsername(std::string value)
|
||||
{
|
||||
m_Username = value;
|
||||
}
|
||||
|
||||
|
||||
SingleRefType AllOfWithSingleRef::getSingleRefType() const
|
||||
{
|
||||
return m_SingleRefType;
|
||||
}
|
||||
|
||||
void AllOfWithSingleRef::setSingleRefType(SingleRefType value)
|
||||
{
|
||||
m_SingleRefType = value;
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::vector<AllOfWithSingleRef> createAllOfWithSingleRefVectorFromJsonString(const std::string& json)
|
||||
{
|
||||
std::stringstream sstream(json);
|
||||
boost::property_tree::ptree pt;
|
||||
boost::property_tree::json_parser::read_json(sstream,pt);
|
||||
|
||||
auto vec = std::vector<AllOfWithSingleRef>();
|
||||
for (const auto& child: pt) {
|
||||
vec.emplace_back(AllOfWithSingleRef(child.second));
|
||||
}
|
||||
|
||||
return vec;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,97 @@
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
|
||||
*
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator unset.
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
/*
|
||||
* AllOfWithSingleRef.h
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef AllOfWithSingleRef_H_
|
||||
#define AllOfWithSingleRef_H_
|
||||
|
||||
|
||||
|
||||
#include <string>
|
||||
#include "SingleRefType.h"
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <boost/property_tree/ptree.hpp>
|
||||
#include "helpers.h"
|
||||
|
||||
namespace org {
|
||||
namespace openapitools {
|
||||
namespace server {
|
||||
namespace model {
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
class AllOfWithSingleRef
|
||||
{
|
||||
public:
|
||||
AllOfWithSingleRef() = default;
|
||||
explicit AllOfWithSingleRef(boost::property_tree::ptree const& pt);
|
||||
virtual ~AllOfWithSingleRef() = default;
|
||||
|
||||
AllOfWithSingleRef(const AllOfWithSingleRef& other) = default; // copy constructor
|
||||
AllOfWithSingleRef(AllOfWithSingleRef&& other) noexcept = default; // move constructor
|
||||
|
||||
AllOfWithSingleRef& operator=(const AllOfWithSingleRef& other) = default; // copy assignment
|
||||
AllOfWithSingleRef& operator=(AllOfWithSingleRef&& other) noexcept = default; // move assignment
|
||||
|
||||
std::string toJsonString(bool prettyJson = false) const;
|
||||
void fromJsonString(std::string const& jsonString);
|
||||
boost::property_tree::ptree toPropertyTree() const;
|
||||
void fromPropertyTree(boost::property_tree::ptree const& pt);
|
||||
|
||||
|
||||
/////////////////////////////////////////////
|
||||
/// AllOfWithSingleRef members
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
std::string getUsername() const;
|
||||
void setUsername(std::string value);
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
SingleRefType getSingleRefType() const;
|
||||
void setSingleRefType(SingleRefType value);
|
||||
|
||||
protected:
|
||||
std::string m_Username = "";
|
||||
SingleRefType m_SingleRefType;
|
||||
};
|
||||
|
||||
std::vector<AllOfWithSingleRef> createAllOfWithSingleRefVectorFromJsonString(const std::string& json);
|
||||
|
||||
template<>
|
||||
inline boost::property_tree::ptree toPt<AllOfWithSingleRef>(const AllOfWithSingleRef& val) {
|
||||
return val.toPropertyTree();
|
||||
}
|
||||
|
||||
template<>
|
||||
inline AllOfWithSingleRef fromPt<AllOfWithSingleRef>(const boost::property_tree::ptree& pt) {
|
||||
AllOfWithSingleRef ret;
|
||||
ret.fromPropertyTree(pt);
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* AllOfWithSingleRef_H_ */
|
@ -0,0 +1,118 @@
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
|
||||
*
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator unset.
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#include "Animal.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <sstream>
|
||||
#include <stdexcept>
|
||||
#include <regex>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <boost/property_tree/ptree.hpp>
|
||||
#include <boost/property_tree/json_parser.hpp>
|
||||
#include "helpers.h"
|
||||
|
||||
using boost::property_tree::ptree;
|
||||
using boost::property_tree::read_json;
|
||||
using boost::property_tree::write_json;
|
||||
|
||||
namespace org {
|
||||
namespace openapitools {
|
||||
namespace server {
|
||||
namespace model {
|
||||
|
||||
Animal::Animal(boost::property_tree::ptree const& pt)
|
||||
{
|
||||
fromPropertyTree(pt);
|
||||
}
|
||||
|
||||
|
||||
std::string Animal::toJsonString(bool prettyJson /* = false */) const
|
||||
{
|
||||
std::stringstream ss;
|
||||
write_json(ss, this->toPropertyTree(), prettyJson);
|
||||
// workaround inspired by: https://stackoverflow.com/a/56395440
|
||||
std::regex reg("\\\"([0-9]+\\.{0,1}[0-9]*)\\\"");
|
||||
std::string result = std::regex_replace(ss.str(), reg, "$1");
|
||||
return result;
|
||||
}
|
||||
|
||||
void Animal::fromJsonString(std::string const& jsonString)
|
||||
{
|
||||
std::stringstream ss(jsonString);
|
||||
ptree pt;
|
||||
read_json(ss,pt);
|
||||
this->fromPropertyTree(pt);
|
||||
}
|
||||
|
||||
ptree Animal::toPropertyTree() const
|
||||
{
|
||||
ptree pt;
|
||||
ptree tmp_node;
|
||||
pt.put("className", m_ClassName);
|
||||
pt.put("color", m_Color);
|
||||
return pt;
|
||||
}
|
||||
|
||||
void Animal::fromPropertyTree(ptree const &pt)
|
||||
{
|
||||
ptree tmp_node;
|
||||
m_ClassName = pt.get("className", "");
|
||||
m_Color = pt.get("color", "red");
|
||||
}
|
||||
|
||||
std::string Animal::getClassName() const
|
||||
{
|
||||
return m_ClassName;
|
||||
}
|
||||
|
||||
void Animal::setClassName(std::string value)
|
||||
{
|
||||
m_ClassName = value;
|
||||
}
|
||||
|
||||
|
||||
std::string Animal::getColor() const
|
||||
{
|
||||
return m_Color;
|
||||
}
|
||||
|
||||
void Animal::setColor(std::string value)
|
||||
{
|
||||
m_Color = value;
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::vector<Animal> createAnimalVectorFromJsonString(const std::string& json)
|
||||
{
|
||||
std::stringstream sstream(json);
|
||||
boost::property_tree::ptree pt;
|
||||
boost::property_tree::json_parser::read_json(sstream,pt);
|
||||
|
||||
auto vec = std::vector<Animal>();
|
||||
for (const auto& child: pt) {
|
||||
vec.emplace_back(Animal(child.second));
|
||||
}
|
||||
|
||||
return vec;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,96 @@
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
|
||||
*
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator unset.
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Animal.h
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef Animal_H_
|
||||
#define Animal_H_
|
||||
|
||||
|
||||
|
||||
#include <string>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <boost/property_tree/ptree.hpp>
|
||||
#include "helpers.h"
|
||||
|
||||
namespace org {
|
||||
namespace openapitools {
|
||||
namespace server {
|
||||
namespace model {
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
class Animal
|
||||
{
|
||||
public:
|
||||
Animal() = default;
|
||||
explicit Animal(boost::property_tree::ptree const& pt);
|
||||
virtual ~Animal() = default;
|
||||
|
||||
Animal(const Animal& other) = default; // copy constructor
|
||||
Animal(Animal&& other) noexcept = default; // move constructor
|
||||
|
||||
Animal& operator=(const Animal& other) = default; // copy assignment
|
||||
Animal& operator=(Animal&& other) noexcept = default; // move assignment
|
||||
|
||||
std::string toJsonString(bool prettyJson = false) const;
|
||||
void fromJsonString(std::string const& jsonString);
|
||||
boost::property_tree::ptree toPropertyTree() const;
|
||||
void fromPropertyTree(boost::property_tree::ptree const& pt);
|
||||
|
||||
|
||||
/////////////////////////////////////////////
|
||||
/// Animal members
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
std::string getClassName() const;
|
||||
void setClassName(std::string value);
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
std::string getColor() const;
|
||||
void setColor(std::string value);
|
||||
|
||||
protected:
|
||||
std::string m_ClassName = "";
|
||||
std::string m_Color = "red";
|
||||
};
|
||||
|
||||
std::vector<Animal> createAnimalVectorFromJsonString(const std::string& json);
|
||||
|
||||
template<>
|
||||
inline boost::property_tree::ptree toPt<Animal>(const Animal& val) {
|
||||
return val.toPropertyTree();
|
||||
}
|
||||
|
||||
template<>
|
||||
inline Animal fromPt<Animal>(const boost::property_tree::ptree& pt) {
|
||||
Animal ret;
|
||||
ret.fromPropertyTree(pt);
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* Animal_H_ */
|
@ -0,0 +1,131 @@
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
|
||||
*
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator unset.
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#include "ApiResponse.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <sstream>
|
||||
#include <stdexcept>
|
||||
#include <regex>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <boost/property_tree/ptree.hpp>
|
||||
#include <boost/property_tree/json_parser.hpp>
|
||||
#include "helpers.h"
|
||||
|
||||
using boost::property_tree::ptree;
|
||||
using boost::property_tree::read_json;
|
||||
using boost::property_tree::write_json;
|
||||
|
||||
namespace org {
|
||||
namespace openapitools {
|
||||
namespace server {
|
||||
namespace model {
|
||||
|
||||
ApiResponse::ApiResponse(boost::property_tree::ptree const& pt)
|
||||
{
|
||||
fromPropertyTree(pt);
|
||||
}
|
||||
|
||||
|
||||
std::string ApiResponse::toJsonString(bool prettyJson /* = false */) const
|
||||
{
|
||||
std::stringstream ss;
|
||||
write_json(ss, this->toPropertyTree(), prettyJson);
|
||||
// workaround inspired by: https://stackoverflow.com/a/56395440
|
||||
std::regex reg("\\\"([0-9]+\\.{0,1}[0-9]*)\\\"");
|
||||
std::string result = std::regex_replace(ss.str(), reg, "$1");
|
||||
return result;
|
||||
}
|
||||
|
||||
void ApiResponse::fromJsonString(std::string const& jsonString)
|
||||
{
|
||||
std::stringstream ss(jsonString);
|
||||
ptree pt;
|
||||
read_json(ss,pt);
|
||||
this->fromPropertyTree(pt);
|
||||
}
|
||||
|
||||
ptree ApiResponse::toPropertyTree() const
|
||||
{
|
||||
ptree pt;
|
||||
ptree tmp_node;
|
||||
pt.put("code", m_Code);
|
||||
pt.put("type", m_Type);
|
||||
pt.put("message", m_Message);
|
||||
return pt;
|
||||
}
|
||||
|
||||
void ApiResponse::fromPropertyTree(ptree const &pt)
|
||||
{
|
||||
ptree tmp_node;
|
||||
m_Code = pt.get("code", 0);
|
||||
m_Type = pt.get("type", "");
|
||||
m_Message = pt.get("message", "");
|
||||
}
|
||||
|
||||
int32_t ApiResponse::getCode() const
|
||||
{
|
||||
return m_Code;
|
||||
}
|
||||
|
||||
void ApiResponse::setCode(int32_t value)
|
||||
{
|
||||
m_Code = value;
|
||||
}
|
||||
|
||||
|
||||
std::string ApiResponse::getType() const
|
||||
{
|
||||
return m_Type;
|
||||
}
|
||||
|
||||
void ApiResponse::setType(std::string value)
|
||||
{
|
||||
m_Type = value;
|
||||
}
|
||||
|
||||
|
||||
std::string ApiResponse::getMessage() const
|
||||
{
|
||||
return m_Message;
|
||||
}
|
||||
|
||||
void ApiResponse::setMessage(std::string value)
|
||||
{
|
||||
m_Message = value;
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::vector<ApiResponse> createApiResponseVectorFromJsonString(const std::string& json)
|
||||
{
|
||||
std::stringstream sstream(json);
|
||||
boost::property_tree::ptree pt;
|
||||
boost::property_tree::json_parser::read_json(sstream,pt);
|
||||
|
||||
auto vec = std::vector<ApiResponse>();
|
||||
for (const auto& child: pt) {
|
||||
vec.emplace_back(ApiResponse(child.second));
|
||||
}
|
||||
|
||||
return vec;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,103 @@
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
|
||||
*
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator unset.
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
/*
|
||||
* ApiResponse.h
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef ApiResponse_H_
|
||||
#define ApiResponse_H_
|
||||
|
||||
|
||||
|
||||
#include <string>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <boost/property_tree/ptree.hpp>
|
||||
#include "helpers.h"
|
||||
|
||||
namespace org {
|
||||
namespace openapitools {
|
||||
namespace server {
|
||||
namespace model {
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
class ApiResponse
|
||||
{
|
||||
public:
|
||||
ApiResponse() = default;
|
||||
explicit ApiResponse(boost::property_tree::ptree const& pt);
|
||||
virtual ~ApiResponse() = default;
|
||||
|
||||
ApiResponse(const ApiResponse& other) = default; // copy constructor
|
||||
ApiResponse(ApiResponse&& other) noexcept = default; // move constructor
|
||||
|
||||
ApiResponse& operator=(const ApiResponse& other) = default; // copy assignment
|
||||
ApiResponse& operator=(ApiResponse&& other) noexcept = default; // move assignment
|
||||
|
||||
std::string toJsonString(bool prettyJson = false) const;
|
||||
void fromJsonString(std::string const& jsonString);
|
||||
boost::property_tree::ptree toPropertyTree() const;
|
||||
void fromPropertyTree(boost::property_tree::ptree const& pt);
|
||||
|
||||
|
||||
/////////////////////////////////////////////
|
||||
/// ApiResponse members
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
int32_t getCode() const;
|
||||
void setCode(int32_t value);
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
std::string getType() const;
|
||||
void setType(std::string value);
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
std::string getMessage() const;
|
||||
void setMessage(std::string value);
|
||||
|
||||
protected:
|
||||
int32_t m_Code = 0;
|
||||
std::string m_Type = "";
|
||||
std::string m_Message = "";
|
||||
};
|
||||
|
||||
std::vector<ApiResponse> createApiResponseVectorFromJsonString(const std::string& json);
|
||||
|
||||
template<>
|
||||
inline boost::property_tree::ptree toPt<ApiResponse>(const ApiResponse& val) {
|
||||
return val.toPropertyTree();
|
||||
}
|
||||
|
||||
template<>
|
||||
inline ApiResponse fromPt<ApiResponse>(const boost::property_tree::ptree& pt) {
|
||||
ApiResponse ret;
|
||||
ret.fromPropertyTree(pt);
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* ApiResponse_H_ */
|
@ -0,0 +1,114 @@
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
|
||||
*
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator unset.
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#include "ArrayOfArrayOfNumberOnly.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <sstream>
|
||||
#include <stdexcept>
|
||||
#include <regex>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <boost/property_tree/ptree.hpp>
|
||||
#include <boost/property_tree/json_parser.hpp>
|
||||
#include "helpers.h"
|
||||
|
||||
using boost::property_tree::ptree;
|
||||
using boost::property_tree::read_json;
|
||||
using boost::property_tree::write_json;
|
||||
|
||||
namespace org {
|
||||
namespace openapitools {
|
||||
namespace server {
|
||||
namespace model {
|
||||
|
||||
ArrayOfArrayOfNumberOnly::ArrayOfArrayOfNumberOnly(boost::property_tree::ptree const& pt)
|
||||
{
|
||||
fromPropertyTree(pt);
|
||||
}
|
||||
|
||||
|
||||
std::string ArrayOfArrayOfNumberOnly::toJsonString(bool prettyJson /* = false */) const
|
||||
{
|
||||
std::stringstream ss;
|
||||
write_json(ss, this->toPropertyTree(), prettyJson);
|
||||
// workaround inspired by: https://stackoverflow.com/a/56395440
|
||||
std::regex reg("\\\"([0-9]+\\.{0,1}[0-9]*)\\\"");
|
||||
std::string result = std::regex_replace(ss.str(), reg, "$1");
|
||||
return result;
|
||||
}
|
||||
|
||||
void ArrayOfArrayOfNumberOnly::fromJsonString(std::string const& jsonString)
|
||||
{
|
||||
std::stringstream ss(jsonString);
|
||||
ptree pt;
|
||||
read_json(ss,pt);
|
||||
this->fromPropertyTree(pt);
|
||||
}
|
||||
|
||||
ptree ArrayOfArrayOfNumberOnly::toPropertyTree() const
|
||||
{
|
||||
ptree pt;
|
||||
ptree tmp_node;
|
||||
// generate tree for ArrayArrayNumber
|
||||
tmp_node.clear();
|
||||
if (!m_ArrayArrayNumber.empty()) {
|
||||
tmp_node = toPt(m_ArrayArrayNumber);
|
||||
pt.add_child("ArrayArrayNumber", tmp_node);
|
||||
tmp_node.clear();
|
||||
}
|
||||
return pt;
|
||||
}
|
||||
|
||||
void ArrayOfArrayOfNumberOnly::fromPropertyTree(ptree const &pt)
|
||||
{
|
||||
ptree tmp_node;
|
||||
// push all items of ArrayArrayNumber into member
|
||||
if (pt.get_child_optional("ArrayArrayNumber")) {
|
||||
m_ArrayArrayNumber = fromPt<std::vector<std::vector<double>>>(pt.get_child("ArrayArrayNumber"));
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<std::vector<double>> ArrayOfArrayOfNumberOnly::getArrayArrayNumber() const
|
||||
{
|
||||
return m_ArrayArrayNumber;
|
||||
}
|
||||
|
||||
void ArrayOfArrayOfNumberOnly::setArrayArrayNumber(std::vector<std::vector<double>> value)
|
||||
{
|
||||
m_ArrayArrayNumber = value;
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::vector<ArrayOfArrayOfNumberOnly> createArrayOfArrayOfNumberOnlyVectorFromJsonString(const std::string& json)
|
||||
{
|
||||
std::stringstream sstream(json);
|
||||
boost::property_tree::ptree pt;
|
||||
boost::property_tree::json_parser::read_json(sstream,pt);
|
||||
|
||||
auto vec = std::vector<ArrayOfArrayOfNumberOnly>();
|
||||
for (const auto& child: pt) {
|
||||
vec.emplace_back(ArrayOfArrayOfNumberOnly(child.second));
|
||||
}
|
||||
|
||||
return vec;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,89 @@
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
|
||||
*
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator unset.
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
/*
|
||||
* ArrayOfArrayOfNumberOnly.h
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef ArrayOfArrayOfNumberOnly_H_
|
||||
#define ArrayOfArrayOfNumberOnly_H_
|
||||
|
||||
|
||||
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <boost/property_tree/ptree.hpp>
|
||||
#include "helpers.h"
|
||||
|
||||
namespace org {
|
||||
namespace openapitools {
|
||||
namespace server {
|
||||
namespace model {
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
class ArrayOfArrayOfNumberOnly
|
||||
{
|
||||
public:
|
||||
ArrayOfArrayOfNumberOnly() = default;
|
||||
explicit ArrayOfArrayOfNumberOnly(boost::property_tree::ptree const& pt);
|
||||
virtual ~ArrayOfArrayOfNumberOnly() = default;
|
||||
|
||||
ArrayOfArrayOfNumberOnly(const ArrayOfArrayOfNumberOnly& other) = default; // copy constructor
|
||||
ArrayOfArrayOfNumberOnly(ArrayOfArrayOfNumberOnly&& other) noexcept = default; // move constructor
|
||||
|
||||
ArrayOfArrayOfNumberOnly& operator=(const ArrayOfArrayOfNumberOnly& other) = default; // copy assignment
|
||||
ArrayOfArrayOfNumberOnly& operator=(ArrayOfArrayOfNumberOnly&& other) noexcept = default; // move assignment
|
||||
|
||||
std::string toJsonString(bool prettyJson = false) const;
|
||||
void fromJsonString(std::string const& jsonString);
|
||||
boost::property_tree::ptree toPropertyTree() const;
|
||||
void fromPropertyTree(boost::property_tree::ptree const& pt);
|
||||
|
||||
|
||||
/////////////////////////////////////////////
|
||||
/// ArrayOfArrayOfNumberOnly members
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
std::vector<std::vector<double>> getArrayArrayNumber() const;
|
||||
void setArrayArrayNumber(std::vector<std::vector<double>> value);
|
||||
|
||||
protected:
|
||||
std::vector<std::vector<double>> m_ArrayArrayNumber;
|
||||
};
|
||||
|
||||
std::vector<ArrayOfArrayOfNumberOnly> createArrayOfArrayOfNumberOnlyVectorFromJsonString(const std::string& json);
|
||||
|
||||
template<>
|
||||
inline boost::property_tree::ptree toPt<ArrayOfArrayOfNumberOnly>(const ArrayOfArrayOfNumberOnly& val) {
|
||||
return val.toPropertyTree();
|
||||
}
|
||||
|
||||
template<>
|
||||
inline ArrayOfArrayOfNumberOnly fromPt<ArrayOfArrayOfNumberOnly>(const boost::property_tree::ptree& pt) {
|
||||
ArrayOfArrayOfNumberOnly ret;
|
||||
ret.fromPropertyTree(pt);
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* ArrayOfArrayOfNumberOnly_H_ */
|
@ -0,0 +1,114 @@
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
|
||||
*
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator unset.
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#include "ArrayOfNumberOnly.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <sstream>
|
||||
#include <stdexcept>
|
||||
#include <regex>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <boost/property_tree/ptree.hpp>
|
||||
#include <boost/property_tree/json_parser.hpp>
|
||||
#include "helpers.h"
|
||||
|
||||
using boost::property_tree::ptree;
|
||||
using boost::property_tree::read_json;
|
||||
using boost::property_tree::write_json;
|
||||
|
||||
namespace org {
|
||||
namespace openapitools {
|
||||
namespace server {
|
||||
namespace model {
|
||||
|
||||
ArrayOfNumberOnly::ArrayOfNumberOnly(boost::property_tree::ptree const& pt)
|
||||
{
|
||||
fromPropertyTree(pt);
|
||||
}
|
||||
|
||||
|
||||
std::string ArrayOfNumberOnly::toJsonString(bool prettyJson /* = false */) const
|
||||
{
|
||||
std::stringstream ss;
|
||||
write_json(ss, this->toPropertyTree(), prettyJson);
|
||||
// workaround inspired by: https://stackoverflow.com/a/56395440
|
||||
std::regex reg("\\\"([0-9]+\\.{0,1}[0-9]*)\\\"");
|
||||
std::string result = std::regex_replace(ss.str(), reg, "$1");
|
||||
return result;
|
||||
}
|
||||
|
||||
void ArrayOfNumberOnly::fromJsonString(std::string const& jsonString)
|
||||
{
|
||||
std::stringstream ss(jsonString);
|
||||
ptree pt;
|
||||
read_json(ss,pt);
|
||||
this->fromPropertyTree(pt);
|
||||
}
|
||||
|
||||
ptree ArrayOfNumberOnly::toPropertyTree() const
|
||||
{
|
||||
ptree pt;
|
||||
ptree tmp_node;
|
||||
// generate tree for ArrayNumber
|
||||
tmp_node.clear();
|
||||
if (!m_ArrayNumber.empty()) {
|
||||
tmp_node = toPt(m_ArrayNumber);
|
||||
pt.add_child("ArrayNumber", tmp_node);
|
||||
tmp_node.clear();
|
||||
}
|
||||
return pt;
|
||||
}
|
||||
|
||||
void ArrayOfNumberOnly::fromPropertyTree(ptree const &pt)
|
||||
{
|
||||
ptree tmp_node;
|
||||
// push all items of ArrayNumber into member
|
||||
if (pt.get_child_optional("ArrayNumber")) {
|
||||
m_ArrayNumber = fromPt<std::vector<double>>(pt.get_child("ArrayNumber"));
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<double> ArrayOfNumberOnly::getArrayNumber() const
|
||||
{
|
||||
return m_ArrayNumber;
|
||||
}
|
||||
|
||||
void ArrayOfNumberOnly::setArrayNumber(std::vector<double> value)
|
||||
{
|
||||
m_ArrayNumber = value;
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::vector<ArrayOfNumberOnly> createArrayOfNumberOnlyVectorFromJsonString(const std::string& json)
|
||||
{
|
||||
std::stringstream sstream(json);
|
||||
boost::property_tree::ptree pt;
|
||||
boost::property_tree::json_parser::read_json(sstream,pt);
|
||||
|
||||
auto vec = std::vector<ArrayOfNumberOnly>();
|
||||
for (const auto& child: pt) {
|
||||
vec.emplace_back(ArrayOfNumberOnly(child.second));
|
||||
}
|
||||
|
||||
return vec;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,89 @@
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
|
||||
*
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator unset.
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
/*
|
||||
* ArrayOfNumberOnly.h
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef ArrayOfNumberOnly_H_
|
||||
#define ArrayOfNumberOnly_H_
|
||||
|
||||
|
||||
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <boost/property_tree/ptree.hpp>
|
||||
#include "helpers.h"
|
||||
|
||||
namespace org {
|
||||
namespace openapitools {
|
||||
namespace server {
|
||||
namespace model {
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
class ArrayOfNumberOnly
|
||||
{
|
||||
public:
|
||||
ArrayOfNumberOnly() = default;
|
||||
explicit ArrayOfNumberOnly(boost::property_tree::ptree const& pt);
|
||||
virtual ~ArrayOfNumberOnly() = default;
|
||||
|
||||
ArrayOfNumberOnly(const ArrayOfNumberOnly& other) = default; // copy constructor
|
||||
ArrayOfNumberOnly(ArrayOfNumberOnly&& other) noexcept = default; // move constructor
|
||||
|
||||
ArrayOfNumberOnly& operator=(const ArrayOfNumberOnly& other) = default; // copy assignment
|
||||
ArrayOfNumberOnly& operator=(ArrayOfNumberOnly&& other) noexcept = default; // move assignment
|
||||
|
||||
std::string toJsonString(bool prettyJson = false) const;
|
||||
void fromJsonString(std::string const& jsonString);
|
||||
boost::property_tree::ptree toPropertyTree() const;
|
||||
void fromPropertyTree(boost::property_tree::ptree const& pt);
|
||||
|
||||
|
||||
/////////////////////////////////////////////
|
||||
/// ArrayOfNumberOnly members
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
std::vector<double> getArrayNumber() const;
|
||||
void setArrayNumber(std::vector<double> value);
|
||||
|
||||
protected:
|
||||
std::vector<double> m_ArrayNumber;
|
||||
};
|
||||
|
||||
std::vector<ArrayOfNumberOnly> createArrayOfNumberOnlyVectorFromJsonString(const std::string& json);
|
||||
|
||||
template<>
|
||||
inline boost::property_tree::ptree toPt<ArrayOfNumberOnly>(const ArrayOfNumberOnly& val) {
|
||||
return val.toPropertyTree();
|
||||
}
|
||||
|
||||
template<>
|
||||
inline ArrayOfNumberOnly fromPt<ArrayOfNumberOnly>(const boost::property_tree::ptree& pt) {
|
||||
ArrayOfNumberOnly ret;
|
||||
ret.fromPropertyTree(pt);
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* ArrayOfNumberOnly_H_ */
|
@ -0,0 +1,158 @@
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
|
||||
*
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator unset.
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#include "ArrayTest.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <sstream>
|
||||
#include <stdexcept>
|
||||
#include <regex>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <boost/property_tree/ptree.hpp>
|
||||
#include <boost/property_tree/json_parser.hpp>
|
||||
#include "helpers.h"
|
||||
|
||||
using boost::property_tree::ptree;
|
||||
using boost::property_tree::read_json;
|
||||
using boost::property_tree::write_json;
|
||||
|
||||
namespace org {
|
||||
namespace openapitools {
|
||||
namespace server {
|
||||
namespace model {
|
||||
|
||||
ArrayTest::ArrayTest(boost::property_tree::ptree const& pt)
|
||||
{
|
||||
fromPropertyTree(pt);
|
||||
}
|
||||
|
||||
|
||||
std::string ArrayTest::toJsonString(bool prettyJson /* = false */) const
|
||||
{
|
||||
std::stringstream ss;
|
||||
write_json(ss, this->toPropertyTree(), prettyJson);
|
||||
// workaround inspired by: https://stackoverflow.com/a/56395440
|
||||
std::regex reg("\\\"([0-9]+\\.{0,1}[0-9]*)\\\"");
|
||||
std::string result = std::regex_replace(ss.str(), reg, "$1");
|
||||
return result;
|
||||
}
|
||||
|
||||
void ArrayTest::fromJsonString(std::string const& jsonString)
|
||||
{
|
||||
std::stringstream ss(jsonString);
|
||||
ptree pt;
|
||||
read_json(ss,pt);
|
||||
this->fromPropertyTree(pt);
|
||||
}
|
||||
|
||||
ptree ArrayTest::toPropertyTree() const
|
||||
{
|
||||
ptree pt;
|
||||
ptree tmp_node;
|
||||
// generate tree for Array_of_string
|
||||
tmp_node.clear();
|
||||
if (!m_Array_of_string.empty()) {
|
||||
tmp_node = toPt(m_Array_of_string);
|
||||
pt.add_child("array_of_string", tmp_node);
|
||||
tmp_node.clear();
|
||||
}
|
||||
// generate tree for Array_array_of_integer
|
||||
tmp_node.clear();
|
||||
if (!m_Array_array_of_integer.empty()) {
|
||||
tmp_node = toPt(m_Array_array_of_integer);
|
||||
pt.add_child("array_array_of_integer", tmp_node);
|
||||
tmp_node.clear();
|
||||
}
|
||||
// generate tree for Array_array_of_model
|
||||
tmp_node.clear();
|
||||
if (!m_Array_array_of_model.empty()) {
|
||||
tmp_node = toPt(m_Array_array_of_model);
|
||||
pt.add_child("array_array_of_model", tmp_node);
|
||||
tmp_node.clear();
|
||||
}
|
||||
return pt;
|
||||
}
|
||||
|
||||
void ArrayTest::fromPropertyTree(ptree const &pt)
|
||||
{
|
||||
ptree tmp_node;
|
||||
// push all items of Array_of_string into member
|
||||
if (pt.get_child_optional("array_of_string")) {
|
||||
m_Array_of_string = fromPt<std::vector<std::string>>(pt.get_child("array_of_string"));
|
||||
}
|
||||
// push all items of Array_array_of_integer into member
|
||||
if (pt.get_child_optional("array_array_of_integer")) {
|
||||
m_Array_array_of_integer = fromPt<std::vector<std::vector<int64_t>>>(pt.get_child("array_array_of_integer"));
|
||||
}
|
||||
// push all items of Array_array_of_model into member
|
||||
if (pt.get_child_optional("array_array_of_model")) {
|
||||
m_Array_array_of_model = fromPt<std::vector<std::vector<ReadOnlyFirst>>>(pt.get_child("array_array_of_model"));
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<std::string> ArrayTest::getArrayOfString() const
|
||||
{
|
||||
return m_Array_of_string;
|
||||
}
|
||||
|
||||
void ArrayTest::setArrayOfString(std::vector<std::string> value)
|
||||
{
|
||||
m_Array_of_string = value;
|
||||
}
|
||||
|
||||
|
||||
std::vector<std::vector<int64_t>> ArrayTest::getArrayArrayOfInteger() const
|
||||
{
|
||||
return m_Array_array_of_integer;
|
||||
}
|
||||
|
||||
void ArrayTest::setArrayArrayOfInteger(std::vector<std::vector<int64_t>> value)
|
||||
{
|
||||
m_Array_array_of_integer = value;
|
||||
}
|
||||
|
||||
|
||||
std::vector<std::vector<ReadOnlyFirst>> ArrayTest::getArrayArrayOfModel() const
|
||||
{
|
||||
return m_Array_array_of_model;
|
||||
}
|
||||
|
||||
void ArrayTest::setArrayArrayOfModel(std::vector<std::vector<ReadOnlyFirst>> value)
|
||||
{
|
||||
m_Array_array_of_model = value;
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::vector<ArrayTest> createArrayTestVectorFromJsonString(const std::string& json)
|
||||
{
|
||||
std::stringstream sstream(json);
|
||||
boost::property_tree::ptree pt;
|
||||
boost::property_tree::json_parser::read_json(sstream,pt);
|
||||
|
||||
auto vec = std::vector<ArrayTest>();
|
||||
for (const auto& child: pt) {
|
||||
vec.emplace_back(ArrayTest(child.second));
|
||||
}
|
||||
|
||||
return vec;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,105 @@
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
|
||||
*
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator unset.
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
/*
|
||||
* ArrayTest.h
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef ArrayTest_H_
|
||||
#define ArrayTest_H_
|
||||
|
||||
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "ReadOnlyFirst.h"
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <boost/property_tree/ptree.hpp>
|
||||
#include "helpers.h"
|
||||
|
||||
namespace org {
|
||||
namespace openapitools {
|
||||
namespace server {
|
||||
namespace model {
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
class ArrayTest
|
||||
{
|
||||
public:
|
||||
ArrayTest() = default;
|
||||
explicit ArrayTest(boost::property_tree::ptree const& pt);
|
||||
virtual ~ArrayTest() = default;
|
||||
|
||||
ArrayTest(const ArrayTest& other) = default; // copy constructor
|
||||
ArrayTest(ArrayTest&& other) noexcept = default; // move constructor
|
||||
|
||||
ArrayTest& operator=(const ArrayTest& other) = default; // copy assignment
|
||||
ArrayTest& operator=(ArrayTest&& other) noexcept = default; // move assignment
|
||||
|
||||
std::string toJsonString(bool prettyJson = false) const;
|
||||
void fromJsonString(std::string const& jsonString);
|
||||
boost::property_tree::ptree toPropertyTree() const;
|
||||
void fromPropertyTree(boost::property_tree::ptree const& pt);
|
||||
|
||||
|
||||
/////////////////////////////////////////////
|
||||
/// ArrayTest members
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
std::vector<std::string> getArrayOfString() const;
|
||||
void setArrayOfString(std::vector<std::string> value);
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
std::vector<std::vector<int64_t>> getArrayArrayOfInteger() const;
|
||||
void setArrayArrayOfInteger(std::vector<std::vector<int64_t>> value);
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
std::vector<std::vector<ReadOnlyFirst>> getArrayArrayOfModel() const;
|
||||
void setArrayArrayOfModel(std::vector<std::vector<ReadOnlyFirst>> value);
|
||||
|
||||
protected:
|
||||
std::vector<std::string> m_Array_of_string;
|
||||
std::vector<std::vector<int64_t>> m_Array_array_of_integer;
|
||||
std::vector<std::vector<ReadOnlyFirst>> m_Array_array_of_model;
|
||||
};
|
||||
|
||||
std::vector<ArrayTest> createArrayTestVectorFromJsonString(const std::string& json);
|
||||
|
||||
template<>
|
||||
inline boost::property_tree::ptree toPt<ArrayTest>(const ArrayTest& val) {
|
||||
return val.toPropertyTree();
|
||||
}
|
||||
|
||||
template<>
|
||||
inline ArrayTest fromPt<ArrayTest>(const boost::property_tree::ptree& pt) {
|
||||
ArrayTest ret;
|
||||
ret.fromPropertyTree(pt);
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* ArrayTest_H_ */
|
@ -0,0 +1,170 @@
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
|
||||
*
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator unset.
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#include "Capitalization.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <sstream>
|
||||
#include <stdexcept>
|
||||
#include <regex>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <boost/property_tree/ptree.hpp>
|
||||
#include <boost/property_tree/json_parser.hpp>
|
||||
#include "helpers.h"
|
||||
|
||||
using boost::property_tree::ptree;
|
||||
using boost::property_tree::read_json;
|
||||
using boost::property_tree::write_json;
|
||||
|
||||
namespace org {
|
||||
namespace openapitools {
|
||||
namespace server {
|
||||
namespace model {
|
||||
|
||||
Capitalization::Capitalization(boost::property_tree::ptree const& pt)
|
||||
{
|
||||
fromPropertyTree(pt);
|
||||
}
|
||||
|
||||
|
||||
std::string Capitalization::toJsonString(bool prettyJson /* = false */) const
|
||||
{
|
||||
std::stringstream ss;
|
||||
write_json(ss, this->toPropertyTree(), prettyJson);
|
||||
// workaround inspired by: https://stackoverflow.com/a/56395440
|
||||
std::regex reg("\\\"([0-9]+\\.{0,1}[0-9]*)\\\"");
|
||||
std::string result = std::regex_replace(ss.str(), reg, "$1");
|
||||
return result;
|
||||
}
|
||||
|
||||
void Capitalization::fromJsonString(std::string const& jsonString)
|
||||
{
|
||||
std::stringstream ss(jsonString);
|
||||
ptree pt;
|
||||
read_json(ss,pt);
|
||||
this->fromPropertyTree(pt);
|
||||
}
|
||||
|
||||
ptree Capitalization::toPropertyTree() const
|
||||
{
|
||||
ptree pt;
|
||||
ptree tmp_node;
|
||||
pt.put("smallCamel", m_SmallCamel);
|
||||
pt.put("CapitalCamel", m_CapitalCamel);
|
||||
pt.put("small_Snake", m_Small_Snake);
|
||||
pt.put("Capital_Snake", m_Capital_Snake);
|
||||
pt.put("SCA_ETH_Flow_Points", m_SCA_ETH_Flow_Points);
|
||||
pt.put("ATT_NAME", m_ATT_NAME);
|
||||
return pt;
|
||||
}
|
||||
|
||||
void Capitalization::fromPropertyTree(ptree const &pt)
|
||||
{
|
||||
ptree tmp_node;
|
||||
m_SmallCamel = pt.get("smallCamel", "");
|
||||
m_CapitalCamel = pt.get("CapitalCamel", "");
|
||||
m_Small_Snake = pt.get("small_Snake", "");
|
||||
m_Capital_Snake = pt.get("Capital_Snake", "");
|
||||
m_SCA_ETH_Flow_Points = pt.get("SCA_ETH_Flow_Points", "");
|
||||
m_ATT_NAME = pt.get("ATT_NAME", "");
|
||||
}
|
||||
|
||||
std::string Capitalization::getSmallCamel() const
|
||||
{
|
||||
return m_SmallCamel;
|
||||
}
|
||||
|
||||
void Capitalization::setSmallCamel(std::string value)
|
||||
{
|
||||
m_SmallCamel = value;
|
||||
}
|
||||
|
||||
|
||||
std::string Capitalization::getCapitalCamel() const
|
||||
{
|
||||
return m_CapitalCamel;
|
||||
}
|
||||
|
||||
void Capitalization::setCapitalCamel(std::string value)
|
||||
{
|
||||
m_CapitalCamel = value;
|
||||
}
|
||||
|
||||
|
||||
std::string Capitalization::getSmallSnake() const
|
||||
{
|
||||
return m_Small_Snake;
|
||||
}
|
||||
|
||||
void Capitalization::setSmallSnake(std::string value)
|
||||
{
|
||||
m_Small_Snake = value;
|
||||
}
|
||||
|
||||
|
||||
std::string Capitalization::getCapitalSnake() const
|
||||
{
|
||||
return m_Capital_Snake;
|
||||
}
|
||||
|
||||
void Capitalization::setCapitalSnake(std::string value)
|
||||
{
|
||||
m_Capital_Snake = value;
|
||||
}
|
||||
|
||||
|
||||
std::string Capitalization::getSCAETHFlowPoints() const
|
||||
{
|
||||
return m_SCA_ETH_Flow_Points;
|
||||
}
|
||||
|
||||
void Capitalization::setSCAETHFlowPoints(std::string value)
|
||||
{
|
||||
m_SCA_ETH_Flow_Points = value;
|
||||
}
|
||||
|
||||
|
||||
std::string Capitalization::getATTNAME() const
|
||||
{
|
||||
return m_ATT_NAME;
|
||||
}
|
||||
|
||||
void Capitalization::setATTNAME(std::string value)
|
||||
{
|
||||
m_ATT_NAME = value;
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::vector<Capitalization> createCapitalizationVectorFromJsonString(const std::string& json)
|
||||
{
|
||||
std::stringstream sstream(json);
|
||||
boost::property_tree::ptree pt;
|
||||
boost::property_tree::json_parser::read_json(sstream,pt);
|
||||
|
||||
auto vec = std::vector<Capitalization>();
|
||||
for (const auto& child: pt) {
|
||||
vec.emplace_back(Capitalization(child.second));
|
||||
}
|
||||
|
||||
return vec;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,124 @@
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
|
||||
*
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator unset.
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Capitalization.h
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef Capitalization_H_
|
||||
#define Capitalization_H_
|
||||
|
||||
|
||||
|
||||
#include <string>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <boost/property_tree/ptree.hpp>
|
||||
#include "helpers.h"
|
||||
|
||||
namespace org {
|
||||
namespace openapitools {
|
||||
namespace server {
|
||||
namespace model {
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
class Capitalization
|
||||
{
|
||||
public:
|
||||
Capitalization() = default;
|
||||
explicit Capitalization(boost::property_tree::ptree const& pt);
|
||||
virtual ~Capitalization() = default;
|
||||
|
||||
Capitalization(const Capitalization& other) = default; // copy constructor
|
||||
Capitalization(Capitalization&& other) noexcept = default; // move constructor
|
||||
|
||||
Capitalization& operator=(const Capitalization& other) = default; // copy assignment
|
||||
Capitalization& operator=(Capitalization&& other) noexcept = default; // move assignment
|
||||
|
||||
std::string toJsonString(bool prettyJson = false) const;
|
||||
void fromJsonString(std::string const& jsonString);
|
||||
boost::property_tree::ptree toPropertyTree() const;
|
||||
void fromPropertyTree(boost::property_tree::ptree const& pt);
|
||||
|
||||
|
||||
/////////////////////////////////////////////
|
||||
/// Capitalization members
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
std::string getSmallCamel() const;
|
||||
void setSmallCamel(std::string value);
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
std::string getCapitalCamel() const;
|
||||
void setCapitalCamel(std::string value);
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
std::string getSmallSnake() const;
|
||||
void setSmallSnake(std::string value);
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
std::string getCapitalSnake() const;
|
||||
void setCapitalSnake(std::string value);
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
std::string getSCAETHFlowPoints() const;
|
||||
void setSCAETHFlowPoints(std::string value);
|
||||
|
||||
/// <summary>
|
||||
/// Name of the pet
|
||||
/// </summary>
|
||||
std::string getATTNAME() const;
|
||||
void setATTNAME(std::string value);
|
||||
|
||||
protected:
|
||||
std::string m_SmallCamel = "";
|
||||
std::string m_CapitalCamel = "";
|
||||
std::string m_Small_Snake = "";
|
||||
std::string m_Capital_Snake = "";
|
||||
std::string m_SCA_ETH_Flow_Points = "";
|
||||
std::string m_ATT_NAME = "";
|
||||
};
|
||||
|
||||
std::vector<Capitalization> createCapitalizationVectorFromJsonString(const std::string& json);
|
||||
|
||||
template<>
|
||||
inline boost::property_tree::ptree toPt<Capitalization>(const Capitalization& val) {
|
||||
return val.toPropertyTree();
|
||||
}
|
||||
|
||||
template<>
|
||||
inline Capitalization fromPt<Capitalization>(const boost::property_tree::ptree& pt) {
|
||||
Capitalization ret;
|
||||
ret.fromPropertyTree(pt);
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* Capitalization_H_ */
|
131
samples/server/petstore/cpp-restbed/generated/3_0/model/Cat.cpp
Normal file
131
samples/server/petstore/cpp-restbed/generated/3_0/model/Cat.cpp
Normal file
@ -0,0 +1,131 @@
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
|
||||
*
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator unset.
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#include "Cat.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <sstream>
|
||||
#include <stdexcept>
|
||||
#include <regex>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <boost/property_tree/ptree.hpp>
|
||||
#include <boost/property_tree/json_parser.hpp>
|
||||
#include "helpers.h"
|
||||
|
||||
using boost::property_tree::ptree;
|
||||
using boost::property_tree::read_json;
|
||||
using boost::property_tree::write_json;
|
||||
|
||||
namespace org {
|
||||
namespace openapitools {
|
||||
namespace server {
|
||||
namespace model {
|
||||
|
||||
Cat::Cat(boost::property_tree::ptree const& pt)
|
||||
{
|
||||
fromPropertyTree(pt);
|
||||
}
|
||||
|
||||
|
||||
std::string Cat::toJsonString(bool prettyJson /* = false */) const
|
||||
{
|
||||
std::stringstream ss;
|
||||
write_json(ss, this->toPropertyTree(), prettyJson);
|
||||
// workaround inspired by: https://stackoverflow.com/a/56395440
|
||||
std::regex reg("\\\"([0-9]+\\.{0,1}[0-9]*)\\\"");
|
||||
std::string result = std::regex_replace(ss.str(), reg, "$1");
|
||||
return result;
|
||||
}
|
||||
|
||||
void Cat::fromJsonString(std::string const& jsonString)
|
||||
{
|
||||
std::stringstream ss(jsonString);
|
||||
ptree pt;
|
||||
read_json(ss,pt);
|
||||
this->fromPropertyTree(pt);
|
||||
}
|
||||
|
||||
ptree Cat::toPropertyTree() const
|
||||
{
|
||||
ptree pt;
|
||||
ptree tmp_node;
|
||||
pt.put("className", m_ClassName);
|
||||
pt.put("color", m_Color);
|
||||
pt.put("declawed", m_Declawed);
|
||||
return pt;
|
||||
}
|
||||
|
||||
void Cat::fromPropertyTree(ptree const &pt)
|
||||
{
|
||||
ptree tmp_node;
|
||||
m_ClassName = pt.get("className", "");
|
||||
m_Color = pt.get("color", "red");
|
||||
m_Declawed = pt.get("declawed", false);
|
||||
}
|
||||
|
||||
std::string Cat::getClassName() const
|
||||
{
|
||||
return m_ClassName;
|
||||
}
|
||||
|
||||
void Cat::setClassName(std::string value)
|
||||
{
|
||||
m_ClassName = value;
|
||||
}
|
||||
|
||||
|
||||
std::string Cat::getColor() const
|
||||
{
|
||||
return m_Color;
|
||||
}
|
||||
|
||||
void Cat::setColor(std::string value)
|
||||
{
|
||||
m_Color = value;
|
||||
}
|
||||
|
||||
|
||||
bool Cat::isDeclawed() const
|
||||
{
|
||||
return m_Declawed;
|
||||
}
|
||||
|
||||
void Cat::setDeclawed(bool value)
|
||||
{
|
||||
m_Declawed = value;
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::vector<Cat> createCatVectorFromJsonString(const std::string& json)
|
||||
{
|
||||
std::stringstream sstream(json);
|
||||
boost::property_tree::ptree pt;
|
||||
boost::property_tree::json_parser::read_json(sstream,pt);
|
||||
|
||||
auto vec = std::vector<Cat>();
|
||||
for (const auto& child: pt) {
|
||||
vec.emplace_back(Cat(child.second));
|
||||
}
|
||||
|
||||
return vec;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
106
samples/server/petstore/cpp-restbed/generated/3_0/model/Cat.h
Normal file
106
samples/server/petstore/cpp-restbed/generated/3_0/model/Cat.h
Normal file
@ -0,0 +1,106 @@
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
|
||||
*
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator unset.
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Cat.h
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef Cat_H_
|
||||
#define Cat_H_
|
||||
|
||||
|
||||
|
||||
#include <string>
|
||||
#include "Animal.h"
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <boost/property_tree/ptree.hpp>
|
||||
#include "Animal.h"
|
||||
#include "Cat_allOf.h"
|
||||
#include "helpers.h"
|
||||
|
||||
namespace org {
|
||||
namespace openapitools {
|
||||
namespace server {
|
||||
namespace model {
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
class Cat : public Animal, public Cat_allOf
|
||||
{
|
||||
public:
|
||||
Cat() = default;
|
||||
explicit Cat(boost::property_tree::ptree const& pt);
|
||||
virtual ~Cat() = default;
|
||||
|
||||
Cat(const Cat& other) = default; // copy constructor
|
||||
Cat(Cat&& other) noexcept = default; // move constructor
|
||||
|
||||
Cat& operator=(const Cat& other) = default; // copy assignment
|
||||
Cat& operator=(Cat&& other) noexcept = default; // move assignment
|
||||
|
||||
std::string toJsonString(bool prettyJson = false) const;
|
||||
void fromJsonString(std::string const& jsonString);
|
||||
boost::property_tree::ptree toPropertyTree() const;
|
||||
void fromPropertyTree(boost::property_tree::ptree const& pt);
|
||||
|
||||
|
||||
/////////////////////////////////////////////
|
||||
/// Cat members
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
std::string getClassName() const;
|
||||
void setClassName(std::string value);
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
std::string getColor() const;
|
||||
void setColor(std::string value);
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
bool isDeclawed() const;
|
||||
void setDeclawed(bool value);
|
||||
|
||||
protected:
|
||||
std::string m_ClassName = "";
|
||||
std::string m_Color = "red";
|
||||
bool m_Declawed = false;
|
||||
};
|
||||
|
||||
std::vector<Cat> createCatVectorFromJsonString(const std::string& json);
|
||||
|
||||
template<>
|
||||
inline boost::property_tree::ptree toPt<Cat>(const Cat& val) {
|
||||
return val.toPropertyTree();
|
||||
}
|
||||
|
||||
template<>
|
||||
inline Cat fromPt<Cat>(const boost::property_tree::ptree& pt) {
|
||||
Cat ret;
|
||||
ret.fromPropertyTree(pt);
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* Cat_H_ */
|
@ -0,0 +1,105 @@
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
|
||||
*
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator unset.
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#include "Cat_allOf.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <sstream>
|
||||
#include <stdexcept>
|
||||
#include <regex>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <boost/property_tree/ptree.hpp>
|
||||
#include <boost/property_tree/json_parser.hpp>
|
||||
#include "helpers.h"
|
||||
|
||||
using boost::property_tree::ptree;
|
||||
using boost::property_tree::read_json;
|
||||
using boost::property_tree::write_json;
|
||||
|
||||
namespace org {
|
||||
namespace openapitools {
|
||||
namespace server {
|
||||
namespace model {
|
||||
|
||||
Cat_allOf::Cat_allOf(boost::property_tree::ptree const& pt)
|
||||
{
|
||||
fromPropertyTree(pt);
|
||||
}
|
||||
|
||||
|
||||
std::string Cat_allOf::toJsonString(bool prettyJson /* = false */) const
|
||||
{
|
||||
std::stringstream ss;
|
||||
write_json(ss, this->toPropertyTree(), prettyJson);
|
||||
// workaround inspired by: https://stackoverflow.com/a/56395440
|
||||
std::regex reg("\\\"([0-9]+\\.{0,1}[0-9]*)\\\"");
|
||||
std::string result = std::regex_replace(ss.str(), reg, "$1");
|
||||
return result;
|
||||
}
|
||||
|
||||
void Cat_allOf::fromJsonString(std::string const& jsonString)
|
||||
{
|
||||
std::stringstream ss(jsonString);
|
||||
ptree pt;
|
||||
read_json(ss,pt);
|
||||
this->fromPropertyTree(pt);
|
||||
}
|
||||
|
||||
ptree Cat_allOf::toPropertyTree() const
|
||||
{
|
||||
ptree pt;
|
||||
ptree tmp_node;
|
||||
pt.put("declawed", m_Declawed);
|
||||
return pt;
|
||||
}
|
||||
|
||||
void Cat_allOf::fromPropertyTree(ptree const &pt)
|
||||
{
|
||||
ptree tmp_node;
|
||||
m_Declawed = pt.get("declawed", false);
|
||||
}
|
||||
|
||||
bool Cat_allOf::isDeclawed() const
|
||||
{
|
||||
return m_Declawed;
|
||||
}
|
||||
|
||||
void Cat_allOf::setDeclawed(bool value)
|
||||
{
|
||||
m_Declawed = value;
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::vector<Cat_allOf> createCat_allOfVectorFromJsonString(const std::string& json)
|
||||
{
|
||||
std::stringstream sstream(json);
|
||||
boost::property_tree::ptree pt;
|
||||
boost::property_tree::json_parser::read_json(sstream,pt);
|
||||
|
||||
auto vec = std::vector<Cat_allOf>();
|
||||
for (const auto& child: pt) {
|
||||
vec.emplace_back(Cat_allOf(child.second));
|
||||
}
|
||||
|
||||
return vec;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,88 @@
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
|
||||
*
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator unset.
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Cat_allOf.h
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef Cat_allOf_H_
|
||||
#define Cat_allOf_H_
|
||||
|
||||
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <boost/property_tree/ptree.hpp>
|
||||
#include "helpers.h"
|
||||
|
||||
namespace org {
|
||||
namespace openapitools {
|
||||
namespace server {
|
||||
namespace model {
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
class Cat_allOf
|
||||
{
|
||||
public:
|
||||
Cat_allOf() = default;
|
||||
explicit Cat_allOf(boost::property_tree::ptree const& pt);
|
||||
virtual ~Cat_allOf() = default;
|
||||
|
||||
Cat_allOf(const Cat_allOf& other) = default; // copy constructor
|
||||
Cat_allOf(Cat_allOf&& other) noexcept = default; // move constructor
|
||||
|
||||
Cat_allOf& operator=(const Cat_allOf& other) = default; // copy assignment
|
||||
Cat_allOf& operator=(Cat_allOf&& other) noexcept = default; // move assignment
|
||||
|
||||
std::string toJsonString(bool prettyJson = false) const;
|
||||
void fromJsonString(std::string const& jsonString);
|
||||
boost::property_tree::ptree toPropertyTree() const;
|
||||
void fromPropertyTree(boost::property_tree::ptree const& pt);
|
||||
|
||||
|
||||
/////////////////////////////////////////////
|
||||
/// Cat_allOf members
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
bool isDeclawed() const;
|
||||
void setDeclawed(bool value);
|
||||
|
||||
protected:
|
||||
bool m_Declawed = false;
|
||||
};
|
||||
|
||||
std::vector<Cat_allOf> createCat_allOfVectorFromJsonString(const std::string& json);
|
||||
|
||||
template<>
|
||||
inline boost::property_tree::ptree toPt<Cat_allOf>(const Cat_allOf& val) {
|
||||
return val.toPropertyTree();
|
||||
}
|
||||
|
||||
template<>
|
||||
inline Cat_allOf fromPt<Cat_allOf>(const boost::property_tree::ptree& pt) {
|
||||
Cat_allOf ret;
|
||||
ret.fromPropertyTree(pt);
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* Cat_allOf_H_ */
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user