diff --git a/.travis.yml b/.travis.yml index 0f5b038ec8c..eae87d704b5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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" diff --git a/bin/configs/unmaintained/cpp-restbed-server-cpp-restbed.yaml b/bin/configs/unmaintained/cpp-restbed-server-cpp-restbed.yaml index 8863620d2ae..d7242c4b607 100644 --- a/bin/configs/unmaintained/cpp-restbed-server-cpp-restbed.yaml +++ b/bin/configs/unmaintained/cpp-restbed-server-cpp-restbed.yaml @@ -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 diff --git a/bin/configs/unmaintained/cpp-restbed-server.yaml b/bin/configs/unmaintained/cpp-restbed-server.yaml new file mode 100644 index 00000000000..d7242c4b607 --- /dev/null +++ b/bin/configs/unmaintained/cpp-restbed-server.yaml @@ -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 diff --git a/bin/configs/unmaintained/openapi3/cpp-restbed-server-cpp-restbed-deprecated.yaml b/bin/configs/unmaintained/openapi3/cpp-restbed-server-cpp-restbed-deprecated.yaml new file mode 100644 index 00000000000..8a9b93fffe8 --- /dev/null +++ b/bin/configs/unmaintained/openapi3/cpp-restbed-server-cpp-restbed-deprecated.yaml @@ -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 diff --git a/bin/configs/unmaintained/openapi3/cpp-restbed-server-cpp-restbed.yaml b/bin/configs/unmaintained/openapi3/cpp-restbed-server-cpp-restbed.yaml index d0acbda2d0e..6dc3929ec08 100644 --- a/bin/configs/unmaintained/openapi3/cpp-restbed-server-cpp-restbed.yaml +++ b/bin/configs/unmaintained/openapi3/cpp-restbed-server-cpp-restbed.yaml @@ -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 diff --git a/docs/generators/cpp-restbed-server.md b/docs/generators/cpp-restbed-server.md index f376b503cc7..a0450db79dd 100644 --- a/docs/generators/cpp-restbed-server.md +++ b/docs/generators/cpp-restbed-server.md @@ -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>| diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractCppCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractCppCodegen.java index 7cbb943a98b..d989776bd33 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractCppCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractCppCodegen.java @@ -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; } } diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppRestbedServerCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppRestbedServerCodegen.java index 9d7ce46bafa..96c092c3fd4 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppRestbedServerCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppRestbedServerCodegen.java @@ -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 "); importMapping.put("std::map", "#include "); + importMapping.put("std::set", "#include "); + importMapping.put("file", "#include "); importMapping.put("std::string", "#include "); - importMapping.put("Object", "#include \"Object.h\""); importMapping.put("restbed::Bytes", "#include "); } @@ -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 "); - } 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 allModels) { OperationMap operations = objs.getOperations(); @@ -291,46 +326,31 @@ public class CppRestbedServerCodegen extends AbstractCppCodegen { List 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); + StringJoiner joiner = new StringJoiner("/"); + for (String pathSegment : pathSegments) { + resourceNameCamelCase += convertPathSegmentToResourceNamePart(pathSegment); + String convertedPathSegment = convertPathParamPattern(pathSegment); + joiner.add(convertedPathSegment); } - } else if (item.length() == 1) { - resourceNameCamelCase += Character.toUpperCase(item.charAt(0)); - } - op.path += item + "/"; - } + + 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 currentOtherMethodList = (List) 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 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 getCodegenXCodegenOtherMethodsOperations(CodegenOperation newOperation) { + List currentOtherMethodList = (List) 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) + ""; } 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()"; + } 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 + "{}"; } } diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppRestbedServerDeprecatedCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppRestbedServerDeprecatedCodegen.java new file mode 100644 index 00000000000..0e243b2f61c --- /dev/null +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppRestbedServerDeprecatedCodegen.java @@ -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 "); + importMapping.put("std::map", "#include "); + importMapping.put("std::string", "#include "); + importMapping.put("Object", "#include \"Object.h\""); + importMapping.put("restbed::Bytes", "#include "); + } + + @Override + public Map updateAllModels(Map objs) { + // Index all CodegenModels by model name. + Map allModels = getAllModels(objs); + + // Clean interfaces of ambiguity + for (Entry cm : allModels.entrySet()) { + if (cm.getValue().getInterfaces() != null && !cm.getValue().getInterfaces().isEmpty()) { + List 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 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 "); + } + 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 allModels) { + OperationMap operations = objs.getOperations(); + List operationList = operations.getOperation(); + List 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 currentOtherMethodList = (List) 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) + ""; + } 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()"; + } 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; + } +} diff --git a/modules/openapi-generator/src/main/resources/META-INF/services/org.openapitools.codegen.CodegenConfig b/modules/openapi-generator/src/main/resources/META-INF/services/org.openapitools.codegen.CodegenConfig index fdc47bd6d91..55a1e66eb88 100644 --- a/modules/openapi-generator/src/main/resources/META-INF/services/org.openapitools.codegen.CodegenConfig +++ b/modules/openapi-generator/src/main/resources/META-INF/services/org.openapitools.codegen.CodegenConfig @@ -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 diff --git a/modules/openapi-generator/src/main/resources/cpp-restbed-server-deprecated/README.mustache b/modules/openapi-generator/src/main/resources/cpp-restbed-server-deprecated/README.mustache new file mode 100644 index 00000000000..0dc00706b11 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/cpp-restbed-server-deprecated/README.mustache @@ -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}}} diff --git a/modules/openapi-generator/src/main/resources/cpp-restbed-server-deprecated/api-header.mustache b/modules/openapi-generator/src/main/resources/cpp-restbed-server-deprecated/api-header.mustache new file mode 100644 index 00000000000..80c7b0d4dd7 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/cpp-restbed-server-deprecated/api-header.mustache @@ -0,0 +1,203 @@ +{{>licenseInfo}} +{{#operations}}/* + * {{classname}}.h + * + * {{description}} + */ + +#ifndef {{classname}}_H_ +#define {{classname}}_H_ + +{{{defaultInclude}}} +#include +#include +#include + +#include +#include +#include +#include +#include + +{{#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}} +/// +/// +/// {{notes}} +/// +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{{/returnType}}{{^returnType}}int{{/returnType}} handler_{{httpMethod}}( + {{#allParams}}{{{dataType}}} const & {{{paramName}}}{{^-last}}, {{/-last}}{{/allParams}}); + + {{#vendorExtensions.x-codegen-other-methods}} + virtual {{#returnType}}std::pair{{/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& session); + + {{#hasPathParams}} + {{#pathParams}} + {{#isPrimitiveType}} + virtual {{{dataType}}} getPathParam_{{{paramName}}}(const std::shared_ptr& request) + { + return request->get_path_parameter("{{{paramName}}}", {{{defaultValue}}}); + } + + {{/isPrimitiveType}} + {{/pathParams}} + {{/hasPathParams}} + {{#hasQueryParams}} + {{#queryParams}} + {{#isPrimitiveType}} + virtual {{{dataType}}} getQueryParam_{{{paramName}}}(const std::shared_ptr& request) + { + return request->get_query_parameter("{{{paramName}}}", {{{defaultValue}}}); + } + + {{/isPrimitiveType}} + {{/queryParams}} + {{/hasQueryParams}} + {{#hasHeaderParams}} + {{#headerParams}} + {{#isPrimitiveType}} + virtual {{{dataType}}} getHeader_{{{baseName}}}(const std::shared_ptr& 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& request) + { + return request->get_path_parameter("{{{paramName}}}", {{{defaultValue}}}); + } + {{/isPrimitiveType}} + {{/pathParams}} + {{/hasPathParams}} + {{#hasQueryParams}} + {{#queryParams}} + {{#isPrimitiveType}} + virtual {{{dataType}}} getQueryParam_{{{paramName}}}_x_extension(const std::shared_ptr& request) + { + return request->get_query_parameter("{{{paramName}}}", {{{defaultValue}}}); + } + {{/isPrimitiveType}} + {{/queryParams}} + {{/hasQueryParams}} + {{#hasHeaderParams}} + {{#headerParams}} + {{#isPrimitiveType}} + virtual {{{dataType}}} getHeader_{{{baseName}}}_x_extension(const std::shared_ptr& request) + { + return request->get_header("{{baseName}}", {{{defaultValue}}}); + } + {{/isPrimitiveType}} + {{/headerParams}} + {{/hasHeaderParams}} + {{/vendorExtensions.x-codegen-other-methods}} + + virtual std::pair handle{{classname}}Exception(const {{classname}}Exception& e); + virtual std::pair handleStdException(const std::exception& e); + virtual std::pair handleUnspecifiedException(); + + virtual void setResponseHeader(const std::shared_ptr& session, + const std::string& header); + + + virtual void returnResponse(const std::shared_ptr& session, + const int status, const std::string& result, const std::string& contentType); + virtual void defaultSessionClose(const std::shared_ptr& session, + const int status, const std::string& result); + +private: + void handler_{{httpMethod}}_internal(const std::shared_ptr session); + {{#vendorExtensions.x-codegen-other-methods}} + void handler_{{httpMethod}}_internal(const std::shared_ptr 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 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 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 m_service; +}; + + +{{#apiNamespaceDeclarations}} +} +{{/apiNamespaceDeclarations}} + +#endif /* {{classname}}_H_ */ + +{{/operations}} diff --git a/modules/openapi-generator/src/main/resources/cpp-restbed-server-deprecated/api-source.mustache b/modules/openapi-generator/src/main/resources/cpp-restbed-server-deprecated/api-source.mustache new file mode 100644 index 00000000000..6a9c99ab284 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/cpp-restbed-server-deprecated/api-source.mustache @@ -0,0 +1,400 @@ +{{>licenseInfo}} +{{#operations}} + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#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 +std::shared_ptr 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(pt); + return model; +} + +template +std::vector> 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>(); + for (const auto& child: pt) { + arrayRet.emplace_back(std::make_shared(child.second)); + } + return arrayRet; +} + +template +std::string convertMapResponse(const std::map& map) +{ + boost::property_tree::ptree pt; + for(const auto &kv: map) { + pt.push_back(boost::property_tree::ptree::value_type( + boost::lexical_cast(kv.first), + boost::property_tree::ptree( + boost::lexical_cast(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 {{classname}}{{vendorExtensions.x-codegen-resource-name}}Resource::handle{{classname}}Exception(const {{classname}}Exception& e) +{ + return std::make_pair(e.getStatus(), e.what()); +} + +std::pair {{classname}}{{vendorExtensions.x-codegen-resource-name}}Resource::handleStdException(const std::exception& e) +{ + return std::make_pair(500, e.what()); +} + +std::pair {{classname}}{{vendorExtensions.x-codegen-resource-name}}Resource::handleUnspecifiedException() +{ + return std::make_pair(500, "Unknown exception occurred"); +} + +void {{classname}}{{vendorExtensions.x-codegen-resource-name}}Resource::setResponseHeader(const std::shared_ptr& session, const std::string& header) +{ + session->set_header(header, ""); +} + +void {{classname}}{{vendorExtensions.x-codegen-resource-name}}Resource::returnResponse(const std::shared_ptr& 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& 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 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 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{{/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{{/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& 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 session, + const restbed::Bytes &body) { + bodyContent = restbed::String::format( + "%.*s\n", (int)body.size(), body.data()); + }); + return bodyContent; +} +{{/operation}} + +{{classname}}::{{classname}}(std::shared_ptr 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 {{classname}}::service() { + return m_service; +} + + +{{#apiNamespaceDeclarations}} +} +{{/apiNamespaceDeclarations}} + +{{/operations}} diff --git a/modules/openapi-generator/src/main/resources/cpp-restbed-server-deprecated/git_push.sh.mustache b/modules/openapi-generator/src/main/resources/cpp-restbed-server-deprecated/git_push.sh.mustache new file mode 100644 index 00000000000..0e3776ae6dd --- /dev/null +++ b/modules/openapi-generator/src/main/resources/cpp-restbed-server-deprecated/git_push.sh.mustache @@ -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' diff --git a/modules/openapi-generator/src/main/resources/cpp-restbed-server-deprecated/gitignore.mustache b/modules/openapi-generator/src/main/resources/cpp-restbed-server-deprecated/gitignore.mustache new file mode 100644 index 00000000000..4581ef2eeef --- /dev/null +++ b/modules/openapi-generator/src/main/resources/cpp-restbed-server-deprecated/gitignore.mustache @@ -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 diff --git a/modules/openapi-generator/src/main/resources/cpp-restbed-server-deprecated/licenseInfo.mustache b/modules/openapi-generator/src/main/resources/cpp-restbed-server-deprecated/licenseInfo.mustache new file mode 100644 index 00000000000..85213c8b15c --- /dev/null +++ b/modules/openapi-generator/src/main/resources/cpp-restbed-server-deprecated/licenseInfo.mustache @@ -0,0 +1,11 @@ +/** + * {{{appName}}} + * {{{appDescription}}} + * + * {{#version}}The version of the OpenAPI document: {{{.}}}{{/version}} + * {{#infoEmail}}Contact: {{{.}}}{{/infoEmail}} + * + * NOTE: This class is auto generated by OpenAPI-Generator {{{generatorVersion}}}. + * https://openapi-generator.tech + * Do not edit the class manually. + */ diff --git a/modules/openapi-generator/src/main/resources/cpp-restbed-server-deprecated/model-header.mustache b/modules/openapi-generator/src/main/resources/cpp-restbed-server-deprecated/model-header.mustache new file mode 100644 index 00000000000..2568ccb6766 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/cpp-restbed-server-deprecated/model-header.mustache @@ -0,0 +1,98 @@ +{{>licenseInfo}} +{{#models}}{{#model}}/* + * {{classname}}.h + * + * {{description}} + */ + +#ifndef {{classname}}_H_ +#define {{classname}}_H_ + +{{{defaultInclude}}} + +{{#imports}}{{{this}}} +{{/imports}} +#include +#include +{{#hasEnums}} +#include +{{/hasEnums}} +#include + +{{#modelNamespaceDeclarations}} +namespace {{this}} { +{{/modelNamespaceDeclarations}} + +/// +/// {{description}} +/// +{{#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}} + + /// + /// {{description}} + /// + {{{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 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}} diff --git a/modules/openapi-generator/src/main/resources/cpp-restbed-server-deprecated/model-source.mustache b/modules/openapi-generator/src/main/resources/cpp-restbed-server-deprecated/model-source.mustache new file mode 100644 index 00000000000..395e415c6b4 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/cpp-restbed-server-deprecated/model-source.mustache @@ -0,0 +1,233 @@ +{{>licenseInfo}} +{{#models}}{{#model}} + +#include "{{classname}}.h" + +#include +#include +#include +#include +{{#hasEnums}} +#include +{{/hasEnums}} +#include +#include + +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}} diff --git a/modules/openapi-generator/src/main/resources/cpp-restbed-server/CMakeLists.txt.mustache b/modules/openapi-generator/src/main/resources/cpp-restbed-server/CMakeLists.txt.mustache new file mode 100644 index 00000000000..1ab7dc0f7f3 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/cpp-restbed-server/CMakeLists.txt.mustache @@ -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) diff --git a/modules/openapi-generator/src/main/resources/cpp-restbed-server/FindRestbedAndBoost.cmake b/modules/openapi-generator/src/main/resources/cpp-restbed-server/FindRestbedAndBoost.cmake new file mode 100644 index 00000000000..630464c6fe0 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/cpp-restbed-server/FindRestbedAndBoost.cmake @@ -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) diff --git a/modules/openapi-generator/src/main/resources/cpp-restbed-server/README.mustache b/modules/openapi-generator/src/main/resources/cpp-restbed-server/README.mustache index 0dc00706b11..60d33765d4a 100644 --- a/modules/openapi-generator/src/main/resources/cpp-restbed-server/README.mustache +++ b/modules/openapi-generator/src/main/resources/cpp-restbed-server/README.mustache @@ -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 + 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(); + + auto storeApi = StoreApi(service); + storeApi.setResource(std::make_shared()); + + 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(); + settings->set_port(1236); + + service->start(settings); +} +``` diff --git a/modules/openapi-generator/src/main/resources/cpp-restbed-server/api-header.mustache b/modules/openapi-generator/src/main/resources/cpp-restbed-server/api-header.mustache index 8bc94376714..b2c7dccf574 100644 --- a/modules/openapi-generator/src/main/resources/cpp-restbed-server/api-header.mustache +++ b/modules/openapi-generator/src/main/resources/cpp-restbed-server/api-header.mustache @@ -12,6 +12,7 @@ #include #include #include +#include #include #include @@ -44,6 +45,7 @@ private: std::string m_what; }; +namespace {{classname}}Resources { {{#operation}} /// /// {{summary}} @@ -51,23 +53,47 @@ private: /// /// {{notes}} /// -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{{/returnType}}{{^returnType}}int{{/returnType}}( + {{#allParams}}{{{dataType}}} & {{{paramName}}}{{^-last}}, {{/-last}}{{/allParams}})> handler_{{httpMethod}}_func = + []({{#allParams}}{{{dataType}}} &{{^-last}}, {{/-last}}{{/allParams}}) -> {{#returnType}}std::pair{{/returnType}}{{^returnType}}int{{/returnType}} + { throw {{classname}}Exception(501, "Not implemented"); }; + + {{#vendorExtensions.x-codegen-other-methods}} + std::function<{{#returnType}}std::pair{{/returnType}}{{^returnType}}int{{/returnType}}( + {{#allParams}}{{{dataType}}} & {{{paramName}}}{{^-last}}, {{/-last}}{{/allParams}})> handler_{{httpMethod}}_func = + []({{#allParams}}{{{dataType}}} &{{^-last}}, {{/-last}}{{/allParams}}) -> {{#returnType}}std::pair{{/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{{/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{{/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& request) - { - return request->get_path_parameter("{{{paramName}}}", {{{defaultValue}}}); - } - - {{/isPrimitiveType}} - {{/pathParams}} - {{/hasPathParams}} - {{#hasQueryParams}} - {{#queryParams}} - {{#isPrimitiveType}} - virtual {{{dataType}}} getQueryParam_{{{paramName}}}(const std::shared_ptr& request) - { - return request->get_query_parameter("{{{paramName}}}", {{{defaultValue}}}); - } - - {{/isPrimitiveType}} - {{/queryParams}} - {{/hasQueryParams}} - {{#hasHeaderParams}} - {{#headerParams}} - {{#isPrimitiveType}} - virtual {{{dataType}}} getHeader_{{{baseName}}}(const std::shared_ptr& 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& request) - { - return request->get_path_parameter("{{{paramName}}}", {{{defaultValue}}}); - } - {{/isPrimitiveType}} - {{/pathParams}} - {{/hasPathParams}} - {{#hasQueryParams}} - {{#queryParams}} - {{#isPrimitiveType}} - virtual {{{dataType}}} getQueryParam_{{{paramName}}}_x_extension(const std::shared_ptr& request) - { - return request->get_query_parameter("{{{paramName}}}", {{{defaultValue}}}); - } - {{/isPrimitiveType}} - {{/queryParams}} - {{/hasQueryParams}} - {{#hasHeaderParams}} - {{#headerParams}} - {{#isPrimitiveType}} - virtual {{{dataType}}} getHeader_{{{baseName}}}_x_extension(const std::shared_ptr& request) - { - return request->get_header("{{baseName}}", {{{defaultValue}}}); - } - {{/isPrimitiveType}} - {{/headerParams}} - {{/hasHeaderParams}} - {{/vendorExtensions.x-codegen-other-methods}} + virtual std::string extractBodyContent(const std::shared_ptr& session); + virtual std::string extractFormParamsFromBody(const std::string& paramName, const std::string& body); virtual std::pair handle{{classname}}Exception(const {{classname}}Exception& e); virtual std::pair handleStdException(const std::exception& e); @@ -149,9 +111,8 @@ protected: virtual void setResponseHeader(const std::shared_ptr& session, const std::string& header); - virtual void returnResponse(const std::shared_ptr& session, - const int status, const std::string& result, const std::string& contentType); + const int status, const std::string& result, std::multimap& contentType); virtual void defaultSessionClose(const std::shared_ptr& 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: diff --git a/modules/openapi-generator/src/main/resources/cpp-restbed-server/api-source-HandlerBody.mustache b/modules/openapi-generator/src/main/resources/cpp-restbed-server/api-source-HandlerBody.mustache new file mode 100644 index 00000000000..5a5e1faf67d --- /dev/null +++ b/modules/openapi-generator/src/main/resources/cpp-restbed-server/api-source-HandlerBody.mustache @@ -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 {{{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 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); diff --git a/modules/openapi-generator/src/main/resources/cpp-restbed-server/api-source.mustache b/modules/openapi-generator/src/main/resources/cpp-restbed-server/api-source.mustache index affd170a8d3..b50cfb673e7 100644 --- a/modules/openapi-generator/src/main/resources/cpp-restbed-server/api-source.mustache +++ b/modules/openapi-generator/src/main/resources/cpp-restbed-server/api-source.mustache @@ -19,6 +19,32 @@ namespace {{this}} { using namespace {{modelNamespace}}; +namespace { +[[maybe_unused]] +std::string selectPreferredContentType(const std::vector& contentTypes) { + if (contentTypes.size() == 0) { + return "application/json"; + } + + if (contentTypes.size() == 1) { + return contentTypes.at(0); + } + + static const std::array 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 -std::shared_ptr 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(pt); + auto model = MODEL_T(pt); return model; } template -std::vector> extractJsonArrayBodyParam(const std::string& bodyContent) +std::vector 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>(); + auto arrayRet = std::vector(); for (const auto& child: pt) { - arrayRet.emplace_back(std::make_shared(child.second)); + arrayRet.emplace_back(MODEL_T(child.second)); } return arrayRet; } @@ -76,160 +102,58 @@ std::string convertMapResponse(const std::map& 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 {{classname}}{{vendorExtensions.x-codegen-resource-name}}Resource::handle{{classname}}Exception(const {{classname}}Exception& e) +std::pair {{vendorExtensions.x-codegen-resource-name}}Resource::handle{{classname}}Exception(const {{classname}}Exception& e) { return std::make_pair(e.getStatus(), e.what()); } -std::pair {{classname}}{{vendorExtensions.x-codegen-resource-name}}Resource::handleStdException(const std::exception& e) +std::pair {{vendorExtensions.x-codegen-resource-name}}Resource::handleStdException(const std::exception& e) { return std::make_pair(500, e.what()); } -std::pair {{classname}}{{vendorExtensions.x-codegen-resource-name}}Resource::handleUnspecifiedException() +std::pair {{vendorExtensions.x-codegen-resource-name}}Resource::handleUnspecifiedException() { return std::make_pair(500, "Unknown exception occurred"); } -void {{classname}}{{vendorExtensions.x-codegen-resource-name}}Resource::setResponseHeader(const std::shared_ptr& session, const std::string& header) +void {{vendorExtensions.x-codegen-resource-name}}Resource::setResponseHeader(const std::shared_ptr& session, const std::string& header) { session->set_header(header, ""); } -void {{classname}}{{vendorExtensions.x-codegen-resource-name}}Resource::returnResponse(const std::shared_ptr& session, const int status, const std::string& result, const std::string& contentType) +void {{vendorExtensions.x-codegen-resource-name}}Resource::returnResponse(const std::shared_ptr& session, const int status, const std::string& result, std::multimap& 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& session, const int status, const std::string& result) +void {{vendorExtensions.x-codegen-resource-name}}Resource::defaultSessionClose(const std::shared_ptr& 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 session) +void {{vendorExtensions.x-codegen-resource-name}}Resource::handler_{{httpMethod}}_internal(const std::shared_ptr 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 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 session) { +void {{vendorExtensions.x-codegen-resource-name}}Resource::handler_{{httpMethod}}_internal(const std::shared_ptr 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 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{{/returnType}}{{^returnType}}int{{/returnType}} {{classname}}{{vendorExtensions.x-codegen-resource-name}}Resource::handler_{{httpMethod}}( - {{#allParams}}{{{dataType}}} const & {{{paramName}}}{{^-last}}, {{/-last}}{{/allParams}}) +{{#returnType}}std::pair{{/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{{/returnType}}{{^returnType}}int{{/returnType}} {{classname}}{{vendorExtensions.x-codegen-resource-name}}Resource::handler_{{httpMethod}}( - {{#allParams}}{{{dataType}}} const & {{{paramName}}}{{^-last}}, {{/-last}}{{/allParams}}) +{{#returnType}}std::pair{{/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& 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 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 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}} } diff --git a/modules/openapi-generator/src/main/resources/cpp-restbed-server/model-header.mustache b/modules/openapi-generator/src/main/resources/cpp-restbed-server/model-header.mustache index 2568ccb6766..56c16eaa7a6 100644 --- a/modules/openapi-generator/src/main/resources/cpp-restbed-server/model-header.mustache +++ b/modules/openapi-generator/src/main/resources/cpp-restbed-server/model-header.mustache @@ -18,6 +18,10 @@ #include {{/hasEnums}} #include +{{#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}} /// @@ -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 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}} diff --git a/modules/openapi-generator/src/main/resources/cpp-restbed-server/model-helpers-header.mustache b/modules/openapi-generator/src/main/resources/cpp-restbed-server/model-helpers-header.mustache new file mode 100644 index 00000000000..b33cd9e0ddd --- /dev/null +++ b/modules/openapi-generator/src/main/resources/cpp-restbed-server/model-helpers-header.mustache @@ -0,0 +1,136 @@ +{{>licenseInfo}} + +#ifndef OPENAPI_MODELS_HELPER_H_ +#define OPENAPI_MODELS_HELPER_H_ + +{{{defaultInclude}}} + +#include +#include +#include +#include + +{{#modelNamespaceDeclarations}} +namespace {{this}} { +{{/modelNamespaceDeclarations}} + +template +boost::property_tree::ptree toPt(const T& val) { + boost::property_tree::ptree pt; + pt.put_value(val); + return pt; +} + +template +boost::property_tree::ptree toPt(const std::vector & 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 +boost::property_tree::ptree toPt(const std::map & 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 +boost::property_tree::ptree toPt(const std::set & 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 +struct is_vector +{ + static constexpr bool value = false; +}; + +template +struct is_vector> +{ + static constexpr bool value = true; +}; + +template +struct is_map +{ + static constexpr bool value = false; +}; + +template +struct is_map> +{ + static constexpr bool value = true; +}; + +template +struct is_set +{ + static constexpr bool value = false; +}; + +template +struct is_set> +{ + static constexpr bool value = true; +}; + + +template +std::enable_if_t::value && !is_map::value && !is_set::value, T> +fromPt(const boost::property_tree::ptree& pt) { + return pt.get_value(); +} + +template +std::enable_if_t::value,T> +fromPt(const boost::property_tree::ptree& pt) { + T vec; + for (const auto &child: pt) { + typename T::value_type childElement = fromPt(child.second); + vec.emplace_back(childElement); + } + return vec; +} + +template +std::enable_if_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(child.second); + map.insert(std::make_pair(child.first, childElement)); + } + return map; +} + +template +std::enable_if_t::value,T> +fromPt(const boost::property_tree::ptree& pt) { + T set; + for (const auto &child: pt) { + typename T::value_type childElement = fromPt(child.second); + set.insert(childElement); + } + return set; +} + +{{#modelNamespaceDeclarations}} +} +{{/modelNamespaceDeclarations}} + +#endif /* OPENAPI_MODELS_HELPER_H_ */ \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/cpp-restbed-server/model-source.mustache b/modules/openapi-generator/src/main/resources/cpp-restbed-server/model-source.mustache index 395e415c6b4..80f87442b24 100644 --- a/modules/openapi-generator/src/main/resources/cpp-restbed-server/model-source.mustache +++ b/modules/openapi-generator/src/main/resources/cpp-restbed-server/model-source.mustache @@ -5,13 +5,17 @@ #include #include +#include #include #include +#include {{#hasEnums}} #include {{/hasEnums}} +#include #include #include +#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}} + {{#isMap}} + {{^isModel}} + 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()) { - 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}} - } + 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}}")) { + m_{{{name}}} = fromPt<{{{dataType}}}>(pt.get_child("{{baseName}}")); + } + {{/isMap}} + {{^isMap}} + {{^isModelContainer}} + // push all items of {{name}} into member 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}}")); } - {{/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}} + {{/isModelContainer}} + {{#isModelContainer}} + // generate new {{complexType}} Object for each item and assign it to the current + if (pt.get_child_optional("{{baseName}}")) { + m_{{{name}}} = fromPt<{{{dataType}}}>(pt.get_child("{{baseName}}")); + } + {{/isModelContainer}} + {{/isMap}} {{/isContainer}} {{/vars}} } +{{#isEnum}} +std::string {{classname}}::toString() const { + return boost::lexical_cast(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(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}} + {{#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(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(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 " + value + " not allowed"); - }{{/isEnum}} + throw std::runtime_error("Value " + boost::lexical_cast(value) + " not allowed"); + } + {{/isContainer}} + {{/isEnum}} + {{^isEnum}} + m_{{name}} = value; + {{/isEnum}} } + + {{/vars}} std::vector<{{classname}}> create{{classname}}VectorFromJsonString(const std::string& json) diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/cpprestbed/CppRestbedServerTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/cpprestbed/CppRestbedServerTest.java new file mode 100644 index 00000000000..cb47b78b87d --- /dev/null +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/cpprestbed/CppRestbedServerTest.java @@ -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 processedObjsOperationList = extractOperationsList(processedObjs); + + Assert.assertEquals(processedObjsOperationList.size(), 1); + Assert.assertEquals(processedObjsOperationList.get(0).path, expectedPath); + } + + private static List extractOperationsList(Map processedObjs) { + Map processedOperations = (Map) processedObjs.get("operations"); + List processedObjsOperationList = (List) processedOperations.get("operation"); + return processedObjsOperationList; + } + + @NotNull + private static OperationsMap setupOperationWithPath(String path) { + CodegenOperation op = new CodegenOperation(); + op.path = path; + + List operationsList = new ArrayList<>(); + operationsList.add(op); + + OperationMap operations = new OperationMap(); + operations.put("operation", operationsList); + + OperationsMap objs = new OperationsMap(); + objs.put("operations", operations); + return objs; + } +} diff --git a/samples/server/petstore/cpp-restbed-deprecated/.gitignore b/samples/server/petstore/cpp-restbed-deprecated/.gitignore new file mode 100644 index 00000000000..4581ef2eeef --- /dev/null +++ b/samples/server/petstore/cpp-restbed-deprecated/.gitignore @@ -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 diff --git a/samples/server/petstore/cpp-restbed/.openapi-generator-ignore b/samples/server/petstore/cpp-restbed-deprecated/.openapi-generator-ignore similarity index 100% rename from samples/server/petstore/cpp-restbed/.openapi-generator-ignore rename to samples/server/petstore/cpp-restbed-deprecated/.openapi-generator-ignore diff --git a/samples/server/petstore/cpp-restbed/.openapi-generator/FILES b/samples/server/petstore/cpp-restbed-deprecated/.openapi-generator/FILES similarity index 92% rename from samples/server/petstore/cpp-restbed/.openapi-generator/FILES rename to samples/server/petstore/cpp-restbed-deprecated/.openapi-generator/FILES index f4948ccd7a2..0537b528d8c 100644 --- a/samples/server/petstore/cpp-restbed/.openapi-generator/FILES +++ b/samples/server/petstore/cpp-restbed-deprecated/.openapi-generator/FILES @@ -1,4 +1,5 @@ .gitignore +.openapi-generator-ignore README.md api/PetApi.cpp api/PetApi.h diff --git a/samples/server/petstore/cpp-restbed/.openapi-generator/VERSION b/samples/server/petstore/cpp-restbed-deprecated/.openapi-generator/VERSION similarity index 100% rename from samples/server/petstore/cpp-restbed/.openapi-generator/VERSION rename to samples/server/petstore/cpp-restbed-deprecated/.openapi-generator/VERSION diff --git a/samples/server/petstore/cpp-restbed/README.md b/samples/server/petstore/cpp-restbed-deprecated/README.md similarity index 100% rename from samples/server/petstore/cpp-restbed/README.md rename to samples/server/petstore/cpp-restbed-deprecated/README.md diff --git a/samples/server/petstore/cpp-restbed/api/PetApi.cpp b/samples/server/petstore/cpp-restbed-deprecated/api/PetApi.cpp similarity index 95% rename from samples/server/petstore/cpp-restbed/api/PetApi.cpp rename to samples/server/petstore/cpp-restbed-deprecated/api/PetApi.cpp index 65b08975bea..e80c5f0cccf 100644 --- a/samples/server/petstore/cpp-restbed/api/PetApi.cpp +++ b/samples/server/petstore/cpp-restbed-deprecated/api/PetApi.cpp @@ -138,17 +138,18 @@ void PetApiPetResource::handler_POST_internal(const std::shared_ptr(bodyContent); + auto pet = extractJsonModelBodyParam(bodyContent); int status_code = 500; + std::shared_ptr resultObject = std::make_shared(); 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_ptrtoJsonString(); + + 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(bodyContent); + auto pet = extractJsonModelBodyParam(bodyContent); int status_code = 500; + std::shared_ptr resultObject = std::make_shared(); 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_ptrtoJsonString(); + + 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 const & body) +std::pair> PetApiPetResource::handler_POST( + std::shared_ptr const & pet) { throw PetApiException(501, "Not implemented"); } -int PetApiPetResource::handler_PUT( - std::shared_ptr const & body) +std::pair> PetApiPetResource::handler_PUT( + std::shared_ptr const & pet) { throw PetApiException(501, "Not implemented"); } diff --git a/samples/server/petstore/cpp-restbed/api/PetApi.h b/samples/server/petstore/cpp-restbed-deprecated/api/PetApi.h similarity index 98% rename from samples/server/petstore/cpp-restbed/api/PetApi.h rename to samples/server/petstore/cpp-restbed-deprecated/api/PetApi.h index 09a6770a953..0dbcfba2c5c 100644 --- a/samples/server/petstore/cpp-restbed/api/PetApi.h +++ b/samples/server/petstore/cpp-restbed-deprecated/api/PetApi.h @@ -74,11 +74,11 @@ protected: // Override these to implement the server functionality // ////////////////////////////////////////////////////////// - virtual int handler_POST( - std::shared_ptr const & body); + virtual std::pair> handler_POST( + std::shared_ptr const & pet); - virtual int handler_PUT( - std::shared_ptr const & body); + virtual std::pair> handler_PUT( + std::shared_ptr const & pet); protected: ////////////////////////////////////// diff --git a/samples/server/petstore/cpp-restbed/api/StoreApi.cpp b/samples/server/petstore/cpp-restbed-deprecated/api/StoreApi.cpp similarity index 98% rename from samples/server/petstore/cpp-restbed/api/StoreApi.cpp rename to samples/server/petstore/cpp-restbed-deprecated/api/StoreApi.cpp index 784232c6112..0ca436e0203 100644 --- a/samples/server/petstore/cpp-restbed/api/StoreApi.cpp +++ b/samples/server/petstore/cpp-restbed-deprecated/api/StoreApi.cpp @@ -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(bodyContent); + auto order = extractJsonModelBodyParam(bodyContent); @@ -402,7 +403,7 @@ void StoreApiStoreOrderResource::handler_POST_internal(const std::shared_ptr> StoreApiStoreOrderResource::handler_POST( - std::shared_ptr const & body) + std::shared_ptr const & order) { throw StoreApiException(501, "Not implemented"); } diff --git a/samples/server/petstore/cpp-restbed/api/StoreApi.h b/samples/server/petstore/cpp-restbed-deprecated/api/StoreApi.h similarity index 99% rename from samples/server/petstore/cpp-restbed/api/StoreApi.h rename to samples/server/petstore/cpp-restbed-deprecated/api/StoreApi.h index 3c14a48c7e9..3c931556247 100644 --- a/samples/server/petstore/cpp-restbed/api/StoreApi.h +++ b/samples/server/petstore/cpp-restbed-deprecated/api/StoreApi.h @@ -183,7 +183,7 @@ protected: ////////////////////////////////////////////////////////// virtual std::pair> handler_POST( - std::shared_ptr const & body); + std::shared_ptr const & order); protected: diff --git a/samples/server/petstore/cpp-restbed/api/UserApi.cpp b/samples/server/petstore/cpp-restbed-deprecated/api/UserApi.cpp similarity index 97% rename from samples/server/petstore/cpp-restbed/api/UserApi.cpp rename to samples/server/petstore/cpp-restbed-deprecated/api/UserApi.cpp index c6485c6e129..c865c44aff6 100644 --- a/samples/server/petstore/cpp-restbed/api/UserApi.cpp +++ b/samples/server/petstore/cpp-restbed-deprecated/api/UserApi.cpp @@ -135,7 +135,7 @@ void UserApiUserResource::handler_POST_internal(const std::shared_ptr(bodyContent); + auto user = extractJsonModelBodyParam(bodyContent); @@ -145,7 +145,7 @@ void UserApiUserResource::handler_POST_internal(const std::shared_ptr const & body) + std::shared_ptr 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(bodyContent); + auto user = extractJsonArrayBodyParam(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> const & body) + std::vector> 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(bodyContent); + auto user = extractJsonArrayBodyParam(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> const & body) + std::vector> const & user) { throw UserApiException(501, "Not implemented"); } @@ -529,7 +529,7 @@ void UserApiUserUsernameResource::handler_PUT_internal(const std::shared_ptr(bodyContent); - auto body = extractJsonModelBodyParam(bodyContent); + auto user = extractJsonModelBodyParam(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> UserApiUserUsernameResource::handler_GET( throw UserApiException(501, "Not implemented"); } int UserApiUserUsernameResource::handler_PUT( - std::string const & username, std::shared_ptr const & body) + std::string const & username, std::shared_ptr const & user) { throw UserApiException(501, "Not implemented"); } @@ -668,9 +668,11 @@ void UserApiUserLoginResource::handler_GET_internal(const std::shared_ptr const & body); + std::shared_ptr const & user); protected: @@ -123,7 +123,7 @@ protected: ////////////////////////////////////////////////////////// virtual int handler_POST( - std::vector> const & body); + std::vector> const & user); protected: @@ -171,7 +171,7 @@ protected: ////////////////////////////////////////////////////////// virtual int handler_POST( - std::vector> const & body); + std::vector> const & user); protected: @@ -224,7 +224,7 @@ protected: virtual std::pair> handler_GET( std::string const & username); virtual int handler_PUT( - std::string const & username, std::shared_ptr const & body); + std::string const & username, std::shared_ptr const & user); protected: ////////////////////////////////////// diff --git a/samples/server/petstore/cpp-restbed/git_push.sh b/samples/server/petstore/cpp-restbed-deprecated/git_push.sh similarity index 87% rename from samples/server/petstore/cpp-restbed/git_push.sh rename to samples/server/petstore/cpp-restbed-deprecated/git_push.sh index ced3be2b0c7..f53a75d4fab 100644 --- a/samples/server/petstore/cpp-restbed/git_push.sh +++ b/samples/server/petstore/cpp-restbed-deprecated/git_push.sh @@ -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' - diff --git a/samples/server/petstore/cpp-restbed/model/ApiResponse.cpp b/samples/server/petstore/cpp-restbed-deprecated/model/ApiResponse.cpp similarity index 100% rename from samples/server/petstore/cpp-restbed/model/ApiResponse.cpp rename to samples/server/petstore/cpp-restbed-deprecated/model/ApiResponse.cpp diff --git a/samples/server/petstore/cpp-restbed/model/ApiResponse.h b/samples/server/petstore/cpp-restbed-deprecated/model/ApiResponse.h similarity index 99% rename from samples/server/petstore/cpp-restbed/model/ApiResponse.h rename to samples/server/petstore/cpp-restbed-deprecated/model/ApiResponse.h index b67b10af78d..bbf3b51f49f 100644 --- a/samples/server/petstore/cpp-restbed/model/ApiResponse.h +++ b/samples/server/petstore/cpp-restbed-deprecated/model/ApiResponse.h @@ -40,7 +40,7 @@ public: ApiResponse() = default; explicit ApiResponse(boost::property_tree::ptree const& pt); virtual ~ApiResponse() = default; - + std::string toJsonString(bool prettyJson = false); void fromJsonString(std::string const& jsonString); boost::property_tree::ptree toPropertyTree(); diff --git a/samples/server/petstore/cpp-restbed/model/Category.cpp b/samples/server/petstore/cpp-restbed-deprecated/model/Category.cpp similarity index 100% rename from samples/server/petstore/cpp-restbed/model/Category.cpp rename to samples/server/petstore/cpp-restbed-deprecated/model/Category.cpp diff --git a/samples/server/petstore/cpp-restbed/model/Category.h b/samples/server/petstore/cpp-restbed-deprecated/model/Category.h similarity index 99% rename from samples/server/petstore/cpp-restbed/model/Category.h rename to samples/server/petstore/cpp-restbed-deprecated/model/Category.h index 949677e8bf7..879b425a7db 100644 --- a/samples/server/petstore/cpp-restbed/model/Category.h +++ b/samples/server/petstore/cpp-restbed-deprecated/model/Category.h @@ -40,7 +40,7 @@ public: Category() = default; explicit Category(boost::property_tree::ptree const& pt); virtual ~Category() = default; - + std::string toJsonString(bool prettyJson = false); void fromJsonString(std::string const& jsonString); boost::property_tree::ptree toPropertyTree(); diff --git a/samples/server/petstore/cpp-restbed/model/Order.cpp b/samples/server/petstore/cpp-restbed-deprecated/model/Order.cpp similarity index 100% rename from samples/server/petstore/cpp-restbed/model/Order.cpp rename to samples/server/petstore/cpp-restbed-deprecated/model/Order.cpp diff --git a/samples/server/petstore/cpp-restbed/model/Order.h b/samples/server/petstore/cpp-restbed-deprecated/model/Order.h similarity index 99% rename from samples/server/petstore/cpp-restbed/model/Order.h rename to samples/server/petstore/cpp-restbed-deprecated/model/Order.h index b10f2daf3ac..1eac0e12fa4 100644 --- a/samples/server/petstore/cpp-restbed/model/Order.h +++ b/samples/server/petstore/cpp-restbed-deprecated/model/Order.h @@ -42,7 +42,7 @@ public: Order() = default; explicit Order(boost::property_tree::ptree const& pt); virtual ~Order() = default; - + std::string toJsonString(bool prettyJson = false); void fromJsonString(std::string const& jsonString); boost::property_tree::ptree toPropertyTree(); diff --git a/samples/server/petstore/cpp-restbed/model/Pet.cpp b/samples/server/petstore/cpp-restbed-deprecated/model/Pet.cpp similarity index 100% rename from samples/server/petstore/cpp-restbed/model/Pet.cpp rename to samples/server/petstore/cpp-restbed-deprecated/model/Pet.cpp diff --git a/samples/server/petstore/cpp-restbed/model/Pet.h b/samples/server/petstore/cpp-restbed-deprecated/model/Pet.h similarity index 99% rename from samples/server/petstore/cpp-restbed/model/Pet.h rename to samples/server/petstore/cpp-restbed-deprecated/model/Pet.h index 43bd89e15be..0ee153980cb 100644 --- a/samples/server/petstore/cpp-restbed/model/Pet.h +++ b/samples/server/petstore/cpp-restbed-deprecated/model/Pet.h @@ -44,7 +44,7 @@ public: Pet() = default; explicit Pet(boost::property_tree::ptree const& pt); virtual ~Pet() = default; - + std::string toJsonString(bool prettyJson = false); void fromJsonString(std::string const& jsonString); boost::property_tree::ptree toPropertyTree(); diff --git a/samples/server/petstore/cpp-restbed/model/Tag.cpp b/samples/server/petstore/cpp-restbed-deprecated/model/Tag.cpp similarity index 100% rename from samples/server/petstore/cpp-restbed/model/Tag.cpp rename to samples/server/petstore/cpp-restbed-deprecated/model/Tag.cpp diff --git a/samples/server/petstore/cpp-restbed/model/Tag.h b/samples/server/petstore/cpp-restbed-deprecated/model/Tag.h similarity index 99% rename from samples/server/petstore/cpp-restbed/model/Tag.h rename to samples/server/petstore/cpp-restbed-deprecated/model/Tag.h index 82de314f729..8900346ad48 100644 --- a/samples/server/petstore/cpp-restbed/model/Tag.h +++ b/samples/server/petstore/cpp-restbed-deprecated/model/Tag.h @@ -40,7 +40,7 @@ public: Tag() = default; explicit Tag(boost::property_tree::ptree const& pt); virtual ~Tag() = default; - + std::string toJsonString(bool prettyJson = false); void fromJsonString(std::string const& jsonString); boost::property_tree::ptree toPropertyTree(); diff --git a/samples/server/petstore/cpp-restbed/model/User.cpp b/samples/server/petstore/cpp-restbed-deprecated/model/User.cpp similarity index 100% rename from samples/server/petstore/cpp-restbed/model/User.cpp rename to samples/server/petstore/cpp-restbed-deprecated/model/User.cpp diff --git a/samples/server/petstore/cpp-restbed/model/User.h b/samples/server/petstore/cpp-restbed-deprecated/model/User.h similarity index 99% rename from samples/server/petstore/cpp-restbed/model/User.h rename to samples/server/petstore/cpp-restbed-deprecated/model/User.h index dcc3902dad0..0f62e4e7156 100644 --- a/samples/server/petstore/cpp-restbed/model/User.h +++ b/samples/server/petstore/cpp-restbed-deprecated/model/User.h @@ -40,7 +40,7 @@ public: User() = default; explicit User(boost::property_tree::ptree const& pt); virtual ~User() = default; - + std::string toJsonString(bool prettyJson = false); void fromJsonString(std::string const& jsonString); boost::property_tree::ptree toPropertyTree(); diff --git a/samples/server/petstore/cpp-restbed/.gitignore b/samples/server/petstore/cpp-restbed/.gitignore index 4581ef2eeef..7a62dc62866 100644 --- a/samples/server/petstore/cpp-restbed/.gitignore +++ b/samples/server/petstore/cpp-restbed/.gitignore @@ -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 diff --git a/samples/server/petstore/cpp-restbed/CMakeLists.txt b/samples/server/petstore/cpp-restbed/CMakeLists.txt new file mode 100644 index 00000000000..bd938a33b5d --- /dev/null +++ b/samples/server/petstore/cpp-restbed/CMakeLists.txt @@ -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) diff --git a/samples/server/petstore/cpp-restbed/build_and_test.sh b/samples/server/petstore/cpp-restbed/build_and_test.sh new file mode 100755 index 00000000000..9c3064a4dbb --- /dev/null +++ b/samples/server/petstore/cpp-restbed/build_and_test.sh @@ -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 \ No newline at end of file diff --git a/samples/server/petstore/cpp-restbed/cmake/JavaClientTests.cmake b/samples/server/petstore/cpp-restbed/cmake/JavaClientTests.cmake new file mode 100644 index 00000000000..46a23d496c8 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/cmake/JavaClientTests.cmake @@ -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() diff --git a/samples/server/petstore/cpp-restbed/cmake/dependencies.cmake b/samples/server/petstore/cpp-restbed/cmake/dependencies.cmake new file mode 100644 index 00000000000..f1e1e740ba3 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/cmake/dependencies.cmake @@ -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) diff --git a/samples/server/petstore/cpp-restbed/cmake/run_java_client_tests_template.txt b/samples/server/petstore/cpp-restbed/cmake/run_java_client_tests_template.txt new file mode 100755 index 00000000000..eaebefd571d --- /dev/null +++ b/samples/server/petstore/cpp-restbed/cmake/run_java_client_tests_template.txt @@ -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@ diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/.gitignore b/samples/server/petstore/cpp-restbed/generated/3_0/.gitignore new file mode 100644 index 00000000000..4581ef2eeef --- /dev/null +++ b/samples/server/petstore/cpp-restbed/generated/3_0/.gitignore @@ -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 diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/.openapi-generator-ignore b/samples/server/petstore/cpp-restbed/generated/3_0/.openapi-generator-ignore new file mode 100644 index 00000000000..7484ee590a3 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/generated/3_0/.openapi-generator-ignore @@ -0,0 +1,23 @@ +# OpenAPI Generator Ignore +# Generated by openapi-generator https://github.com/openapitools/openapi-generator + +# Use this file to prevent files from being overwritten by the generator. +# The patterns follow closely to .gitignore or .dockerignore. + +# As an example, the C# client generator defines ApiClient.cs. +# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line: +#ApiClient.cs + +# You can match any string of characters against a directory, file or extension with a single asterisk (*): +#foo/*/qux +# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux + +# You can recursively match patterns against a directory, file or extension with a double asterisk (**): +#foo/**/qux +# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux + +# You can also negate patterns with an exclamation (!). +# For example, you can ignore all files in a docs folder with the file extension .md: +#docs/*.md +# Then explicitly reverse the ignore rule for a single file: +#!docs/README.md diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/.openapi-generator/FILES b/samples/server/petstore/cpp-restbed/generated/3_0/.openapi-generator/FILES new file mode 100644 index 00000000000..ab1dc1a7a75 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/generated/3_0/.openapi-generator/FILES @@ -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 diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/.openapi-generator/VERSION b/samples/server/petstore/cpp-restbed/generated/3_0/.openapi-generator/VERSION new file mode 100644 index 00000000000..717311e32e3 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/generated/3_0/.openapi-generator/VERSION @@ -0,0 +1 @@ +unset \ No newline at end of file diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/CMakeLists.txt b/samples/server/petstore/cpp-restbed/generated/3_0/CMakeLists.txt new file mode 100644 index 00000000000..547aa6c12c3 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/generated/3_0/CMakeLists.txt @@ -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) diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/FindRestbedAndBoost.cmake b/samples/server/petstore/cpp-restbed/generated/3_0/FindRestbedAndBoost.cmake new file mode 100644 index 00000000000..630464c6fe0 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/generated/3_0/FindRestbedAndBoost.cmake @@ -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) diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/README.md b/samples/server/petstore/cpp-restbed/generated/3_0/README.md new file mode 100644 index 00000000000..f43fbf34d1d --- /dev/null +++ b/samples/server/petstore/cpp-restbed/generated/3_0/README.md @@ -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 + 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(); + + auto storeApi = StoreApi(service); + storeApi.setResource(std::make_shared()); + + 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(); + settings->set_port(1236); + + service->start(settings); +} +``` diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/api/AnotherFakeApi.cpp b/samples/server/petstore/cpp-restbed/generated/3_0/api/AnotherFakeApi.cpp new file mode 100644 index 00000000000..b63bd61b370 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/generated/3_0/api/AnotherFakeApi.cpp @@ -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 +#include +#include +#include +#include +#include +#include +#include +#include + +#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& contentTypes) { + if (contentTypes.size() == 0) { + return "application/json"; + } + + if (contentTypes.size() == 1) { + return contentTypes.at(0); + } + + static const std::array 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 +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 +std::vector 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(); + for (const auto& child: pt) { + arrayRet.emplace_back(MODEL_T(child.second)); + } + return arrayRet; +} + +template +std::string convertMapResponse(const std::map& map) +{ + boost::property_tree::ptree pt; + for(const auto &kv: map) { + pt.push_back(boost::property_tree::ptree::value_type( + boost::lexical_cast(kv.first), + boost::property_tree::ptree( + boost::lexical_cast(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 Another_fakeDummyResource::handleAnotherFakeApiException(const AnotherFakeApiException& e) +{ + return std::make_pair(e.getStatus(), e.what()); +} + +std::pair Another_fakeDummyResource::handleStdException(const std::exception& e) +{ + return std::make_pair(500, e.what()); +} + +std::pair Another_fakeDummyResource::handleUnspecifiedException() +{ + return std::make_pair(500, "Unknown exception occurred"); +} + +void Another_fakeDummyResource::setResponseHeader(const std::shared_ptr& session, const std::string& header) +{ + session->set_header(header, ""); +} + +void Another_fakeDummyResource::returnResponse(const std::shared_ptr& session, const int status, const std::string& result, std::multimap& responseHeaders) +{ + responseHeaders.insert(std::make_pair("Connection", "close")); + session->close(status, result, responseHeaders); +} + +void Another_fakeDummyResource::defaultSessionClose(const std::shared_ptr& session, const int status, const std::string& result) +{ + session->close(status, result, { {"Connection", "close"} }); +} + +void Another_fakeDummyResource::handler_PATCH_internal(const std::shared_ptr 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(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 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 Another_fakeDummyResource::handler_PATCH( + Client & client) +{ + return handler_PATCH_func(client); +} + + +std::string Another_fakeDummyResource::extractBodyContent(const std::shared_ptr& 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 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 const& restbedService) +: m_service(restbedService) +{ +} + +AnotherFakeApi::~AnotherFakeApi() {} + +std::shared_ptr AnotherFakeApi::getAnother_fakeDummyResource() { + if (!m_spAnother_fakeDummyResource) { + setResource(std::make_shared()); + } + return m_spAnother_fakeDummyResource; +} +void AnotherFakeApi::setResource(std::shared_ptr resource) { + m_spAnother_fakeDummyResource = resource; + m_service->publish(m_spAnother_fakeDummyResource); +} +void AnotherFakeApi::setAnotherFakeApiAnother_fakeDummyResource(std::shared_ptr spAnother_fakeDummyResource) { + m_spAnother_fakeDummyResource = spAnother_fakeDummyResource; + m_service->publish(m_spAnother_fakeDummyResource); +} + + +void AnotherFakeApi::publishDefaultResources() { + if (!m_spAnother_fakeDummyResource) { + setResource(std::make_shared()); + } +} + +std::shared_ptr AnotherFakeApi::service() { + return m_service; +} + + +} +} +} +} + diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/api/AnotherFakeApi.h b/samples/server/petstore/cpp-restbed/generated/3_0/api/AnotherFakeApi.h new file mode 100644 index 00000000000..7e028d5f3b5 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/generated/3_0/api/AnotherFakeApi.h @@ -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 +#include +#include +#include + +#include +#include +#include +#include +#include + +#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 { +/// +/// To test special tags +/// +/// +/// To test special tags and operation ID starting with number +/// +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( + Client & client)> handler_PATCH_func = + [](Client &) -> std::pair + { 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 handler_PATCH( + Client & client); + + +protected: + ////////////////////////////////////// + // Override these for customization // + ////////////////////////////////////// + + virtual std::string extractBodyContent(const std::shared_ptr& session); + virtual std::string extractFormParamsFromBody(const std::string& paramName, const std::string& body); + + virtual std::pair handleAnotherFakeApiException(const AnotherFakeApiException& e); + virtual std::pair handleStdException(const std::exception& e); + virtual std::pair handleUnspecifiedException(); + + virtual void setResponseHeader(const std::shared_ptr& session, + const std::string& header); + + virtual void returnResponse(const std::shared_ptr& session, + const int status, const std::string& result, std::multimap& contentType); + virtual void defaultSessionClose(const std::shared_ptr& session, + const int status, const std::string& result); + +private: + void handler_PATCH_internal(const std::shared_ptr 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 const& restbedService); + virtual ~AnotherFakeApi(); + + std::shared_ptr getAnother_fakeDummyResource(); + + void setResource(std::shared_ptr resource); + [[deprecated("use setResource()")]] + virtual void setAnotherFakeApiAnother_fakeDummyResource(std::shared_ptr spAnotherFakeApiAnother_fakeDummyResource); + + virtual void publishDefaultResources(); + + virtual std::shared_ptr service(); + +protected: + std::shared_ptr m_spAnother_fakeDummyResource; + +private: + std::shared_ptr m_service; +}; + + +} +} +} +} + +#endif /* AnotherFakeApi_H_ */ + diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/api/DefaultApi.cpp b/samples/server/petstore/cpp-restbed/generated/3_0/api/DefaultApi.cpp new file mode 100644 index 00000000000..d92b33de68e --- /dev/null +++ b/samples/server/petstore/cpp-restbed/generated/3_0/api/DefaultApi.cpp @@ -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 +#include +#include +#include +#include +#include +#include +#include +#include + +#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& contentTypes) { + if (contentTypes.size() == 0) { + return "application/json"; + } + + if (contentTypes.size() == 1) { + return contentTypes.at(0); + } + + static const std::array 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 +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 +std::vector 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(); + for (const auto& child: pt) { + arrayRet.emplace_back(MODEL_T(child.second)); + } + return arrayRet; +} + +template +std::string convertMapResponse(const std::map& map) +{ + boost::property_tree::ptree pt; + for(const auto &kv: map) { + pt.push_back(boost::property_tree::ptree::value_type( + boost::lexical_cast(kv.first), + boost::property_tree::ptree( + boost::lexical_cast(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 FooResource::handleDefaultApiException(const DefaultApiException& e) +{ + return std::make_pair(e.getStatus(), e.what()); +} + +std::pair FooResource::handleStdException(const std::exception& e) +{ + return std::make_pair(500, e.what()); +} + +std::pair FooResource::handleUnspecifiedException() +{ + return std::make_pair(500, "Unknown exception occurred"); +} + +void FooResource::setResponseHeader(const std::shared_ptr& session, const std::string& header) +{ + session->set_header(header, ""); +} + +void FooResource::returnResponse(const std::shared_ptr& session, const int status, const std::string& result, std::multimap& responseHeaders) +{ + responseHeaders.insert(std::make_pair("Connection", "close")); + session->close(status, result, responseHeaders); +} + +void FooResource::defaultSessionClose(const std::shared_ptr& session, const int status, const std::string& result) +{ + session->close(status, result, { {"Connection", "close"} }); +} + +void FooResource::handler_GET_internal(const std::shared_ptr 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 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 FooResource::handler_GET( + ) +{ + return handler_GET_func(); +} + + +std::string FooResource::extractBodyContent(const std::shared_ptr& 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 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 const& restbedService) +: m_service(restbedService) +{ +} + +DefaultApi::~DefaultApi() {} + +std::shared_ptr DefaultApi::getFooResource() { + if (!m_spFooResource) { + setResource(std::make_shared()); + } + return m_spFooResource; +} +void DefaultApi::setResource(std::shared_ptr resource) { + m_spFooResource = resource; + m_service->publish(m_spFooResource); +} +void DefaultApi::setDefaultApiFooResource(std::shared_ptr spFooResource) { + m_spFooResource = spFooResource; + m_service->publish(m_spFooResource); +} + + +void DefaultApi::publishDefaultResources() { + if (!m_spFooResource) { + setResource(std::make_shared()); + } +} + +std::shared_ptr DefaultApi::service() { + return m_service; +} + + +} +} +} +} + diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/api/DefaultApi.h b/samples/server/petstore/cpp-restbed/generated/3_0/api/DefaultApi.h new file mode 100644 index 00000000000..eb0337bfff5 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/generated/3_0/api/DefaultApi.h @@ -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 +#include +#include +#include + +#include +#include +#include +#include +#include + +#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 { +/// +/// +/// +/// +/// +/// +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( + )> handler_GET_func = + []() -> std::pair + { 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 handler_GET( + ); + + +protected: + ////////////////////////////////////// + // Override these for customization // + ////////////////////////////////////// + + virtual std::string extractBodyContent(const std::shared_ptr& session); + virtual std::string extractFormParamsFromBody(const std::string& paramName, const std::string& body); + + virtual std::pair handleDefaultApiException(const DefaultApiException& e); + virtual std::pair handleStdException(const std::exception& e); + virtual std::pair handleUnspecifiedException(); + + virtual void setResponseHeader(const std::shared_ptr& session, + const std::string& header); + + virtual void returnResponse(const std::shared_ptr& session, + const int status, const std::string& result, std::multimap& contentType); + virtual void defaultSessionClose(const std::shared_ptr& session, + const int status, const std::string& result); + +private: + void handler_GET_internal(const std::shared_ptr 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 const& restbedService); + virtual ~DefaultApi(); + + std::shared_ptr getFooResource(); + + void setResource(std::shared_ptr resource); + [[deprecated("use setResource()")]] + virtual void setDefaultApiFooResource(std::shared_ptr spDefaultApiFooResource); + + virtual void publishDefaultResources(); + + virtual std::shared_ptr service(); + +protected: + std::shared_ptr m_spFooResource; + +private: + std::shared_ptr m_service; +}; + + +} +} +} +} + +#endif /* DefaultApi_H_ */ + diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/api/FakeApi.cpp b/samples/server/petstore/cpp-restbed/generated/3_0/api/FakeApi.cpp new file mode 100644 index 00000000000..9bcbe3844d7 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/generated/3_0/api/FakeApi.cpp @@ -0,0 +1,2207 @@ +/** + * 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 +#include +#include +#include +#include +#include +#include +#include +#include + +#include "FakeApi.h" + +namespace org { +namespace openapitools { +namespace server { +namespace api { + +using namespace org::openapitools::server::model; + +namespace { +[[maybe_unused]] +std::string selectPreferredContentType(const std::vector& contentTypes) { + if (contentTypes.size() == 0) { + return "application/json"; + } + + if (contentTypes.size() == 1) { + return contentTypes.at(0); + } + + static const std::array 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); +} +} + +FakeApiException::FakeApiException(int status_code, std::string what) + : m_status(status_code), + m_what(what) +{ + +} +int FakeApiException::getStatus() const +{ + return m_status; +} +const char* FakeApiException::what() const noexcept +{ + return m_what.c_str(); +} + + +template +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 +std::vector 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(); + for (const auto& child: pt) { + arrayRet.emplace_back(MODEL_T(child.second)); + } + return arrayRet; +} + +template +std::string convertMapResponse(const std::map& map) +{ + boost::property_tree::ptree pt; + for(const auto &kv: map) { + pt.push_back(boost::property_tree::ptree::value_type( + boost::lexical_cast(kv.first), + boost::property_tree::ptree( + boost::lexical_cast(kv.second)))); + } + std::stringstream sstream; + write_json(sstream, pt); + std::string result = sstream.str(); + return result; +} + +namespace FakeApiResources { +FakeHealthResource::FakeHealthResource(const std::string& context /* = "/v2" */) +{ + this->set_path(context + "/fake/health"); + this->set_method_handler("GET", + std::bind(&FakeHealthResource::handler_GET_internal, this, + std::placeholders::_1)); +} + +std::pair FakeHealthResource::handleFakeApiException(const FakeApiException& e) +{ + return std::make_pair(e.getStatus(), e.what()); +} + +std::pair FakeHealthResource::handleStdException(const std::exception& e) +{ + return std::make_pair(500, e.what()); +} + +std::pair FakeHealthResource::handleUnspecifiedException() +{ + return std::make_pair(500, "Unknown exception occurred"); +} + +void FakeHealthResource::setResponseHeader(const std::shared_ptr& session, const std::string& header) +{ + session->set_header(header, ""); +} + +void FakeHealthResource::returnResponse(const std::shared_ptr& session, const int status, const std::string& result, std::multimap& responseHeaders) +{ + responseHeaders.insert(std::make_pair("Connection", "close")); + session->close(status, result, responseHeaders); +} + +void FakeHealthResource::defaultSessionClose(const std::shared_ptr& session, const int status, const std::string& result) +{ + session->close(status, result, { {"Connection", "close"} }); +} + +void FakeHealthResource::handler_GET_internal(const std::shared_ptr session) +{ + const auto request = session->get_request(); + + int status_code = 500; + HealthCheckResult resultObject = HealthCheckResult{}; + std::string result = ""; + + try { + std::tie(status_code, resultObject) = + handler_GET(); + } + catch(const FakeApiException& e) { + std::tie(status_code, result) = handleFakeApiException(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 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 = resultObject.toJsonString(); + returnResponse(session, 200, result.empty() ? "{}" : result, responseHeaders); + return; + } + defaultSessionClose(session, status_code, result); +} + + +std::pair FakeHealthResource::handler_GET( + ) +{ + return handler_GET_func(); +} + + +std::string FakeHealthResource::extractBodyContent(const std::shared_ptr& 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 session, + const restbed::Bytes &body) { + bodyContent = restbed::String::format( + "%.*s\n", (int)body.size(), body.data()); + }); + return bodyContent; +} + +std::string FakeHealthResource::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 ""; +} +FakeHttp_signature_testResource::FakeHttp_signature_testResource(const std::string& context /* = "/v2" */) +{ + this->set_path(context + "/fake/http-signature-test"); + this->set_method_handler("GET", + std::bind(&FakeHttp_signature_testResource::handler_GET_internal, this, + std::placeholders::_1)); +} + +std::pair FakeHttp_signature_testResource::handleFakeApiException(const FakeApiException& e) +{ + return std::make_pair(e.getStatus(), e.what()); +} + +std::pair FakeHttp_signature_testResource::handleStdException(const std::exception& e) +{ + return std::make_pair(500, e.what()); +} + +std::pair FakeHttp_signature_testResource::handleUnspecifiedException() +{ + return std::make_pair(500, "Unknown exception occurred"); +} + +void FakeHttp_signature_testResource::setResponseHeader(const std::shared_ptr& session, const std::string& header) +{ + session->set_header(header, ""); +} + +void FakeHttp_signature_testResource::returnResponse(const std::shared_ptr& session, const int status, const std::string& result, std::multimap& responseHeaders) +{ + responseHeaders.insert(std::make_pair("Connection", "close")); + session->close(status, result, responseHeaders); +} + +void FakeHttp_signature_testResource::defaultSessionClose(const std::shared_ptr& session, const int status, const std::string& result) +{ + session->close(status, result, { {"Connection", "close"} }); +} + +void FakeHttp_signature_testResource::handler_GET_internal(const std::shared_ptr session) +{ + const auto request = session->get_request(); + // body params or form params here from the body content string + std::string bodyContent = extractBodyContent(session); + auto pet = extractJsonModelBodyParam(bodyContent); + // Getting the query params + std::string query1 = request->get_query_parameter("query1", ""); + // Getting the headers + std::string header1 = request->get_header("header_1", ""); + + int status_code = 500; + std::string result = ""; + + try { + status_code = + handler_GET(pet, query1, header1); + } + catch(const FakeApiException& e) { + std::tie(status_code, result) = handleFakeApiException(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 contentTypes{ + "application/json" + }; + static const std::string acceptTypes{ + "application/json, application/xml, " + }; + + if (status_code == 200) { + responseHeaders.insert(std::make_pair("Content-Type", selectPreferredContentType(contentTypes))); + if (!acceptTypes.empty()) { + responseHeaders.insert(std::make_pair("Accept", acceptTypes)); + } + + returnResponse(session, 200, result.empty() ? "{}" : result, responseHeaders); + return; + } + defaultSessionClose(session, status_code, result); +} + + +int FakeHttp_signature_testResource::handler_GET( + Pet & pet, std::string & query1, std::string & header1) +{ + return handler_GET_func(pet, query1, header1); +} + + +std::string FakeHttp_signature_testResource::extractBodyContent(const std::shared_ptr& 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 session, + const restbed::Bytes &body) { + bodyContent = restbed::String::format( + "%.*s\n", (int)body.size(), body.data()); + }); + return bodyContent; +} + +std::string FakeHttp_signature_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 ""; +} +FakeOuterBooleanResource::FakeOuterBooleanResource(const std::string& context /* = "/v2" */) +{ + this->set_path(context + "/fake/outer/boolean"); + this->set_method_handler("POST", + std::bind(&FakeOuterBooleanResource::handler_POST_internal, this, + std::placeholders::_1)); +} + +std::pair FakeOuterBooleanResource::handleFakeApiException(const FakeApiException& e) +{ + return std::make_pair(e.getStatus(), e.what()); +} + +std::pair FakeOuterBooleanResource::handleStdException(const std::exception& e) +{ + return std::make_pair(500, e.what()); +} + +std::pair FakeOuterBooleanResource::handleUnspecifiedException() +{ + return std::make_pair(500, "Unknown exception occurred"); +} + +void FakeOuterBooleanResource::setResponseHeader(const std::shared_ptr& session, const std::string& header) +{ + session->set_header(header, ""); +} + +void FakeOuterBooleanResource::returnResponse(const std::shared_ptr& session, const int status, const std::string& result, std::multimap& responseHeaders) +{ + responseHeaders.insert(std::make_pair("Connection", "close")); + session->close(status, result, responseHeaders); +} + +void FakeOuterBooleanResource::defaultSessionClose(const std::shared_ptr& session, const int status, const std::string& result) +{ + session->close(status, result, { {"Connection", "close"} }); +} + +void FakeOuterBooleanResource::handler_POST_internal(const std::shared_ptr session) +{ + const auto request = session->get_request(); + // body params or form params here from the body content string + std::string bodyContent = extractBodyContent(session); + auto body = boost::lexical_cast(bodyContent); + + int status_code = 500; + bool resultObject = false; + std::string result = ""; + + try { + std::tie(status_code, resultObject) = + handler_POST(body); + } + catch(const FakeApiException& e) { + std::tie(status_code, result) = handleFakeApiException(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 contentTypes{ + "*/*", + }; + 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)); + } + + returnResponse(session, 200, result.empty() ? "{}" : result, responseHeaders); + return; + } + defaultSessionClose(session, status_code, result); +} + + +std::pair FakeOuterBooleanResource::handler_POST( + bool & body) +{ + return handler_POST_func(body); +} + + +std::string FakeOuterBooleanResource::extractBodyContent(const std::shared_ptr& 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 session, + const restbed::Bytes &body) { + bodyContent = restbed::String::format( + "%.*s\n", (int)body.size(), body.data()); + }); + return bodyContent; +} + +std::string FakeOuterBooleanResource::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 ""; +} +FakeOuterCompositeResource::FakeOuterCompositeResource(const std::string& context /* = "/v2" */) +{ + this->set_path(context + "/fake/outer/composite"); + this->set_method_handler("POST", + std::bind(&FakeOuterCompositeResource::handler_POST_internal, this, + std::placeholders::_1)); +} + +std::pair FakeOuterCompositeResource::handleFakeApiException(const FakeApiException& e) +{ + return std::make_pair(e.getStatus(), e.what()); +} + +std::pair FakeOuterCompositeResource::handleStdException(const std::exception& e) +{ + return std::make_pair(500, e.what()); +} + +std::pair FakeOuterCompositeResource::handleUnspecifiedException() +{ + return std::make_pair(500, "Unknown exception occurred"); +} + +void FakeOuterCompositeResource::setResponseHeader(const std::shared_ptr& session, const std::string& header) +{ + session->set_header(header, ""); +} + +void FakeOuterCompositeResource::returnResponse(const std::shared_ptr& session, const int status, const std::string& result, std::multimap& responseHeaders) +{ + responseHeaders.insert(std::make_pair("Connection", "close")); + session->close(status, result, responseHeaders); +} + +void FakeOuterCompositeResource::defaultSessionClose(const std::shared_ptr& session, const int status, const std::string& result) +{ + session->close(status, result, { {"Connection", "close"} }); +} + +void FakeOuterCompositeResource::handler_POST_internal(const std::shared_ptr session) +{ + const auto request = session->get_request(); + // body params or form params here from the body content string + std::string bodyContent = extractBodyContent(session); + auto outerComposite = extractJsonModelBodyParam(bodyContent); + + int status_code = 500; + OuterComposite resultObject = OuterComposite{}; + std::string result = ""; + + try { + std::tie(status_code, resultObject) = + handler_POST(outerComposite); + } + catch(const FakeApiException& e) { + std::tie(status_code, result) = handleFakeApiException(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 contentTypes{ + "*/*", + }; + 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 FakeOuterCompositeResource::handler_POST( + OuterComposite & outerComposite) +{ + return handler_POST_func(outerComposite); +} + + +std::string FakeOuterCompositeResource::extractBodyContent(const std::shared_ptr& 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 session, + const restbed::Bytes &body) { + bodyContent = restbed::String::format( + "%.*s\n", (int)body.size(), body.data()); + }); + return bodyContent; +} + +std::string FakeOuterCompositeResource::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 ""; +} +FakeOuterNumberResource::FakeOuterNumberResource(const std::string& context /* = "/v2" */) +{ + this->set_path(context + "/fake/outer/number"); + this->set_method_handler("POST", + std::bind(&FakeOuterNumberResource::handler_POST_internal, this, + std::placeholders::_1)); +} + +std::pair FakeOuterNumberResource::handleFakeApiException(const FakeApiException& e) +{ + return std::make_pair(e.getStatus(), e.what()); +} + +std::pair FakeOuterNumberResource::handleStdException(const std::exception& e) +{ + return std::make_pair(500, e.what()); +} + +std::pair FakeOuterNumberResource::handleUnspecifiedException() +{ + return std::make_pair(500, "Unknown exception occurred"); +} + +void FakeOuterNumberResource::setResponseHeader(const std::shared_ptr& session, const std::string& header) +{ + session->set_header(header, ""); +} + +void FakeOuterNumberResource::returnResponse(const std::shared_ptr& session, const int status, const std::string& result, std::multimap& responseHeaders) +{ + responseHeaders.insert(std::make_pair("Connection", "close")); + session->close(status, result, responseHeaders); +} + +void FakeOuterNumberResource::defaultSessionClose(const std::shared_ptr& session, const int status, const std::string& result) +{ + session->close(status, result, { {"Connection", "close"} }); +} + +void FakeOuterNumberResource::handler_POST_internal(const std::shared_ptr session) +{ + const auto request = session->get_request(); + // body params or form params here from the body content string + std::string bodyContent = extractBodyContent(session); + auto body = boost::lexical_cast(bodyContent); + + int status_code = 500; + double resultObject = 0.0; + std::string result = ""; + + try { + std::tie(status_code, resultObject) = + handler_POST(body); + } + catch(const FakeApiException& e) { + std::tie(status_code, result) = handleFakeApiException(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 contentTypes{ + "*/*", + }; + 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)); + } + + returnResponse(session, 200, result.empty() ? "{}" : result, responseHeaders); + return; + } + defaultSessionClose(session, status_code, result); +} + + +std::pair FakeOuterNumberResource::handler_POST( + double & body) +{ + return handler_POST_func(body); +} + + +std::string FakeOuterNumberResource::extractBodyContent(const std::shared_ptr& 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 session, + const restbed::Bytes &body) { + bodyContent = restbed::String::format( + "%.*s\n", (int)body.size(), body.data()); + }); + return bodyContent; +} + +std::string FakeOuterNumberResource::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 ""; +} +FakeOuterStringResource::FakeOuterStringResource(const std::string& context /* = "/v2" */) +{ + this->set_path(context + "/fake/outer/string"); + this->set_method_handler("POST", + std::bind(&FakeOuterStringResource::handler_POST_internal, this, + std::placeholders::_1)); +} + +std::pair FakeOuterStringResource::handleFakeApiException(const FakeApiException& e) +{ + return std::make_pair(e.getStatus(), e.what()); +} + +std::pair FakeOuterStringResource::handleStdException(const std::exception& e) +{ + return std::make_pair(500, e.what()); +} + +std::pair FakeOuterStringResource::handleUnspecifiedException() +{ + return std::make_pair(500, "Unknown exception occurred"); +} + +void FakeOuterStringResource::setResponseHeader(const std::shared_ptr& session, const std::string& header) +{ + session->set_header(header, ""); +} + +void FakeOuterStringResource::returnResponse(const std::shared_ptr& session, const int status, const std::string& result, std::multimap& responseHeaders) +{ + responseHeaders.insert(std::make_pair("Connection", "close")); + session->close(status, result, responseHeaders); +} + +void FakeOuterStringResource::defaultSessionClose(const std::shared_ptr& session, const int status, const std::string& result) +{ + session->close(status, result, { {"Connection", "close"} }); +} + +void FakeOuterStringResource::handler_POST_internal(const std::shared_ptr session) +{ + const auto request = session->get_request(); + // body params or form params here from the body content string + std::string bodyContent = extractBodyContent(session); + auto body = boost::lexical_cast(bodyContent); + + int status_code = 500; + std::string resultObject = ""; + std::string result = ""; + + try { + std::tie(status_code, resultObject) = + handler_POST(body); + } + catch(const FakeApiException& e) { + std::tie(status_code, result) = handleFakeApiException(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 contentTypes{ + "*/*", + }; + 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; + returnResponse(session, 200, result.empty() ? "{}" : result, responseHeaders); + return; + } + defaultSessionClose(session, status_code, result); +} + + +std::pair FakeOuterStringResource::handler_POST( + std::string & body) +{ + return handler_POST_func(body); +} + + +std::string FakeOuterStringResource::extractBodyContent(const std::shared_ptr& 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 session, + const restbed::Bytes &body) { + bodyContent = restbed::String::format( + "%.*s\n", (int)body.size(), body.data()); + }); + return bodyContent; +} + +std::string FakeOuterStringResource::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 ""; +} +FakePropertyEnum_intResource::FakePropertyEnum_intResource(const std::string& context /* = "/v2" */) +{ + this->set_path(context + "/fake/property/enum-int"); + this->set_method_handler("POST", + std::bind(&FakePropertyEnum_intResource::handler_POST_internal, this, + std::placeholders::_1)); +} + +std::pair FakePropertyEnum_intResource::handleFakeApiException(const FakeApiException& e) +{ + return std::make_pair(e.getStatus(), e.what()); +} + +std::pair FakePropertyEnum_intResource::handleStdException(const std::exception& e) +{ + return std::make_pair(500, e.what()); +} + +std::pair FakePropertyEnum_intResource::handleUnspecifiedException() +{ + return std::make_pair(500, "Unknown exception occurred"); +} + +void FakePropertyEnum_intResource::setResponseHeader(const std::shared_ptr& session, const std::string& header) +{ + session->set_header(header, ""); +} + +void FakePropertyEnum_intResource::returnResponse(const std::shared_ptr& session, const int status, const std::string& result, std::multimap& responseHeaders) +{ + responseHeaders.insert(std::make_pair("Connection", "close")); + session->close(status, result, responseHeaders); +} + +void FakePropertyEnum_intResource::defaultSessionClose(const std::shared_ptr& session, const int status, const std::string& result) +{ + session->close(status, result, { {"Connection", "close"} }); +} + +void FakePropertyEnum_intResource::handler_POST_internal(const std::shared_ptr session) +{ + const auto request = session->get_request(); + // body params or form params here from the body content string + std::string bodyContent = extractBodyContent(session); + auto outerObjectWithEnumProperty = extractJsonModelBodyParam(bodyContent); + + int status_code = 500; + OuterObjectWithEnumProperty resultObject = OuterObjectWithEnumProperty{}; + std::string result = ""; + + try { + std::tie(status_code, resultObject) = + handler_POST(outerObjectWithEnumProperty); + } + catch(const FakeApiException& e) { + std::tie(status_code, result) = handleFakeApiException(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 contentTypes{ + "*/*", + }; + 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 FakePropertyEnum_intResource::handler_POST( + OuterObjectWithEnumProperty & outerObjectWithEnumProperty) +{ + return handler_POST_func(outerObjectWithEnumProperty); +} + + +std::string FakePropertyEnum_intResource::extractBodyContent(const std::shared_ptr& 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 session, + const restbed::Bytes &body) { + bodyContent = restbed::String::format( + "%.*s\n", (int)body.size(), body.data()); + }); + return bodyContent; +} + +std::string FakePropertyEnum_intResource::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 ""; +} +FakeBody_with_binaryResource::FakeBody_with_binaryResource(const std::string& context /* = "/v2" */) +{ + this->set_path(context + "/fake/body-with-binary"); + this->set_method_handler("PUT", + std::bind(&FakeBody_with_binaryResource::handler_PUT_internal, this, + std::placeholders::_1)); +} + +std::pair FakeBody_with_binaryResource::handleFakeApiException(const FakeApiException& e) +{ + return std::make_pair(e.getStatus(), e.what()); +} + +std::pair FakeBody_with_binaryResource::handleStdException(const std::exception& e) +{ + return std::make_pair(500, e.what()); +} + +std::pair FakeBody_with_binaryResource::handleUnspecifiedException() +{ + return std::make_pair(500, "Unknown exception occurred"); +} + +void FakeBody_with_binaryResource::setResponseHeader(const std::shared_ptr& session, const std::string& header) +{ + session->set_header(header, ""); +} + +void FakeBody_with_binaryResource::returnResponse(const std::shared_ptr& session, const int status, const std::string& result, std::multimap& responseHeaders) +{ + responseHeaders.insert(std::make_pair("Connection", "close")); + session->close(status, result, responseHeaders); +} + +void FakeBody_with_binaryResource::defaultSessionClose(const std::shared_ptr& session, const int status, const std::string& result) +{ + session->close(status, result, { {"Connection", "close"} }); +} + +void FakeBody_with_binaryResource::handler_PUT_internal(const std::shared_ptr session) +{ + const auto request = session->get_request(); + // body params or form params here from the body content string + std::string bodyContent = extractBodyContent(session); + auto body = boost::lexical_cast(bodyContent); + + int status_code = 500; + std::string result = ""; + + try { + status_code = + handler_PUT(body); + } + catch(const FakeApiException& e) { + std::tie(status_code, result) = handleFakeApiException(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 contentTypes{ + "application/json" + }; + static const std::string acceptTypes{ + "image/png, " + }; + + if (status_code == 200) { + responseHeaders.insert(std::make_pair("Content-Type", selectPreferredContentType(contentTypes))); + if (!acceptTypes.empty()) { + responseHeaders.insert(std::make_pair("Accept", acceptTypes)); + } + + returnResponse(session, 200, result.empty() ? "{}" : result, responseHeaders); + return; + } + defaultSessionClose(session, status_code, result); +} + + +int FakeBody_with_binaryResource::handler_PUT( + std::string & body) +{ + return handler_PUT_func(body); +} + + +std::string FakeBody_with_binaryResource::extractBodyContent(const std::shared_ptr& 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 session, + const restbed::Bytes &body) { + bodyContent = restbed::String::format( + "%.*s\n", (int)body.size(), body.data()); + }); + return bodyContent; +} + +std::string FakeBody_with_binaryResource::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 ""; +} +FakeBody_with_file_schemaResource::FakeBody_with_file_schemaResource(const std::string& context /* = "/v2" */) +{ + this->set_path(context + "/fake/body-with-file-schema"); + this->set_method_handler("PUT", + std::bind(&FakeBody_with_file_schemaResource::handler_PUT_internal, this, + std::placeholders::_1)); +} + +std::pair FakeBody_with_file_schemaResource::handleFakeApiException(const FakeApiException& e) +{ + return std::make_pair(e.getStatus(), e.what()); +} + +std::pair FakeBody_with_file_schemaResource::handleStdException(const std::exception& e) +{ + return std::make_pair(500, e.what()); +} + +std::pair FakeBody_with_file_schemaResource::handleUnspecifiedException() +{ + return std::make_pair(500, "Unknown exception occurred"); +} + +void FakeBody_with_file_schemaResource::setResponseHeader(const std::shared_ptr& session, const std::string& header) +{ + session->set_header(header, ""); +} + +void FakeBody_with_file_schemaResource::returnResponse(const std::shared_ptr& session, const int status, const std::string& result, std::multimap& responseHeaders) +{ + responseHeaders.insert(std::make_pair("Connection", "close")); + session->close(status, result, responseHeaders); +} + +void FakeBody_with_file_schemaResource::defaultSessionClose(const std::shared_ptr& session, const int status, const std::string& result) +{ + session->close(status, result, { {"Connection", "close"} }); +} + +void FakeBody_with_file_schemaResource::handler_PUT_internal(const std::shared_ptr session) +{ + const auto request = session->get_request(); + // body params or form params here from the body content string + std::string bodyContent = extractBodyContent(session); + auto fileSchemaTestClass = extractJsonModelBodyParam(bodyContent); + + int status_code = 500; + std::string result = ""; + + try { + status_code = + handler_PUT(fileSchemaTestClass); + } + catch(const FakeApiException& e) { + std::tie(status_code, result) = handleFakeApiException(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 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)); + } + + returnResponse(session, 200, result.empty() ? "{}" : result, responseHeaders); + return; + } + defaultSessionClose(session, status_code, result); +} + + +int FakeBody_with_file_schemaResource::handler_PUT( + FileSchemaTestClass & fileSchemaTestClass) +{ + return handler_PUT_func(fileSchemaTestClass); +} + + +std::string FakeBody_with_file_schemaResource::extractBodyContent(const std::shared_ptr& 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 session, + const restbed::Bytes &body) { + bodyContent = restbed::String::format( + "%.*s\n", (int)body.size(), body.data()); + }); + return bodyContent; +} + +std::string FakeBody_with_file_schemaResource::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 ""; +} +FakeBody_with_query_paramsResource::FakeBody_with_query_paramsResource(const std::string& context /* = "/v2" */) +{ + this->set_path(context + "/fake/body-with-query-params"); + this->set_method_handler("PUT", + std::bind(&FakeBody_with_query_paramsResource::handler_PUT_internal, this, + std::placeholders::_1)); +} + +std::pair FakeBody_with_query_paramsResource::handleFakeApiException(const FakeApiException& e) +{ + return std::make_pair(e.getStatus(), e.what()); +} + +std::pair FakeBody_with_query_paramsResource::handleStdException(const std::exception& e) +{ + return std::make_pair(500, e.what()); +} + +std::pair FakeBody_with_query_paramsResource::handleUnspecifiedException() +{ + return std::make_pair(500, "Unknown exception occurred"); +} + +void FakeBody_with_query_paramsResource::setResponseHeader(const std::shared_ptr& session, const std::string& header) +{ + session->set_header(header, ""); +} + +void FakeBody_with_query_paramsResource::returnResponse(const std::shared_ptr& session, const int status, const std::string& result, std::multimap& responseHeaders) +{ + responseHeaders.insert(std::make_pair("Connection", "close")); + session->close(status, result, responseHeaders); +} + +void FakeBody_with_query_paramsResource::defaultSessionClose(const std::shared_ptr& session, const int status, const std::string& result) +{ + session->close(status, result, { {"Connection", "close"} }); +} + +void FakeBody_with_query_paramsResource::handler_PUT_internal(const std::shared_ptr session) +{ + const auto request = session->get_request(); + // body params or form params here from the body content string + std::string bodyContent = extractBodyContent(session); + auto user = extractJsonModelBodyParam(bodyContent); + // Getting the query params + std::string query = request->get_query_parameter("query", ""); + + int status_code = 500; + std::string result = ""; + + try { + status_code = + handler_PUT(query, user); + } + catch(const FakeApiException& e) { + std::tie(status_code, result) = handleFakeApiException(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 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)); + } + + returnResponse(session, 200, result.empty() ? "{}" : result, responseHeaders); + return; + } + defaultSessionClose(session, status_code, result); +} + + +int FakeBody_with_query_paramsResource::handler_PUT( + std::string & query, User & user) +{ + return handler_PUT_func(query, user); +} + + +std::string FakeBody_with_query_paramsResource::extractBodyContent(const std::shared_ptr& 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 session, + const restbed::Bytes &body) { + bodyContent = restbed::String::format( + "%.*s\n", (int)body.size(), body.data()); + }); + return bodyContent; +} + +std::string FakeBody_with_query_paramsResource::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 ""; +} +FakeResource::FakeResource(const std::string& context /* = "/v2" */) +{ + this->set_path(context + "/fake"); + this->set_method_handler("PATCH", + std::bind(&FakeResource::handler_PATCH_internal, this, + std::placeholders::_1)); + this->set_method_handler("POST", + std::bind(&FakeResource::handler_POST_internal, this, + std::placeholders::_1)); + this->set_method_handler("GET", + std::bind(&FakeResource::handler_GET_internal, this, + std::placeholders::_1)); + this->set_method_handler("DELETE", + std::bind(&FakeResource::handler_DELETE_internal, this, + std::placeholders::_1)); +} + +std::pair FakeResource::handleFakeApiException(const FakeApiException& e) +{ + return std::make_pair(e.getStatus(), e.what()); +} + +std::pair FakeResource::handleStdException(const std::exception& e) +{ + return std::make_pair(500, e.what()); +} + +std::pair FakeResource::handleUnspecifiedException() +{ + return std::make_pair(500, "Unknown exception occurred"); +} + +void FakeResource::setResponseHeader(const std::shared_ptr& session, const std::string& header) +{ + session->set_header(header, ""); +} + +void FakeResource::returnResponse(const std::shared_ptr& session, const int status, const std::string& result, std::multimap& responseHeaders) +{ + responseHeaders.insert(std::make_pair("Connection", "close")); + session->close(status, result, responseHeaders); +} + +void FakeResource::defaultSessionClose(const std::shared_ptr& session, const int status, const std::string& result) +{ + session->close(status, result, { {"Connection", "close"} }); +} + +void FakeResource::handler_PATCH_internal(const std::shared_ptr 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(bodyContent); + + int status_code = 500; + Client resultObject = Client{}; + std::string result = ""; + + try { + std::tie(status_code, resultObject) = + handler_PATCH(client); + } + catch(const FakeApiException& e) { + std::tie(status_code, result) = handleFakeApiException(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 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); +} + +// x-extension +void FakeResource::handler_POST_internal(const std::shared_ptr session) { + const auto request = session->get_request(); + auto integer = boost::lexical_cast(extractFormParamsFromBody("integer", extractBodyContent(session))); + auto int32 = boost::lexical_cast(extractFormParamsFromBody("int32", extractBodyContent(session))); + auto int64 = boost::lexical_cast(extractFormParamsFromBody("int64", extractBodyContent(session))); + auto number = boost::lexical_cast(extractFormParamsFromBody("number", extractBodyContent(session))); + auto r_float = boost::lexical_cast(extractFormParamsFromBody("r_float", extractBodyContent(session))); + auto r_double = boost::lexical_cast(extractFormParamsFromBody("r_double", extractBodyContent(session))); + auto string = boost::lexical_cast(extractFormParamsFromBody("string", extractBodyContent(session))); + auto patternWithoutDelimiter = boost::lexical_cast(extractFormParamsFromBody("patternWithoutDelimiter", extractBodyContent(session))); + auto byte = boost::lexical_cast(extractFormParamsFromBody("byte", extractBodyContent(session))); + auto binary = boost::lexical_cast(extractFormParamsFromBody("binary", extractBodyContent(session))); + auto date = boost::lexical_cast(extractFormParamsFromBody("date", extractBodyContent(session))); + auto dateTime = boost::lexical_cast(extractFormParamsFromBody("dateTime", extractBodyContent(session))); + auto password = boost::lexical_cast(extractFormParamsFromBody("password", extractBodyContent(session))); + auto callback = boost::lexical_cast(extractFormParamsFromBody("callback", extractBodyContent(session))); + + int status_code = 500; + std::string result = ""; + + try { + status_code = + handler_POST(number, r_double, patternWithoutDelimiter, byte, integer, int32, int64, r_float, string, binary, date, dateTime, password, callback); + } + catch(const FakeApiException& e) { + std::tie(status_code, result) = handleFakeApiException(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 contentTypes{ + "application/json" + }; + static const std::string acceptTypes{ + "application/x-www-form-urlencoded, " + }; + + if (status_code == 400) { + responseHeaders.insert(std::make_pair("Content-Type", "text/plain")); + result = "Invalid username supplied"; + + returnResponse(session, 400, result.empty() ? "{}" : result, responseHeaders); + return; + } + if (status_code == 404) { + responseHeaders.insert(std::make_pair("Content-Type", "text/plain")); + result = "User not found"; + + returnResponse(session, 404, result.empty() ? "{}" : result, responseHeaders); + return; + } + defaultSessionClose(session, status_code, result); +} +// x-extension +void FakeResource::handler_GET_internal(const std::shared_ptr session) { + const auto request = session->get_request(); + std::string enumFormStringArray_raw = extractFormParamsFromBody("enumFormStringArray", extractBodyContent(session)); + std::vector enumFormStringArray; + boost::split(enumFormStringArray, enumFormStringArray_raw, boost::is_any_of(",")); + auto enumFormString = boost::lexical_cast(extractFormParamsFromBody("enumFormString", extractBodyContent(session))); + // Getting the query params + std::string enumQueryStringArray_raw = request->get_query_parameter("enumQueryStringArray"); + std::vector enumQueryStringArray; + std::vector enumQueryStringArray_temp; + boost::split(enumQueryStringArray_temp, enumQueryStringArray_raw, boost::is_any_of(",")); + std::copy(enumQueryStringArray_temp.begin(), enumQueryStringArray_temp.end(), std::inserter(enumQueryStringArray, std::next(enumQueryStringArray.begin()))); + std::string enumQueryString = request->get_query_parameter("enumQueryString", "-efg"); + int32_t enumQueryInteger = request->get_query_parameter("enumQueryInteger", 0); + double enumQueryDouble = request->get_query_parameter("enumQueryDouble", 0.0); + std::string enumQueryModelArray_raw = request->get_query_parameter("enumQueryModelArray"); + std::vector enumQueryModelArray; + std::vector enumQueryModelArray_temp; + boost::split(enumQueryModelArray_temp, enumQueryModelArray_raw, boost::is_any_of(",")); + #if 0 + /* + CodegenProperty{openApiType='EnumClass', baseName='inner', complexType='EnumClass', getter='getInner', setter='setInner', description='null', dataType='EnumClass', datatypeWithEnum='EnumClass', dataFormat='null', name='Inner', min='null', max='null', defaultValue='EnumClass{}', defaultValueWithParam=' = data.inner;', baseType='EnumClass', containerType='null', title='null', unescapedDescription='null', maxLength=null, minLength=null, pattern='null', example='null', jsonSchema='{ + "$ref" : "#/components/schemas/EnumClass" + }', minimum='null', maximum='null', exclusiveMinimum=false, exclusiveMaximum=false, required=false, deprecated=false, hasMoreNonReadOnly=false, isPrimitiveType=false, isModel=false, isContainer=false, isString=false, isNumeric=false, isInteger=false, isShort=false, isLong=false, isUnboundedInteger=false, isNumber=false, isFloat=false, isDouble=false, isDecimal=false, isByteArray=false, isBinary=false, isFile=false, isBoolean=false, isDate=false, isDateTime=false, isUuid=false, isUri=false, isEmail=false, isFreeFormObject=false, isArray=false, isMap=false, isEnum=false, isAnyType=false, isReadOnly=false, isWriteOnly=false, isNullable=false, isSelfReference=false, isCircularReference=false, isDiscriminator=false, _enum=null, allowableValues={values=[_abc, -efg, (xyz)]}, items=null, additionalProperties=null, vars=[], requiredVars=[], mostInnerItems=null, vendorExtensions={}, hasValidation=false, isInherited=false, discriminatorValue='null', nameInCamelCase='inner', nameInSnakeCase='INNER', enumName='null', maxItems=null, minItems=null, maxProperties=null, minProperties=null, uniqueItems=false, multipleOf=null, isXmlAttribute=false, xmlPrefix='null', xmlName='null', xmlNamespace='null', isXmlWrapped=false, isNull=false, getAdditionalPropertiesIsAnyType=false, getHasVars=false, getHasRequired=false, getHasDiscriminatorWithNonEmptyMapping=false, composedSchemas=null, hasMultipleTypes=false} + */ + #endif + std::transform(enumQueryModelArray_temp.begin(), enumQueryModelArray_temp.end(), std::back_inserter(enumQueryModelArray), [](const auto& i){ EnumClass ret; ret.fromString(i); return ret;}); + // Getting the headers + std::string enumHeaderStringArray_raw = request->get_header("enumHeaderStringArray"); + std::vector enumHeaderStringArray; + boost::split(enumHeaderStringArray, enumHeaderStringArray_raw, boost::is_any_of(",")); + std::string enumHeaderString = request->get_header("enum_header_string", "-efg"); + + int status_code = 500; + std::string result = ""; + + try { + status_code = + handler_GET(enumHeaderStringArray, enumHeaderString, enumQueryStringArray, enumQueryString, enumQueryInteger, enumQueryDouble, enumQueryModelArray, enumFormStringArray, enumFormString); + } + catch(const FakeApiException& e) { + std::tie(status_code, result) = handleFakeApiException(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 contentTypes{ + "application/json" + }; + static const std::string acceptTypes{ + "application/x-www-form-urlencoded, " + }; + + if (status_code == 400) { + responseHeaders.insert(std::make_pair("Content-Type", "text/plain")); + result = "Invalid request"; + + returnResponse(session, 400, result.empty() ? "{}" : result, responseHeaders); + return; + } + if (status_code == 404) { + responseHeaders.insert(std::make_pair("Content-Type", "text/plain")); + result = "Not found"; + + returnResponse(session, 404, result.empty() ? "{}" : result, responseHeaders); + return; + } + defaultSessionClose(session, status_code, result); +} +// x-extension +void FakeResource::handler_DELETE_internal(const std::shared_ptr session) { + const auto request = session->get_request(); + // Getting the query params + int32_t requiredStringGroup = request->get_query_parameter("requiredStringGroup", 0); + int64_t requiredInt64Group = request->get_query_parameter("requiredInt64Group", 0L); + int32_t stringGroup = request->get_query_parameter("stringGroup", 0); + int64_t int64Group = request->get_query_parameter("int64Group", 0L); + // Getting the headers + bool requiredBooleanGroup = request->get_header("required_boolean_group", false); + bool booleanGroup = request->get_header("boolean_group", false); + + int status_code = 500; + std::string result = ""; + + try { + status_code = + handler_DELETE(requiredStringGroup, requiredBooleanGroup, requiredInt64Group, stringGroup, booleanGroup, int64Group); + } + catch(const FakeApiException& e) { + std::tie(status_code, result) = handleFakeApiException(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 contentTypes{ + "application/json" + }; + static const std::string acceptTypes{ + }; + + if (status_code == 400) { + responseHeaders.insert(std::make_pair("Content-Type", "text/plain")); + result = "Someting wrong"; + + returnResponse(session, 400, result.empty() ? "{}" : result, responseHeaders); + return; + } + defaultSessionClose(session, status_code, result); +} + +std::pair FakeResource::handler_PATCH( + Client & client) +{ + return handler_PATCH_func(client); +} + +int FakeResource::handler_POST( + double & number, double & r_double, std::string & patternWithoutDelimiter, std::string & byte, int32_t & integer, int32_t & int32, int64_t & int64, float & r_float, std::string & string, std::string & binary, std::string & date, std::string & dateTime, std::string & password, std::string & callback) +{ + return handler_POST_func(number, r_double, patternWithoutDelimiter, byte, integer, int32, int64, r_float, string, binary, date, dateTime, password, callback); +} +int FakeResource::handler_GET( + std::vector & enumHeaderStringArray, std::string & enumHeaderString, std::vector & enumQueryStringArray, std::string & enumQueryString, int32_t & enumQueryInteger, double & enumQueryDouble, std::vector & enumQueryModelArray, std::vector & enumFormStringArray, std::string & enumFormString) +{ + return handler_GET_func(enumHeaderStringArray, enumHeaderString, enumQueryStringArray, enumQueryString, enumQueryInteger, enumQueryDouble, enumQueryModelArray, enumFormStringArray, enumFormString); +} +int FakeResource::handler_DELETE( + int32_t & requiredStringGroup, bool & requiredBooleanGroup, int64_t & requiredInt64Group, int32_t & stringGroup, bool & booleanGroup, int64_t & int64Group) +{ + return handler_DELETE_func(requiredStringGroup, requiredBooleanGroup, requiredInt64Group, stringGroup, booleanGroup, int64Group); +} + +std::string FakeResource::extractBodyContent(const std::shared_ptr& 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 session, + const restbed::Bytes &body) { + bodyContent = restbed::String::format( + "%.*s\n", (int)body.size(), body.data()); + }); + return bodyContent; +} + +std::string FakeResource::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 ""; +} +FakeInline_additionalPropertiesResource::FakeInline_additionalPropertiesResource(const std::string& context /* = "/v2" */) +{ + this->set_path(context + "/fake/inline-additionalProperties"); + this->set_method_handler("POST", + std::bind(&FakeInline_additionalPropertiesResource::handler_POST_internal, this, + std::placeholders::_1)); +} + +std::pair FakeInline_additionalPropertiesResource::handleFakeApiException(const FakeApiException& e) +{ + return std::make_pair(e.getStatus(), e.what()); +} + +std::pair FakeInline_additionalPropertiesResource::handleStdException(const std::exception& e) +{ + return std::make_pair(500, e.what()); +} + +std::pair FakeInline_additionalPropertiesResource::handleUnspecifiedException() +{ + return std::make_pair(500, "Unknown exception occurred"); +} + +void FakeInline_additionalPropertiesResource::setResponseHeader(const std::shared_ptr& session, const std::string& header) +{ + session->set_header(header, ""); +} + +void FakeInline_additionalPropertiesResource::returnResponse(const std::shared_ptr& session, const int status, const std::string& result, std::multimap& responseHeaders) +{ + responseHeaders.insert(std::make_pair("Connection", "close")); + session->close(status, result, responseHeaders); +} + +void FakeInline_additionalPropertiesResource::defaultSessionClose(const std::shared_ptr& session, const int status, const std::string& result) +{ + session->close(status, result, { {"Connection", "close"} }); +} + +void FakeInline_additionalPropertiesResource::handler_POST_internal(const std::shared_ptr session) +{ + const auto request = session->get_request(); + // body params or form params here from the body content string + std::string bodyContent = extractBodyContent(session); + std::map requestBody; // TODO + + int status_code = 500; + std::string result = ""; + + try { + status_code = + handler_POST(requestBody); + } + catch(const FakeApiException& e) { + std::tie(status_code, result) = handleFakeApiException(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 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)); + } + + returnResponse(session, 200, result.empty() ? "{}" : result, responseHeaders); + return; + } + defaultSessionClose(session, status_code, result); +} + + +int FakeInline_additionalPropertiesResource::handler_POST( + std::map & requestBody) +{ + return handler_POST_func(requestBody); +} + + +std::string FakeInline_additionalPropertiesResource::extractBodyContent(const std::shared_ptr& 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 session, + const restbed::Bytes &body) { + bodyContent = restbed::String::format( + "%.*s\n", (int)body.size(), body.data()); + }); + return bodyContent; +} + +std::string FakeInline_additionalPropertiesResource::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 ""; +} +FakeJsonFormDataResource::FakeJsonFormDataResource(const std::string& context /* = "/v2" */) +{ + this->set_path(context + "/fake/jsonFormData"); + this->set_method_handler("GET", + std::bind(&FakeJsonFormDataResource::handler_GET_internal, this, + std::placeholders::_1)); +} + +std::pair FakeJsonFormDataResource::handleFakeApiException(const FakeApiException& e) +{ + return std::make_pair(e.getStatus(), e.what()); +} + +std::pair FakeJsonFormDataResource::handleStdException(const std::exception& e) +{ + return std::make_pair(500, e.what()); +} + +std::pair FakeJsonFormDataResource::handleUnspecifiedException() +{ + return std::make_pair(500, "Unknown exception occurred"); +} + +void FakeJsonFormDataResource::setResponseHeader(const std::shared_ptr& session, const std::string& header) +{ + session->set_header(header, ""); +} + +void FakeJsonFormDataResource::returnResponse(const std::shared_ptr& session, const int status, const std::string& result, std::multimap& responseHeaders) +{ + responseHeaders.insert(std::make_pair("Connection", "close")); + session->close(status, result, responseHeaders); +} + +void FakeJsonFormDataResource::defaultSessionClose(const std::shared_ptr& session, const int status, const std::string& result) +{ + session->close(status, result, { {"Connection", "close"} }); +} + +void FakeJsonFormDataResource::handler_GET_internal(const std::shared_ptr session) +{ + const auto request = session->get_request(); + auto param = boost::lexical_cast(extractFormParamsFromBody("param", extractBodyContent(session))); + auto param2 = boost::lexical_cast(extractFormParamsFromBody("param2", extractBodyContent(session))); + + int status_code = 500; + std::string result = ""; + + try { + status_code = + handler_GET(param, param2); + } + catch(const FakeApiException& e) { + std::tie(status_code, result) = handleFakeApiException(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 contentTypes{ + "application/json" + }; + static const std::string acceptTypes{ + "application/x-www-form-urlencoded, " + }; + + if (status_code == 200) { + responseHeaders.insert(std::make_pair("Content-Type", selectPreferredContentType(contentTypes))); + if (!acceptTypes.empty()) { + responseHeaders.insert(std::make_pair("Accept", acceptTypes)); + } + + returnResponse(session, 200, result.empty() ? "{}" : result, responseHeaders); + return; + } + defaultSessionClose(session, status_code, result); +} + + +int FakeJsonFormDataResource::handler_GET( + std::string & param, std::string & param2) +{ + return handler_GET_func(param, param2); +} + + +std::string FakeJsonFormDataResource::extractBodyContent(const std::shared_ptr& 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 session, + const restbed::Bytes &body) { + bodyContent = restbed::String::format( + "%.*s\n", (int)body.size(), body.data()); + }); + return bodyContent; +} + +std::string FakeJsonFormDataResource::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 ""; +} +FakeTest_query_parametersResource::FakeTest_query_parametersResource(const std::string& context /* = "/v2" */) +{ + this->set_path(context + "/fake/test-query-parameters"); + this->set_method_handler("PUT", + std::bind(&FakeTest_query_parametersResource::handler_PUT_internal, this, + std::placeholders::_1)); +} + +std::pair FakeTest_query_parametersResource::handleFakeApiException(const FakeApiException& e) +{ + return std::make_pair(e.getStatus(), e.what()); +} + +std::pair FakeTest_query_parametersResource::handleStdException(const std::exception& e) +{ + return std::make_pair(500, e.what()); +} + +std::pair FakeTest_query_parametersResource::handleUnspecifiedException() +{ + return std::make_pair(500, "Unknown exception occurred"); +} + +void FakeTest_query_parametersResource::setResponseHeader(const std::shared_ptr& session, const std::string& header) +{ + session->set_header(header, ""); +} + +void FakeTest_query_parametersResource::returnResponse(const std::shared_ptr& session, const int status, const std::string& result, std::multimap& responseHeaders) +{ + responseHeaders.insert(std::make_pair("Connection", "close")); + session->close(status, result, responseHeaders); +} + +void FakeTest_query_parametersResource::defaultSessionClose(const std::shared_ptr& session, const int status, const std::string& result) +{ + session->close(status, result, { {"Connection", "close"} }); +} + +void FakeTest_query_parametersResource::handler_PUT_internal(const std::shared_ptr session) +{ + const auto request = session->get_request(); + // Getting the query params + std::string pipe_raw = request->get_query_parameter("pipe"); + std::vector pipe; + std::vector pipe_temp; + boost::split(pipe_temp, pipe_raw, boost::is_any_of(",")); + std::copy(pipe_temp.begin(), pipe_temp.end(), std::inserter(pipe, std::next(pipe.begin()))); + std::string ioutil_raw = request->get_query_parameter("ioutil"); + std::vector ioutil; + std::vector ioutil_temp; + boost::split(ioutil_temp, ioutil_raw, boost::is_any_of(",")); + std::copy(ioutil_temp.begin(), ioutil_temp.end(), std::inserter(ioutil, std::next(ioutil.begin()))); + std::string http_raw = request->get_query_parameter("http"); + std::vector http; + std::vector http_temp; + boost::split(http_temp, http_raw, boost::is_any_of(",")); + std::copy(http_temp.begin(), http_temp.end(), std::inserter(http, std::next(http.begin()))); + std::string url_raw = request->get_query_parameter("url"); + std::vector url; + std::vector url_temp; + boost::split(url_temp, url_raw, boost::is_any_of(",")); + std::copy(url_temp.begin(), url_temp.end(), std::inserter(url, std::next(url.begin()))); + std::string context_raw = request->get_query_parameter("context"); + std::vector context; + std::vector context_temp; + boost::split(context_temp, context_raw, boost::is_any_of(",")); + std::copy(context_temp.begin(), context_temp.end(), std::inserter(context, std::next(context.begin()))); + std::stringstream language_raw(request->get_query_parameter("language")); + boost::property_tree::ptree language_pt; + boost::property_tree::json_parser::read_json(language_raw,language_pt); + std::map language = std::map{}; + for (auto& item: language_pt) { + language.emplace(item.first, item.second.get_value()); + } + std::string allowEmpty = request->get_query_parameter("allowEmpty", ""); + + int status_code = 500; + std::string result = ""; + + try { + status_code = + handler_PUT(pipe, ioutil, http, url, context, allowEmpty, language); + } + catch(const FakeApiException& e) { + std::tie(status_code, result) = handleFakeApiException(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 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)); + } + + returnResponse(session, 200, result.empty() ? "{}" : result, responseHeaders); + return; + } + defaultSessionClose(session, status_code, result); +} + + +int FakeTest_query_parametersResource::handler_PUT( + std::vector & pipe, std::vector & ioutil, std::vector & http, std::vector & url, std::vector & context, std::string & allowEmpty, std::map & language) +{ + return handler_PUT_func(pipe, ioutil, http, url, context, allowEmpty, language); +} + + +std::string FakeTest_query_parametersResource::extractBodyContent(const std::shared_ptr& 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 session, + const restbed::Bytes &body) { + bodyContent = restbed::String::format( + "%.*s\n", (int)body.size(), body.data()); + }); + return bodyContent; +} + +std::string FakeTest_query_parametersResource::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 FakeApiResources */ + +FakeApi::FakeApi(std::shared_ptr const& restbedService) +: m_service(restbedService) +{ +} + +FakeApi::~FakeApi() {} + +std::shared_ptr FakeApi::getFakeHealthResource() { + if (!m_spFakeHealthResource) { + setResource(std::make_shared()); + } + return m_spFakeHealthResource; +} +std::shared_ptr FakeApi::getFakeHttp_signature_testResource() { + if (!m_spFakeHttp_signature_testResource) { + setResource(std::make_shared()); + } + return m_spFakeHttp_signature_testResource; +} +std::shared_ptr FakeApi::getFakeOuterBooleanResource() { + if (!m_spFakeOuterBooleanResource) { + setResource(std::make_shared()); + } + return m_spFakeOuterBooleanResource; +} +std::shared_ptr FakeApi::getFakeOuterCompositeResource() { + if (!m_spFakeOuterCompositeResource) { + setResource(std::make_shared()); + } + return m_spFakeOuterCompositeResource; +} +std::shared_ptr FakeApi::getFakeOuterNumberResource() { + if (!m_spFakeOuterNumberResource) { + setResource(std::make_shared()); + } + return m_spFakeOuterNumberResource; +} +std::shared_ptr FakeApi::getFakeOuterStringResource() { + if (!m_spFakeOuterStringResource) { + setResource(std::make_shared()); + } + return m_spFakeOuterStringResource; +} +std::shared_ptr FakeApi::getFakePropertyEnum_intResource() { + if (!m_spFakePropertyEnum_intResource) { + setResource(std::make_shared()); + } + return m_spFakePropertyEnum_intResource; +} +std::shared_ptr FakeApi::getFakeBody_with_binaryResource() { + if (!m_spFakeBody_with_binaryResource) { + setResource(std::make_shared()); + } + return m_spFakeBody_with_binaryResource; +} +std::shared_ptr FakeApi::getFakeBody_with_file_schemaResource() { + if (!m_spFakeBody_with_file_schemaResource) { + setResource(std::make_shared()); + } + return m_spFakeBody_with_file_schemaResource; +} +std::shared_ptr FakeApi::getFakeBody_with_query_paramsResource() { + if (!m_spFakeBody_with_query_paramsResource) { + setResource(std::make_shared()); + } + return m_spFakeBody_with_query_paramsResource; +} +std::shared_ptr FakeApi::getFakeResource() { + if (!m_spFakeResource) { + setResource(std::make_shared()); + } + return m_spFakeResource; +} +std::shared_ptr FakeApi::getFakeInline_additionalPropertiesResource() { + if (!m_spFakeInline_additionalPropertiesResource) { + setResource(std::make_shared()); + } + return m_spFakeInline_additionalPropertiesResource; +} +std::shared_ptr FakeApi::getFakeJsonFormDataResource() { + if (!m_spFakeJsonFormDataResource) { + setResource(std::make_shared()); + } + return m_spFakeJsonFormDataResource; +} +std::shared_ptr FakeApi::getFakeTest_query_parametersResource() { + if (!m_spFakeTest_query_parametersResource) { + setResource(std::make_shared()); + } + return m_spFakeTest_query_parametersResource; +} +void FakeApi::setResource(std::shared_ptr resource) { + m_spFakeHealthResource = resource; + m_service->publish(m_spFakeHealthResource); +} +void FakeApi::setResource(std::shared_ptr resource) { + m_spFakeHttp_signature_testResource = resource; + m_service->publish(m_spFakeHttp_signature_testResource); +} +void FakeApi::setResource(std::shared_ptr resource) { + m_spFakeOuterBooleanResource = resource; + m_service->publish(m_spFakeOuterBooleanResource); +} +void FakeApi::setResource(std::shared_ptr resource) { + m_spFakeOuterCompositeResource = resource; + m_service->publish(m_spFakeOuterCompositeResource); +} +void FakeApi::setResource(std::shared_ptr resource) { + m_spFakeOuterNumberResource = resource; + m_service->publish(m_spFakeOuterNumberResource); +} +void FakeApi::setResource(std::shared_ptr resource) { + m_spFakeOuterStringResource = resource; + m_service->publish(m_spFakeOuterStringResource); +} +void FakeApi::setResource(std::shared_ptr resource) { + m_spFakePropertyEnum_intResource = resource; + m_service->publish(m_spFakePropertyEnum_intResource); +} +void FakeApi::setResource(std::shared_ptr resource) { + m_spFakeBody_with_binaryResource = resource; + m_service->publish(m_spFakeBody_with_binaryResource); +} +void FakeApi::setResource(std::shared_ptr resource) { + m_spFakeBody_with_file_schemaResource = resource; + m_service->publish(m_spFakeBody_with_file_schemaResource); +} +void FakeApi::setResource(std::shared_ptr resource) { + m_spFakeBody_with_query_paramsResource = resource; + m_service->publish(m_spFakeBody_with_query_paramsResource); +} +void FakeApi::setResource(std::shared_ptr resource) { + m_spFakeResource = resource; + m_service->publish(m_spFakeResource); +} +void FakeApi::setResource(std::shared_ptr resource) { + m_spFakeInline_additionalPropertiesResource = resource; + m_service->publish(m_spFakeInline_additionalPropertiesResource); +} +void FakeApi::setResource(std::shared_ptr resource) { + m_spFakeJsonFormDataResource = resource; + m_service->publish(m_spFakeJsonFormDataResource); +} +void FakeApi::setResource(std::shared_ptr resource) { + m_spFakeTest_query_parametersResource = resource; + m_service->publish(m_spFakeTest_query_parametersResource); +} +void FakeApi::setFakeApiFakeHealthResource(std::shared_ptr spFakeHealthResource) { + m_spFakeHealthResource = spFakeHealthResource; + m_service->publish(m_spFakeHealthResource); +} +void FakeApi::setFakeApiFakeHttp_signature_testResource(std::shared_ptr spFakeHttp_signature_testResource) { + m_spFakeHttp_signature_testResource = spFakeHttp_signature_testResource; + m_service->publish(m_spFakeHttp_signature_testResource); +} +void FakeApi::setFakeApiFakeOuterBooleanResource(std::shared_ptr spFakeOuterBooleanResource) { + m_spFakeOuterBooleanResource = spFakeOuterBooleanResource; + m_service->publish(m_spFakeOuterBooleanResource); +} +void FakeApi::setFakeApiFakeOuterCompositeResource(std::shared_ptr spFakeOuterCompositeResource) { + m_spFakeOuterCompositeResource = spFakeOuterCompositeResource; + m_service->publish(m_spFakeOuterCompositeResource); +} +void FakeApi::setFakeApiFakeOuterNumberResource(std::shared_ptr spFakeOuterNumberResource) { + m_spFakeOuterNumberResource = spFakeOuterNumberResource; + m_service->publish(m_spFakeOuterNumberResource); +} +void FakeApi::setFakeApiFakeOuterStringResource(std::shared_ptr spFakeOuterStringResource) { + m_spFakeOuterStringResource = spFakeOuterStringResource; + m_service->publish(m_spFakeOuterStringResource); +} +void FakeApi::setFakeApiFakePropertyEnum_intResource(std::shared_ptr spFakePropertyEnum_intResource) { + m_spFakePropertyEnum_intResource = spFakePropertyEnum_intResource; + m_service->publish(m_spFakePropertyEnum_intResource); +} +void FakeApi::setFakeApiFakeBody_with_binaryResource(std::shared_ptr spFakeBody_with_binaryResource) { + m_spFakeBody_with_binaryResource = spFakeBody_with_binaryResource; + m_service->publish(m_spFakeBody_with_binaryResource); +} +void FakeApi::setFakeApiFakeBody_with_file_schemaResource(std::shared_ptr spFakeBody_with_file_schemaResource) { + m_spFakeBody_with_file_schemaResource = spFakeBody_with_file_schemaResource; + m_service->publish(m_spFakeBody_with_file_schemaResource); +} +void FakeApi::setFakeApiFakeBody_with_query_paramsResource(std::shared_ptr spFakeBody_with_query_paramsResource) { + m_spFakeBody_with_query_paramsResource = spFakeBody_with_query_paramsResource; + m_service->publish(m_spFakeBody_with_query_paramsResource); +} +void FakeApi::setFakeApiFakeResource(std::shared_ptr spFakeResource) { + m_spFakeResource = spFakeResource; + m_service->publish(m_spFakeResource); +} +void FakeApi::setFakeApiFakeInline_additionalPropertiesResource(std::shared_ptr spFakeInline_additionalPropertiesResource) { + m_spFakeInline_additionalPropertiesResource = spFakeInline_additionalPropertiesResource; + m_service->publish(m_spFakeInline_additionalPropertiesResource); +} +void FakeApi::setFakeApiFakeJsonFormDataResource(std::shared_ptr spFakeJsonFormDataResource) { + m_spFakeJsonFormDataResource = spFakeJsonFormDataResource; + m_service->publish(m_spFakeJsonFormDataResource); +} +void FakeApi::setFakeApiFakeTest_query_parametersResource(std::shared_ptr spFakeTest_query_parametersResource) { + m_spFakeTest_query_parametersResource = spFakeTest_query_parametersResource; + m_service->publish(m_spFakeTest_query_parametersResource); +} + + +void FakeApi::publishDefaultResources() { + if (!m_spFakeHealthResource) { + setResource(std::make_shared()); + } + if (!m_spFakeHttp_signature_testResource) { + setResource(std::make_shared()); + } + if (!m_spFakeOuterBooleanResource) { + setResource(std::make_shared()); + } + if (!m_spFakeOuterCompositeResource) { + setResource(std::make_shared()); + } + if (!m_spFakeOuterNumberResource) { + setResource(std::make_shared()); + } + if (!m_spFakeOuterStringResource) { + setResource(std::make_shared()); + } + if (!m_spFakePropertyEnum_intResource) { + setResource(std::make_shared()); + } + if (!m_spFakeBody_with_binaryResource) { + setResource(std::make_shared()); + } + if (!m_spFakeBody_with_file_schemaResource) { + setResource(std::make_shared()); + } + if (!m_spFakeBody_with_query_paramsResource) { + setResource(std::make_shared()); + } + if (!m_spFakeResource) { + setResource(std::make_shared()); + } + if (!m_spFakeInline_additionalPropertiesResource) { + setResource(std::make_shared()); + } + if (!m_spFakeJsonFormDataResource) { + setResource(std::make_shared()); + } + if (!m_spFakeTest_query_parametersResource) { + setResource(std::make_shared()); + } +} + +std::shared_ptr FakeApi::service() { + return m_service; +} + + +} +} +} +} + diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/api/FakeApi.h b/samples/server/petstore/cpp-restbed/generated/3_0/api/FakeApi.h new file mode 100644 index 00000000000..95ab43aa2dd --- /dev/null +++ b/samples/server/petstore/cpp-restbed/generated/3_0/api/FakeApi.h @@ -0,0 +1,1076 @@ +/** + * 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. + */ + +/* + * FakeApi.h + * + * + */ + +#ifndef FakeApi_H_ +#define FakeApi_H_ + + +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include "Client.h" +#include "EnumClass.h" +#include "FileSchemaTestClass.h" +#include "HealthCheckResult.h" +#include "OuterComposite.h" +#include "OuterObjectWithEnumProperty.h" +#include "Pet.h" +#include "User.h" +#include +#include + +namespace org { +namespace openapitools { +namespace server { +namespace api { + +using namespace org::openapitools::server::model; + +/// +/// Exception to flag problems in the handlers +/// +class FakeApiException: public std::exception +{ +public: + FakeApiException(int status_code, std::string what); + + int getStatus() const; + const char* what() const noexcept override; + +private: + int m_status; + std::string m_what; +}; + +namespace FakeApiResources { +/// +/// Health check endpoint +/// +/// +/// +/// +class FakeHealthResource: public restbed::Resource +{ +public: + FakeHealthResource(const std::string& context = "/v2"); + virtual ~FakeHealthResource() = default; + + FakeHealthResource( + const FakeHealthResource& other) = default; // copy constructor + FakeHealthResource(FakeHealthResource&& other) noexcept = default; // move constructor + + FakeHealthResource& operator=(const FakeHealthResource& other) = default; // copy assignment + FakeHealthResource& operator=(FakeHealthResource&& other) noexcept = default; // move assignment + + ///////////////////////////////////////////////////// + // Set these to implement the server functionality // + ///////////////////////////////////////////////////// + std::function( + )> handler_GET_func = + []() -> std::pair + { throw FakeApiException(501, "Not implemented"); }; + + +protected: + ////////////////////////////////////////////////////////// + // As an alternative to setting the `std::function`s // + // override these to implement the server functionality // + ////////////////////////////////////////////////////////// + + virtual std::pair handler_GET( + ); + + +protected: + ////////////////////////////////////// + // Override these for customization // + ////////////////////////////////////// + + virtual std::string extractBodyContent(const std::shared_ptr& session); + virtual std::string extractFormParamsFromBody(const std::string& paramName, const std::string& body); + + virtual std::pair handleFakeApiException(const FakeApiException& e); + virtual std::pair handleStdException(const std::exception& e); + virtual std::pair handleUnspecifiedException(); + + virtual void setResponseHeader(const std::shared_ptr& session, + const std::string& header); + + virtual void returnResponse(const std::shared_ptr& session, + const int status, const std::string& result, std::multimap& contentType); + virtual void defaultSessionClose(const std::shared_ptr& session, + const int status, const std::string& result); + +private: + void handler_GET_internal(const std::shared_ptr session); +}; + +/// +/// test http signature authentication +/// +/// +/// +/// +class FakeHttp_signature_testResource: public restbed::Resource +{ +public: + FakeHttp_signature_testResource(const std::string& context = "/v2"); + virtual ~FakeHttp_signature_testResource() = default; + + FakeHttp_signature_testResource( + const FakeHttp_signature_testResource& other) = default; // copy constructor + FakeHttp_signature_testResource(FakeHttp_signature_testResource&& other) noexcept = default; // move constructor + + FakeHttp_signature_testResource& operator=(const FakeHttp_signature_testResource& other) = default; // copy assignment + FakeHttp_signature_testResource& operator=(FakeHttp_signature_testResource&& other) noexcept = default; // move assignment + + ///////////////////////////////////////////////////// + // Set these to implement the server functionality // + ///////////////////////////////////////////////////// + std::function handler_GET_func = + [](Pet &, std::string &, std::string &) -> int + { throw FakeApiException(501, "Not implemented"); }; + + +protected: + ////////////////////////////////////////////////////////// + // As an alternative to setting the `std::function`s // + // override these to implement the server functionality // + ////////////////////////////////////////////////////////// + + virtual int handler_GET( + Pet & pet, std::string & query1, std::string & header1); + + +protected: + ////////////////////////////////////// + // Override these for customization // + ////////////////////////////////////// + + virtual std::string extractBodyContent(const std::shared_ptr& session); + virtual std::string extractFormParamsFromBody(const std::string& paramName, const std::string& body); + + virtual std::pair handleFakeApiException(const FakeApiException& e); + virtual std::pair handleStdException(const std::exception& e); + virtual std::pair handleUnspecifiedException(); + + virtual void setResponseHeader(const std::shared_ptr& session, + const std::string& header); + + virtual void returnResponse(const std::shared_ptr& session, + const int status, const std::string& result, std::multimap& contentType); + virtual void defaultSessionClose(const std::shared_ptr& session, + const int status, const std::string& result); + +private: + void handler_GET_internal(const std::shared_ptr session); +}; + +/// +/// +/// +/// +/// Test serialization of outer boolean types +/// +class FakeOuterBooleanResource: public restbed::Resource +{ +public: + FakeOuterBooleanResource(const std::string& context = "/v2"); + virtual ~FakeOuterBooleanResource() = default; + + FakeOuterBooleanResource( + const FakeOuterBooleanResource& other) = default; // copy constructor + FakeOuterBooleanResource(FakeOuterBooleanResource&& other) noexcept = default; // move constructor + + FakeOuterBooleanResource& operator=(const FakeOuterBooleanResource& other) = default; // copy assignment + FakeOuterBooleanResource& operator=(FakeOuterBooleanResource&& other) noexcept = default; // move assignment + + ///////////////////////////////////////////////////// + // Set these to implement the server functionality // + ///////////////////////////////////////////////////// + std::function( + bool & body)> handler_POST_func = + [](bool &) -> std::pair + { throw FakeApiException(501, "Not implemented"); }; + + +protected: + ////////////////////////////////////////////////////////// + // As an alternative to setting the `std::function`s // + // override these to implement the server functionality // + ////////////////////////////////////////////////////////// + + virtual std::pair handler_POST( + bool & body); + + +protected: + ////////////////////////////////////// + // Override these for customization // + ////////////////////////////////////// + + virtual std::string extractBodyContent(const std::shared_ptr& session); + virtual std::string extractFormParamsFromBody(const std::string& paramName, const std::string& body); + + virtual std::pair handleFakeApiException(const FakeApiException& e); + virtual std::pair handleStdException(const std::exception& e); + virtual std::pair handleUnspecifiedException(); + + virtual void setResponseHeader(const std::shared_ptr& session, + const std::string& header); + + virtual void returnResponse(const std::shared_ptr& session, + const int status, const std::string& result, std::multimap& contentType); + virtual void defaultSessionClose(const std::shared_ptr& session, + const int status, const std::string& result); + +private: + void handler_POST_internal(const std::shared_ptr session); +}; + +/// +/// +/// +/// +/// Test serialization of object with outer number type +/// +class FakeOuterCompositeResource: public restbed::Resource +{ +public: + FakeOuterCompositeResource(const std::string& context = "/v2"); + virtual ~FakeOuterCompositeResource() = default; + + FakeOuterCompositeResource( + const FakeOuterCompositeResource& other) = default; // copy constructor + FakeOuterCompositeResource(FakeOuterCompositeResource&& other) noexcept = default; // move constructor + + FakeOuterCompositeResource& operator=(const FakeOuterCompositeResource& other) = default; // copy assignment + FakeOuterCompositeResource& operator=(FakeOuterCompositeResource&& other) noexcept = default; // move assignment + + ///////////////////////////////////////////////////// + // Set these to implement the server functionality // + ///////////////////////////////////////////////////// + std::function( + OuterComposite & outerComposite)> handler_POST_func = + [](OuterComposite &) -> std::pair + { throw FakeApiException(501, "Not implemented"); }; + + +protected: + ////////////////////////////////////////////////////////// + // As an alternative to setting the `std::function`s // + // override these to implement the server functionality // + ////////////////////////////////////////////////////////// + + virtual std::pair handler_POST( + OuterComposite & outerComposite); + + +protected: + ////////////////////////////////////// + // Override these for customization // + ////////////////////////////////////// + + virtual std::string extractBodyContent(const std::shared_ptr& session); + virtual std::string extractFormParamsFromBody(const std::string& paramName, const std::string& body); + + virtual std::pair handleFakeApiException(const FakeApiException& e); + virtual std::pair handleStdException(const std::exception& e); + virtual std::pair handleUnspecifiedException(); + + virtual void setResponseHeader(const std::shared_ptr& session, + const std::string& header); + + virtual void returnResponse(const std::shared_ptr& session, + const int status, const std::string& result, std::multimap& contentType); + virtual void defaultSessionClose(const std::shared_ptr& session, + const int status, const std::string& result); + +private: + void handler_POST_internal(const std::shared_ptr session); +}; + +/// +/// +/// +/// +/// Test serialization of outer number types +/// +class FakeOuterNumberResource: public restbed::Resource +{ +public: + FakeOuterNumberResource(const std::string& context = "/v2"); + virtual ~FakeOuterNumberResource() = default; + + FakeOuterNumberResource( + const FakeOuterNumberResource& other) = default; // copy constructor + FakeOuterNumberResource(FakeOuterNumberResource&& other) noexcept = default; // move constructor + + FakeOuterNumberResource& operator=(const FakeOuterNumberResource& other) = default; // copy assignment + FakeOuterNumberResource& operator=(FakeOuterNumberResource&& other) noexcept = default; // move assignment + + ///////////////////////////////////////////////////// + // Set these to implement the server functionality // + ///////////////////////////////////////////////////// + std::function( + double & body)> handler_POST_func = + [](double &) -> std::pair + { throw FakeApiException(501, "Not implemented"); }; + + +protected: + ////////////////////////////////////////////////////////// + // As an alternative to setting the `std::function`s // + // override these to implement the server functionality // + ////////////////////////////////////////////////////////// + + virtual std::pair handler_POST( + double & body); + + +protected: + ////////////////////////////////////// + // Override these for customization // + ////////////////////////////////////// + + virtual std::string extractBodyContent(const std::shared_ptr& session); + virtual std::string extractFormParamsFromBody(const std::string& paramName, const std::string& body); + + virtual std::pair handleFakeApiException(const FakeApiException& e); + virtual std::pair handleStdException(const std::exception& e); + virtual std::pair handleUnspecifiedException(); + + virtual void setResponseHeader(const std::shared_ptr& session, + const std::string& header); + + virtual void returnResponse(const std::shared_ptr& session, + const int status, const std::string& result, std::multimap& contentType); + virtual void defaultSessionClose(const std::shared_ptr& session, + const int status, const std::string& result); + +private: + void handler_POST_internal(const std::shared_ptr session); +}; + +/// +/// +/// +/// +/// Test serialization of outer string types +/// +class FakeOuterStringResource: public restbed::Resource +{ +public: + FakeOuterStringResource(const std::string& context = "/v2"); + virtual ~FakeOuterStringResource() = default; + + FakeOuterStringResource( + const FakeOuterStringResource& other) = default; // copy constructor + FakeOuterStringResource(FakeOuterStringResource&& other) noexcept = default; // move constructor + + FakeOuterStringResource& operator=(const FakeOuterStringResource& other) = default; // copy assignment + FakeOuterStringResource& operator=(FakeOuterStringResource&& other) noexcept = default; // move assignment + + ///////////////////////////////////////////////////// + // Set these to implement the server functionality // + ///////////////////////////////////////////////////// + std::function( + std::string & body)> handler_POST_func = + [](std::string &) -> std::pair + { throw FakeApiException(501, "Not implemented"); }; + + +protected: + ////////////////////////////////////////////////////////// + // As an alternative to setting the `std::function`s // + // override these to implement the server functionality // + ////////////////////////////////////////////////////////// + + virtual std::pair handler_POST( + std::string & body); + + +protected: + ////////////////////////////////////// + // Override these for customization // + ////////////////////////////////////// + + virtual std::string extractBodyContent(const std::shared_ptr& session); + virtual std::string extractFormParamsFromBody(const std::string& paramName, const std::string& body); + + virtual std::pair handleFakeApiException(const FakeApiException& e); + virtual std::pair handleStdException(const std::exception& e); + virtual std::pair handleUnspecifiedException(); + + virtual void setResponseHeader(const std::shared_ptr& session, + const std::string& header); + + virtual void returnResponse(const std::shared_ptr& session, + const int status, const std::string& result, std::multimap& contentType); + virtual void defaultSessionClose(const std::shared_ptr& session, + const int status, const std::string& result); + +private: + void handler_POST_internal(const std::shared_ptr session); +}; + +/// +/// +/// +/// +/// Test serialization of enum (int) properties with examples +/// +class FakePropertyEnum_intResource: public restbed::Resource +{ +public: + FakePropertyEnum_intResource(const std::string& context = "/v2"); + virtual ~FakePropertyEnum_intResource() = default; + + FakePropertyEnum_intResource( + const FakePropertyEnum_intResource& other) = default; // copy constructor + FakePropertyEnum_intResource(FakePropertyEnum_intResource&& other) noexcept = default; // move constructor + + FakePropertyEnum_intResource& operator=(const FakePropertyEnum_intResource& other) = default; // copy assignment + FakePropertyEnum_intResource& operator=(FakePropertyEnum_intResource&& other) noexcept = default; // move assignment + + ///////////////////////////////////////////////////// + // Set these to implement the server functionality // + ///////////////////////////////////////////////////// + std::function( + OuterObjectWithEnumProperty & outerObjectWithEnumProperty)> handler_POST_func = + [](OuterObjectWithEnumProperty &) -> std::pair + { throw FakeApiException(501, "Not implemented"); }; + + +protected: + ////////////////////////////////////////////////////////// + // As an alternative to setting the `std::function`s // + // override these to implement the server functionality // + ////////////////////////////////////////////////////////// + + virtual std::pair handler_POST( + OuterObjectWithEnumProperty & outerObjectWithEnumProperty); + + +protected: + ////////////////////////////////////// + // Override these for customization // + ////////////////////////////////////// + + virtual std::string extractBodyContent(const std::shared_ptr& session); + virtual std::string extractFormParamsFromBody(const std::string& paramName, const std::string& body); + + virtual std::pair handleFakeApiException(const FakeApiException& e); + virtual std::pair handleStdException(const std::exception& e); + virtual std::pair handleUnspecifiedException(); + + virtual void setResponseHeader(const std::shared_ptr& session, + const std::string& header); + + virtual void returnResponse(const std::shared_ptr& session, + const int status, const std::string& result, std::multimap& contentType); + virtual void defaultSessionClose(const std::shared_ptr& session, + const int status, const std::string& result); + +private: + void handler_POST_internal(const std::shared_ptr session); +}; + +/// +/// +/// +/// +/// For this test, the body has to be a binary file. +/// +class FakeBody_with_binaryResource: public restbed::Resource +{ +public: + FakeBody_with_binaryResource(const std::string& context = "/v2"); + virtual ~FakeBody_with_binaryResource() = default; + + FakeBody_with_binaryResource( + const FakeBody_with_binaryResource& other) = default; // copy constructor + FakeBody_with_binaryResource(FakeBody_with_binaryResource&& other) noexcept = default; // move constructor + + FakeBody_with_binaryResource& operator=(const FakeBody_with_binaryResource& other) = default; // copy assignment + FakeBody_with_binaryResource& operator=(FakeBody_with_binaryResource&& other) noexcept = default; // move assignment + + ///////////////////////////////////////////////////// + // Set these to implement the server functionality // + ///////////////////////////////////////////////////// + std::function handler_PUT_func = + [](std::string &) -> int + { throw FakeApiException(501, "Not implemented"); }; + + +protected: + ////////////////////////////////////////////////////////// + // As an alternative to setting the `std::function`s // + // override these to implement the server functionality // + ////////////////////////////////////////////////////////// + + virtual int handler_PUT( + std::string & body); + + +protected: + ////////////////////////////////////// + // Override these for customization // + ////////////////////////////////////// + + virtual std::string extractBodyContent(const std::shared_ptr& session); + virtual std::string extractFormParamsFromBody(const std::string& paramName, const std::string& body); + + virtual std::pair handleFakeApiException(const FakeApiException& e); + virtual std::pair handleStdException(const std::exception& e); + virtual std::pair handleUnspecifiedException(); + + virtual void setResponseHeader(const std::shared_ptr& session, + const std::string& header); + + virtual void returnResponse(const std::shared_ptr& session, + const int status, const std::string& result, std::multimap& contentType); + virtual void defaultSessionClose(const std::shared_ptr& session, + const int status, const std::string& result); + +private: + void handler_PUT_internal(const std::shared_ptr session); +}; + +/// +/// +/// +/// +/// For this test, the body for this request must reference a schema named `File`. +/// +class FakeBody_with_file_schemaResource: public restbed::Resource +{ +public: + FakeBody_with_file_schemaResource(const std::string& context = "/v2"); + virtual ~FakeBody_with_file_schemaResource() = default; + + FakeBody_with_file_schemaResource( + const FakeBody_with_file_schemaResource& other) = default; // copy constructor + FakeBody_with_file_schemaResource(FakeBody_with_file_schemaResource&& other) noexcept = default; // move constructor + + FakeBody_with_file_schemaResource& operator=(const FakeBody_with_file_schemaResource& other) = default; // copy assignment + FakeBody_with_file_schemaResource& operator=(FakeBody_with_file_schemaResource&& other) noexcept = default; // move assignment + + ///////////////////////////////////////////////////// + // Set these to implement the server functionality // + ///////////////////////////////////////////////////// + std::function handler_PUT_func = + [](FileSchemaTestClass &) -> int + { throw FakeApiException(501, "Not implemented"); }; + + +protected: + ////////////////////////////////////////////////////////// + // As an alternative to setting the `std::function`s // + // override these to implement the server functionality // + ////////////////////////////////////////////////////////// + + virtual int handler_PUT( + FileSchemaTestClass & fileSchemaTestClass); + + +protected: + ////////////////////////////////////// + // Override these for customization // + ////////////////////////////////////// + + virtual std::string extractBodyContent(const std::shared_ptr& session); + virtual std::string extractFormParamsFromBody(const std::string& paramName, const std::string& body); + + virtual std::pair handleFakeApiException(const FakeApiException& e); + virtual std::pair handleStdException(const std::exception& e); + virtual std::pair handleUnspecifiedException(); + + virtual void setResponseHeader(const std::shared_ptr& session, + const std::string& header); + + virtual void returnResponse(const std::shared_ptr& session, + const int status, const std::string& result, std::multimap& contentType); + virtual void defaultSessionClose(const std::shared_ptr& session, + const int status, const std::string& result); + +private: + void handler_PUT_internal(const std::shared_ptr session); +}; + +/// +/// +/// +/// +/// +/// +class FakeBody_with_query_paramsResource: public restbed::Resource +{ +public: + FakeBody_with_query_paramsResource(const std::string& context = "/v2"); + virtual ~FakeBody_with_query_paramsResource() = default; + + FakeBody_with_query_paramsResource( + const FakeBody_with_query_paramsResource& other) = default; // copy constructor + FakeBody_with_query_paramsResource(FakeBody_with_query_paramsResource&& other) noexcept = default; // move constructor + + FakeBody_with_query_paramsResource& operator=(const FakeBody_with_query_paramsResource& other) = default; // copy assignment + FakeBody_with_query_paramsResource& operator=(FakeBody_with_query_paramsResource&& other) noexcept = default; // move assignment + + ///////////////////////////////////////////////////// + // Set these to implement the server functionality // + ///////////////////////////////////////////////////// + std::function handler_PUT_func = + [](std::string &, User &) -> int + { throw FakeApiException(501, "Not implemented"); }; + + +protected: + ////////////////////////////////////////////////////////// + // As an alternative to setting the `std::function`s // + // override these to implement the server functionality // + ////////////////////////////////////////////////////////// + + virtual int handler_PUT( + std::string & query, User & user); + + +protected: + ////////////////////////////////////// + // Override these for customization // + ////////////////////////////////////// + + virtual std::string extractBodyContent(const std::shared_ptr& session); + virtual std::string extractFormParamsFromBody(const std::string& paramName, const std::string& body); + + virtual std::pair handleFakeApiException(const FakeApiException& e); + virtual std::pair handleStdException(const std::exception& e); + virtual std::pair handleUnspecifiedException(); + + virtual void setResponseHeader(const std::shared_ptr& session, + const std::string& header); + + virtual void returnResponse(const std::shared_ptr& session, + const int status, const std::string& result, std::multimap& contentType); + virtual void defaultSessionClose(const std::shared_ptr& session, + const int status, const std::string& result); + +private: + void handler_PUT_internal(const std::shared_ptr session); +}; + +/// +/// To test \"client\" model +/// +/// +/// To test \"client\" model +/// +class FakeResource: public restbed::Resource +{ +public: + FakeResource(const std::string& context = "/v2"); + virtual ~FakeResource() = default; + + FakeResource( + const FakeResource& other) = default; // copy constructor + FakeResource(FakeResource&& other) noexcept = default; // move constructor + + FakeResource& operator=(const FakeResource& other) = default; // copy assignment + FakeResource& operator=(FakeResource&& other) noexcept = default; // move assignment + + ///////////////////////////////////////////////////// + // Set these to implement the server functionality // + ///////////////////////////////////////////////////// + std::function( + Client & client)> handler_PATCH_func = + [](Client &) -> std::pair + { throw FakeApiException(501, "Not implemented"); }; + + std::function handler_POST_func = + [](double &, double &, std::string &, std::string &, int32_t &, int32_t &, int64_t &, float &, std::string &, std::string &, std::string &, std::string &, std::string &, std::string &) -> int + { throw FakeApiException(501, "Not implemented"); }; + + std::function & enumHeaderStringArray, std::string & enumHeaderString, std::vector & enumQueryStringArray, std::string & enumQueryString, int32_t & enumQueryInteger, double & enumQueryDouble, std::vector & enumQueryModelArray, std::vector & enumFormStringArray, std::string & enumFormString)> handler_GET_func = + [](std::vector &, std::string &, std::vector &, std::string &, int32_t &, double &, std::vector &, std::vector &, std::string &) -> int + { throw FakeApiException(501, "Not implemented"); }; + + std::function handler_DELETE_func = + [](int32_t &, bool &, int64_t &, int32_t &, bool &, int64_t &) -> int + { throw FakeApiException(501, "Not implemented"); }; + + +protected: + ////////////////////////////////////////////////////////// + // As an alternative to setting the `std::function`s // + // override these to implement the server functionality // + ////////////////////////////////////////////////////////// + + virtual std::pair handler_PATCH( + Client & client); + + virtual int handler_POST( + double & number, double & r_double, std::string & patternWithoutDelimiter, std::string & byte, int32_t & integer, int32_t & int32, int64_t & int64, float & r_float, std::string & string, std::string & binary, std::string & date, std::string & dateTime, std::string & password, std::string & callback); + virtual int handler_GET( + std::vector & enumHeaderStringArray, std::string & enumHeaderString, std::vector & enumQueryStringArray, std::string & enumQueryString, int32_t & enumQueryInteger, double & enumQueryDouble, std::vector & enumQueryModelArray, std::vector & enumFormStringArray, std::string & enumFormString); + virtual int handler_DELETE( + int32_t & requiredStringGroup, bool & requiredBooleanGroup, int64_t & requiredInt64Group, int32_t & stringGroup, bool & booleanGroup, int64_t & int64Group); + +protected: + ////////////////////////////////////// + // Override these for customization // + ////////////////////////////////////// + + virtual std::string extractBodyContent(const std::shared_ptr& session); + virtual std::string extractFormParamsFromBody(const std::string& paramName, const std::string& body); + + virtual std::pair handleFakeApiException(const FakeApiException& e); + virtual std::pair handleStdException(const std::exception& e); + virtual std::pair handleUnspecifiedException(); + + virtual void setResponseHeader(const std::shared_ptr& session, + const std::string& header); + + virtual void returnResponse(const std::shared_ptr& session, + const int status, const std::string& result, std::multimap& contentType); + virtual void defaultSessionClose(const std::shared_ptr& session, + const int status, const std::string& result); + +private: + void handler_PATCH_internal(const std::shared_ptr session); + void handler_POST_internal(const std::shared_ptr session); + void handler_GET_internal(const std::shared_ptr session); + void handler_DELETE_internal(const std::shared_ptr session); +}; + +/// +/// test inline additionalProperties +/// +/// +/// +/// +class FakeInline_additionalPropertiesResource: public restbed::Resource +{ +public: + FakeInline_additionalPropertiesResource(const std::string& context = "/v2"); + virtual ~FakeInline_additionalPropertiesResource() = default; + + FakeInline_additionalPropertiesResource( + const FakeInline_additionalPropertiesResource& other) = default; // copy constructor + FakeInline_additionalPropertiesResource(FakeInline_additionalPropertiesResource&& other) noexcept = default; // move constructor + + FakeInline_additionalPropertiesResource& operator=(const FakeInline_additionalPropertiesResource& other) = default; // copy assignment + FakeInline_additionalPropertiesResource& operator=(FakeInline_additionalPropertiesResource&& other) noexcept = default; // move assignment + + ///////////////////////////////////////////////////// + // Set these to implement the server functionality // + ///////////////////////////////////////////////////// + std::function & requestBody)> handler_POST_func = + [](std::map &) -> int + { throw FakeApiException(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::map & requestBody); + + +protected: + ////////////////////////////////////// + // Override these for customization // + ////////////////////////////////////// + + virtual std::string extractBodyContent(const std::shared_ptr& session); + virtual std::string extractFormParamsFromBody(const std::string& paramName, const std::string& body); + + virtual std::pair handleFakeApiException(const FakeApiException& e); + virtual std::pair handleStdException(const std::exception& e); + virtual std::pair handleUnspecifiedException(); + + virtual void setResponseHeader(const std::shared_ptr& session, + const std::string& header); + + virtual void returnResponse(const std::shared_ptr& session, + const int status, const std::string& result, std::multimap& contentType); + virtual void defaultSessionClose(const std::shared_ptr& session, + const int status, const std::string& result); + +private: + void handler_POST_internal(const std::shared_ptr session); +}; + +/// +/// test json serialization of form data +/// +/// +/// +/// +class FakeJsonFormDataResource: public restbed::Resource +{ +public: + FakeJsonFormDataResource(const std::string& context = "/v2"); + virtual ~FakeJsonFormDataResource() = default; + + FakeJsonFormDataResource( + const FakeJsonFormDataResource& other) = default; // copy constructor + FakeJsonFormDataResource(FakeJsonFormDataResource&& other) noexcept = default; // move constructor + + FakeJsonFormDataResource& operator=(const FakeJsonFormDataResource& other) = default; // copy assignment + FakeJsonFormDataResource& operator=(FakeJsonFormDataResource&& other) noexcept = default; // move assignment + + ///////////////////////////////////////////////////// + // Set these to implement the server functionality // + ///////////////////////////////////////////////////// + std::function handler_GET_func = + [](std::string &, std::string &) -> int + { throw FakeApiException(501, "Not implemented"); }; + + +protected: + ////////////////////////////////////////////////////////// + // As an alternative to setting the `std::function`s // + // override these to implement the server functionality // + ////////////////////////////////////////////////////////// + + virtual int handler_GET( + std::string & param, std::string & param2); + + +protected: + ////////////////////////////////////// + // Override these for customization // + ////////////////////////////////////// + + virtual std::string extractBodyContent(const std::shared_ptr& session); + virtual std::string extractFormParamsFromBody(const std::string& paramName, const std::string& body); + + virtual std::pair handleFakeApiException(const FakeApiException& e); + virtual std::pair handleStdException(const std::exception& e); + virtual std::pair handleUnspecifiedException(); + + virtual void setResponseHeader(const std::shared_ptr& session, + const std::string& header); + + virtual void returnResponse(const std::shared_ptr& session, + const int status, const std::string& result, std::multimap& contentType); + virtual void defaultSessionClose(const std::shared_ptr& session, + const int status, const std::string& result); + +private: + void handler_GET_internal(const std::shared_ptr session); +}; + +/// +/// +/// +/// +/// To test the collection format in query parameters +/// +class FakeTest_query_parametersResource: public restbed::Resource +{ +public: + FakeTest_query_parametersResource(const std::string& context = "/v2"); + virtual ~FakeTest_query_parametersResource() = default; + + FakeTest_query_parametersResource( + const FakeTest_query_parametersResource& other) = default; // copy constructor + FakeTest_query_parametersResource(FakeTest_query_parametersResource&& other) noexcept = default; // move constructor + + FakeTest_query_parametersResource& operator=(const FakeTest_query_parametersResource& other) = default; // copy assignment + FakeTest_query_parametersResource& operator=(FakeTest_query_parametersResource&& other) noexcept = default; // move assignment + + ///////////////////////////////////////////////////// + // Set these to implement the server functionality // + ///////////////////////////////////////////////////// + std::function & pipe, std::vector & ioutil, std::vector & http, std::vector & url, std::vector & context, std::string & allowEmpty, std::map & language)> handler_PUT_func = + [](std::vector &, std::vector &, std::vector &, std::vector &, std::vector &, std::string &, std::map &) -> int + { throw FakeApiException(501, "Not implemented"); }; + + +protected: + ////////////////////////////////////////////////////////// + // As an alternative to setting the `std::function`s // + // override these to implement the server functionality // + ////////////////////////////////////////////////////////// + + virtual int handler_PUT( + std::vector & pipe, std::vector & ioutil, std::vector & http, std::vector & url, std::vector & context, std::string & allowEmpty, std::map & language); + + +protected: + ////////////////////////////////////// + // Override these for customization // + ////////////////////////////////////// + + virtual std::string extractBodyContent(const std::shared_ptr& session); + virtual std::string extractFormParamsFromBody(const std::string& paramName, const std::string& body); + + virtual std::pair handleFakeApiException(const FakeApiException& e); + virtual std::pair handleStdException(const std::exception& e); + virtual std::pair handleUnspecifiedException(); + + virtual void setResponseHeader(const std::shared_ptr& session, + const std::string& header); + + virtual void returnResponse(const std::shared_ptr& session, + const int status, const std::string& result, std::multimap& contentType); + virtual void defaultSessionClose(const std::shared_ptr& session, + const int status, const std::string& result); + +private: + void handler_PUT_internal(const std::shared_ptr session); +}; + +} /* namespace FakeApiResources */ + +using FakeApiFakeHealthResource [[deprecated]] = FakeApiResources::FakeHealthResource; +using FakeApiFakeHttp_signature_testResource [[deprecated]] = FakeApiResources::FakeHttp_signature_testResource; +using FakeApiFakeOuterBooleanResource [[deprecated]] = FakeApiResources::FakeOuterBooleanResource; +using FakeApiFakeOuterCompositeResource [[deprecated]] = FakeApiResources::FakeOuterCompositeResource; +using FakeApiFakeOuterNumberResource [[deprecated]] = FakeApiResources::FakeOuterNumberResource; +using FakeApiFakeOuterStringResource [[deprecated]] = FakeApiResources::FakeOuterStringResource; +using FakeApiFakePropertyEnum_intResource [[deprecated]] = FakeApiResources::FakePropertyEnum_intResource; +using FakeApiFakeBody_with_binaryResource [[deprecated]] = FakeApiResources::FakeBody_with_binaryResource; +using FakeApiFakeBody_with_file_schemaResource [[deprecated]] = FakeApiResources::FakeBody_with_file_schemaResource; +using FakeApiFakeBody_with_query_paramsResource [[deprecated]] = FakeApiResources::FakeBody_with_query_paramsResource; +using FakeApiFakeResource [[deprecated]] = FakeApiResources::FakeResource; +using FakeApiFakeInline_additionalPropertiesResource [[deprecated]] = FakeApiResources::FakeInline_additionalPropertiesResource; +using FakeApiFakeJsonFormDataResource [[deprecated]] = FakeApiResources::FakeJsonFormDataResource; +using FakeApiFakeTest_query_parametersResource [[deprecated]] = FakeApiResources::FakeTest_query_parametersResource; + +// +// The restbed service to actually implement the REST server +// +class FakeApi +{ +public: + explicit FakeApi(std::shared_ptr const& restbedService); + virtual ~FakeApi(); + + std::shared_ptr getFakeHealthResource(); + std::shared_ptr getFakeHttp_signature_testResource(); + std::shared_ptr getFakeOuterBooleanResource(); + std::shared_ptr getFakeOuterCompositeResource(); + std::shared_ptr getFakeOuterNumberResource(); + std::shared_ptr getFakeOuterStringResource(); + std::shared_ptr getFakePropertyEnum_intResource(); + std::shared_ptr getFakeBody_with_binaryResource(); + std::shared_ptr getFakeBody_with_file_schemaResource(); + std::shared_ptr getFakeBody_with_query_paramsResource(); + std::shared_ptr getFakeResource(); + std::shared_ptr getFakeInline_additionalPropertiesResource(); + std::shared_ptr getFakeJsonFormDataResource(); + std::shared_ptr getFakeTest_query_parametersResource(); + + void setResource(std::shared_ptr resource); + void setResource(std::shared_ptr resource); + void setResource(std::shared_ptr resource); + void setResource(std::shared_ptr resource); + void setResource(std::shared_ptr resource); + void setResource(std::shared_ptr resource); + void setResource(std::shared_ptr resource); + void setResource(std::shared_ptr resource); + void setResource(std::shared_ptr resource); + void setResource(std::shared_ptr resource); + void setResource(std::shared_ptr resource); + void setResource(std::shared_ptr resource); + void setResource(std::shared_ptr resource); + void setResource(std::shared_ptr resource); + [[deprecated("use setResource()")]] + virtual void setFakeApiFakeHealthResource(std::shared_ptr spFakeApiFakeHealthResource); + [[deprecated("use setResource()")]] + virtual void setFakeApiFakeHttp_signature_testResource(std::shared_ptr spFakeApiFakeHttp_signature_testResource); + [[deprecated("use setResource()")]] + virtual void setFakeApiFakeOuterBooleanResource(std::shared_ptr spFakeApiFakeOuterBooleanResource); + [[deprecated("use setResource()")]] + virtual void setFakeApiFakeOuterCompositeResource(std::shared_ptr spFakeApiFakeOuterCompositeResource); + [[deprecated("use setResource()")]] + virtual void setFakeApiFakeOuterNumberResource(std::shared_ptr spFakeApiFakeOuterNumberResource); + [[deprecated("use setResource()")]] + virtual void setFakeApiFakeOuterStringResource(std::shared_ptr spFakeApiFakeOuterStringResource); + [[deprecated("use setResource()")]] + virtual void setFakeApiFakePropertyEnum_intResource(std::shared_ptr spFakeApiFakePropertyEnum_intResource); + [[deprecated("use setResource()")]] + virtual void setFakeApiFakeBody_with_binaryResource(std::shared_ptr spFakeApiFakeBody_with_binaryResource); + [[deprecated("use setResource()")]] + virtual void setFakeApiFakeBody_with_file_schemaResource(std::shared_ptr spFakeApiFakeBody_with_file_schemaResource); + [[deprecated("use setResource()")]] + virtual void setFakeApiFakeBody_with_query_paramsResource(std::shared_ptr spFakeApiFakeBody_with_query_paramsResource); + [[deprecated("use setResource()")]] + virtual void setFakeApiFakeResource(std::shared_ptr spFakeApiFakeResource); + [[deprecated("use setResource()")]] + virtual void setFakeApiFakeInline_additionalPropertiesResource(std::shared_ptr spFakeApiFakeInline_additionalPropertiesResource); + [[deprecated("use setResource()")]] + virtual void setFakeApiFakeJsonFormDataResource(std::shared_ptr spFakeApiFakeJsonFormDataResource); + [[deprecated("use setResource()")]] + virtual void setFakeApiFakeTest_query_parametersResource(std::shared_ptr spFakeApiFakeTest_query_parametersResource); + + virtual void publishDefaultResources(); + + virtual std::shared_ptr service(); + +protected: + std::shared_ptr m_spFakeHealthResource; + std::shared_ptr m_spFakeHttp_signature_testResource; + std::shared_ptr m_spFakeOuterBooleanResource; + std::shared_ptr m_spFakeOuterCompositeResource; + std::shared_ptr m_spFakeOuterNumberResource; + std::shared_ptr m_spFakeOuterStringResource; + std::shared_ptr m_spFakePropertyEnum_intResource; + std::shared_ptr m_spFakeBody_with_binaryResource; + std::shared_ptr m_spFakeBody_with_file_schemaResource; + std::shared_ptr m_spFakeBody_with_query_paramsResource; + std::shared_ptr m_spFakeResource; + std::shared_ptr m_spFakeInline_additionalPropertiesResource; + std::shared_ptr m_spFakeJsonFormDataResource; + std::shared_ptr m_spFakeTest_query_parametersResource; + +private: + std::shared_ptr m_service; +}; + + +} +} +} +} + +#endif /* FakeApi_H_ */ + diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/api/FakeClassnameTags123Api.cpp b/samples/server/petstore/cpp-restbed/generated/3_0/api/FakeClassnameTags123Api.cpp new file mode 100644 index 00000000000..a1ca04919b3 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/generated/3_0/api/FakeClassnameTags123Api.cpp @@ -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 +#include +#include +#include +#include +#include +#include +#include +#include + +#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& contentTypes) { + if (contentTypes.size() == 0) { + return "application/json"; + } + + if (contentTypes.size() == 1) { + return contentTypes.at(0); + } + + static const std::array 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 +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 +std::vector 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(); + for (const auto& child: pt) { + arrayRet.emplace_back(MODEL_T(child.second)); + } + return arrayRet; +} + +template +std::string convertMapResponse(const std::map& map) +{ + boost::property_tree::ptree pt; + for(const auto &kv: map) { + pt.push_back(boost::property_tree::ptree::value_type( + boost::lexical_cast(kv.first), + boost::property_tree::ptree( + boost::lexical_cast(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 Fake_classname_testResource::handleFakeClassnameTags123ApiException(const FakeClassnameTags123ApiException& e) +{ + return std::make_pair(e.getStatus(), e.what()); +} + +std::pair Fake_classname_testResource::handleStdException(const std::exception& e) +{ + return std::make_pair(500, e.what()); +} + +std::pair Fake_classname_testResource::handleUnspecifiedException() +{ + return std::make_pair(500, "Unknown exception occurred"); +} + +void Fake_classname_testResource::setResponseHeader(const std::shared_ptr& session, const std::string& header) +{ + session->set_header(header, ""); +} + +void Fake_classname_testResource::returnResponse(const std::shared_ptr& session, const int status, const std::string& result, std::multimap& responseHeaders) +{ + responseHeaders.insert(std::make_pair("Connection", "close")); + session->close(status, result, responseHeaders); +} + +void Fake_classname_testResource::defaultSessionClose(const std::shared_ptr& 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 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(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 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 Fake_classname_testResource::handler_PATCH( + Client & client) +{ + return handler_PATCH_func(client); +} + + +std::string Fake_classname_testResource::extractBodyContent(const std::shared_ptr& 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 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 const& restbedService) +: m_service(restbedService) +{ +} + +FakeClassnameTags123Api::~FakeClassnameTags123Api() {} + +std::shared_ptr FakeClassnameTags123Api::getFake_classname_testResource() { + if (!m_spFake_classname_testResource) { + setResource(std::make_shared()); + } + return m_spFake_classname_testResource; +} +void FakeClassnameTags123Api::setResource(std::shared_ptr resource) { + m_spFake_classname_testResource = resource; + m_service->publish(m_spFake_classname_testResource); +} +void FakeClassnameTags123Api::setFakeClassnameTags123ApiFake_classname_testResource(std::shared_ptr 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()); + } +} + +std::shared_ptr FakeClassnameTags123Api::service() { + return m_service; +} + + +} +} +} +} + diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/api/FakeClassnameTags123Api.h b/samples/server/petstore/cpp-restbed/generated/3_0/api/FakeClassnameTags123Api.h new file mode 100644 index 00000000000..cc5928f2a26 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/generated/3_0/api/FakeClassnameTags123Api.h @@ -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 +#include +#include +#include + +#include +#include +#include +#include +#include + +#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 { +/// +/// To test class name in snake case +/// +/// +/// To test class name in snake case +/// +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( + Client & client)> handler_PATCH_func = + [](Client &) -> std::pair + { 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 handler_PATCH( + Client & client); + + +protected: + ////////////////////////////////////// + // Override these for customization // + ////////////////////////////////////// + + virtual std::string extractBodyContent(const std::shared_ptr& session); + virtual std::string extractFormParamsFromBody(const std::string& paramName, const std::string& body); + + virtual std::pair handleFakeClassnameTags123ApiException(const FakeClassnameTags123ApiException& e); + virtual std::pair handleStdException(const std::exception& e); + virtual std::pair handleUnspecifiedException(); + + virtual void setResponseHeader(const std::shared_ptr& session, + const std::string& header); + + virtual void returnResponse(const std::shared_ptr& session, + const int status, const std::string& result, std::multimap& contentType); + virtual void defaultSessionClose(const std::shared_ptr& session, + const int status, const std::string& result); + +private: + void handler_PATCH_internal(const std::shared_ptr 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 const& restbedService); + virtual ~FakeClassnameTags123Api(); + + std::shared_ptr getFake_classname_testResource(); + + void setResource(std::shared_ptr resource); + [[deprecated("use setResource()")]] + virtual void setFakeClassnameTags123ApiFake_classname_testResource(std::shared_ptr spFakeClassnameTags123ApiFake_classname_testResource); + + virtual void publishDefaultResources(); + + virtual std::shared_ptr service(); + +protected: + std::shared_ptr m_spFake_classname_testResource; + +private: + std::shared_ptr m_service; +}; + + +} +} +} +} + +#endif /* FakeClassnameTags123Api_H_ */ + diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/api/PetApi.cpp b/samples/server/petstore/cpp-restbed/generated/3_0/api/PetApi.cpp new file mode 100644 index 00000000000..8bc1c5e932a --- /dev/null +++ b/samples/server/petstore/cpp-restbed/generated/3_0/api/PetApi.cpp @@ -0,0 +1,1157 @@ +/** + * 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 +#include +#include +#include +#include +#include +#include +#include +#include + +#include "PetApi.h" + +namespace org { +namespace openapitools { +namespace server { +namespace api { + +using namespace org::openapitools::server::model; + +namespace { +[[maybe_unused]] +std::string selectPreferredContentType(const std::vector& contentTypes) { + if (contentTypes.size() == 0) { + return "application/json"; + } + + if (contentTypes.size() == 1) { + return contentTypes.at(0); + } + + static const std::array 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); +} +} + +PetApiException::PetApiException(int status_code, std::string what) + : m_status(status_code), + m_what(what) +{ + +} +int PetApiException::getStatus() const +{ + return m_status; +} +const char* PetApiException::what() const noexcept +{ + return m_what.c_str(); +} + + +template +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 +std::vector 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(); + for (const auto& child: pt) { + arrayRet.emplace_back(MODEL_T(child.second)); + } + return arrayRet; +} + +template +std::string convertMapResponse(const std::map& map) +{ + boost::property_tree::ptree pt; + for(const auto &kv: map) { + pt.push_back(boost::property_tree::ptree::value_type( + boost::lexical_cast(kv.first), + boost::property_tree::ptree( + boost::lexical_cast(kv.second)))); + } + std::stringstream sstream; + write_json(sstream, pt); + std::string result = sstream.str(); + return result; +} + +namespace PetApiResources { +PetResource::PetResource(const std::string& context /* = "/v2" */) +{ + this->set_path(context + "/pet"); + this->set_method_handler("POST", + std::bind(&PetResource::handler_POST_internal, this, + std::placeholders::_1)); + this->set_method_handler("PUT", + std::bind(&PetResource::handler_PUT_internal, this, + std::placeholders::_1)); +} + +std::pair PetResource::handlePetApiException(const PetApiException& e) +{ + return std::make_pair(e.getStatus(), e.what()); +} + +std::pair PetResource::handleStdException(const std::exception& e) +{ + return std::make_pair(500, e.what()); +} + +std::pair PetResource::handleUnspecifiedException() +{ + return std::make_pair(500, "Unknown exception occurred"); +} + +void PetResource::setResponseHeader(const std::shared_ptr& session, const std::string& header) +{ + session->set_header(header, ""); +} + +void PetResource::returnResponse(const std::shared_ptr& session, const int status, const std::string& result, std::multimap& responseHeaders) +{ + responseHeaders.insert(std::make_pair("Connection", "close")); + session->close(status, result, responseHeaders); +} + +void PetResource::defaultSessionClose(const std::shared_ptr& session, const int status, const std::string& result) +{ + session->close(status, result, { {"Connection", "close"} }); +} + +void PetResource::handler_POST_internal(const std::shared_ptr session) +{ + const auto request = session->get_request(); + // body params or form params here from the body content string + std::string bodyContent = extractBodyContent(session); + auto pet = extractJsonModelBodyParam(bodyContent); + + int status_code = 500; + std::string result = ""; + + try { + status_code = + handler_POST(pet); + } + catch(const PetApiException& e) { + std::tie(status_code, result) = handlePetApiException(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 contentTypes{ + "application/json" + }; + static const std::string acceptTypes{ + "application/json, application/xml, " + }; + + if (status_code == 200) { + responseHeaders.insert(std::make_pair("Content-Type", selectPreferredContentType(contentTypes))); + if (!acceptTypes.empty()) { + responseHeaders.insert(std::make_pair("Accept", acceptTypes)); + } + + returnResponse(session, 200, result.empty() ? "{}" : result, responseHeaders); + return; + } + if (status_code == 405) { + responseHeaders.insert(std::make_pair("Content-Type", "text/plain")); + result = "Invalid input"; + + returnResponse(session, 405, result.empty() ? "{}" : result, responseHeaders); + return; + } + defaultSessionClose(session, status_code, result); +} + +// x-extension +void PetResource::handler_PUT_internal(const std::shared_ptr session) { + const auto request = session->get_request(); + // body params or form params here from the body content string + std::string bodyContent = extractBodyContent(session); + auto pet = extractJsonModelBodyParam(bodyContent); + + int status_code = 500; + std::string result = ""; + + try { + status_code = + handler_PUT(pet); + } + catch(const PetApiException& e) { + std::tie(status_code, result) = handlePetApiException(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 contentTypes{ + "application/json" + }; + static const std::string acceptTypes{ + "application/json, application/xml, " + }; + + if (status_code == 200) { + responseHeaders.insert(std::make_pair("Content-Type", selectPreferredContentType(contentTypes))); + if (!acceptTypes.empty()) { + responseHeaders.insert(std::make_pair("Accept", acceptTypes)); + } + + 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 = "Pet not found"; + + returnResponse(session, 404, result.empty() ? "{}" : result, responseHeaders); + return; + } + if (status_code == 405) { + responseHeaders.insert(std::make_pair("Content-Type", "text/plain")); + result = "Validation exception"; + + returnResponse(session, 405, result.empty() ? "{}" : result, responseHeaders); + return; + } + defaultSessionClose(session, status_code, result); +} + +int PetResource::handler_POST( + Pet & pet) +{ + return handler_POST_func(pet); +} + +int PetResource::handler_PUT( + Pet & pet) +{ + return handler_PUT_func(pet); +} + +std::string PetResource::extractBodyContent(const std::shared_ptr& 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 session, + const restbed::Bytes &body) { + bodyContent = restbed::String::format( + "%.*s\n", (int)body.size(), body.data()); + }); + return bodyContent; +} + +std::string PetResource::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 ""; +} +PetPetIdResource::PetPetIdResource(const std::string& context /* = "/v2" */) +{ + this->set_path(context + "/pet/{petId: .*}"); + this->set_method_handler("DELETE", + std::bind(&PetPetIdResource::handler_DELETE_internal, this, + std::placeholders::_1)); + this->set_method_handler("GET", + std::bind(&PetPetIdResource::handler_GET_internal, this, + std::placeholders::_1)); + this->set_method_handler("POST", + std::bind(&PetPetIdResource::handler_POST_internal, this, + std::placeholders::_1)); +} + +std::pair PetPetIdResource::handlePetApiException(const PetApiException& e) +{ + return std::make_pair(e.getStatus(), e.what()); +} + +std::pair PetPetIdResource::handleStdException(const std::exception& e) +{ + return std::make_pair(500, e.what()); +} + +std::pair PetPetIdResource::handleUnspecifiedException() +{ + return std::make_pair(500, "Unknown exception occurred"); +} + +void PetPetIdResource::setResponseHeader(const std::shared_ptr& session, const std::string& header) +{ + session->set_header(header, ""); +} + +void PetPetIdResource::returnResponse(const std::shared_ptr& session, const int status, const std::string& result, std::multimap& responseHeaders) +{ + responseHeaders.insert(std::make_pair("Connection", "close")); + session->close(status, result, responseHeaders); +} + +void PetPetIdResource::defaultSessionClose(const std::shared_ptr& session, const int status, const std::string& result) +{ + session->close(status, result, { {"Connection", "close"} }); +} + +void PetPetIdResource::handler_DELETE_internal(const std::shared_ptr session) +{ + const auto request = session->get_request(); + // Getting the path params + int64_t petId = request->get_path_parameter("petId", 0L); + // Getting the headers + std::string apiKey = request->get_header("api_key", ""); + + int status_code = 500; + std::string result = ""; + + try { + status_code = + handler_DELETE(petId, apiKey); + } + catch(const PetApiException& e) { + std::tie(status_code, result) = handlePetApiException(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 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)); + } + + returnResponse(session, 200, result.empty() ? "{}" : result, responseHeaders); + return; + } + if (status_code == 400) { + responseHeaders.insert(std::make_pair("Content-Type", "text/plain")); + result = "Invalid pet value"; + + returnResponse(session, 400, result.empty() ? "{}" : result, responseHeaders); + return; + } + defaultSessionClose(session, status_code, result); +} + +// x-extension +void PetPetIdResource::handler_GET_internal(const std::shared_ptr session) { + const auto request = session->get_request(); + // Getting the path params + int64_t petId = request->get_path_parameter("petId", 0L); + + int status_code = 500; + Pet resultObject = Pet{}; + std::string result = ""; + + try { + std::tie(status_code, resultObject) = + handler_GET(petId); + } + catch(const PetApiException& e) { + std::tie(status_code, result) = handlePetApiException(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 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 = "Pet not found"; + + returnResponse(session, 404, result.empty() ? "{}" : result, responseHeaders); + return; + } + defaultSessionClose(session, status_code, result); +} +// x-extension +void PetPetIdResource::handler_POST_internal(const std::shared_ptr session) { + const auto request = session->get_request(); + auto name = boost::lexical_cast(extractFormParamsFromBody("name", extractBodyContent(session))); + auto status = boost::lexical_cast(extractFormParamsFromBody("status", extractBodyContent(session))); + // Getting the path params + int64_t petId = request->get_path_parameter("petId", 0L); + + int status_code = 500; + std::string result = ""; + + try { + status_code = + handler_POST(petId, name, status); + } + catch(const PetApiException& e) { + std::tie(status_code, result) = handlePetApiException(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 contentTypes{ + "application/json" + }; + static const std::string acceptTypes{ + "application/x-www-form-urlencoded, " + }; + + if (status_code == 200) { + responseHeaders.insert(std::make_pair("Content-Type", selectPreferredContentType(contentTypes))); + if (!acceptTypes.empty()) { + responseHeaders.insert(std::make_pair("Accept", acceptTypes)); + } + + returnResponse(session, 200, result.empty() ? "{}" : result, responseHeaders); + return; + } + if (status_code == 405) { + responseHeaders.insert(std::make_pair("Content-Type", "text/plain")); + result = "Invalid input"; + + returnResponse(session, 405, result.empty() ? "{}" : result, responseHeaders); + return; + } + defaultSessionClose(session, status_code, result); +} + +int PetPetIdResource::handler_DELETE( + int64_t & petId, std::string & apiKey) +{ + return handler_DELETE_func(petId, apiKey); +} + +std::pair PetPetIdResource::handler_GET( + int64_t & petId) +{ + return handler_GET_func(petId); +} +int PetPetIdResource::handler_POST( + int64_t & petId, std::string & name, std::string & status) +{ + return handler_POST_func(petId, name, status); +} + +std::string PetPetIdResource::extractBodyContent(const std::shared_ptr& 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 session, + const restbed::Bytes &body) { + bodyContent = restbed::String::format( + "%.*s\n", (int)body.size(), body.data()); + }); + return bodyContent; +} + +std::string PetPetIdResource::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 ""; +} +PetFindByStatusResource::PetFindByStatusResource(const std::string& context /* = "/v2" */) +{ + this->set_path(context + "/pet/findByStatus"); + this->set_method_handler("GET", + std::bind(&PetFindByStatusResource::handler_GET_internal, this, + std::placeholders::_1)); +} + +std::pair PetFindByStatusResource::handlePetApiException(const PetApiException& e) +{ + return std::make_pair(e.getStatus(), e.what()); +} + +std::pair PetFindByStatusResource::handleStdException(const std::exception& e) +{ + return std::make_pair(500, e.what()); +} + +std::pair PetFindByStatusResource::handleUnspecifiedException() +{ + return std::make_pair(500, "Unknown exception occurred"); +} + +void PetFindByStatusResource::setResponseHeader(const std::shared_ptr& session, const std::string& header) +{ + session->set_header(header, ""); +} + +void PetFindByStatusResource::returnResponse(const std::shared_ptr& session, const int status, const std::string& result, std::multimap& responseHeaders) +{ + responseHeaders.insert(std::make_pair("Connection", "close")); + session->close(status, result, responseHeaders); +} + +void PetFindByStatusResource::defaultSessionClose(const std::shared_ptr& session, const int status, const std::string& result) +{ + session->close(status, result, { {"Connection", "close"} }); +} + +void PetFindByStatusResource::handler_GET_internal(const std::shared_ptr session) +{ + const auto request = session->get_request(); + // Getting the query params + std::string status_raw = request->get_query_parameter("status"); + std::vector status; + std::vector status_temp; + boost::split(status_temp, status_raw, boost::is_any_of(",")); + std::copy(status_temp.begin(), status_temp.end(), std::inserter(status, std::next(status.begin()))); + + int status_code = 500; + std::vector resultObject = std::vector(); + std::string result = ""; + + try { + std::tie(status_code, resultObject) = + handler_GET(status); + } + catch(const PetApiException& e) { + std::tie(status_code, result) = handlePetApiException(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 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)); + } + + returnResponse(session, 200, result.empty() ? "{}" : result, responseHeaders); + return; + } + if (status_code == 400) { + responseHeaders.insert(std::make_pair("Content-Type", "text/plain")); + result = "Invalid status value"; + + returnResponse(session, 400, result.empty() ? "{}" : result, responseHeaders); + return; + } + defaultSessionClose(session, status_code, result); +} + + +std::pair> PetFindByStatusResource::handler_GET( + std::vector & status) +{ + return handler_GET_func(status); +} + + +std::string PetFindByStatusResource::extractBodyContent(const std::shared_ptr& 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 session, + const restbed::Bytes &body) { + bodyContent = restbed::String::format( + "%.*s\n", (int)body.size(), body.data()); + }); + return bodyContent; +} + +std::string PetFindByStatusResource::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 ""; +} +PetFindByTagsResource::PetFindByTagsResource(const std::string& context /* = "/v2" */) +{ + this->set_path(context + "/pet/findByTags"); + this->set_method_handler("GET", + std::bind(&PetFindByTagsResource::handler_GET_internal, this, + std::placeholders::_1)); +} + +std::pair PetFindByTagsResource::handlePetApiException(const PetApiException& e) +{ + return std::make_pair(e.getStatus(), e.what()); +} + +std::pair PetFindByTagsResource::handleStdException(const std::exception& e) +{ + return std::make_pair(500, e.what()); +} + +std::pair PetFindByTagsResource::handleUnspecifiedException() +{ + return std::make_pair(500, "Unknown exception occurred"); +} + +void PetFindByTagsResource::setResponseHeader(const std::shared_ptr& session, const std::string& header) +{ + session->set_header(header, ""); +} + +void PetFindByTagsResource::returnResponse(const std::shared_ptr& session, const int status, const std::string& result, std::multimap& responseHeaders) +{ + responseHeaders.insert(std::make_pair("Connection", "close")); + session->close(status, result, responseHeaders); +} + +void PetFindByTagsResource::defaultSessionClose(const std::shared_ptr& session, const int status, const std::string& result) +{ + session->close(status, result, { {"Connection", "close"} }); +} + +void PetFindByTagsResource::handler_GET_internal(const std::shared_ptr session) +{ + const auto request = session->get_request(); + // Getting the query params + std::string tags_raw = request->get_query_parameter("tags"); + std::set tags; + std::vector tags_temp; + boost::split(tags_temp, tags_raw, boost::is_any_of(",")); + std::copy(tags_temp.begin(), tags_temp.end(), std::inserter(tags, std::next(tags.begin()))); + + int status_code = 500; + std::set resultObject = std::set(); + std::string result = ""; + + try { + std::tie(status_code, resultObject) = + handler_GET(tags); + } + catch(const PetApiException& e) { + std::tie(status_code, result) = handlePetApiException(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 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)); + } + + returnResponse(session, 200, result.empty() ? "{}" : result, responseHeaders); + return; + } + if (status_code == 400) { + responseHeaders.insert(std::make_pair("Content-Type", "text/plain")); + result = "Invalid tag value"; + + returnResponse(session, 400, result.empty() ? "{}" : result, responseHeaders); + return; + } + defaultSessionClose(session, status_code, result); +} + + +std::pair> PetFindByTagsResource::handler_GET( + std::set & tags) +{ + return handler_GET_func(tags); +} + + +std::string PetFindByTagsResource::extractBodyContent(const std::shared_ptr& 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 session, + const restbed::Bytes &body) { + bodyContent = restbed::String::format( + "%.*s\n", (int)body.size(), body.data()); + }); + return bodyContent; +} + +std::string PetFindByTagsResource::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 ""; +} +PetPetIdUploadImageResource::PetPetIdUploadImageResource(const std::string& context /* = "/v2" */) +{ + this->set_path(context + "/pet/{petId: .*}/uploadImage"); + this->set_method_handler("POST", + std::bind(&PetPetIdUploadImageResource::handler_POST_internal, this, + std::placeholders::_1)); +} + +std::pair PetPetIdUploadImageResource::handlePetApiException(const PetApiException& e) +{ + return std::make_pair(e.getStatus(), e.what()); +} + +std::pair PetPetIdUploadImageResource::handleStdException(const std::exception& e) +{ + return std::make_pair(500, e.what()); +} + +std::pair PetPetIdUploadImageResource::handleUnspecifiedException() +{ + return std::make_pair(500, "Unknown exception occurred"); +} + +void PetPetIdUploadImageResource::setResponseHeader(const std::shared_ptr& session, const std::string& header) +{ + session->set_header(header, ""); +} + +void PetPetIdUploadImageResource::returnResponse(const std::shared_ptr& session, const int status, const std::string& result, std::multimap& responseHeaders) +{ + responseHeaders.insert(std::make_pair("Connection", "close")); + session->close(status, result, responseHeaders); +} + +void PetPetIdUploadImageResource::defaultSessionClose(const std::shared_ptr& session, const int status, const std::string& result) +{ + session->close(status, result, { {"Connection", "close"} }); +} + +void PetPetIdUploadImageResource::handler_POST_internal(const std::shared_ptr session) +{ + const auto request = session->get_request(); + auto additionalMetadata = boost::lexical_cast(extractFormParamsFromBody("additionalMetadata", extractBodyContent(session))); + auto file = boost::lexical_cast(extractFormParamsFromBody("file", extractBodyContent(session))); + // Getting the path params + int64_t petId = request->get_path_parameter("petId", 0L); + + int status_code = 500; + ApiResponse resultObject = ApiResponse{}; + std::string result = ""; + + try { + std::tie(status_code, resultObject) = + handler_POST(petId, additionalMetadata, file); + } + catch(const PetApiException& e) { + std::tie(status_code, result) = handlePetApiException(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 contentTypes{ + "application/json", + }; + static const std::string acceptTypes{ + "multipart/form-data, " + }; + + 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 PetPetIdUploadImageResource::handler_POST( + int64_t & petId, std::string & additionalMetadata, std::string & file) +{ + return handler_POST_func(petId, additionalMetadata, file); +} + + +std::string PetPetIdUploadImageResource::extractBodyContent(const std::shared_ptr& 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 session, + const restbed::Bytes &body) { + bodyContent = restbed::String::format( + "%.*s\n", (int)body.size(), body.data()); + }); + return bodyContent; +} + +std::string PetPetIdUploadImageResource::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 ""; +} +FakePetIdUploadImageWithRequiredFileResource::FakePetIdUploadImageWithRequiredFileResource(const std::string& context /* = "/v2" */) +{ + this->set_path(context + "/fake/{petId: .*}/uploadImageWithRequiredFile"); + this->set_method_handler("POST", + std::bind(&FakePetIdUploadImageWithRequiredFileResource::handler_POST_internal, this, + std::placeholders::_1)); +} + +std::pair FakePetIdUploadImageWithRequiredFileResource::handlePetApiException(const PetApiException& e) +{ + return std::make_pair(e.getStatus(), e.what()); +} + +std::pair FakePetIdUploadImageWithRequiredFileResource::handleStdException(const std::exception& e) +{ + return std::make_pair(500, e.what()); +} + +std::pair FakePetIdUploadImageWithRequiredFileResource::handleUnspecifiedException() +{ + return std::make_pair(500, "Unknown exception occurred"); +} + +void FakePetIdUploadImageWithRequiredFileResource::setResponseHeader(const std::shared_ptr& session, const std::string& header) +{ + session->set_header(header, ""); +} + +void FakePetIdUploadImageWithRequiredFileResource::returnResponse(const std::shared_ptr& session, const int status, const std::string& result, std::multimap& responseHeaders) +{ + responseHeaders.insert(std::make_pair("Connection", "close")); + session->close(status, result, responseHeaders); +} + +void FakePetIdUploadImageWithRequiredFileResource::defaultSessionClose(const std::shared_ptr& session, const int status, const std::string& result) +{ + session->close(status, result, { {"Connection", "close"} }); +} + +void FakePetIdUploadImageWithRequiredFileResource::handler_POST_internal(const std::shared_ptr session) +{ + const auto request = session->get_request(); + auto additionalMetadata = boost::lexical_cast(extractFormParamsFromBody("additionalMetadata", extractBodyContent(session))); + auto requiredFile = boost::lexical_cast(extractFormParamsFromBody("requiredFile", extractBodyContent(session))); + // Getting the path params + int64_t petId = request->get_path_parameter("petId", 0L); + + int status_code = 500; + ApiResponse resultObject = ApiResponse{}; + std::string result = ""; + + try { + std::tie(status_code, resultObject) = + handler_POST(petId, requiredFile, additionalMetadata); + } + catch(const PetApiException& e) { + std::tie(status_code, result) = handlePetApiException(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 contentTypes{ + "application/json", + }; + static const std::string acceptTypes{ + "multipart/form-data, " + }; + + 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 FakePetIdUploadImageWithRequiredFileResource::handler_POST( + int64_t & petId, std::string & requiredFile, std::string & additionalMetadata) +{ + return handler_POST_func(petId, requiredFile, additionalMetadata); +} + + +std::string FakePetIdUploadImageWithRequiredFileResource::extractBodyContent(const std::shared_ptr& 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 session, + const restbed::Bytes &body) { + bodyContent = restbed::String::format( + "%.*s\n", (int)body.size(), body.data()); + }); + return bodyContent; +} + +std::string FakePetIdUploadImageWithRequiredFileResource::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 PetApiResources */ + +PetApi::PetApi(std::shared_ptr const& restbedService) +: m_service(restbedService) +{ +} + +PetApi::~PetApi() {} + +std::shared_ptr PetApi::getPetResource() { + if (!m_spPetResource) { + setResource(std::make_shared()); + } + return m_spPetResource; +} +std::shared_ptr PetApi::getPetPetIdResource() { + if (!m_spPetPetIdResource) { + setResource(std::make_shared()); + } + return m_spPetPetIdResource; +} +std::shared_ptr PetApi::getPetFindByStatusResource() { + if (!m_spPetFindByStatusResource) { + setResource(std::make_shared()); + } + return m_spPetFindByStatusResource; +} +std::shared_ptr PetApi::getPetFindByTagsResource() { + if (!m_spPetFindByTagsResource) { + setResource(std::make_shared()); + } + return m_spPetFindByTagsResource; +} +std::shared_ptr PetApi::getPetPetIdUploadImageResource() { + if (!m_spPetPetIdUploadImageResource) { + setResource(std::make_shared()); + } + return m_spPetPetIdUploadImageResource; +} +std::shared_ptr PetApi::getFakePetIdUploadImageWithRequiredFileResource() { + if (!m_spFakePetIdUploadImageWithRequiredFileResource) { + setResource(std::make_shared()); + } + return m_spFakePetIdUploadImageWithRequiredFileResource; +} +void PetApi::setResource(std::shared_ptr resource) { + m_spPetResource = resource; + m_service->publish(m_spPetResource); +} +void PetApi::setResource(std::shared_ptr resource) { + m_spPetPetIdResource = resource; + m_service->publish(m_spPetPetIdResource); +} +void PetApi::setResource(std::shared_ptr resource) { + m_spPetFindByStatusResource = resource; + m_service->publish(m_spPetFindByStatusResource); +} +void PetApi::setResource(std::shared_ptr resource) { + m_spPetFindByTagsResource = resource; + m_service->publish(m_spPetFindByTagsResource); +} +void PetApi::setResource(std::shared_ptr resource) { + m_spPetPetIdUploadImageResource = resource; + m_service->publish(m_spPetPetIdUploadImageResource); +} +void PetApi::setResource(std::shared_ptr resource) { + m_spFakePetIdUploadImageWithRequiredFileResource = resource; + m_service->publish(m_spFakePetIdUploadImageWithRequiredFileResource); +} +void PetApi::setPetApiPetResource(std::shared_ptr spPetResource) { + m_spPetResource = spPetResource; + m_service->publish(m_spPetResource); +} +void PetApi::setPetApiPetPetIdResource(std::shared_ptr spPetPetIdResource) { + m_spPetPetIdResource = spPetPetIdResource; + m_service->publish(m_spPetPetIdResource); +} +void PetApi::setPetApiPetFindByStatusResource(std::shared_ptr spPetFindByStatusResource) { + m_spPetFindByStatusResource = spPetFindByStatusResource; + m_service->publish(m_spPetFindByStatusResource); +} +void PetApi::setPetApiPetFindByTagsResource(std::shared_ptr spPetFindByTagsResource) { + m_spPetFindByTagsResource = spPetFindByTagsResource; + m_service->publish(m_spPetFindByTagsResource); +} +void PetApi::setPetApiPetPetIdUploadImageResource(std::shared_ptr spPetPetIdUploadImageResource) { + m_spPetPetIdUploadImageResource = spPetPetIdUploadImageResource; + m_service->publish(m_spPetPetIdUploadImageResource); +} +void PetApi::setPetApiFakePetIdUploadImageWithRequiredFileResource(std::shared_ptr spFakePetIdUploadImageWithRequiredFileResource) { + m_spFakePetIdUploadImageWithRequiredFileResource = spFakePetIdUploadImageWithRequiredFileResource; + m_service->publish(m_spFakePetIdUploadImageWithRequiredFileResource); +} + + +void PetApi::publishDefaultResources() { + if (!m_spPetResource) { + setResource(std::make_shared()); + } + if (!m_spPetPetIdResource) { + setResource(std::make_shared()); + } + if (!m_spPetFindByStatusResource) { + setResource(std::make_shared()); + } + if (!m_spPetFindByTagsResource) { + setResource(std::make_shared()); + } + if (!m_spPetPetIdUploadImageResource) { + setResource(std::make_shared()); + } + if (!m_spFakePetIdUploadImageWithRequiredFileResource) { + setResource(std::make_shared()); + } +} + +std::shared_ptr PetApi::service() { + return m_service; +} + + +} +} +} +} + diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/api/PetApi.h b/samples/server/petstore/cpp-restbed/generated/3_0/api/PetApi.h new file mode 100644 index 00000000000..992e41c46be --- /dev/null +++ b/samples/server/petstore/cpp-restbed/generated/3_0/api/PetApi.h @@ -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 +#include +#include +#include + +#include +#include +#include +#include +#include + +#include "ApiResponse.h" +#include "Pet.h" +#include +#include + +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 { +/// +/// Add a new pet to the store +/// +/// +/// +/// +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 handler_POST_func = + [](Pet &) -> int + { throw PetApiException(501, "Not implemented"); }; + + std::function 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& session); + virtual std::string extractFormParamsFromBody(const std::string& paramName, const std::string& body); + + virtual std::pair handlePetApiException(const PetApiException& e); + virtual std::pair handleStdException(const std::exception& e); + virtual std::pair handleUnspecifiedException(); + + virtual void setResponseHeader(const std::shared_ptr& session, + const std::string& header); + + virtual void returnResponse(const std::shared_ptr& session, + const int status, const std::string& result, std::multimap& contentType); + virtual void defaultSessionClose(const std::shared_ptr& session, + const int status, const std::string& result); + +private: + void handler_POST_internal(const std::shared_ptr session); + void handler_PUT_internal(const std::shared_ptr session); +}; + +/// +/// Deletes a pet +/// +/// +/// +/// +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 handler_DELETE_func = + [](int64_t &, std::string &) -> int + { throw PetApiException(501, "Not implemented"); }; + + std::function( + int64_t & petId)> handler_GET_func = + [](int64_t &) -> std::pair + { throw PetApiException(501, "Not implemented"); }; + + std::function 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 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& session); + virtual std::string extractFormParamsFromBody(const std::string& paramName, const std::string& body); + + virtual std::pair handlePetApiException(const PetApiException& e); + virtual std::pair handleStdException(const std::exception& e); + virtual std::pair handleUnspecifiedException(); + + virtual void setResponseHeader(const std::shared_ptr& session, + const std::string& header); + + virtual void returnResponse(const std::shared_ptr& session, + const int status, const std::string& result, std::multimap& contentType); + virtual void defaultSessionClose(const std::shared_ptr& session, + const int status, const std::string& result); + +private: + void handler_DELETE_internal(const std::shared_ptr session); + void handler_GET_internal(const std::shared_ptr session); + void handler_POST_internal(const std::shared_ptr session); +}; + +/// +/// Finds Pets by status +/// +/// +/// Multiple status values can be provided with comma separated strings +/// +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::vector & status)> handler_GET_func = + [](std::vector &) -> std::pair> + { 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> handler_GET( + std::vector & status); + + +protected: + ////////////////////////////////////// + // Override these for customization // + ////////////////////////////////////// + + virtual std::string extractBodyContent(const std::shared_ptr& session); + virtual std::string extractFormParamsFromBody(const std::string& paramName, const std::string& body); + + virtual std::pair handlePetApiException(const PetApiException& e); + virtual std::pair handleStdException(const std::exception& e); + virtual std::pair handleUnspecifiedException(); + + virtual void setResponseHeader(const std::shared_ptr& session, + const std::string& header); + + virtual void returnResponse(const std::shared_ptr& session, + const int status, const std::string& result, std::multimap& contentType); + virtual void defaultSessionClose(const std::shared_ptr& session, + const int status, const std::string& result); + +private: + void handler_GET_internal(const std::shared_ptr session); +}; + +/// +/// Finds Pets by tags +/// +/// +/// Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. +/// +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::set & tags)> handler_GET_func = + [](std::set &) -> std::pair> + { 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> handler_GET( + std::set & tags); + + +protected: + ////////////////////////////////////// + // Override these for customization // + ////////////////////////////////////// + + virtual std::string extractBodyContent(const std::shared_ptr& session); + virtual std::string extractFormParamsFromBody(const std::string& paramName, const std::string& body); + + virtual std::pair handlePetApiException(const PetApiException& e); + virtual std::pair handleStdException(const std::exception& e); + virtual std::pair handleUnspecifiedException(); + + virtual void setResponseHeader(const std::shared_ptr& session, + const std::string& header); + + virtual void returnResponse(const std::shared_ptr& session, + const int status, const std::string& result, std::multimap& contentType); + virtual void defaultSessionClose(const std::shared_ptr& session, + const int status, const std::string& result); + +private: + void handler_GET_internal(const std::shared_ptr session); +}; + +/// +/// uploads an image +/// +/// +/// +/// +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( + int64_t & petId, std::string & additionalMetadata, std::string & file)> handler_POST_func = + [](int64_t &, std::string &, std::string &) -> std::pair + { 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 handler_POST( + int64_t & petId, std::string & additionalMetadata, std::string & file); + + +protected: + ////////////////////////////////////// + // Override these for customization // + ////////////////////////////////////// + + virtual std::string extractBodyContent(const std::shared_ptr& session); + virtual std::string extractFormParamsFromBody(const std::string& paramName, const std::string& body); + + virtual std::pair handlePetApiException(const PetApiException& e); + virtual std::pair handleStdException(const std::exception& e); + virtual std::pair handleUnspecifiedException(); + + virtual void setResponseHeader(const std::shared_ptr& session, + const std::string& header); + + virtual void returnResponse(const std::shared_ptr& session, + const int status, const std::string& result, std::multimap& contentType); + virtual void defaultSessionClose(const std::shared_ptr& session, + const int status, const std::string& result); + +private: + void handler_POST_internal(const std::shared_ptr session); +}; + +/// +/// uploads an image (required) +/// +/// +/// +/// +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( + int64_t & petId, std::string & requiredFile, std::string & additionalMetadata)> handler_POST_func = + [](int64_t &, std::string &, std::string &) -> std::pair + { 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 handler_POST( + int64_t & petId, std::string & requiredFile, std::string & additionalMetadata); + + +protected: + ////////////////////////////////////// + // Override these for customization // + ////////////////////////////////////// + + virtual std::string extractBodyContent(const std::shared_ptr& session); + virtual std::string extractFormParamsFromBody(const std::string& paramName, const std::string& body); + + virtual std::pair handlePetApiException(const PetApiException& e); + virtual std::pair handleStdException(const std::exception& e); + virtual std::pair handleUnspecifiedException(); + + virtual void setResponseHeader(const std::shared_ptr& session, + const std::string& header); + + virtual void returnResponse(const std::shared_ptr& session, + const int status, const std::string& result, std::multimap& contentType); + virtual void defaultSessionClose(const std::shared_ptr& session, + const int status, const std::string& result); + +private: + void handler_POST_internal(const std::shared_ptr 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 const& restbedService); + virtual ~PetApi(); + + std::shared_ptr getPetResource(); + std::shared_ptr getPetPetIdResource(); + std::shared_ptr getPetFindByStatusResource(); + std::shared_ptr getPetFindByTagsResource(); + std::shared_ptr getPetPetIdUploadImageResource(); + std::shared_ptr getFakePetIdUploadImageWithRequiredFileResource(); + + void setResource(std::shared_ptr resource); + void setResource(std::shared_ptr resource); + void setResource(std::shared_ptr resource); + void setResource(std::shared_ptr resource); + void setResource(std::shared_ptr resource); + void setResource(std::shared_ptr resource); + [[deprecated("use setResource()")]] + virtual void setPetApiPetResource(std::shared_ptr spPetApiPetResource); + [[deprecated("use setResource()")]] + virtual void setPetApiPetPetIdResource(std::shared_ptr spPetApiPetPetIdResource); + [[deprecated("use setResource()")]] + virtual void setPetApiPetFindByStatusResource(std::shared_ptr spPetApiPetFindByStatusResource); + [[deprecated("use setResource()")]] + virtual void setPetApiPetFindByTagsResource(std::shared_ptr spPetApiPetFindByTagsResource); + [[deprecated("use setResource()")]] + virtual void setPetApiPetPetIdUploadImageResource(std::shared_ptr spPetApiPetPetIdUploadImageResource); + [[deprecated("use setResource()")]] + virtual void setPetApiFakePetIdUploadImageWithRequiredFileResource(std::shared_ptr spPetApiFakePetIdUploadImageWithRequiredFileResource); + + virtual void publishDefaultResources(); + + virtual std::shared_ptr service(); + +protected: + std::shared_ptr m_spPetResource; + std::shared_ptr m_spPetPetIdResource; + std::shared_ptr m_spPetFindByStatusResource; + std::shared_ptr m_spPetFindByTagsResource; + std::shared_ptr m_spPetPetIdUploadImageResource; + std::shared_ptr m_spFakePetIdUploadImageWithRequiredFileResource; + +private: + std::shared_ptr m_service; +}; + + +} +} +} +} + +#endif /* PetApi_H_ */ + diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/api/StoreApi.cpp b/samples/server/petstore/cpp-restbed/generated/3_0/api/StoreApi.cpp new file mode 100644 index 00000000000..fe26f20762d --- /dev/null +++ b/samples/server/petstore/cpp-restbed/generated/3_0/api/StoreApi.cpp @@ -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 +#include +#include +#include +#include +#include +#include +#include +#include + +#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& contentTypes) { + if (contentTypes.size() == 0) { + return "application/json"; + } + + if (contentTypes.size() == 1) { + return contentTypes.at(0); + } + + static const std::array 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 +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 +std::vector 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(); + for (const auto& child: pt) { + arrayRet.emplace_back(MODEL_T(child.second)); + } + return arrayRet; +} + +template +std::string convertMapResponse(const std::map& map) +{ + boost::property_tree::ptree pt; + for(const auto &kv: map) { + pt.push_back(boost::property_tree::ptree::value_type( + boost::lexical_cast(kv.first), + boost::property_tree::ptree( + boost::lexical_cast(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 StoreOrderOrder_idResource::handleStoreApiException(const StoreApiException& e) +{ + return std::make_pair(e.getStatus(), e.what()); +} + +std::pair StoreOrderOrder_idResource::handleStdException(const std::exception& e) +{ + return std::make_pair(500, e.what()); +} + +std::pair StoreOrderOrder_idResource::handleUnspecifiedException() +{ + return std::make_pair(500, "Unknown exception occurred"); +} + +void StoreOrderOrder_idResource::setResponseHeader(const std::shared_ptr& session, const std::string& header) +{ + session->set_header(header, ""); +} + +void StoreOrderOrder_idResource::returnResponse(const std::shared_ptr& session, const int status, const std::string& result, std::multimap& responseHeaders) +{ + responseHeaders.insert(std::make_pair("Connection", "close")); + session->close(status, result, responseHeaders); +} + +void StoreOrderOrder_idResource::defaultSessionClose(const std::shared_ptr& session, const int status, const std::string& result) +{ + session->close(status, result, { {"Connection", "close"} }); +} + +void StoreOrderOrder_idResource::handler_DELETE_internal(const std::shared_ptr 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 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 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 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 StoreOrderOrder_idResource::handler_GET( + int64_t & orderId) +{ + return handler_GET_func(orderId); +} + +std::string StoreOrderOrder_idResource::extractBodyContent(const std::shared_ptr& 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 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 StoreInventoryResource::handleStoreApiException(const StoreApiException& e) +{ + return std::make_pair(e.getStatus(), e.what()); +} + +std::pair StoreInventoryResource::handleStdException(const std::exception& e) +{ + return std::make_pair(500, e.what()); +} + +std::pair StoreInventoryResource::handleUnspecifiedException() +{ + return std::make_pair(500, "Unknown exception occurred"); +} + +void StoreInventoryResource::setResponseHeader(const std::shared_ptr& session, const std::string& header) +{ + session->set_header(header, ""); +} + +void StoreInventoryResource::returnResponse(const std::shared_ptr& session, const int status, const std::string& result, std::multimap& responseHeaders) +{ + responseHeaders.insert(std::make_pair("Connection", "close")); + session->close(status, result, responseHeaders); +} + +void StoreInventoryResource::defaultSessionClose(const std::shared_ptr& session, const int status, const std::string& result) +{ + session->close(status, result, { {"Connection", "close"} }); +} + +void StoreInventoryResource::handler_GET_internal(const std::shared_ptr session) +{ + const auto request = session->get_request(); + + int status_code = 500; + std::map resultObject = std::map(); + 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 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> StoreInventoryResource::handler_GET( + ) +{ + return handler_GET_func(); +} + + +std::string StoreInventoryResource::extractBodyContent(const std::shared_ptr& 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 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 StoreOrderResource::handleStoreApiException(const StoreApiException& e) +{ + return std::make_pair(e.getStatus(), e.what()); +} + +std::pair StoreOrderResource::handleStdException(const std::exception& e) +{ + return std::make_pair(500, e.what()); +} + +std::pair StoreOrderResource::handleUnspecifiedException() +{ + return std::make_pair(500, "Unknown exception occurred"); +} + +void StoreOrderResource::setResponseHeader(const std::shared_ptr& session, const std::string& header) +{ + session->set_header(header, ""); +} + +void StoreOrderResource::returnResponse(const std::shared_ptr& session, const int status, const std::string& result, std::multimap& responseHeaders) +{ + responseHeaders.insert(std::make_pair("Connection", "close")); + session->close(status, result, responseHeaders); +} + +void StoreOrderResource::defaultSessionClose(const std::shared_ptr& session, const int status, const std::string& result) +{ + session->close(status, result, { {"Connection", "close"} }); +} + +void StoreOrderResource::handler_POST_internal(const std::shared_ptr 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(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 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 StoreOrderResource::handler_POST( + Order & order) +{ + return handler_POST_func(order); +} + + +std::string StoreOrderResource::extractBodyContent(const std::shared_ptr& 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 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 const& restbedService) +: m_service(restbedService) +{ +} + +StoreApi::~StoreApi() {} + +std::shared_ptr StoreApi::getStoreOrderOrder_idResource() { + if (!m_spStoreOrderOrder_idResource) { + setResource(std::make_shared()); + } + return m_spStoreOrderOrder_idResource; +} +std::shared_ptr StoreApi::getStoreInventoryResource() { + if (!m_spStoreInventoryResource) { + setResource(std::make_shared()); + } + return m_spStoreInventoryResource; +} +std::shared_ptr StoreApi::getStoreOrderResource() { + if (!m_spStoreOrderResource) { + setResource(std::make_shared()); + } + return m_spStoreOrderResource; +} +void StoreApi::setResource(std::shared_ptr resource) { + m_spStoreOrderOrder_idResource = resource; + m_service->publish(m_spStoreOrderOrder_idResource); +} +void StoreApi::setResource(std::shared_ptr resource) { + m_spStoreInventoryResource = resource; + m_service->publish(m_spStoreInventoryResource); +} +void StoreApi::setResource(std::shared_ptr resource) { + m_spStoreOrderResource = resource; + m_service->publish(m_spStoreOrderResource); +} +void StoreApi::setStoreApiStoreOrderOrder_idResource(std::shared_ptr spStoreOrderOrder_idResource) { + m_spStoreOrderOrder_idResource = spStoreOrderOrder_idResource; + m_service->publish(m_spStoreOrderOrder_idResource); +} +void StoreApi::setStoreApiStoreInventoryResource(std::shared_ptr spStoreInventoryResource) { + m_spStoreInventoryResource = spStoreInventoryResource; + m_service->publish(m_spStoreInventoryResource); +} +void StoreApi::setStoreApiStoreOrderResource(std::shared_ptr spStoreOrderResource) { + m_spStoreOrderResource = spStoreOrderResource; + m_service->publish(m_spStoreOrderResource); +} + + +void StoreApi::publishDefaultResources() { + if (!m_spStoreOrderOrder_idResource) { + setResource(std::make_shared()); + } + if (!m_spStoreInventoryResource) { + setResource(std::make_shared()); + } + if (!m_spStoreOrderResource) { + setResource(std::make_shared()); + } +} + +std::shared_ptr StoreApi::service() { + return m_service; +} + + +} +} +} +} + diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/api/StoreApi.h b/samples/server/petstore/cpp-restbed/generated/3_0/api/StoreApi.h new file mode 100644 index 00000000000..ac9bbb6d4d4 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/generated/3_0/api/StoreApi.h @@ -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 +#include +#include +#include + +#include +#include +#include +#include +#include + +#include "Order.h" +#include +#include + +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 { +/// +/// Delete purchase order by ID +/// +/// +/// For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors +/// +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 handler_DELETE_func = + [](std::string &) -> int + { throw StoreApiException(501, "Not implemented"); }; + + std::function( + int64_t & orderId)> handler_GET_func = + [](int64_t &) -> std::pair + { 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 handler_GET( + int64_t & orderId); + +protected: + ////////////////////////////////////// + // Override these for customization // + ////////////////////////////////////// + + virtual std::string extractBodyContent(const std::shared_ptr& session); + virtual std::string extractFormParamsFromBody(const std::string& paramName, const std::string& body); + + virtual std::pair handleStoreApiException(const StoreApiException& e); + virtual std::pair handleStdException(const std::exception& e); + virtual std::pair handleUnspecifiedException(); + + virtual void setResponseHeader(const std::shared_ptr& session, + const std::string& header); + + virtual void returnResponse(const std::shared_ptr& session, + const int status, const std::string& result, std::multimap& contentType); + virtual void defaultSessionClose(const std::shared_ptr& session, + const int status, const std::string& result); + +private: + void handler_DELETE_internal(const std::shared_ptr session); + void handler_GET_internal(const std::shared_ptr session); +}; + +/// +/// Returns pet inventories by status +/// +/// +/// Returns a map of status codes to quantities +/// +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>( + )> handler_GET_func = + []() -> std::pair> + { 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> handler_GET( + ); + + +protected: + ////////////////////////////////////// + // Override these for customization // + ////////////////////////////////////// + + virtual std::string extractBodyContent(const std::shared_ptr& session); + virtual std::string extractFormParamsFromBody(const std::string& paramName, const std::string& body); + + virtual std::pair handleStoreApiException(const StoreApiException& e); + virtual std::pair handleStdException(const std::exception& e); + virtual std::pair handleUnspecifiedException(); + + virtual void setResponseHeader(const std::shared_ptr& session, + const std::string& header); + + virtual void returnResponse(const std::shared_ptr& session, + const int status, const std::string& result, std::multimap& contentType); + virtual void defaultSessionClose(const std::shared_ptr& session, + const int status, const std::string& result); + +private: + void handler_GET_internal(const std::shared_ptr session); +}; + +/// +/// Place an order for a pet +/// +/// +/// +/// +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( + Order & order)> handler_POST_func = + [](Order &) -> std::pair + { 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 handler_POST( + Order & order); + + +protected: + ////////////////////////////////////// + // Override these for customization // + ////////////////////////////////////// + + virtual std::string extractBodyContent(const std::shared_ptr& session); + virtual std::string extractFormParamsFromBody(const std::string& paramName, const std::string& body); + + virtual std::pair handleStoreApiException(const StoreApiException& e); + virtual std::pair handleStdException(const std::exception& e); + virtual std::pair handleUnspecifiedException(); + + virtual void setResponseHeader(const std::shared_ptr& session, + const std::string& header); + + virtual void returnResponse(const std::shared_ptr& session, + const int status, const std::string& result, std::multimap& contentType); + virtual void defaultSessionClose(const std::shared_ptr& session, + const int status, const std::string& result); + +private: + void handler_POST_internal(const std::shared_ptr 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 const& restbedService); + virtual ~StoreApi(); + + std::shared_ptr getStoreOrderOrder_idResource(); + std::shared_ptr getStoreInventoryResource(); + std::shared_ptr getStoreOrderResource(); + + void setResource(std::shared_ptr resource); + void setResource(std::shared_ptr resource); + void setResource(std::shared_ptr resource); + [[deprecated("use setResource()")]] + virtual void setStoreApiStoreOrderOrder_idResource(std::shared_ptr spStoreApiStoreOrderOrder_idResource); + [[deprecated("use setResource()")]] + virtual void setStoreApiStoreInventoryResource(std::shared_ptr spStoreApiStoreInventoryResource); + [[deprecated("use setResource()")]] + virtual void setStoreApiStoreOrderResource(std::shared_ptr spStoreApiStoreOrderResource); + + virtual void publishDefaultResources(); + + virtual std::shared_ptr service(); + +protected: + std::shared_ptr m_spStoreOrderOrder_idResource; + std::shared_ptr m_spStoreInventoryResource; + std::shared_ptr m_spStoreOrderResource; + +private: + std::shared_ptr m_service; +}; + + +} +} +} +} + +#endif /* StoreApi_H_ */ + diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/api/UserApi.cpp b/samples/server/petstore/cpp-restbed/generated/3_0/api/UserApi.cpp new file mode 100644 index 00000000000..4d42febf704 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/generated/3_0/api/UserApi.cpp @@ -0,0 +1,1047 @@ +/** + * 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 +#include +#include +#include +#include +#include +#include +#include +#include + +#include "UserApi.h" + +namespace org { +namespace openapitools { +namespace server { +namespace api { + +using namespace org::openapitools::server::model; + +namespace { +[[maybe_unused]] +std::string selectPreferredContentType(const std::vector& contentTypes) { + if (contentTypes.size() == 0) { + return "application/json"; + } + + if (contentTypes.size() == 1) { + return contentTypes.at(0); + } + + static const std::array 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); +} +} + +UserApiException::UserApiException(int status_code, std::string what) + : m_status(status_code), + m_what(what) +{ + +} +int UserApiException::getStatus() const +{ + return m_status; +} +const char* UserApiException::what() const noexcept +{ + return m_what.c_str(); +} + + +template +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 +std::vector 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(); + for (const auto& child: pt) { + arrayRet.emplace_back(MODEL_T(child.second)); + } + return arrayRet; +} + +template +std::string convertMapResponse(const std::map& map) +{ + boost::property_tree::ptree pt; + for(const auto &kv: map) { + pt.push_back(boost::property_tree::ptree::value_type( + boost::lexical_cast(kv.first), + boost::property_tree::ptree( + boost::lexical_cast(kv.second)))); + } + std::stringstream sstream; + write_json(sstream, pt); + std::string result = sstream.str(); + return result; +} + +namespace UserApiResources { +UserResource::UserResource(const std::string& context /* = "/v2" */) +{ + this->set_path(context + "/user"); + this->set_method_handler("POST", + std::bind(&UserResource::handler_POST_internal, this, + std::placeholders::_1)); +} + +std::pair UserResource::handleUserApiException(const UserApiException& e) +{ + return std::make_pair(e.getStatus(), e.what()); +} + +std::pair UserResource::handleStdException(const std::exception& e) +{ + return std::make_pair(500, e.what()); +} + +std::pair UserResource::handleUnspecifiedException() +{ + return std::make_pair(500, "Unknown exception occurred"); +} + +void UserResource::setResponseHeader(const std::shared_ptr& session, const std::string& header) +{ + session->set_header(header, ""); +} + +void UserResource::returnResponse(const std::shared_ptr& session, const int status, const std::string& result, std::multimap& responseHeaders) +{ + responseHeaders.insert(std::make_pair("Connection", "close")); + session->close(status, result, responseHeaders); +} + +void UserResource::defaultSessionClose(const std::shared_ptr& session, const int status, const std::string& result) +{ + session->close(status, result, { {"Connection", "close"} }); +} + +void UserResource::handler_POST_internal(const std::shared_ptr session) +{ + const auto request = session->get_request(); + // body params or form params here from the body content string + std::string bodyContent = extractBodyContent(session); + auto user = extractJsonModelBodyParam(bodyContent); + + int status_code = 500; + std::string result = ""; + + try { + status_code = + handler_POST(user); + } + catch(const UserApiException& e) { + std::tie(status_code, result) = handleUserApiException(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 contentTypes{ + "application/json" + }; + static const std::string acceptTypes{ + "application/json, " + }; + + if (status_code == 0) { + responseHeaders.insert(std::make_pair("Content-Type", "text/plain")); + result = "successful operation"; + + returnResponse(session, 0, result.empty() ? "{}" : result, responseHeaders); + return; + } + defaultSessionClose(session, status_code, result); +} + + +int UserResource::handler_POST( + User & user) +{ + return handler_POST_func(user); +} + + +std::string UserResource::extractBodyContent(const std::shared_ptr& 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 session, + const restbed::Bytes &body) { + bodyContent = restbed::String::format( + "%.*s\n", (int)body.size(), body.data()); + }); + return bodyContent; +} + +std::string UserResource::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 ""; +} +UserCreateWithArrayResource::UserCreateWithArrayResource(const std::string& context /* = "/v2" */) +{ + this->set_path(context + "/user/createWithArray"); + this->set_method_handler("POST", + std::bind(&UserCreateWithArrayResource::handler_POST_internal, this, + std::placeholders::_1)); +} + +std::pair UserCreateWithArrayResource::handleUserApiException(const UserApiException& e) +{ + return std::make_pair(e.getStatus(), e.what()); +} + +std::pair UserCreateWithArrayResource::handleStdException(const std::exception& e) +{ + return std::make_pair(500, e.what()); +} + +std::pair UserCreateWithArrayResource::handleUnspecifiedException() +{ + return std::make_pair(500, "Unknown exception occurred"); +} + +void UserCreateWithArrayResource::setResponseHeader(const std::shared_ptr& session, const std::string& header) +{ + session->set_header(header, ""); +} + +void UserCreateWithArrayResource::returnResponse(const std::shared_ptr& session, const int status, const std::string& result, std::multimap& responseHeaders) +{ + responseHeaders.insert(std::make_pair("Connection", "close")); + session->close(status, result, responseHeaders); +} + +void UserCreateWithArrayResource::defaultSessionClose(const std::shared_ptr& session, const int status, const std::string& result) +{ + session->close(status, result, { {"Connection", "close"} }); +} + +void UserCreateWithArrayResource::handler_POST_internal(const std::shared_ptr session) +{ + const auto request = session->get_request(); + // body params or form params here from the body content string + std::string bodyContent = extractBodyContent(session); + auto user = extractJsonArrayBodyParam(bodyContent); + + int status_code = 500; + std::string result = ""; + + try { + status_code = + handler_POST(user); + } + catch(const UserApiException& e) { + std::tie(status_code, result) = handleUserApiException(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 contentTypes{ + "application/json" + }; + static const std::string acceptTypes{ + "application/json, " + }; + + if (status_code == 0) { + responseHeaders.insert(std::make_pair("Content-Type", "text/plain")); + result = "successful operation"; + + returnResponse(session, 0, result.empty() ? "{}" : result, responseHeaders); + return; + } + defaultSessionClose(session, status_code, result); +} + + +int UserCreateWithArrayResource::handler_POST( + std::vector & user) +{ + return handler_POST_func(user); +} + + +std::string UserCreateWithArrayResource::extractBodyContent(const std::shared_ptr& 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 session, + const restbed::Bytes &body) { + bodyContent = restbed::String::format( + "%.*s\n", (int)body.size(), body.data()); + }); + return bodyContent; +} + +std::string UserCreateWithArrayResource::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 ""; +} +UserCreateWithListResource::UserCreateWithListResource(const std::string& context /* = "/v2" */) +{ + this->set_path(context + "/user/createWithList"); + this->set_method_handler("POST", + std::bind(&UserCreateWithListResource::handler_POST_internal, this, + std::placeholders::_1)); +} + +std::pair UserCreateWithListResource::handleUserApiException(const UserApiException& e) +{ + return std::make_pair(e.getStatus(), e.what()); +} + +std::pair UserCreateWithListResource::handleStdException(const std::exception& e) +{ + return std::make_pair(500, e.what()); +} + +std::pair UserCreateWithListResource::handleUnspecifiedException() +{ + return std::make_pair(500, "Unknown exception occurred"); +} + +void UserCreateWithListResource::setResponseHeader(const std::shared_ptr& session, const std::string& header) +{ + session->set_header(header, ""); +} + +void UserCreateWithListResource::returnResponse(const std::shared_ptr& session, const int status, const std::string& result, std::multimap& responseHeaders) +{ + responseHeaders.insert(std::make_pair("Connection", "close")); + session->close(status, result, responseHeaders); +} + +void UserCreateWithListResource::defaultSessionClose(const std::shared_ptr& session, const int status, const std::string& result) +{ + session->close(status, result, { {"Connection", "close"} }); +} + +void UserCreateWithListResource::handler_POST_internal(const std::shared_ptr session) +{ + const auto request = session->get_request(); + // body params or form params here from the body content string + std::string bodyContent = extractBodyContent(session); + auto user = extractJsonArrayBodyParam(bodyContent); + + int status_code = 500; + std::string result = ""; + + try { + status_code = + handler_POST(user); + } + catch(const UserApiException& e) { + std::tie(status_code, result) = handleUserApiException(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 contentTypes{ + "application/json" + }; + static const std::string acceptTypes{ + "application/json, " + }; + + if (status_code == 0) { + responseHeaders.insert(std::make_pair("Content-Type", "text/plain")); + result = "successful operation"; + + returnResponse(session, 0, result.empty() ? "{}" : result, responseHeaders); + return; + } + defaultSessionClose(session, status_code, result); +} + + +int UserCreateWithListResource::handler_POST( + std::vector & user) +{ + return handler_POST_func(user); +} + + +std::string UserCreateWithListResource::extractBodyContent(const std::shared_ptr& 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 session, + const restbed::Bytes &body) { + bodyContent = restbed::String::format( + "%.*s\n", (int)body.size(), body.data()); + }); + return bodyContent; +} + +std::string UserCreateWithListResource::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 ""; +} +UserUsernameResource::UserUsernameResource(const std::string& context /* = "/v2" */) +{ + this->set_path(context + "/user/{username: .*}"); + this->set_method_handler("DELETE", + std::bind(&UserUsernameResource::handler_DELETE_internal, this, + std::placeholders::_1)); + this->set_method_handler("GET", + std::bind(&UserUsernameResource::handler_GET_internal, this, + std::placeholders::_1)); + this->set_method_handler("PUT", + std::bind(&UserUsernameResource::handler_PUT_internal, this, + std::placeholders::_1)); +} + +std::pair UserUsernameResource::handleUserApiException(const UserApiException& e) +{ + return std::make_pair(e.getStatus(), e.what()); +} + +std::pair UserUsernameResource::handleStdException(const std::exception& e) +{ + return std::make_pair(500, e.what()); +} + +std::pair UserUsernameResource::handleUnspecifiedException() +{ + return std::make_pair(500, "Unknown exception occurred"); +} + +void UserUsernameResource::setResponseHeader(const std::shared_ptr& session, const std::string& header) +{ + session->set_header(header, ""); +} + +void UserUsernameResource::returnResponse(const std::shared_ptr& session, const int status, const std::string& result, std::multimap& responseHeaders) +{ + responseHeaders.insert(std::make_pair("Connection", "close")); + session->close(status, result, responseHeaders); +} + +void UserUsernameResource::defaultSessionClose(const std::shared_ptr& session, const int status, const std::string& result) +{ + session->close(status, result, { {"Connection", "close"} }); +} + +void UserUsernameResource::handler_DELETE_internal(const std::shared_ptr session) +{ + const auto request = session->get_request(); + // Getting the path params + std::string username = request->get_path_parameter("username", ""); + + int status_code = 500; + std::string result = ""; + + try { + status_code = + handler_DELETE(username); + } + catch(const UserApiException& e) { + std::tie(status_code, result) = handleUserApiException(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 contentTypes{ + "application/json" + }; + static const std::string acceptTypes{ + }; + + if (status_code == 400) { + responseHeaders.insert(std::make_pair("Content-Type", "text/plain")); + result = "Invalid username supplied"; + + returnResponse(session, 400, result.empty() ? "{}" : result, responseHeaders); + return; + } + if (status_code == 404) { + responseHeaders.insert(std::make_pair("Content-Type", "text/plain")); + result = "User not found"; + + returnResponse(session, 404, result.empty() ? "{}" : result, responseHeaders); + return; + } + defaultSessionClose(session, status_code, result); +} + +// x-extension +void UserUsernameResource::handler_GET_internal(const std::shared_ptr session) { + const auto request = session->get_request(); + // Getting the path params + std::string username = request->get_path_parameter("username", ""); + + int status_code = 500; + User resultObject = User{}; + std::string result = ""; + + try { + std::tie(status_code, resultObject) = + handler_GET(username); + } + catch(const UserApiException& e) { + std::tie(status_code, result) = handleUserApiException(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 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 username supplied"; + + returnResponse(session, 400, result.empty() ? "{}" : result, responseHeaders); + return; + } + if (status_code == 404) { + responseHeaders.insert(std::make_pair("Content-Type", "text/plain")); + result = "User not found"; + + returnResponse(session, 404, result.empty() ? "{}" : result, responseHeaders); + return; + } + defaultSessionClose(session, status_code, result); +} +// x-extension +void UserUsernameResource::handler_PUT_internal(const std::shared_ptr session) { + const auto request = session->get_request(); + // body params or form params here from the body content string + std::string bodyContent = extractBodyContent(session); + auto user = extractJsonModelBodyParam(bodyContent); + // Getting the path params + std::string username = request->get_path_parameter("username", ""); + + int status_code = 500; + std::string result = ""; + + try { + status_code = + handler_PUT(username, user); + } + catch(const UserApiException& e) { + std::tie(status_code, result) = handleUserApiException(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 contentTypes{ + "application/json" + }; + static const std::string acceptTypes{ + "application/json, " + }; + + if (status_code == 400) { + responseHeaders.insert(std::make_pair("Content-Type", "text/plain")); + result = "Invalid user supplied"; + + returnResponse(session, 400, result.empty() ? "{}" : result, responseHeaders); + return; + } + if (status_code == 404) { + responseHeaders.insert(std::make_pair("Content-Type", "text/plain")); + result = "User not found"; + + returnResponse(session, 404, result.empty() ? "{}" : result, responseHeaders); + return; + } + defaultSessionClose(session, status_code, result); +} + +int UserUsernameResource::handler_DELETE( + std::string & username) +{ + return handler_DELETE_func(username); +} + +std::pair UserUsernameResource::handler_GET( + std::string & username) +{ + return handler_GET_func(username); +} +int UserUsernameResource::handler_PUT( + std::string & username, User & user) +{ + return handler_PUT_func(username, user); +} + +std::string UserUsernameResource::extractBodyContent(const std::shared_ptr& 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 session, + const restbed::Bytes &body) { + bodyContent = restbed::String::format( + "%.*s\n", (int)body.size(), body.data()); + }); + return bodyContent; +} + +std::string UserUsernameResource::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 ""; +} +UserLoginResource::UserLoginResource(const std::string& context /* = "/v2" */) +{ + this->set_path(context + "/user/login"); + this->set_method_handler("GET", + std::bind(&UserLoginResource::handler_GET_internal, this, + std::placeholders::_1)); +} + +std::pair UserLoginResource::handleUserApiException(const UserApiException& e) +{ + return std::make_pair(e.getStatus(), e.what()); +} + +std::pair UserLoginResource::handleStdException(const std::exception& e) +{ + return std::make_pair(500, e.what()); +} + +std::pair UserLoginResource::handleUnspecifiedException() +{ + return std::make_pair(500, "Unknown exception occurred"); +} + +void UserLoginResource::setResponseHeader(const std::shared_ptr& session, const std::string& header) +{ + session->set_header(header, ""); +} + +void UserLoginResource::returnResponse(const std::shared_ptr& session, const int status, const std::string& result, std::multimap& responseHeaders) +{ + responseHeaders.insert(std::make_pair("Connection", "close")); + session->close(status, result, responseHeaders); +} + +void UserLoginResource::defaultSessionClose(const std::shared_ptr& session, const int status, const std::string& result) +{ + session->close(status, result, { {"Connection", "close"} }); +} + +void UserLoginResource::handler_GET_internal(const std::shared_ptr session) +{ + const auto request = session->get_request(); + // Getting the query params + std::string username = request->get_query_parameter("username", ""); + std::string password = request->get_query_parameter("password", ""); + + int status_code = 500; + std::string resultObject = ""; + std::string result = ""; + + try { + std::tie(status_code, resultObject) = + handler_GET(username, password); + } + catch(const UserApiException& e) { + std::tie(status_code, result) = handleUserApiException(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 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; + // Description: calls per hour allowed by the user + setResponseHeader(session, "X-Rate-Limit"); + // Description: date in UTC when token expires + setResponseHeader(session, "X-Expires-After"); + returnResponse(session, 200, result.empty() ? "{}" : result, responseHeaders); + return; + } + if (status_code == 400) { + responseHeaders.insert(std::make_pair("Content-Type", "text/plain")); + result = "Invalid username/password supplied"; + + returnResponse(session, 400, result.empty() ? "{}" : result, responseHeaders); + return; + } + defaultSessionClose(session, status_code, result); +} + + +std::pair UserLoginResource::handler_GET( + std::string & username, std::string & password) +{ + return handler_GET_func(username, password); +} + + +std::string UserLoginResource::extractBodyContent(const std::shared_ptr& 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 session, + const restbed::Bytes &body) { + bodyContent = restbed::String::format( + "%.*s\n", (int)body.size(), body.data()); + }); + return bodyContent; +} + +std::string UserLoginResource::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 ""; +} +UserLogoutResource::UserLogoutResource(const std::string& context /* = "/v2" */) +{ + this->set_path(context + "/user/logout"); + this->set_method_handler("GET", + std::bind(&UserLogoutResource::handler_GET_internal, this, + std::placeholders::_1)); +} + +std::pair UserLogoutResource::handleUserApiException(const UserApiException& e) +{ + return std::make_pair(e.getStatus(), e.what()); +} + +std::pair UserLogoutResource::handleStdException(const std::exception& e) +{ + return std::make_pair(500, e.what()); +} + +std::pair UserLogoutResource::handleUnspecifiedException() +{ + return std::make_pair(500, "Unknown exception occurred"); +} + +void UserLogoutResource::setResponseHeader(const std::shared_ptr& session, const std::string& header) +{ + session->set_header(header, ""); +} + +void UserLogoutResource::returnResponse(const std::shared_ptr& session, const int status, const std::string& result, std::multimap& responseHeaders) +{ + responseHeaders.insert(std::make_pair("Connection", "close")); + session->close(status, result, responseHeaders); +} + +void UserLogoutResource::defaultSessionClose(const std::shared_ptr& session, const int status, const std::string& result) +{ + session->close(status, result, { {"Connection", "close"} }); +} + +void UserLogoutResource::handler_GET_internal(const std::shared_ptr session) +{ + const auto request = session->get_request(); + + int status_code = 500; + std::string result = ""; + + try { + status_code = + handler_GET(); + } + catch(const UserApiException& e) { + std::tie(status_code, result) = handleUserApiException(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 contentTypes{ + "application/json" + }; + static const std::string acceptTypes{ + }; + + if (status_code == 0) { + responseHeaders.insert(std::make_pair("Content-Type", "text/plain")); + result = "successful operation"; + + returnResponse(session, 0, result.empty() ? "{}" : result, responseHeaders); + return; + } + defaultSessionClose(session, status_code, result); +} + + +int UserLogoutResource::handler_GET( + ) +{ + return handler_GET_func(); +} + + +std::string UserLogoutResource::extractBodyContent(const std::shared_ptr& 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 session, + const restbed::Bytes &body) { + bodyContent = restbed::String::format( + "%.*s\n", (int)body.size(), body.data()); + }); + return bodyContent; +} + +std::string UserLogoutResource::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 UserApiResources */ + +UserApi::UserApi(std::shared_ptr const& restbedService) +: m_service(restbedService) +{ +} + +UserApi::~UserApi() {} + +std::shared_ptr UserApi::getUserResource() { + if (!m_spUserResource) { + setResource(std::make_shared()); + } + return m_spUserResource; +} +std::shared_ptr UserApi::getUserCreateWithArrayResource() { + if (!m_spUserCreateWithArrayResource) { + setResource(std::make_shared()); + } + return m_spUserCreateWithArrayResource; +} +std::shared_ptr UserApi::getUserCreateWithListResource() { + if (!m_spUserCreateWithListResource) { + setResource(std::make_shared()); + } + return m_spUserCreateWithListResource; +} +std::shared_ptr UserApi::getUserUsernameResource() { + if (!m_spUserUsernameResource) { + setResource(std::make_shared()); + } + return m_spUserUsernameResource; +} +std::shared_ptr UserApi::getUserLoginResource() { + if (!m_spUserLoginResource) { + setResource(std::make_shared()); + } + return m_spUserLoginResource; +} +std::shared_ptr UserApi::getUserLogoutResource() { + if (!m_spUserLogoutResource) { + setResource(std::make_shared()); + } + return m_spUserLogoutResource; +} +void UserApi::setResource(std::shared_ptr resource) { + m_spUserResource = resource; + m_service->publish(m_spUserResource); +} +void UserApi::setResource(std::shared_ptr resource) { + m_spUserCreateWithArrayResource = resource; + m_service->publish(m_spUserCreateWithArrayResource); +} +void UserApi::setResource(std::shared_ptr resource) { + m_spUserCreateWithListResource = resource; + m_service->publish(m_spUserCreateWithListResource); +} +void UserApi::setResource(std::shared_ptr resource) { + m_spUserUsernameResource = resource; + m_service->publish(m_spUserUsernameResource); +} +void UserApi::setResource(std::shared_ptr resource) { + m_spUserLoginResource = resource; + m_service->publish(m_spUserLoginResource); +} +void UserApi::setResource(std::shared_ptr resource) { + m_spUserLogoutResource = resource; + m_service->publish(m_spUserLogoutResource); +} +void UserApi::setUserApiUserResource(std::shared_ptr spUserResource) { + m_spUserResource = spUserResource; + m_service->publish(m_spUserResource); +} +void UserApi::setUserApiUserCreateWithArrayResource(std::shared_ptr spUserCreateWithArrayResource) { + m_spUserCreateWithArrayResource = spUserCreateWithArrayResource; + m_service->publish(m_spUserCreateWithArrayResource); +} +void UserApi::setUserApiUserCreateWithListResource(std::shared_ptr spUserCreateWithListResource) { + m_spUserCreateWithListResource = spUserCreateWithListResource; + m_service->publish(m_spUserCreateWithListResource); +} +void UserApi::setUserApiUserUsernameResource(std::shared_ptr spUserUsernameResource) { + m_spUserUsernameResource = spUserUsernameResource; + m_service->publish(m_spUserUsernameResource); +} +void UserApi::setUserApiUserLoginResource(std::shared_ptr spUserLoginResource) { + m_spUserLoginResource = spUserLoginResource; + m_service->publish(m_spUserLoginResource); +} +void UserApi::setUserApiUserLogoutResource(std::shared_ptr spUserLogoutResource) { + m_spUserLogoutResource = spUserLogoutResource; + m_service->publish(m_spUserLogoutResource); +} + + +void UserApi::publishDefaultResources() { + if (!m_spUserResource) { + setResource(std::make_shared()); + } + if (!m_spUserCreateWithArrayResource) { + setResource(std::make_shared()); + } + if (!m_spUserCreateWithListResource) { + setResource(std::make_shared()); + } + if (!m_spUserUsernameResource) { + setResource(std::make_shared()); + } + if (!m_spUserLoginResource) { + setResource(std::make_shared()); + } + if (!m_spUserLogoutResource) { + setResource(std::make_shared()); + } +} + +std::shared_ptr UserApi::service() { + return m_service; +} + + +} +} +} +} + diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/api/UserApi.h b/samples/server/petstore/cpp-restbed/generated/3_0/api/UserApi.h new file mode 100644 index 00000000000..29fcfc78079 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/generated/3_0/api/UserApi.h @@ -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 +#include +#include +#include + +#include +#include +#include +#include +#include + +#include "User.h" +#include +#include + +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 { +/// +/// Create user +/// +/// +/// This can only be done by the logged in user. +/// +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 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& session); + virtual std::string extractFormParamsFromBody(const std::string& paramName, const std::string& body); + + virtual std::pair handleUserApiException(const UserApiException& e); + virtual std::pair handleStdException(const std::exception& e); + virtual std::pair handleUnspecifiedException(); + + virtual void setResponseHeader(const std::shared_ptr& session, + const std::string& header); + + virtual void returnResponse(const std::shared_ptr& session, + const int status, const std::string& result, std::multimap& contentType); + virtual void defaultSessionClose(const std::shared_ptr& session, + const int status, const std::string& result); + +private: + void handler_POST_internal(const std::shared_ptr session); +}; + +/// +/// Creates list of users with given input array +/// +/// +/// +/// +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 & user)> handler_POST_func = + [](std::vector &) -> 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); + + +protected: + ////////////////////////////////////// + // Override these for customization // + ////////////////////////////////////// + + virtual std::string extractBodyContent(const std::shared_ptr& session); + virtual std::string extractFormParamsFromBody(const std::string& paramName, const std::string& body); + + virtual std::pair handleUserApiException(const UserApiException& e); + virtual std::pair handleStdException(const std::exception& e); + virtual std::pair handleUnspecifiedException(); + + virtual void setResponseHeader(const std::shared_ptr& session, + const std::string& header); + + virtual void returnResponse(const std::shared_ptr& session, + const int status, const std::string& result, std::multimap& contentType); + virtual void defaultSessionClose(const std::shared_ptr& session, + const int status, const std::string& result); + +private: + void handler_POST_internal(const std::shared_ptr session); +}; + +/// +/// Creates list of users with given input array +/// +/// +/// +/// +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 & user)> handler_POST_func = + [](std::vector &) -> 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); + + +protected: + ////////////////////////////////////// + // Override these for customization // + ////////////////////////////////////// + + virtual std::string extractBodyContent(const std::shared_ptr& session); + virtual std::string extractFormParamsFromBody(const std::string& paramName, const std::string& body); + + virtual std::pair handleUserApiException(const UserApiException& e); + virtual std::pair handleStdException(const std::exception& e); + virtual std::pair handleUnspecifiedException(); + + virtual void setResponseHeader(const std::shared_ptr& session, + const std::string& header); + + virtual void returnResponse(const std::shared_ptr& session, + const int status, const std::string& result, std::multimap& contentType); + virtual void defaultSessionClose(const std::shared_ptr& session, + const int status, const std::string& result); + +private: + void handler_POST_internal(const std::shared_ptr session); +}; + +/// +/// Delete user +/// +/// +/// This can only be done by the logged in user. +/// +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 handler_DELETE_func = + [](std::string &) -> int + { throw UserApiException(501, "Not implemented"); }; + + std::function( + std::string & username)> handler_GET_func = + [](std::string &) -> std::pair + { throw UserApiException(501, "Not implemented"); }; + + std::function 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 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& session); + virtual std::string extractFormParamsFromBody(const std::string& paramName, const std::string& body); + + virtual std::pair handleUserApiException(const UserApiException& e); + virtual std::pair handleStdException(const std::exception& e); + virtual std::pair handleUnspecifiedException(); + + virtual void setResponseHeader(const std::shared_ptr& session, + const std::string& header); + + virtual void returnResponse(const std::shared_ptr& session, + const int status, const std::string& result, std::multimap& contentType); + virtual void defaultSessionClose(const std::shared_ptr& session, + const int status, const std::string& result); + +private: + void handler_DELETE_internal(const std::shared_ptr session); + void handler_GET_internal(const std::shared_ptr session); + void handler_PUT_internal(const std::shared_ptr session); +}; + +/// +/// Logs user into the system +/// +/// +/// +/// +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::string & username, std::string & password)> handler_GET_func = + [](std::string &, std::string &) -> std::pair + { 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 handler_GET( + std::string & username, std::string & password); + + +protected: + ////////////////////////////////////// + // Override these for customization // + ////////////////////////////////////// + + virtual std::string extractBodyContent(const std::shared_ptr& session); + virtual std::string extractFormParamsFromBody(const std::string& paramName, const std::string& body); + + virtual std::pair handleUserApiException(const UserApiException& e); + virtual std::pair handleStdException(const std::exception& e); + virtual std::pair handleUnspecifiedException(); + + virtual void setResponseHeader(const std::shared_ptr& session, + const std::string& header); + + virtual void returnResponse(const std::shared_ptr& session, + const int status, const std::string& result, std::multimap& contentType); + virtual void defaultSessionClose(const std::shared_ptr& session, + const int status, const std::string& result); + +private: + void handler_GET_internal(const std::shared_ptr session); +}; + +/// +/// Logs out current logged in user session +/// +/// +/// +/// +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 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& session); + virtual std::string extractFormParamsFromBody(const std::string& paramName, const std::string& body); + + virtual std::pair handleUserApiException(const UserApiException& e); + virtual std::pair handleStdException(const std::exception& e); + virtual std::pair handleUnspecifiedException(); + + virtual void setResponseHeader(const std::shared_ptr& session, + const std::string& header); + + virtual void returnResponse(const std::shared_ptr& session, + const int status, const std::string& result, std::multimap& contentType); + virtual void defaultSessionClose(const std::shared_ptr& session, + const int status, const std::string& result); + +private: + void handler_GET_internal(const std::shared_ptr 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 const& restbedService); + virtual ~UserApi(); + + std::shared_ptr getUserResource(); + std::shared_ptr getUserCreateWithArrayResource(); + std::shared_ptr getUserCreateWithListResource(); + std::shared_ptr getUserUsernameResource(); + std::shared_ptr getUserLoginResource(); + std::shared_ptr getUserLogoutResource(); + + void setResource(std::shared_ptr resource); + void setResource(std::shared_ptr resource); + void setResource(std::shared_ptr resource); + void setResource(std::shared_ptr resource); + void setResource(std::shared_ptr resource); + void setResource(std::shared_ptr resource); + [[deprecated("use setResource()")]] + virtual void setUserApiUserResource(std::shared_ptr spUserApiUserResource); + [[deprecated("use setResource()")]] + virtual void setUserApiUserCreateWithArrayResource(std::shared_ptr spUserApiUserCreateWithArrayResource); + [[deprecated("use setResource()")]] + virtual void setUserApiUserCreateWithListResource(std::shared_ptr spUserApiUserCreateWithListResource); + [[deprecated("use setResource()")]] + virtual void setUserApiUserUsernameResource(std::shared_ptr spUserApiUserUsernameResource); + [[deprecated("use setResource()")]] + virtual void setUserApiUserLoginResource(std::shared_ptr spUserApiUserLoginResource); + [[deprecated("use setResource()")]] + virtual void setUserApiUserLogoutResource(std::shared_ptr spUserApiUserLogoutResource); + + virtual void publishDefaultResources(); + + virtual std::shared_ptr service(); + +protected: + std::shared_ptr m_spUserResource; + std::shared_ptr m_spUserCreateWithArrayResource; + std::shared_ptr m_spUserCreateWithListResource; + std::shared_ptr m_spUserUsernameResource; + std::shared_ptr m_spUserLoginResource; + std::shared_ptr m_spUserLogoutResource; + +private: + std::shared_ptr m_service; +}; + + +} +} +} +} + +#endif /* UserApi_H_ */ + diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/git_push.sh b/samples/server/petstore/cpp-restbed/generated/3_0/git_push.sh new file mode 100644 index 00000000000..f53a75d4fab --- /dev/null +++ b/samples/server/petstore/cpp-restbed/generated/3_0/git_push.sh @@ -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' diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/model/AdditionalPropertiesClass.cpp b/samples/server/petstore/cpp-restbed/generated/3_0/model/AdditionalPropertiesClass.cpp new file mode 100644 index 00000000000..7b0add347b0 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/generated/3_0/model/AdditionalPropertiesClass.cpp @@ -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 +#include +#include +#include +#include +#include +#include +#include +#include +#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>(pt.get_child("map_property")); + } + if (pt.get_child_optional("map_of_map_property")) { + m_Map_of_map_property = fromPt>>(pt.get_child("map_of_map_property")); + } +} + +std::map AdditionalPropertiesClass::getMapProperty() const +{ + return m_Map_property; +} + +void AdditionalPropertiesClass::setMapProperty(std::map value) +{ + m_Map_property = value; +} + + +std::map> AdditionalPropertiesClass::getMapOfMapProperty() const +{ + return m_Map_of_map_property; +} + +void AdditionalPropertiesClass::setMapOfMapProperty(std::map> value) +{ + m_Map_of_map_property = value; +} + + + +std::vector 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(); + for (const auto& child: pt) { + vec.emplace_back(AdditionalPropertiesClass(child.second)); + } + + return vec; +} + +} +} +} +} + diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/model/AdditionalPropertiesClass.h b/samples/server/petstore/cpp-restbed/generated/3_0/model/AdditionalPropertiesClass.h new file mode 100644 index 00000000000..b333b9bffdb --- /dev/null +++ b/samples/server/petstore/cpp-restbed/generated/3_0/model/AdditionalPropertiesClass.h @@ -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 +#include +#include +#include +#include +#include "helpers.h" + +namespace org { +namespace openapitools { +namespace server { +namespace model { + +/// +/// +/// +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 + + /// + /// + /// + std::map getMapProperty() const; + void setMapProperty(std::map value); + + /// + /// + /// + std::map> getMapOfMapProperty() const; + void setMapOfMapProperty(std::map> value); + +protected: + std::map m_Map_property; + std::map> m_Map_of_map_property; +}; + +std::vector createAdditionalPropertiesClassVectorFromJsonString(const std::string& json); + +template<> +inline boost::property_tree::ptree toPt(const AdditionalPropertiesClass& val) { + return val.toPropertyTree(); +} + +template<> +inline AdditionalPropertiesClass fromPt(const boost::property_tree::ptree& pt) { + AdditionalPropertiesClass ret; + ret.fromPropertyTree(pt); + return ret; +} + +} +} +} +} + +#endif /* AdditionalPropertiesClass_H_ */ diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/model/AllOfWithSingleRef.cpp b/samples/server/petstore/cpp-restbed/generated/3_0/model/AllOfWithSingleRef.cpp new file mode 100644 index 00000000000..e441165cc2f --- /dev/null +++ b/samples/server/petstore/cpp-restbed/generated/3_0/model/AllOfWithSingleRef.cpp @@ -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 +#include +#include +#include +#include +#include +#include +#include +#include +#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(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 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(); + for (const auto& child: pt) { + vec.emplace_back(AllOfWithSingleRef(child.second)); + } + + return vec; +} + +} +} +} +} + diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/model/AllOfWithSingleRef.h b/samples/server/petstore/cpp-restbed/generated/3_0/model/AllOfWithSingleRef.h new file mode 100644 index 00000000000..55b282160b1 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/generated/3_0/model/AllOfWithSingleRef.h @@ -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 +#include "SingleRefType.h" +#include +#include +#include +#include "helpers.h" + +namespace org { +namespace openapitools { +namespace server { +namespace model { + +/// +/// +/// +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 + + /// + /// + /// + std::string getUsername() const; + void setUsername(std::string value); + + /// + /// + /// + SingleRefType getSingleRefType() const; + void setSingleRefType(SingleRefType value); + +protected: + std::string m_Username = ""; + SingleRefType m_SingleRefType; +}; + +std::vector createAllOfWithSingleRefVectorFromJsonString(const std::string& json); + +template<> +inline boost::property_tree::ptree toPt(const AllOfWithSingleRef& val) { + return val.toPropertyTree(); +} + +template<> +inline AllOfWithSingleRef fromPt(const boost::property_tree::ptree& pt) { + AllOfWithSingleRef ret; + ret.fromPropertyTree(pt); + return ret; +} + +} +} +} +} + +#endif /* AllOfWithSingleRef_H_ */ diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/model/Animal.cpp b/samples/server/petstore/cpp-restbed/generated/3_0/model/Animal.cpp new file mode 100644 index 00000000000..bee00c01fd6 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/generated/3_0/model/Animal.cpp @@ -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 +#include +#include +#include +#include +#include +#include +#include +#include +#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 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(); + for (const auto& child: pt) { + vec.emplace_back(Animal(child.second)); + } + + return vec; +} + +} +} +} +} + diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/model/Animal.h b/samples/server/petstore/cpp-restbed/generated/3_0/model/Animal.h new file mode 100644 index 00000000000..41ebed4c93d --- /dev/null +++ b/samples/server/petstore/cpp-restbed/generated/3_0/model/Animal.h @@ -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 +#include +#include +#include +#include "helpers.h" + +namespace org { +namespace openapitools { +namespace server { +namespace model { + +/// +/// +/// +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 + + /// + /// + /// + std::string getClassName() const; + void setClassName(std::string value); + + /// + /// + /// + std::string getColor() const; + void setColor(std::string value); + +protected: + std::string m_ClassName = ""; + std::string m_Color = "red"; +}; + +std::vector createAnimalVectorFromJsonString(const std::string& json); + +template<> +inline boost::property_tree::ptree toPt(const Animal& val) { + return val.toPropertyTree(); +} + +template<> +inline Animal fromPt(const boost::property_tree::ptree& pt) { + Animal ret; + ret.fromPropertyTree(pt); + return ret; +} + +} +} +} +} + +#endif /* Animal_H_ */ diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/model/ApiResponse.cpp b/samples/server/petstore/cpp-restbed/generated/3_0/model/ApiResponse.cpp new file mode 100644 index 00000000000..7b3645a9bd5 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/generated/3_0/model/ApiResponse.cpp @@ -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 +#include +#include +#include +#include +#include +#include +#include +#include +#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 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(); + for (const auto& child: pt) { + vec.emplace_back(ApiResponse(child.second)); + } + + return vec; +} + +} +} +} +} + diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/model/ApiResponse.h b/samples/server/petstore/cpp-restbed/generated/3_0/model/ApiResponse.h new file mode 100644 index 00000000000..86decc18444 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/generated/3_0/model/ApiResponse.h @@ -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 +#include +#include +#include +#include "helpers.h" + +namespace org { +namespace openapitools { +namespace server { +namespace model { + +/// +/// +/// +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 + + /// + /// + /// + int32_t getCode() const; + void setCode(int32_t value); + + /// + /// + /// + std::string getType() const; + void setType(std::string value); + + /// + /// + /// + 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 createApiResponseVectorFromJsonString(const std::string& json); + +template<> +inline boost::property_tree::ptree toPt(const ApiResponse& val) { + return val.toPropertyTree(); +} + +template<> +inline ApiResponse fromPt(const boost::property_tree::ptree& pt) { + ApiResponse ret; + ret.fromPropertyTree(pt); + return ret; +} + +} +} +} +} + +#endif /* ApiResponse_H_ */ diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/model/ArrayOfArrayOfNumberOnly.cpp b/samples/server/petstore/cpp-restbed/generated/3_0/model/ArrayOfArrayOfNumberOnly.cpp new file mode 100644 index 00000000000..f0c64571fcf --- /dev/null +++ b/samples/server/petstore/cpp-restbed/generated/3_0/model/ArrayOfArrayOfNumberOnly.cpp @@ -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 +#include +#include +#include +#include +#include +#include +#include +#include +#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>>(pt.get_child("ArrayArrayNumber")); + } +} + +std::vector> ArrayOfArrayOfNumberOnly::getArrayArrayNumber() const +{ + return m_ArrayArrayNumber; +} + +void ArrayOfArrayOfNumberOnly::setArrayArrayNumber(std::vector> value) +{ + m_ArrayArrayNumber = value; +} + + + +std::vector 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(); + for (const auto& child: pt) { + vec.emplace_back(ArrayOfArrayOfNumberOnly(child.second)); + } + + return vec; +} + +} +} +} +} + diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/model/ArrayOfArrayOfNumberOnly.h b/samples/server/petstore/cpp-restbed/generated/3_0/model/ArrayOfArrayOfNumberOnly.h new file mode 100644 index 00000000000..b01febcef80 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/generated/3_0/model/ArrayOfArrayOfNumberOnly.h @@ -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 +#include +#include +#include +#include "helpers.h" + +namespace org { +namespace openapitools { +namespace server { +namespace model { + +/// +/// +/// +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 + + /// + /// + /// + std::vector> getArrayArrayNumber() const; + void setArrayArrayNumber(std::vector> value); + +protected: + std::vector> m_ArrayArrayNumber; +}; + +std::vector createArrayOfArrayOfNumberOnlyVectorFromJsonString(const std::string& json); + +template<> +inline boost::property_tree::ptree toPt(const ArrayOfArrayOfNumberOnly& val) { + return val.toPropertyTree(); +} + +template<> +inline ArrayOfArrayOfNumberOnly fromPt(const boost::property_tree::ptree& pt) { + ArrayOfArrayOfNumberOnly ret; + ret.fromPropertyTree(pt); + return ret; +} + +} +} +} +} + +#endif /* ArrayOfArrayOfNumberOnly_H_ */ diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/model/ArrayOfNumberOnly.cpp b/samples/server/petstore/cpp-restbed/generated/3_0/model/ArrayOfNumberOnly.cpp new file mode 100644 index 00000000000..c09ddfaa0d6 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/generated/3_0/model/ArrayOfNumberOnly.cpp @@ -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 +#include +#include +#include +#include +#include +#include +#include +#include +#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>(pt.get_child("ArrayNumber")); + } +} + +std::vector ArrayOfNumberOnly::getArrayNumber() const +{ + return m_ArrayNumber; +} + +void ArrayOfNumberOnly::setArrayNumber(std::vector value) +{ + m_ArrayNumber = value; +} + + + +std::vector 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(); + for (const auto& child: pt) { + vec.emplace_back(ArrayOfNumberOnly(child.second)); + } + + return vec; +} + +} +} +} +} + diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/model/ArrayOfNumberOnly.h b/samples/server/petstore/cpp-restbed/generated/3_0/model/ArrayOfNumberOnly.h new file mode 100644 index 00000000000..289fa184017 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/generated/3_0/model/ArrayOfNumberOnly.h @@ -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 +#include +#include +#include +#include "helpers.h" + +namespace org { +namespace openapitools { +namespace server { +namespace model { + +/// +/// +/// +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 + + /// + /// + /// + std::vector getArrayNumber() const; + void setArrayNumber(std::vector value); + +protected: + std::vector m_ArrayNumber; +}; + +std::vector createArrayOfNumberOnlyVectorFromJsonString(const std::string& json); + +template<> +inline boost::property_tree::ptree toPt(const ArrayOfNumberOnly& val) { + return val.toPropertyTree(); +} + +template<> +inline ArrayOfNumberOnly fromPt(const boost::property_tree::ptree& pt) { + ArrayOfNumberOnly ret; + ret.fromPropertyTree(pt); + return ret; +} + +} +} +} +} + +#endif /* ArrayOfNumberOnly_H_ */ diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/model/ArrayTest.cpp b/samples/server/petstore/cpp-restbed/generated/3_0/model/ArrayTest.cpp new file mode 100644 index 00000000000..0ddab20c4ea --- /dev/null +++ b/samples/server/petstore/cpp-restbed/generated/3_0/model/ArrayTest.cpp @@ -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 +#include +#include +#include +#include +#include +#include +#include +#include +#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>(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>>(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>>(pt.get_child("array_array_of_model")); + } +} + +std::vector ArrayTest::getArrayOfString() const +{ + return m_Array_of_string; +} + +void ArrayTest::setArrayOfString(std::vector value) +{ + m_Array_of_string = value; +} + + +std::vector> ArrayTest::getArrayArrayOfInteger() const +{ + return m_Array_array_of_integer; +} + +void ArrayTest::setArrayArrayOfInteger(std::vector> value) +{ + m_Array_array_of_integer = value; +} + + +std::vector> ArrayTest::getArrayArrayOfModel() const +{ + return m_Array_array_of_model; +} + +void ArrayTest::setArrayArrayOfModel(std::vector> value) +{ + m_Array_array_of_model = value; +} + + + +std::vector 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(); + for (const auto& child: pt) { + vec.emplace_back(ArrayTest(child.second)); + } + + return vec; +} + +} +} +} +} + diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/model/ArrayTest.h b/samples/server/petstore/cpp-restbed/generated/3_0/model/ArrayTest.h new file mode 100644 index 00000000000..60a12616644 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/generated/3_0/model/ArrayTest.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. + */ + +/* + * ArrayTest.h + * + * + */ + +#ifndef ArrayTest_H_ +#define ArrayTest_H_ + + + +#include +#include +#include "ReadOnlyFirst.h" +#include +#include +#include +#include "helpers.h" + +namespace org { +namespace openapitools { +namespace server { +namespace model { + +/// +/// +/// +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 + + /// + /// + /// + std::vector getArrayOfString() const; + void setArrayOfString(std::vector value); + + /// + /// + /// + std::vector> getArrayArrayOfInteger() const; + void setArrayArrayOfInteger(std::vector> value); + + /// + /// + /// + std::vector> getArrayArrayOfModel() const; + void setArrayArrayOfModel(std::vector> value); + +protected: + std::vector m_Array_of_string; + std::vector> m_Array_array_of_integer; + std::vector> m_Array_array_of_model; +}; + +std::vector createArrayTestVectorFromJsonString(const std::string& json); + +template<> +inline boost::property_tree::ptree toPt(const ArrayTest& val) { + return val.toPropertyTree(); +} + +template<> +inline ArrayTest fromPt(const boost::property_tree::ptree& pt) { + ArrayTest ret; + ret.fromPropertyTree(pt); + return ret; +} + +} +} +} +} + +#endif /* ArrayTest_H_ */ diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/model/Capitalization.cpp b/samples/server/petstore/cpp-restbed/generated/3_0/model/Capitalization.cpp new file mode 100644 index 00000000000..585792079d7 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/generated/3_0/model/Capitalization.cpp @@ -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 +#include +#include +#include +#include +#include +#include +#include +#include +#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 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(); + for (const auto& child: pt) { + vec.emplace_back(Capitalization(child.second)); + } + + return vec; +} + +} +} +} +} + diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/model/Capitalization.h b/samples/server/petstore/cpp-restbed/generated/3_0/model/Capitalization.h new file mode 100644 index 00000000000..b0f88a65603 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/generated/3_0/model/Capitalization.h @@ -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 +#include +#include +#include +#include "helpers.h" + +namespace org { +namespace openapitools { +namespace server { +namespace model { + +/// +/// +/// +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 + + /// + /// + /// + std::string getSmallCamel() const; + void setSmallCamel(std::string value); + + /// + /// + /// + std::string getCapitalCamel() const; + void setCapitalCamel(std::string value); + + /// + /// + /// + std::string getSmallSnake() const; + void setSmallSnake(std::string value); + + /// + /// + /// + std::string getCapitalSnake() const; + void setCapitalSnake(std::string value); + + /// + /// + /// + std::string getSCAETHFlowPoints() const; + void setSCAETHFlowPoints(std::string value); + + /// + /// Name of the pet + /// + 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 createCapitalizationVectorFromJsonString(const std::string& json); + +template<> +inline boost::property_tree::ptree toPt(const Capitalization& val) { + return val.toPropertyTree(); +} + +template<> +inline Capitalization fromPt(const boost::property_tree::ptree& pt) { + Capitalization ret; + ret.fromPropertyTree(pt); + return ret; +} + +} +} +} +} + +#endif /* Capitalization_H_ */ diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/model/Cat.cpp b/samples/server/petstore/cpp-restbed/generated/3_0/model/Cat.cpp new file mode 100644 index 00000000000..775e31910c1 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/generated/3_0/model/Cat.cpp @@ -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 +#include +#include +#include +#include +#include +#include +#include +#include +#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 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(); + for (const auto& child: pt) { + vec.emplace_back(Cat(child.second)); + } + + return vec; +} + +} +} +} +} + diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/model/Cat.h b/samples/server/petstore/cpp-restbed/generated/3_0/model/Cat.h new file mode 100644 index 00000000000..67c5dda9136 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/generated/3_0/model/Cat.h @@ -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 +#include "Animal.h" +#include +#include +#include +#include "Animal.h" +#include "Cat_allOf.h" +#include "helpers.h" + +namespace org { +namespace openapitools { +namespace server { +namespace model { + +/// +/// +/// +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 + + /// + /// + /// + std::string getClassName() const; + void setClassName(std::string value); + + /// + /// + /// + std::string getColor() const; + void setColor(std::string value); + + /// + /// + /// + bool isDeclawed() const; + void setDeclawed(bool value); + +protected: + std::string m_ClassName = ""; + std::string m_Color = "red"; + bool m_Declawed = false; +}; + +std::vector createCatVectorFromJsonString(const std::string& json); + +template<> +inline boost::property_tree::ptree toPt(const Cat& val) { + return val.toPropertyTree(); +} + +template<> +inline Cat fromPt(const boost::property_tree::ptree& pt) { + Cat ret; + ret.fromPropertyTree(pt); + return ret; +} + +} +} +} +} + +#endif /* Cat_H_ */ diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/model/Cat_allOf.cpp b/samples/server/petstore/cpp-restbed/generated/3_0/model/Cat_allOf.cpp new file mode 100644 index 00000000000..59fd8eda58c --- /dev/null +++ b/samples/server/petstore/cpp-restbed/generated/3_0/model/Cat_allOf.cpp @@ -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 +#include +#include +#include +#include +#include +#include +#include +#include +#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 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(); + for (const auto& child: pt) { + vec.emplace_back(Cat_allOf(child.second)); + } + + return vec; +} + +} +} +} +} + diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/model/Cat_allOf.h b/samples/server/petstore/cpp-restbed/generated/3_0/model/Cat_allOf.h new file mode 100644 index 00000000000..0a1c8ddebb6 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/generated/3_0/model/Cat_allOf.h @@ -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 +#include +#include +#include "helpers.h" + +namespace org { +namespace openapitools { +namespace server { +namespace model { + +/// +/// +/// +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 + + /// + /// + /// + bool isDeclawed() const; + void setDeclawed(bool value); + +protected: + bool m_Declawed = false; +}; + +std::vector createCat_allOfVectorFromJsonString(const std::string& json); + +template<> +inline boost::property_tree::ptree toPt(const Cat_allOf& val) { + return val.toPropertyTree(); +} + +template<> +inline Cat_allOf fromPt(const boost::property_tree::ptree& pt) { + Cat_allOf ret; + ret.fromPropertyTree(pt); + return ret; +} + +} +} +} +} + +#endif /* Cat_allOf_H_ */ diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/model/Category.cpp b/samples/server/petstore/cpp-restbed/generated/3_0/model/Category.cpp new file mode 100644 index 00000000000..bf2943a92bf --- /dev/null +++ b/samples/server/petstore/cpp-restbed/generated/3_0/model/Category.cpp @@ -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 "Category.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#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 { + +Category::Category(boost::property_tree::ptree const& pt) +{ + fromPropertyTree(pt); +} + + +std::string Category::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 Category::fromJsonString(std::string const& jsonString) +{ + std::stringstream ss(jsonString); + ptree pt; + read_json(ss,pt); + this->fromPropertyTree(pt); +} + +ptree Category::toPropertyTree() const +{ + ptree pt; + ptree tmp_node; + pt.put("id", m_Id); + pt.put("name", m_Name); + return pt; +} + +void Category::fromPropertyTree(ptree const &pt) +{ + ptree tmp_node; + m_Id = pt.get("id", 0L); + m_Name = pt.get("name", "default-name"); +} + +int64_t Category::getId() const +{ + return m_Id; +} + +void Category::setId(int64_t value) +{ + m_Id = value; +} + + +std::string Category::getName() const +{ + return m_Name; +} + +void Category::setName(std::string value) +{ + m_Name = value; +} + + + +std::vector createCategoryVectorFromJsonString(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(); + for (const auto& child: pt) { + vec.emplace_back(Category(child.second)); + } + + return vec; +} + +} +} +} +} + diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/model/Category.h b/samples/server/petstore/cpp-restbed/generated/3_0/model/Category.h new file mode 100644 index 00000000000..bf1ed7f9b0d --- /dev/null +++ b/samples/server/petstore/cpp-restbed/generated/3_0/model/Category.h @@ -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. + */ + +/* + * Category.h + * + * + */ + +#ifndef Category_H_ +#define Category_H_ + + + +#include +#include +#include +#include +#include "helpers.h" + +namespace org { +namespace openapitools { +namespace server { +namespace model { + +/// +/// +/// +class Category +{ +public: + Category() = default; + explicit Category(boost::property_tree::ptree const& pt); + virtual ~Category() = default; + + Category(const Category& other) = default; // copy constructor + Category(Category&& other) noexcept = default; // move constructor + + Category& operator=(const Category& other) = default; // copy assignment + Category& operator=(Category&& 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); + + + ///////////////////////////////////////////// + /// Category members + + /// + /// + /// + int64_t getId() const; + void setId(int64_t value); + + /// + /// + /// + std::string getName() const; + void setName(std::string value); + +protected: + int64_t m_Id = 0L; + std::string m_Name = "default-name"; +}; + +std::vector createCategoryVectorFromJsonString(const std::string& json); + +template<> +inline boost::property_tree::ptree toPt(const Category& val) { + return val.toPropertyTree(); +} + +template<> +inline Category fromPt(const boost::property_tree::ptree& pt) { + Category ret; + ret.fromPropertyTree(pt); + return ret; +} + +} +} +} +} + +#endif /* Category_H_ */ diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/model/ClassModel.cpp b/samples/server/petstore/cpp-restbed/generated/3_0/model/ClassModel.cpp new file mode 100644 index 00000000000..22a4b89b181 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/generated/3_0/model/ClassModel.cpp @@ -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 "ClassModel.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#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 { + +ClassModel::ClassModel(boost::property_tree::ptree const& pt) +{ + fromPropertyTree(pt); +} + + +std::string ClassModel::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 ClassModel::fromJsonString(std::string const& jsonString) +{ + std::stringstream ss(jsonString); + ptree pt; + read_json(ss,pt); + this->fromPropertyTree(pt); +} + +ptree ClassModel::toPropertyTree() const +{ + ptree pt; + ptree tmp_node; + pt.put("_class", m__class); + return pt; +} + +void ClassModel::fromPropertyTree(ptree const &pt) +{ + ptree tmp_node; + m__class = pt.get("_class", ""); +} + +std::string ClassModel::get_Class() const +{ + return m__class; +} + +void ClassModel::set_Class(std::string value) +{ + m__class = value; +} + + + +std::vector createClassModelVectorFromJsonString(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(); + for (const auto& child: pt) { + vec.emplace_back(ClassModel(child.second)); + } + + return vec; +} + +} +} +} +} + diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/model/ClassModel.h b/samples/server/petstore/cpp-restbed/generated/3_0/model/ClassModel.h new file mode 100644 index 00000000000..b93444d2d78 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/generated/3_0/model/ClassModel.h @@ -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. + */ + +/* + * ClassModel.h + * + * Model for testing model with \"_class\" property + */ + +#ifndef ClassModel_H_ +#define ClassModel_H_ + + + +#include +#include +#include +#include +#include "helpers.h" + +namespace org { +namespace openapitools { +namespace server { +namespace model { + +/// +/// Model for testing model with \"_class\" property +/// +class ClassModel +{ +public: + ClassModel() = default; + explicit ClassModel(boost::property_tree::ptree const& pt); + virtual ~ClassModel() = default; + + ClassModel(const ClassModel& other) = default; // copy constructor + ClassModel(ClassModel&& other) noexcept = default; // move constructor + + ClassModel& operator=(const ClassModel& other) = default; // copy assignment + ClassModel& operator=(ClassModel&& 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); + + + ///////////////////////////////////////////// + /// ClassModel members + + /// + /// + /// + std::string get_Class() const; + void set_Class(std::string value); + +protected: + std::string m__class = ""; +}; + +std::vector createClassModelVectorFromJsonString(const std::string& json); + +template<> +inline boost::property_tree::ptree toPt(const ClassModel& val) { + return val.toPropertyTree(); +} + +template<> +inline ClassModel fromPt(const boost::property_tree::ptree& pt) { + ClassModel ret; + ret.fromPropertyTree(pt); + return ret; +} + +} +} +} +} + +#endif /* ClassModel_H_ */ diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/model/Client.cpp b/samples/server/petstore/cpp-restbed/generated/3_0/model/Client.cpp new file mode 100644 index 00000000000..40dd9e4aea2 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/generated/3_0/model/Client.cpp @@ -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 "Client.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#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 { + +Client::Client(boost::property_tree::ptree const& pt) +{ + fromPropertyTree(pt); +} + + +std::string Client::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 Client::fromJsonString(std::string const& jsonString) +{ + std::stringstream ss(jsonString); + ptree pt; + read_json(ss,pt); + this->fromPropertyTree(pt); +} + +ptree Client::toPropertyTree() const +{ + ptree pt; + ptree tmp_node; + pt.put("client", m_Client); + return pt; +} + +void Client::fromPropertyTree(ptree const &pt) +{ + ptree tmp_node; + m_Client = pt.get("client", ""); +} + +std::string Client::getClient() const +{ + return m_Client; +} + +void Client::setClient(std::string value) +{ + m_Client = value; +} + + + +std::vector createClientVectorFromJsonString(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(); + for (const auto& child: pt) { + vec.emplace_back(Client(child.second)); + } + + return vec; +} + +} +} +} +} + diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/model/Client.h b/samples/server/petstore/cpp-restbed/generated/3_0/model/Client.h new file mode 100644 index 00000000000..b4186414c3c --- /dev/null +++ b/samples/server/petstore/cpp-restbed/generated/3_0/model/Client.h @@ -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. + */ + +/* + * Client.h + * + * + */ + +#ifndef Client_H_ +#define Client_H_ + + + +#include +#include +#include +#include +#include "helpers.h" + +namespace org { +namespace openapitools { +namespace server { +namespace model { + +/// +/// +/// +class Client +{ +public: + Client() = default; + explicit Client(boost::property_tree::ptree const& pt); + virtual ~Client() = default; + + Client(const Client& other) = default; // copy constructor + Client(Client&& other) noexcept = default; // move constructor + + Client& operator=(const Client& other) = default; // copy assignment + Client& operator=(Client&& 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); + + + ///////////////////////////////////////////// + /// Client members + + /// + /// + /// + std::string getClient() const; + void setClient(std::string value); + +protected: + std::string m_Client = ""; +}; + +std::vector createClientVectorFromJsonString(const std::string& json); + +template<> +inline boost::property_tree::ptree toPt(const Client& val) { + return val.toPropertyTree(); +} + +template<> +inline Client fromPt(const boost::property_tree::ptree& pt) { + Client ret; + ret.fromPropertyTree(pt); + return ret; +} + +} +} +} +} + +#endif /* Client_H_ */ diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/model/DeprecatedObject.cpp b/samples/server/petstore/cpp-restbed/generated/3_0/model/DeprecatedObject.cpp new file mode 100644 index 00000000000..3e58ffa81c9 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/generated/3_0/model/DeprecatedObject.cpp @@ -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 "DeprecatedObject.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#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 { + +DeprecatedObject::DeprecatedObject(boost::property_tree::ptree const& pt) +{ + fromPropertyTree(pt); +} + + +std::string DeprecatedObject::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 DeprecatedObject::fromJsonString(std::string const& jsonString) +{ + std::stringstream ss(jsonString); + ptree pt; + read_json(ss,pt); + this->fromPropertyTree(pt); +} + +ptree DeprecatedObject::toPropertyTree() const +{ + ptree pt; + ptree tmp_node; + pt.put("name", m_Name); + return pt; +} + +void DeprecatedObject::fromPropertyTree(ptree const &pt) +{ + ptree tmp_node; + m_Name = pt.get("name", ""); +} + +std::string DeprecatedObject::getName() const +{ + return m_Name; +} + +void DeprecatedObject::setName(std::string value) +{ + m_Name = value; +} + + + +std::vector createDeprecatedObjectVectorFromJsonString(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(); + for (const auto& child: pt) { + vec.emplace_back(DeprecatedObject(child.second)); + } + + return vec; +} + +} +} +} +} + diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/model/DeprecatedObject.h b/samples/server/petstore/cpp-restbed/generated/3_0/model/DeprecatedObject.h new file mode 100644 index 00000000000..b6e91c43842 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/generated/3_0/model/DeprecatedObject.h @@ -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. + */ + +/* + * DeprecatedObject.h + * + * + */ + +#ifndef DeprecatedObject_H_ +#define DeprecatedObject_H_ + + + +#include +#include +#include +#include +#include "helpers.h" + +namespace org { +namespace openapitools { +namespace server { +namespace model { + +/// +/// +/// +class DeprecatedObject +{ +public: + DeprecatedObject() = default; + explicit DeprecatedObject(boost::property_tree::ptree const& pt); + virtual ~DeprecatedObject() = default; + + DeprecatedObject(const DeprecatedObject& other) = default; // copy constructor + DeprecatedObject(DeprecatedObject&& other) noexcept = default; // move constructor + + DeprecatedObject& operator=(const DeprecatedObject& other) = default; // copy assignment + DeprecatedObject& operator=(DeprecatedObject&& 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); + + + ///////////////////////////////////////////// + /// DeprecatedObject members + + /// + /// + /// + std::string getName() const; + void setName(std::string value); + +protected: + std::string m_Name = ""; +}; + +std::vector createDeprecatedObjectVectorFromJsonString(const std::string& json); + +template<> +inline boost::property_tree::ptree toPt(const DeprecatedObject& val) { + return val.toPropertyTree(); +} + +template<> +inline DeprecatedObject fromPt(const boost::property_tree::ptree& pt) { + DeprecatedObject ret; + ret.fromPropertyTree(pt); + return ret; +} + +} +} +} +} + +#endif /* DeprecatedObject_H_ */ diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/model/Dog.cpp b/samples/server/petstore/cpp-restbed/generated/3_0/model/Dog.cpp new file mode 100644 index 00000000000..425909a46fb --- /dev/null +++ b/samples/server/petstore/cpp-restbed/generated/3_0/model/Dog.cpp @@ -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 "Dog.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#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 { + +Dog::Dog(boost::property_tree::ptree const& pt) +{ + fromPropertyTree(pt); +} + + +std::string Dog::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 Dog::fromJsonString(std::string const& jsonString) +{ + std::stringstream ss(jsonString); + ptree pt; + read_json(ss,pt); + this->fromPropertyTree(pt); +} + +ptree Dog::toPropertyTree() const +{ + ptree pt; + ptree tmp_node; + pt.put("className", m_ClassName); + pt.put("color", m_Color); + pt.put("breed", m_Breed); + return pt; +} + +void Dog::fromPropertyTree(ptree const &pt) +{ + ptree tmp_node; + m_ClassName = pt.get("className", ""); + m_Color = pt.get("color", "red"); + m_Breed = pt.get("breed", ""); +} + +std::string Dog::getClassName() const +{ + return m_ClassName; +} + +void Dog::setClassName(std::string value) +{ + m_ClassName = value; +} + + +std::string Dog::getColor() const +{ + return m_Color; +} + +void Dog::setColor(std::string value) +{ + m_Color = value; +} + + +std::string Dog::getBreed() const +{ + return m_Breed; +} + +void Dog::setBreed(std::string value) +{ + m_Breed = value; +} + + + +std::vector createDogVectorFromJsonString(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(); + for (const auto& child: pt) { + vec.emplace_back(Dog(child.second)); + } + + return vec; +} + +} +} +} +} + diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/model/Dog.h b/samples/server/petstore/cpp-restbed/generated/3_0/model/Dog.h new file mode 100644 index 00000000000..2759a8342ed --- /dev/null +++ b/samples/server/petstore/cpp-restbed/generated/3_0/model/Dog.h @@ -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. + */ + +/* + * Dog.h + * + * + */ + +#ifndef Dog_H_ +#define Dog_H_ + + + +#include +#include "Animal.h" +#include +#include +#include +#include "Animal.h" +#include "Dog_allOf.h" +#include "helpers.h" + +namespace org { +namespace openapitools { +namespace server { +namespace model { + +/// +/// +/// +class Dog : public Animal, public Dog_allOf +{ +public: + Dog() = default; + explicit Dog(boost::property_tree::ptree const& pt); + virtual ~Dog() = default; + + Dog(const Dog& other) = default; // copy constructor + Dog(Dog&& other) noexcept = default; // move constructor + + Dog& operator=(const Dog& other) = default; // copy assignment + Dog& operator=(Dog&& 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); + + + ///////////////////////////////////////////// + /// Dog members + + /// + /// + /// + std::string getClassName() const; + void setClassName(std::string value); + + /// + /// + /// + std::string getColor() const; + void setColor(std::string value); + + /// + /// + /// + std::string getBreed() const; + void setBreed(std::string value); + +protected: + std::string m_ClassName = ""; + std::string m_Color = "red"; + std::string m_Breed = ""; +}; + +std::vector createDogVectorFromJsonString(const std::string& json); + +template<> +inline boost::property_tree::ptree toPt(const Dog& val) { + return val.toPropertyTree(); +} + +template<> +inline Dog fromPt(const boost::property_tree::ptree& pt) { + Dog ret; + ret.fromPropertyTree(pt); + return ret; +} + +} +} +} +} + +#endif /* Dog_H_ */ diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/model/Dog_allOf.cpp b/samples/server/petstore/cpp-restbed/generated/3_0/model/Dog_allOf.cpp new file mode 100644 index 00000000000..1ff79d5dcf4 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/generated/3_0/model/Dog_allOf.cpp @@ -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 "Dog_allOf.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#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 { + +Dog_allOf::Dog_allOf(boost::property_tree::ptree const& pt) +{ + fromPropertyTree(pt); +} + + +std::string Dog_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 Dog_allOf::fromJsonString(std::string const& jsonString) +{ + std::stringstream ss(jsonString); + ptree pt; + read_json(ss,pt); + this->fromPropertyTree(pt); +} + +ptree Dog_allOf::toPropertyTree() const +{ + ptree pt; + ptree tmp_node; + pt.put("breed", m_Breed); + return pt; +} + +void Dog_allOf::fromPropertyTree(ptree const &pt) +{ + ptree tmp_node; + m_Breed = pt.get("breed", ""); +} + +std::string Dog_allOf::getBreed() const +{ + return m_Breed; +} + +void Dog_allOf::setBreed(std::string value) +{ + m_Breed = value; +} + + + +std::vector createDog_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(); + for (const auto& child: pt) { + vec.emplace_back(Dog_allOf(child.second)); + } + + return vec; +} + +} +} +} +} + diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/model/Dog_allOf.h b/samples/server/petstore/cpp-restbed/generated/3_0/model/Dog_allOf.h new file mode 100644 index 00000000000..b3d10b2eb6d --- /dev/null +++ b/samples/server/petstore/cpp-restbed/generated/3_0/model/Dog_allOf.h @@ -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. + */ + +/* + * Dog_allOf.h + * + * + */ + +#ifndef Dog_allOf_H_ +#define Dog_allOf_H_ + + + +#include +#include +#include +#include +#include "helpers.h" + +namespace org { +namespace openapitools { +namespace server { +namespace model { + +/// +/// +/// +class Dog_allOf +{ +public: + Dog_allOf() = default; + explicit Dog_allOf(boost::property_tree::ptree const& pt); + virtual ~Dog_allOf() = default; + + Dog_allOf(const Dog_allOf& other) = default; // copy constructor + Dog_allOf(Dog_allOf&& other) noexcept = default; // move constructor + + Dog_allOf& operator=(const Dog_allOf& other) = default; // copy assignment + Dog_allOf& operator=(Dog_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); + + + ///////////////////////////////////////////// + /// Dog_allOf members + + /// + /// + /// + std::string getBreed() const; + void setBreed(std::string value); + +protected: + std::string m_Breed = ""; +}; + +std::vector createDog_allOfVectorFromJsonString(const std::string& json); + +template<> +inline boost::property_tree::ptree toPt(const Dog_allOf& val) { + return val.toPropertyTree(); +} + +template<> +inline Dog_allOf fromPt(const boost::property_tree::ptree& pt) { + Dog_allOf ret; + ret.fromPropertyTree(pt); + return ret; +} + +} +} +} +} + +#endif /* Dog_allOf_H_ */ diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/model/EnumArrays.cpp b/samples/server/petstore/cpp-restbed/generated/3_0/model/EnumArrays.cpp new file mode 100644 index 00000000000..260eadcf9f6 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/generated/3_0/model/EnumArrays.cpp @@ -0,0 +1,144 @@ +/** + * 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 "EnumArrays.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#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 { + +EnumArrays::EnumArrays(boost::property_tree::ptree const& pt) +{ + fromPropertyTree(pt); +} + + +std::string EnumArrays::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 EnumArrays::fromJsonString(std::string const& jsonString) +{ + std::stringstream ss(jsonString); + ptree pt; + read_json(ss,pt); + this->fromPropertyTree(pt); +} + +ptree EnumArrays::toPropertyTree() const +{ + ptree pt; + ptree tmp_node; + pt.put("just_symbol", m_Just_symbol); + // generate tree for Array_enum + tmp_node.clear(); + if (!m_Array_enum.empty()) { + tmp_node = toPt(m_Array_enum); + pt.add_child("array_enum", tmp_node); + tmp_node.clear(); + } + return pt; +} + +void EnumArrays::fromPropertyTree(ptree const &pt) +{ + ptree tmp_node; + setJustSymbol(pt.get("just_symbol", "")); + // push all items of Array_enum into member + if (pt.get_child_optional("array_enum")) { + m_Array_enum = fromPt>(pt.get_child("array_enum")); + } +} + +std::string EnumArrays::getJustSymbol() const +{ + return m_Just_symbol; +} + +void EnumArrays::setJustSymbol(std::string value) +{ + static const std::array allowedValues = { + ">=", "$" + }; + + if (std::find(allowedValues.begin(), allowedValues.end(), value) != allowedValues.end()) { + m_Just_symbol = value; + } else { + throw std::runtime_error("Value " + boost::lexical_cast(value) + " not allowed"); + } +} + + +std::vector EnumArrays::getArrayEnum() const +{ + return m_Array_enum; +} + +void EnumArrays::setArrayEnum(std::vector value) +{ + static const std::array allowedValues = { + "fish", "crab" + }; + + for (const auto &v: value) { + if (std::find(allowedValues.begin(), allowedValues.end(), v) == allowedValues.end()) { + throw std::runtime_error("Value " + boost::lexical_cast(v) + " not allowed"); + } + } +} + + + +std::vector createEnumArraysVectorFromJsonString(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(); + for (const auto& child: pt) { + vec.emplace_back(EnumArrays(child.second)); + } + + return vec; +} + +} +} +} +} + diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/model/EnumArrays.h b/samples/server/petstore/cpp-restbed/generated/3_0/model/EnumArrays.h new file mode 100644 index 00000000000..05b476df455 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/generated/3_0/model/EnumArrays.h @@ -0,0 +1,98 @@ +/** + * 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. + */ + +/* + * EnumArrays.h + * + * + */ + +#ifndef EnumArrays_H_ +#define EnumArrays_H_ + + + +#include +#include +#include +#include +#include +#include +#include "helpers.h" + +namespace org { +namespace openapitools { +namespace server { +namespace model { + +/// +/// +/// +class EnumArrays +{ +public: + EnumArrays() = default; + explicit EnumArrays(boost::property_tree::ptree const& pt); + virtual ~EnumArrays() = default; + + EnumArrays(const EnumArrays& other) = default; // copy constructor + EnumArrays(EnumArrays&& other) noexcept = default; // move constructor + + EnumArrays& operator=(const EnumArrays& other) = default; // copy assignment + EnumArrays& operator=(EnumArrays&& 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); + + + ///////////////////////////////////////////// + /// EnumArrays members + + /// + /// + /// + std::string getJustSymbol() const; + void setJustSymbol(std::string value); + + /// + /// + /// + std::vector getArrayEnum() const; + void setArrayEnum(std::vector value); + +protected: + std::string m_Just_symbol = ""; + std::vector m_Array_enum; +}; + +std::vector createEnumArraysVectorFromJsonString(const std::string& json); + +template<> +inline boost::property_tree::ptree toPt(const EnumArrays& val) { + return val.toPropertyTree(); +} + +template<> +inline EnumArrays fromPt(const boost::property_tree::ptree& pt) { + EnumArrays ret; + ret.fromPropertyTree(pt); + return ret; +} + +} +} +} +} + +#endif /* EnumArrays_H_ */ diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/model/EnumClass.cpp b/samples/server/petstore/cpp-restbed/generated/3_0/model/EnumClass.cpp new file mode 100644 index 00000000000..4cc87a3391f --- /dev/null +++ b/samples/server/petstore/cpp-restbed/generated/3_0/model/EnumClass.cpp @@ -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 "EnumClass.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#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 { + +EnumClass::EnumClass(boost::property_tree::ptree const& pt) +{ + fromPropertyTree(pt); +} + + +std::string EnumClass::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 EnumClass::fromJsonString(std::string const& jsonString) +{ + std::stringstream ss(jsonString); + ptree pt; + read_json(ss,pt); + this->fromPropertyTree(pt); +} + +ptree EnumClass::toPropertyTree() const +{ + ptree pt; + ptree tmp_node; + return pt; +} + +void EnumClass::fromPropertyTree(ptree const &pt) +{ + ptree tmp_node; +} + +std::string EnumClass::toString() const { + return boost::lexical_cast(getEnumValue()); +} + +void EnumClass::fromString(const std::string& str) { + setEnumValue(boost::lexical_cast(str)); +} + +std::string EnumClass::getEnumValue() const { + return m_EnumClassEnumValue; +} + +void EnumClass::setEnumValue(const std::string& val) { + static const std::array allowedValues = { + "_abc", "-efg", "(xyz)" + }; + if (std::find(allowedValues.begin(), allowedValues.end(), val) != allowedValues.end()) { + m_EnumClassEnumValue = val; + } else { + throw std::runtime_error("Value " + boost::lexical_cast(val) + " not allowed"); + } +} + +std::vector createEnumClassVectorFromJsonString(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(); + for (const auto& child: pt) { + vec.emplace_back(EnumClass(child.second)); + } + + return vec; +} + +} +} +} +} + diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/model/EnumClass.h b/samples/server/petstore/cpp-restbed/generated/3_0/model/EnumClass.h new file mode 100644 index 00000000000..718a905890a --- /dev/null +++ b/samples/server/petstore/cpp-restbed/generated/3_0/model/EnumClass.h @@ -0,0 +1,86 @@ +/** + * 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. + */ + +/* + * EnumClass.h + * + * + */ + +#ifndef EnumClass_H_ +#define EnumClass_H_ + + + +#include +#include +#include +#include "helpers.h" + +namespace org { +namespace openapitools { +namespace server { +namespace model { + +/// +/// +/// +class EnumClass +{ +public: + EnumClass() = default; + explicit EnumClass(boost::property_tree::ptree const& pt); + virtual ~EnumClass() = default; + + EnumClass(const EnumClass& other) = default; // copy constructor + EnumClass(EnumClass&& other) noexcept = default; // move constructor + + EnumClass& operator=(const EnumClass& other) = default; // copy assignment + EnumClass& operator=(EnumClass&& 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); + + std::string toString() const; + void fromString(const std::string& str); + + ///////////////////////////////////////////// + /// EnumClass members + std::string getEnumValue() const; + void setEnumValue(const std::string& val); + +protected: + std::string m_EnumClassEnumValue; +}; + +std::vector createEnumClassVectorFromJsonString(const std::string& json); + +template<> +inline boost::property_tree::ptree toPt(const EnumClass& val) { + return val.toPropertyTree(); +} + +template<> +inline EnumClass fromPt(const boost::property_tree::ptree& pt) { + EnumClass ret; + ret.fromPropertyTree(pt); + return ret; +} + +} +} +} +} + +#endif /* EnumClass_H_ */ diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/model/Enum_Test.cpp b/samples/server/petstore/cpp-restbed/generated/3_0/model/Enum_Test.cpp new file mode 100644 index 00000000000..280cb3c3af0 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/generated/3_0/model/Enum_Test.cpp @@ -0,0 +1,221 @@ +/** + * 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 "Enum_Test.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#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 { + +Enum_Test::Enum_Test(boost::property_tree::ptree const& pt) +{ + fromPropertyTree(pt); +} + + +std::string Enum_Test::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 Enum_Test::fromJsonString(std::string const& jsonString) +{ + std::stringstream ss(jsonString); + ptree pt; + read_json(ss,pt); + this->fromPropertyTree(pt); +} + +ptree Enum_Test::toPropertyTree() const +{ + ptree pt; + ptree tmp_node; + pt.put("enum_string", m_Enum_string); + pt.put("enum_string_required", m_Enum_string_required); + pt.put("enum_integer", m_Enum_integer); + pt.put("enum_number", m_Enum_number); + return pt; +} + +void Enum_Test::fromPropertyTree(ptree const &pt) +{ + ptree tmp_node; + setEnumString(pt.get("enum_string", "")); + setEnumStringRequired(pt.get("enum_string_required", "")); + setEnumInteger(pt.get("enum_integer", 0)); + setEnumNumber(pt.get("enum_number", 0.0)); +} + +std::string Enum_Test::getEnumString() const +{ + return m_Enum_string; +} + +void Enum_Test::setEnumString(std::string value) +{ + static const std::array allowedValues = { + "UPPER", "lower", "" + }; + + if (std::find(allowedValues.begin(), allowedValues.end(), value) != allowedValues.end()) { + m_Enum_string = value; + } else { + throw std::runtime_error("Value " + boost::lexical_cast(value) + " not allowed"); + } +} + + +std::string Enum_Test::getEnumStringRequired() const +{ + return m_Enum_string_required; +} + +void Enum_Test::setEnumStringRequired(std::string value) +{ + static const std::array allowedValues = { + "UPPER", "lower", "" + }; + + if (std::find(allowedValues.begin(), allowedValues.end(), value) != allowedValues.end()) { + m_Enum_string_required = value; + } else { + throw std::runtime_error("Value " + boost::lexical_cast(value) + " not allowed"); + } +} + + +int32_t Enum_Test::getEnumInteger() const +{ + return m_Enum_integer; +} + +void Enum_Test::setEnumInteger(int32_t value) +{ + static const std::array allowedValues = { + 1, -1 + }; + + if (std::find(allowedValues.begin(), allowedValues.end(), value) != allowedValues.end()) { + m_Enum_integer = value; + } else { + throw std::runtime_error("Value " + boost::lexical_cast(value) + " not allowed"); + } +} + + +double Enum_Test::getEnumNumber() const +{ + return m_Enum_number; +} + +void Enum_Test::setEnumNumber(double value) +{ + static const std::array allowedValues = { + 1.1, -1.2 + }; + + if (std::find(allowedValues.begin(), allowedValues.end(), value) != allowedValues.end()) { + m_Enum_number = value; + } else { + throw std::runtime_error("Value " + boost::lexical_cast(value) + " not allowed"); + } +} + + +OuterEnum Enum_Test::getOuterEnum() const +{ + return m_OuterEnum; +} + +void Enum_Test::setOuterEnum(OuterEnum value) +{ + m_OuterEnum = value; +} + + +OuterEnumInteger Enum_Test::getOuterEnumInteger() const +{ + return m_OuterEnumInteger; +} + +void Enum_Test::setOuterEnumInteger(OuterEnumInteger value) +{ + m_OuterEnumInteger = value; +} + + +OuterEnumDefaultValue Enum_Test::getOuterEnumDefaultValue() const +{ + return m_OuterEnumDefaultValue; +} + +void Enum_Test::setOuterEnumDefaultValue(OuterEnumDefaultValue value) +{ + m_OuterEnumDefaultValue = value; +} + + +OuterEnumIntegerDefaultValue Enum_Test::getOuterEnumIntegerDefaultValue() const +{ + return m_OuterEnumIntegerDefaultValue; +} + +void Enum_Test::setOuterEnumIntegerDefaultValue(OuterEnumIntegerDefaultValue value) +{ + m_OuterEnumIntegerDefaultValue = value; +} + + + +std::vector createEnum_TestVectorFromJsonString(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(); + for (const auto& child: pt) { + vec.emplace_back(Enum_Test(child.second)); + } + + return vec; +} + +} +} +} +} + diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/model/Enum_Test.h b/samples/server/petstore/cpp-restbed/generated/3_0/model/Enum_Test.h new file mode 100644 index 00000000000..092712065e6 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/generated/3_0/model/Enum_Test.h @@ -0,0 +1,143 @@ +/** + * 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. + */ + +/* + * Enum_Test.h + * + * + */ + +#ifndef Enum_Test_H_ +#define Enum_Test_H_ + + + +#include "OuterEnumIntegerDefaultValue.h" +#include "OuterEnumInteger.h" +#include "OuterEnum.h" +#include "OuterEnumDefaultValue.h" +#include +#include +#include +#include +#include +#include "helpers.h" + +namespace org { +namespace openapitools { +namespace server { +namespace model { + +/// +/// +/// +class Enum_Test +{ +public: + Enum_Test() = default; + explicit Enum_Test(boost::property_tree::ptree const& pt); + virtual ~Enum_Test() = default; + + Enum_Test(const Enum_Test& other) = default; // copy constructor + Enum_Test(Enum_Test&& other) noexcept = default; // move constructor + + Enum_Test& operator=(const Enum_Test& other) = default; // copy assignment + Enum_Test& operator=(Enum_Test&& 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); + + + ///////////////////////////////////////////// + /// Enum_Test members + + /// + /// + /// + std::string getEnumString() const; + void setEnumString(std::string value); + + /// + /// + /// + std::string getEnumStringRequired() const; + void setEnumStringRequired(std::string value); + + /// + /// + /// + int32_t getEnumInteger() const; + void setEnumInteger(int32_t value); + + /// + /// + /// + double getEnumNumber() const; + void setEnumNumber(double value); + + /// + /// + /// + OuterEnum getOuterEnum() const; + void setOuterEnum(OuterEnum value); + + /// + /// + /// + OuterEnumInteger getOuterEnumInteger() const; + void setOuterEnumInteger(OuterEnumInteger value); + + /// + /// + /// + OuterEnumDefaultValue getOuterEnumDefaultValue() const; + void setOuterEnumDefaultValue(OuterEnumDefaultValue value); + + /// + /// + /// + OuterEnumIntegerDefaultValue getOuterEnumIntegerDefaultValue() const; + void setOuterEnumIntegerDefaultValue(OuterEnumIntegerDefaultValue value); + +protected: + std::string m_Enum_string = ""; + std::string m_Enum_string_required = ""; + int32_t m_Enum_integer = 0; + double m_Enum_number = 0.0; + OuterEnum m_OuterEnum = OuterEnum{}; + OuterEnumInteger m_OuterEnumInteger = OuterEnumInteger{}; + OuterEnumDefaultValue m_OuterEnumDefaultValue = OuterEnumDefaultValue{}; + OuterEnumIntegerDefaultValue m_OuterEnumIntegerDefaultValue = OuterEnumIntegerDefaultValue{}; +}; + +std::vector createEnum_TestVectorFromJsonString(const std::string& json); + +template<> +inline boost::property_tree::ptree toPt(const Enum_Test& val) { + return val.toPropertyTree(); +} + +template<> +inline Enum_Test fromPt(const boost::property_tree::ptree& pt) { + Enum_Test ret; + ret.fromPropertyTree(pt); + return ret; +} + +} +} +} +} + +#endif /* Enum_Test_H_ */ diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/model/File.cpp b/samples/server/petstore/cpp-restbed/generated/3_0/model/File.cpp new file mode 100644 index 00000000000..af06dfec90b --- /dev/null +++ b/samples/server/petstore/cpp-restbed/generated/3_0/model/File.cpp @@ -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 "File.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#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 { + +File::File(boost::property_tree::ptree const& pt) +{ + fromPropertyTree(pt); +} + + +std::string File::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 File::fromJsonString(std::string const& jsonString) +{ + std::stringstream ss(jsonString); + ptree pt; + read_json(ss,pt); + this->fromPropertyTree(pt); +} + +ptree File::toPropertyTree() const +{ + ptree pt; + ptree tmp_node; + pt.put("sourceURI", m_SourceURI); + return pt; +} + +void File::fromPropertyTree(ptree const &pt) +{ + ptree tmp_node; + m_SourceURI = pt.get("sourceURI", ""); +} + +std::string File::getSourceURI() const +{ + return m_SourceURI; +} + +void File::setSourceURI(std::string value) +{ + m_SourceURI = value; +} + + + +std::vector createFileVectorFromJsonString(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(); + for (const auto& child: pt) { + vec.emplace_back(File(child.second)); + } + + return vec; +} + +} +} +} +} + diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/model/File.h b/samples/server/petstore/cpp-restbed/generated/3_0/model/File.h new file mode 100644 index 00000000000..e9e2938d086 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/generated/3_0/model/File.h @@ -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. + */ + +/* + * File.h + * + * Must be named `File` for test. + */ + +#ifndef File_H_ +#define File_H_ + + + +#include +#include +#include +#include +#include "helpers.h" + +namespace org { +namespace openapitools { +namespace server { +namespace model { + +/// +/// Must be named `File` for test. +/// +class File +{ +public: + File() = default; + explicit File(boost::property_tree::ptree const& pt); + virtual ~File() = default; + + File(const File& other) = default; // copy constructor + File(File&& other) noexcept = default; // move constructor + + File& operator=(const File& other) = default; // copy assignment + File& operator=(File&& 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); + + + ///////////////////////////////////////////// + /// File members + + /// + /// Test capitalization + /// + std::string getSourceURI() const; + void setSourceURI(std::string value); + +protected: + std::string m_SourceURI = ""; +}; + +std::vector createFileVectorFromJsonString(const std::string& json); + +template<> +inline boost::property_tree::ptree toPt(const File& val) { + return val.toPropertyTree(); +} + +template<> +inline File fromPt(const boost::property_tree::ptree& pt) { + File ret; + ret.fromPropertyTree(pt); + return ret; +} + +} +} +} +} + +#endif /* File_H_ */ diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/model/FileSchemaTestClass.cpp b/samples/server/petstore/cpp-restbed/generated/3_0/model/FileSchemaTestClass.cpp new file mode 100644 index 00000000000..e6eba4c5249 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/generated/3_0/model/FileSchemaTestClass.cpp @@ -0,0 +1,129 @@ +/** + * 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 "FileSchemaTestClass.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#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 { + +FileSchemaTestClass::FileSchemaTestClass(boost::property_tree::ptree const& pt) +{ + fromPropertyTree(pt); +} + + +std::string FileSchemaTestClass::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 FileSchemaTestClass::fromJsonString(std::string const& jsonString) +{ + std::stringstream ss(jsonString); + ptree pt; + read_json(ss,pt); + this->fromPropertyTree(pt); +} + +ptree FileSchemaTestClass::toPropertyTree() const +{ + ptree pt; + ptree tmp_node; + pt.add_child("file", m_file.toPropertyTree()); + // generate tree for Files + tmp_node.clear(); + if (!m_Files.empty()) { + tmp_node = toPt(m_Files); + pt.add_child("files", tmp_node); + tmp_node.clear(); + } + return pt; +} + +void FileSchemaTestClass::fromPropertyTree(ptree const &pt) +{ + ptree tmp_node; + if (pt.get_child_optional("file")) { + m_file = fromPt(pt.get_child("file")); + } + // push all items of Files into member + if (pt.get_child_optional("files")) { + m_Files = fromPt>(pt.get_child("files")); + } +} + +File FileSchemaTestClass::getFile() const +{ + return m_file; +} + +void FileSchemaTestClass::setFile(File value) +{ + m_file = value; +} + + +std::vector FileSchemaTestClass::getFiles() const +{ + return m_Files; +} + +void FileSchemaTestClass::setFiles(std::vector value) +{ + m_Files = value; +} + + + +std::vector createFileSchemaTestClassVectorFromJsonString(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(); + for (const auto& child: pt) { + vec.emplace_back(FileSchemaTestClass(child.second)); + } + + return vec; +} + +} +} +} +} + diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/model/FileSchemaTestClass.h b/samples/server/petstore/cpp-restbed/generated/3_0/model/FileSchemaTestClass.h new file mode 100644 index 00000000000..f8584fb55dc --- /dev/null +++ b/samples/server/petstore/cpp-restbed/generated/3_0/model/FileSchemaTestClass.h @@ -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. + */ + +/* + * FileSchemaTestClass.h + * + * + */ + +#ifndef FileSchemaTestClass_H_ +#define FileSchemaTestClass_H_ + + + +#include "File.h" +#include +#include +#include +#include +#include "helpers.h" + +namespace org { +namespace openapitools { +namespace server { +namespace model { + +/// +/// +/// +class FileSchemaTestClass +{ +public: + FileSchemaTestClass() = default; + explicit FileSchemaTestClass(boost::property_tree::ptree const& pt); + virtual ~FileSchemaTestClass() = default; + + FileSchemaTestClass(const FileSchemaTestClass& other) = default; // copy constructor + FileSchemaTestClass(FileSchemaTestClass&& other) noexcept = default; // move constructor + + FileSchemaTestClass& operator=(const FileSchemaTestClass& other) = default; // copy assignment + FileSchemaTestClass& operator=(FileSchemaTestClass&& 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); + + + ///////////////////////////////////////////// + /// FileSchemaTestClass members + + /// + /// + /// + File getFile() const; + void setFile(File value); + + /// + /// + /// + std::vector getFiles() const; + void setFiles(std::vector value); + +protected: + File m_file; + std::vector m_Files; +}; + +std::vector createFileSchemaTestClassVectorFromJsonString(const std::string& json); + +template<> +inline boost::property_tree::ptree toPt(const FileSchemaTestClass& val) { + return val.toPropertyTree(); +} + +template<> +inline FileSchemaTestClass fromPt(const boost::property_tree::ptree& pt) { + FileSchemaTestClass ret; + ret.fromPropertyTree(pt); + return ret; +} + +} +} +} +} + +#endif /* FileSchemaTestClass_H_ */ diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/model/Foo.cpp b/samples/server/petstore/cpp-restbed/generated/3_0/model/Foo.cpp new file mode 100644 index 00000000000..ddeaebd6f89 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/generated/3_0/model/Foo.cpp @@ -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 "Foo.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#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 { + +Foo::Foo(boost::property_tree::ptree const& pt) +{ + fromPropertyTree(pt); +} + + +std::string Foo::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 Foo::fromJsonString(std::string const& jsonString) +{ + std::stringstream ss(jsonString); + ptree pt; + read_json(ss,pt); + this->fromPropertyTree(pt); +} + +ptree Foo::toPropertyTree() const +{ + ptree pt; + ptree tmp_node; + pt.put("bar", m_Bar); + return pt; +} + +void Foo::fromPropertyTree(ptree const &pt) +{ + ptree tmp_node; + m_Bar = pt.get("bar", "bar"); +} + +std::string Foo::getBar() const +{ + return m_Bar; +} + +void Foo::setBar(std::string value) +{ + m_Bar = value; +} + + + +std::vector createFooVectorFromJsonString(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(); + for (const auto& child: pt) { + vec.emplace_back(Foo(child.second)); + } + + return vec; +} + +} +} +} +} + diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/model/Foo.h b/samples/server/petstore/cpp-restbed/generated/3_0/model/Foo.h new file mode 100644 index 00000000000..004ba8c27e5 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/generated/3_0/model/Foo.h @@ -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. + */ + +/* + * Foo.h + * + * + */ + +#ifndef Foo_H_ +#define Foo_H_ + + + +#include +#include +#include +#include +#include "helpers.h" + +namespace org { +namespace openapitools { +namespace server { +namespace model { + +/// +/// +/// +class Foo +{ +public: + Foo() = default; + explicit Foo(boost::property_tree::ptree const& pt); + virtual ~Foo() = default; + + Foo(const Foo& other) = default; // copy constructor + Foo(Foo&& other) noexcept = default; // move constructor + + Foo& operator=(const Foo& other) = default; // copy assignment + Foo& operator=(Foo&& 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); + + + ///////////////////////////////////////////// + /// Foo members + + /// + /// + /// + std::string getBar() const; + void setBar(std::string value); + +protected: + std::string m_Bar = "bar"; +}; + +std::vector createFooVectorFromJsonString(const std::string& json); + +template<> +inline boost::property_tree::ptree toPt(const Foo& val) { + return val.toPropertyTree(); +} + +template<> +inline Foo fromPt(const boost::property_tree::ptree& pt) { + Foo ret; + ret.fromPropertyTree(pt); + return ret; +} + +} +} +} +} + +#endif /* Foo_H_ */ diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/model/Format_test.cpp b/samples/server/petstore/cpp-restbed/generated/3_0/model/Format_test.cpp new file mode 100644 index 00000000000..4701ba408ba --- /dev/null +++ b/samples/server/petstore/cpp-restbed/generated/3_0/model/Format_test.cpp @@ -0,0 +1,294 @@ +/** + * 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 "Format_test.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#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 { + +Format_test::Format_test(boost::property_tree::ptree const& pt) +{ + fromPropertyTree(pt); +} + + +std::string Format_test::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 Format_test::fromJsonString(std::string const& jsonString) +{ + std::stringstream ss(jsonString); + ptree pt; + read_json(ss,pt); + this->fromPropertyTree(pt); +} + +ptree Format_test::toPropertyTree() const +{ + ptree pt; + ptree tmp_node; + pt.put("integer", m_integer); + pt.put("int32", m_Int32); + pt.put("int64", m_Int64); + pt.put("number", m_number); + pt.put("float", m_float); + pt.put("double", m_double); + pt.put("string", m_string); + pt.put("date", m_date); + pt.put("dateTime", m_DateTime); + pt.put("uuid", m_Uuid); + pt.put("password", m_Password); + pt.put("pattern_with_digits", m_Pattern_with_digits); + pt.put("pattern_with_digits_and_delimiter", m_Pattern_with_digits_and_delimiter); + return pt; +} + +void Format_test::fromPropertyTree(ptree const &pt) +{ + ptree tmp_node; + m_integer = pt.get("integer", 0); + m_Int32 = pt.get("int32", 0); + m_Int64 = pt.get("int64", 0L); + m_number = pt.get("number", 0.0); + m_float = pt.get("float", 0.0f); + m_double = pt.get("double", 0.0); + m_string = pt.get("string", ""); + m_date = pt.get("date", ""); + m_DateTime = pt.get("dateTime", ""); + m_Uuid = pt.get("uuid", ""); + m_Password = pt.get("password", ""); + m_Pattern_with_digits = pt.get("pattern_with_digits", ""); + m_Pattern_with_digits_and_delimiter = pt.get("pattern_with_digits_and_delimiter", ""); +} + +int32_t Format_test::getInteger() const +{ + return m_integer; +} + +void Format_test::setInteger(int32_t value) +{ + m_integer = value; +} + + +int32_t Format_test::getInt32() const +{ + return m_Int32; +} + +void Format_test::setInt32(int32_t value) +{ + m_Int32 = value; +} + + +int64_t Format_test::getInt64() const +{ + return m_Int64; +} + +void Format_test::setInt64(int64_t value) +{ + m_Int64 = value; +} + + +double Format_test::getNumber() const +{ + return m_number; +} + +void Format_test::setNumber(double value) +{ + m_number = value; +} + + +float Format_test::getFloat() const +{ + return m_float; +} + +void Format_test::setFloat(float value) +{ + m_float = value; +} + + +double Format_test::getDouble() const +{ + return m_double; +} + +void Format_test::setDouble(double value) +{ + m_double = value; +} + + +std::string Format_test::getDecimal() const +{ + return m_decimal; +} + +void Format_test::setDecimal(std::string value) +{ + m_decimal = value; +} + + +std::string Format_test::getString() const +{ + return m_string; +} + +void Format_test::setString(std::string value) +{ + m_string = value; +} + + +std::string Format_test::getByte() const +{ + return m_Byte; +} + +void Format_test::setByte(std::string value) +{ + m_Byte = value; +} + + +std::string Format_test::getBinary() const +{ + return m_binary; +} + +void Format_test::setBinary(std::string value) +{ + m_binary = value; +} + + +std::string Format_test::getDate() const +{ + return m_date; +} + +void Format_test::setDate(std::string value) +{ + m_date = value; +} + + +std::string Format_test::getDateTime() const +{ + return m_DateTime; +} + +void Format_test::setDateTime(std::string value) +{ + m_DateTime = value; +} + + +std::string Format_test::getUuid() const +{ + return m_Uuid; +} + +void Format_test::setUuid(std::string value) +{ + m_Uuid = value; +} + + +std::string Format_test::getPassword() const +{ + return m_Password; +} + +void Format_test::setPassword(std::string value) +{ + m_Password = value; +} + + +std::string Format_test::getPatternWithDigits() const +{ + return m_Pattern_with_digits; +} + +void Format_test::setPatternWithDigits(std::string value) +{ + m_Pattern_with_digits = value; +} + + +std::string Format_test::getPatternWithDigitsAndDelimiter() const +{ + return m_Pattern_with_digits_and_delimiter; +} + +void Format_test::setPatternWithDigitsAndDelimiter(std::string value) +{ + m_Pattern_with_digits_and_delimiter = value; +} + + + +std::vector createFormat_testVectorFromJsonString(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(); + for (const auto& child: pt) { + vec.emplace_back(Format_test(child.second)); + } + + return vec; +} + +} +} +} +} + diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/model/Format_test.h b/samples/server/petstore/cpp-restbed/generated/3_0/model/Format_test.h new file mode 100644 index 00000000000..1db28a3af5c --- /dev/null +++ b/samples/server/petstore/cpp-restbed/generated/3_0/model/Format_test.h @@ -0,0 +1,194 @@ +/** + * 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. + */ + +/* + * Format_test.h + * + * + */ + +#ifndef Format_test_H_ +#define Format_test_H_ + + + +#include +#include +#include +#include +#include "helpers.h" + +namespace org { +namespace openapitools { +namespace server { +namespace model { + +/// +/// +/// +class Format_test +{ +public: + Format_test() = default; + explicit Format_test(boost::property_tree::ptree const& pt); + virtual ~Format_test() = default; + + Format_test(const Format_test& other) = default; // copy constructor + Format_test(Format_test&& other) noexcept = default; // move constructor + + Format_test& operator=(const Format_test& other) = default; // copy assignment + Format_test& operator=(Format_test&& 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); + + + ///////////////////////////////////////////// + /// Format_test members + + /// + /// + /// + int32_t getInteger() const; + void setInteger(int32_t value); + + /// + /// + /// + int32_t getInt32() const; + void setInt32(int32_t value); + + /// + /// + /// + int64_t getInt64() const; + void setInt64(int64_t value); + + /// + /// + /// + double getNumber() const; + void setNumber(double value); + + /// + /// + /// + float getFloat() const; + void setFloat(float value); + + /// + /// + /// + double getDouble() const; + void setDouble(double value); + + /// + /// + /// + std::string getDecimal() const; + void setDecimal(std::string value); + + /// + /// + /// + std::string getString() const; + void setString(std::string value); + + /// + /// + /// + std::string getByte() const; + void setByte(std::string value); + + /// + /// + /// + std::string getBinary() const; + void setBinary(std::string value); + + /// + /// + /// + std::string getDate() const; + void setDate(std::string value); + + /// + /// + /// + std::string getDateTime() const; + void setDateTime(std::string value); + + /// + /// + /// + std::string getUuid() const; + void setUuid(std::string value); + + /// + /// + /// + std::string getPassword() const; + void setPassword(std::string value); + + /// + /// A string that is a 10 digit number. Can have leading zeros. + /// + std::string getPatternWithDigits() const; + void setPatternWithDigits(std::string value); + + /// + /// A string starting with 'image_' (case insensitive) and one to three digits following i.e. Image_01. + /// + std::string getPatternWithDigitsAndDelimiter() const; + void setPatternWithDigitsAndDelimiter(std::string value); + +protected: + int32_t m_integer = 0; + int32_t m_Int32 = 0; + int64_t m_Int64 = 0L; + double m_number = 0.0; + float m_float = 0.0f; + double m_double = 0.0; + std::string m_decimal = ""; + std::string m_string = ""; + std::string m_Byte = ""; + std::string m_binary = ""; + std::string m_date = ""; + std::string m_DateTime = ""; + std::string m_Uuid = ""; + std::string m_Password = ""; + std::string m_Pattern_with_digits = ""; + std::string m_Pattern_with_digits_and_delimiter = ""; +}; + +std::vector createFormat_testVectorFromJsonString(const std::string& json); + +template<> +inline boost::property_tree::ptree toPt(const Format_test& val) { + return val.toPropertyTree(); +} + +template<> +inline Format_test fromPt(const boost::property_tree::ptree& pt) { + Format_test ret; + ret.fromPropertyTree(pt); + return ret; +} + +} +} +} +} + +#endif /* Format_test_H_ */ diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/model/HasOnlyReadOnly.cpp b/samples/server/petstore/cpp-restbed/generated/3_0/model/HasOnlyReadOnly.cpp new file mode 100644 index 00000000000..9e02f55f431 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/generated/3_0/model/HasOnlyReadOnly.cpp @@ -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 "HasOnlyReadOnly.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#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 { + +HasOnlyReadOnly::HasOnlyReadOnly(boost::property_tree::ptree const& pt) +{ + fromPropertyTree(pt); +} + + +std::string HasOnlyReadOnly::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 HasOnlyReadOnly::fromJsonString(std::string const& jsonString) +{ + std::stringstream ss(jsonString); + ptree pt; + read_json(ss,pt); + this->fromPropertyTree(pt); +} + +ptree HasOnlyReadOnly::toPropertyTree() const +{ + ptree pt; + ptree tmp_node; + pt.put("bar", m_Bar); + pt.put("foo", m_Foo); + return pt; +} + +void HasOnlyReadOnly::fromPropertyTree(ptree const &pt) +{ + ptree tmp_node; + m_Bar = pt.get("bar", ""); + m_Foo = pt.get("foo", ""); +} + +std::string HasOnlyReadOnly::getBar() const +{ + return m_Bar; +} + +void HasOnlyReadOnly::setBar(std::string value) +{ + m_Bar = value; +} + + +std::string HasOnlyReadOnly::getFoo() const +{ + return m_Foo; +} + +void HasOnlyReadOnly::setFoo(std::string value) +{ + m_Foo = value; +} + + + +std::vector createHasOnlyReadOnlyVectorFromJsonString(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(); + for (const auto& child: pt) { + vec.emplace_back(HasOnlyReadOnly(child.second)); + } + + return vec; +} + +} +} +} +} + diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/model/HasOnlyReadOnly.h b/samples/server/petstore/cpp-restbed/generated/3_0/model/HasOnlyReadOnly.h new file mode 100644 index 00000000000..16f64910937 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/generated/3_0/model/HasOnlyReadOnly.h @@ -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. + */ + +/* + * HasOnlyReadOnly.h + * + * + */ + +#ifndef HasOnlyReadOnly_H_ +#define HasOnlyReadOnly_H_ + + + +#include +#include +#include +#include +#include "helpers.h" + +namespace org { +namespace openapitools { +namespace server { +namespace model { + +/// +/// +/// +class HasOnlyReadOnly +{ +public: + HasOnlyReadOnly() = default; + explicit HasOnlyReadOnly(boost::property_tree::ptree const& pt); + virtual ~HasOnlyReadOnly() = default; + + HasOnlyReadOnly(const HasOnlyReadOnly& other) = default; // copy constructor + HasOnlyReadOnly(HasOnlyReadOnly&& other) noexcept = default; // move constructor + + HasOnlyReadOnly& operator=(const HasOnlyReadOnly& other) = default; // copy assignment + HasOnlyReadOnly& operator=(HasOnlyReadOnly&& 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); + + + ///////////////////////////////////////////// + /// HasOnlyReadOnly members + + /// + /// + /// + std::string getBar() const; + void setBar(std::string value); + + /// + /// + /// + std::string getFoo() const; + void setFoo(std::string value); + +protected: + std::string m_Bar = ""; + std::string m_Foo = ""; +}; + +std::vector createHasOnlyReadOnlyVectorFromJsonString(const std::string& json); + +template<> +inline boost::property_tree::ptree toPt(const HasOnlyReadOnly& val) { + return val.toPropertyTree(); +} + +template<> +inline HasOnlyReadOnly fromPt(const boost::property_tree::ptree& pt) { + HasOnlyReadOnly ret; + ret.fromPropertyTree(pt); + return ret; +} + +} +} +} +} + +#endif /* HasOnlyReadOnly_H_ */ diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/model/HealthCheckResult.cpp b/samples/server/petstore/cpp-restbed/generated/3_0/model/HealthCheckResult.cpp new file mode 100644 index 00000000000..16ca7e8f962 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/generated/3_0/model/HealthCheckResult.cpp @@ -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 "HealthCheckResult.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#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 { + +HealthCheckResult::HealthCheckResult(boost::property_tree::ptree const& pt) +{ + fromPropertyTree(pt); +} + + +std::string HealthCheckResult::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 HealthCheckResult::fromJsonString(std::string const& jsonString) +{ + std::stringstream ss(jsonString); + ptree pt; + read_json(ss,pt); + this->fromPropertyTree(pt); +} + +ptree HealthCheckResult::toPropertyTree() const +{ + ptree pt; + ptree tmp_node; + pt.put("NullableMessage", m_NullableMessage); + return pt; +} + +void HealthCheckResult::fromPropertyTree(ptree const &pt) +{ + ptree tmp_node; + m_NullableMessage = pt.get("NullableMessage", ""); +} + +std::string HealthCheckResult::getNullableMessage() const +{ + return m_NullableMessage; +} + +void HealthCheckResult::setNullableMessage(std::string value) +{ + m_NullableMessage = value; +} + + + +std::vector createHealthCheckResultVectorFromJsonString(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(); + for (const auto& child: pt) { + vec.emplace_back(HealthCheckResult(child.second)); + } + + return vec; +} + +} +} +} +} + diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/model/HealthCheckResult.h b/samples/server/petstore/cpp-restbed/generated/3_0/model/HealthCheckResult.h new file mode 100644 index 00000000000..4314b5cdcde --- /dev/null +++ b/samples/server/petstore/cpp-restbed/generated/3_0/model/HealthCheckResult.h @@ -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. + */ + +/* + * HealthCheckResult.h + * + * Just a string to inform instance is up and running. Make it nullable in hope to get it as pointer in generated model. + */ + +#ifndef HealthCheckResult_H_ +#define HealthCheckResult_H_ + + + +#include +#include +#include +#include +#include "helpers.h" + +namespace org { +namespace openapitools { +namespace server { +namespace model { + +/// +/// Just a string to inform instance is up and running. Make it nullable in hope to get it as pointer in generated model. +/// +class HealthCheckResult +{ +public: + HealthCheckResult() = default; + explicit HealthCheckResult(boost::property_tree::ptree const& pt); + virtual ~HealthCheckResult() = default; + + HealthCheckResult(const HealthCheckResult& other) = default; // copy constructor + HealthCheckResult(HealthCheckResult&& other) noexcept = default; // move constructor + + HealthCheckResult& operator=(const HealthCheckResult& other) = default; // copy assignment + HealthCheckResult& operator=(HealthCheckResult&& 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); + + + ///////////////////////////////////////////// + /// HealthCheckResult members + + /// + /// + /// + std::string getNullableMessage() const; + void setNullableMessage(std::string value); + +protected: + std::string m_NullableMessage = ""; +}; + +std::vector createHealthCheckResultVectorFromJsonString(const std::string& json); + +template<> +inline boost::property_tree::ptree toPt(const HealthCheckResult& val) { + return val.toPropertyTree(); +} + +template<> +inline HealthCheckResult fromPt(const boost::property_tree::ptree& pt) { + HealthCheckResult ret; + ret.fromPropertyTree(pt); + return ret; +} + +} +} +} +} + +#endif /* HealthCheckResult_H_ */ diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/model/List.cpp b/samples/server/petstore/cpp-restbed/generated/3_0/model/List.cpp new file mode 100644 index 00000000000..79224a61b5c --- /dev/null +++ b/samples/server/petstore/cpp-restbed/generated/3_0/model/List.cpp @@ -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 "List.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#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 { + +List::List(boost::property_tree::ptree const& pt) +{ + fromPropertyTree(pt); +} + + +std::string List::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 List::fromJsonString(std::string const& jsonString) +{ + std::stringstream ss(jsonString); + ptree pt; + read_json(ss,pt); + this->fromPropertyTree(pt); +} + +ptree List::toPropertyTree() const +{ + ptree pt; + ptree tmp_node; + pt.put("123-list", m_r_123_list); + return pt; +} + +void List::fromPropertyTree(ptree const &pt) +{ + ptree tmp_node; + m_r_123_list = pt.get("123-list", ""); +} + +std::string List::getR123List() const +{ + return m_r_123_list; +} + +void List::setR123List(std::string value) +{ + m_r_123_list = value; +} + + + +std::vector createListVectorFromJsonString(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(); + for (const auto& child: pt) { + vec.emplace_back(List(child.second)); + } + + return vec; +} + +} +} +} +} + diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/model/List.h b/samples/server/petstore/cpp-restbed/generated/3_0/model/List.h new file mode 100644 index 00000000000..df9a0b764c6 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/generated/3_0/model/List.h @@ -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. + */ + +/* + * List.h + * + * + */ + +#ifndef List_H_ +#define List_H_ + + + +#include +#include +#include +#include +#include "helpers.h" + +namespace org { +namespace openapitools { +namespace server { +namespace model { + +/// +/// +/// +class List +{ +public: + List() = default; + explicit List(boost::property_tree::ptree const& pt); + virtual ~List() = default; + + List(const List& other) = default; // copy constructor + List(List&& other) noexcept = default; // move constructor + + List& operator=(const List& other) = default; // copy assignment + List& operator=(List&& 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); + + + ///////////////////////////////////////////// + /// List members + + /// + /// + /// + std::string getR123List() const; + void setR123List(std::string value); + +protected: + std::string m_r_123_list = ""; +}; + +std::vector createListVectorFromJsonString(const std::string& json); + +template<> +inline boost::property_tree::ptree toPt(const List& val) { + return val.toPropertyTree(); +} + +template<> +inline List fromPt(const boost::property_tree::ptree& pt) { + List ret; + ret.fromPropertyTree(pt); + return ret; +} + +} +} +} +} + +#endif /* List_H_ */ diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/model/MapTest.cpp b/samples/server/petstore/cpp-restbed/generated/3_0/model/MapTest.cpp new file mode 100644 index 00000000000..00488de0d8b --- /dev/null +++ b/samples/server/petstore/cpp-restbed/generated/3_0/model/MapTest.cpp @@ -0,0 +1,182 @@ +/** + * 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 "MapTest.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#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 { + +MapTest::MapTest(boost::property_tree::ptree const& pt) +{ + fromPropertyTree(pt); +} + + +std::string MapTest::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 MapTest::fromJsonString(std::string const& jsonString) +{ + std::stringstream ss(jsonString); + ptree pt; + read_json(ss,pt); + this->fromPropertyTree(pt); +} + +ptree MapTest::toPropertyTree() const +{ + ptree pt; + ptree tmp_node; + // generate tree for Map_map_of_string + if (!m_Map_map_of_string.empty()) { + tmp_node = toPt(m_Map_map_of_string); + pt.add_child("map_map_of_string", tmp_node); + } + tmp_node.clear(); + // generate tree for Map_of_enum_string + if (!m_Map_of_enum_string.empty()) { + tmp_node = toPt(m_Map_of_enum_string); + pt.add_child("map_of_enum_string", tmp_node); + } + tmp_node.clear(); + // generate tree for Direct_map + if (!m_Direct_map.empty()) { + tmp_node = toPt(m_Direct_map); + pt.add_child("direct_map", tmp_node); + } + tmp_node.clear(); + // generate tree for Indirect_map + if (!m_Indirect_map.empty()) { + tmp_node = toPt(m_Indirect_map); + pt.add_child("indirect_map", tmp_node); + } + tmp_node.clear(); + return pt; +} + +void MapTest::fromPropertyTree(ptree const &pt) +{ + ptree tmp_node; + if (pt.get_child_optional("map_map_of_string")) { + m_Map_map_of_string = fromPt>>(pt.get_child("map_map_of_string")); + } + if (pt.get_child_optional("map_of_enum_string")) { + m_Map_of_enum_string = fromPt>(pt.get_child("map_of_enum_string")); + } + if (pt.get_child_optional("direct_map")) { + m_Direct_map = fromPt>(pt.get_child("direct_map")); + } + if (pt.get_child_optional("indirect_map")) { + m_Indirect_map = fromPt>(pt.get_child("indirect_map")); + } +} + +std::map> MapTest::getMapMapOfString() const +{ + return m_Map_map_of_string; +} + +void MapTest::setMapMapOfString(std::map> value) +{ + m_Map_map_of_string = value; +} + + +std::map MapTest::getMapOfEnumString() const +{ + return m_Map_of_enum_string; +} + +void MapTest::setMapOfEnumString(std::map value) +{ + static const std::array allowedValues = { + "UPPER", "lower" + }; + + for (const auto &v: value) { + if (std::find(allowedValues.begin(), allowedValues.end(), v.first) == allowedValues.end()) { + throw std::runtime_error("Value " + boost::lexical_cast(v.first) + " not allowed"); + } + } + m_Map_of_enum_string = value; +} + + +std::map MapTest::getDirectMap() const +{ + return m_Direct_map; +} + +void MapTest::setDirectMap(std::map value) +{ + m_Direct_map = value; +} + + +std::map MapTest::getIndirectMap() const +{ + return m_Indirect_map; +} + +void MapTest::setIndirectMap(std::map value) +{ + m_Indirect_map = value; +} + + + +std::vector createMapTestVectorFromJsonString(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(); + for (const auto& child: pt) { + vec.emplace_back(MapTest(child.second)); + } + + return vec; +} + +} +} +} +} + diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/model/MapTest.h b/samples/server/petstore/cpp-restbed/generated/3_0/model/MapTest.h new file mode 100644 index 00000000000..0c94e561659 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/generated/3_0/model/MapTest.h @@ -0,0 +1,112 @@ +/** + * 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. + */ + +/* + * MapTest.h + * + * + */ + +#ifndef MapTest_H_ +#define MapTest_H_ + + + +#include +#include +#include +#include +#include +#include +#include "helpers.h" + +namespace org { +namespace openapitools { +namespace server { +namespace model { + +/// +/// +/// +class MapTest +{ +public: + MapTest() = default; + explicit MapTest(boost::property_tree::ptree const& pt); + virtual ~MapTest() = default; + + MapTest(const MapTest& other) = default; // copy constructor + MapTest(MapTest&& other) noexcept = default; // move constructor + + MapTest& operator=(const MapTest& other) = default; // copy assignment + MapTest& operator=(MapTest&& 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); + + + ///////////////////////////////////////////// + /// MapTest members + + /// + /// + /// + std::map> getMapMapOfString() const; + void setMapMapOfString(std::map> value); + + /// + /// + /// + std::map getMapOfEnumString() const; + void setMapOfEnumString(std::map value); + + /// + /// + /// + std::map getDirectMap() const; + void setDirectMap(std::map value); + + /// + /// + /// + std::map getIndirectMap() const; + void setIndirectMap(std::map value); + +protected: + std::map> m_Map_map_of_string; + std::map m_Map_of_enum_string; + std::map m_Direct_map; + std::map m_Indirect_map; +}; + +std::vector createMapTestVectorFromJsonString(const std::string& json); + +template<> +inline boost::property_tree::ptree toPt(const MapTest& val) { + return val.toPropertyTree(); +} + +template<> +inline MapTest fromPt(const boost::property_tree::ptree& pt) { + MapTest ret; + ret.fromPropertyTree(pt); + return ret; +} + +} +} +} +} + +#endif /* MapTest_H_ */ diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/model/MixedPropertiesAndAdditionalPropertiesClass.cpp b/samples/server/petstore/cpp-restbed/generated/3_0/model/MixedPropertiesAndAdditionalPropertiesClass.cpp new file mode 100644 index 00000000000..9c442804615 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/generated/3_0/model/MixedPropertiesAndAdditionalPropertiesClass.cpp @@ -0,0 +1,138 @@ +/** + * 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 "MixedPropertiesAndAdditionalPropertiesClass.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#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 { + +MixedPropertiesAndAdditionalPropertiesClass::MixedPropertiesAndAdditionalPropertiesClass(boost::property_tree::ptree const& pt) +{ + fromPropertyTree(pt); +} + + +std::string MixedPropertiesAndAdditionalPropertiesClass::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 MixedPropertiesAndAdditionalPropertiesClass::fromJsonString(std::string const& jsonString) +{ + std::stringstream ss(jsonString); + ptree pt; + read_json(ss,pt); + this->fromPropertyTree(pt); +} + +ptree MixedPropertiesAndAdditionalPropertiesClass::toPropertyTree() const +{ + ptree pt; + ptree tmp_node; + pt.put("uuid", m_Uuid); + pt.put("dateTime", m_DateTime); + // generate tree for map + if (!m_map.empty()) { + tmp_node = toPt(m_map); + pt.add_child("map", tmp_node); + } + tmp_node.clear(); + return pt; +} + +void MixedPropertiesAndAdditionalPropertiesClass::fromPropertyTree(ptree const &pt) +{ + ptree tmp_node; + m_Uuid = pt.get("uuid", ""); + m_DateTime = pt.get("dateTime", ""); + if (pt.get_child_optional("map")) { + m_map = fromPt>(pt.get_child("map")); + } +} + +std::string MixedPropertiesAndAdditionalPropertiesClass::getUuid() const +{ + return m_Uuid; +} + +void MixedPropertiesAndAdditionalPropertiesClass::setUuid(std::string value) +{ + m_Uuid = value; +} + + +std::string MixedPropertiesAndAdditionalPropertiesClass::getDateTime() const +{ + return m_DateTime; +} + +void MixedPropertiesAndAdditionalPropertiesClass::setDateTime(std::string value) +{ + m_DateTime = value; +} + + +std::map MixedPropertiesAndAdditionalPropertiesClass::getMap() const +{ + return m_map; +} + +void MixedPropertiesAndAdditionalPropertiesClass::setMap(std::map value) +{ + m_map = value; +} + + + +std::vector createMixedPropertiesAndAdditionalPropertiesClassVectorFromJsonString(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(); + for (const auto& child: pt) { + vec.emplace_back(MixedPropertiesAndAdditionalPropertiesClass(child.second)); + } + + return vec; +} + +} +} +} +} + diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/model/MixedPropertiesAndAdditionalPropertiesClass.h b/samples/server/petstore/cpp-restbed/generated/3_0/model/MixedPropertiesAndAdditionalPropertiesClass.h new file mode 100644 index 00000000000..1c6fdbf3774 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/generated/3_0/model/MixedPropertiesAndAdditionalPropertiesClass.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. + */ + +/* + * MixedPropertiesAndAdditionalPropertiesClass.h + * + * + */ + +#ifndef MixedPropertiesAndAdditionalPropertiesClass_H_ +#define MixedPropertiesAndAdditionalPropertiesClass_H_ + + + +#include +#include +#include "Animal.h" +#include +#include +#include +#include "helpers.h" + +namespace org { +namespace openapitools { +namespace server { +namespace model { + +/// +/// +/// +class MixedPropertiesAndAdditionalPropertiesClass +{ +public: + MixedPropertiesAndAdditionalPropertiesClass() = default; + explicit MixedPropertiesAndAdditionalPropertiesClass(boost::property_tree::ptree const& pt); + virtual ~MixedPropertiesAndAdditionalPropertiesClass() = default; + + MixedPropertiesAndAdditionalPropertiesClass(const MixedPropertiesAndAdditionalPropertiesClass& other) = default; // copy constructor + MixedPropertiesAndAdditionalPropertiesClass(MixedPropertiesAndAdditionalPropertiesClass&& other) noexcept = default; // move constructor + + MixedPropertiesAndAdditionalPropertiesClass& operator=(const MixedPropertiesAndAdditionalPropertiesClass& other) = default; // copy assignment + MixedPropertiesAndAdditionalPropertiesClass& operator=(MixedPropertiesAndAdditionalPropertiesClass&& 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); + + + ///////////////////////////////////////////// + /// MixedPropertiesAndAdditionalPropertiesClass members + + /// + /// + /// + std::string getUuid() const; + void setUuid(std::string value); + + /// + /// + /// + std::string getDateTime() const; + void setDateTime(std::string value); + + /// + /// + /// + std::map getMap() const; + void setMap(std::map value); + +protected: + std::string m_Uuid = ""; + std::string m_DateTime = ""; + std::map m_map; +}; + +std::vector createMixedPropertiesAndAdditionalPropertiesClassVectorFromJsonString(const std::string& json); + +template<> +inline boost::property_tree::ptree toPt(const MixedPropertiesAndAdditionalPropertiesClass& val) { + return val.toPropertyTree(); +} + +template<> +inline MixedPropertiesAndAdditionalPropertiesClass fromPt(const boost::property_tree::ptree& pt) { + MixedPropertiesAndAdditionalPropertiesClass ret; + ret.fromPropertyTree(pt); + return ret; +} + +} +} +} +} + +#endif /* MixedPropertiesAndAdditionalPropertiesClass_H_ */ diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/model/Name.cpp b/samples/server/petstore/cpp-restbed/generated/3_0/model/Name.cpp new file mode 100644 index 00000000000..c9fcd6795da --- /dev/null +++ b/samples/server/petstore/cpp-restbed/generated/3_0/model/Name.cpp @@ -0,0 +1,144 @@ +/** + * 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 "Name.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#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 { + +Name::Name(boost::property_tree::ptree const& pt) +{ + fromPropertyTree(pt); +} + + +std::string Name::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 Name::fromJsonString(std::string const& jsonString) +{ + std::stringstream ss(jsonString); + ptree pt; + read_json(ss,pt); + this->fromPropertyTree(pt); +} + +ptree Name::toPropertyTree() const +{ + ptree pt; + ptree tmp_node; + pt.put("name", m_Name); + pt.put("snake_case", m_Snake_case); + pt.put("property", m_Property); + pt.put("123Number", m_r_123Number); + return pt; +} + +void Name::fromPropertyTree(ptree const &pt) +{ + ptree tmp_node; + m_Name = pt.get("name", 0); + m_Snake_case = pt.get("snake_case", 0); + m_Property = pt.get("property", ""); + m_r_123Number = pt.get("123Number", 0); +} + +int32_t Name::getName() const +{ + return m_Name; +} + +void Name::setName(int32_t value) +{ + m_Name = value; +} + + +int32_t Name::getSnakeCase() const +{ + return m_Snake_case; +} + +void Name::setSnakeCase(int32_t value) +{ + m_Snake_case = value; +} + + +std::string Name::getProperty() const +{ + return m_Property; +} + +void Name::setProperty(std::string value) +{ + m_Property = value; +} + + +int32_t Name::getR123Number() const +{ + return m_r_123Number; +} + +void Name::setR123Number(int32_t value) +{ + m_r_123Number = value; +} + + + +std::vector createNameVectorFromJsonString(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(); + for (const auto& child: pt) { + vec.emplace_back(Name(child.second)); + } + + return vec; +} + +} +} +} +} + diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/model/Name.h b/samples/server/petstore/cpp-restbed/generated/3_0/model/Name.h new file mode 100644 index 00000000000..69f04cd79f1 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/generated/3_0/model/Name.h @@ -0,0 +1,110 @@ +/** + * 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. + */ + +/* + * Name.h + * + * Model for testing model name same as property name + */ + +#ifndef Name_H_ +#define Name_H_ + + + +#include +#include +#include +#include +#include "helpers.h" + +namespace org { +namespace openapitools { +namespace server { +namespace model { + +/// +/// Model for testing model name same as property name +/// +class Name +{ +public: + Name() = default; + explicit Name(boost::property_tree::ptree const& pt); + virtual ~Name() = default; + + Name(const Name& other) = default; // copy constructor + Name(Name&& other) noexcept = default; // move constructor + + Name& operator=(const Name& other) = default; // copy assignment + Name& operator=(Name&& 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); + + + ///////////////////////////////////////////// + /// Name members + + /// + /// + /// + int32_t getName() const; + void setName(int32_t value); + + /// + /// + /// + int32_t getSnakeCase() const; + void setSnakeCase(int32_t value); + + /// + /// + /// + std::string getProperty() const; + void setProperty(std::string value); + + /// + /// + /// + int32_t getR123Number() const; + void setR123Number(int32_t value); + +protected: + int32_t m_Name = 0; + int32_t m_Snake_case = 0; + std::string m_Property = ""; + int32_t m_r_123Number = 0; +}; + +std::vector createNameVectorFromJsonString(const std::string& json); + +template<> +inline boost::property_tree::ptree toPt(const Name& val) { + return val.toPropertyTree(); +} + +template<> +inline Name fromPt(const boost::property_tree::ptree& pt) { + Name ret; + ret.fromPropertyTree(pt); + return ret; +} + +} +} +} +} + +#endif /* Name_H_ */ diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/model/NullableClass.cpp b/samples/server/petstore/cpp-restbed/generated/3_0/model/NullableClass.cpp new file mode 100644 index 00000000000..ec1f0b8fb95 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/generated/3_0/model/NullableClass.cpp @@ -0,0 +1,296 @@ +/** + * 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 "NullableClass.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#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 { + +NullableClass::NullableClass(boost::property_tree::ptree const& pt) +{ + fromPropertyTree(pt); +} + + +std::string NullableClass::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 NullableClass::fromJsonString(std::string const& jsonString) +{ + std::stringstream ss(jsonString); + ptree pt; + read_json(ss,pt); + this->fromPropertyTree(pt); +} + +ptree NullableClass::toPropertyTree() const +{ + ptree pt; + ptree tmp_node; + pt.put("integer_prop", m_Integer_prop); + pt.put("number_prop", m_Number_prop); + pt.put("boolean_prop", m_Boolean_prop); + pt.put("string_prop", m_String_prop); + pt.put("date_prop", m_Date_prop); + pt.put("datetime_prop", m_Datetime_prop); + // generate tree for Array_nullable_prop + tmp_node.clear(); + if (!m_Array_nullable_prop.empty()) { + tmp_node = toPt(m_Array_nullable_prop); + pt.add_child("array_nullable_prop", tmp_node); + tmp_node.clear(); + } + // generate tree for Array_and_items_nullable_prop + tmp_node.clear(); + if (!m_Array_and_items_nullable_prop.empty()) { + tmp_node = toPt(m_Array_and_items_nullable_prop); + pt.add_child("array_and_items_nullable_prop", tmp_node); + tmp_node.clear(); + } + // generate tree for Array_items_nullable + tmp_node.clear(); + if (!m_Array_items_nullable.empty()) { + tmp_node = toPt(m_Array_items_nullable); + pt.add_child("array_items_nullable", tmp_node); + tmp_node.clear(); + } + // generate tree for Object_nullable_prop + if (!m_Object_nullable_prop.empty()) { + tmp_node = toPt(m_Object_nullable_prop); + pt.add_child("object_nullable_prop", tmp_node); + } + tmp_node.clear(); + // generate tree for Object_and_items_nullable_prop + if (!m_Object_and_items_nullable_prop.empty()) { + tmp_node = toPt(m_Object_and_items_nullable_prop); + pt.add_child("object_and_items_nullable_prop", tmp_node); + } + tmp_node.clear(); + // generate tree for Object_items_nullable + if (!m_Object_items_nullable.empty()) { + tmp_node = toPt(m_Object_items_nullable); + pt.add_child("object_items_nullable", tmp_node); + } + tmp_node.clear(); + return pt; +} + +void NullableClass::fromPropertyTree(ptree const &pt) +{ + ptree tmp_node; + m_Integer_prop = pt.get("integer_prop", 0); + m_Number_prop = pt.get("number_prop", 0.0); + m_Boolean_prop = pt.get("boolean_prop", false); + m_String_prop = pt.get("string_prop", ""); + m_Date_prop = pt.get("date_prop", ""); + m_Datetime_prop = pt.get("datetime_prop", ""); + // push all items of Array_nullable_prop into member + if (pt.get_child_optional("array_nullable_prop")) { + m_Array_nullable_prop = fromPt>(pt.get_child("array_nullable_prop")); + } + // push all items of Array_and_items_nullable_prop into member + if (pt.get_child_optional("array_and_items_nullable_prop")) { + m_Array_and_items_nullable_prop = fromPt>(pt.get_child("array_and_items_nullable_prop")); + } + // push all items of Array_items_nullable into member + if (pt.get_child_optional("array_items_nullable")) { + m_Array_items_nullable = fromPt>(pt.get_child("array_items_nullable")); + } + if (pt.get_child_optional("object_nullable_prop")) { + m_Object_nullable_prop = fromPt>(pt.get_child("object_nullable_prop")); + } + if (pt.get_child_optional("object_and_items_nullable_prop")) { + m_Object_and_items_nullable_prop = fromPt>(pt.get_child("object_and_items_nullable_prop")); + } + if (pt.get_child_optional("object_items_nullable")) { + m_Object_items_nullable = fromPt>(pt.get_child("object_items_nullable")); + } +} + +int32_t NullableClass::getIntegerProp() const +{ + return m_Integer_prop; +} + +void NullableClass::setIntegerProp(int32_t value) +{ + m_Integer_prop = value; +} + + +double NullableClass::getNumberProp() const +{ + return m_Number_prop; +} + +void NullableClass::setNumberProp(double value) +{ + m_Number_prop = value; +} + + +bool NullableClass::isBooleanProp() const +{ + return m_Boolean_prop; +} + +void NullableClass::setBooleanProp(bool value) +{ + m_Boolean_prop = value; +} + + +std::string NullableClass::getStringProp() const +{ + return m_String_prop; +} + +void NullableClass::setStringProp(std::string value) +{ + m_String_prop = value; +} + + +std::string NullableClass::getDateProp() const +{ + return m_Date_prop; +} + +void NullableClass::setDateProp(std::string value) +{ + m_Date_prop = value; +} + + +std::string NullableClass::getDatetimeProp() const +{ + return m_Datetime_prop; +} + +void NullableClass::setDatetimeProp(std::string value) +{ + m_Datetime_prop = value; +} + + +std::vector NullableClass::getArrayNullableProp() const +{ + return m_Array_nullable_prop; +} + +void NullableClass::setArrayNullableProp(std::vector value) +{ + m_Array_nullable_prop = value; +} + + +std::vector NullableClass::getArrayAndItemsNullableProp() const +{ + return m_Array_and_items_nullable_prop; +} + +void NullableClass::setArrayAndItemsNullableProp(std::vector value) +{ + m_Array_and_items_nullable_prop = value; +} + + +std::vector NullableClass::getArrayItemsNullable() const +{ + return m_Array_items_nullable; +} + +void NullableClass::setArrayItemsNullable(std::vector value) +{ + m_Array_items_nullable = value; +} + + +std::map NullableClass::getObjectNullableProp() const +{ + return m_Object_nullable_prop; +} + +void NullableClass::setObjectNullableProp(std::map value) +{ + m_Object_nullable_prop = value; +} + + +std::map NullableClass::getObjectAndItemsNullableProp() const +{ + return m_Object_and_items_nullable_prop; +} + +void NullableClass::setObjectAndItemsNullableProp(std::map value) +{ + m_Object_and_items_nullable_prop = value; +} + + +std::map NullableClass::getObjectItemsNullable() const +{ + return m_Object_items_nullable; +} + +void NullableClass::setObjectItemsNullable(std::map value) +{ + m_Object_items_nullable = value; +} + + + +std::vector createNullableClassVectorFromJsonString(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(); + for (const auto& child: pt) { + vec.emplace_back(NullableClass(child.second)); + } + + return vec; +} + +} +} +} +} + diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/model/NullableClass.h b/samples/server/petstore/cpp-restbed/generated/3_0/model/NullableClass.h new file mode 100644 index 00000000000..9babc72b38e --- /dev/null +++ b/samples/server/petstore/cpp-restbed/generated/3_0/model/NullableClass.h @@ -0,0 +1,168 @@ +/** + * 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. + */ + +/* + * NullableClass.h + * + * + */ + +#ifndef NullableClass_H_ +#define NullableClass_H_ + + + +#include +#include +#include +#include +#include +#include +#include "helpers.h" + +namespace org { +namespace openapitools { +namespace server { +namespace model { + +/// +/// +/// +class NullableClass +{ +public: + NullableClass() = default; + explicit NullableClass(boost::property_tree::ptree const& pt); + virtual ~NullableClass() = default; + + NullableClass(const NullableClass& other) = default; // copy constructor + NullableClass(NullableClass&& other) noexcept = default; // move constructor + + NullableClass& operator=(const NullableClass& other) = default; // copy assignment + NullableClass& operator=(NullableClass&& 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); + + + ///////////////////////////////////////////// + /// NullableClass members + + /// + /// + /// + int32_t getIntegerProp() const; + void setIntegerProp(int32_t value); + + /// + /// + /// + double getNumberProp() const; + void setNumberProp(double value); + + /// + /// + /// + bool isBooleanProp() const; + void setBooleanProp(bool value); + + /// + /// + /// + std::string getStringProp() const; + void setStringProp(std::string value); + + /// + /// + /// + std::string getDateProp() const; + void setDateProp(std::string value); + + /// + /// + /// + std::string getDatetimeProp() const; + void setDatetimeProp(std::string value); + + /// + /// + /// + std::vector getArrayNullableProp() const; + void setArrayNullableProp(std::vector value); + + /// + /// + /// + std::vector getArrayAndItemsNullableProp() const; + void setArrayAndItemsNullableProp(std::vector value); + + /// + /// + /// + std::vector getArrayItemsNullable() const; + void setArrayItemsNullable(std::vector value); + + /// + /// + /// + std::map getObjectNullableProp() const; + void setObjectNullableProp(std::map value); + + /// + /// + /// + std::map getObjectAndItemsNullableProp() const; + void setObjectAndItemsNullableProp(std::map value); + + /// + /// + /// + std::map getObjectItemsNullable() const; + void setObjectItemsNullable(std::map value); + +protected: + int32_t m_Integer_prop = 0; + double m_Number_prop = 0.0; + bool m_Boolean_prop = false; + std::string m_String_prop = ""; + std::string m_Date_prop = ""; + std::string m_Datetime_prop = ""; + std::vector m_Array_nullable_prop; + std::vector m_Array_and_items_nullable_prop; + std::vector m_Array_items_nullable; + std::map m_Object_nullable_prop; + std::map m_Object_and_items_nullable_prop; + std::map m_Object_items_nullable; +}; + +std::vector createNullableClassVectorFromJsonString(const std::string& json); + +template<> +inline boost::property_tree::ptree toPt(const NullableClass& val) { + return val.toPropertyTree(); +} + +template<> +inline NullableClass fromPt(const boost::property_tree::ptree& pt) { + NullableClass ret; + ret.fromPropertyTree(pt); + return ret; +} + +} +} +} +} + +#endif /* NullableClass_H_ */ diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/model/NumberOnly.cpp b/samples/server/petstore/cpp-restbed/generated/3_0/model/NumberOnly.cpp new file mode 100644 index 00000000000..d5681a55b81 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/generated/3_0/model/NumberOnly.cpp @@ -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 "NumberOnly.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#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 { + +NumberOnly::NumberOnly(boost::property_tree::ptree const& pt) +{ + fromPropertyTree(pt); +} + + +std::string NumberOnly::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 NumberOnly::fromJsonString(std::string const& jsonString) +{ + std::stringstream ss(jsonString); + ptree pt; + read_json(ss,pt); + this->fromPropertyTree(pt); +} + +ptree NumberOnly::toPropertyTree() const +{ + ptree pt; + ptree tmp_node; + pt.put("JustNumber", m_JustNumber); + return pt; +} + +void NumberOnly::fromPropertyTree(ptree const &pt) +{ + ptree tmp_node; + m_JustNumber = pt.get("JustNumber", 0.0); +} + +double NumberOnly::getJustNumber() const +{ + return m_JustNumber; +} + +void NumberOnly::setJustNumber(double value) +{ + m_JustNumber = value; +} + + + +std::vector createNumberOnlyVectorFromJsonString(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(); + for (const auto& child: pt) { + vec.emplace_back(NumberOnly(child.second)); + } + + return vec; +} + +} +} +} +} + diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/model/NumberOnly.h b/samples/server/petstore/cpp-restbed/generated/3_0/model/NumberOnly.h new file mode 100644 index 00000000000..19fe2c72c17 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/generated/3_0/model/NumberOnly.h @@ -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. + */ + +/* + * NumberOnly.h + * + * + */ + +#ifndef NumberOnly_H_ +#define NumberOnly_H_ + + + +#include +#include +#include +#include "helpers.h" + +namespace org { +namespace openapitools { +namespace server { +namespace model { + +/// +/// +/// +class NumberOnly +{ +public: + NumberOnly() = default; + explicit NumberOnly(boost::property_tree::ptree const& pt); + virtual ~NumberOnly() = default; + + NumberOnly(const NumberOnly& other) = default; // copy constructor + NumberOnly(NumberOnly&& other) noexcept = default; // move constructor + + NumberOnly& operator=(const NumberOnly& other) = default; // copy assignment + NumberOnly& operator=(NumberOnly&& 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); + + + ///////////////////////////////////////////// + /// NumberOnly members + + /// + /// + /// + double getJustNumber() const; + void setJustNumber(double value); + +protected: + double m_JustNumber = 0.0; +}; + +std::vector createNumberOnlyVectorFromJsonString(const std::string& json); + +template<> +inline boost::property_tree::ptree toPt(const NumberOnly& val) { + return val.toPropertyTree(); +} + +template<> +inline NumberOnly fromPt(const boost::property_tree::ptree& pt) { + NumberOnly ret; + ret.fromPropertyTree(pt); + return ret; +} + +} +} +} +} + +#endif /* NumberOnly_H_ */ diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/model/ObjectWithDeprecatedFields.cpp b/samples/server/petstore/cpp-restbed/generated/3_0/model/ObjectWithDeprecatedFields.cpp new file mode 100644 index 00000000000..aab1b5b7612 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/generated/3_0/model/ObjectWithDeprecatedFields.cpp @@ -0,0 +1,155 @@ +/** + * 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 "ObjectWithDeprecatedFields.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#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 { + +ObjectWithDeprecatedFields::ObjectWithDeprecatedFields(boost::property_tree::ptree const& pt) +{ + fromPropertyTree(pt); +} + + +std::string ObjectWithDeprecatedFields::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 ObjectWithDeprecatedFields::fromJsonString(std::string const& jsonString) +{ + std::stringstream ss(jsonString); + ptree pt; + read_json(ss,pt); + this->fromPropertyTree(pt); +} + +ptree ObjectWithDeprecatedFields::toPropertyTree() const +{ + ptree pt; + ptree tmp_node; + pt.put("uuid", m_Uuid); + pt.put("id", m_Id); + pt.add_child("deprecatedRef", m_DeprecatedRef.toPropertyTree()); + // generate tree for Bars + tmp_node.clear(); + if (!m_Bars.empty()) { + tmp_node = toPt(m_Bars); + pt.add_child("bars", tmp_node); + tmp_node.clear(); + } + return pt; +} + +void ObjectWithDeprecatedFields::fromPropertyTree(ptree const &pt) +{ + ptree tmp_node; + m_Uuid = pt.get("uuid", ""); + m_Id = pt.get("id", 0.0); + if (pt.get_child_optional("deprecatedRef")) { + m_DeprecatedRef = fromPt(pt.get_child("deprecatedRef")); + } + // push all items of Bars into member + if (pt.get_child_optional("bars")) { + m_Bars = fromPt>(pt.get_child("bars")); + } +} + +std::string ObjectWithDeprecatedFields::getUuid() const +{ + return m_Uuid; +} + +void ObjectWithDeprecatedFields::setUuid(std::string value) +{ + m_Uuid = value; +} + + +double ObjectWithDeprecatedFields::getId() const +{ + return m_Id; +} + +void ObjectWithDeprecatedFields::setId(double value) +{ + m_Id = value; +} + + +DeprecatedObject ObjectWithDeprecatedFields::getDeprecatedRef() const +{ + return m_DeprecatedRef; +} + +void ObjectWithDeprecatedFields::setDeprecatedRef(DeprecatedObject value) +{ + m_DeprecatedRef = value; +} + + +std::vector ObjectWithDeprecatedFields::getBars() const +{ + return m_Bars; +} + +void ObjectWithDeprecatedFields::setBars(std::vector value) +{ + m_Bars = value; +} + + + +std::vector createObjectWithDeprecatedFieldsVectorFromJsonString(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(); + for (const auto& child: pt) { + vec.emplace_back(ObjectWithDeprecatedFields(child.second)); + } + + return vec; +} + +} +} +} +} + diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/model/ObjectWithDeprecatedFields.h b/samples/server/petstore/cpp-restbed/generated/3_0/model/ObjectWithDeprecatedFields.h new file mode 100644 index 00000000000..2a262b46fee --- /dev/null +++ b/samples/server/petstore/cpp-restbed/generated/3_0/model/ObjectWithDeprecatedFields.h @@ -0,0 +1,112 @@ +/** + * 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. + */ + +/* + * ObjectWithDeprecatedFields.h + * + * + */ + +#ifndef ObjectWithDeprecatedFields_H_ +#define ObjectWithDeprecatedFields_H_ + + + +#include +#include "DeprecatedObject.h" +#include +#include +#include +#include +#include "helpers.h" + +namespace org { +namespace openapitools { +namespace server { +namespace model { + +/// +/// +/// +class ObjectWithDeprecatedFields +{ +public: + ObjectWithDeprecatedFields() = default; + explicit ObjectWithDeprecatedFields(boost::property_tree::ptree const& pt); + virtual ~ObjectWithDeprecatedFields() = default; + + ObjectWithDeprecatedFields(const ObjectWithDeprecatedFields& other) = default; // copy constructor + ObjectWithDeprecatedFields(ObjectWithDeprecatedFields&& other) noexcept = default; // move constructor + + ObjectWithDeprecatedFields& operator=(const ObjectWithDeprecatedFields& other) = default; // copy assignment + ObjectWithDeprecatedFields& operator=(ObjectWithDeprecatedFields&& 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); + + + ///////////////////////////////////////////// + /// ObjectWithDeprecatedFields members + + /// + /// + /// + std::string getUuid() const; + void setUuid(std::string value); + + /// + /// + /// + double getId() const; + void setId(double value); + + /// + /// + /// + DeprecatedObject getDeprecatedRef() const; + void setDeprecatedRef(DeprecatedObject value); + + /// + /// + /// + std::vector getBars() const; + void setBars(std::vector value); + +protected: + std::string m_Uuid = ""; + double m_Id = 0.0; + DeprecatedObject m_DeprecatedRef; + std::vector m_Bars; +}; + +std::vector createObjectWithDeprecatedFieldsVectorFromJsonString(const std::string& json); + +template<> +inline boost::property_tree::ptree toPt(const ObjectWithDeprecatedFields& val) { + return val.toPropertyTree(); +} + +template<> +inline ObjectWithDeprecatedFields fromPt(const boost::property_tree::ptree& pt) { + ObjectWithDeprecatedFields ret; + ret.fromPropertyTree(pt); + return ret; +} + +} +} +} +} + +#endif /* ObjectWithDeprecatedFields_H_ */ diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/model/Order.cpp b/samples/server/petstore/cpp-restbed/generated/3_0/model/Order.cpp new file mode 100644 index 00000000000..963b7d4b0db --- /dev/null +++ b/samples/server/petstore/cpp-restbed/generated/3_0/model/Order.cpp @@ -0,0 +1,179 @@ +/** + * 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 "Order.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#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 { + +Order::Order(boost::property_tree::ptree const& pt) +{ + fromPropertyTree(pt); +} + + +std::string Order::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 Order::fromJsonString(std::string const& jsonString) +{ + std::stringstream ss(jsonString); + ptree pt; + read_json(ss,pt); + this->fromPropertyTree(pt); +} + +ptree Order::toPropertyTree() const +{ + ptree pt; + ptree tmp_node; + pt.put("id", m_Id); + pt.put("petId", m_PetId); + pt.put("quantity", m_Quantity); + pt.put("shipDate", m_ShipDate); + pt.put("status", m_Status); + pt.put("complete", m_Complete); + return pt; +} + +void Order::fromPropertyTree(ptree const &pt) +{ + ptree tmp_node; + m_Id = pt.get("id", 0L); + m_PetId = pt.get("petId", 0L); + m_Quantity = pt.get("quantity", 0); + m_ShipDate = pt.get("shipDate", ""); + setStatus(pt.get("status", "")); + m_Complete = pt.get("complete", false); +} + +int64_t Order::getId() const +{ + return m_Id; +} + +void Order::setId(int64_t value) +{ + m_Id = value; +} + + +int64_t Order::getPetId() const +{ + return m_PetId; +} + +void Order::setPetId(int64_t value) +{ + m_PetId = value; +} + + +int32_t Order::getQuantity() const +{ + return m_Quantity; +} + +void Order::setQuantity(int32_t value) +{ + m_Quantity = value; +} + + +std::string Order::getShipDate() const +{ + return m_ShipDate; +} + +void Order::setShipDate(std::string value) +{ + m_ShipDate = value; +} + + +std::string Order::getStatus() const +{ + return m_Status; +} + +void Order::setStatus(std::string value) +{ + static const std::array allowedValues = { + "placed", "approved", "delivered" + }; + + if (std::find(allowedValues.begin(), allowedValues.end(), value) != allowedValues.end()) { + m_Status = value; + } else { + throw std::runtime_error("Value " + boost::lexical_cast(value) + " not allowed"); + } +} + + +bool Order::isComplete() const +{ + return m_Complete; +} + +void Order::setComplete(bool value) +{ + m_Complete = value; +} + + + +std::vector createOrderVectorFromJsonString(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(); + for (const auto& child: pt) { + vec.emplace_back(Order(child.second)); + } + + return vec; +} + +} +} +} +} + diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/model/Order.h b/samples/server/petstore/cpp-restbed/generated/3_0/model/Order.h new file mode 100644 index 00000000000..c1e9c1902d1 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/generated/3_0/model/Order.h @@ -0,0 +1,125 @@ +/** + * 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. + */ + +/* + * Order.h + * + * + */ + +#ifndef Order_H_ +#define Order_H_ + + + +#include +#include +#include +#include +#include +#include "helpers.h" + +namespace org { +namespace openapitools { +namespace server { +namespace model { + +/// +/// +/// +class Order +{ +public: + Order() = default; + explicit Order(boost::property_tree::ptree const& pt); + virtual ~Order() = default; + + Order(const Order& other) = default; // copy constructor + Order(Order&& other) noexcept = default; // move constructor + + Order& operator=(const Order& other) = default; // copy assignment + Order& operator=(Order&& 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); + + + ///////////////////////////////////////////// + /// Order members + + /// + /// + /// + int64_t getId() const; + void setId(int64_t value); + + /// + /// + /// + int64_t getPetId() const; + void setPetId(int64_t value); + + /// + /// + /// + int32_t getQuantity() const; + void setQuantity(int32_t value); + + /// + /// + /// + std::string getShipDate() const; + void setShipDate(std::string value); + + /// + /// Order Status + /// + std::string getStatus() const; + void setStatus(std::string value); + + /// + /// + /// + bool isComplete() const; + void setComplete(bool value); + +protected: + int64_t m_Id = 0L; + int64_t m_PetId = 0L; + int32_t m_Quantity = 0; + std::string m_ShipDate = ""; + std::string m_Status = ""; + bool m_Complete = false; +}; + +std::vector createOrderVectorFromJsonString(const std::string& json); + +template<> +inline boost::property_tree::ptree toPt(const Order& val) { + return val.toPropertyTree(); +} + +template<> +inline Order fromPt(const boost::property_tree::ptree& pt) { + Order ret; + ret.fromPropertyTree(pt); + return ret; +} + +} +} +} +} + +#endif /* Order_H_ */ diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/model/OuterComposite.cpp b/samples/server/petstore/cpp-restbed/generated/3_0/model/OuterComposite.cpp new file mode 100644 index 00000000000..5cdb9bbfb65 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/generated/3_0/model/OuterComposite.cpp @@ -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 "OuterComposite.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#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 { + +OuterComposite::OuterComposite(boost::property_tree::ptree const& pt) +{ + fromPropertyTree(pt); +} + + +std::string OuterComposite::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 OuterComposite::fromJsonString(std::string const& jsonString) +{ + std::stringstream ss(jsonString); + ptree pt; + read_json(ss,pt); + this->fromPropertyTree(pt); +} + +ptree OuterComposite::toPropertyTree() const +{ + ptree pt; + ptree tmp_node; + pt.put("my_number", m_My_number); + pt.put("my_string", m_My_string); + pt.put("my_boolean", m_My_boolean); + return pt; +} + +void OuterComposite::fromPropertyTree(ptree const &pt) +{ + ptree tmp_node; + m_My_number = pt.get("my_number", 0.0); + m_My_string = pt.get("my_string", ""); + m_My_boolean = pt.get("my_boolean", false); +} + +double OuterComposite::getMyNumber() const +{ + return m_My_number; +} + +void OuterComposite::setMyNumber(double value) +{ + m_My_number = value; +} + + +std::string OuterComposite::getMyString() const +{ + return m_My_string; +} + +void OuterComposite::setMyString(std::string value) +{ + m_My_string = value; +} + + +bool OuterComposite::isMyBoolean() const +{ + return m_My_boolean; +} + +void OuterComposite::setMyBoolean(bool value) +{ + m_My_boolean = value; +} + + + +std::vector createOuterCompositeVectorFromJsonString(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(); + for (const auto& child: pt) { + vec.emplace_back(OuterComposite(child.second)); + } + + return vec; +} + +} +} +} +} + diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/model/OuterComposite.h b/samples/server/petstore/cpp-restbed/generated/3_0/model/OuterComposite.h new file mode 100644 index 00000000000..f2f74cb335f --- /dev/null +++ b/samples/server/petstore/cpp-restbed/generated/3_0/model/OuterComposite.h @@ -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. + */ + +/* + * OuterComposite.h + * + * + */ + +#ifndef OuterComposite_H_ +#define OuterComposite_H_ + + + +#include +#include +#include +#include +#include "helpers.h" + +namespace org { +namespace openapitools { +namespace server { +namespace model { + +/// +/// +/// +class OuterComposite +{ +public: + OuterComposite() = default; + explicit OuterComposite(boost::property_tree::ptree const& pt); + virtual ~OuterComposite() = default; + + OuterComposite(const OuterComposite& other) = default; // copy constructor + OuterComposite(OuterComposite&& other) noexcept = default; // move constructor + + OuterComposite& operator=(const OuterComposite& other) = default; // copy assignment + OuterComposite& operator=(OuterComposite&& 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); + + + ///////////////////////////////////////////// + /// OuterComposite members + + /// + /// + /// + double getMyNumber() const; + void setMyNumber(double value); + + /// + /// + /// + std::string getMyString() const; + void setMyString(std::string value); + + /// + /// + /// + bool isMyBoolean() const; + void setMyBoolean(bool value); + +protected: + double m_My_number = 0.0; + std::string m_My_string = ""; + bool m_My_boolean = false; +}; + +std::vector createOuterCompositeVectorFromJsonString(const std::string& json); + +template<> +inline boost::property_tree::ptree toPt(const OuterComposite& val) { + return val.toPropertyTree(); +} + +template<> +inline OuterComposite fromPt(const boost::property_tree::ptree& pt) { + OuterComposite ret; + ret.fromPropertyTree(pt); + return ret; +} + +} +} +} +} + +#endif /* OuterComposite_H_ */ diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/model/OuterEnum.cpp b/samples/server/petstore/cpp-restbed/generated/3_0/model/OuterEnum.cpp new file mode 100644 index 00000000000..736b9ee19ad --- /dev/null +++ b/samples/server/petstore/cpp-restbed/generated/3_0/model/OuterEnum.cpp @@ -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 "OuterEnum.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#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 { + +OuterEnum::OuterEnum(boost::property_tree::ptree const& pt) +{ + fromPropertyTree(pt); +} + + +std::string OuterEnum::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 OuterEnum::fromJsonString(std::string const& jsonString) +{ + std::stringstream ss(jsonString); + ptree pt; + read_json(ss,pt); + this->fromPropertyTree(pt); +} + +ptree OuterEnum::toPropertyTree() const +{ + ptree pt; + ptree tmp_node; + return pt; +} + +void OuterEnum::fromPropertyTree(ptree const &pt) +{ + ptree tmp_node; +} + +std::string OuterEnum::toString() const { + return boost::lexical_cast(getEnumValue()); +} + +void OuterEnum::fromString(const std::string& str) { + setEnumValue(boost::lexical_cast(str)); +} + +std::string OuterEnum::getEnumValue() const { + return m_OuterEnumEnumValue; +} + +void OuterEnum::setEnumValue(const std::string& val) { + static const std::array allowedValues = { + "placed", "approved", "delivered" + }; + if (std::find(allowedValues.begin(), allowedValues.end(), val) != allowedValues.end()) { + m_OuterEnumEnumValue = val; + } else { + throw std::runtime_error("Value " + boost::lexical_cast(val) + " not allowed"); + } +} + +std::vector createOuterEnumVectorFromJsonString(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(); + for (const auto& child: pt) { + vec.emplace_back(OuterEnum(child.second)); + } + + return vec; +} + +} +} +} +} + diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/model/OuterEnum.h b/samples/server/petstore/cpp-restbed/generated/3_0/model/OuterEnum.h new file mode 100644 index 00000000000..0af9b81b99d --- /dev/null +++ b/samples/server/petstore/cpp-restbed/generated/3_0/model/OuterEnum.h @@ -0,0 +1,86 @@ +/** + * 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. + */ + +/* + * OuterEnum.h + * + * + */ + +#ifndef OuterEnum_H_ +#define OuterEnum_H_ + + + +#include +#include +#include +#include "helpers.h" + +namespace org { +namespace openapitools { +namespace server { +namespace model { + +/// +/// +/// +class OuterEnum +{ +public: + OuterEnum() = default; + explicit OuterEnum(boost::property_tree::ptree const& pt); + virtual ~OuterEnum() = default; + + OuterEnum(const OuterEnum& other) = default; // copy constructor + OuterEnum(OuterEnum&& other) noexcept = default; // move constructor + + OuterEnum& operator=(const OuterEnum& other) = default; // copy assignment + OuterEnum& operator=(OuterEnum&& 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); + + std::string toString() const; + void fromString(const std::string& str); + + ///////////////////////////////////////////// + /// OuterEnum members + std::string getEnumValue() const; + void setEnumValue(const std::string& val); + +protected: + std::string m_OuterEnumEnumValue; +}; + +std::vector createOuterEnumVectorFromJsonString(const std::string& json); + +template<> +inline boost::property_tree::ptree toPt(const OuterEnum& val) { + return val.toPropertyTree(); +} + +template<> +inline OuterEnum fromPt(const boost::property_tree::ptree& pt) { + OuterEnum ret; + ret.fromPropertyTree(pt); + return ret; +} + +} +} +} +} + +#endif /* OuterEnum_H_ */ diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/model/OuterEnumDefaultValue.cpp b/samples/server/petstore/cpp-restbed/generated/3_0/model/OuterEnumDefaultValue.cpp new file mode 100644 index 00000000000..8d9315737e8 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/generated/3_0/model/OuterEnumDefaultValue.cpp @@ -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 "OuterEnumDefaultValue.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#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 { + +OuterEnumDefaultValue::OuterEnumDefaultValue(boost::property_tree::ptree const& pt) +{ + fromPropertyTree(pt); +} + + +std::string OuterEnumDefaultValue::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 OuterEnumDefaultValue::fromJsonString(std::string const& jsonString) +{ + std::stringstream ss(jsonString); + ptree pt; + read_json(ss,pt); + this->fromPropertyTree(pt); +} + +ptree OuterEnumDefaultValue::toPropertyTree() const +{ + ptree pt; + ptree tmp_node; + return pt; +} + +void OuterEnumDefaultValue::fromPropertyTree(ptree const &pt) +{ + ptree tmp_node; +} + +std::string OuterEnumDefaultValue::toString() const { + return boost::lexical_cast(getEnumValue()); +} + +void OuterEnumDefaultValue::fromString(const std::string& str) { + setEnumValue(boost::lexical_cast(str)); +} + +std::string OuterEnumDefaultValue::getEnumValue() const { + return m_OuterEnumDefaultValueEnumValue; +} + +void OuterEnumDefaultValue::setEnumValue(const std::string& val) { + static const std::array allowedValues = { + "placed", "approved", "delivered" + }; + if (std::find(allowedValues.begin(), allowedValues.end(), val) != allowedValues.end()) { + m_OuterEnumDefaultValueEnumValue = val; + } else { + throw std::runtime_error("Value " + boost::lexical_cast(val) + " not allowed"); + } +} + +std::vector createOuterEnumDefaultValueVectorFromJsonString(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(); + for (const auto& child: pt) { + vec.emplace_back(OuterEnumDefaultValue(child.second)); + } + + return vec; +} + +} +} +} +} + diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/model/OuterEnumDefaultValue.h b/samples/server/petstore/cpp-restbed/generated/3_0/model/OuterEnumDefaultValue.h new file mode 100644 index 00000000000..08861af9ca4 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/generated/3_0/model/OuterEnumDefaultValue.h @@ -0,0 +1,86 @@ +/** + * 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. + */ + +/* + * OuterEnumDefaultValue.h + * + * + */ + +#ifndef OuterEnumDefaultValue_H_ +#define OuterEnumDefaultValue_H_ + + + +#include +#include +#include +#include "helpers.h" + +namespace org { +namespace openapitools { +namespace server { +namespace model { + +/// +/// +/// +class OuterEnumDefaultValue +{ +public: + OuterEnumDefaultValue() = default; + explicit OuterEnumDefaultValue(boost::property_tree::ptree const& pt); + virtual ~OuterEnumDefaultValue() = default; + + OuterEnumDefaultValue(const OuterEnumDefaultValue& other) = default; // copy constructor + OuterEnumDefaultValue(OuterEnumDefaultValue&& other) noexcept = default; // move constructor + + OuterEnumDefaultValue& operator=(const OuterEnumDefaultValue& other) = default; // copy assignment + OuterEnumDefaultValue& operator=(OuterEnumDefaultValue&& 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); + + std::string toString() const; + void fromString(const std::string& str); + + ///////////////////////////////////////////// + /// OuterEnumDefaultValue members + std::string getEnumValue() const; + void setEnumValue(const std::string& val); + +protected: + std::string m_OuterEnumDefaultValueEnumValue; +}; + +std::vector createOuterEnumDefaultValueVectorFromJsonString(const std::string& json); + +template<> +inline boost::property_tree::ptree toPt(const OuterEnumDefaultValue& val) { + return val.toPropertyTree(); +} + +template<> +inline OuterEnumDefaultValue fromPt(const boost::property_tree::ptree& pt) { + OuterEnumDefaultValue ret; + ret.fromPropertyTree(pt); + return ret; +} + +} +} +} +} + +#endif /* OuterEnumDefaultValue_H_ */ diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/model/OuterEnumInteger.cpp b/samples/server/petstore/cpp-restbed/generated/3_0/model/OuterEnumInteger.cpp new file mode 100644 index 00000000000..c56782e5351 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/generated/3_0/model/OuterEnumInteger.cpp @@ -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 "OuterEnumInteger.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#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 { + +OuterEnumInteger::OuterEnumInteger(boost::property_tree::ptree const& pt) +{ + fromPropertyTree(pt); +} + + +std::string OuterEnumInteger::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 OuterEnumInteger::fromJsonString(std::string const& jsonString) +{ + std::stringstream ss(jsonString); + ptree pt; + read_json(ss,pt); + this->fromPropertyTree(pt); +} + +ptree OuterEnumInteger::toPropertyTree() const +{ + ptree pt; + ptree tmp_node; + return pt; +} + +void OuterEnumInteger::fromPropertyTree(ptree const &pt) +{ + ptree tmp_node; +} + +std::string OuterEnumInteger::toString() const { + return boost::lexical_cast(getEnumValue()); +} + +void OuterEnumInteger::fromString(const std::string& str) { + setEnumValue(boost::lexical_cast(str)); +} + +int32_t OuterEnumInteger::getEnumValue() const { + return m_OuterEnumIntegerEnumValue; +} + +void OuterEnumInteger::setEnumValue(const int32_t& val) { + static const std::array allowedValues = { + 0, 1, 2 + }; + if (std::find(allowedValues.begin(), allowedValues.end(), val) != allowedValues.end()) { + m_OuterEnumIntegerEnumValue = val; + } else { + throw std::runtime_error("Value " + boost::lexical_cast(val) + " not allowed"); + } +} + +std::vector createOuterEnumIntegerVectorFromJsonString(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(); + for (const auto& child: pt) { + vec.emplace_back(OuterEnumInteger(child.second)); + } + + return vec; +} + +} +} +} +} + diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/model/OuterEnumInteger.h b/samples/server/petstore/cpp-restbed/generated/3_0/model/OuterEnumInteger.h new file mode 100644 index 00000000000..cb0a77c18bf --- /dev/null +++ b/samples/server/petstore/cpp-restbed/generated/3_0/model/OuterEnumInteger.h @@ -0,0 +1,86 @@ +/** + * 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. + */ + +/* + * OuterEnumInteger.h + * + * + */ + +#ifndef OuterEnumInteger_H_ +#define OuterEnumInteger_H_ + + + +#include +#include +#include +#include "helpers.h" + +namespace org { +namespace openapitools { +namespace server { +namespace model { + +/// +/// +/// +class OuterEnumInteger +{ +public: + OuterEnumInteger() = default; + explicit OuterEnumInteger(boost::property_tree::ptree const& pt); + virtual ~OuterEnumInteger() = default; + + OuterEnumInteger(const OuterEnumInteger& other) = default; // copy constructor + OuterEnumInteger(OuterEnumInteger&& other) noexcept = default; // move constructor + + OuterEnumInteger& operator=(const OuterEnumInteger& other) = default; // copy assignment + OuterEnumInteger& operator=(OuterEnumInteger&& 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); + + std::string toString() const; + void fromString(const std::string& str); + + ///////////////////////////////////////////// + /// OuterEnumInteger members + int32_t getEnumValue() const; + void setEnumValue(const int32_t& val); + +protected: + int32_t m_OuterEnumIntegerEnumValue; +}; + +std::vector createOuterEnumIntegerVectorFromJsonString(const std::string& json); + +template<> +inline boost::property_tree::ptree toPt(const OuterEnumInteger& val) { + return val.toPropertyTree(); +} + +template<> +inline OuterEnumInteger fromPt(const boost::property_tree::ptree& pt) { + OuterEnumInteger ret; + ret.fromPropertyTree(pt); + return ret; +} + +} +} +} +} + +#endif /* OuterEnumInteger_H_ */ diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/model/OuterEnumIntegerDefaultValue.cpp b/samples/server/petstore/cpp-restbed/generated/3_0/model/OuterEnumIntegerDefaultValue.cpp new file mode 100644 index 00000000000..dfcef0d19f9 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/generated/3_0/model/OuterEnumIntegerDefaultValue.cpp @@ -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 "OuterEnumIntegerDefaultValue.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#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 { + +OuterEnumIntegerDefaultValue::OuterEnumIntegerDefaultValue(boost::property_tree::ptree const& pt) +{ + fromPropertyTree(pt); +} + + +std::string OuterEnumIntegerDefaultValue::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 OuterEnumIntegerDefaultValue::fromJsonString(std::string const& jsonString) +{ + std::stringstream ss(jsonString); + ptree pt; + read_json(ss,pt); + this->fromPropertyTree(pt); +} + +ptree OuterEnumIntegerDefaultValue::toPropertyTree() const +{ + ptree pt; + ptree tmp_node; + return pt; +} + +void OuterEnumIntegerDefaultValue::fromPropertyTree(ptree const &pt) +{ + ptree tmp_node; +} + +std::string OuterEnumIntegerDefaultValue::toString() const { + return boost::lexical_cast(getEnumValue()); +} + +void OuterEnumIntegerDefaultValue::fromString(const std::string& str) { + setEnumValue(boost::lexical_cast(str)); +} + +int32_t OuterEnumIntegerDefaultValue::getEnumValue() const { + return m_OuterEnumIntegerDefaultValueEnumValue; +} + +void OuterEnumIntegerDefaultValue::setEnumValue(const int32_t& val) { + static const std::array allowedValues = { + 0, 1, 2 + }; + if (std::find(allowedValues.begin(), allowedValues.end(), val) != allowedValues.end()) { + m_OuterEnumIntegerDefaultValueEnumValue = val; + } else { + throw std::runtime_error("Value " + boost::lexical_cast(val) + " not allowed"); + } +} + +std::vector createOuterEnumIntegerDefaultValueVectorFromJsonString(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(); + for (const auto& child: pt) { + vec.emplace_back(OuterEnumIntegerDefaultValue(child.second)); + } + + return vec; +} + +} +} +} +} + diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/model/OuterEnumIntegerDefaultValue.h b/samples/server/petstore/cpp-restbed/generated/3_0/model/OuterEnumIntegerDefaultValue.h new file mode 100644 index 00000000000..98597d5229e --- /dev/null +++ b/samples/server/petstore/cpp-restbed/generated/3_0/model/OuterEnumIntegerDefaultValue.h @@ -0,0 +1,86 @@ +/** + * 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. + */ + +/* + * OuterEnumIntegerDefaultValue.h + * + * + */ + +#ifndef OuterEnumIntegerDefaultValue_H_ +#define OuterEnumIntegerDefaultValue_H_ + + + +#include +#include +#include +#include "helpers.h" + +namespace org { +namespace openapitools { +namespace server { +namespace model { + +/// +/// +/// +class OuterEnumIntegerDefaultValue +{ +public: + OuterEnumIntegerDefaultValue() = default; + explicit OuterEnumIntegerDefaultValue(boost::property_tree::ptree const& pt); + virtual ~OuterEnumIntegerDefaultValue() = default; + + OuterEnumIntegerDefaultValue(const OuterEnumIntegerDefaultValue& other) = default; // copy constructor + OuterEnumIntegerDefaultValue(OuterEnumIntegerDefaultValue&& other) noexcept = default; // move constructor + + OuterEnumIntegerDefaultValue& operator=(const OuterEnumIntegerDefaultValue& other) = default; // copy assignment + OuterEnumIntegerDefaultValue& operator=(OuterEnumIntegerDefaultValue&& 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); + + std::string toString() const; + void fromString(const std::string& str); + + ///////////////////////////////////////////// + /// OuterEnumIntegerDefaultValue members + int32_t getEnumValue() const; + void setEnumValue(const int32_t& val); + +protected: + int32_t m_OuterEnumIntegerDefaultValueEnumValue; +}; + +std::vector createOuterEnumIntegerDefaultValueVectorFromJsonString(const std::string& json); + +template<> +inline boost::property_tree::ptree toPt(const OuterEnumIntegerDefaultValue& val) { + return val.toPropertyTree(); +} + +template<> +inline OuterEnumIntegerDefaultValue fromPt(const boost::property_tree::ptree& pt) { + OuterEnumIntegerDefaultValue ret; + ret.fromPropertyTree(pt); + return ret; +} + +} +} +} +} + +#endif /* OuterEnumIntegerDefaultValue_H_ */ diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/model/OuterObjectWithEnumProperty.cpp b/samples/server/petstore/cpp-restbed/generated/3_0/model/OuterObjectWithEnumProperty.cpp new file mode 100644 index 00000000000..f3c4bd4098e --- /dev/null +++ b/samples/server/petstore/cpp-restbed/generated/3_0/model/OuterObjectWithEnumProperty.cpp @@ -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. + */ + + + +#include "OuterObjectWithEnumProperty.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#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 { + +OuterObjectWithEnumProperty::OuterObjectWithEnumProperty(boost::property_tree::ptree const& pt) +{ + fromPropertyTree(pt); +} + + +std::string OuterObjectWithEnumProperty::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 OuterObjectWithEnumProperty::fromJsonString(std::string const& jsonString) +{ + std::stringstream ss(jsonString); + ptree pt; + read_json(ss,pt); + this->fromPropertyTree(pt); +} + +ptree OuterObjectWithEnumProperty::toPropertyTree() const +{ + ptree pt; + ptree tmp_node; + return pt; +} + +void OuterObjectWithEnumProperty::fromPropertyTree(ptree const &pt) +{ + ptree tmp_node; +} + +OuterEnumInteger OuterObjectWithEnumProperty::getValue() const +{ + return m_Value; +} + +void OuterObjectWithEnumProperty::setValue(OuterEnumInteger value) +{ + m_Value = value; +} + + + +std::vector createOuterObjectWithEnumPropertyVectorFromJsonString(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(); + for (const auto& child: pt) { + vec.emplace_back(OuterObjectWithEnumProperty(child.second)); + } + + return vec; +} + +} +} +} +} + diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/model/OuterObjectWithEnumProperty.h b/samples/server/petstore/cpp-restbed/generated/3_0/model/OuterObjectWithEnumProperty.h new file mode 100644 index 00000000000..79a3a6b7274 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/generated/3_0/model/OuterObjectWithEnumProperty.h @@ -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. + */ + +/* + * OuterObjectWithEnumProperty.h + * + * + */ + +#ifndef OuterObjectWithEnumProperty_H_ +#define OuterObjectWithEnumProperty_H_ + + + +#include "OuterEnumInteger.h" +#include +#include +#include +#include "helpers.h" + +namespace org { +namespace openapitools { +namespace server { +namespace model { + +/// +/// +/// +class OuterObjectWithEnumProperty +{ +public: + OuterObjectWithEnumProperty() = default; + explicit OuterObjectWithEnumProperty(boost::property_tree::ptree const& pt); + virtual ~OuterObjectWithEnumProperty() = default; + + OuterObjectWithEnumProperty(const OuterObjectWithEnumProperty& other) = default; // copy constructor + OuterObjectWithEnumProperty(OuterObjectWithEnumProperty&& other) noexcept = default; // move constructor + + OuterObjectWithEnumProperty& operator=(const OuterObjectWithEnumProperty& other) = default; // copy assignment + OuterObjectWithEnumProperty& operator=(OuterObjectWithEnumProperty&& 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); + + + ///////////////////////////////////////////// + /// OuterObjectWithEnumProperty members + + /// + /// + /// + OuterEnumInteger getValue() const; + void setValue(OuterEnumInteger value); + +protected: + OuterEnumInteger m_Value = OuterEnumInteger{}; +}; + +std::vector createOuterObjectWithEnumPropertyVectorFromJsonString(const std::string& json); + +template<> +inline boost::property_tree::ptree toPt(const OuterObjectWithEnumProperty& val) { + return val.toPropertyTree(); +} + +template<> +inline OuterObjectWithEnumProperty fromPt(const boost::property_tree::ptree& pt) { + OuterObjectWithEnumProperty ret; + ret.fromPropertyTree(pt); + return ret; +} + +} +} +} +} + +#endif /* OuterObjectWithEnumProperty_H_ */ diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/model/Pet.cpp b/samples/server/petstore/cpp-restbed/generated/3_0/model/Pet.cpp new file mode 100644 index 00000000000..1f7a01feeb0 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/generated/3_0/model/Pet.cpp @@ -0,0 +1,199 @@ +/** + * 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 "Pet.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#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 { + +Pet::Pet(boost::property_tree::ptree const& pt) +{ + fromPropertyTree(pt); +} + + +std::string Pet::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 Pet::fromJsonString(std::string const& jsonString) +{ + std::stringstream ss(jsonString); + ptree pt; + read_json(ss,pt); + this->fromPropertyTree(pt); +} + +ptree Pet::toPropertyTree() const +{ + ptree pt; + ptree tmp_node; + pt.put("id", m_Id); + pt.add_child("category", m_Category.toPropertyTree()); + pt.put("name", m_Name); + // generate tree for PhotoUrls + tmp_node.clear(); + if (!m_PhotoUrls.empty()) { + tmp_node = toPt(m_PhotoUrls); + pt.add_child("photoUrls", tmp_node); + tmp_node.clear(); + } + // generate tree for Tags + tmp_node.clear(); + if (!m_Tags.empty()) { + tmp_node = toPt(m_Tags); + pt.add_child("tags", tmp_node); + tmp_node.clear(); + } + pt.put("status", m_Status); + return pt; +} + +void Pet::fromPropertyTree(ptree const &pt) +{ + ptree tmp_node; + m_Id = pt.get("id", 0L); + if (pt.get_child_optional("category")) { + m_Category = fromPt(pt.get_child("category")); + } + m_Name = pt.get("name", ""); + // push all items of PhotoUrls into member + if (pt.get_child_optional("photoUrls")) { + m_PhotoUrls = fromPt>(pt.get_child("photoUrls")); + } + // push all items of Tags into member + if (pt.get_child_optional("tags")) { + m_Tags = fromPt>(pt.get_child("tags")); + } + setStatus(pt.get("status", "")); +} + +int64_t Pet::getId() const +{ + return m_Id; +} + +void Pet::setId(int64_t value) +{ + m_Id = value; +} + + +Category Pet::getCategory() const +{ + return m_Category; +} + +void Pet::setCategory(Category value) +{ + m_Category = value; +} + + +std::string Pet::getName() const +{ + return m_Name; +} + +void Pet::setName(std::string value) +{ + m_Name = value; +} + + +std::set Pet::getPhotoUrls() const +{ + return m_PhotoUrls; +} + +void Pet::setPhotoUrls(std::set value) +{ + m_PhotoUrls = value; +} + + +std::vector Pet::getTags() const +{ + return m_Tags; +} + +void Pet::setTags(std::vector value) +{ + m_Tags = value; +} + + +std::string Pet::getStatus() const +{ + return m_Status; +} + +void Pet::setStatus(std::string value) +{ + static const std::array allowedValues = { + "available", "pending", "sold" + }; + + if (std::find(allowedValues.begin(), allowedValues.end(), value) != allowedValues.end()) { + m_Status = value; + } else { + throw std::runtime_error("Value " + boost::lexical_cast(value) + " not allowed"); + } +} + + + +std::vector createPetVectorFromJsonString(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(); + for (const auto& child: pt) { + vec.emplace_back(Pet(child.second)); + } + + return vec; +} + +} +} +} +} + diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/model/Pet.h b/samples/server/petstore/cpp-restbed/generated/3_0/model/Pet.h new file mode 100644 index 00000000000..2fc33d0c1ac --- /dev/null +++ b/samples/server/petstore/cpp-restbed/generated/3_0/model/Pet.h @@ -0,0 +1,129 @@ +/** + * 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. + */ + +/* + * Pet.h + * + * + */ + +#ifndef Pet_H_ +#define Pet_H_ + + + +#include "Tag.h" +#include +#include "Category.h" +#include +#include +#include +#include +#include +#include +#include "helpers.h" + +namespace org { +namespace openapitools { +namespace server { +namespace model { + +/// +/// +/// +class Pet +{ +public: + Pet() = default; + explicit Pet(boost::property_tree::ptree const& pt); + virtual ~Pet() = default; + + Pet(const Pet& other) = default; // copy constructor + Pet(Pet&& other) noexcept = default; // move constructor + + Pet& operator=(const Pet& other) = default; // copy assignment + Pet& operator=(Pet&& 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); + + + ///////////////////////////////////////////// + /// Pet members + + /// + /// + /// + int64_t getId() const; + void setId(int64_t value); + + /// + /// + /// + Category getCategory() const; + void setCategory(Category value); + + /// + /// + /// + std::string getName() const; + void setName(std::string value); + + /// + /// + /// + std::set getPhotoUrls() const; + void setPhotoUrls(std::set value); + + /// + /// + /// + std::vector getTags() const; + void setTags(std::vector value); + + /// + /// pet status in the store + /// + std::string getStatus() const; + void setStatus(std::string value); + +protected: + int64_t m_Id = 0L; + Category m_Category; + std::string m_Name = ""; + std::set m_PhotoUrls; + std::vector m_Tags; + std::string m_Status = ""; +}; + +std::vector createPetVectorFromJsonString(const std::string& json); + +template<> +inline boost::property_tree::ptree toPt(const Pet& val) { + return val.toPropertyTree(); +} + +template<> +inline Pet fromPt(const boost::property_tree::ptree& pt) { + Pet ret; + ret.fromPropertyTree(pt); + return ret; +} + +} +} +} +} + +#endif /* Pet_H_ */ diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/model/ReadOnlyFirst.cpp b/samples/server/petstore/cpp-restbed/generated/3_0/model/ReadOnlyFirst.cpp new file mode 100644 index 00000000000..d17debded35 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/generated/3_0/model/ReadOnlyFirst.cpp @@ -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 "ReadOnlyFirst.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#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 { + +ReadOnlyFirst::ReadOnlyFirst(boost::property_tree::ptree const& pt) +{ + fromPropertyTree(pt); +} + + +std::string ReadOnlyFirst::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 ReadOnlyFirst::fromJsonString(std::string const& jsonString) +{ + std::stringstream ss(jsonString); + ptree pt; + read_json(ss,pt); + this->fromPropertyTree(pt); +} + +ptree ReadOnlyFirst::toPropertyTree() const +{ + ptree pt; + ptree tmp_node; + pt.put("bar", m_Bar); + pt.put("baz", m_Baz); + return pt; +} + +void ReadOnlyFirst::fromPropertyTree(ptree const &pt) +{ + ptree tmp_node; + m_Bar = pt.get("bar", ""); + m_Baz = pt.get("baz", ""); +} + +std::string ReadOnlyFirst::getBar() const +{ + return m_Bar; +} + +void ReadOnlyFirst::setBar(std::string value) +{ + m_Bar = value; +} + + +std::string ReadOnlyFirst::getBaz() const +{ + return m_Baz; +} + +void ReadOnlyFirst::setBaz(std::string value) +{ + m_Baz = value; +} + + + +std::vector createReadOnlyFirstVectorFromJsonString(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(); + for (const auto& child: pt) { + vec.emplace_back(ReadOnlyFirst(child.second)); + } + + return vec; +} + +} +} +} +} + diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/model/ReadOnlyFirst.h b/samples/server/petstore/cpp-restbed/generated/3_0/model/ReadOnlyFirst.h new file mode 100644 index 00000000000..1b416dadc60 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/generated/3_0/model/ReadOnlyFirst.h @@ -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. + */ + +/* + * ReadOnlyFirst.h + * + * + */ + +#ifndef ReadOnlyFirst_H_ +#define ReadOnlyFirst_H_ + + + +#include +#include +#include +#include +#include "helpers.h" + +namespace org { +namespace openapitools { +namespace server { +namespace model { + +/// +/// +/// +class ReadOnlyFirst +{ +public: + ReadOnlyFirst() = default; + explicit ReadOnlyFirst(boost::property_tree::ptree const& pt); + virtual ~ReadOnlyFirst() = default; + + ReadOnlyFirst(const ReadOnlyFirst& other) = default; // copy constructor + ReadOnlyFirst(ReadOnlyFirst&& other) noexcept = default; // move constructor + + ReadOnlyFirst& operator=(const ReadOnlyFirst& other) = default; // copy assignment + ReadOnlyFirst& operator=(ReadOnlyFirst&& 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); + + + ///////////////////////////////////////////// + /// ReadOnlyFirst members + + /// + /// + /// + std::string getBar() const; + void setBar(std::string value); + + /// + /// + /// + std::string getBaz() const; + void setBaz(std::string value); + +protected: + std::string m_Bar = ""; + std::string m_Baz = ""; +}; + +std::vector createReadOnlyFirstVectorFromJsonString(const std::string& json); + +template<> +inline boost::property_tree::ptree toPt(const ReadOnlyFirst& val) { + return val.toPropertyTree(); +} + +template<> +inline ReadOnlyFirst fromPt(const boost::property_tree::ptree& pt) { + ReadOnlyFirst ret; + ret.fromPropertyTree(pt); + return ret; +} + +} +} +} +} + +#endif /* ReadOnlyFirst_H_ */ diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/model/Return.cpp b/samples/server/petstore/cpp-restbed/generated/3_0/model/Return.cpp new file mode 100644 index 00000000000..6332ef30fc7 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/generated/3_0/model/Return.cpp @@ -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 "Return.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#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 { + +Return::Return(boost::property_tree::ptree const& pt) +{ + fromPropertyTree(pt); +} + + +std::string Return::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 Return::fromJsonString(std::string const& jsonString) +{ + std::stringstream ss(jsonString); + ptree pt; + read_json(ss,pt); + this->fromPropertyTree(pt); +} + +ptree Return::toPropertyTree() const +{ + ptree pt; + ptree tmp_node; + pt.put("return", m_r_return); + return pt; +} + +void Return::fromPropertyTree(ptree const &pt) +{ + ptree tmp_node; + m_r_return = pt.get("return", 0); +} + +int32_t Return::getRReturn() const +{ + return m_r_return; +} + +void Return::setRReturn(int32_t value) +{ + m_r_return = value; +} + + + +std::vector createReturnVectorFromJsonString(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(); + for (const auto& child: pt) { + vec.emplace_back(Return(child.second)); + } + + return vec; +} + +} +} +} +} + diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/model/Return.h b/samples/server/petstore/cpp-restbed/generated/3_0/model/Return.h new file mode 100644 index 00000000000..e57ee29a4f8 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/generated/3_0/model/Return.h @@ -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. + */ + +/* + * Return.h + * + * Model for testing reserved words + */ + +#ifndef Return_H_ +#define Return_H_ + + + +#include +#include +#include +#include "helpers.h" + +namespace org { +namespace openapitools { +namespace server { +namespace model { + +/// +/// Model for testing reserved words +/// +class Return +{ +public: + Return() = default; + explicit Return(boost::property_tree::ptree const& pt); + virtual ~Return() = default; + + Return(const Return& other) = default; // copy constructor + Return(Return&& other) noexcept = default; // move constructor + + Return& operator=(const Return& other) = default; // copy assignment + Return& operator=(Return&& 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); + + + ///////////////////////////////////////////// + /// Return members + + /// + /// + /// + int32_t getRReturn() const; + void setRReturn(int32_t value); + +protected: + int32_t m_r_return = 0; +}; + +std::vector createReturnVectorFromJsonString(const std::string& json); + +template<> +inline boost::property_tree::ptree toPt(const Return& val) { + return val.toPropertyTree(); +} + +template<> +inline Return fromPt(const boost::property_tree::ptree& pt) { + Return ret; + ret.fromPropertyTree(pt); + return ret; +} + +} +} +} +} + +#endif /* Return_H_ */ diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/model/SingleRefType.cpp b/samples/server/petstore/cpp-restbed/generated/3_0/model/SingleRefType.cpp new file mode 100644 index 00000000000..bfe5abd1cdb --- /dev/null +++ b/samples/server/petstore/cpp-restbed/generated/3_0/model/SingleRefType.cpp @@ -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 "SingleRefType.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#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 { + +SingleRefType::SingleRefType(boost::property_tree::ptree const& pt) +{ + fromPropertyTree(pt); +} + + +std::string SingleRefType::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 SingleRefType::fromJsonString(std::string const& jsonString) +{ + std::stringstream ss(jsonString); + ptree pt; + read_json(ss,pt); + this->fromPropertyTree(pt); +} + +ptree SingleRefType::toPropertyTree() const +{ + ptree pt; + ptree tmp_node; + return pt; +} + +void SingleRefType::fromPropertyTree(ptree const &pt) +{ + ptree tmp_node; +} + +std::string SingleRefType::toString() const { + return boost::lexical_cast(getEnumValue()); +} + +void SingleRefType::fromString(const std::string& str) { + setEnumValue(boost::lexical_cast(str)); +} + +std::string SingleRefType::getEnumValue() const { + return m_SingleRefTypeEnumValue; +} + +void SingleRefType::setEnumValue(const std::string& val) { + static const std::array allowedValues = { + "admin", "user" + }; + if (std::find(allowedValues.begin(), allowedValues.end(), val) != allowedValues.end()) { + m_SingleRefTypeEnumValue = val; + } else { + throw std::runtime_error("Value " + boost::lexical_cast(val) + " not allowed"); + } +} + +std::vector createSingleRefTypeVectorFromJsonString(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(); + for (const auto& child: pt) { + vec.emplace_back(SingleRefType(child.second)); + } + + return vec; +} + +} +} +} +} + diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/model/SingleRefType.h b/samples/server/petstore/cpp-restbed/generated/3_0/model/SingleRefType.h new file mode 100644 index 00000000000..8162686fc02 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/generated/3_0/model/SingleRefType.h @@ -0,0 +1,86 @@ +/** + * 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. + */ + +/* + * SingleRefType.h + * + * + */ + +#ifndef SingleRefType_H_ +#define SingleRefType_H_ + + + +#include +#include +#include +#include "helpers.h" + +namespace org { +namespace openapitools { +namespace server { +namespace model { + +/// +/// +/// +class SingleRefType +{ +public: + SingleRefType() = default; + explicit SingleRefType(boost::property_tree::ptree const& pt); + virtual ~SingleRefType() = default; + + SingleRefType(const SingleRefType& other) = default; // copy constructor + SingleRefType(SingleRefType&& other) noexcept = default; // move constructor + + SingleRefType& operator=(const SingleRefType& other) = default; // copy assignment + SingleRefType& operator=(SingleRefType&& 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); + + std::string toString() const; + void fromString(const std::string& str); + + ///////////////////////////////////////////// + /// SingleRefType members + std::string getEnumValue() const; + void setEnumValue(const std::string& val); + +protected: + std::string m_SingleRefTypeEnumValue; +}; + +std::vector createSingleRefTypeVectorFromJsonString(const std::string& json); + +template<> +inline boost::property_tree::ptree toPt(const SingleRefType& val) { + return val.toPropertyTree(); +} + +template<> +inline SingleRefType fromPt(const boost::property_tree::ptree& pt) { + SingleRefType ret; + ret.fromPropertyTree(pt); + return ret; +} + +} +} +} +} + +#endif /* SingleRefType_H_ */ diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/model/Tag.cpp b/samples/server/petstore/cpp-restbed/generated/3_0/model/Tag.cpp new file mode 100644 index 00000000000..44ab7a2c97f --- /dev/null +++ b/samples/server/petstore/cpp-restbed/generated/3_0/model/Tag.cpp @@ -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 "Tag.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#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 { + +Tag::Tag(boost::property_tree::ptree const& pt) +{ + fromPropertyTree(pt); +} + + +std::string Tag::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 Tag::fromJsonString(std::string const& jsonString) +{ + std::stringstream ss(jsonString); + ptree pt; + read_json(ss,pt); + this->fromPropertyTree(pt); +} + +ptree Tag::toPropertyTree() const +{ + ptree pt; + ptree tmp_node; + pt.put("id", m_Id); + pt.put("name", m_Name); + return pt; +} + +void Tag::fromPropertyTree(ptree const &pt) +{ + ptree tmp_node; + m_Id = pt.get("id", 0L); + m_Name = pt.get("name", ""); +} + +int64_t Tag::getId() const +{ + return m_Id; +} + +void Tag::setId(int64_t value) +{ + m_Id = value; +} + + +std::string Tag::getName() const +{ + return m_Name; +} + +void Tag::setName(std::string value) +{ + m_Name = value; +} + + + +std::vector createTagVectorFromJsonString(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(); + for (const auto& child: pt) { + vec.emplace_back(Tag(child.second)); + } + + return vec; +} + +} +} +} +} + diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/model/Tag.h b/samples/server/petstore/cpp-restbed/generated/3_0/model/Tag.h new file mode 100644 index 00000000000..e6ba3ee96c1 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/generated/3_0/model/Tag.h @@ -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. + */ + +/* + * Tag.h + * + * + */ + +#ifndef Tag_H_ +#define Tag_H_ + + + +#include +#include +#include +#include +#include "helpers.h" + +namespace org { +namespace openapitools { +namespace server { +namespace model { + +/// +/// +/// +class Tag +{ +public: + Tag() = default; + explicit Tag(boost::property_tree::ptree const& pt); + virtual ~Tag() = default; + + Tag(const Tag& other) = default; // copy constructor + Tag(Tag&& other) noexcept = default; // move constructor + + Tag& operator=(const Tag& other) = default; // copy assignment + Tag& operator=(Tag&& 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); + + + ///////////////////////////////////////////// + /// Tag members + + /// + /// + /// + int64_t getId() const; + void setId(int64_t value); + + /// + /// + /// + std::string getName() const; + void setName(std::string value); + +protected: + int64_t m_Id = 0L; + std::string m_Name = ""; +}; + +std::vector createTagVectorFromJsonString(const std::string& json); + +template<> +inline boost::property_tree::ptree toPt(const Tag& val) { + return val.toPropertyTree(); +} + +template<> +inline Tag fromPt(const boost::property_tree::ptree& pt) { + Tag ret; + ret.fromPropertyTree(pt); + return ret; +} + +} +} +} +} + +#endif /* Tag_H_ */ diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/model/User.cpp b/samples/server/petstore/cpp-restbed/generated/3_0/model/User.cpp new file mode 100644 index 00000000000..666999644e7 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/generated/3_0/model/User.cpp @@ -0,0 +1,196 @@ +/** + * 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 "User.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#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 { + +User::User(boost::property_tree::ptree const& pt) +{ + fromPropertyTree(pt); +} + + +std::string User::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 User::fromJsonString(std::string const& jsonString) +{ + std::stringstream ss(jsonString); + ptree pt; + read_json(ss,pt); + this->fromPropertyTree(pt); +} + +ptree User::toPropertyTree() const +{ + ptree pt; + ptree tmp_node; + pt.put("id", m_Id); + pt.put("username", m_Username); + pt.put("firstName", m_FirstName); + pt.put("lastName", m_LastName); + pt.put("email", m_Email); + pt.put("password", m_Password); + pt.put("phone", m_Phone); + pt.put("userStatus", m_UserStatus); + return pt; +} + +void User::fromPropertyTree(ptree const &pt) +{ + ptree tmp_node; + m_Id = pt.get("id", 0L); + m_Username = pt.get("username", ""); + m_FirstName = pt.get("firstName", ""); + m_LastName = pt.get("lastName", ""); + m_Email = pt.get("email", ""); + m_Password = pt.get("password", ""); + m_Phone = pt.get("phone", ""); + m_UserStatus = pt.get("userStatus", 0); +} + +int64_t User::getId() const +{ + return m_Id; +} + +void User::setId(int64_t value) +{ + m_Id = value; +} + + +std::string User::getUsername() const +{ + return m_Username; +} + +void User::setUsername(std::string value) +{ + m_Username = value; +} + + +std::string User::getFirstName() const +{ + return m_FirstName; +} + +void User::setFirstName(std::string value) +{ + m_FirstName = value; +} + + +std::string User::getLastName() const +{ + return m_LastName; +} + +void User::setLastName(std::string value) +{ + m_LastName = value; +} + + +std::string User::getEmail() const +{ + return m_Email; +} + +void User::setEmail(std::string value) +{ + m_Email = value; +} + + +std::string User::getPassword() const +{ + return m_Password; +} + +void User::setPassword(std::string value) +{ + m_Password = value; +} + + +std::string User::getPhone() const +{ + return m_Phone; +} + +void User::setPhone(std::string value) +{ + m_Phone = value; +} + + +int32_t User::getUserStatus() const +{ + return m_UserStatus; +} + +void User::setUserStatus(int32_t value) +{ + m_UserStatus = value; +} + + + +std::vector createUserVectorFromJsonString(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(); + for (const auto& child: pt) { + vec.emplace_back(User(child.second)); + } + + return vec; +} + +} +} +} +} + diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/model/User.h b/samples/server/petstore/cpp-restbed/generated/3_0/model/User.h new file mode 100644 index 00000000000..214640aae14 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/generated/3_0/model/User.h @@ -0,0 +1,138 @@ +/** + * 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. + */ + +/* + * User.h + * + * + */ + +#ifndef User_H_ +#define User_H_ + + + +#include +#include +#include +#include +#include "helpers.h" + +namespace org { +namespace openapitools { +namespace server { +namespace model { + +/// +/// +/// +class User +{ +public: + User() = default; + explicit User(boost::property_tree::ptree const& pt); + virtual ~User() = default; + + User(const User& other) = default; // copy constructor + User(User&& other) noexcept = default; // move constructor + + User& operator=(const User& other) = default; // copy assignment + User& operator=(User&& 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); + + + ///////////////////////////////////////////// + /// User members + + /// + /// + /// + int64_t getId() const; + void setId(int64_t value); + + /// + /// + /// + std::string getUsername() const; + void setUsername(std::string value); + + /// + /// + /// + std::string getFirstName() const; + void setFirstName(std::string value); + + /// + /// + /// + std::string getLastName() const; + void setLastName(std::string value); + + /// + /// + /// + std::string getEmail() const; + void setEmail(std::string value); + + /// + /// + /// + std::string getPassword() const; + void setPassword(std::string value); + + /// + /// + /// + std::string getPhone() const; + void setPhone(std::string value); + + /// + /// User Status + /// + int32_t getUserStatus() const; + void setUserStatus(int32_t value); + +protected: + int64_t m_Id = 0L; + std::string m_Username = ""; + std::string m_FirstName = ""; + std::string m_LastName = ""; + std::string m_Email = ""; + std::string m_Password = ""; + std::string m_Phone = ""; + int32_t m_UserStatus = 0; +}; + +std::vector createUserVectorFromJsonString(const std::string& json); + +template<> +inline boost::property_tree::ptree toPt(const User& val) { + return val.toPropertyTree(); +} + +template<> +inline User fromPt(const boost::property_tree::ptree& pt) { + User ret; + ret.fromPropertyTree(pt); + return ret; +} + +} +} +} +} + +#endif /* User_H_ */ diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/model/_foo_get_default_response.cpp b/samples/server/petstore/cpp-restbed/generated/3_0/model/_foo_get_default_response.cpp new file mode 100644 index 00000000000..1ad8bb0a0a1 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/generated/3_0/model/_foo_get_default_response.cpp @@ -0,0 +1,107 @@ +/** + * 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 "_foo_get_default_response.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#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 { + +_foo_get_default_response::_foo_get_default_response(boost::property_tree::ptree const& pt) +{ + fromPropertyTree(pt); +} + + +std::string _foo_get_default_response::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 _foo_get_default_response::fromJsonString(std::string const& jsonString) +{ + std::stringstream ss(jsonString); + ptree pt; + read_json(ss,pt); + this->fromPropertyTree(pt); +} + +ptree _foo_get_default_response::toPropertyTree() const +{ + ptree pt; + ptree tmp_node; + pt.add_child("string", m_string.toPropertyTree()); + return pt; +} + +void _foo_get_default_response::fromPropertyTree(ptree const &pt) +{ + ptree tmp_node; + if (pt.get_child_optional("string")) { + m_string = fromPt(pt.get_child("string")); + } +} + +Foo _foo_get_default_response::getString() const +{ + return m_string; +} + +void _foo_get_default_response::setString(Foo value) +{ + m_string = value; +} + + + +std::vector<_foo_get_default_response> create_foo_get_default_responseVectorFromJsonString(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<_foo_get_default_response>(); + for (const auto& child: pt) { + vec.emplace_back(_foo_get_default_response(child.second)); + } + + return vec; +} + +} +} +} +} + diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/model/_foo_get_default_response.h b/samples/server/petstore/cpp-restbed/generated/3_0/model/_foo_get_default_response.h new file mode 100644 index 00000000000..9c5416bd8f2 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/generated/3_0/model/_foo_get_default_response.h @@ -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. + */ + +/* + * _foo_get_default_response.h + * + * + */ + +#ifndef _foo_get_default_response_H_ +#define _foo_get_default_response_H_ + + + +#include "Foo.h" +#include +#include +#include +#include "helpers.h" + +namespace org { +namespace openapitools { +namespace server { +namespace model { + +/// +/// +/// +class _foo_get_default_response +{ +public: + _foo_get_default_response() = default; + explicit _foo_get_default_response(boost::property_tree::ptree const& pt); + virtual ~_foo_get_default_response() = default; + + _foo_get_default_response(const _foo_get_default_response& other) = default; // copy constructor + _foo_get_default_response(_foo_get_default_response&& other) noexcept = default; // move constructor + + _foo_get_default_response& operator=(const _foo_get_default_response& other) = default; // copy assignment + _foo_get_default_response& operator=(_foo_get_default_response&& 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); + + + ///////////////////////////////////////////// + /// _foo_get_default_response members + + /// + /// + /// + Foo getString() const; + void setString(Foo value); + +protected: + Foo m_string; +}; + +std::vector<_foo_get_default_response> create_foo_get_default_responseVectorFromJsonString(const std::string& json); + +template<> +inline boost::property_tree::ptree toPt<_foo_get_default_response>(const _foo_get_default_response& val) { + return val.toPropertyTree(); +} + +template<> +inline _foo_get_default_response fromPt<_foo_get_default_response>(const boost::property_tree::ptree& pt) { + _foo_get_default_response ret; + ret.fromPropertyTree(pt); + return ret; +} + +} +} +} +} + +#endif /* _foo_get_default_response_H_ */ diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/model/_special_model_name_.cpp b/samples/server/petstore/cpp-restbed/generated/3_0/model/_special_model_name_.cpp new file mode 100644 index 00000000000..3f3ca3e8cd1 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/generated/3_0/model/_special_model_name_.cpp @@ -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 "_special_model_name_.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#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 { + +_special_model_name_::_special_model_name_(boost::property_tree::ptree const& pt) +{ + fromPropertyTree(pt); +} + + +std::string _special_model_name_::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 _special_model_name_::fromJsonString(std::string const& jsonString) +{ + std::stringstream ss(jsonString); + ptree pt; + read_json(ss,pt); + this->fromPropertyTree(pt); +} + +ptree _special_model_name_::toPropertyTree() const +{ + ptree pt; + ptree tmp_node; + pt.put("$special[property.name]", m_special_property_name); + return pt; +} + +void _special_model_name_::fromPropertyTree(ptree const &pt) +{ + ptree tmp_node; + m_special_property_name = pt.get("$special[property.name]", 0L); +} + +int64_t _special_model_name_::getSpecialPropertyName() const +{ + return m_special_property_name; +} + +void _special_model_name_::setSpecialPropertyName(int64_t value) +{ + m_special_property_name = value; +} + + + +std::vector<_special_model_name_> create_special_model_name_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<_special_model_name_>(); + for (const auto& child: pt) { + vec.emplace_back(_special_model_name_(child.second)); + } + + return vec; +} + +} +} +} +} + diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/model/_special_model_name_.h b/samples/server/petstore/cpp-restbed/generated/3_0/model/_special_model_name_.h new file mode 100644 index 00000000000..4333323a4c2 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/generated/3_0/model/_special_model_name_.h @@ -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. + */ + +/* + * _special_model_name_.h + * + * + */ + +#ifndef _special_model_name__H_ +#define _special_model_name__H_ + + + +#include +#include +#include +#include "helpers.h" + +namespace org { +namespace openapitools { +namespace server { +namespace model { + +/// +/// +/// +class _special_model_name_ +{ +public: + _special_model_name_() = default; + explicit _special_model_name_(boost::property_tree::ptree const& pt); + virtual ~_special_model_name_() = default; + + _special_model_name_(const _special_model_name_& other) = default; // copy constructor + _special_model_name_(_special_model_name_&& other) noexcept = default; // move constructor + + _special_model_name_& operator=(const _special_model_name_& other) = default; // copy assignment + _special_model_name_& operator=(_special_model_name_&& 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); + + + ///////////////////////////////////////////// + /// _special_model_name_ members + + /// + /// + /// + int64_t getSpecialPropertyName() const; + void setSpecialPropertyName(int64_t value); + +protected: + int64_t m_special_property_name = 0L; +}; + +std::vector<_special_model_name_> create_special_model_name_VectorFromJsonString(const std::string& json); + +template<> +inline boost::property_tree::ptree toPt<_special_model_name_>(const _special_model_name_& val) { + return val.toPropertyTree(); +} + +template<> +inline _special_model_name_ fromPt<_special_model_name_>(const boost::property_tree::ptree& pt) { + _special_model_name_ ret; + ret.fromPropertyTree(pt); + return ret; +} + +} +} +} +} + +#endif /* _special_model_name__H_ */ diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/model/helpers.h b/samples/server/petstore/cpp-restbed/generated/3_0/model/helpers.h new file mode 100644 index 00000000000..4201555c639 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/generated/3_0/model/helpers.h @@ -0,0 +1,149 @@ +/** + * 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. + */ + + +#ifndef OPENAPI_MODELS_HELPER_H_ +#define OPENAPI_MODELS_HELPER_H_ + + + +#include +#include +#include +#include + +namespace org { +namespace openapitools { +namespace server { +namespace model { + +template +boost::property_tree::ptree toPt(const T& val) { + boost::property_tree::ptree pt; + pt.put_value(val); + return pt; +} + +template +boost::property_tree::ptree toPt(const std::vector & 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 +boost::property_tree::ptree toPt(const std::map & 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 +boost::property_tree::ptree toPt(const std::set & 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 +struct is_vector +{ + static constexpr bool value = false; +}; + +template +struct is_vector> +{ + static constexpr bool value = true; +}; + +template +struct is_map +{ + static constexpr bool value = false; +}; + +template +struct is_map> +{ + static constexpr bool value = true; +}; + +template +struct is_set +{ + static constexpr bool value = false; +}; + +template +struct is_set> +{ + static constexpr bool value = true; +}; + + +template +std::enable_if_t::value && !is_map::value && !is_set::value, T> +fromPt(const boost::property_tree::ptree& pt) { + return pt.get_value(); +} + +template +std::enable_if_t::value,T> +fromPt(const boost::property_tree::ptree& pt) { + T vec; + for (const auto &child: pt) { + typename T::value_type childElement = fromPt(child.second); + vec.emplace_back(childElement); + } + return vec; +} + +template +std::enable_if_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(child.second); + map.insert(std::make_pair(child.first, childElement)); + } + return map; +} + +template +std::enable_if_t::value,T> +fromPt(const boost::property_tree::ptree& pt) { + T set; + for (const auto &child: pt) { + typename T::value_type childElement = fromPt(child.second); + set.insert(childElement); + } + return set; +} + +} +} +} +} + +#endif /* OPENAPI_MODELS_HELPER_H_ */ \ No newline at end of file diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/model/r_200_response.cpp b/samples/server/petstore/cpp-restbed/generated/3_0/model/r_200_response.cpp new file mode 100644 index 00000000000..a5b3309bb21 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/generated/3_0/model/r_200_response.cpp @@ -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 "r_200_response.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#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 { + +r_200_response::r_200_response(boost::property_tree::ptree const& pt) +{ + fromPropertyTree(pt); +} + + +std::string r_200_response::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 r_200_response::fromJsonString(std::string const& jsonString) +{ + std::stringstream ss(jsonString); + ptree pt; + read_json(ss,pt); + this->fromPropertyTree(pt); +} + +ptree r_200_response::toPropertyTree() const +{ + ptree pt; + ptree tmp_node; + pt.put("name", m_Name); + pt.put("class", m_r_class); + return pt; +} + +void r_200_response::fromPropertyTree(ptree const &pt) +{ + ptree tmp_node; + m_Name = pt.get("name", 0); + m_r_class = pt.get("class", ""); +} + +int32_t r_200_response::getName() const +{ + return m_Name; +} + +void r_200_response::setName(int32_t value) +{ + m_Name = value; +} + + +std::string r_200_response::getRClass() const +{ + return m_r_class; +} + +void r_200_response::setRClass(std::string value) +{ + m_r_class = value; +} + + + +std::vector creater_200_responseVectorFromJsonString(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(); + for (const auto& child: pt) { + vec.emplace_back(r_200_response(child.second)); + } + + return vec; +} + +} +} +} +} + diff --git a/samples/server/petstore/cpp-restbed/generated/3_0/model/r_200_response.h b/samples/server/petstore/cpp-restbed/generated/3_0/model/r_200_response.h new file mode 100644 index 00000000000..6108e2edf37 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/generated/3_0/model/r_200_response.h @@ -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. + */ + +/* + * r_200_response.h + * + * Model for testing model name starting with number + */ + +#ifndef r_200_response_H_ +#define r_200_response_H_ + + + +#include +#include +#include +#include +#include "helpers.h" + +namespace org { +namespace openapitools { +namespace server { +namespace model { + +/// +/// Model for testing model name starting with number +/// +class r_200_response +{ +public: + r_200_response() = default; + explicit r_200_response(boost::property_tree::ptree const& pt); + virtual ~r_200_response() = default; + + r_200_response(const r_200_response& other) = default; // copy constructor + r_200_response(r_200_response&& other) noexcept = default; // move constructor + + r_200_response& operator=(const r_200_response& other) = default; // copy assignment + r_200_response& operator=(r_200_response&& 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); + + + ///////////////////////////////////////////// + /// r_200_response members + + /// + /// + /// + int32_t getName() const; + void setName(int32_t value); + + /// + /// + /// + std::string getRClass() const; + void setRClass(std::string value); + +protected: + int32_t m_Name = 0; + std::string m_r_class = ""; +}; + +std::vector creater_200_responseVectorFromJsonString(const std::string& json); + +template<> +inline boost::property_tree::ptree toPt(const r_200_response& val) { + return val.toPropertyTree(); +} + +template<> +inline r_200_response fromPt(const boost::property_tree::ptree& pt) { + r_200_response ret; + ret.fromPropertyTree(pt); + return ret; +} + +} +} +} +} + +#endif /* r_200_response_H_ */ diff --git a/samples/server/petstore/cpp-restbed/pom.xml b/samples/server/petstore/cpp-restbed/pom.xml new file mode 100644 index 00000000000..9b496524c15 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/pom.xml @@ -0,0 +1,43 @@ + + 4.0.0 + org.openapitools + CppRestbedServerTests + pom + 1.0-SNAPSHOT + C++ Restbed Petstore Server + + + + maven-dependency-plugin + + + package + + copy-dependencies + + + ${project.build.directory} + + + + + + org.codehaus.mojo + exec-maven-plugin + 1.6.0 + + + build-and-run-restbed + integration-test + + exec + + + ./build_and_test.sh + + + + + + + diff --git a/samples/server/petstore/cpp-restbed/test/CMakeLists.txt b/samples/server/petstore/cpp-restbed/test/CMakeLists.txt new file mode 100644 index 00000000000..1de7e93ba41 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/CMakeLists.txt @@ -0,0 +1,4 @@ + +add_subdirectory(model_tests) +add_subdirectory(api_tests) +add_subdirectory(java_client_tests) \ No newline at end of file diff --git a/samples/server/petstore/cpp-restbed/test/api_tests/CMakeLists.txt b/samples/server/petstore/cpp-restbed/test/api_tests/CMakeLists.txt new file mode 100644 index 00000000000..ec3493bf125 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/api_tests/CMakeLists.txt @@ -0,0 +1,23 @@ + +add_executable(api_tests) + +target_sources(api_tests + PRIVATE + main.cpp + store_api_test.cpp + beast_client.cpp +) + +target_include_directories(api_tests + SYSTEM PRIVATE + ${Boost_INCLUDE_DIRS} + #${restbed_SOURCE_DIR}/source +) + +target_link_libraries(api_tests + PRIVATE + ${Boost_LIBRARIES} + org.openapitools.server.apiStubs +) + +add_test(NAME api_tests COMMAND api_tests) diff --git a/samples/server/petstore/cpp-restbed/test/api_tests/beast_client.cpp b/samples/server/petstore/cpp-restbed/test/api_tests/beast_client.cpp new file mode 100644 index 00000000000..fdea3f15570 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/api_tests/beast_client.cpp @@ -0,0 +1,58 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +#include "beast_client.h" + +namespace beast = boost::beast; // from +namespace http = beast::http; // from +namespace net = boost::asio; // from +using tcp = net::ip::tcp; // from + + +std::pair requestData(const http::verb verb, + const std::string& target, + const std::string& data) +{ + std::string out; + int status = 0; + + auto const host = "localhost"; + auto const port = "1234"; + int version = 11; + + net::io_context ioc; + + tcp::resolver resolver(ioc); + beast::tcp_stream stream(ioc); + + auto const results = resolver.resolve(host, port); + + stream.connect(results); + + http::request req{verb, target, version}; + req.set(http::field::host, host); + req.set(http::field::user_agent, BOOST_BEAST_VERSION_STRING); + req.set(http::field::body, data); + + http::write(stream, req); + + beast::flat_buffer buffer; + http::response res; + http::read(stream, buffer, res); + out = boost::beast::buffers_to_string(res.body().data()); + status = static_cast(res.result()); + + beast::error_code ec; + stream.socket().shutdown(tcp::socket::shutdown_both, ec); + + if(ec && ec != beast::errc::not_connected) + throw beast::system_error{ec}; + + return std::make_pair(std::move(status), std::move(out)); +} \ No newline at end of file diff --git a/samples/server/petstore/cpp-restbed/test/api_tests/beast_client.h b/samples/server/petstore/cpp-restbed/test/api_tests/beast_client.h new file mode 100644 index 00000000000..35909fd3dac --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/api_tests/beast_client.h @@ -0,0 +1,7 @@ +#pragma once + +#include + +std::pair requestData(const boost::beast::http::verb verb, + const std::string& target, + const std::string& data = ""); diff --git a/samples/server/petstore/cpp-restbed/test/api_tests/main.cpp b/samples/server/petstore/cpp-restbed/test/api_tests/main.cpp new file mode 100644 index 00000000000..4af53a2ba3f --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/api_tests/main.cpp @@ -0,0 +1,4 @@ +#define BOOST_TEST_MODULE ModelTests + +//#include // static or dynamic boost build +#include // header only boost diff --git a/samples/server/petstore/cpp-restbed/test/api_tests/store_api_test.cpp b/samples/server/petstore/cpp-restbed/test/api_tests/store_api_test.cpp new file mode 100644 index 00000000000..9dac7846398 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/api_tests/store_api_test.cpp @@ -0,0 +1,81 @@ +#define BOOST_TEST_INCLUDED + +#include +#include +#include +#include +#include +#include + +#include "api/StoreApi.h" + +#include "beast_client.h" + + +using namespace org::openapitools::server::model; +using namespace org::openapitools::server::api; + +class MyStoreApiStoreInventoryResource : public StoreApiResources::StoreInventoryResource { +public: + virtual std::pair> handler_GET() override { + std::map map; + map["Hello inventory"] = 23; + return std::make_pair(200, std::move(map)); + } + +}; + +std::string formatJson(const std::string& jsonString) { + boost::property_tree::ptree pt; + std::stringstream sstream(jsonString); + read_json(sstream,pt); + write_json(sstream, pt); + return sstream.str(); +} + +BOOST_AUTO_TEST_SUITE(StoreApiTest) + +BOOST_AUTO_TEST_CASE(startService) +{ + auto restbedService = std::make_shared(); + + auto storeApi = StoreApi(restbedService); + std::shared_ptr res = std::make_shared(); + storeApi.setResource(res); + + std::thread thread([&]{ + auto settings = std::make_shared(); + settings->set_port(1234); + restbedService->start(settings); + }); + thread.detach(); + + sleep(1); + + int status = 0; + std::string data; + + // localhost:1234/v2/store/inventory/ + auto response = requestData(boost::beast::http::verb::get, + "/v2/store/inventory/"); + status = response.first; + data = formatJson(response.second); + + const auto expectedJson = formatJson(R"JSON({"Hello inventory": "23"})JSON"); + BOOST_TEST(200 == status); + BOOST_TEST(expectedJson == data); + + // /store/order/{orderId: .*}/ + response = requestData(boost::beast::http::verb::get, + "/v2/store/order/3"); + + status = response.first; + data = response.second; + + BOOST_TEST(404 == status); + BOOST_TEST(data.empty()); + + restbedService->stop(); +} + +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/samples/server/petstore/cpp-restbed/test/java_client_tests/CMakeLists.txt b/samples/server/petstore/cpp-restbed/test/java_client_tests/CMakeLists.txt new file mode 100644 index 00000000000..141e48c163a --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/java_client_tests/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(tests_servers) \ No newline at end of file diff --git a/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/.gitignore b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/.gitignore new file mode 100644 index 00000000000..ac96206f319 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/.gitignore @@ -0,0 +1 @@ +.gradle/ \ No newline at end of file diff --git a/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/build.gradle b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/build.gradle new file mode 100644 index 00000000000..ec2aff75198 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/build.gradle @@ -0,0 +1,51 @@ +plugins { + id 'org.springframework.boot' version '2.6.7' + id 'io.spring.dependency-management' version '1.0.11.RELEASE' + id 'java' + id "org.openapi.generator" version "5.4.0" +} + +group 'org.example' +version '1.0-SNAPSHOT' + +repositories { + mavenCentral() + mavenLocal() + maven { url "https://repo1.maven.org/maven2" } +} + +dependencies { + compile 'org.springframework.boot:spring-boot-starter-webflux' + implementation group: 'org.openapitools', name: 'jackson-databind-nullable', version: '0.2.2' + implementation group: 'io.swagger', name: 'swagger-annotations', version: '1.6.6' + implementation group: 'com.google.guava', name: 'guava', version: '31.1-jre' + + testImplementation('com.approvaltests:approvaltests:15.3.0') + testImplementation(platform('org.junit:junit-bom:5.8.2')) + testImplementation('org.junit.jupiter:junit-jupiter') + testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2' + testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.2' + +} + +test { + useJUnitPlatform() +} + + +compileJava.dependsOn tasks.openApiGenerate + +openApiGenerate { + generatorName = "java" + inputSpec = "$rootDir/../../../../../../../modules/openapi-generator/src/test/resources/3_0/petstore.yaml".toString() + outputDir = "$buildDir/generated".toString() + apiPackage = "org.openapi.example.api" + invokerPackage = "org.openapi.example.invoker" + modelPackage = "org.openapi.example.model" + configOptions = [ + dateLibrary: "java8", + library: "webclient" + ] +} + +sourceSets.main.java.srcDirs += "$buildDir/generated/src/main/java".toString() diff --git a/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/gradle/wrapper/gradle-wrapper.jar b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 00000000000..e708b1c023e Binary files /dev/null and b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/gradle/wrapper/gradle-wrapper.jar differ diff --git a/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/gradle/wrapper/gradle-wrapper.properties b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 00000000000..da9702f9e70 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,5 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-6.8-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/gradlew b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/gradlew new file mode 100755 index 00000000000..4f906e0c811 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/gradlew @@ -0,0 +1,185 @@ +#!/usr/bin/env sh + +# +# Copyright 2015 the original author or authors. +# +# 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. +# + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn () { + echo "$*" +} + +die () { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; + NONSTOP* ) + nonstop=true + ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin or MSYS, switch paths to Windows format before running java +if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=`expr $i + 1` + done + case $i in + 0) set -- ;; + 1) set -- "$args0" ;; + 2) set -- "$args0" "$args1" ;; + 3) set -- "$args0" "$args1" "$args2" ;; + 4) set -- "$args0" "$args1" "$args2" "$args3" ;; + 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Escape application args +save () { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " +} +APP_ARGS=`save "$@"` + +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" + +exec "$JAVACMD" "$@" diff --git a/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/gradlew.bat b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/gradlew.bat new file mode 100644 index 00000000000..107acd32c4e --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/gradlew.bat @@ -0,0 +1,89 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/settings.gradle b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/settings.gradle new file mode 100644 index 00000000000..af83dec850c --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/settings.gradle @@ -0,0 +1,2 @@ +rootProject.name = 'java_client_for_tests' + diff --git a/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/helper/ApiClientFactories.java b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/helper/ApiClientFactories.java new file mode 100644 index 00000000000..7af90cbf9e2 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/helper/ApiClientFactories.java @@ -0,0 +1,25 @@ +package helper; + +import org.openapi.example.api.PetApi; +import org.openapi.example.api.StoreApi; +import org.openapi.example.api.UserApi; +import org.openapi.example.invoker.ApiClient; + +public class ApiClientFactories { + public static PetApi setUpPetApi(int port) { + return new PetApi(setUpDefaultApiClient(port)); + } + + public static StoreApi setUpStoreApi(int port) { + return new StoreApi(setUpDefaultApiClient(port)); + } + public static UserApi setUpUserApi(int port) { + return new UserApi(setUpDefaultApiClient(port)); + } + + private static ApiClient setUpDefaultApiClient(int port) { + ApiClient defaultClient = new ApiClient(); + defaultClient.setBasePath("http://localhost:" + String.valueOf(port) + "/v2"); + return defaultClient; + } +} diff --git a/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/helper/StripTrailingWhitespaceScrubber.java b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/helper/StripTrailingWhitespaceScrubber.java new file mode 100644 index 00000000000..14e32987bad --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/helper/StripTrailingWhitespaceScrubber.java @@ -0,0 +1,12 @@ +package helper; + +import org.approvaltests.core.Scrubber; + +class StripTrailingWhitespaceScrubber implements Scrubber { + + @Override + public String scrub(String input) { + String replaced = input.replaceAll("\\s+\n", "\n"); + return replaced.trim(); + } +} diff --git a/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/helper/TestingHelper.java b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/helper/TestingHelper.java new file mode 100644 index 00000000000..e5a649fe6d3 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/helper/TestingHelper.java @@ -0,0 +1,69 @@ +package helper; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.MapperFeature; +import com.fasterxml.jackson.databind.SerializationFeature; +import com.fasterxml.jackson.databind.util.StdDateFormat; +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; +import org.approvaltests.Approvals; +import org.approvaltests.core.Options; +import org.springframework.web.reactive.function.client.WebClientRequestException; +import org.springframework.web.reactive.function.client.WebClientResponseException; + +import java.text.SimpleDateFormat; + +public class TestingHelper { + + private static Options removeTrailingSpaces = new Options(new StripTrailingWhitespaceScrubber()); + + public static void approveException(WebClientResponseException exception) { + String message = "Status code: " + exception.getStatusCode() + + "\nReason: " + exception.getResponseBodyAsString() + + "\nResponse headers: " + exception.getHeaders(); + Approvals.verify(message, removeTrailingSpaces); + } + + public static void approveException(WebClientRequestException exception) { + String message = "URI: " + exception.getUri() + + "\nMethod: " + exception.getMethod () + + "\nHeaders: " + exception.getHeaders() + + "\nMessage: " + exception.getMessage(); + Approvals.verify(message, removeTrailingSpaces); + } + + public static void approveResponseAsJson(Object reponseObject) { + ObjectMapper objectMapper = new ObjectMapper(); + objectMapper.registerModule(new JavaTimeModule()); + objectMapper.setDateFormat(new StdDateFormat()); + objectMapper.setConfig(objectMapper.getSerializationConfig() + .with(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY) + .with(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS)); + + String json = ""; + + try { + json = objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(reponseObject); + } catch (JsonProcessingException e) { + json = e.toString(); + } + Approvals.verify(json, removeTrailingSpaces); + } + + + public static long errorRaisingStringToInt(String errorRisingString) { + if (errorRisingString.equals("ThrowsApiException")) { + return 9100; + } + else if (errorRisingString.equals("ThrowsStdExceptionDerivedException")) { + return 9200; + } + else if (errorRisingString.equals("ThrowsInt")) { + return 9300; + } + + String status = errorRisingString.replace("ReturnsStatus", ""); + + return Integer.parseInt(status); + } +} diff --git a/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_default_unimplemented_server_stubs/PackageSettings.java b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_default_unimplemented_server_stubs/PackageSettings.java new file mode 100644 index 00000000000..66720b89e63 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_default_unimplemented_server_stubs/PackageSettings.java @@ -0,0 +1,8 @@ +package test_default_unimplemented_server_stubs; + +import org.approvaltests.reporters.linux.MeldMergeReporter; + +public class PackageSettings { + public static String UseApprovalSubdirectory = "approval_files"; + public static MeldMergeReporter UseReporter = MeldMergeReporter.INSTANCE; +} diff --git a/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_default_unimplemented_server_stubs/PetApiTest.java b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_default_unimplemented_server_stubs/PetApiTest.java new file mode 100644 index 00000000000..48309ef5562 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_default_unimplemented_server_stubs/PetApiTest.java @@ -0,0 +1,65 @@ +package test_default_unimplemented_server_stubs; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.openapi.example.api.PetApi; +import org.openapi.example.model.Pet; +import org.springframework.web.reactive.function.client.WebClientResponseException; + + +import static helper.ApiClientFactories.setUpPetApi; +import static helper.TestingHelper.approveException; +import static org.junit.jupiter.api.Assertions.assertThrows; + +class PetApiTest { + + PetApi apiInstance; + + @BeforeEach + void setUp() { + apiInstance = setUpPetApi(1234); + } + + @Test + void addPet() { + Pet pet = new Pet(); + WebClientResponseException exception = assertThrows( + WebClientResponseException.class, () -> { + apiInstance.addPet(pet).block(); + }); + + approveException(exception); + } + + @Test + void deletePet() { + WebClientResponseException exception = assertThrows( + WebClientResponseException.class, () -> { + apiInstance.deletePet(99L, "myApiKey").block(); + }); + + approveException(exception); + } + + @Test + void getPetById() { + WebClientResponseException exception = assertThrows( + WebClientResponseException.class, () -> { + apiInstance.getPetById(9L).block(); + }); + + approveException(exception); + } + + @Test + void updatePet() { + Pet pet = new Pet(); + WebClientResponseException exception = assertThrows( + WebClientResponseException.class, () -> { + apiInstance.updatePet(pet).block(); + }); + + approveException(exception); + } + +} \ No newline at end of file diff --git a/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_default_unimplemented_server_stubs/StoreApiTest.java b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_default_unimplemented_server_stubs/StoreApiTest.java new file mode 100644 index 00000000000..ba25d240635 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_default_unimplemented_server_stubs/StoreApiTest.java @@ -0,0 +1,63 @@ +package test_default_unimplemented_server_stubs; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.openapi.example.api.StoreApi; +import org.openapi.example.model.Order; +import org.openapi.example.invoker.ApiClient; +import org.springframework.web.reactive.function.client.WebClientResponseException; + +import static helper.ApiClientFactories.setUpStoreApi; +import static org.junit.jupiter.api.Assertions.*; +import static helper.TestingHelper.approveException; + +class StoreApiTest { + + StoreApi apiInstance; + + @BeforeEach + void setUp() { + apiInstance = setUpStoreApi(1234); + } + + @Test + void deleteOrder() { + WebClientResponseException exception = assertThrows( + WebClientResponseException.class, () -> { + apiInstance.deleteOrder("myOrderId").block(); + }); + + approveException(exception); + } + + @Test + void getInventory() { + WebClientResponseException exception = assertThrows( + WebClientResponseException.class, () -> { + apiInstance.getInventory().block(); + }); + + approveException(exception); + } + + @Test + void getOrderById() { + WebClientResponseException exception = assertThrows( + WebClientResponseException.class, () -> { + apiInstance.getOrderById(1L).block(); + }); + + approveException(exception); + } + + @Test + void placeOrder() { + Order order = new Order(); + WebClientResponseException exception = assertThrows( + WebClientResponseException.class, () -> { + apiInstance.placeOrder(order).block(); + }); + + approveException(exception); + } +} \ No newline at end of file diff --git a/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_default_unimplemented_server_stubs/UserApiTest.java b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_default_unimplemented_server_stubs/UserApiTest.java new file mode 100644 index 00000000000..56a37c5737f --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_default_unimplemented_server_stubs/UserApiTest.java @@ -0,0 +1,75 @@ +package test_default_unimplemented_server_stubs; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.openapi.example.api.UserApi; +import org.openapi.example.model.User; +import org.springframework.web.reactive.function.client.WebClientResponseException; + +import java.util.Arrays; + +import static helper.ApiClientFactories.setUpUserApi; +import static org.junit.jupiter.api.Assertions.*; +import static helper.TestingHelper.approveException; + +class UserApiTest { + + UserApi apiInstance; + + @BeforeEach + void setUp() { + apiInstance = setUpUserApi(1234); + } + + @Test + void createUser() { + User user = new User(); + WebClientResponseException exception = assertThrows( + WebClientResponseException.class, () -> { + apiInstance.createUser(user).block(); + }); + + approveException(exception); + } + + @Test + void createUsersWithArrayInput() { + User user = new User(); + WebClientResponseException exception = assertThrows( + WebClientResponseException.class, () -> { + apiInstance.createUsersWithArrayInput(Arrays.asList(user)).block(); + }); + + approveException(exception); + } + + @Test + void createUsersWithListInput() { + User user = new User(); + WebClientResponseException exception = assertThrows( + WebClientResponseException.class, () -> { + apiInstance.createUsersWithListInput(Arrays.asList(user)).block(); + }); + approveException(exception); + } + + @Test + void loginUser() { + WebClientResponseException exception = assertThrows( + WebClientResponseException.class, () -> { + apiInstance.loginUser("my name", "my password").block(); + }); + + approveException(exception); + } + + @Test + void logoutUser() { + WebClientResponseException exception = assertThrows( + WebClientResponseException.class, () -> { + apiInstance.logoutUser().block(); + }); + + approveException(exception); + } +} \ No newline at end of file diff --git a/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_default_unimplemented_server_stubs/approval_files/PetApiTest.addPet.approved.txt b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_default_unimplemented_server_stubs/approval_files/PetApiTest.addPet.approved.txt new file mode 100644 index 00000000000..4345dec9eef --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_default_unimplemented_server_stubs/approval_files/PetApiTest.addPet.approved.txt @@ -0,0 +1,3 @@ +Status code: 400 BAD_REQUEST +Reason: Value null not allowed +Response headers: [Content-Type:"text/plain", content-length:"22"] \ No newline at end of file diff --git a/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_default_unimplemented_server_stubs/approval_files/PetApiTest.deletePet.approved.txt b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_default_unimplemented_server_stubs/approval_files/PetApiTest.deletePet.approved.txt new file mode 100644 index 00000000000..00d009312a4 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_default_unimplemented_server_stubs/approval_files/PetApiTest.deletePet.approved.txt @@ -0,0 +1,3 @@ +Status code: 501 NOT_IMPLEMENTED +Reason: Not implemented +Response headers: [Connection:"close"] \ No newline at end of file diff --git a/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_default_unimplemented_server_stubs/approval_files/PetApiTest.getPetById.approved.txt b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_default_unimplemented_server_stubs/approval_files/PetApiTest.getPetById.approved.txt new file mode 100644 index 00000000000..00d009312a4 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_default_unimplemented_server_stubs/approval_files/PetApiTest.getPetById.approved.txt @@ -0,0 +1,3 @@ +Status code: 501 NOT_IMPLEMENTED +Reason: Not implemented +Response headers: [Connection:"close"] \ No newline at end of file diff --git a/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_default_unimplemented_server_stubs/approval_files/PetApiTest.updatePet.approved.txt b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_default_unimplemented_server_stubs/approval_files/PetApiTest.updatePet.approved.txt new file mode 100644 index 00000000000..4345dec9eef --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_default_unimplemented_server_stubs/approval_files/PetApiTest.updatePet.approved.txt @@ -0,0 +1,3 @@ +Status code: 400 BAD_REQUEST +Reason: Value null not allowed +Response headers: [Content-Type:"text/plain", content-length:"22"] \ No newline at end of file diff --git a/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_default_unimplemented_server_stubs/approval_files/StoreApiTest.deleteOrder.approved.txt b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_default_unimplemented_server_stubs/approval_files/StoreApiTest.deleteOrder.approved.txt new file mode 100644 index 00000000000..00d009312a4 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_default_unimplemented_server_stubs/approval_files/StoreApiTest.deleteOrder.approved.txt @@ -0,0 +1,3 @@ +Status code: 501 NOT_IMPLEMENTED +Reason: Not implemented +Response headers: [Connection:"close"] \ No newline at end of file diff --git a/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_default_unimplemented_server_stubs/approval_files/StoreApiTest.getInventory.approved.txt b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_default_unimplemented_server_stubs/approval_files/StoreApiTest.getInventory.approved.txt new file mode 100644 index 00000000000..00d009312a4 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_default_unimplemented_server_stubs/approval_files/StoreApiTest.getInventory.approved.txt @@ -0,0 +1,3 @@ +Status code: 501 NOT_IMPLEMENTED +Reason: Not implemented +Response headers: [Connection:"close"] \ No newline at end of file diff --git a/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_default_unimplemented_server_stubs/approval_files/StoreApiTest.getOrderById.approved.txt b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_default_unimplemented_server_stubs/approval_files/StoreApiTest.getOrderById.approved.txt new file mode 100644 index 00000000000..00d009312a4 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_default_unimplemented_server_stubs/approval_files/StoreApiTest.getOrderById.approved.txt @@ -0,0 +1,3 @@ +Status code: 501 NOT_IMPLEMENTED +Reason: Not implemented +Response headers: [Connection:"close"] \ No newline at end of file diff --git a/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_default_unimplemented_server_stubs/approval_files/StoreApiTest.placeOrder.approved.txt b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_default_unimplemented_server_stubs/approval_files/StoreApiTest.placeOrder.approved.txt new file mode 100644 index 00000000000..4345dec9eef --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_default_unimplemented_server_stubs/approval_files/StoreApiTest.placeOrder.approved.txt @@ -0,0 +1,3 @@ +Status code: 400 BAD_REQUEST +Reason: Value null not allowed +Response headers: [Content-Type:"text/plain", content-length:"22"] \ No newline at end of file diff --git a/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_default_unimplemented_server_stubs/approval_files/UserApiTest.createUser.approved.txt b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_default_unimplemented_server_stubs/approval_files/UserApiTest.createUser.approved.txt new file mode 100644 index 00000000000..00d009312a4 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_default_unimplemented_server_stubs/approval_files/UserApiTest.createUser.approved.txt @@ -0,0 +1,3 @@ +Status code: 501 NOT_IMPLEMENTED +Reason: Not implemented +Response headers: [Connection:"close"] \ No newline at end of file diff --git a/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_default_unimplemented_server_stubs/approval_files/UserApiTest.createUsersWithArrayInput.approved.txt b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_default_unimplemented_server_stubs/approval_files/UserApiTest.createUsersWithArrayInput.approved.txt new file mode 100644 index 00000000000..3ec1930af20 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_default_unimplemented_server_stubs/approval_files/UserApiTest.createUsersWithArrayInput.approved.txt @@ -0,0 +1,3 @@ +Status code: 405 METHOD_NOT_ALLOWED +Reason: +Response headers: [] \ No newline at end of file diff --git a/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_default_unimplemented_server_stubs/approval_files/UserApiTest.createUsersWithListInput.approved.txt b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_default_unimplemented_server_stubs/approval_files/UserApiTest.createUsersWithListInput.approved.txt new file mode 100644 index 00000000000..3ec1930af20 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_default_unimplemented_server_stubs/approval_files/UserApiTest.createUsersWithListInput.approved.txt @@ -0,0 +1,3 @@ +Status code: 405 METHOD_NOT_ALLOWED +Reason: +Response headers: [] \ No newline at end of file diff --git a/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_default_unimplemented_server_stubs/approval_files/UserApiTest.loginUser.approved.txt b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_default_unimplemented_server_stubs/approval_files/UserApiTest.loginUser.approved.txt new file mode 100644 index 00000000000..00d009312a4 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_default_unimplemented_server_stubs/approval_files/UserApiTest.loginUser.approved.txt @@ -0,0 +1,3 @@ +Status code: 501 NOT_IMPLEMENTED +Reason: Not implemented +Response headers: [Connection:"close"] \ No newline at end of file diff --git a/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_default_unimplemented_server_stubs/approval_files/UserApiTest.logoutUser.approved.txt b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_default_unimplemented_server_stubs/approval_files/UserApiTest.logoutUser.approved.txt new file mode 100644 index 00000000000..00d009312a4 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_default_unimplemented_server_stubs/approval_files/UserApiTest.logoutUser.approved.txt @@ -0,0 +1,3 @@ +Status code: 501 NOT_IMPLEMENTED +Reason: Not implemented +Response headers: [Connection:"close"] \ No newline at end of file diff --git a/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/PackageSettings.java b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/PackageSettings.java new file mode 100644 index 00000000000..be75667bc0b --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/PackageSettings.java @@ -0,0 +1,8 @@ +package test_error_handling_server_stubs; + +import org.approvaltests.reporters.linux.MeldMergeReporter; + +public class PackageSettings { + public static String UseApprovalSubdirectory = "approval_files"; + public static MeldMergeReporter UseReporter = MeldMergeReporter.INSTANCE; +} diff --git a/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/PetApiTest.java b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/PetApiTest.java new file mode 100644 index 00000000000..abc320cd76c --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/PetApiTest.java @@ -0,0 +1,274 @@ +package test_error_handling_server_stubs; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.openapi.example.api.PetApi; +import org.openapi.example.model.Pet; +import org.springframework.web.reactive.function.client.WebClientResponseException; + +import static helper.ApiClientFactories.setUpPetApi; +import static helper.TestingHelper.*; +import static org.junit.jupiter.api.Assertions.*; + +class PetApiTest { + + PetApi apiInstance; + + @BeforeEach + void setUp() { + apiInstance = setUpPetApi(1236); + } + + @Test + void addPetInvalidEnumValue() { + Pet pet = new Pet(); + pet.name("PetWithInvalidStatus"); + pet.status(null); // not allowed + WebClientResponseException exception = assertThrows( + WebClientResponseException.class, () -> { + apiInstance.addPet(pet).block(); + }); + approveException(exception); + } + + @Test + void addPetThatThrowsApiException() { + Pet pet = new Pet(); + pet.name("ThrowsApiException"); + pet.status(Pet.StatusEnum.SOLD); + WebClientResponseException exception = assertThrows( + WebClientResponseException.class, () -> { + apiInstance.addPet(pet).block(); + }); + approveException(exception); + } + + @Test + void addPetThatThrowsStdExceptionDerivedException() { + Pet pet = new Pet(); + pet.name("ThrowsStdExceptionDerivedException"); + pet.status(Pet.StatusEnum.AVAILABLE); + WebClientResponseException exception = assertThrows( + WebClientResponseException.class, () -> { + apiInstance.addPet(pet).block(); + }); + approveException(exception); + } + + @Test + void addPetThatThrowsInt() { + Pet pet = new Pet(); + pet.name("ThrowsInt"); + pet.status(Pet.StatusEnum.AVAILABLE); + WebClientResponseException exception = assertThrows( + WebClientResponseException.class, () -> { + apiInstance.addPet(pet).block(); + }); + + approveException(exception); + } + + @Test + void addPetThatReturnsStatus200() { + Pet pet = new Pet(); + pet.name("ReturnsStatus200"); + pet.status(Pet.StatusEnum.AVAILABLE); + apiInstance.addPet(pet).block(); + } + + @Test + void addPetThatReturnsStatus405() { + Pet pet = new Pet(); + pet.name("ReturnsStatus405"); + pet.status(Pet.StatusEnum.AVAILABLE); + + WebClientResponseException exception = assertThrows( + WebClientResponseException.class, () -> { + apiInstance.addPet(pet).block(); + }); + + approveException(exception); + } + + @Test + void deletePetThrowsApiException() { + WebClientResponseException exception = assertThrows( + WebClientResponseException.class, () -> { + apiInstance.deletePet(1342L, "ThrowsApiException").block(); + }); + approveException(exception); + } + + @Test + void deletePetThrowsStdExceptionDerivedException() { + WebClientResponseException exception = assertThrows( + WebClientResponseException.class, () -> { + apiInstance.deletePet(1342L, "ThrowsStdExceptionDerivedException").block(); + }); + approveException(exception); + } + + @Test + void deletePetThrowsInt() { + WebClientResponseException exception = assertThrows( + WebClientResponseException.class, () -> { + apiInstance.deletePet(1342L, "ThrowsInt").block(); + }); + approveException(exception); + } + + @Test + void deletePetReturnsStatus200() { + apiInstance.deletePet(1342L, "ReturnsStatus200").block(); + } + + @Test + void deletePetReturnsStatus400() { + WebClientResponseException exception = assertThrows( + WebClientResponseException.class, () -> { + apiInstance.deletePet(1342L, "ReturnsStatus400").block(); + }); + approveException(exception); + } + + @Test + void deletePetReturnsStatus300() { + apiInstance.deletePet(1342L, "ReturnsStatus300").block(); + } + + @Test + void getPetByIdThrowsApiException() { + long id = errorRaisingStringToInt("ThrowsApiException"); + WebClientResponseException exception = assertThrows( + WebClientResponseException.class, () -> { + apiInstance.getPetById(id).block(); + }); + approveException(exception); + } + + @Test + void getPetByIdThrowsStdExceptionDerivedException() { + long id = errorRaisingStringToInt("ThrowsStdExceptionDerivedException"); + WebClientResponseException exception = assertThrows( + WebClientResponseException.class, () -> { + apiInstance.getPetById(id).block(); + }); + approveException(exception); + } + + @Test + void getPetByIdThrowsInt() { + long id = errorRaisingStringToInt("ThrowsInt"); + WebClientResponseException exception = assertThrows( + WebClientResponseException.class, () -> { + apiInstance.getPetById(id).block(); + }); + approveException(exception); + } + + @Test + void getPetByIdReturnsStatus200() { + long id = errorRaisingStringToInt("ReturnsStatus200"); + Pet pet = apiInstance.getPetById(id).block(); + approveResponseAsJson(pet); + } + + @Test + void getPetByIdReturnsStatus300() { + long id = errorRaisingStringToInt("ReturnsStatus300"); + Pet pet = apiInstance.getPetById(id).block(); + assertNull(pet); + } + + @Test + void getPetByIdReturnsStatus400() { + long id = errorRaisingStringToInt("ReturnsStatus400"); + WebClientResponseException exception = assertThrows( + WebClientResponseException.class, () -> { + apiInstance.getPetById(id).block(); + }); + approveException(exception); + } + + @Test + void getPetByIdReturnsStatus404() { + long id = errorRaisingStringToInt("ReturnsStatus404"); + WebClientResponseException exception = assertThrows( + WebClientResponseException.class, () -> { + apiInstance.getPetById(id).block(); + }); + approveException(exception); + } + + @Test + void updatePetThrowsApiException() { + Pet pet = new Pet(); + pet.name("ThrowsApiException"); + pet.status(Pet.StatusEnum.SOLD); + WebClientResponseException exception = assertThrows( + WebClientResponseException.class, () -> { + apiInstance.updatePet(pet).block(); + }); + approveException(exception); + } + + @Test + void updatePetThrowsStdExceptionDerivedException() { + Pet pet = new Pet(); + pet.name("ThrowsStdExceptionDerivedException"); + pet.status(Pet.StatusEnum.SOLD); + WebClientResponseException exception = assertThrows( + WebClientResponseException.class, () -> { + apiInstance.updatePet(pet).block(); + }); + approveException(exception); + } + + @Test + void updatePetThrowsInt() { + Pet pet = new Pet(); + pet.name("ThrowsInt"); + pet.status(Pet.StatusEnum.SOLD); + WebClientResponseException exception = assertThrows( + WebClientResponseException.class, () -> { + apiInstance.updatePet(pet).block(); + }); + approveException(exception); + } + + + @Test + void updatePetReturnsStatus400() { + Pet pet = new Pet(); + pet.name("ReturnsStatus400"); + pet.status(Pet.StatusEnum.SOLD); + WebClientResponseException exception = assertThrows( + WebClientResponseException.class, () -> { + apiInstance.updatePet(pet).block(); + }); + approveException(exception); + } + + @Test + void updatePetReturnsStatus405() { + Pet pet = new Pet(); + pet.name("ReturnsStatus405"); + pet.status(Pet.StatusEnum.SOLD); + WebClientResponseException exception = assertThrows( + WebClientResponseException.class, () -> { + apiInstance.updatePet(pet).block(); + }); + approveException(exception); + } + @Test + void updatePetReturnsStatus500() { + Pet pet = new Pet(); + pet.name("ReturnsStatus500"); + pet.status(Pet.StatusEnum.SOLD); + WebClientResponseException exception = assertThrows( + WebClientResponseException.class, () -> { + apiInstance.updatePet(pet).block(); + }); + approveException(exception); + } +} diff --git a/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/StoreApiTest.java b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/StoreApiTest.java new file mode 100644 index 00000000000..b0c6f66515f --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/StoreApiTest.java @@ -0,0 +1,232 @@ +package test_error_handling_server_stubs; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.openapi.example.api.StoreApi; +import org.openapi.example.model.Order; +import org.springframework.core.codec.DecodingException; +import org.springframework.web.reactive.function.client.WebClientResponseException; + +import java.util.Map; + +import static helper.ApiClientFactories.setUpStoreApi; +import static helper.TestingHelper.*; +import static org.junit.jupiter.api.Assertions.*; + +class StoreApiTest { + + StoreApi apiInstance; + + @BeforeEach + void setUp() { + apiInstance = setUpStoreApi(1236); + } + + @Test + void deleteOrderThrowsApiException() { + WebClientResponseException exception = assertThrows( + WebClientResponseException.class, () -> { + apiInstance.deleteOrder("ThrowsApiException").block(); + }); + approveException(exception); + } + + @Test + void deleteOrderThrowsStdExceptionDerivedException() { + WebClientResponseException exception = assertThrows( + WebClientResponseException.class, () -> { + apiInstance.deleteOrder("ThrowsStdExceptionDerivedException").block(); + }); + approveException(exception); + } + + @Test + void deleteOrderThrowsInt() { + WebClientResponseException exception = assertThrows( + WebClientResponseException.class, () -> { + apiInstance.deleteOrder("ThrowsInt").block(); + }); + approveException(exception); + } + + @Test + void deleteOrderReturnsStatus200() { + apiInstance.deleteOrder("ReturnsStatus200").block(); + } + + @Test + void deleteOrderReturnsStatus400() { + WebClientResponseException exception = assertThrows( + WebClientResponseException.class, () -> { + apiInstance.deleteOrder("ReturnsStatus400").block(); + }); + + approveException(exception); + } + + @Test + void deleteOrderReturnsStatus404() { + WebClientResponseException exception = assertThrows( + WebClientResponseException.class, () -> { + apiInstance.deleteOrder("ReturnsStatus404").block(); + }); + + approveException(exception); + } + @Test + void deleteOrderReturnsStatus405() { + WebClientResponseException exception = assertThrows( + WebClientResponseException.class, () -> { + apiInstance.deleteOrder("ReturnsStatus405").block(); + }); + + approveException(exception); + } + + @Test + void getInventory() { + Map ret = apiInstance.getInventory().block(); + assertNull(ret); + } + + @Test + void getOrderByIdThrowsApiException() { + long id = errorRaisingStringToInt("ThrowsApiException"); + WebClientResponseException exception = assertThrows( + WebClientResponseException.class, () -> { + apiInstance.getOrderById(id).block(); + }); + approveException(exception); + } + + @Test + void getOrderByIdThrowsStdExceptionDerivedException() { + long id = errorRaisingStringToInt("ThrowsStdExceptionDerivedException"); + WebClientResponseException exception = assertThrows( + WebClientResponseException.class, () -> { + apiInstance.getOrderById(id).block(); + }); + approveException(exception); + } + + @Test + void getOrderByIdThrowsInt() { + long id = errorRaisingStringToInt("ThrowsInt"); + WebClientResponseException exception = assertThrows( + WebClientResponseException.class, () -> { + apiInstance.getOrderById(id).block(); + }); + approveException(exception); + } + + @Test + void getOrderByIdReturnsStatus200WithInvalidEnumValue() { + long id = errorRaisingStringToInt("ReturnsStatus200"); + DecodingException exception = assertThrows(DecodingException.class, () -> { + apiInstance.getOrderById(id).block(); + }); + } + + @Test + void getOrderByIdReturnsStatus300() { + long id = errorRaisingStringToInt("ReturnsStatus300"); + Order resp = apiInstance.getOrderById(id).block(); + assertNull(resp); + } + + @Test + void getOrderByIdReturnsStatus400() { + long id = errorRaisingStringToInt("ReturnsStatus400"); + WebClientResponseException exception = assertThrows( + WebClientResponseException.class, () -> { + apiInstance.getOrderById(id).block(); + }); + approveException(exception); + } + + @Test + void getOrderByIdReturnsStatus404() { + long id = errorRaisingStringToInt("ReturnsStatus404"); + WebClientResponseException exception = assertThrows( + WebClientResponseException.class, () -> { + apiInstance.getOrderById(id).block(); + }); + approveException(exception); + } + + @Test + void placeOrderThrowsApiException() { + long id = errorRaisingStringToInt("ThrowsApiException"); + + Order order = new Order(); + order.setId(id); + order.setStatus(Order.StatusEnum.PLACED); + + WebClientResponseException exception = assertThrows( + WebClientResponseException.class, () -> { + apiInstance.placeOrder(order).block(); + }); + approveException(exception); + + } + + @Test + void placeOrderThrowsStdExceptionDerivedException() { + long id = errorRaisingStringToInt("ThrowsStdExceptionDerivedException"); + + Order order = new Order(); + order.setId(id); + order.setStatus(Order.StatusEnum.PLACED); + + WebClientResponseException exception = assertThrows( + WebClientResponseException.class, () -> { + apiInstance.placeOrder(order).block(); + }); + approveException(exception); + + } + + @Test + void placeOrderThrowsInt() { + long id = errorRaisingStringToInt("ThrowsInt"); + + Order order = new Order(); + order.setId(id); + order.setStatus(Order.StatusEnum.PLACED); + + WebClientResponseException exception = assertThrows( + WebClientResponseException.class, () -> { + apiInstance.placeOrder(order).block(); + }); + approveException(exception); + + } + + @Test + void placeOrderReturnsStatus300() { + long id = errorRaisingStringToInt("ReturnsStatus300"); + + Order order = new Order(); + order.setId(id); + order.setStatus(Order.StatusEnum.PLACED); + + Order resp = apiInstance.placeOrder(order).block(); + + assertNull(resp); + } + + @Test + void placeOrderReturnsStatus400() { + long id = errorRaisingStringToInt("ReturnsStatus400"); + + Order order = new Order(); + order.setId(id); + order.setStatus(Order.StatusEnum.PLACED); + + WebClientResponseException exception = assertThrows( + WebClientResponseException.class, () -> { + apiInstance.placeOrder(order).block(); + }); + approveException(exception); + } +} \ No newline at end of file diff --git a/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/UserApiTest.java b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/UserApiTest.java new file mode 100644 index 00000000000..7815b8e864f --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/UserApiTest.java @@ -0,0 +1,303 @@ +package test_error_handling_server_stubs; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.openapi.example.api.UserApi; +import org.openapi.example.model.User; +import org.springframework.web.reactive.function.client.WebClientResponseException; + +import java.util.ArrayList; +import java.util.List; + +import static helper.ApiClientFactories.setUpUserApi; +import static helper.TestingHelper.approveException; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; + +class UserApiTest { + + UserApi apiInstance; + + @BeforeEach + void setUp() { + apiInstance = setUpUserApi(1236); + } + + @Test + void createUserThrowsApiException() { + User user = new User(); + user.setFirstName("ThrowsApiException"); + WebClientResponseException exception = assertThrows( + WebClientResponseException.class, () -> { + apiInstance.createUser(user).block(); + }); + approveException(exception); + } + + @Test + void createUserThrowsStdExceptionDerivedException() { + User user = new User(); + user.setFirstName("ThrowsStdExceptionDerivedException"); + WebClientResponseException exception = assertThrows( + WebClientResponseException.class, () -> { + apiInstance.createUser(user).block(); + }); + approveException(exception); + } + + @Test + void createUserThrowsInt() { + User user = new User(); + user.setFirstName("ThrowsInt"); + WebClientResponseException exception = assertThrows( + WebClientResponseException.class, () -> { + apiInstance.createUser(user).block(); + }); + approveException(exception); + } + + @Test + void createUserReturnsStatus0() { + User user = new User(); + user.setFirstName("ReturnsStatus0"); + + apiInstance.createUser(user).block(); + } + + + @Test + void createUserReturnsStatus400() { + User user = new User(); + user.setFirstName("ReturnsStatus400"); + WebClientResponseException exception = assertThrows( + WebClientResponseException.class, () -> { + apiInstance.createUser(user).block(); + }); + approveException(exception); + } + + @Test + void createUserReturnsStatus500() { + User user = new User(); + user.setFirstName("ReturnsStatus500"); + WebClientResponseException exception = assertThrows( + WebClientResponseException.class, () -> { + apiInstance.createUser(user).block(); + }); + approveException(exception); + } + + @Test + void createUsersWithArrayInputThrowsApiException() { + List users = new ArrayList<>(); + User user = new User(); + user.setFirstName("ThrowsApiException"); + users.add(user); + WebClientResponseException exception = assertThrows( + WebClientResponseException.class, () -> { + apiInstance.createUsersWithArrayInput(users).block(); + }); + approveException(exception); + } + + @Test + void createUsersWithArrayInputThrowsStdExceptionDerivedException() { + List users = new ArrayList<>(); + User user = new User(); + user.setFirstName("ThrowsStdExceptionDerivedException"); + users.add(user); + WebClientResponseException exception = assertThrows( + WebClientResponseException.class, () -> { + apiInstance.createUsersWithArrayInput(users).block(); + }); + approveException(exception); + } + + @Test + void createUsersWithArrayInputThrowsInt() { + List users = new ArrayList<>(); + User user = new User(); + user.setFirstName("ThrowsInt"); + users.add(user); + WebClientResponseException exception = assertThrows( + WebClientResponseException.class, () -> { + apiInstance.createUsersWithArrayInput(users).block(); + }); + approveException(exception); + } + + @Test + void createUsersWithArrayInputReturnsStatus0() { + List users = new ArrayList<>(); + User user = new User(); + user.setFirstName("ReturnsStatus0"); + users.add(user); + + apiInstance.createUsersWithArrayInput(users).block(); + } + + @Test + void createUsersWithArrayInputReturnsStatus400() { + List users = new ArrayList<>(); + User user = new User(); + user.setFirstName("ReturnsStatus400"); + users.add(user); + + WebClientResponseException exception = assertThrows( + WebClientResponseException.class, () -> { + apiInstance.createUsersWithArrayInput(users).block(); + }); + approveException(exception); + } + + @Test + void createUsersWithArrayInputReturnsStatus500() { + List users = new ArrayList<>(); + User user = new User(); + user.setFirstName("ReturnsStatus500"); + users.add(user); + + WebClientResponseException exception = assertThrows( + WebClientResponseException.class, () -> { + apiInstance.createUsersWithArrayInput(users).block(); + }); + approveException(exception); + } + + @Test + void createUsersWithListInputThrowsApiException() { + List users = new ArrayList<>(); + User user = new User(); + user.setFirstName("ThrowsApiException"); + users.add(user); + WebClientResponseException exception = assertThrows( + WebClientResponseException.class, () -> { + apiInstance.createUsersWithListInput(users).block(); + }); + approveException(exception); + } + + @Test + void createUsersWithListInputThrowsStdExceptionDerivedException() { + List users = new ArrayList<>(); + User user = new User(); + user.setFirstName("ThrowsStdExceptionDerivedException"); + users.add(user); + WebClientResponseException exception = assertThrows( + WebClientResponseException.class, () -> { + apiInstance.createUsersWithListInput(users).block(); + }); + approveException(exception); + } + + @Test + void createUsersWithListInputThrowsInt() { + List users = new ArrayList<>(); + User user = new User(); + user.setFirstName("ThrowsInt"); + users.add(user); + WebClientResponseException exception = assertThrows( + WebClientResponseException.class, () -> { + apiInstance.createUsersWithListInput(users).block(); + }); + approveException(exception); + } + + @Test + void createUsersWithListInputReturnsStatus0() { + List users = new ArrayList<>(); + User user = new User(); + user.setFirstName("ReturnsStatus0"); + users.add(user); + + apiInstance.createUsersWithListInput(users).block(); + } + + @Test + void createUsersWithListInputReturnsStatus400() { + List users = new ArrayList<>(); + User user = new User(); + user.setFirstName("ReturnsStatus400"); + users.add(user); + + WebClientResponseException exception = assertThrows( + WebClientResponseException.class, () -> { + apiInstance.createUsersWithListInput(users).block(); + }); + approveException(exception); + } + + @Test + void createUsersWithListInputReturnsStatus500() { + List users = new ArrayList<>(); + User user = new User(); + user.setFirstName("ReturnsStatus500"); + users.add(user); + + WebClientResponseException exception = assertThrows( + WebClientResponseException.class, () -> { + apiInstance.createUsersWithListInput(users).block(); + }); + approveException(exception); + } + + @Test + void loginUserThrowsApiException() { + WebClientResponseException exception = assertThrows( + WebClientResponseException.class, () -> { + apiInstance.loginUser("ThrowsApiException", "mypassword").block(); + }); + approveException(exception); + } + + @Test + void loginUserThrowsStdExceptionDerivedException() { + WebClientResponseException exception = assertThrows( + WebClientResponseException.class, () -> { + apiInstance.loginUser("ThrowsStdExceptionDerivedException", "mypassword").block(); + }); + approveException(exception); + } + + @Test + void loginUserThrowsInt() { + WebClientResponseException exception = assertThrows( + WebClientResponseException.class, () -> { + apiInstance.loginUser("ThrowsInt", "mypassword").block(); + }); + approveException(exception); + } + + @Test + void loginUserReturnsStatus200() { + String resp = apiInstance.loginUser("ReturnsStatus200", "mypassword").block(); + assertEquals("ReturnsStatus200", resp); + } + + @Test + void loginUserReturnsStatus400() { + WebClientResponseException exception = assertThrows( + WebClientResponseException.class, () -> { + apiInstance.loginUser("ReturnsStatus400", "mypassword").block(); + }); + approveException(exception); + } + + @Test + void loginUserReturnsStatus500() { + WebClientResponseException exception = assertThrows( + WebClientResponseException.class, () -> { + apiInstance.loginUser("ReturnsStatus500", "mypassword").block(); + }); + approveException(exception); + } + + @Test + void logoutUser() { + WebClientResponseException exception = assertThrows( + WebClientResponseException.class, () -> { + apiInstance.logoutUser().block(); + }); + approveException(exception); + } +} \ No newline at end of file diff --git a/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/PetApiTest.addPetInvalidEnumValue.approved.txt b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/PetApiTest.addPetInvalidEnumValue.approved.txt new file mode 100644 index 00000000000..4345dec9eef --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/PetApiTest.addPetInvalidEnumValue.approved.txt @@ -0,0 +1,3 @@ +Status code: 400 BAD_REQUEST +Reason: Value null not allowed +Response headers: [Content-Type:"text/plain", content-length:"22"] \ No newline at end of file diff --git a/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/PetApiTest.addPetThatReturnsStatus405.approved.txt b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/PetApiTest.addPetThatReturnsStatus405.approved.txt new file mode 100644 index 00000000000..0d8b7af92b4 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/PetApiTest.addPetThatReturnsStatus405.approved.txt @@ -0,0 +1,3 @@ +Status code: 405 METHOD_NOT_ALLOWED +Reason: Invalid input +Response headers: [Connection:"close", Content-Type:"text/plain"] \ No newline at end of file diff --git a/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/PetApiTest.addPetThatThrowsApiException.approved.txt b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/PetApiTest.addPetThatThrowsApiException.approved.txt new file mode 100644 index 00000000000..00656c64e91 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/PetApiTest.addPetThatThrowsApiException.approved.txt @@ -0,0 +1,3 @@ +Status code: 500 INTERNAL_SERVER_ERROR +Reason: ApiException raised +Response headers: [Connection:"close"] \ No newline at end of file diff --git a/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/PetApiTest.addPetThatThrowsInt.approved.txt b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/PetApiTest.addPetThatThrowsInt.approved.txt new file mode 100644 index 00000000000..5f4c01af399 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/PetApiTest.addPetThatThrowsInt.approved.txt @@ -0,0 +1,3 @@ +Status code: 500 INTERNAL_SERVER_ERROR +Reason: Unknown exception occurred +Response headers: [Connection:"close"] \ No newline at end of file diff --git a/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/PetApiTest.addPetThatThrowsStdExceptionDerivedException.approved.txt b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/PetApiTest.addPetThatThrowsStdExceptionDerivedException.approved.txt new file mode 100644 index 00000000000..bc8d2c1aebf --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/PetApiTest.addPetThatThrowsStdExceptionDerivedException.approved.txt @@ -0,0 +1,3 @@ +Status code: 500 INTERNAL_SERVER_ERROR +Reason: std::logic_error raised +Response headers: [Connection:"close"] \ No newline at end of file diff --git a/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/PetApiTest.deletePetReturnsStatus400.approved.txt b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/PetApiTest.deletePetReturnsStatus400.approved.txt new file mode 100644 index 00000000000..9ccdd07a3c7 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/PetApiTest.deletePetReturnsStatus400.approved.txt @@ -0,0 +1,3 @@ +Status code: 400 BAD_REQUEST +Reason: Invalid pet value +Response headers: [Connection:"close", Content-Type:"text/plain"] \ No newline at end of file diff --git a/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/PetApiTest.deletePetThrowsApiException.approved.txt b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/PetApiTest.deletePetThrowsApiException.approved.txt new file mode 100644 index 00000000000..00656c64e91 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/PetApiTest.deletePetThrowsApiException.approved.txt @@ -0,0 +1,3 @@ +Status code: 500 INTERNAL_SERVER_ERROR +Reason: ApiException raised +Response headers: [Connection:"close"] \ No newline at end of file diff --git a/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/PetApiTest.deletePetThrowsInt.approved.txt b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/PetApiTest.deletePetThrowsInt.approved.txt new file mode 100644 index 00000000000..5f4c01af399 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/PetApiTest.deletePetThrowsInt.approved.txt @@ -0,0 +1,3 @@ +Status code: 500 INTERNAL_SERVER_ERROR +Reason: Unknown exception occurred +Response headers: [Connection:"close"] \ No newline at end of file diff --git a/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/PetApiTest.deletePetThrowsStdExceptionDerivedException.approved.txt b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/PetApiTest.deletePetThrowsStdExceptionDerivedException.approved.txt new file mode 100644 index 00000000000..bc8d2c1aebf --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/PetApiTest.deletePetThrowsStdExceptionDerivedException.approved.txt @@ -0,0 +1,3 @@ +Status code: 500 INTERNAL_SERVER_ERROR +Reason: std::logic_error raised +Response headers: [Connection:"close"] \ No newline at end of file diff --git a/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/PetApiTest.getPetByIdReturnsStatus200.approved.txt b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/PetApiTest.getPetByIdReturnsStatus200.approved.txt new file mode 100644 index 00000000000..c03269b46b2 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/PetApiTest.getPetByIdReturnsStatus200.approved.txt @@ -0,0 +1,11 @@ +{ + "id" : 0, + "category" : { + "id" : 0, + "name" : "default-name" + }, + "name" : "MyPuppy", + "photoUrls" : [ ], + "tags" : null, + "status" : "available" +} diff --git a/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/PetApiTest.getPetByIdReturnsStatus400.approved.txt b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/PetApiTest.getPetByIdReturnsStatus400.approved.txt new file mode 100644 index 00000000000..59421a5e448 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/PetApiTest.getPetByIdReturnsStatus400.approved.txt @@ -0,0 +1,3 @@ +Status code: 400 BAD_REQUEST +Reason: Invalid ID supplied +Response headers: [Connection:"close", Content-Type:"text/plain"] \ No newline at end of file diff --git a/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/PetApiTest.getPetByIdReturnsStatus404.approved.txt b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/PetApiTest.getPetByIdReturnsStatus404.approved.txt new file mode 100644 index 00000000000..98f77ecd9a9 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/PetApiTest.getPetByIdReturnsStatus404.approved.txt @@ -0,0 +1,3 @@ +Status code: 404 NOT_FOUND +Reason: Pet not found +Response headers: [Connection:"close", Content-Type:"text/plain"] \ No newline at end of file diff --git a/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/PetApiTest.getPetByIdThrowsApiException.approved.txt b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/PetApiTest.getPetByIdThrowsApiException.approved.txt new file mode 100644 index 00000000000..00656c64e91 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/PetApiTest.getPetByIdThrowsApiException.approved.txt @@ -0,0 +1,3 @@ +Status code: 500 INTERNAL_SERVER_ERROR +Reason: ApiException raised +Response headers: [Connection:"close"] \ No newline at end of file diff --git a/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/PetApiTest.getPetByIdThrowsInt.approved.txt b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/PetApiTest.getPetByIdThrowsInt.approved.txt new file mode 100644 index 00000000000..5f4c01af399 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/PetApiTest.getPetByIdThrowsInt.approved.txt @@ -0,0 +1,3 @@ +Status code: 500 INTERNAL_SERVER_ERROR +Reason: Unknown exception occurred +Response headers: [Connection:"close"] \ No newline at end of file diff --git a/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/PetApiTest.getPetByIdThrowsStdExceptionDerivedException.approved.txt b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/PetApiTest.getPetByIdThrowsStdExceptionDerivedException.approved.txt new file mode 100644 index 00000000000..bc8d2c1aebf --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/PetApiTest.getPetByIdThrowsStdExceptionDerivedException.approved.txt @@ -0,0 +1,3 @@ +Status code: 500 INTERNAL_SERVER_ERROR +Reason: std::logic_error raised +Response headers: [Connection:"close"] \ No newline at end of file diff --git a/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/PetApiTest.updatePetReturnsStatus400.approved.txt b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/PetApiTest.updatePetReturnsStatus400.approved.txt new file mode 100644 index 00000000000..59421a5e448 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/PetApiTest.updatePetReturnsStatus400.approved.txt @@ -0,0 +1,3 @@ +Status code: 400 BAD_REQUEST +Reason: Invalid ID supplied +Response headers: [Connection:"close", Content-Type:"text/plain"] \ No newline at end of file diff --git a/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/PetApiTest.updatePetReturnsStatus405.approved.txt b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/PetApiTest.updatePetReturnsStatus405.approved.txt new file mode 100644 index 00000000000..7eb5d3588fd --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/PetApiTest.updatePetReturnsStatus405.approved.txt @@ -0,0 +1,3 @@ +Status code: 405 METHOD_NOT_ALLOWED +Reason: Validation exception +Response headers: [Connection:"close", Content-Type:"text/plain"] \ No newline at end of file diff --git a/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/PetApiTest.updatePetReturnsStatus500.approved.txt b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/PetApiTest.updatePetReturnsStatus500.approved.txt new file mode 100644 index 00000000000..8e19ce45911 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/PetApiTest.updatePetReturnsStatus500.approved.txt @@ -0,0 +1,3 @@ +Status code: 500 INTERNAL_SERVER_ERROR +Reason: +Response headers: [Connection:"close"] \ No newline at end of file diff --git a/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/PetApiTest.updatePetThrowsApiException.approved.txt b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/PetApiTest.updatePetThrowsApiException.approved.txt new file mode 100644 index 00000000000..00656c64e91 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/PetApiTest.updatePetThrowsApiException.approved.txt @@ -0,0 +1,3 @@ +Status code: 500 INTERNAL_SERVER_ERROR +Reason: ApiException raised +Response headers: [Connection:"close"] \ No newline at end of file diff --git a/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/PetApiTest.updatePetThrowsInt.approved.txt b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/PetApiTest.updatePetThrowsInt.approved.txt new file mode 100644 index 00000000000..5f4c01af399 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/PetApiTest.updatePetThrowsInt.approved.txt @@ -0,0 +1,3 @@ +Status code: 500 INTERNAL_SERVER_ERROR +Reason: Unknown exception occurred +Response headers: [Connection:"close"] \ No newline at end of file diff --git a/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/PetApiTest.updatePetThrowsStdExceptionDerivedException.approved.txt b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/PetApiTest.updatePetThrowsStdExceptionDerivedException.approved.txt new file mode 100644 index 00000000000..bc8d2c1aebf --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/PetApiTest.updatePetThrowsStdExceptionDerivedException.approved.txt @@ -0,0 +1,3 @@ +Status code: 500 INTERNAL_SERVER_ERROR +Reason: std::logic_error raised +Response headers: [Connection:"close"] \ No newline at end of file diff --git a/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/StoreApiTest.deleteOrderReturnsStatus400.approved.txt b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/StoreApiTest.deleteOrderReturnsStatus400.approved.txt new file mode 100644 index 00000000000..59421a5e448 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/StoreApiTest.deleteOrderReturnsStatus400.approved.txt @@ -0,0 +1,3 @@ +Status code: 400 BAD_REQUEST +Reason: Invalid ID supplied +Response headers: [Connection:"close", Content-Type:"text/plain"] \ No newline at end of file diff --git a/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/StoreApiTest.deleteOrderReturnsStatus404.approved.txt b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/StoreApiTest.deleteOrderReturnsStatus404.approved.txt new file mode 100644 index 00000000000..d905f316fb6 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/StoreApiTest.deleteOrderReturnsStatus404.approved.txt @@ -0,0 +1,3 @@ +Status code: 404 NOT_FOUND +Reason: Order not found +Response headers: [Connection:"close", Content-Type:"text/plain"] \ No newline at end of file diff --git a/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/StoreApiTest.deleteOrderReturnsStatus405.approved.txt b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/StoreApiTest.deleteOrderReturnsStatus405.approved.txt new file mode 100644 index 00000000000..4b8f7d15f1c --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/StoreApiTest.deleteOrderReturnsStatus405.approved.txt @@ -0,0 +1,3 @@ +Status code: 405 METHOD_NOT_ALLOWED +Reason: +Response headers: [Connection:"close"] \ No newline at end of file diff --git a/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/StoreApiTest.deleteOrderThrowsApiException.approved.txt b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/StoreApiTest.deleteOrderThrowsApiException.approved.txt new file mode 100644 index 00000000000..00656c64e91 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/StoreApiTest.deleteOrderThrowsApiException.approved.txt @@ -0,0 +1,3 @@ +Status code: 500 INTERNAL_SERVER_ERROR +Reason: ApiException raised +Response headers: [Connection:"close"] \ No newline at end of file diff --git a/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/StoreApiTest.deleteOrderThrowsInt.approved.txt b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/StoreApiTest.deleteOrderThrowsInt.approved.txt new file mode 100644 index 00000000000..5f4c01af399 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/StoreApiTest.deleteOrderThrowsInt.approved.txt @@ -0,0 +1,3 @@ +Status code: 500 INTERNAL_SERVER_ERROR +Reason: Unknown exception occurred +Response headers: [Connection:"close"] \ No newline at end of file diff --git a/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/StoreApiTest.deleteOrderThrowsStdExceptionDerivedException.approved.txt b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/StoreApiTest.deleteOrderThrowsStdExceptionDerivedException.approved.txt new file mode 100644 index 00000000000..bc8d2c1aebf --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/StoreApiTest.deleteOrderThrowsStdExceptionDerivedException.approved.txt @@ -0,0 +1,3 @@ +Status code: 500 INTERNAL_SERVER_ERROR +Reason: std::logic_error raised +Response headers: [Connection:"close"] \ No newline at end of file diff --git a/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/StoreApiTest.getOrderByIdReturnsStatus400.approved.txt b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/StoreApiTest.getOrderByIdReturnsStatus400.approved.txt new file mode 100644 index 00000000000..59421a5e448 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/StoreApiTest.getOrderByIdReturnsStatus400.approved.txt @@ -0,0 +1,3 @@ +Status code: 400 BAD_REQUEST +Reason: Invalid ID supplied +Response headers: [Connection:"close", Content-Type:"text/plain"] \ No newline at end of file diff --git a/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/StoreApiTest.getOrderByIdReturnsStatus404.approved.txt b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/StoreApiTest.getOrderByIdReturnsStatus404.approved.txt new file mode 100644 index 00000000000..d905f316fb6 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/StoreApiTest.getOrderByIdReturnsStatus404.approved.txt @@ -0,0 +1,3 @@ +Status code: 404 NOT_FOUND +Reason: Order not found +Response headers: [Connection:"close", Content-Type:"text/plain"] \ No newline at end of file diff --git a/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/StoreApiTest.getOrderByIdThrowsApiException.approved.txt b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/StoreApiTest.getOrderByIdThrowsApiException.approved.txt new file mode 100644 index 00000000000..00656c64e91 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/StoreApiTest.getOrderByIdThrowsApiException.approved.txt @@ -0,0 +1,3 @@ +Status code: 500 INTERNAL_SERVER_ERROR +Reason: ApiException raised +Response headers: [Connection:"close"] \ No newline at end of file diff --git a/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/StoreApiTest.getOrderByIdThrowsInt.approved.txt b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/StoreApiTest.getOrderByIdThrowsInt.approved.txt new file mode 100644 index 00000000000..5f4c01af399 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/StoreApiTest.getOrderByIdThrowsInt.approved.txt @@ -0,0 +1,3 @@ +Status code: 500 INTERNAL_SERVER_ERROR +Reason: Unknown exception occurred +Response headers: [Connection:"close"] \ No newline at end of file diff --git a/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/StoreApiTest.getOrderByIdThrowsStdExceptionDerivedException.approved.txt b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/StoreApiTest.getOrderByIdThrowsStdExceptionDerivedException.approved.txt new file mode 100644 index 00000000000..bc8d2c1aebf --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/StoreApiTest.getOrderByIdThrowsStdExceptionDerivedException.approved.txt @@ -0,0 +1,3 @@ +Status code: 500 INTERNAL_SERVER_ERROR +Reason: std::logic_error raised +Response headers: [Connection:"close"] \ No newline at end of file diff --git a/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/StoreApiTest.placeOrderReturnsStatus400.approved.txt b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/StoreApiTest.placeOrderReturnsStatus400.approved.txt new file mode 100644 index 00000000000..d951d2bf99a --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/StoreApiTest.placeOrderReturnsStatus400.approved.txt @@ -0,0 +1,3 @@ +Status code: 400 BAD_REQUEST +Reason: Invalid Order +Response headers: [Connection:"close", Content-Type:"text/plain"] \ No newline at end of file diff --git a/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/StoreApiTest.placeOrderThrowsApiException.approved.txt b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/StoreApiTest.placeOrderThrowsApiException.approved.txt new file mode 100644 index 00000000000..00656c64e91 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/StoreApiTest.placeOrderThrowsApiException.approved.txt @@ -0,0 +1,3 @@ +Status code: 500 INTERNAL_SERVER_ERROR +Reason: ApiException raised +Response headers: [Connection:"close"] \ No newline at end of file diff --git a/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/StoreApiTest.placeOrderThrowsInt.approved.txt b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/StoreApiTest.placeOrderThrowsInt.approved.txt new file mode 100644 index 00000000000..5f4c01af399 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/StoreApiTest.placeOrderThrowsInt.approved.txt @@ -0,0 +1,3 @@ +Status code: 500 INTERNAL_SERVER_ERROR +Reason: Unknown exception occurred +Response headers: [Connection:"close"] \ No newline at end of file diff --git a/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/StoreApiTest.placeOrderThrowsStdExceptionDerivedException.approved.txt b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/StoreApiTest.placeOrderThrowsStdExceptionDerivedException.approved.txt new file mode 100644 index 00000000000..bc8d2c1aebf --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/StoreApiTest.placeOrderThrowsStdExceptionDerivedException.approved.txt @@ -0,0 +1,3 @@ +Status code: 500 INTERNAL_SERVER_ERROR +Reason: std::logic_error raised +Response headers: [Connection:"close"] \ No newline at end of file diff --git a/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/UserApiTest.createUserReturnsStatus400.approved.txt b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/UserApiTest.createUserReturnsStatus400.approved.txt new file mode 100644 index 00000000000..32ade16b26a --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/UserApiTest.createUserReturnsStatus400.approved.txt @@ -0,0 +1,3 @@ +Status code: 400 BAD_REQUEST +Reason: +Response headers: [Connection:"close"] \ No newline at end of file diff --git a/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/UserApiTest.createUserReturnsStatus500.approved.txt b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/UserApiTest.createUserReturnsStatus500.approved.txt new file mode 100644 index 00000000000..8e19ce45911 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/UserApiTest.createUserReturnsStatus500.approved.txt @@ -0,0 +1,3 @@ +Status code: 500 INTERNAL_SERVER_ERROR +Reason: +Response headers: [Connection:"close"] \ No newline at end of file diff --git a/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/UserApiTest.createUserThrowsApiException.approved.txt b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/UserApiTest.createUserThrowsApiException.approved.txt new file mode 100644 index 00000000000..00656c64e91 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/UserApiTest.createUserThrowsApiException.approved.txt @@ -0,0 +1,3 @@ +Status code: 500 INTERNAL_SERVER_ERROR +Reason: ApiException raised +Response headers: [Connection:"close"] \ No newline at end of file diff --git a/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/UserApiTest.createUserThrowsInt.approved.txt b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/UserApiTest.createUserThrowsInt.approved.txt new file mode 100644 index 00000000000..5f4c01af399 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/UserApiTest.createUserThrowsInt.approved.txt @@ -0,0 +1,3 @@ +Status code: 500 INTERNAL_SERVER_ERROR +Reason: Unknown exception occurred +Response headers: [Connection:"close"] \ No newline at end of file diff --git a/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/UserApiTest.createUserThrowsStdExceptionDerivedException.approved.txt b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/UserApiTest.createUserThrowsStdExceptionDerivedException.approved.txt new file mode 100644 index 00000000000..bc8d2c1aebf --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/UserApiTest.createUserThrowsStdExceptionDerivedException.approved.txt @@ -0,0 +1,3 @@ +Status code: 500 INTERNAL_SERVER_ERROR +Reason: std::logic_error raised +Response headers: [Connection:"close"] \ No newline at end of file diff --git a/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/UserApiTest.createUsersWithArrayInputReturnsStatus400.approved.txt b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/UserApiTest.createUsersWithArrayInputReturnsStatus400.approved.txt new file mode 100644 index 00000000000..32ade16b26a --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/UserApiTest.createUsersWithArrayInputReturnsStatus400.approved.txt @@ -0,0 +1,3 @@ +Status code: 400 BAD_REQUEST +Reason: +Response headers: [Connection:"close"] \ No newline at end of file diff --git a/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/UserApiTest.createUsersWithArrayInputReturnsStatus500.approved.txt b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/UserApiTest.createUsersWithArrayInputReturnsStatus500.approved.txt new file mode 100644 index 00000000000..8e19ce45911 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/UserApiTest.createUsersWithArrayInputReturnsStatus500.approved.txt @@ -0,0 +1,3 @@ +Status code: 500 INTERNAL_SERVER_ERROR +Reason: +Response headers: [Connection:"close"] \ No newline at end of file diff --git a/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/UserApiTest.createUsersWithArrayInputThrowsApiException.approved.txt b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/UserApiTest.createUsersWithArrayInputThrowsApiException.approved.txt new file mode 100644 index 00000000000..00656c64e91 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/UserApiTest.createUsersWithArrayInputThrowsApiException.approved.txt @@ -0,0 +1,3 @@ +Status code: 500 INTERNAL_SERVER_ERROR +Reason: ApiException raised +Response headers: [Connection:"close"] \ No newline at end of file diff --git a/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/UserApiTest.createUsersWithArrayInputThrowsInt.approved.txt b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/UserApiTest.createUsersWithArrayInputThrowsInt.approved.txt new file mode 100644 index 00000000000..5f4c01af399 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/UserApiTest.createUsersWithArrayInputThrowsInt.approved.txt @@ -0,0 +1,3 @@ +Status code: 500 INTERNAL_SERVER_ERROR +Reason: Unknown exception occurred +Response headers: [Connection:"close"] \ No newline at end of file diff --git a/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/UserApiTest.createUsersWithArrayInputThrowsStdExceptionDerivedException.approved.txt b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/UserApiTest.createUsersWithArrayInputThrowsStdExceptionDerivedException.approved.txt new file mode 100644 index 00000000000..bc8d2c1aebf --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/UserApiTest.createUsersWithArrayInputThrowsStdExceptionDerivedException.approved.txt @@ -0,0 +1,3 @@ +Status code: 500 INTERNAL_SERVER_ERROR +Reason: std::logic_error raised +Response headers: [Connection:"close"] \ No newline at end of file diff --git a/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/UserApiTest.createUsersWithListInputReturnsStatus400.approved.txt b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/UserApiTest.createUsersWithListInputReturnsStatus400.approved.txt new file mode 100644 index 00000000000..32ade16b26a --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/UserApiTest.createUsersWithListInputReturnsStatus400.approved.txt @@ -0,0 +1,3 @@ +Status code: 400 BAD_REQUEST +Reason: +Response headers: [Connection:"close"] \ No newline at end of file diff --git a/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/UserApiTest.createUsersWithListInputReturnsStatus500.approved.txt b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/UserApiTest.createUsersWithListInputReturnsStatus500.approved.txt new file mode 100644 index 00000000000..8e19ce45911 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/UserApiTest.createUsersWithListInputReturnsStatus500.approved.txt @@ -0,0 +1,3 @@ +Status code: 500 INTERNAL_SERVER_ERROR +Reason: +Response headers: [Connection:"close"] \ No newline at end of file diff --git a/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/UserApiTest.createUsersWithListInputThrowsApiException.approved.txt b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/UserApiTest.createUsersWithListInputThrowsApiException.approved.txt new file mode 100644 index 00000000000..00656c64e91 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/UserApiTest.createUsersWithListInputThrowsApiException.approved.txt @@ -0,0 +1,3 @@ +Status code: 500 INTERNAL_SERVER_ERROR +Reason: ApiException raised +Response headers: [Connection:"close"] \ No newline at end of file diff --git a/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/UserApiTest.createUsersWithListInputThrowsInt.approved.txt b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/UserApiTest.createUsersWithListInputThrowsInt.approved.txt new file mode 100644 index 00000000000..5f4c01af399 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/UserApiTest.createUsersWithListInputThrowsInt.approved.txt @@ -0,0 +1,3 @@ +Status code: 500 INTERNAL_SERVER_ERROR +Reason: Unknown exception occurred +Response headers: [Connection:"close"] \ No newline at end of file diff --git a/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/UserApiTest.createUsersWithListInputThrowsStdExceptionDerivedException.approved.txt b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/UserApiTest.createUsersWithListInputThrowsStdExceptionDerivedException.approved.txt new file mode 100644 index 00000000000..bc8d2c1aebf --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/UserApiTest.createUsersWithListInputThrowsStdExceptionDerivedException.approved.txt @@ -0,0 +1,3 @@ +Status code: 500 INTERNAL_SERVER_ERROR +Reason: std::logic_error raised +Response headers: [Connection:"close"] \ No newline at end of file diff --git a/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/UserApiTest.loginUserReturnsStatus400.approved.txt b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/UserApiTest.loginUserReturnsStatus400.approved.txt new file mode 100644 index 00000000000..534bb97a399 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/UserApiTest.loginUserReturnsStatus400.approved.txt @@ -0,0 +1,3 @@ +Status code: 400 BAD_REQUEST +Reason: Invalid username/password supplied +Response headers: [Connection:"close", Content-Type:"text/plain"] \ No newline at end of file diff --git a/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/UserApiTest.loginUserReturnsStatus500.approved.txt b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/UserApiTest.loginUserReturnsStatus500.approved.txt new file mode 100644 index 00000000000..8e19ce45911 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/UserApiTest.loginUserReturnsStatus500.approved.txt @@ -0,0 +1,3 @@ +Status code: 500 INTERNAL_SERVER_ERROR +Reason: +Response headers: [Connection:"close"] \ No newline at end of file diff --git a/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/UserApiTest.loginUserThrowsApiException.approved.txt b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/UserApiTest.loginUserThrowsApiException.approved.txt new file mode 100644 index 00000000000..00656c64e91 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/UserApiTest.loginUserThrowsApiException.approved.txt @@ -0,0 +1,3 @@ +Status code: 500 INTERNAL_SERVER_ERROR +Reason: ApiException raised +Response headers: [Connection:"close"] \ No newline at end of file diff --git a/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/UserApiTest.loginUserThrowsInt.approved.txt b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/UserApiTest.loginUserThrowsInt.approved.txt new file mode 100644 index 00000000000..5f4c01af399 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/UserApiTest.loginUserThrowsInt.approved.txt @@ -0,0 +1,3 @@ +Status code: 500 INTERNAL_SERVER_ERROR +Reason: Unknown exception occurred +Response headers: [Connection:"close"] \ No newline at end of file diff --git a/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/UserApiTest.loginUserThrowsStdExceptionDerivedException.approved.txt b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/UserApiTest.loginUserThrowsStdExceptionDerivedException.approved.txt new file mode 100644 index 00000000000..bc8d2c1aebf --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/UserApiTest.loginUserThrowsStdExceptionDerivedException.approved.txt @@ -0,0 +1,3 @@ +Status code: 500 INTERNAL_SERVER_ERROR +Reason: std::logic_error raised +Response headers: [Connection:"close"] \ No newline at end of file diff --git a/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/UserApiTest.logoutUser.approved.txt b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/UserApiTest.logoutUser.approved.txt new file mode 100644 index 00000000000..5f4c01af399 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_error_handling_server_stubs/approval_files/UserApiTest.logoutUser.approved.txt @@ -0,0 +1,3 @@ +Status code: 500 INTERNAL_SERVER_ERROR +Reason: Unknown exception occurred +Response headers: [Connection:"close"] \ No newline at end of file diff --git a/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_simple_server_stubs/PackageSettings.java b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_simple_server_stubs/PackageSettings.java new file mode 100644 index 00000000000..f5ccf2b2b38 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_simple_server_stubs/PackageSettings.java @@ -0,0 +1,8 @@ +package test_simple_server_stubs; + +import org.approvaltests.reporters.linux.MeldMergeReporter; + +public class PackageSettings { + public static String UseApprovalSubdirectory = "approval_files"; + public static MeldMergeReporter UseReporter = MeldMergeReporter.INSTANCE; +} diff --git a/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_simple_server_stubs/PetApiTest.java b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_simple_server_stubs/PetApiTest.java new file mode 100644 index 00000000000..e7d3fe4ad7a --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_simple_server_stubs/PetApiTest.java @@ -0,0 +1,67 @@ +package test_simple_server_stubs; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.openapi.example.api.PetApi; +import org.openapi.example.model.Category; +import org.openapi.example.model.Pet; +import org.openapi.example.model.Tag; +import java.util.List; + +import static helper.ApiClientFactories.setUpPetApi; +import static helper.TestingHelper.approveResponseAsJson; + +class PetApiTest { + + PetApi apiInstance; + + @BeforeEach + void setUp() { + apiInstance = setUpPetApi(1235); + } + + @Test + void addPet() { + Pet pet = createTestPet(); + Pet responsePet = apiInstance.addPet(pet).block(); + approveResponseAsJson(responsePet); + } + + @Test + void deletePet() { + apiInstance.deletePet(1L, "myApiKey").block(); + } + + @Test + void getPetById() { + Pet responsePet = apiInstance.getPetById(99L).block(); + approveResponseAsJson(responsePet); + } + + @Test + void updatePet() { + Pet pet = createTestPet(); + apiInstance.updatePet(pet).block(); + } + + private Pet createTestPet() { + Pet pet = new Pet(); + + pet.setId(12L); + pet.setName("MyPet"); + pet.setStatus(Pet.StatusEnum.SOLD); + + Tag tag = new Tag(); + tag.name("MyTag"); + pet.addTagsItem(tag); + + Category category = new Category(); + category.setId(1L); + category.setName("MyCategory"); + pet.setCategory(category); + + pet.addPhotoUrlsItem("myUrl"); + + return pet; + } +} \ No newline at end of file diff --git a/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_simple_server_stubs/StoreApiTest.java b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_simple_server_stubs/StoreApiTest.java new file mode 100644 index 00000000000..2a17d9aeaeb --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_simple_server_stubs/StoreApiTest.java @@ -0,0 +1,48 @@ +package test_simple_server_stubs; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.openapi.example.api.StoreApi; +import org.openapi.example.model.Order; + +import java.util.Map; + +import static helper.ApiClientFactories.setUpStoreApi; +import static helper.TestingHelper.approveResponseAsJson; +import static org.junit.jupiter.api.Assertions.*; + +class StoreApiTest { + + StoreApi apiInstance; + + @BeforeEach + void setUp() { + apiInstance = setUpStoreApi(1235); + } + + @Test + void deleteOrder() { + apiInstance.deleteOrder("myOrderId").block(); + } + + @Test + void getInventory() { + Map inventory = apiInstance.getInventory().block(); + approveResponseAsJson(inventory); + } + + @Test + void getOrderById() { + Order order = apiInstance.getOrderById(123L).block(); + approveResponseAsJson(order); + } + + @Test + void placeOrder() { + Order order = new Order(); + order.setId(9876L); + order.setStatus(Order.StatusEnum.PLACED); + Order response = apiInstance.placeOrder(order).block(); + approveResponseAsJson(response); + } +} \ No newline at end of file diff --git a/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_simple_server_stubs/UserApiTest.java b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_simple_server_stubs/UserApiTest.java new file mode 100644 index 00000000000..7479a5966b1 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_simple_server_stubs/UserApiTest.java @@ -0,0 +1,68 @@ +package test_simple_server_stubs; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.openapi.example.api.UserApi; +import org.openapi.example.model.User; + +import java.util.ArrayList; +import java.util.List; + +import static helper.ApiClientFactories.setUpUserApi; +import static org.junit.jupiter.api.Assertions.assertEquals; + +class UserApiTest { + + UserApi apiInstance; + + @BeforeEach + void setUp() { + apiInstance = setUpUserApi(1235); + } + + @Test + void createUser() { + User user = new User(); + apiInstance.createUser(user).block(); + } + + @Test + void createUsersWithArrayInput() { + List users = createUsersForTests(); + apiInstance.createUsersWithArrayInput(users).block(); + } + + @Test + void createUsersWithListInput() { + List users = createUsersForTests(); + apiInstance.createUsersWithListInput(users).block(); + } + + @Test + void loginUser() { + final String username = "user1"; + String response = apiInstance.loginUser(username, "pa55w0rd").block(); + assertEquals(response, username); + } + + @Test + void logoutUser() { + apiInstance.logoutUser().block(); + } + + + private static List createUsersForTests() { + List users = new ArrayList<>(); + + User user1 = new User(); + user1.setUsername("User1"); + user1.setId(7L); + users.add(user1); + + User user2 = new User(); + user2.setUsername("User2"); + user2.setId(8L); + users.add(user2); + return users; + } +} \ No newline at end of file diff --git a/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_simple_server_stubs/approval_files/PetApiTest.addPet.approved.txt b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_simple_server_stubs/approval_files/PetApiTest.addPet.approved.txt new file mode 100644 index 00000000000..cc99464f6ef --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_simple_server_stubs/approval_files/PetApiTest.addPet.approved.txt @@ -0,0 +1,8 @@ +{ + "id" : null, + "category" : null, + "name" : null, + "photoUrls" : [ ], + "tags" : null, + "status" : null +} \ No newline at end of file diff --git a/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_simple_server_stubs/approval_files/PetApiTest.getPetById.approved.txt b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_simple_server_stubs/approval_files/PetApiTest.getPetById.approved.txt new file mode 100644 index 00000000000..588d5364d1b --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_simple_server_stubs/approval_files/PetApiTest.getPetById.approved.txt @@ -0,0 +1,11 @@ +{ + "id" : 23, + "category" : { + "id" : 0, + "name" : "default-name" + }, + "name" : "HelloPet", + "photoUrls" : [ ], + "tags" : null, + "status" : "available" +} diff --git a/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_simple_server_stubs/approval_files/StoreApiTest.getInventory.approved.txt b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_simple_server_stubs/approval_files/StoreApiTest.getInventory.approved.txt new file mode 100644 index 00000000000..ce4b5e94738 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_simple_server_stubs/approval_files/StoreApiTest.getInventory.approved.txt @@ -0,0 +1,4 @@ +{ + "MyPet" : 123, + "OtherPet" : 99 +} \ No newline at end of file diff --git a/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_simple_server_stubs/approval_files/StoreApiTest.getOrderById.approved.txt b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_simple_server_stubs/approval_files/StoreApiTest.getOrderById.approved.txt new file mode 100644 index 00000000000..b2027050433 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_simple_server_stubs/approval_files/StoreApiTest.getOrderById.approved.txt @@ -0,0 +1,8 @@ +{ + "id" : 123, + "petId" : 4444, + "quantity" : 3, + "shipDate" : "2011-09-21T17:32:28Z", + "status" : "placed", + "complete" : false +} \ No newline at end of file diff --git a/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_simple_server_stubs/approval_files/StoreApiTest.placeOrder.approved.txt b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_simple_server_stubs/approval_files/StoreApiTest.placeOrder.approved.txt new file mode 100644 index 00000000000..e361d95edf0 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/java_client_tests/java_client/src/test/java/test_simple_server_stubs/approval_files/StoreApiTest.placeOrder.approved.txt @@ -0,0 +1,8 @@ +{ + "id" : 9876, + "petId" : 0, + "quantity" : 0, + "shipDate" : "2011-01-12T23:24:02Z", + "status" : "placed", + "complete" : false +} \ No newline at end of file diff --git a/samples/server/petstore/cpp-restbed/test/java_client_tests/tests_servers/CMakeLists.txt b/samples/server/petstore/cpp-restbed/test/java_client_tests/tests_servers/CMakeLists.txt new file mode 100644 index 00000000000..4b06953e816 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/java_client_tests/tests_servers/CMakeLists.txt @@ -0,0 +1,3 @@ +add_subdirectory(default_unimplemented_server_stubs) +add_subdirectory(simple_server_stubs) +add_subdirectory(error_handling_server_stubs) \ No newline at end of file diff --git a/samples/server/petstore/cpp-restbed/test/java_client_tests/tests_servers/default_unimplemented_server_stubs/CMakeLists.txt b/samples/server/petstore/cpp-restbed/test/java_client_tests/tests_servers/default_unimplemented_server_stubs/CMakeLists.txt new file mode 100644 index 00000000000..6566d191c56 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/java_client_tests/tests_servers/default_unimplemented_server_stubs/CMakeLists.txt @@ -0,0 +1,10 @@ +set(TARGET_NAME default_unimplemented_server_stubs) + +add_executable(${TARGET_NAME}) + +target_sources(${TARGET_NAME} + PRIVATE main.cpp) + +target_link_libraries(${TARGET_NAME} PRIVATE org.openapitools.server.apiStubs) + +run_java_client_test_for_cpp_server(${TARGET_NAME}) \ No newline at end of file diff --git a/samples/server/petstore/cpp-restbed/test/java_client_tests/tests_servers/default_unimplemented_server_stubs/main.cpp b/samples/server/petstore/cpp-restbed/test/java_client_tests/tests_servers/default_unimplemented_server_stubs/main.cpp new file mode 100644 index 00000000000..a2ad83bc608 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/java_client_tests/tests_servers/default_unimplemented_server_stubs/main.cpp @@ -0,0 +1,24 @@ +#include "api/PetApi.h" +#include "api/StoreApi.h" +#include "api/UserApi.h" + +using namespace org::openapitools::server::api; + +int main() { + const auto service = std::make_shared(); + + auto petApi = PetApi(service); + petApi.publishDefaultResources(); + + auto storeApi = StoreApi(service); + storeApi.publishDefaultResources(); + + auto userApi = UserApi(service); + userApi.publishDefaultResources(); + + const auto settings = std::make_shared(); + settings->set_port(1234); + + service->start(settings); + +} \ No newline at end of file diff --git a/samples/server/petstore/cpp-restbed/test/java_client_tests/tests_servers/error_handling_server_stubs/CMakeLists.txt b/samples/server/petstore/cpp-restbed/test/java_client_tests/tests_servers/error_handling_server_stubs/CMakeLists.txt new file mode 100644 index 00000000000..23a4633dba2 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/java_client_tests/tests_servers/error_handling_server_stubs/CMakeLists.txt @@ -0,0 +1,10 @@ +set(TARGET_NAME error_handling_server_stubs) + +add_executable(${TARGET_NAME}) + +target_sources(${TARGET_NAME} + PRIVATE main.cpp) + +target_link_libraries(${TARGET_NAME} PRIVATE org.openapitools.server.apiStubs) + +run_java_client_test_for_cpp_server(${TARGET_NAME}) \ No newline at end of file diff --git a/samples/server/petstore/cpp-restbed/test/java_client_tests/tests_servers/error_handling_server_stubs/main.cpp b/samples/server/petstore/cpp-restbed/test/java_client_tests/tests_servers/error_handling_server_stubs/main.cpp new file mode 100644 index 00000000000..d151b1c2895 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/java_client_tests/tests_servers/error_handling_server_stubs/main.cpp @@ -0,0 +1,218 @@ +#include "api/PetApi.h" +#include "api/StoreApi.h" +#include "api/UserApi.h" + +#include + +#include +void sig_handler(int signum){ + printf("\nSIGINT received!\n"); + exit(0); +} + +using namespace org::openapitools::server::api; +using namespace org::openapitools::server::api::PetApiResources; +using namespace org::openapitools::server::api::StoreApiResources; +using namespace org::openapitools::server::api::UserApiResources; + +namespace { +const auto RETURN_STATUS = std::string("ReturnsStatus"); + +bool isReturnStatusString(const std::string &errorType) { + return errorType.rfind(RETURN_STATUS, 0) == 0; +} + +int extractReturnStatus(const std::string &errorType) { + assert(isReturnStatusString(errorType)); + + auto returnValString = errorType; + returnValString.erase(0, RETURN_STATUS.length()); + + return std::stoi(returnValString); +} + + +template +std::pair +raiseErrorForTesting(const RETURN_T &modelObj, + const std::string &errorType) { + if ("ThrowsApiException" == errorType) { + throw API_EXCEPTION_T(500, "ApiException raised"); + } else if ("ThrowsStdExceptionDerivedException" == errorType) { + throw std::logic_error("std::logic_error raised"); + } else if ("ThrowsInt" == errorType) { + throw int(1); + } else if (isReturnStatusString(errorType)) { + auto retStatus = extractReturnStatus(errorType); + return {retStatus, modelObj}; + } + + return std::make_pair(500, modelObj); +} + +std::string intToErrorRaisingString(const int64_t &id) { + std::string errorType; + switch(id) { + case 9100: errorType = "ThrowsApiException"; + break; + case 9200: errorType = "ThrowsStdExceptionDerivedException"; + break; + case 9300: errorType = "ThrowsInt"; + break; + default: errorType = RETURN_STATUS + std::to_string(id); + } + return errorType; +} + +} // namespace + +class MyPetApiPetResource : public PetResource { +public: + int handler_POST(Pet &pet) override { + const std::string &name = pet.getName(); + int status; + Pet pet_; + std::tie(status, pet_) = raiseErrorForTesting(pet, name); + return status; + } + + int handler_PUT(Pet &pet) override { + const std::string &name = pet.getName(); + int status; + Pet pet_; + std::tie(status, pet_) = raiseErrorForTesting(pet, name); + return status; + } +}; + +class MyPetApiPetPetIdResource : public PetPetIdResource { +public: + int handler_DELETE(int64_t &petId, + std::string &api_key) override { + int status; + Pet pet; + std::tie(status, pet) = raiseErrorForTesting(Pet(), api_key); + return status; + } + + std::pair + handler_GET(int64_t &id) override { + std::string errorType = intToErrorRaisingString(id); + + auto pet = Pet(); + pet.setName("MyPuppy"); + pet.setStatus("available"); + + return raiseErrorForTesting(pet, errorType); + } +}; + +class MyStoreApiStoreOrderOrderIdResource : public StoreOrderOrder_idResource { +public: + int handler_DELETE(std::string &orderId) override { + int status; + Pet pet; + std::tie(status, pet) = raiseErrorForTesting(Pet(), orderId); + return status; + } + + std::pair + handler_GET(int64_t &orderId) override { + std::string errorType = intToErrorRaisingString(orderId); + const auto order = Order(); + return raiseErrorForTesting(order, errorType); + } +}; + +class MyStoreApiStoreInventoryResource : public StoreInventoryResource { +public: + std::pair> handler_GET() override { + std::map ret; + return {300, ret}; + } +}; + +class MyStoreApiStoreOrderResource : public StoreOrderResource { +public: + std::pair + handler_POST(Order &order) override { + std::string errorType = intToErrorRaisingString(order.getId()); + return raiseErrorForTesting(order, errorType); + } +}; + +class MyUserApiUserCreateWithArrayResource : public UserCreateWithArrayResource { +public: + int handler_POST(std::vector &user) override { + const auto errorType = user[0].getFirstName(); + int status; + User user_; + std::tie(status, user_) = raiseErrorForTesting(User(), errorType); + return status; + } +}; + +class MyUserApiUserCreateWithListResource : public UserCreateWithListResource { +public: + int handler_POST(std::vector &user) override { + const auto errorType = user[0].getFirstName(); + int status; + User user_; + std::tie(status, user_) = raiseErrorForTesting(User(), errorType); + return status; + } +}; + +class MyUserApiUserLoginResource : public UserLoginResource { +public: + std::pair + handler_GET(std::string &username, + std::string &password) override { + int status; + User user_; + std::tie(status, user_) = raiseErrorForTesting(User(), username); + return {status, username}; + } +}; + +class MyUserApiUserLogoutResource : public UserLogoutResource { +public: + int handler_GET() override { + throw int(5); + } +}; + +int main() { + signal(SIGINT,sig_handler); + + const auto service = std::make_shared(); + + auto petApi = PetApi(service); + petApi.setResource(std::make_shared()); + petApi.setResource(std::make_shared()); + + auto storeApi = StoreApi(service); + storeApi.setResource(std::make_shared()); + storeApi.setResource(std::make_shared()); + storeApi.setResource(std::make_shared()); + + auto userApi = UserApi(service); + userApi.getUserResource()->handler_POST_func = [](auto& user) { + const auto errorType = user.getFirstName(); + int status; + User user_; + std::tie(status, user_) = raiseErrorForTesting(user, errorType); + return status; + }; + userApi.setResource(std::make_shared()); + userApi.setResource(std::make_shared()); + userApi.setResource(std::make_shared()); + userApi.setResource(std::make_shared()); + + + const auto settings = std::make_shared(); + settings->set_port(1236); + + service->start(settings); + +} diff --git a/samples/server/petstore/cpp-restbed/test/java_client_tests/tests_servers/simple_server_stubs/CMakeLists.txt b/samples/server/petstore/cpp-restbed/test/java_client_tests/tests_servers/simple_server_stubs/CMakeLists.txt new file mode 100644 index 00000000000..12361397e4e --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/java_client_tests/tests_servers/simple_server_stubs/CMakeLists.txt @@ -0,0 +1,10 @@ +set(TARGET_NAME simple_server_stubs) + +add_executable(${TARGET_NAME}) + +target_sources(${TARGET_NAME} + PRIVATE main.cpp) + +target_link_libraries(${TARGET_NAME} PRIVATE org.openapitools.server.apiStubs) + +run_java_client_test_for_cpp_server(${TARGET_NAME}) \ No newline at end of file diff --git a/samples/server/petstore/cpp-restbed/test/java_client_tests/tests_servers/simple_server_stubs/main.cpp b/samples/server/petstore/cpp-restbed/test/java_client_tests/tests_servers/simple_server_stubs/main.cpp new file mode 100644 index 00000000000..8728037272a --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/java_client_tests/tests_servers/simple_server_stubs/main.cpp @@ -0,0 +1,154 @@ +#include "api/PetApi.h" +#include "api/StoreApi.h" +#include "api/UserApi.h" + +using namespace org::openapitools::server::api; +using namespace org::openapitools::server::api::PetApiResources; +using namespace org::openapitools::server::api::StoreApiResources; +using namespace org::openapitools::server::api::UserApiResources; + +Pet createPetForTesting_1() { + auto pet = Pet(); + pet.setName("HelloPet"); + pet.setId(23); + pet.setStatus("available"); + return pet; +} + +std::shared_ptr createPetForTesting_2() { + auto pet = std::make_shared(); + pet->setName("HelloPet2"); + pet->setId(44); + pet->setStatus("sold"); + return pet; +} + +class MyPetApiPetResource : public PetResource { +public: + int + handler_POST(Pet &pet) override { + return 200; + } + + int + handler_PUT(Pet &pet) override { + return 200; + } +}; + +class MyPetApiPetPetIdResource : public PetPetIdResource { +public: + int handler_DELETE(int64_t &petId, + std::string &api_key) override { + return 200; + } + + std::pair + handler_GET(int64_t &petId) override { + Pet pet = createPetForTesting_1(); + + return std::make_pair(200, pet); + } +}; + +class MyStoreApiStoreOrderOrderIdResource : public StoreOrderOrder_idResource { +public: + int handler_DELETE(std::string &orderId) override { + return 200; + } + + std::pair + handler_GET(int64_t &orderId) override { + auto order = Order(); + order.setStatus("placed"); + order.setId(orderId); + order.setComplete(false); + order.setPetId(4444L); + order.setQuantity(3); + order.setShipDate("2011-09-21T17:32:28Z"); + + return std::make_pair(200, order); + } +}; + +class MyStoreApiStoreInventoryResource : public StoreInventoryResource { +public: + std::pair> handler_GET() override { + std::map result {{"MyPet", 123}, {"OtherPet", 99}}; + return std::make_pair(200, result); + } +}; + +class MyStoreApiStoreOrderResource: public StoreOrderResource { +public: + std::pair + handler_POST(Order &order) override { + order.setStatus("placed"); + order.setShipDate("2011-01-12T23:24:02Z"); + return {200, order}; + } +}; + +class MyUserApiUserResource : public UserResource { +public: + int handler_POST(User &User) override { + return 200; + } +}; + + +class MyUserApiUserCreateWithArrayResource : public UserCreateWithArrayResource { +public: + int handler_POST(std::vector &User) override { + return 200; + } +}; + +class MyUserApiUserCreateWithListResource : public UserCreateWithListResource { +public: + int handler_POST(std::vector &User) override { + return 200; + } +}; + +class MyUserApiUserLoginResource : public UserLoginResource { +public: + std::pair + handler_GET(std::string &username, + std::string &password) override { + return {200, username}; + } +}; + +class MyUserApiUserLogoutResource : public UserLogoutResource { +public: + int handler_GET() override { + return 200; + } +}; + +int main() { + const auto service = std::make_shared(); + + auto petApi = PetApi(service); + petApi.setResource(std::make_shared()); + petApi.setResource(std::make_shared()); + + auto storeApi = StoreApi(service); + storeApi.setResource(std::make_shared()); + storeApi.setResource(std::make_shared()); + storeApi.setResource(std::make_shared()); + + auto userApi = UserApi(service); + userApi.setResource(std::make_shared()); + userApi.setResource(std::make_shared()); + userApi.setResource(std::make_shared()); + userApi.setResource(std::make_shared()); + userApi.setResource(std::make_shared()); + + const auto settings = std::make_shared(); + settings->set_port(1235); + + service->start(settings); + +} \ No newline at end of file diff --git a/samples/server/petstore/cpp-restbed/test/model_tests/AllOfWithSingleRef_test.cpp b/samples/server/petstore/cpp-restbed/test/model_tests/AllOfWithSingleRef_test.cpp new file mode 100644 index 00000000000..85ce5f500e3 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/model_tests/AllOfWithSingleRef_test.cpp @@ -0,0 +1,47 @@ + +#define BOOST_TEST_INCLUDED + +#include +#include +#include +#include +#include "test_helper.h" + + +#include "model/AllOfWithSingleRef.h" + +using namespace org::openapitools::server::model; + +namespace { + const std::string jsonForTest = R"( + { + "username" : "string", + "SingleRefType" : { } + } + )"; +} + +BOOST_AUTO_TEST_SUITE(AllOfWithSingleRefModelTest) + +BOOST_AUTO_TEST_CASE(fromJsonAndBack) +{ + auto obj = AllOfWithSingleRef(); + obj.fromJsonString(jsonForTest); + + const auto newJson = obj.toJsonString(); + + TEST_COMPARE_JSON(jsonForTest, newJson); +} + +BOOST_AUTO_TEST_CASE(vectorFromJsonString) +{ + const auto jsonString = "[" + + jsonForTest + + "," + + jsonForTest + + "]"; + const auto vec = createAllOfWithSingleRefVectorFromJsonString(jsonString); + BOOST_TEST(vec.size() == 2); +} + +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/samples/server/petstore/cpp-restbed/test/model_tests/Animal_test.cpp b/samples/server/petstore/cpp-restbed/test/model_tests/Animal_test.cpp new file mode 100644 index 00000000000..7d268b90cde --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/model_tests/Animal_test.cpp @@ -0,0 +1,46 @@ + +#define BOOST_TEST_INCLUDED + +#include +#include +#include +#include +#include "test_helper.h" + + +#include "model/Animal.h" + +using namespace org::openapitools::server::model; + +namespace { + const std::string jsonForTest = R"( +{ + "className" : "string", + "color" : "red" +})"; +} + +BOOST_AUTO_TEST_SUITE(AnimalModelTest) + + BOOST_AUTO_TEST_CASE(fromJsonAndBack) + { + auto obj = Animal(); + obj.fromJsonString(jsonForTest); + + const auto newJson = obj.toJsonString(); + + TEST_COMPARE_JSON(jsonForTest, newJson); + } + + BOOST_AUTO_TEST_CASE(vectorFromJsonString) + { + const auto jsonString = "[" + + jsonForTest + + "," + + jsonForTest + + "]"; + const auto vec = createAnimalVectorFromJsonString(jsonString); + BOOST_TEST(vec.size() == 2); + } + +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/samples/server/petstore/cpp-restbed/test/model_tests/CMakeLists.txt b/samples/server/petstore/cpp-restbed/test/model_tests/CMakeLists.txt new file mode 100644 index 00000000000..5d48a812cd8 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/model_tests/CMakeLists.txt @@ -0,0 +1,33 @@ + +add_executable(model_tests) + +target_sources(model_tests + PRIVATE + main.cpp + pet_model_test.cpp + tag_model_test.cpp + user_model_test.cpp + category_model_test.cpp + order_model_test.cpp + api_response_model_test.cpp + _foo_get_default_response_test.cpp + _special_model_name_test.cpp + additional_properties_class_test.cpp + AllOfWithSingleRef_test.cpp + Animal_test.cpp +) + +target_include_directories(model_tests + SYSTEM PRIVATE + ${Boost_INCLUDE_DIRS} +) + +target_include_directories(model_tests PRIVATE ${CMAKE_CURRENT_LIST_DIR}) + +target_link_libraries(model_tests + PRIVATE + org.openapitools.server.apiStubs + ${Boost_LIBRARIES}) + + +add_test(NAME model_tests COMMAND model_tests) \ No newline at end of file diff --git a/samples/server/petstore/cpp-restbed/test/model_tests/_foo_get_default_response_test.cpp b/samples/server/petstore/cpp-restbed/test/model_tests/_foo_get_default_response_test.cpp new file mode 100644 index 00000000000..0d80e7ccf63 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/model_tests/_foo_get_default_response_test.cpp @@ -0,0 +1,39 @@ +#define BOOST_TEST_INCLUDED +#include +#include +#include +#include + + +#include "model/_foo_get_default_response.h" + +using namespace org::openapitools::server::model; + + +BOOST_AUTO_TEST_SUITE(GetDefaultResponseModelTest) + + BOOST_AUTO_TEST_CASE(toJsonString) + { + auto defaultResponse = _foo_get_default_response(); + auto foo = Foo(); + foo.setBar("bar1"); + defaultResponse.setString(foo); + + const auto jsonString = defaultResponse.toJsonString(); + + auto newDefaultResponse = _foo_get_default_response(); + newDefaultResponse.fromJsonString(jsonString); + + BOOST_TEST(newDefaultResponse.getString().getBar() == "bar1"); + } + + BOOST_AUTO_TEST_CASE(vectorFromJsonString) + { + const auto jsonString = R"([{"string":{"bar":"bar1"}}, {"string":{"bar":"bar2"}}])"; + const auto vec = create_foo_get_default_responseVectorFromJsonString(jsonString); + BOOST_TEST(vec.size() == 2); + BOOST_TEST(vec[0].getString().getBar() == "bar1"); + BOOST_TEST(vec[1].getString().getBar() == "bar2"); + } + +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/samples/server/petstore/cpp-restbed/test/model_tests/_special_model_name_test.cpp b/samples/server/petstore/cpp-restbed/test/model_tests/_special_model_name_test.cpp new file mode 100644 index 00000000000..2edac999d99 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/model_tests/_special_model_name_test.cpp @@ -0,0 +1,48 @@ + +#define BOOST_TEST_INCLUDED + +#include +#include +#include +#include + + +#include "model/_special_model_name_.h" + +using namespace org::openapitools::server::model; + +namespace { +_special_model_name_ create_special_model_name_forTest() { + auto obj = _special_model_name_(); + obj.setSpecialPropertyName(12); + return obj; +} +} + +BOOST_AUTO_TEST_SUITE(special_model_name_ModelTest) + +BOOST_AUTO_TEST_CASE(toJsonString) +{ + const auto obj = create_special_model_name_forTest(); + const auto jsonString = obj.toJsonString(); + + auto newObj = _special_model_name_(); + newObj.fromJsonString(jsonString); + + BOOST_TEST(newObj.getSpecialPropertyName() == 12); +} + +BOOST_AUTO_TEST_CASE(vectorFromJsonString) +{ + const auto obj = create_special_model_name_forTest(); + + const auto jsonString = "[" + + obj.toJsonString() + + "," + + obj.toJsonString() + + "]"; + const auto vec = create_special_model_name_VectorFromJsonString(jsonString); + BOOST_TEST(vec.size() == 2); +} + +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/samples/server/petstore/cpp-restbed/test/model_tests/additional_properties_class_test.cpp b/samples/server/petstore/cpp-restbed/test/model_tests/additional_properties_class_test.cpp new file mode 100644 index 00000000000..d636c2749a3 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/model_tests/additional_properties_class_test.cpp @@ -0,0 +1,85 @@ + +#define BOOST_TEST_INCLUDED + +#include +#include +#include +#include + + +#include "model/AdditionalPropertiesClass.h" +#include "test_helper.h" + +using namespace org::openapitools::server::model; + +namespace { + const std::string jsonForTest = R"({ + "map_property" : { + "additionalProp1" : "string", + "additionalProp2" : "string", + "additionalProp3" : "string" + }, + "map_of_map_property" : { + "additionalProp1" : { + "additionalProp1" : "string", + "additionalProp2" : "string", + "additionalProp3" : "string" + }, + "additionalProp2" : { + "additionalProp1" : "string", + "additionalProp2" : "string", + "additionalProp3" : "string" + }, + "additionalProp3" : { + "additionalProp1" : "string", + "additionalProp2" : "string", + "additionalProp3" : "string" + } + } +} + )"; +} + +BOOST_AUTO_TEST_SUITE(AdditionalPropertiesClassModelTest) + +BOOST_AUTO_TEST_CASE(toJsonString) +{ + auto obj = AdditionalPropertiesClass(); + std::map mapProperty; + mapProperty.insert(std::make_pair("foo", "bar")); + obj.setMapProperty(mapProperty); + + const auto jsonString = obj.toJsonString(); + + auto newObj = AdditionalPropertiesClass(); + newObj.fromJsonString(jsonString); + + auto map = newObj.getMapProperty(); + BOOST_TEST(map.size() == 1); + + auto prop = map["foo"]; + BOOST_TEST(prop == "bar"); +} + +BOOST_AUTO_TEST_CASE(fromJsonAndBack) +{ + auto obj = AdditionalPropertiesClass(); + obj.fromJsonString(jsonForTest); + + const auto newJson = obj.toJsonString(); + + TEST_COMPARE_JSON(jsonForTest, newJson); +} + +BOOST_AUTO_TEST_CASE(vectorFromJsonString) +{ + const auto jsonString = "[" + + jsonForTest + + "," + + jsonForTest + + "]"; + const auto vec = createAdditionalPropertiesClassVectorFromJsonString(jsonString); + BOOST_TEST(vec.size() == 2); +} + +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/samples/server/petstore/cpp-restbed/test/model_tests/api_response_model_test.cpp b/samples/server/petstore/cpp-restbed/test/model_tests/api_response_model_test.cpp new file mode 100644 index 00000000000..d08635bd742 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/model_tests/api_response_model_test.cpp @@ -0,0 +1,93 @@ +#define BOOST_TEST_INCLUDED +#include +#include + +#include "model/ApiResponse.h" + +using namespace org::openapitools::server::model; + + +BOOST_AUTO_TEST_SUITE(ApiResponseModelTest) + +BOOST_AUTO_TEST_CASE(toJsonString) +{ + ApiResponse apiResponse; + apiResponse.setCode(404); + apiResponse.setType("Error"); + apiResponse.setMessage("Not available"); + + const auto json = apiResponse.toJsonString(true); + + ApiResponse newResponse; + newResponse.fromJsonString(json); + + BOOST_TEST(newResponse.getCode() == 404); + BOOST_TEST(newResponse.getType() == "Error"); + BOOST_TEST(newResponse.getMessage() == "Not available"); + + +} + +BOOST_AUTO_TEST_CASE(fromJsonString) +{ + const std::string json = R"JSON( +{ + "code": "200", + "type": "Ok", + "message": "Nice!" +} +)JSON"; + + ApiResponse apiResponse; + + apiResponse.fromJsonString(json); + + + BOOST_TEST(apiResponse.getCode() == 200); + BOOST_TEST(apiResponse.getType() == "Ok"); + BOOST_TEST(apiResponse.getMessage() == "Nice!"); +} + + +BOOST_AUTO_TEST_CASE(fromJsonArrayString) +{ + const std::string json = R"JSON( +[{ + "code": "200", + "type": "Ok", + "message": "Nice!" +},{ + "code": "404", + "type": "error", + "message": "bad!" +}] +)JSON"; + + const auto apiResponseVec = createApiResponseVectorFromJsonString(json); + + BOOST_TEST(apiResponseVec.size() == 2); + BOOST_TEST(apiResponseVec[0].getCode() == 200); + BOOST_TEST(apiResponseVec[0].getType() == "Ok"); + BOOST_TEST(apiResponseVec[0].getMessage() == "Nice!"); + BOOST_TEST(apiResponseVec[1].getCode() == 404); + BOOST_TEST(apiResponseVec[1].getType() == "error"); + BOOST_TEST(apiResponseVec[1].getMessage() == "bad!"); +} + +BOOST_AUTO_TEST_CASE(toAndFromPropertyTree) +{ + ApiResponse apiResponse; + apiResponse.setCode(200); + apiResponse.setType("Ack"); + apiResponse.setMessage("cool"); + + const auto pt = apiResponse.toPropertyTree(); + + const auto newApiResponse = ApiResponse(pt); + + BOOST_TEST(newApiResponse.getCode() == 200); + BOOST_TEST(newApiResponse.getType() == "Ack"); + BOOST_TEST(newApiResponse.getMessage() == "cool"); +} + +BOOST_AUTO_TEST_SUITE_END() diff --git a/samples/server/petstore/cpp-restbed/test/model_tests/category_model_test.cpp b/samples/server/petstore/cpp-restbed/test/model_tests/category_model_test.cpp new file mode 100644 index 00000000000..5daf866be62 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/model_tests/category_model_test.cpp @@ -0,0 +1,88 @@ +#define BOOST_TEST_INCLUDED +#include +#include +#include +#include + + +#include "model/Category.h" + +using namespace org::openapitools::server::model; + + +BOOST_AUTO_TEST_SUITE(CategoryModelTest) + +BOOST_AUTO_TEST_CASE(toJsonString) +{ + Category category; + category.setId(1); + category.setName("category1"); + + const auto json = category.toJsonString(false); + + Category newCategory; + newCategory.fromJsonString(json); + + BOOST_TEST(newCategory.getId() == 1); + BOOST_TEST(newCategory.getName() == "category1"); +} + +BOOST_AUTO_TEST_CASE(fromJsonString) +{ + const std::string json = R"JSON( +{ + "id": "23", + "name": "categoryB" +} +)JSON"; + + Category category; + category.fromJsonString(json); + + BOOST_TEST(category.getId() == 23); + BOOST_TEST(category.getName() == "categoryB"); +} + +BOOST_AUTO_TEST_CASE(fromJsonArrayString) +{ + const std::string json = R"JSON( +[{ + "id": "1", + "name": "categoryA" +}, +{ + "id": "2", + "name": "categoryB" +}, +{ + "id": "3", + "name": "categoryC" +}] +)JSON"; + + const auto categoryVec = createCategoryVectorFromJsonString(json); + + BOOST_TEST(categoryVec.size() == 3); + BOOST_TEST(categoryVec[0].getId() == 1); + BOOST_TEST(categoryVec[0].getName() == "categoryA"); + BOOST_TEST(categoryVec[1].getId() == 2); + BOOST_TEST(categoryVec[1].getName() == "categoryB"); + BOOST_TEST(categoryVec[2].getId() == 3); + BOOST_TEST(categoryVec[2].getName() == "categoryC"); + +} + +BOOST_AUTO_TEST_CASE(fromAndToPropertyTree) +{ + Category category; + category.setId(23); + category.setName("categoryX"); + + const auto pt = category.toPropertyTree(); + + const auto newCategory = Category(pt); + BOOST_TEST(newCategory.getId() == 23); + BOOST_TEST(newCategory.getName() == "categoryX"); +} + +BOOST_AUTO_TEST_SUITE_END() diff --git a/samples/server/petstore/cpp-restbed/test/model_tests/main.cpp b/samples/server/petstore/cpp-restbed/test/model_tests/main.cpp new file mode 100644 index 00000000000..4af53a2ba3f --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/model_tests/main.cpp @@ -0,0 +1,4 @@ +#define BOOST_TEST_MODULE ModelTests + +//#include // static or dynamic boost build +#include // header only boost diff --git a/samples/server/petstore/cpp-restbed/test/model_tests/order_model_test.cpp b/samples/server/petstore/cpp-restbed/test/model_tests/order_model_test.cpp new file mode 100644 index 00000000000..0fef2d14769 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/model_tests/order_model_test.cpp @@ -0,0 +1,170 @@ +#define BOOST_TEST_INCLUDED +#include +#include +#include +#include +#include + +#include "model/Order.h" + +using namespace org::openapitools::server::model; + + +BOOST_AUTO_TEST_SUITE(OrderModelTest) + +BOOST_AUTO_TEST_CASE(toJsonString) +{ + Order order; + order.setId(2L); + order.setPetId(3L); + order.setQuantity(6); + order.setShipDate("123"); + order.setStatus("placed"); + order.setComplete(false); + + const auto json = order.toJsonString(true); + + Order newOrder; + newOrder.fromJsonString(json); + + BOOST_TEST(newOrder.getId() == 2L); + BOOST_TEST(newOrder.getPetId() == 3L); + BOOST_TEST(newOrder.getQuantity() == 6); + BOOST_TEST(newOrder.getShipDate() == "123"); + BOOST_TEST(newOrder.getStatus() == "placed"); + BOOST_TEST(newOrder.isComplete() == false); +} + +BOOST_AUTO_TEST_CASE(fromJsonString) +{ + const std::string json = R"JSON( +{ + "id": "22", + "petId": "32", + "quantity": "1", + "shipDate": "999999", + "status": "placed", + "complete": "true" +} +)JSON"; + + Order order; + order.fromJsonString(json); + + BOOST_TEST(order.getId() == 22L); + BOOST_TEST(order.getPetId() == 32L); + BOOST_TEST(order.getQuantity() == 1); + BOOST_TEST(order.getShipDate() == "999999"); + BOOST_TEST(order.getStatus() == "placed"); + BOOST_TEST(order.isComplete() == true); +} + +BOOST_AUTO_TEST_CASE(fromJsonArrayString) +{ + const std::string json = R"JSON( +[{ + "id": "1", + "petId": "1", + "quantity": "1", + "shipDate": "11111", + "status": "placed", + "complete": "true" +},{ + "id": "2", + "petId": "2", + "quantity": "2", + "shipDate": "222222", + "status": "approved", + "complete": "false" +},{ + "id": "3", + "petId": "3", + "quantity": "3", + "shipDate": "33333", + "status": "delivered" +}] +)JSON"; + + const auto orderVec = createOrderVectorFromJsonString(json); + + + BOOST_TEST(orderVec.size() == 3); + BOOST_TEST(orderVec[0].getId() == 1); + BOOST_TEST(orderVec[0].getPetId() == 1); + BOOST_TEST(orderVec[0].getQuantity() == 1); + BOOST_TEST(orderVec[0].getShipDate() == "11111"); + BOOST_TEST(orderVec[0].getStatus() == "placed"); + BOOST_TEST(orderVec[0].isComplete() == true); + BOOST_TEST(orderVec[1].getId() == 2); + BOOST_TEST(orderVec[1].getPetId() == 2); + BOOST_TEST(orderVec[1].getQuantity() == 2); + BOOST_TEST(orderVec[1].getShipDate() == "222222"); + BOOST_TEST(orderVec[1].getStatus() == "approved"); + BOOST_TEST(orderVec[1].isComplete() == false); + BOOST_TEST(orderVec[2].getId() == 3); + BOOST_TEST(orderVec[2].getPetId() == 3); + BOOST_TEST(orderVec[2].getQuantity() == 3); + BOOST_TEST(orderVec[2].getShipDate() == "33333"); + BOOST_TEST(orderVec[2].getStatus() == "delivered"); + BOOST_TEST(orderVec[2].isComplete() == false); +} + +BOOST_AUTO_TEST_CASE(toAndFromPropertyTree) +{ + Order order; + order.setId(1L); + order.setPetId(2L); + order.setQuantity(4); + order.setShipDate("111123"); + order.setStatus("approved"); + order.setComplete(false); + + const auto pt = order.toPropertyTree(); + + const auto newOrder = Order(pt); + + BOOST_TEST(newOrder.getId() == 1L); + BOOST_TEST(newOrder.getPetId() == 2L); + BOOST_TEST(newOrder.getQuantity() == 4); + BOOST_TEST(newOrder.getShipDate() == "111123"); + BOOST_TEST(newOrder.getStatus() == "approved"); + BOOST_TEST(newOrder.isComplete() == false); +} + + +BOOST_DATA_TEST_CASE( + validStatusValues, + boost::unit_test::data::make({"placed","approved","delivered"}), + status) +{ + Order order; + order.setStatus(status); + + BOOST_TEST(order.getStatus() == status); + +} + +BOOST_DATA_TEST_CASE(invalidStatusValues, + boost::unit_test::data::make({"", + "notallowed", + "not available"}), + invalid_status) +{ + bool exceptionCaught = false; + + Order order; + + try { + order.setStatus(invalid_status); + } + catch(const std::runtime_error& excp) { + exceptionCaught = true; + const auto expectedErrorMessage = std::string("Value ") + + invalid_status + + " not allowed"; + BOOST_TEST(excp.what() == expectedErrorMessage); + } + BOOST_TEST(exceptionCaught); +} + +BOOST_AUTO_TEST_SUITE_END() diff --git a/samples/server/petstore/cpp-restbed/test/model_tests/pet_model_test.cpp b/samples/server/petstore/cpp-restbed/test/model_tests/pet_model_test.cpp new file mode 100644 index 00000000000..a199d3d240b --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/model_tests/pet_model_test.cpp @@ -0,0 +1,290 @@ +#define BOOST_TEST_INCLUDED +#include +#include +#include +#include +#include +#include +#include + +#include "model/Pet.h" +#include "model/Tag.h" +#include "model/Category.h" + +using namespace org::openapitools::server::model; + +template +boost::property_tree::ptree createPropertyTreeSubArray(const std::initializer_list& data) { + boost::property_tree::ptree tmp_node; + for (const auto &tag : data) { + boost::property_tree::ptree tagEntry; + tagEntry.put("", tag); + tmp_node.push_back(std::make_pair("", tagEntry)); + } + + return tmp_node; +} + +BOOST_AUTO_TEST_SUITE(PetModelTest) + + +BOOST_AUTO_TEST_CASE(toJsonStringWithCategory) +{ + Pet pet; + pet.setId(1); + pet.setName("MyName"); + auto category = Category(); + pet.setCategory(category); + pet.setStatus("pending"); + + const auto json = pet.toJsonString(true); + + Pet newPet; + newPet.fromJsonString(json); + BOOST_TEST(newPet.getId() == 1); + BOOST_TEST(newPet.getName() == "MyName"); + + const auto newCategory = newPet.getCategory(); + BOOST_TEST(newCategory.getName() == "default-name"); + BOOST_TEST(newCategory.getId() == 0); + + +} + +BOOST_AUTO_TEST_CASE(toJsonStringWithTags) +{ + Pet pet; + pet.setId(1); + pet.setName("MyName"); + pet.setStatus("sold"); + + std::vector tags; + auto tag1 = Tag(); + tag1.setName("tag1"); + tag1.setId(1); + tags.emplace_back(tag1); + auto tag2 = Tag(); + tag2.setName("tag2"); + tag2.setId(2); + tags.emplace_back(tag2); + pet.setTags(tags); + + const auto json = pet.toJsonString(true); + + Pet newPet; + newPet.fromJsonString(json); + + BOOST_TEST(newPet.getId() == 1); + BOOST_TEST(newPet.getName() =="MyName"); + + const auto newTags = newPet.getTags(); + BOOST_TEST(newTags.size() == 2); +} + +BOOST_AUTO_TEST_CASE(fromJsonString) +{ + Pet pet; + std::string json = R"JSON( +{ + "id": "23", + "name": "ThePet", + "status": "available" +})JSON"; + + pet.fromJsonString(json); + + BOOST_TEST(pet.getId() == 23); + BOOST_TEST(pet.getName() == "ThePet"); + BOOST_TEST(pet.getStatus() == "available"); +} + +BOOST_AUTO_TEST_CASE(fromJsonArrayString) +{ + Pet pet; + std::string json = R"JSON( +[{ + "id": "23", + "name": "ThePet", + "status": "available" +},{ + "id": "42", + "name": "TheOtherPet", + "status": "available" +}])JSON"; + + const auto petVector = createPetVectorFromJsonString(json); + + BOOST_TEST(petVector.size() == 2); + + BOOST_TEST(petVector[0].getId() == 23); + BOOST_TEST(petVector[0].getName() == "ThePet"); + BOOST_TEST(petVector[0].getStatus() == "available"); + + BOOST_TEST(petVector[1].getId() == 42); + BOOST_TEST(petVector[1].getName() == "TheOtherPet"); + BOOST_TEST(petVector[1].getStatus() == "available"); +} + + +BOOST_AUTO_TEST_CASE(fromJsonAndPropertyTree) +{ + std::stringstream json_stream; + json_stream << R"JSON( +{ + "id": "23", + "name": "ThePet", + "status": "available" +})JSON"; + + boost::property_tree::ptree pt; + boost::property_tree::read_json(json_stream, pt); + + Pet pet{pt}; + + BOOST_TEST(pet.getId() == 23); + BOOST_TEST(pet.getName() == "ThePet"); + BOOST_TEST(pet.getStatus() == "available"); +} + +BOOST_AUTO_TEST_CASE(fromPropertyTree) +{ + + boost::property_tree::ptree pt; + + pt.add("id", 11); + pt.add("status", "available"); + pt.add("name", "Fluffy"); + + boost::property_tree::ptree tags; + boost::property_tree::ptree tagPt1; + tagPt1.add("name", "tag1"); + tagPt1.add("id", 1); + tags.push_back(std::make_pair("", tagPt1)); + boost::property_tree::ptree tagPt2; + tagPt2.add("name", "tag2"); + tagPt2.add("id", 2); + tags.push_back(std::make_pair("", tagPt2)); + pt.add_child("tags", tags); + + pt.add_child("photoUrls", createPropertyTreeSubArray({"www.example.com/photo1", + "www.example.com/photo2"})); + + pt.add("category.name", "Category1"); + pt.add("category.id", 0); + + Pet pet; + pet.fromPropertyTree(pt); + + BOOST_TEST(pet.getName() == "Fluffy"); +} + +BOOST_AUTO_TEST_CASE(toPropertyTree) +{ + Pet pet; + + std::vector tags; + auto tag = Tag(); + tag.setName("Tag1"); + tags.emplace_back(tag); + pet.setTags(tags); + + std::set photoUrls; + photoUrls.insert("www.example.com/photo1"); + photoUrls.insert("www.example.com/photo2"); + pet.setPhotoUrls(photoUrls); + + auto category = Category(); + category.setName("Category1"); + pet.setCategory(category); + + auto pt = pet.toPropertyTree(); + + BOOST_TEST(pt.get("id") == 0); + BOOST_TEST(pt.get("name") == ""); + BOOST_TEST(pt.get("status") == ""); + + auto tagsFromPt = pt.get_child("tags"); + BOOST_TEST(tagsFromPt.size() == 1); + + auto photoUrlsFromPt = pt.get_child("photoUrls"); + BOOST_TEST(photoUrlsFromPt.size() == 2); + + BOOST_TEST(pet.getCategory().getName() == "Category1"); + auto categoryFromPt = pt.get_child("category"); + BOOST_TEST(categoryFromPt.get("name") == "Category1"); +} + +BOOST_AUTO_TEST_CASE(photoUrls) +{ + Pet pet; + std::set photoUrls{"url1", "url2"}; + pet.setPhotoUrls(photoUrls); + + BOOST_TEST(pet.getPhotoUrls().size() == 2); + BOOST_TEST(pet.getPhotoUrls().count("url1") == 1); + BOOST_TEST(pet.getPhotoUrls().count("url2") == 1); +} + +BOOST_AUTO_TEST_CASE(fromJsonWithTags) { + std::string json_str = R"JSON( +{ + "id": "1", + "name": "MyName", + "tags": [ + { + "id": "1", + "name": "tag1" + }, + { + "id": "2", + "name": "tag2" + } + ], + "status": "available" +})JSON"; + + Pet pet; + pet.fromJsonString(json_str); + + BOOST_TEST(pet.getTags().size() == 2); + BOOST_TEST(pet.getTags()[0].getId() == 1); + BOOST_TEST(pet.getTags()[1].getId() == 2); +} + +BOOST_DATA_TEST_CASE(validStatusValues, + boost::unit_test::data::make({"available", + "pending", + "sold"}), + status) +{ + Pet pet; + pet.setStatus(status); + + BOOST_TEST(pet.getStatus() == status); + +} + +BOOST_DATA_TEST_CASE(invalidStatusValues, + boost::unit_test::data::make({"", + "notallowed", + "not available"}), + invalid_status) +{ + bool exceptionCaught = false; + + Pet pet; + + try { + pet.setStatus(invalid_status); + } + catch(const std::runtime_error& excp) { + exceptionCaught = true; + const auto expectedErrorMessage = std::string("Value ") + + invalid_status + + " not allowed"; + BOOST_TEST(excp.what() == expectedErrorMessage); + } + BOOST_TEST(exceptionCaught); +} + +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/samples/server/petstore/cpp-restbed/test/model_tests/tag_model_test.cpp b/samples/server/petstore/cpp-restbed/test/model_tests/tag_model_test.cpp new file mode 100644 index 00000000000..8ebfb75eafe --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/model_tests/tag_model_test.cpp @@ -0,0 +1,84 @@ +#define BOOST_TEST_INCLUDED +#include +#include +#include +#include + +#include "model/Tag.h" + +using namespace org::openapitools::server::model; + + +BOOST_AUTO_TEST_SUITE(TagModelTest) + +BOOST_AUTO_TEST_CASE(toJsonString) +{ + Tag tag; + tag.setId(1); + tag.setName("MyTag"); + const auto json = tag.toJsonString(true); + + Tag newTag; + newTag.fromJsonString(json); + BOOST_TEST(newTag.getId() == 1); + BOOST_TEST(newTag.getName() == "MyTag"); + +} + +BOOST_AUTO_TEST_CASE(fromJsonString) +{ + const std::string json = R"JSON( +{ + "id": 23, + "name": "HelloTag" +})JSON"; + + Tag tag; + tag.fromJsonString(json); + + BOOST_TEST(tag.getId() == 23); + BOOST_TEST(tag.getName() == "HelloTag"); +} + + +BOOST_AUTO_TEST_CASE(fromJsonArrayString) +{ + const std::string json = R"JSON( +[{ + "id": 23, + "name": "HelloTag" +},{ + "id": 42, + "name": "MyTag" +},{ + "id": 13, + "name": "OtherTag" +}])JSON"; + + const auto tagVector = createTagVectorFromJsonString(json); + + BOOST_TEST(tagVector.size() == 3); + BOOST_TEST(tagVector[0].getId() == 23); + BOOST_TEST(tagVector[0].getName() == "HelloTag"); + BOOST_TEST(tagVector[1].getId() == 42); + BOOST_TEST(tagVector[1].getName() == "MyTag"); + BOOST_TEST(tagVector[2].getId() == 13); + BOOST_TEST(tagVector[2].getName() == "OtherTag"); +} + + +BOOST_AUTO_TEST_CASE(ToAndFromPropertyTree) +{ + Tag tag; + tag.setId(42); + tag.setName("AnotherTag"); + + const auto pt = tag.toPropertyTree(); + + const auto newTag = Tag(pt); + + BOOST_TEST(newTag.getId() == 42); + BOOST_TEST(newTag.getName() == "AnotherTag"); +} + +BOOST_AUTO_TEST_SUITE_END() diff --git a/samples/server/petstore/cpp-restbed/test/model_tests/test_helper.h b/samples/server/petstore/cpp-restbed/test/model_tests/test_helper.h new file mode 100644 index 00000000000..228fdd88376 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/model_tests/test_helper.h @@ -0,0 +1,20 @@ +#ifndef CPP_RESTPED_SERVER_OPEN_API_TEST_HELPER_H +#define CPP_RESTPED_SERVER_OPEN_API_TEST_HELPER_H + +#include +#include +#include +#include + +#define TEST_COMPARE_JSON(jsonA, jsonB) do { \ + std::stringstream ssA(jsonA); \ + boost::property_tree::ptree ptA; \ + read_json(ssA,ptA); \ + std::stringstream ssB(jsonB); \ + boost::property_tree::ptree ptB; \ + read_json(ssB,ptB); \ + BOOST_TEST(ptA == ptB); \ +} while(0) + + +#endif //CPP_RESTPED_SERVER_OPEN_API_TEST_HELPER_H diff --git a/samples/server/petstore/cpp-restbed/test/model_tests/user_model_test.cpp b/samples/server/petstore/cpp-restbed/test/model_tests/user_model_test.cpp new file mode 100644 index 00000000000..22de8a51f8a --- /dev/null +++ b/samples/server/petstore/cpp-restbed/test/model_tests/user_model_test.cpp @@ -0,0 +1,136 @@ +#define BOOST_TEST_INCLUDED +#include +#include +#include +#include + +#include "model/User.h" + +using namespace org::openapitools::server::model; + + +BOOST_AUTO_TEST_SUITE(UserModelTest) + +BOOST_AUTO_TEST_CASE(toJsonString) +{ + User user; + user.setId(4L); + user.setUsername("User"); + user.setFirstName("First Name"); + user.setLastName("Last Name"); + user.setEmail("user@example.com"); + user.setPassword("passw0rd"); + user.setPhone("1234567890"); + user.setUserStatus(2); + + const auto json = user.toJsonString(true); + + User newUser; + newUser.fromJsonString(json); + + BOOST_TEST(newUser.getId() == 4L); + BOOST_TEST(newUser.getUsername() == "User"); + BOOST_TEST(newUser.getFirstName() == "First Name"); + BOOST_TEST(newUser.getLastName() == "Last Name"); + BOOST_TEST(newUser.getEmail() == "user@example.com"); + BOOST_TEST(newUser.getPassword() == "passw0rd"); + BOOST_TEST(newUser.getPhone() == "1234567890"); + BOOST_TEST(newUser.getUserStatus() == 2); + +} + +BOOST_AUTO_TEST_CASE(fromJsonString) +{ + const std::string json = R"JSON( +{ + "id": "3", + "username": "TheUser", + "firstName": "My Name", + "lastName": "My Last Name", + "email": "user@example.com", + "password": "pa55word", + "phone": "0987654321", + "userStatus": "3" +})JSON"; + + User user; + user.fromJsonString(json); + + BOOST_TEST(user.getId() == 3L); + BOOST_TEST(user.getUsername() == "TheUser"); + BOOST_TEST(user.getFirstName() == "My Name"); + BOOST_TEST(user.getLastName() == "My Last Name"); + BOOST_TEST(user.getEmail() == "user@example.com"); + BOOST_TEST(user.getPassword() == "pa55word"); + BOOST_TEST(user.getPhone() == "0987654321"); + BOOST_TEST(user.getUserStatus() == 3); +} + +BOOST_AUTO_TEST_CASE(toAndFromPropertyTree) +{ + User user; + user.setId(7L); + user.setUsername("User1"); + user.setFirstName("First Name 1"); + user.setLastName("Last Name 1"); + user.setEmail("user1@example.com"); + user.setPassword("passw0rd1"); + user.setPhone("1111122222333"); + user.setUserStatus(23); + + const auto pt = user.toPropertyTree(); + + const auto newUser = User(pt); + + BOOST_TEST(newUser.getId() == 7L); + BOOST_TEST(newUser.getUsername() == "User1"); + BOOST_TEST(newUser.getFirstName() == "First Name 1"); + BOOST_TEST(newUser.getLastName() == "Last Name 1"); + BOOST_TEST(newUser.getEmail() == "user1@example.com"); + BOOST_TEST(newUser.getPassword() == "passw0rd1"); + BOOST_TEST(newUser.getPhone() == "1111122222333"); + BOOST_TEST(newUser.getUserStatus() == 23); +} + + +BOOST_AUTO_TEST_CASE(fromJsonArrayString) { + const std::string json = R"JSON( +[{ + "id": "4", + "username": "TheUser", + "firstName": "My Name", + "lastName": "My Last Name", + "email": "user@example.com", + "password": "pa55word", + "phone": "0987654321", + "userStatus": "3" +},{ + "id": "3", + "username": "TheUser2", + "firstName": "My Name 2", + "lastName": "My Last Name 2", + "email": "user2@example.com", + "password": "pa55word2", + "phone": "098222222", + "userStatus": "22" +},{ + "id": "1", + "username": "TheUser3", + "firstName": "My Name 3", + "lastName": "My Last Name 3", + "email": "user3@example.com", + "password": "pa55word3", + "phone": "098333333", + "userStatus": "33" +}])JSON"; + + const auto userVec = createUserVectorFromJsonString(json); + + BOOST_TEST(userVec.size() == 3); + BOOST_TEST(userVec[0].getUsername() == "TheUser"); + BOOST_TEST(userVec[1].getUsername() == "TheUser2"); + BOOST_TEST(userVec[2].getUsername() == "TheUser3"); + +} + +BOOST_AUTO_TEST_SUITE_END()