diff --git a/bin/restbed-petstore-server.sh b/bin/restbed-petstore-server.sh new file mode 100755 index 000000000000..2744c37ce996 --- /dev/null +++ b/bin/restbed-petstore-server.sh @@ -0,0 +1,31 @@ +#!/usr/bin/env bash + +SCRIPT="$0" + +while [ -h "$SCRIPT" ] ; do + ls=`ls -ld "$SCRIPT"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + SCRIPT="$link" + else + SCRIPT=`dirname "$SCRIPT"`/"$link" + fi +done + +if [ ! -d "${APP_DIR}" ]; then + APP_DIR=`dirname "$SCRIPT"`/.. + APP_DIR=`cd "${APP_DIR}"; pwd` +fi + +executable="./modules/swagger-codegen-cli/target/swagger-codegen-cli.jar" + +if [ ! -f "$executable" ] +then + mvn clean package +fi + +# if you've executed sbt assembly previously it will use that instead. +export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties" +ags="$@ generate -l restbed -i modules/swagger-codegen/src/test/resources/2_0/petstore.yaml -o samples/server/petstore/restbed" + +java $JAVA_OPTS -jar $executable $ags diff --git a/bin/windows/restbed-petstore-server.bat b/bin/windows/restbed-petstore-server.bat new file mode 100644 index 000000000000..fe23e7284c2c --- /dev/null +++ b/bin/windows/restbed-petstore-server.bat @@ -0,0 +1,10 @@ +set executable=.\modules\swagger-codegen-cli\target\swagger-codegen-cli.jar + +If Not Exist %executable% ( + mvn clean package +) + +REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M -DloggerPath=conf/log4j.properties +set ags=generate -i modules\swagger-codegen\src\test\resources\2_0\petstore.yaml -l restbed -o samples\server\petstore\restbed\ + +java %JAVA_OPTS% -jar %executable% %ags% diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/RestbedCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/RestbedCodegen.java new file mode 100644 index 000000000000..639b0d9f5a55 --- /dev/null +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/RestbedCodegen.java @@ -0,0 +1,421 @@ +package io.swagger.codegen.languages; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import io.swagger.codegen.CliOption; +import io.swagger.codegen.CodegenConfig; +import io.swagger.codegen.CodegenConstants; +import io.swagger.codegen.CodegenModel; +import io.swagger.codegen.CodegenOperation; +import io.swagger.codegen.CodegenParameter; +import io.swagger.codegen.CodegenProperty; +import io.swagger.codegen.CodegenType; +import io.swagger.codegen.DefaultCodegen; +import io.swagger.codegen.SupportingFile; +import io.swagger.models.Model; +import io.swagger.models.Operation; +import io.swagger.models.Response; +import io.swagger.models.Swagger; +import io.swagger.models.properties.ArrayProperty; +import io.swagger.models.properties.BaseIntegerProperty; +import io.swagger.models.properties.BooleanProperty; +import io.swagger.models.properties.DateProperty; +import io.swagger.models.properties.DateTimeProperty; +import io.swagger.models.properties.DecimalProperty; +import io.swagger.models.properties.DoubleProperty; +import io.swagger.models.properties.FileProperty; +import io.swagger.models.properties.FloatProperty; +import io.swagger.models.properties.IntegerProperty; +import io.swagger.models.properties.LongProperty; +import io.swagger.models.properties.MapProperty; +import io.swagger.models.properties.Property; +import io.swagger.models.properties.RefProperty; +import io.swagger.models.properties.StringProperty; + +public class RestbedCodegen extends DefaultCodegen implements CodegenConfig { + + 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 = ""; + + /** + * Configures the type of generator. + * + * @return the CodegenType for this generator + * @see io.swagger.codegen.CodegenType + */ + 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 -l flag. + * + * @return the friendly name for the generator + */ + public String getName() { + return "restbed"; + } + + /** + * Returns human-friendly help for the generator. Provide the consumer with + * help tips, parameters here + * + * @return A string value for the help message + */ + public String getHelp() { + return "Generates a C++ API Server with Restbed (https://github.com/Corvusoft/restbed)."; + } + + public RestbedCodegen() { + super(); + + apiPackage = "io.swagger.server.api"; + modelPackage = "io.swagger.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 = "restbed"; + + 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); + + reservedWords = new HashSet(); + + 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"); + + 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 "); + } + + protected void addOption(String key, String description, String defaultValue) { + CliOption option = new CliOption(key, description); + if (defaultValue != null) + option.defaultValue(defaultValue); + cliOptions.add(option); + } + + @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(); + } + + 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); + } + + /** + * Escapes a reserved word as defined in the `reservedWords` array. Handle + * escaping those terms here. This logic is only called if a variable + * matches the reseved words + * + * @return the escaped term + */ + @Override + public String escapeReservedWord(String name) { + return "_" + name; // add an underscore to the name + } + + /** + * Location to write model files. You can use the modelPackage() as defined + * when the class is instantiated + */ + public String modelFileFolder() { + return outputFolder + "/model"; + } + + /** + * Location to write api files. You can use the apiPackage() as defined when + * the class is instantiated + */ + @Override + public String apiFileFolder() { + return outputFolder + "/api"; + } + + @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, Model model, Map allDefinitions) { + CodegenModel codegenModel = super.fromModel(name, model, allDefinitions); + + Set oldImports = codegenModel.imports; + codegenModel.imports = new HashSet(); + for (String imp : oldImports) { + String newImp = toModelImport(imp); + if (!newImp.isEmpty()) { + codegenModel.imports.add(newImp); + } + } + + return codegenModel; + } + + + @Override + public String toModelFilename(String name) { + return initialCaps(name); + } + + @Override + public String toApiFilename(String name) { + return initialCaps(name) + "Api"; + } + + @SuppressWarnings("unchecked") + @Override + public Map postProcessOperations(Map objs) { + Map operations = (Map) objs.get("operations"); + List operationList = (List) operations.get("operation"); + List newOpList = new ArrayList(); + for (CodegenOperation op : operationList) { + String path = new String(op.path); + + String[] items = path.split("/", -1); + List splitPath = new ArrayList(); + op.path = ""; + for (String item: items) { + if (item.matches("^\\{(.*)\\}$")) { + item = item.substring(0, item.length()-1); + item += ": .*}"; + } + splitPath.add(item); + op.path += item + "/"; + } + boolean foundInNewList = false; + for (CodegenOperation op1 : newOpList) { + if (!foundInNewList) { + if (op1.path.equals(op.path)) { + foundInNewList = true; + List currentOtherMethodList = (List) op1.vendorExtensions.get("x-codegen-otherMethods"); + if (currentOtherMethodList == null) { + currentOtherMethodList = new ArrayList(); + } + op.operationIdCamelCase = op1.operationIdCamelCase; + currentOtherMethodList.add(op); + op1.vendorExtensions.put("x-codegen-otherMethods", currentOtherMethodList); + } + } + } + if (!foundInNewList) { + newOpList.add(op); + } + } + operations.put("operation", 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(Property p) { + String swaggerType = getSwaggerType(p); + + if (p instanceof ArrayProperty) { + ArrayProperty ap = (ArrayProperty) p; + Property inner = ap.getItems(); + return getSwaggerType(p) + "<" + getTypeDeclaration(inner) + ">"; + } + if (p instanceof MapProperty) { + MapProperty mp = (MapProperty) p; + Property inner = mp.getAdditionalProperties(); + return getSwaggerType(p) + ""; + } + if (p instanceof StringProperty || p instanceof DateProperty + || p instanceof DateTimeProperty || p instanceof FileProperty + || languageSpecificPrimitives.contains(swaggerType)) { + return toModelName(swaggerType); + } + + return "std::shared_ptr<" + swaggerType + ">"; + } + + @Override + public String toDefaultValue(Property p) { + if (p instanceof StringProperty) { + return "\"\""; + } else if (p instanceof BooleanProperty) { + return "false"; + } else if (p instanceof DateProperty) { + return "\"\""; + } else if (p instanceof DateTimeProperty) { + return "\"\""; + } else if (p instanceof DoubleProperty) { + return "0.0"; + } else if (p instanceof FloatProperty) { + return "0.0f"; + } else if (p instanceof IntegerProperty || p instanceof BaseIntegerProperty) { + return "0"; + } else if (p instanceof LongProperty) { + return "0L"; + } else if (p instanceof DecimalProperty) { + return "0.0"; + } else if (p instanceof MapProperty) { + MapProperty ap = (MapProperty) p; + String inner = getSwaggerType(ap.getAdditionalProperties()); + return "std::map()"; + } else if (p instanceof ArrayProperty) { + ArrayProperty ap = (ArrayProperty) p; + String inner = getSwaggerType(ap.getItems()); + if (!languageSpecificPrimitives.contains(inner)) { + inner = "std::shared_ptr<" + inner + ">"; + } + return "std::vector<" + inner + ">()"; + } else if (p instanceof RefProperty) { + RefProperty rp = (RefProperty) p; + return "new " + toModelName(rp.getSimpleRef()) + "()"; + } + return "nullptr"; + } + + @Override + public void postProcessParameter(CodegenParameter parameter) { + super.postProcessParameter(parameter); + + boolean isPrimitiveType = parameter.isPrimitiveType == Boolean.TRUE; + boolean isListContainer = parameter.isListContainer == Boolean.TRUE; + boolean isString = parameter.isString == Boolean.TRUE; + + if (!isPrimitiveType && !isListContainer && !isString && !parameter.dataType.startsWith("std::shared_ptr")) { + parameter.dataType = "std::shared_ptr<" + parameter.dataType + ">"; + } + } + + /** + * Optional - swagger type conversion. This is used to map swagger types in + * a `Property` 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 + * @see io.swagger.models.properties.Property + */ + @Override + public String getSwaggerType(Property p) { + String swaggerType = super.getSwaggerType(p); + String type = null; + if (typeMapping.containsKey(swaggerType)) { + type = typeMapping.get(swaggerType); + if (languageSpecificPrimitives.contains(type)) + return toModelName(type); + } else + type = swaggerType; + return toModelName(type); + } + + @Override + public String toModelName(String type) { + if (typeMapping.keySet().contains(type) || typeMapping.values().contains(type) + || importMapping.values().contains(type) || defaultIncludes.contains(type) + || languageSpecificPrimitives.contains(type)) { + return type; + } else { + return Character.toUpperCase(type.charAt(0)) + type.substring(1); + } + } + + @Override + public String toVarName(String name) { + if (typeMapping.keySet().contains(name) || typeMapping.values().contains(name) + || importMapping.values().contains(name) || defaultIncludes.contains(name) + || languageSpecificPrimitives.contains(name)) { + return name; + } + + if (name.length() > 1) { + return Character.toUpperCase(name.charAt(0)) + name.substring(1); + } + + return name; + } + + @Override + public String toApiName(String type) { + return Character.toUpperCase(type.charAt(0)) + type.substring(1) + "Api"; + } + + @Override + public String escapeQuotationMark(String input) { + // remove " to avoid code injection + return input.replace("\"", ""); + } + + @Override + public String escapeUnsafeCharacters(String input) { + return input.replace("*/", "*_/").replace("/*", "/_*"); + } + + +} diff --git a/modules/swagger-codegen/src/main/resources/META-INF/services/io.swagger.codegen.CodegenConfig b/modules/swagger-codegen/src/main/resources/META-INF/services/io.swagger.codegen.CodegenConfig index 0cbaedde7a50..b4d8ed733caa 100644 --- a/modules/swagger-codegen/src/main/resources/META-INF/services/io.swagger.codegen.CodegenConfig +++ b/modules/swagger-codegen/src/main/resources/META-INF/services/io.swagger.codegen.CodegenConfig @@ -45,6 +45,7 @@ io.swagger.codegen.languages.PhpClientCodegen io.swagger.codegen.languages.PythonClientCodegen io.swagger.codegen.languages.Qt5CPPGenerator io.swagger.codegen.languages.Rails5ServerCodegen +io.swagger.codegen.languages.RestbedCodegen io.swagger.codegen.languages.RubyClientCodegen io.swagger.codegen.languages.ScalaClientCodegen io.swagger.codegen.languages.ScalatraServerCodegen diff --git a/modules/swagger-codegen/src/main/resources/restbed/README.mustache b/modules/swagger-codegen/src/main/resources/restbed/README.mustache new file mode 100644 index 000000000000..a8850271a9bb --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/restbed/README.mustache @@ -0,0 +1,23 @@ +# REST API Server for {{appName}} + +## Overview +This API Server was generated by the [swagger-codegen](https://github.com/swagger-api/swagger-codegen) 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 +io::swagger::server::api +io::swagger::server::model diff --git a/modules/swagger-codegen/src/main/resources/restbed/api-header.mustache b/modules/swagger-codegen/src/main/resources/restbed/api-header.mustache new file mode 100644 index 000000000000..e934035a63cd --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/restbed/api-header.mustache @@ -0,0 +1,62 @@ +{{>licenseInfo}} +{{#operations}}/* + * {{classname}}.h + * + * {{description}} + */ + +#ifndef {{classname}}_H_ +#define {{classname}}_H_ + +{{{defaultInclude}}} +#include +#include +#include +#include + +{{#imports}}{{{import}}} +{{/imports}} + +{{#apiNamespaceDeclarations}} +namespace {{this}} { +{{/apiNamespaceDeclarations}} + +using namespace {{modelNamespace}}; + +class {{declspec}} {{classname}}: public restbed::Service +{ +public: + {{classname}}(); + ~{{classname}}(); + void startService(int const& port); + void stopService(); +}; + + +{{#operation}} +/// +/// {{summary}} +/// +/// +/// {{notes}} +/// +class {{declspec}} {{classname}}{{operationIdCamelCase}}Resource: public restbed::Resource +{ +public: + {{classname}}{{operationIdCamelCase}}Resource(); + virtual ~{{classname}}{{operationIdCamelCase}}Resource(); + void {{httpMethod}}_method_handler(const std::shared_ptr session); + {{#vendorExtensions.x-codegen-otherMethods}} + void {{httpMethod}}_method_handler(const std::shared_ptr session); + {{/vendorExtensions.x-codegen-otherMethods}} +}; + +{{/operation}} + +{{#apiNamespaceDeclarations}} +} +{{/apiNamespaceDeclarations}} + +#endif /* {{classname}}_H_ */ + +{{/operations}} diff --git a/modules/swagger-codegen/src/main/resources/restbed/api-source.mustache b/modules/swagger-codegen/src/main/resources/restbed/api-source.mustache new file mode 100644 index 000000000000..852627d90411 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/restbed/api-source.mustache @@ -0,0 +1,200 @@ +{{>licenseInfo}} +{{#operations}} + +#include +#include +#include +#include + +#include "{{classname}}.h" + +{{#apiNamespaceDeclarations}} +namespace {{this}} { +{{/apiNamespaceDeclarations}} + +using namespace {{modelNamespace}}; + +{{classname}}::{{classname}}() { + {{#operation}} + std::shared_ptr<{{classname}}{{operationIdCamelCase}}Resource> sp{{classname}}{{operationIdCamelCase}}Resource = std::make_shared<{{classname}}{{operationIdCamelCase}}Resource>(); + this->publish(sp{{classname}}{{operationIdCamelCase}}Resource); + + {{/operation}} +} + +{{classname}}::~{{classname}}() {} + +void {{classname}}::startService(int const& port) { + std::shared_ptr settings = std::make_shared(); + settings->set_port(port); + settings->set_root("{{contextPath}}"); + + this->start(settings); +} + +void {{classname}}::stopService() { + this->stop(); +} + +{{#operation}} +{{classname}}{{operationIdCamelCase}}Resource::{{classname}}{{operationIdCamelCase}}Resource() +{ + this->set_path("{{path}}"); + this->set_method_handler("{{httpMethod}}", + std::bind(&{{classname}}{{operationIdCamelCase}}Resource::{{httpMethod}}_method_handler, this, + std::placeholders::_1)); + {{#vendorExtensions.x-codegen-otherMethods}} + this->set_method_handler("{{httpMethod}}", + std::bind(&{{classname}}{{operationIdCamelCase}}Resource::{{httpMethod}}_method_handler, this, + std::placeholders::_1)); + {{/vendorExtensions.x-codegen-otherMethods}} +} + +{{classname}}{{operationIdCamelCase}}Resource::~{{classname}}{{operationIdCamelCase}}Resource() +{ +} + +void {{classname}}{{operationIdCamelCase}}Resource::{{httpMethod}}_method_handler(const std::shared_ptr session) { + + const auto request = session->get_request(); + {{#hasBodyParam}} + // Body params are present, therefore we have to fetch them + int content_length = request->get_header("Content-Length", 0); + session->fetch(content_length, + [ this ]( const std::shared_ptr session, const restbed::Bytes & body ) + { + + const auto request = session->get_request(); + std::string requestBody = restbed::String::format("%.*s\n", ( int ) body.size( ), body.data( )); + /** + * Get body params or form params here from the requestBody string + */ + {{/hasBodyParam}} + + {{#hasPathParams}} + // Getting the path params + {{#pathParams}} + {{#isPrimitiveType}} + const {{dataType}} {{paramName}} = request->get_path_parameter("{{paramName}}", {{#isString}}""{{/isString}}{{#isInteger}}0{{/isInteger}}{{#isLong}}0L{{/isLong}}{{#isFloat}}0.0f{{/isFloat}}{{#isDouble}}0.0{{/isDouble}}); + {{/isPrimitiveType}} + {{/pathParams}} + {{/hasPathParams}} + + {{#hasQueryParams}} + // Getting the query params + {{#queryParams}} + {{#isPrimitiveType}} + const {{dataType}} {{paramName}} = request->get_query_parameter("{{paramName}}", {{#isString}}""{{/isString}}{{#isInteger}}0{{/isInteger}}{{#isLong}}0L{{/isLong}}{{#isFloat}}0.0f{{/isFloat}}{{#isDouble}}0.0{{/isDouble}}); + {{/isPrimitiveType}} + {{/queryParams}} + {{/hasQueryParams}} + + {{#hasHeaderParams}} + // Getting the headers + {{#headerParams}} + {{#isPrimitiveType}} + const {{dataType}} {{paramName}} = request->get_header("{{paramName}}", {{#isString}}""{{/isString}}{{#isInteger}}0{{/isInteger}}{{#isLong}}0L{{/isLong}}{{#isFloat}}0.0f{{/isFloat}}{{#isDouble}}0.0{{/isDouble}}); + {{/isPrimitiveType}} + {{/headerParams}} + {{/hasHeaderParams}} + + // Change the value of this variable to the appropriate response before sending the response + int status_code = 200; + + /** + * Process the received information here + */ + + {{#responses}} + if (status_code == {{code}}) { + {{#headers}} + // Description: {{description}} + session->set_header("{{baseName}}", ""); // Change second param to your header value + {{/headers}} + session->close({{code}}, "{{message}}", { {"Connection", "close"} }); + return; + } + {{/responses}} + + {{#hasBodyParam}} + }); + {{/hasBodyParam}} +} + +{{#vendorExtensions.x-codegen-otherMethods}} +void {{classname}}{{operationIdCamelCase}}Resource::{{httpMethod}}_method_handler(const std::shared_ptr session) { + + const auto request = session->get_request(); + {{#hasBodyParam}} + // Body params are present, therefore we have to fetch them + int content_length = request->get_header("Content-Length", 0); + session->fetch(content_length, + [ this ]( const std::shared_ptr session, const restbed::Bytes & body ) + { + + const auto request = session->get_request(); + std::string requestBody = restbed::String::format("%.*s\n", ( int ) body.size( ), body.data( )); + {{/hasBodyParam}} + + {{#hasPathParams}} + // Getting the path params + {{#pathParams}} + {{#isPrimitiveType}} + const {{dataType}} {{paramName}} = request->get_path_parameter("{{paramName}}", {{#isString}}""{{/isString}}{{#isInteger}}0{{/isInteger}}{{#isLong}}0L{{/isLong}}{{#isFloat}}0.0f{{/isFloat}}{{#isDouble}}0.0{{/isDouble}}); + {{/isPrimitiveType}} + {{/pathParams}} + {{/hasPathParams}} + + {{#hasQueryParams}} + // Getting the query params + {{#queryParams}} + {{#isPrimitiveType}} + const {{dataType}} {{paramName}} = request->get_query_parameter("{{paramName}}", {{#isString}}""{{/isString}}{{#isInteger}}0{{/isInteger}}{{#isLong}}0L{{/isLong}}{{#isFloat}}0.0f{{/isFloat}}{{#isDouble}}0.0{{/isDouble}}); + {{/isPrimitiveType}} + {{/queryParams}} + {{/hasQueryParams}} + + {{#hasHeaderParams}} + // Getting the headers + {{#headerParams}} + {{#isPrimitiveType}} + const {{dataType}} {{paramName}} = request->get_header("{{paramName}}", {{#isString}}""{{/isString}}{{#isInteger}}0{{/isInteger}}{{#isLong}}0L{{/isLong}}{{#isFloat}}0.0f{{/isFloat}}{{#isDouble}}0.0{{/isDouble}}); + {{/isPrimitiveType}} + {{/headerParams}} + {{/hasHeaderParams}} + + // Change the value of this variable to the appropriate response before sending the response + int status_code = 200; + + /** + * Process the received information here + */ + + {{#responses}} + if (status_code == {{code}}) { + {{#baseType}} + std::shared_ptr<{{.}}> response = NULL; + {{/baseType}} + {{#headers}} + // Description: {{description}} + session->set_header("{{baseName}}", ""); // Change second param to your header value + {{/headers}} + session->close({{code}}, "{{message}}", { {"Connection", "close"} }); + return; + } + {{/responses}} + + {{#hasBodyParam}} + }); + {{/hasBodyParam}} +} +{{/vendorExtensions.x-codegen-otherMethods}} + + +{{/operation}} + +{{#apiNamespaceDeclarations}} +} +{{/apiNamespaceDeclarations}} + +{{/operations}} diff --git a/modules/swagger-codegen/src/main/resources/restbed/git_push.sh.mustache b/modules/swagger-codegen/src/main/resources/restbed/git_push.sh.mustache new file mode 100644 index 000000000000..c7d7c390acf3 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/restbed/git_push.sh.mustache @@ -0,0 +1,51 @@ +#!/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 swagger-petstore-cpprest "minor update" + +git_user_id=$1 +git_repo_id=$2 +release_note=$3 + +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 crediential in your environment." + git remote add origin https://github.com/${git_user_id}/${git_repo_id}.git + else + git remote add origin https://${git_user_id}:${GIT_TOKEN}@github.com/${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://github.com/${git_user_id}/${git_repo_id}.git" +git push origin master 2>&1 | grep -v 'To https' diff --git a/modules/swagger-codegen/src/main/resources/restbed/gitignore.mustache b/modules/swagger-codegen/src/main/resources/restbed/gitignore.mustache new file mode 100644 index 000000000000..4581ef2eeefc --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/restbed/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/swagger-codegen/src/main/resources/restbed/licenseInfo.mustache b/modules/swagger-codegen/src/main/resources/restbed/licenseInfo.mustache new file mode 100644 index 000000000000..bbd8742e52a5 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/restbed/licenseInfo.mustache @@ -0,0 +1,11 @@ +/** + * {{{appName}}} + * {{{appDescription}}} + * + * {{#version}}OpenAPI spec version: {{{version}}}{{/version}} + * {{#infoEmail}}Contact: {{{infoEmail}}}{{/infoEmail}} + * + * NOTE: This class is auto generated by the swagger code generator program. + * https://github.com/swagger-api/swagger-codegen.git + * Do not edit the class manually. + */ diff --git a/modules/swagger-codegen/src/main/resources/restbed/model-header.mustache b/modules/swagger-codegen/src/main/resources/restbed/model-header.mustache new file mode 100644 index 000000000000..634472e9a3a6 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/restbed/model-header.mustache @@ -0,0 +1,58 @@ +{{>licenseInfo}} +{{#models}}{{#model}}/* + * {{classname}}.h + * + * {{description}} + */ + +#ifndef {{classname}}_H_ +#define {{classname}}_H_ + +{{{defaultInclude}}} + +{{#imports}}{{{this}}} +{{/imports}} +#include + +{{#modelNamespaceDeclarations}} +namespace {{this}} { +{{/modelNamespaceDeclarations}} + +/// +/// {{description}} +/// +class {{declspec}} {{classname}} +{ +public: + {{classname}}(); + virtual ~{{classname}}(); + + std::string toJsonString(); + void fromJsonString(std::string const& jsonString); + + ///////////////////////////////////////////// + /// {{classname}} members + + {{#vars}} + /// + /// {{description}} + /// + {{^isNotContainer}}{{{datatype}}}& {{getter}}(); + {{/isNotContainer}}{{#isNotContainer}}{{{datatype}}} {{getter}}() const; + void {{setter}}({{{datatype}}} value); + {{/isNotContainer}} + {{/vars}} + +protected: + {{#vars}} + {{{datatype}}} m_{{name}}; + {{/vars}} +}; + +{{#modelNamespaceDeclarations}} +} +{{/modelNamespaceDeclarations}} + +#endif /* {{classname}}_H_ */ +{{/model}} +{{/models}} diff --git a/modules/swagger-codegen/src/main/resources/restbed/model-source.mustache b/modules/swagger-codegen/src/main/resources/restbed/model-source.mustache new file mode 100644 index 000000000000..c93f8d793217 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/restbed/model-source.mustache @@ -0,0 +1,96 @@ +{{>licenseInfo}} +{{#models}}{{#model}} + +#include "{{classname}}.h" + +#include +#include +#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}}() +{ + {{#vars}}{{#isNotContainer}}{{#isPrimitiveType}}m_{{name}} = {{{defaultValue}}}; + {{/isPrimitiveType}}{{^isPrimitiveType}}{{#isString}}m_{{name}} = {{{defaultValue}}}; + {{/isString}}{{#isDateTime}}m_{{name}} = {{{defaultValue}}}; + {{/isDateTime}}{{/isPrimitiveType}}{{/isNotContainer}}{{/vars}} +} + +{{classname}}::~{{classname}}() +{ +} + +std::string {{classname}}::toJsonString() +{ + std::stringstream ss; + ptree pt; + {{#vars}} + {{#isNotContainer}} + {{#isPrimitiveType}} + pt.put("{{name}}", m_{{name}}); + {{/isPrimitiveType}} + {{^isPrimitiveType}} + {{#isString}} + pt.put("{{name}}", m_{{name}}); + {{/isString}} + {{#isDateTime}} + pt.put("{{name}}", m_{{name}}); + {{/isDateTime}} + {{/isPrimitiveType}} + {{/isNotContainer}} + {{/vars}} + write_json(ss, pt, false); + return ss.str(); +} + +void {{classname}}::fromJsonString(std::string const& jsonString) +{ + std::stringstream ss(jsonString); + ptree pt; + read_json(ss,pt); + {{#vars}} + {{#isNotContainer}} + {{#isPrimitiveType}} + m_{{name}} = pt.get("{{name}}", {{{defaultValue}}}); + {{/isPrimitiveType}} + {{^isPrimitiveType}} + {{#isString}} + m_{{name}} = pt.get("{{name}}", {{{defaultValue}}}); + {{/isString}} + {{#isDateTime}} + m_{{name}} = pt.get("{{name}}", {{{defaultValue}}}); + {{/isDateTime}} + {{/isPrimitiveType}} + {{/isNotContainer}} + {{/vars}} +} + +{{#vars}}{{^isNotContainer}}{{{datatype}}}& {{classname}}::{{getter}}() +{ + return m_{{name}}; +} +{{/isNotContainer}}{{#isNotContainer}}{{{datatype}}} {{classname}}::{{getter}}() const +{ + return m_{{name}}; +} +void {{classname}}::{{setter}}({{{datatype}}} value) +{ + m_{{name}} = value; +} +{{/isNotContainer}} +{{/vars}} + +{{#modelNamespaceDeclarations}} +} +{{/modelNamespaceDeclarations}} + +{{/model}} +{{/models}} diff --git a/samples/server/petstore/restbed/.gitignore b/samples/server/petstore/restbed/.gitignore new file mode 100644 index 000000000000..4581ef2eeefc --- /dev/null +++ b/samples/server/petstore/restbed/.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/restbed/.swagger-codegen-ignore b/samples/server/petstore/restbed/.swagger-codegen-ignore new file mode 100644 index 000000000000..c5fa491b4c55 --- /dev/null +++ b/samples/server/petstore/restbed/.swagger-codegen-ignore @@ -0,0 +1,23 @@ +# Swagger Codegen Ignore +# Generated by swagger-codegen https://github.com/swagger-api/swagger-codegen + +# 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 Swagger Codgen 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/restbed/.swagger-codegen/VERSION b/samples/server/petstore/restbed/.swagger-codegen/VERSION new file mode 100644 index 000000000000..7fea99011a6f --- /dev/null +++ b/samples/server/petstore/restbed/.swagger-codegen/VERSION @@ -0,0 +1 @@ +2.2.3-SNAPSHOT \ No newline at end of file diff --git a/samples/server/petstore/restbed/README.md b/samples/server/petstore/restbed/README.md new file mode 100644 index 000000000000..5f3ca0fbd99c --- /dev/null +++ b/samples/server/petstore/restbed/README.md @@ -0,0 +1,23 @@ +# REST API Server for Swagger Petstore + +## Overview +This API Server was generated by the [swagger-codegen](https://github.com/swagger-api/swagger-codegen) 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 +io::swagger::server::api +io::swagger::server::model diff --git a/samples/server/petstore/restbed/api/PetApi.cpp b/samples/server/petstore/restbed/api/PetApi.cpp new file mode 100644 index 000000000000..aaceb24001ba --- /dev/null +++ b/samples/server/petstore/restbed/api/PetApi.cpp @@ -0,0 +1,367 @@ +/** + * Swagger Petstore + * This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters. + * + * OpenAPI spec version: 1.0.0 + * Contact: apiteam@swagger.io + * + * NOTE: This class is auto generated by the swagger code generator program. + * https://github.com/swagger-api/swagger-codegen.git + * Do not edit the class manually. + */ + + +#include +#include +#include +#include + +#include "PetApi.h" + +namespace io { +namespace swagger { +namespace server { +namespace api { + +using namespace io::swagger::server::model; + +PetApi::PetApi() { + std::shared_ptr spPetApiAddPetResource = std::make_shared(); + this->publish(spPetApiAddPetResource); + + std::shared_ptr spPetApiDeletePetResource = std::make_shared(); + this->publish(spPetApiDeletePetResource); + + std::shared_ptr spPetApiFindPetsByStatusResource = std::make_shared(); + this->publish(spPetApiFindPetsByStatusResource); + + std::shared_ptr spPetApiFindPetsByTagsResource = std::make_shared(); + this->publish(spPetApiFindPetsByTagsResource); + + std::shared_ptr spPetApiUploadFileResource = std::make_shared(); + this->publish(spPetApiUploadFileResource); + +} + +PetApi::~PetApi() {} + +void PetApi::startService(int const& port) { + std::shared_ptr settings = std::make_shared(); + settings->set_port(port); + settings->set_root("/v2"); + + this->start(settings); +} + +void PetApi::stopService() { + this->stop(); +} + +PetApiAddPetResource::PetApiAddPetResource() +{ + this->set_path("/pet/"); + this->set_method_handler("POST", + std::bind(&PetApiAddPetResource::POST_method_handler, this, + std::placeholders::_1)); + this->set_method_handler("PUT", + std::bind(&PetApiAddPetResource::PUT_method_handler, this, + std::placeholders::_1)); +} + +PetApiAddPetResource::~PetApiAddPetResource() +{ +} + +void PetApiAddPetResource::POST_method_handler(const std::shared_ptr session) { + + const auto request = session->get_request(); + // Body params are present, therefore we have to fetch them + int content_length = request->get_header("Content-Length", 0); + session->fetch(content_length, + [ this ]( const std::shared_ptr session, const restbed::Bytes & body ) + { + + const auto request = session->get_request(); + std::string requestBody = restbed::String::format("%.*s\n", ( int ) body.size( ), body.data( )); + /** + * Get body params or form params here from the requestBody string + */ + + + + + // Change the value of this variable to the appropriate response before sending the response + int status_code = 200; + + /** + * Process the received information here + */ + + if (status_code == 405) { + session->close(405, "Invalid input", { {"Connection", "close"} }); + return; + } + + }); +} + +void PetApiAddPetResource::PUT_method_handler(const std::shared_ptr session) { + + const auto request = session->get_request(); + // Body params are present, therefore we have to fetch them + int content_length = request->get_header("Content-Length", 0); + session->fetch(content_length, + [ this ]( const std::shared_ptr session, const restbed::Bytes & body ) + { + + const auto request = session->get_request(); + std::string requestBody = restbed::String::format("%.*s\n", ( int ) body.size( ), body.data( )); + + + + + // Change the value of this variable to the appropriate response before sending the response + int status_code = 200; + + /** + * Process the received information here + */ + + if (status_code == 400) { + session->close(400, "Invalid ID supplied", { {"Connection", "close"} }); + return; + } + if (status_code == 404) { + session->close(404, "Pet not found", { {"Connection", "close"} }); + return; + } + if (status_code == 405) { + session->close(405, "Validation exception", { {"Connection", "close"} }); + return; + } + + }); +} + + +PetApiDeletePetResource::PetApiDeletePetResource() +{ + this->set_path("/pet/{petId: .*}/"); + this->set_method_handler("DELETE", + std::bind(&PetApiDeletePetResource::DELETE_method_handler, this, + std::placeholders::_1)); + this->set_method_handler("GET", + std::bind(&PetApiDeletePetResource::GET_method_handler, this, + std::placeholders::_1)); + this->set_method_handler("POST", + std::bind(&PetApiDeletePetResource::POST_method_handler, this, + std::placeholders::_1)); +} + +PetApiDeletePetResource::~PetApiDeletePetResource() +{ +} + +void PetApiDeletePetResource::DELETE_method_handler(const std::shared_ptr session) { + + const auto request = session->get_request(); + + // Getting the path params + const int64_t petId = request->get_path_parameter("petId", 0L); + + + // Getting the headers + const std::string apiKey = request->get_header("apiKey", ""); + + // Change the value of this variable to the appropriate response before sending the response + int status_code = 200; + + /** + * Process the received information here + */ + + if (status_code == 400) { + session->close(400, "Invalid pet value", { {"Connection", "close"} }); + return; + } + +} + +void PetApiDeletePetResource::GET_method_handler(const std::shared_ptr session) { + + const auto request = session->get_request(); + + // Getting the path params + const int64_t petId = request->get_path_parameter("petId", 0L); + + + + // Change the value of this variable to the appropriate response before sending the response + int status_code = 200; + + /** + * Process the received information here + */ + + if (status_code == 200) { + std::shared_ptr response = NULL; + session->close(200, "successful operation", { {"Connection", "close"} }); + return; + } + if (status_code == 400) { + session->close(400, "Invalid ID supplied", { {"Connection", "close"} }); + return; + } + if (status_code == 404) { + session->close(404, "Pet not found", { {"Connection", "close"} }); + return; + } + +} +void PetApiDeletePetResource::POST_method_handler(const std::shared_ptr session) { + + const auto request = session->get_request(); + + // Getting the path params + const int64_t petId = request->get_path_parameter("petId", 0L); + + + + // Change the value of this variable to the appropriate response before sending the response + int status_code = 200; + + /** + * Process the received information here + */ + + if (status_code == 405) { + session->close(405, "Invalid input", { {"Connection", "close"} }); + return; + } + +} + + +PetApiFindPetsByStatusResource::PetApiFindPetsByStatusResource() +{ + this->set_path("/pet/findByStatus/"); + this->set_method_handler("GET", + std::bind(&PetApiFindPetsByStatusResource::GET_method_handler, this, + std::placeholders::_1)); +} + +PetApiFindPetsByStatusResource::~PetApiFindPetsByStatusResource() +{ +} + +void PetApiFindPetsByStatusResource::GET_method_handler(const std::shared_ptr session) { + + const auto request = session->get_request(); + + + // Getting the query params + + + // Change the value of this variable to the appropriate response before sending the response + int status_code = 200; + + /** + * Process the received information here + */ + + if (status_code == 200) { + session->close(200, "successful operation", { {"Connection", "close"} }); + return; + } + if (status_code == 400) { + session->close(400, "Invalid status value", { {"Connection", "close"} }); + return; + } + +} + + + +PetApiFindPetsByTagsResource::PetApiFindPetsByTagsResource() +{ + this->set_path("/pet/findByTags/"); + this->set_method_handler("GET", + std::bind(&PetApiFindPetsByTagsResource::GET_method_handler, this, + std::placeholders::_1)); +} + +PetApiFindPetsByTagsResource::~PetApiFindPetsByTagsResource() +{ +} + +void PetApiFindPetsByTagsResource::GET_method_handler(const std::shared_ptr session) { + + const auto request = session->get_request(); + + + // Getting the query params + + + // Change the value of this variable to the appropriate response before sending the response + int status_code = 200; + + /** + * Process the received information here + */ + + if (status_code == 200) { + session->close(200, "successful operation", { {"Connection", "close"} }); + return; + } + if (status_code == 400) { + session->close(400, "Invalid tag value", { {"Connection", "close"} }); + return; + } + +} + + + +PetApiUploadFileResource::PetApiUploadFileResource() +{ + this->set_path("/pet/{petId: .*}/uploadImage/"); + this->set_method_handler("POST", + std::bind(&PetApiUploadFileResource::POST_method_handler, this, + std::placeholders::_1)); +} + +PetApiUploadFileResource::~PetApiUploadFileResource() +{ +} + +void PetApiUploadFileResource::POST_method_handler(const std::shared_ptr session) { + + const auto request = session->get_request(); + + // Getting the path params + const int64_t petId = request->get_path_parameter("petId", 0L); + + + + // Change the value of this variable to the appropriate response before sending the response + int status_code = 200; + + /** + * Process the received information here + */ + + if (status_code == 200) { + session->close(200, "successful operation", { {"Connection", "close"} }); + return; + } + +} + + + + +} +} +} +} + diff --git a/samples/server/petstore/restbed/api/PetApi.h b/samples/server/petstore/restbed/api/PetApi.h new file mode 100644 index 000000000000..eff260b039e0 --- /dev/null +++ b/samples/server/petstore/restbed/api/PetApi.h @@ -0,0 +1,129 @@ +/** + * Swagger Petstore + * This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters. + * + * OpenAPI spec version: 1.0.0 + * Contact: apiteam@swagger.io + * + * NOTE: This class is auto generated by the swagger code generator program. + * https://github.com/swagger-api/swagger-codegen.git + * Do not edit the class manually. + */ + +/* + * PetApi.h + * + * + */ + +#ifndef PetApi_H_ +#define PetApi_H_ + + +#include +#include +#include +#include + +#include "ApiResponse.h" +#include "Pet.h" +#include + +namespace io { +namespace swagger { +namespace server { +namespace api { + +using namespace io::swagger::server::model; + +class PetApi: public restbed::Service +{ +public: + PetApi(); + ~PetApi(); + void startService(int const& port); + void stopService(); +}; + + +/// +/// Add a new pet to the store +/// +/// +/// +/// +class PetApiAddPetResource: public restbed::Resource +{ +public: + PetApiAddPetResource(); + virtual ~PetApiAddPetResource(); + void POST_method_handler(const std::shared_ptr session); + void PUT_method_handler(const std::shared_ptr session); +}; + +/// +/// Deletes a pet +/// +/// +/// +/// +class PetApiDeletePetResource: public restbed::Resource +{ +public: + PetApiDeletePetResource(); + virtual ~PetApiDeletePetResource(); + void DELETE_method_handler(const std::shared_ptr session); + void GET_method_handler(const std::shared_ptr session); + void POST_method_handler(const std::shared_ptr session); +}; + +/// +/// Finds Pets by status +/// +/// +/// Multiple status values can be provided with comma separated strings +/// +class PetApiFindPetsByStatusResource: public restbed::Resource +{ +public: + PetApiFindPetsByStatusResource(); + virtual ~PetApiFindPetsByStatusResource(); + void GET_method_handler(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 PetApiFindPetsByTagsResource: public restbed::Resource +{ +public: + PetApiFindPetsByTagsResource(); + virtual ~PetApiFindPetsByTagsResource(); + void GET_method_handler(const std::shared_ptr session); +}; + +/// +/// uploads an image +/// +/// +/// +/// +class PetApiUploadFileResource: public restbed::Resource +{ +public: + PetApiUploadFileResource(); + virtual ~PetApiUploadFileResource(); + void POST_method_handler(const std::shared_ptr session); +}; + + +} +} +} +} + +#endif /* PetApi_H_ */ + diff --git a/samples/server/petstore/restbed/api/StoreApi.cpp b/samples/server/petstore/restbed/api/StoreApi.cpp new file mode 100644 index 000000000000..f3b6e97b94ca --- /dev/null +++ b/samples/server/petstore/restbed/api/StoreApi.cpp @@ -0,0 +1,220 @@ +/** + * Swagger Petstore + * This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters. + * + * OpenAPI spec version: 1.0.0 + * Contact: apiteam@swagger.io + * + * NOTE: This class is auto generated by the swagger code generator program. + * https://github.com/swagger-api/swagger-codegen.git + * Do not edit the class manually. + */ + + +#include +#include +#include +#include + +#include "StoreApi.h" + +namespace io { +namespace swagger { +namespace server { +namespace api { + +using namespace io::swagger::server::model; + +StoreApi::StoreApi() { + std::shared_ptr spStoreApiDeleteOrderResource = std::make_shared(); + this->publish(spStoreApiDeleteOrderResource); + + std::shared_ptr spStoreApiGetInventoryResource = std::make_shared(); + this->publish(spStoreApiGetInventoryResource); + + std::shared_ptr spStoreApiPlaceOrderResource = std::make_shared(); + this->publish(spStoreApiPlaceOrderResource); + +} + +StoreApi::~StoreApi() {} + +void StoreApi::startService(int const& port) { + std::shared_ptr settings = std::make_shared(); + settings->set_port(port); + settings->set_root("/v2"); + + this->start(settings); +} + +void StoreApi::stopService() { + this->stop(); +} + +StoreApiDeleteOrderResource::StoreApiDeleteOrderResource() +{ + this->set_path("/store/order/{orderId: .*}/"); + this->set_method_handler("DELETE", + std::bind(&StoreApiDeleteOrderResource::DELETE_method_handler, this, + std::placeholders::_1)); + this->set_method_handler("GET", + std::bind(&StoreApiDeleteOrderResource::GET_method_handler, this, + std::placeholders::_1)); +} + +StoreApiDeleteOrderResource::~StoreApiDeleteOrderResource() +{ +} + +void StoreApiDeleteOrderResource::DELETE_method_handler(const std::shared_ptr session) { + + const auto request = session->get_request(); + + // Getting the path params + const std::string orderId = request->get_path_parameter("orderId", ""); + + + + // Change the value of this variable to the appropriate response before sending the response + int status_code = 200; + + /** + * Process the received information here + */ + + if (status_code == 400) { + session->close(400, "Invalid ID supplied", { {"Connection", "close"} }); + return; + } + if (status_code == 404) { + session->close(404, "Order not found", { {"Connection", "close"} }); + return; + } + +} + +void StoreApiDeleteOrderResource::GET_method_handler(const std::shared_ptr session) { + + const auto request = session->get_request(); + + // Getting the path params + const int64_t orderId = request->get_path_parameter("orderId", 0L); + + + + // Change the value of this variable to the appropriate response before sending the response + int status_code = 200; + + /** + * Process the received information here + */ + + if (status_code == 200) { + std::shared_ptr response = NULL; + session->close(200, "successful operation", { {"Connection", "close"} }); + return; + } + if (status_code == 400) { + session->close(400, "Invalid ID supplied", { {"Connection", "close"} }); + return; + } + if (status_code == 404) { + session->close(404, "Order not found", { {"Connection", "close"} }); + return; + } + +} + + +StoreApiGetInventoryResource::StoreApiGetInventoryResource() +{ + this->set_path("/store/inventory/"); + this->set_method_handler("GET", + std::bind(&StoreApiGetInventoryResource::GET_method_handler, this, + std::placeholders::_1)); +} + +StoreApiGetInventoryResource::~StoreApiGetInventoryResource() +{ +} + +void StoreApiGetInventoryResource::GET_method_handler(const std::shared_ptr session) { + + const auto request = session->get_request(); + + + + + // Change the value of this variable to the appropriate response before sending the response + int status_code = 200; + + /** + * Process the received information here + */ + + if (status_code == 200) { + session->close(200, "successful operation", { {"Connection", "close"} }); + return; + } + +} + + + +StoreApiPlaceOrderResource::StoreApiPlaceOrderResource() +{ + this->set_path("/store/order/"); + this->set_method_handler("POST", + std::bind(&StoreApiPlaceOrderResource::POST_method_handler, this, + std::placeholders::_1)); +} + +StoreApiPlaceOrderResource::~StoreApiPlaceOrderResource() +{ +} + +void StoreApiPlaceOrderResource::POST_method_handler(const std::shared_ptr session) { + + const auto request = session->get_request(); + // Body params are present, therefore we have to fetch them + int content_length = request->get_header("Content-Length", 0); + session->fetch(content_length, + [ this ]( const std::shared_ptr session, const restbed::Bytes & body ) + { + + const auto request = session->get_request(); + std::string requestBody = restbed::String::format("%.*s\n", ( int ) body.size( ), body.data( )); + /** + * Get body params or form params here from the requestBody string + */ + + + + + // Change the value of this variable to the appropriate response before sending the response + int status_code = 200; + + /** + * Process the received information here + */ + + if (status_code == 200) { + session->close(200, "successful operation", { {"Connection", "close"} }); + return; + } + if (status_code == 400) { + session->close(400, "Invalid Order", { {"Connection", "close"} }); + return; + } + + }); +} + + + + +} +} +} +} + diff --git a/samples/server/petstore/restbed/api/StoreApi.h b/samples/server/petstore/restbed/api/StoreApi.h new file mode 100644 index 000000000000..d4765c108234 --- /dev/null +++ b/samples/server/petstore/restbed/api/StoreApi.h @@ -0,0 +1,99 @@ +/** + * Swagger Petstore + * This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters. + * + * OpenAPI spec version: 1.0.0 + * Contact: apiteam@swagger.io + * + * NOTE: This class is auto generated by the swagger code generator program. + * https://github.com/swagger-api/swagger-codegen.git + * Do not edit the class manually. + */ + +/* + * StoreApi.h + * + * + */ + +#ifndef StoreApi_H_ +#define StoreApi_H_ + + +#include +#include +#include +#include + +#include "Order.h" +#include +#include + +namespace io { +namespace swagger { +namespace server { +namespace api { + +using namespace io::swagger::server::model; + +class StoreApi: public restbed::Service +{ +public: + StoreApi(); + ~StoreApi(); + void startService(int const& port); + void stopService(); +}; + + +/// +/// Delete purchase order by ID +/// +/// +/// For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors +/// +class StoreApiDeleteOrderResource: public restbed::Resource +{ +public: + StoreApiDeleteOrderResource(); + virtual ~StoreApiDeleteOrderResource(); + void DELETE_method_handler(const std::shared_ptr session); + void GET_method_handler(const std::shared_ptr session); +}; + +/// +/// Returns pet inventories by status +/// +/// +/// Returns a map of status codes to quantities +/// +class StoreApiGetInventoryResource: public restbed::Resource +{ +public: + StoreApiGetInventoryResource(); + virtual ~StoreApiGetInventoryResource(); + void GET_method_handler(const std::shared_ptr session); +}; + +/// +/// Place an order for a pet +/// +/// +/// +/// +class StoreApiPlaceOrderResource: public restbed::Resource +{ +public: + StoreApiPlaceOrderResource(); + virtual ~StoreApiPlaceOrderResource(); + void POST_method_handler(const std::shared_ptr session); +}; + + +} +} +} +} + +#endif /* StoreApi_H_ */ + diff --git a/samples/server/petstore/restbed/api/UserApi.cpp b/samples/server/petstore/restbed/api/UserApi.cpp new file mode 100644 index 000000000000..3477f3c4926f --- /dev/null +++ b/samples/server/petstore/restbed/api/UserApi.cpp @@ -0,0 +1,403 @@ +/** + * Swagger Petstore + * This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters. + * + * OpenAPI spec version: 1.0.0 + * Contact: apiteam@swagger.io + * + * NOTE: This class is auto generated by the swagger code generator program. + * https://github.com/swagger-api/swagger-codegen.git + * Do not edit the class manually. + */ + + +#include +#include +#include +#include + +#include "UserApi.h" + +namespace io { +namespace swagger { +namespace server { +namespace api { + +using namespace io::swagger::server::model; + +UserApi::UserApi() { + std::shared_ptr spUserApiCreateUserResource = std::make_shared(); + this->publish(spUserApiCreateUserResource); + + std::shared_ptr spUserApiCreateUsersWithArrayInputResource = std::make_shared(); + this->publish(spUserApiCreateUsersWithArrayInputResource); + + std::shared_ptr spUserApiCreateUsersWithListInputResource = std::make_shared(); + this->publish(spUserApiCreateUsersWithListInputResource); + + std::shared_ptr spUserApiDeleteUserResource = std::make_shared(); + this->publish(spUserApiDeleteUserResource); + + std::shared_ptr spUserApiLoginUserResource = std::make_shared(); + this->publish(spUserApiLoginUserResource); + + std::shared_ptr spUserApiLogoutUserResource = std::make_shared(); + this->publish(spUserApiLogoutUserResource); + +} + +UserApi::~UserApi() {} + +void UserApi::startService(int const& port) { + std::shared_ptr settings = std::make_shared(); + settings->set_port(port); + settings->set_root("/v2"); + + this->start(settings); +} + +void UserApi::stopService() { + this->stop(); +} + +UserApiCreateUserResource::UserApiCreateUserResource() +{ + this->set_path("/user/"); + this->set_method_handler("POST", + std::bind(&UserApiCreateUserResource::POST_method_handler, this, + std::placeholders::_1)); +} + +UserApiCreateUserResource::~UserApiCreateUserResource() +{ +} + +void UserApiCreateUserResource::POST_method_handler(const std::shared_ptr session) { + + const auto request = session->get_request(); + // Body params are present, therefore we have to fetch them + int content_length = request->get_header("Content-Length", 0); + session->fetch(content_length, + [ this ]( const std::shared_ptr session, const restbed::Bytes & body ) + { + + const auto request = session->get_request(); + std::string requestBody = restbed::String::format("%.*s\n", ( int ) body.size( ), body.data( )); + /** + * Get body params or form params here from the requestBody string + */ + + + + + // Change the value of this variable to the appropriate response before sending the response + int status_code = 200; + + /** + * Process the received information here + */ + + if (status_code == 0) { + session->close(0, "successful operation", { {"Connection", "close"} }); + return; + } + + }); +} + + + +UserApiCreateUsersWithArrayInputResource::UserApiCreateUsersWithArrayInputResource() +{ + this->set_path("/user/createWithArray/"); + this->set_method_handler("POST", + std::bind(&UserApiCreateUsersWithArrayInputResource::POST_method_handler, this, + std::placeholders::_1)); +} + +UserApiCreateUsersWithArrayInputResource::~UserApiCreateUsersWithArrayInputResource() +{ +} + +void UserApiCreateUsersWithArrayInputResource::POST_method_handler(const std::shared_ptr session) { + + const auto request = session->get_request(); + // Body params are present, therefore we have to fetch them + int content_length = request->get_header("Content-Length", 0); + session->fetch(content_length, + [ this ]( const std::shared_ptr session, const restbed::Bytes & body ) + { + + const auto request = session->get_request(); + std::string requestBody = restbed::String::format("%.*s\n", ( int ) body.size( ), body.data( )); + /** + * Get body params or form params here from the requestBody string + */ + + + + + // Change the value of this variable to the appropriate response before sending the response + int status_code = 200; + + /** + * Process the received information here + */ + + if (status_code == 0) { + session->close(0, "successful operation", { {"Connection", "close"} }); + return; + } + + }); +} + + + +UserApiCreateUsersWithListInputResource::UserApiCreateUsersWithListInputResource() +{ + this->set_path("/user/createWithList/"); + this->set_method_handler("POST", + std::bind(&UserApiCreateUsersWithListInputResource::POST_method_handler, this, + std::placeholders::_1)); +} + +UserApiCreateUsersWithListInputResource::~UserApiCreateUsersWithListInputResource() +{ +} + +void UserApiCreateUsersWithListInputResource::POST_method_handler(const std::shared_ptr session) { + + const auto request = session->get_request(); + // Body params are present, therefore we have to fetch them + int content_length = request->get_header("Content-Length", 0); + session->fetch(content_length, + [ this ]( const std::shared_ptr session, const restbed::Bytes & body ) + { + + const auto request = session->get_request(); + std::string requestBody = restbed::String::format("%.*s\n", ( int ) body.size( ), body.data( )); + /** + * Get body params or form params here from the requestBody string + */ + + + + + // Change the value of this variable to the appropriate response before sending the response + int status_code = 200; + + /** + * Process the received information here + */ + + if (status_code == 0) { + session->close(0, "successful operation", { {"Connection", "close"} }); + return; + } + + }); +} + + + +UserApiDeleteUserResource::UserApiDeleteUserResource() +{ + this->set_path("/user/{username: .*}/"); + this->set_method_handler("DELETE", + std::bind(&UserApiDeleteUserResource::DELETE_method_handler, this, + std::placeholders::_1)); + this->set_method_handler("GET", + std::bind(&UserApiDeleteUserResource::GET_method_handler, this, + std::placeholders::_1)); + this->set_method_handler("PUT", + std::bind(&UserApiDeleteUserResource::PUT_method_handler, this, + std::placeholders::_1)); +} + +UserApiDeleteUserResource::~UserApiDeleteUserResource() +{ +} + +void UserApiDeleteUserResource::DELETE_method_handler(const std::shared_ptr session) { + + const auto request = session->get_request(); + + // Getting the path params + const std::string username = request->get_path_parameter("username", ""); + + + + // Change the value of this variable to the appropriate response before sending the response + int status_code = 200; + + /** + * Process the received information here + */ + + if (status_code == 400) { + session->close(400, "Invalid username supplied", { {"Connection", "close"} }); + return; + } + if (status_code == 404) { + session->close(404, "User not found", { {"Connection", "close"} }); + return; + } + +} + +void UserApiDeleteUserResource::GET_method_handler(const std::shared_ptr session) { + + const auto request = session->get_request(); + + // Getting the path params + const std::string username = request->get_path_parameter("username", ""); + + + + // Change the value of this variable to the appropriate response before sending the response + int status_code = 200; + + /** + * Process the received information here + */ + + if (status_code == 200) { + std::shared_ptr response = NULL; + session->close(200, "successful operation", { {"Connection", "close"} }); + return; + } + if (status_code == 400) { + session->close(400, "Invalid username supplied", { {"Connection", "close"} }); + return; + } + if (status_code == 404) { + session->close(404, "User not found", { {"Connection", "close"} }); + return; + } + +} +void UserApiDeleteUserResource::PUT_method_handler(const std::shared_ptr session) { + + const auto request = session->get_request(); + // Body params are present, therefore we have to fetch them + int content_length = request->get_header("Content-Length", 0); + session->fetch(content_length, + [ this ]( const std::shared_ptr session, const restbed::Bytes & body ) + { + + const auto request = session->get_request(); + std::string requestBody = restbed::String::format("%.*s\n", ( int ) body.size( ), body.data( )); + + // Getting the path params + const std::string username = request->get_path_parameter("username", ""); + + + + // Change the value of this variable to the appropriate response before sending the response + int status_code = 200; + + /** + * Process the received information here + */ + + if (status_code == 400) { + session->close(400, "Invalid user supplied", { {"Connection", "close"} }); + return; + } + if (status_code == 404) { + session->close(404, "User not found", { {"Connection", "close"} }); + return; + } + + }); +} + + +UserApiLoginUserResource::UserApiLoginUserResource() +{ + this->set_path("/user/login/"); + this->set_method_handler("GET", + std::bind(&UserApiLoginUserResource::GET_method_handler, this, + std::placeholders::_1)); +} + +UserApiLoginUserResource::~UserApiLoginUserResource() +{ +} + +void UserApiLoginUserResource::GET_method_handler(const std::shared_ptr session) { + + const auto request = session->get_request(); + + + // Getting the query params + const std::string username = request->get_query_parameter("username", ""); + const std::string password = request->get_query_parameter("password", ""); + + + // Change the value of this variable to the appropriate response before sending the response + int status_code = 200; + + /** + * Process the received information here + */ + + if (status_code == 200) { + // Description: calls per hour allowed by the user + session->set_header("X-Rate-Limit", ""); // Change second param to your header value + // Description: date in UTC when toekn expires + session->set_header("X-Expires-After", ""); // Change second param to your header value + session->close(200, "successful operation", { {"Connection", "close"} }); + return; + } + if (status_code == 400) { + session->close(400, "Invalid username/password supplied", { {"Connection", "close"} }); + return; + } + +} + + + +UserApiLogoutUserResource::UserApiLogoutUserResource() +{ + this->set_path("/user/logout/"); + this->set_method_handler("GET", + std::bind(&UserApiLogoutUserResource::GET_method_handler, this, + std::placeholders::_1)); +} + +UserApiLogoutUserResource::~UserApiLogoutUserResource() +{ +} + +void UserApiLogoutUserResource::GET_method_handler(const std::shared_ptr session) { + + const auto request = session->get_request(); + + + + + // Change the value of this variable to the appropriate response before sending the response + int status_code = 200; + + /** + * Process the received information here + */ + + if (status_code == 0) { + session->close(0, "successful operation", { {"Connection", "close"} }); + return; + } + +} + + + + +} +} +} +} + diff --git a/samples/server/petstore/restbed/api/UserApi.h b/samples/server/petstore/restbed/api/UserApi.h new file mode 100644 index 000000000000..ee24ffa2eff6 --- /dev/null +++ b/samples/server/petstore/restbed/api/UserApi.h @@ -0,0 +1,142 @@ +/** + * Swagger Petstore + * This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters. + * + * OpenAPI spec version: 1.0.0 + * Contact: apiteam@swagger.io + * + * NOTE: This class is auto generated by the swagger code generator program. + * https://github.com/swagger-api/swagger-codegen.git + * Do not edit the class manually. + */ + +/* + * UserApi.h + * + * + */ + +#ifndef UserApi_H_ +#define UserApi_H_ + + +#include +#include +#include +#include + +#include "User.h" +#include +#include + +namespace io { +namespace swagger { +namespace server { +namespace api { + +using namespace io::swagger::server::model; + +class UserApi: public restbed::Service +{ +public: + UserApi(); + ~UserApi(); + void startService(int const& port); + void stopService(); +}; + + +/// +/// Create user +/// +/// +/// This can only be done by the logged in user. +/// +class UserApiCreateUserResource: public restbed::Resource +{ +public: + UserApiCreateUserResource(); + virtual ~UserApiCreateUserResource(); + void POST_method_handler(const std::shared_ptr session); +}; + +/// +/// Creates list of users with given input array +/// +/// +/// +/// +class UserApiCreateUsersWithArrayInputResource: public restbed::Resource +{ +public: + UserApiCreateUsersWithArrayInputResource(); + virtual ~UserApiCreateUsersWithArrayInputResource(); + void POST_method_handler(const std::shared_ptr session); +}; + +/// +/// Creates list of users with given input array +/// +/// +/// +/// +class UserApiCreateUsersWithListInputResource: public restbed::Resource +{ +public: + UserApiCreateUsersWithListInputResource(); + virtual ~UserApiCreateUsersWithListInputResource(); + void POST_method_handler(const std::shared_ptr session); +}; + +/// +/// Delete user +/// +/// +/// This can only be done by the logged in user. +/// +class UserApiDeleteUserResource: public restbed::Resource +{ +public: + UserApiDeleteUserResource(); + virtual ~UserApiDeleteUserResource(); + void DELETE_method_handler(const std::shared_ptr session); + void GET_method_handler(const std::shared_ptr session); + void PUT_method_handler(const std::shared_ptr session); +}; + +/// +/// Logs user into the system +/// +/// +/// +/// +class UserApiLoginUserResource: public restbed::Resource +{ +public: + UserApiLoginUserResource(); + virtual ~UserApiLoginUserResource(); + void GET_method_handler(const std::shared_ptr session); +}; + +/// +/// Logs out current logged in user session +/// +/// +/// +/// +class UserApiLogoutUserResource: public restbed::Resource +{ +public: + UserApiLogoutUserResource(); + virtual ~UserApiLogoutUserResource(); + void GET_method_handler(const std::shared_ptr session); +}; + + +} +} +} +} + +#endif /* UserApi_H_ */ + diff --git a/samples/server/petstore/restbed/git_push.sh b/samples/server/petstore/restbed/git_push.sh new file mode 100644 index 000000000000..35d20f1851db --- /dev/null +++ b/samples/server/petstore/restbed/git_push.sh @@ -0,0 +1,51 @@ +#!/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 swagger-petstore-cpprest "minor update" + +git_user_id=$1 +git_repo_id=$2 +release_note=$3 + +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 crediential in your environment." + git remote add origin https://github.com/${git_user_id}/${git_repo_id}.git + else + git remote add origin https://${git_user_id}:${GIT_TOKEN}@github.com/${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://github.com/${git_user_id}/${git_repo_id}.git" +git push origin master 2>&1 | grep -v 'To https' diff --git a/samples/server/petstore/restbed/model/ApiResponse.cpp b/samples/server/petstore/restbed/model/ApiResponse.cpp new file mode 100644 index 000000000000..eafab8702bc2 --- /dev/null +++ b/samples/server/petstore/restbed/model/ApiResponse.cpp @@ -0,0 +1,93 @@ +/** + * Swagger Petstore + * This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters. + * + * OpenAPI spec version: 1.0.0 + * Contact: apiteam@swagger.io + * + * NOTE: This class is auto generated by the swagger code generator program. + * https://github.com/swagger-api/swagger-codegen.git + * Do not edit the class manually. + */ + + + +#include "ApiResponse.h" + +#include +#include +#include +#include + +using boost::property_tree::ptree; +using boost::property_tree::read_json; +using boost::property_tree::write_json; + +namespace io { +namespace swagger { +namespace server { +namespace model { + +ApiResponse::ApiResponse() +{ + m_Code = 0; + m_Type = ""; + m_Message = ""; + +} + +ApiResponse::~ApiResponse() +{ +} + +std::string ApiResponse::toJsonString() +{ + std::stringstream ss; + ptree pt; + pt.put("Code", m_Code); + pt.put("Type", m_Type); + pt.put("Message", m_Message); + write_json(ss, pt, false); + return ss.str(); +} + +void ApiResponse::fromJsonString(std::string const& jsonString) +{ + std::stringstream ss(jsonString); + ptree pt; + read_json(ss,pt); + 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; +} + +} +} +} +} + diff --git a/samples/server/petstore/restbed/model/ApiResponse.h b/samples/server/petstore/restbed/model/ApiResponse.h new file mode 100644 index 000000000000..acfe2f0b36f2 --- /dev/null +++ b/samples/server/petstore/restbed/model/ApiResponse.h @@ -0,0 +1,74 @@ +/** + * Swagger Petstore + * This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters. + * + * OpenAPI spec version: 1.0.0 + * Contact: apiteam@swagger.io + * + * NOTE: This class is auto generated by the swagger code generator program. + * https://github.com/swagger-api/swagger-codegen.git + * Do not edit the class manually. + */ + +/* + * ApiResponse.h + * + * Describes the result of uploading an image resource + */ + +#ifndef ApiResponse_H_ +#define ApiResponse_H_ + + + +#include +#include + +namespace io { +namespace swagger { +namespace server { +namespace model { + +/// +/// Describes the result of uploading an image resource +/// +class ApiResponse +{ +public: + ApiResponse(); + virtual ~ApiResponse(); + + std::string toJsonString(); + void fromJsonString(std::string const& jsonString); + + ///////////////////////////////////////////// + /// 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; + std::string m_Type; + std::string m_Message; +}; + +} +} +} +} + +#endif /* ApiResponse_H_ */ diff --git a/samples/server/petstore/restbed/model/Category.cpp b/samples/server/petstore/restbed/model/Category.cpp new file mode 100644 index 000000000000..e5a38f26420e --- /dev/null +++ b/samples/server/petstore/restbed/model/Category.cpp @@ -0,0 +1,82 @@ +/** + * Swagger Petstore + * This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters. + * + * OpenAPI spec version: 1.0.0 + * Contact: apiteam@swagger.io + * + * NOTE: This class is auto generated by the swagger code generator program. + * https://github.com/swagger-api/swagger-codegen.git + * Do not edit the class manually. + */ + + + +#include "Category.h" + +#include +#include +#include +#include + +using boost::property_tree::ptree; +using boost::property_tree::read_json; +using boost::property_tree::write_json; + +namespace io { +namespace swagger { +namespace server { +namespace model { + +Category::Category() +{ + m_Id = 0; + m_Name = ""; + +} + +Category::~Category() +{ +} + +std::string Category::toJsonString() +{ + std::stringstream ss; + ptree pt; + pt.put("Id", m_Id); + pt.put("Name", m_Name); + write_json(ss, pt, false); + return ss.str(); +} + +void Category::fromJsonString(std::string const& jsonString) +{ + std::stringstream ss(jsonString); + ptree pt; + read_json(ss,pt); + m_Id = pt.get("Id", 0); + m_Name = pt.get("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; +} + +} +} +} +} + diff --git a/samples/server/petstore/restbed/model/Category.h b/samples/server/petstore/restbed/model/Category.h new file mode 100644 index 000000000000..862294647c8f --- /dev/null +++ b/samples/server/petstore/restbed/model/Category.h @@ -0,0 +1,68 @@ +/** + * Swagger Petstore + * This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters. + * + * OpenAPI spec version: 1.0.0 + * Contact: apiteam@swagger.io + * + * NOTE: This class is auto generated by the swagger code generator program. + * https://github.com/swagger-api/swagger-codegen.git + * Do not edit the class manually. + */ + +/* + * Category.h + * + * A category for a pet + */ + +#ifndef Category_H_ +#define Category_H_ + + + +#include +#include + +namespace io { +namespace swagger { +namespace server { +namespace model { + +/// +/// A category for a pet +/// +class Category +{ +public: + Category(); + virtual ~Category(); + + std::string toJsonString(); + void fromJsonString(std::string const& jsonString); + + ///////////////////////////////////////////// + /// 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; + std::string m_Name; +}; + +} +} +} +} + +#endif /* Category_H_ */ diff --git a/samples/server/petstore/restbed/model/Order.cpp b/samples/server/petstore/restbed/model/Order.cpp new file mode 100644 index 000000000000..b6e97cecd1c4 --- /dev/null +++ b/samples/server/petstore/restbed/model/Order.cpp @@ -0,0 +1,126 @@ +/** + * Swagger Petstore + * This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters. + * + * OpenAPI spec version: 1.0.0 + * Contact: apiteam@swagger.io + * + * NOTE: This class is auto generated by the swagger code generator program. + * https://github.com/swagger-api/swagger-codegen.git + * Do not edit the class manually. + */ + + + +#include "Order.h" + +#include +#include +#include +#include + +using boost::property_tree::ptree; +using boost::property_tree::read_json; +using boost::property_tree::write_json; + +namespace io { +namespace swagger { +namespace server { +namespace model { + +Order::Order() +{ + m_Id = 0; + m_PetId = 0; + m_Quantity = 0; + m_ShipDate = ""; + m_Status = ""; + m_Complete = false; + +} + +Order::~Order() +{ +} + +std::string Order::toJsonString() +{ + std::stringstream ss; + ptree pt; + 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); + write_json(ss, pt, false); + return ss.str(); +} + +void Order::fromJsonString(std::string const& jsonString) +{ + std::stringstream ss(jsonString); + ptree pt; + read_json(ss,pt); + m_Id = pt.get("Id", 0); + m_PetId = pt.get("PetId", 0); + m_Quantity = pt.get("Quantity", 0); + m_ShipDate = pt.get("ShipDate", ""); + m_Status = 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) +{ + m_Status = value; +} +bool Order::getComplete() const +{ + return m_Complete; +} +void Order::setComplete(bool value) +{ + m_Complete = value; +} + +} +} +} +} + diff --git a/samples/server/petstore/restbed/model/Order.h b/samples/server/petstore/restbed/model/Order.h new file mode 100644 index 000000000000..e84f11e37c23 --- /dev/null +++ b/samples/server/petstore/restbed/model/Order.h @@ -0,0 +1,92 @@ +/** + * Swagger Petstore + * This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters. + * + * OpenAPI spec version: 1.0.0 + * Contact: apiteam@swagger.io + * + * NOTE: This class is auto generated by the swagger code generator program. + * https://github.com/swagger-api/swagger-codegen.git + * Do not edit the class manually. + */ + +/* + * Order.h + * + * An order for a pets from the pet store + */ + +#ifndef Order_H_ +#define Order_H_ + + + +#include +#include + +namespace io { +namespace swagger { +namespace server { +namespace model { + +/// +/// An order for a pets from the pet store +/// +class Order +{ +public: + Order(); + virtual ~Order(); + + std::string toJsonString(); + void fromJsonString(std::string const& jsonString); + + ///////////////////////////////////////////// + /// 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 getComplete() const; + void setComplete(bool value); + +protected: + int64_t m_Id; + int64_t m_PetId; + int32_t m_Quantity; + std::string m_ShipDate; + std::string m_Status; + bool m_Complete; +}; + +} +} +} +} + +#endif /* Order_H_ */ diff --git a/samples/server/petstore/restbed/model/Pet.cpp b/samples/server/petstore/restbed/model/Pet.cpp new file mode 100644 index 000000000000..f047b8a883c8 --- /dev/null +++ b/samples/server/petstore/restbed/model/Pet.cpp @@ -0,0 +1,109 @@ +/** + * Swagger Petstore + * This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters. + * + * OpenAPI spec version: 1.0.0 + * Contact: apiteam@swagger.io + * + * NOTE: This class is auto generated by the swagger code generator program. + * https://github.com/swagger-api/swagger-codegen.git + * Do not edit the class manually. + */ + + + +#include "Pet.h" + +#include +#include +#include +#include + +using boost::property_tree::ptree; +using boost::property_tree::read_json; +using boost::property_tree::write_json; + +namespace io { +namespace swagger { +namespace server { +namespace model { + +Pet::Pet() +{ + m_Id = 0; + m_Name = ""; + m_Status = ""; + +} + +Pet::~Pet() +{ +} + +std::string Pet::toJsonString() +{ + std::stringstream ss; + ptree pt; + pt.put("Id", m_Id); + pt.put("Name", m_Name); + pt.put("Status", m_Status); + write_json(ss, pt, false); + return ss.str(); +} + +void Pet::fromJsonString(std::string const& jsonString) +{ + std::stringstream ss(jsonString); + ptree pt; + read_json(ss,pt); + m_Id = pt.get("Id", 0); + m_Name = pt.get("Name", ""); + m_Status = pt.get("Status", ""); +} + +int64_t Pet::getId() const +{ + return m_Id; +} +void Pet::setId(int64_t value) +{ + m_Id = value; +} +std::shared_ptr Pet::getCategory() const +{ + return m_Category; +} +void Pet::setCategory(std::shared_ptr value) +{ + m_Category = value; +} +std::string Pet::getName() const +{ + return m_Name; +} +void Pet::setName(std::string value) +{ + m_Name = value; +} +std::vector& Pet::getPhotoUrls() +{ + return m_PhotoUrls; +} +std::vector>& Pet::getTags() +{ + return m_Tags; +} +std::string Pet::getStatus() const +{ + return m_Status; +} +void Pet::setStatus(std::string value) +{ + m_Status = value; +} + +} +} +} +} + diff --git a/samples/server/petstore/restbed/model/Pet.h b/samples/server/petstore/restbed/model/Pet.h new file mode 100644 index 000000000000..73234cfe1451 --- /dev/null +++ b/samples/server/petstore/restbed/model/Pet.h @@ -0,0 +1,93 @@ +/** + * Swagger Petstore + * This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters. + * + * OpenAPI spec version: 1.0.0 + * Contact: apiteam@swagger.io + * + * NOTE: This class is auto generated by the swagger code generator program. + * https://github.com/swagger-api/swagger-codegen.git + * Do not edit the class manually. + */ + +/* + * Pet.h + * + * A pet for sale in the pet store + */ + +#ifndef Pet_H_ +#define Pet_H_ + + + +#include "Tag.h" +#include +#include "Category.h" +#include +#include + +namespace io { +namespace swagger { +namespace server { +namespace model { + +/// +/// A pet for sale in the pet store +/// +class Pet +{ +public: + Pet(); + virtual ~Pet(); + + std::string toJsonString(); + void fromJsonString(std::string const& jsonString); + + ///////////////////////////////////////////// + /// Pet members + + /// + /// + /// + int64_t getId() const; + void setId(int64_t value); + /// + /// + /// + std::shared_ptr getCategory() const; + void setCategory(std::shared_ptr value); + /// + /// + /// + std::string getName() const; + void setName(std::string value); + /// + /// + /// + std::vector& getPhotoUrls(); + /// + /// + /// + std::vector>& getTags(); + /// + /// pet status in the store + /// + std::string getStatus() const; + void setStatus(std::string value); + +protected: + int64_t m_Id; + std::shared_ptr m_Category; + std::string m_Name; + std::vector m_PhotoUrls; + std::vector> m_Tags; + std::string m_Status; +}; + +} +} +} +} + +#endif /* Pet_H_ */ diff --git a/samples/server/petstore/restbed/model/Tag.cpp b/samples/server/petstore/restbed/model/Tag.cpp new file mode 100644 index 000000000000..a23bb9f767fe --- /dev/null +++ b/samples/server/petstore/restbed/model/Tag.cpp @@ -0,0 +1,82 @@ +/** + * Swagger Petstore + * This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters. + * + * OpenAPI spec version: 1.0.0 + * Contact: apiteam@swagger.io + * + * NOTE: This class is auto generated by the swagger code generator program. + * https://github.com/swagger-api/swagger-codegen.git + * Do not edit the class manually. + */ + + + +#include "Tag.h" + +#include +#include +#include +#include + +using boost::property_tree::ptree; +using boost::property_tree::read_json; +using boost::property_tree::write_json; + +namespace io { +namespace swagger { +namespace server { +namespace model { + +Tag::Tag() +{ + m_Id = 0; + m_Name = ""; + +} + +Tag::~Tag() +{ +} + +std::string Tag::toJsonString() +{ + std::stringstream ss; + ptree pt; + pt.put("Id", m_Id); + pt.put("Name", m_Name); + write_json(ss, pt, false); + return ss.str(); +} + +void Tag::fromJsonString(std::string const& jsonString) +{ + std::stringstream ss(jsonString); + ptree pt; + read_json(ss,pt); + m_Id = pt.get("Id", 0); + 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; +} + +} +} +} +} + diff --git a/samples/server/petstore/restbed/model/Tag.h b/samples/server/petstore/restbed/model/Tag.h new file mode 100644 index 000000000000..94967dda7555 --- /dev/null +++ b/samples/server/petstore/restbed/model/Tag.h @@ -0,0 +1,68 @@ +/** + * Swagger Petstore + * This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters. + * + * OpenAPI spec version: 1.0.0 + * Contact: apiteam@swagger.io + * + * NOTE: This class is auto generated by the swagger code generator program. + * https://github.com/swagger-api/swagger-codegen.git + * Do not edit the class manually. + */ + +/* + * Tag.h + * + * A tag for a pet + */ + +#ifndef Tag_H_ +#define Tag_H_ + + + +#include +#include + +namespace io { +namespace swagger { +namespace server { +namespace model { + +/// +/// A tag for a pet +/// +class Tag +{ +public: + Tag(); + virtual ~Tag(); + + std::string toJsonString(); + void fromJsonString(std::string const& jsonString); + + ///////////////////////////////////////////// + /// 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; + std::string m_Name; +}; + +} +} +} +} + +#endif /* Tag_H_ */ diff --git a/samples/server/petstore/restbed/model/User.cpp b/samples/server/petstore/restbed/model/User.cpp new file mode 100644 index 000000000000..be22d9bc9eff --- /dev/null +++ b/samples/server/petstore/restbed/model/User.cpp @@ -0,0 +1,148 @@ +/** + * Swagger Petstore + * This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters. + * + * OpenAPI spec version: 1.0.0 + * Contact: apiteam@swagger.io + * + * NOTE: This class is auto generated by the swagger code generator program. + * https://github.com/swagger-api/swagger-codegen.git + * Do not edit the class manually. + */ + + + +#include "User.h" + +#include +#include +#include +#include + +using boost::property_tree::ptree; +using boost::property_tree::read_json; +using boost::property_tree::write_json; + +namespace io { +namespace swagger { +namespace server { +namespace model { + +User::User() +{ + m_Id = 0; + m_Username = ""; + m_FirstName = ""; + m_LastName = ""; + m_Email = ""; + m_Password = ""; + m_Phone = ""; + m_UserStatus = 0; + +} + +User::~User() +{ +} + +std::string User::toJsonString() +{ + std::stringstream ss; + ptree pt; + 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); + write_json(ss, pt, false); + return ss.str(); +} + +void User::fromJsonString(std::string const& jsonString) +{ + std::stringstream ss(jsonString); + ptree pt; + read_json(ss,pt); + m_Id = pt.get("Id", 0); + 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; +} + +} +} +} +} + diff --git a/samples/server/petstore/restbed/model/User.h b/samples/server/petstore/restbed/model/User.h new file mode 100644 index 000000000000..0ec055397325 --- /dev/null +++ b/samples/server/petstore/restbed/model/User.h @@ -0,0 +1,104 @@ +/** + * Swagger Petstore + * This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters. + * + * OpenAPI spec version: 1.0.0 + * Contact: apiteam@swagger.io + * + * NOTE: This class is auto generated by the swagger code generator program. + * https://github.com/swagger-api/swagger-codegen.git + * Do not edit the class manually. + */ + +/* + * User.h + * + * A User who is purchasing from the pet store + */ + +#ifndef User_H_ +#define User_H_ + + + +#include +#include + +namespace io { +namespace swagger { +namespace server { +namespace model { + +/// +/// A User who is purchasing from the pet store +/// +class User +{ +public: + User(); + virtual ~User(); + + std::string toJsonString(); + void fromJsonString(std::string const& jsonString); + + ///////////////////////////////////////////// + /// 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; + 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; +}; + +} +} +} +} + +#endif /* User_H_ */