diff --git a/README.md b/README.md index 2d729e84802..8c37f3f39d5 100644 --- a/README.md +++ b/README.md @@ -936,6 +936,7 @@ Swaagger Codegen core team members are contributors who have been making signfic Here is a list of template creators: * API Clients: * Akka-Scala: @cchafer + * C++ REST: @Danielku15 * C# (.NET 2.0): @who * Clojure: @xhh * Dart: @yissachar diff --git a/bin/cpprest-petstore.sh b/bin/cpprest-petstore.sh new file mode 100755 index 00000000000..93f7ad609cc --- /dev/null +++ b/bin/cpprest-petstore.sh @@ -0,0 +1,31 @@ +#!/bin/sh + +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 -t modules/swagger-codegen/src/main/resources/cpprest -i modules/swagger-codegen/src/test/resources/2_0/petstore.yaml -l cpprest -o samples/client/petstore/cpprest" + +java $JAVA_OPTS -jar $executable $ags diff --git a/bin/go-petstore-server.sh b/bin/go-petstore-server.sh new file mode 100755 index 00000000000..a668a1cfbdd --- /dev/null +++ b/bin/go-petstore-server.sh @@ -0,0 +1,31 @@ +#!/bin/sh + +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 -i modules/swagger-codegen/src/test/resources/2_0/petstore.yaml -l go-server -o samples/server/petstore/go-api-server -DpackageName=petstoreserver " + +java $JAVA_OPTS -Dservice -jar $executable $ags diff --git a/bin/windows/cpprest-petstore.bat b/bin/windows/cpprest-petstore.bat new file mode 100755 index 00000000000..43312669840 --- /dev/null +++ b/bin/windows/cpprest-petstore.bat @@ -0,0 +1,10 @@ +set executable=.\modules\swagger-codegen-cli\target\swagger-codegen-cli.jar + +If Not Exist %executable% ( + mvn clean package +) + +set JAVA_OPTS=%JAVA_OPTS% -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties +set ags=generate -t modules\swagger-codegen\src\main\resources\cpprest -i modules\swagger-codegen\src\test\resources\2_0\petstore.json -l cpprest -o samples\client\petstore\cpprest + +java %JAVA_OPTS% -jar %executable% %ags% diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/CppRestClientCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/CppRestClientCodegen.java new file mode 100644 index 00000000000..f8299fc60cd --- /dev/null +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/CppRestClientCodegen.java @@ -0,0 +1,380 @@ +package io.swagger.codegen.languages; + +import io.swagger.codegen.*; +import io.swagger.codegen.examples.ExampleGenerator; +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.*; + +import java.util.*; +import java.io.File; + +public class CppRestClientCodegen 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.CLIENT; + } + + /** + * 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 "cpprest"; + } + + /** + * 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 client with C++ REST SDK (https://github.com/Microsoft/cpprestsdk)."; + } + + public CppRestClientCodegen() { + super(); + + apiPackage = "io.swagger.client.api"; + modelPackage = "io.swagger.client.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"); + + templateDir = "cpprest"; + + 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("modelbase-header.mustache", "", "ModelBase.h")); + supportingFiles.add(new SupportingFile("modelbase-source.mustache", "", "ModelBase.cpp")); + supportingFiles.add(new SupportingFile("apiclient-header.mustache", "", "ApiClient.h")); + supportingFiles.add(new SupportingFile("apiclient-source.mustache", "", "ApiClient.cpp")); + supportingFiles.add(new SupportingFile("apiconfiguration-header.mustache", "", "ApiConfiguration.h")); + supportingFiles.add(new SupportingFile("apiconfiguration-source.mustache", "", "ApiConfiguration.cpp")); + supportingFiles.add(new SupportingFile("apiexception-header.mustache", "", "ApiException.h")); + supportingFiles.add(new SupportingFile("apiexception-source.mustache", "", "ApiException.cpp")); + supportingFiles.add(new SupportingFile("ihttpbody-header.mustache", "", "IHttpBody.h")); + supportingFiles.add(new SupportingFile("jsonbody-header.mustache", "", "JsonBody.h")); + supportingFiles.add(new SupportingFile("jsonbody-source.mustache", "", "JsonBody.cpp")); + supportingFiles.add(new SupportingFile("httpcontent-header.mustache", "", "HttpContent.h")); + supportingFiles.add(new SupportingFile("httpcontent-source.mustache", "", "HttpContent.cpp")); + supportingFiles.add(new SupportingFile("multipart-header.mustache", "", "MultipartFormData.h")); + supportingFiles.add(new SupportingFile("multipart-source.mustache", "", "MultipartFormData.cpp")); + supportingFiles.add(new SupportingFile("gitignore.mustache", "", ".gitignore")); + supportingFiles.add(new SupportingFile("git_push.sh.mustache", "", "git_push.sh")); + + languageSpecificPrimitives = new HashSet( + Arrays.asList("int", "char", "bool", "long", "float", "double", "int32_t", "int64_t")); + + typeMapping = new HashMap(); + typeMapping.put("date", "utility::datetime"); + typeMapping.put("DateTime", "utility::datetime"); + typeMapping.put("string", "utility::string_t"); + 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", "HttpContent"); + typeMapping.put("object", "Object"); + typeMapping.put("binary", "std::string"); + + super.importMapping = new HashMap(); + importMapping.put("std::vector", "#include "); + importMapping.put("std::map", "#include "); + importMapping.put("std::string", "#include "); + importMapping.put("HttpContent", "#include \"HttpContent.h\""); + importMapping.put("Object", "#include \"Object.h\""); + importMapping.put("utility::string_t", "#include "); + importMapping.put("utility::datetime", "#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 CodegenOperation fromOperation(String path, String httpMethod, Operation operation, + Map definitions, Swagger swagger) { + CodegenOperation op = super.fromOperation(path, httpMethod, operation, definitions, swagger); + + if (operation.getResponses() != null && !operation.getResponses().isEmpty()) { + Response methodResponse = findMethodResponse(operation.getResponses()); + + if (methodResponse != null) { + if (methodResponse.getSchema() != null) { + CodegenProperty cm = fromProperty("response", methodResponse.getSchema()); + op.vendorExtensions.put("x-codegen-response", cm); + } + } + } + + return op; + } + + @Override + public void postProcessModelProperty(CodegenModel model, CodegenProperty property) { + if (isFileProperty(property)) { + property.vendorExtensions.put("x-codegen-file", true); + } + } + + protected boolean isFileProperty(CodegenProperty property) { + return property.baseType.equals("HttpContent"); + } + + @Override + public String toModelFilename(String name) { + return initialCaps(name); + } + + @Override + public String toApiFilename(String name) { + return initialCaps(name) + "Api"; + } + + /** + * 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 + || languageSpecificPrimitives.contains(swaggerType)) { + return toModelName(swaggerType); + } + + return "std::shared_ptr<" + swaggerType + ">"; + } + + @Override + public String toDefaultValue(Property p) { + if (p instanceof StringProperty) { + return "U(\"\")"; + } else if (p instanceof BooleanProperty) { + return "false"; + } else if (p instanceof DateProperty) { + return "utility::datetime()"; + } else if (p instanceof DateTimeProperty) { + return "utility::datetime()"; + } else if (p instanceof DoubleProperty) { + return "0.0"; + } else if (p instanceof FloatProperty) { + return "0.0f"; + } else if (p instanceof IntegerProperty) { + 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"; + } +} diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/GoServerCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/GoServerCodegen.java new file mode 100644 index 00000000000..43c48cc64f7 --- /dev/null +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/GoServerCodegen.java @@ -0,0 +1,266 @@ +package io.swagger.codegen.languages; + +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonSerializer; +import com.fasterxml.jackson.databind.SerializerProvider; +import com.fasterxml.jackson.databind.module.SimpleModule; +import com.google.common.collect.ArrayListMultimap; +import com.google.common.collect.Lists; +import com.google.common.collect.Multimap; +import io.swagger.codegen.*; +import io.swagger.models.*; +import io.swagger.util.Yaml; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.File; +import java.io.IOException; +import java.math.BigDecimal; +import java.util.*; +import java.util.Map.Entry; +import org.apache.commons.lang3.StringUtils; + +public class GoServerCodegen extends DefaultCodegen implements CodegenConfig { + + private static final Logger LOGGER = LoggerFactory.getLogger(GoServerCodegen.class); + + protected String apiVersion = "1.0.0"; + protected int serverPort = 8080; + protected String projectName = "swagger-server"; + protected String apiPath = "go"; + + public GoServerCodegen() { + super(); + + // set the output folder here + outputFolder = "generated-code/go"; + + /** + * Models. You can write model files using the modelTemplateFiles map. + * if you want to create one template for file, you can do so here. + * for multiple files for model, just put another entry in the `modelTemplateFiles` with + * a different extension + */ + modelTemplateFiles.clear(); + + /** + * Api classes. You can write classes for each Api file with the apiTemplateFiles map. + * as with models, add multiple entries with different extensions for multiple files per + * class + */ + apiTemplateFiles.put( + "controller.mustache", // the template to use + ".go"); // the extension for each file to write + + /** + * Template Location. This is the location which templates will be read from. The generator + * will use the resource stream to attempt to read the templates. + */ + embeddedTemplateDir = templateDir = "go-server"; + + /** + * Reserved words. Override this with reserved words specific to your language + */ + setReservedWordsLowerCase( + Arrays.asList( + "break", "default", "func", "interface", "select", + "case", "defer", "go", "map", "struct", + "chan", "else", "goto", "package", "switch", + "const", "fallthrough", "if", "range", "type", + "continue", "for", "import", "return", "var", "error", "ApiResponse") + // Added "error" as it's used so frequently that it may as well be a keyword + ); + + defaultIncludes = new HashSet( + Arrays.asList( + "map", + "array") + ); + + languageSpecificPrimitives = new HashSet( + Arrays.asList( + "string", + "bool", + "uint", + "uint32", + "uint64", + "int", + "int32", + "int64", + "float32", + "float64", + "complex64", + "complex128", + "rune", + "byte") + ); + + instantiationTypes.clear(); + /*instantiationTypes.put("array", "GoArray"); + instantiationTypes.put("map", "GoMap");*/ + + typeMapping.clear(); + typeMapping.put("integer", "int32"); + typeMapping.put("long", "int64"); + typeMapping.put("number", "float32"); + typeMapping.put("float", "float32"); + typeMapping.put("double", "float64"); + typeMapping.put("boolean", "bool"); + typeMapping.put("string", "string"); + typeMapping.put("date", "time.Time"); + typeMapping.put("DateTime", "time.Time"); + typeMapping.put("password", "string"); + typeMapping.put("File", "*os.File"); + typeMapping.put("file", "*os.File"); + // map binary to string as a workaround + // the correct solution is to use []byte + typeMapping.put("binary", "string"); + typeMapping.put("ByteArray", "string"); + + importMapping = new HashMap(); + importMapping.put("time.Time", "time"); + importMapping.put("*os.File", "os"); + importMapping.put("os", "io/ioutil"); + + cliOptions.clear(); + cliOptions.add(new CliOption(CodegenConstants.PACKAGE_NAME, "Go package name (convention: lowercase).") + .defaultValue("swagger")); + /** + * Additional Properties. These values can be passed to the templates and + * are available in models, apis, and supporting files + */ + additionalProperties.put("apiVersion", apiVersion); + additionalProperties.put("serverPort", serverPort); + additionalProperties.put("apiPath", apiPath); + /** + * Supporting Files. You can write single files for the generator with the + * entire object tree available. If the input file has a suffix of `.mustache + * it will be processed by the template engine. Otherwise, it will be copied + */ + supportingFiles.add(new SupportingFile("swagger.mustache", + "api", + "swagger.yaml") + ); + supportingFiles.add(new SupportingFile("main.mustache", "", "main.go")); + supportingFiles.add(new SupportingFile("routers.mustache", apiPath, "routers.go")); + supportingFiles.add(new SupportingFile("logger.mustache", apiPath, "logger.go")); + supportingFiles.add(new SupportingFile("app.mustache", apiPath, "app.yaml")); + writeOptional(outputFolder, new SupportingFile("README.mustache", apiPath, "README.md")); + } + + @Override + public String apiPackage() { + return apiPath; + } + + /** + * Configures the type of generator. + * + * @return the CodegenType for this generator + * @see io.swagger.codegen.CodegenType + */ + @Override + public CodegenType getTag() { + return CodegenType.SERVER; + } + + /** + * Configures a friendly name for the generator. This will be used by the generator + * to select the library with the -l flag. + * + * @return the friendly name for the generator + */ + @Override + public String getName() { + return "go-server"; + } + + /** + * Returns human-friendly help for the generator. Provide the consumer with help + * tips, parameters here + * + * @return A string value for the help message + */ + @Override + public String getHelp() { + return "Generates a Go server library using the swagger-tools project. By default, " + + "it will also generate service classes--which you can disable with the `-Dnoservice` environment variable."; + } + + @Override + public String toApiName(String name) { + if (name.length() == 0) { + return "DefaultController"; + } + return initialCaps(name); + } + + /** + * 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 api files. You can use the apiPackage() as defined when the class is + * instantiated + */ + @Override + public String apiFileFolder() { + return outputFolder + File.separator + apiPackage().replace('.', File.separatorChar); + } + + @Override + public String toModelName(String name) { + // camelize the model name + // phone_number => PhoneNumber + return camelize(toModelFilename(name)); + } + + @Override + public String toOperationId(String operationId) { + // method name cannot use reserved keyword, e.g. return + if (isReservedWord(operationId)) { + LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to " + camelize(sanitizeName("call_" + operationId))); + operationId = "call_" + operationId; + } + + return camelize(operationId); + } + + @Override + public String toModelFilename(String name) { + if (!StringUtils.isEmpty(modelNamePrefix)) { + name = modelNamePrefix + "_" + name; + } + + if (!StringUtils.isEmpty(modelNameSuffix)) { + name = name + "_" + modelNameSuffix; + } + + name = sanitizeName(name); + + // model name cannot use reserved keyword, e.g. return + if (isReservedWord(name)) { + LOGGER.warn(name + " (reserved word) cannot be used as model name. Renamed to " + camelize("model_" + name)); + name = "model_" + name; // e.g. return => ModelReturn (after camelize) + } + + return underscore(name); + } + + @Override + public String toApiFilename(String name) { + // replace - with _ e.g. created-at => created_at + name = name.replaceAll("-", "_"); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'. + + // e.g. PetApi.go => pet_api.go + return underscore(name); + } +} diff --git a/modules/swagger-codegen/src/main/resources/Javascript/ApiClient.mustache b/modules/swagger-codegen/src/main/resources/Javascript/ApiClient.mustache index 25a0e5155aa..3b301e0937c 100644 --- a/modules/swagger-codegen/src/main/resources/Javascript/ApiClient.mustache +++ b/modules/swagger-codegen/src/main/resources/Javascript/ApiClient.mustache @@ -1,3 +1,4 @@ +{{>licenseInfo}} (function(root, factory) { if (typeof define === 'function' && define.amd) { // AMD. Register as an anonymous module. diff --git a/modules/swagger-codegen/src/main/resources/Javascript/api.mustache b/modules/swagger-codegen/src/main/resources/Javascript/api.mustache index 14abda4751c..375acd90ac7 100644 --- a/modules/swagger-codegen/src/main/resources/Javascript/api.mustache +++ b/modules/swagger-codegen/src/main/resources/Javascript/api.mustache @@ -1,3 +1,4 @@ +{{>licenseInfo}} {{=< >=}}(function(root, factory) { if (typeof define === 'function' && define.amd) { // AMD. Register as an anonymous module. diff --git a/modules/swagger-codegen/src/main/resources/Javascript/api_test.mustache b/modules/swagger-codegen/src/main/resources/Javascript/api_test.mustache index a30a58f97df..181c114ca96 100644 --- a/modules/swagger-codegen/src/main/resources/Javascript/api_test.mustache +++ b/modules/swagger-codegen/src/main/resources/Javascript/api_test.mustache @@ -1,3 +1,4 @@ +{{>licenseInfo}} (function(root, factory) { if (typeof define === 'function' && define.amd) { // AMD. diff --git a/modules/swagger-codegen/src/main/resources/Javascript/index.mustache b/modules/swagger-codegen/src/main/resources/Javascript/index.mustache index 1561763af0e..d6ca3cff704 100644 --- a/modules/swagger-codegen/src/main/resources/Javascript/index.mustache +++ b/modules/swagger-codegen/src/main/resources/Javascript/index.mustache @@ -1,3 +1,4 @@ +{{>licenseInfo}} (function(factory) { if (typeof define === 'function' && define.amd) { // AMD. Register as an anonymous module. diff --git a/modules/swagger-codegen/src/main/resources/Javascript/licenseInfo.mustache b/modules/swagger-codegen/src/main/resources/Javascript/licenseInfo.mustache new file mode 100644 index 00000000000..861d97234cf --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/Javascript/licenseInfo.mustache @@ -0,0 +1,23 @@ +/** + * {{{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. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ diff --git a/modules/swagger-codegen/src/main/resources/Javascript/model.mustache b/modules/swagger-codegen/src/main/resources/Javascript/model.mustache index db480f05b1d..95f2b2df81d 100644 --- a/modules/swagger-codegen/src/main/resources/Javascript/model.mustache +++ b/modules/swagger-codegen/src/main/resources/Javascript/model.mustache @@ -1,3 +1,4 @@ +{{>licenseInfo}} (function(root, factory) { if (typeof define === 'function' && define.amd) { // AMD. Register as an anonymous module. diff --git a/modules/swagger-codegen/src/main/resources/Javascript/model_test.mustache b/modules/swagger-codegen/src/main/resources/Javascript/model_test.mustache index 251516bd2ec..2b43b338812 100644 --- a/modules/swagger-codegen/src/main/resources/Javascript/model_test.mustache +++ b/modules/swagger-codegen/src/main/resources/Javascript/model_test.mustache @@ -1,3 +1,4 @@ +{{>licenseInfo}} (function(root, factory) { if (typeof define === 'function' && define.amd) { // AMD. 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 f0d0fde5e57..c75af63df84 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 @@ -2,6 +2,7 @@ io.swagger.codegen.languages.AndroidClientCodegen io.swagger.codegen.languages.AspNet5ServerCodegen io.swagger.codegen.languages.AsyncScalaClientCodegen io.swagger.codegen.languages.CSharpClientCodegen +io.swagger.codegen.languages.CppRestClientCodegen io.swagger.codegen.languages.DartClientCodegen io.swagger.codegen.languages.FlashClientCodegen io.swagger.codegen.languages.FlaskConnexionCodegen @@ -46,3 +47,4 @@ io.swagger.codegen.languages.CsharpDotNet2ClientCodegen io.swagger.codegen.languages.ClojureClientCodegen io.swagger.codegen.languages.HaskellServantCodegen io.swagger.codegen.languages.LumenServerCodegen +io.swagger.codegen.languages.GoServerCodegen \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/cpprest/api-header.mustache b/modules/swagger-codegen/src/main/resources/cpprest/api-header.mustache new file mode 100644 index 00000000000..a93709b1fd5 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/cpprest/api-header.mustache @@ -0,0 +1,48 @@ +{{#operations}}/* + * {{classname}}.h + * + * {{description}} + */ + +#ifndef {{classname}}_H_ +#define {{classname}}_H_ + +{{{defaultInclude}}} +#include "ApiClient.h" + +{{#imports}}{{{import}}} +{{/imports}} + +{{#apiNamespaceDeclarations}} +namespace {{this}} { +{{/apiNamespaceDeclarations}} + +using namespace {{modelNamespace}}; + +class {{declspec}} {{classname}} +{ +public: + {{classname}}( std::shared_ptr apiClient ); + virtual ~{{classname}}(); + {{#operation}} + /// + /// {{summary}} + /// + /// + /// {{notes}} + /// + {{#allParams}}/// {{description}}{{^required}} (optional{{#defaultValue}}, default to {{.}}{{/defaultValue}}){{/required}}{{/allParams}} + pplx::task<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}}> {{operationId}}({{#allParams}}{{{dataType}}} {{paramName}}{{^required}}{{/required}}{{#hasMore}}, {{/hasMore}}{{/allParams}}); + {{/operation}} + +protected: + std::shared_ptr m_ApiClient; +}; + +{{#apiNamespaceDeclarations}} +} +{{/apiNamespaceDeclarations}} + +#endif /* {{classname}}_H_ */ + +{{/operations}} diff --git a/modules/swagger-codegen/src/main/resources/cpprest/api-source.mustache b/modules/swagger-codegen/src/main/resources/cpprest/api-source.mustache new file mode 100644 index 00000000000..6ecbdb1a0f5 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/cpprest/api-source.mustache @@ -0,0 +1,269 @@ +{{#operations}} + +#include "{{classname}}.h" +#include "IHttpBody.h" +#include "JsonBody.h" +#include "MultipartFormData.h" + +#include + +#include + +{{#apiNamespaceDeclarations}} +namespace {{this}} { +{{/apiNamespaceDeclarations}} + +using namespace {{modelNamespace}}; + +{{classname}}::{{classname}}( std::shared_ptr apiClient ) + : m_ApiClient(apiClient) +{ +} + +{{classname}}::~{{classname}}() +{ +} + +{{#operation}} +pplx::task<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}}> {{classname}}::{{operationId}}({{#allParams}}{{{dataType}}} {{paramName}}{{^required}}{{/required}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) +{ + {{#allParams}}{{#required}}{{^isPrimitiveType}}{{^isContainer}} + // verify the required parameter '{{paramName}}' is set + if ({{paramName}} == nullptr) + { + throw ApiException(400, U("Missing required parameter '{{paramName}}' when calling {{classname}}->{{operationId}}")); + } + {{/isContainer}}{{/isPrimitiveType}}{{/required}}{{/allParams}} + + std::shared_ptr apiConfiguration( m_ApiClient->getConfiguration() ); + utility::string_t path = U("{{path}}"); + {{#pathParams}}boost::replace_all(path, U("{") U("{{baseName}}") U("}"), ApiClient::parameterToString({{{paramName}}})); + {{/pathParams}} + + std::map queryParams; + std::map headerParams( apiConfiguration->getDefaultHeaders() ); + std::map formParams; + std::map> fileParams; + + std::unordered_set responseHttpContentTypes; + {{#produces}}responseHttpContentTypes.insert( U("{{mediaType}}") ); + {{/produces}} + + utility::string_t responseHttpContentType; + + // use JSON if possible + if ( responseHttpContentTypes.size() == 0 || responseHttpContentTypes.find(U("application/json")) != responseHttpContentTypes.end() ) + { + responseHttpContentType = U("application/json"); + } + // multipart formdata + else if( responseHttpContentTypes.find(U("multipart/form-data")) != responseHttpContentTypes.end() ) + { + responseHttpContentType = U("multipart/form-data"); + } + else + { + throw ApiException(400, U("{{classname}}->{{operationId}} does not produce any supported media type")); + } + + headerParams[U("Accept")] = responseHttpContentType; + + std::unordered_set consumeHttpContentTypes; + {{#consumes}}consumeHttpContentTypes.insert( U("{{mediaType}}") ); + {{/consumes}} + + {{#allParams}}{{^isBodyParam}}{{^isPrimitiveType}}{{^isContainer}}if ({{paramName}} != nullptr){{/isContainer}}{{/isPrimitiveType}} + { + {{#isContainer}}{{#isQueryParam}}queryParams[U("{{baseName}}")] = ApiClient::parameterToArrayString<{{items.datatype}}>({{paramName}}); + {{/isQueryParam}}{{#isHeaderParam}}headerParams[U("{{baseName}}")] = ApiClient::parameterToArrayString<{{items.datatype}}>({{paramName}}); + {{/isHeaderParam}}{{#isFormParam}}{{^isFile}}formParams[ U("{{baseName}}") ] = ApiClient::parameterToArrayString<{{items.datatype}}>({{paramName}}); + {{/isFile}}{{/isFormParam}}{{/isContainer}}{{^isContainer}}{{#isQueryParam}}queryParams[U("{{baseName}}")] = ApiClient::parameterToString({{paramName}}); + {{/isQueryParam}}{{#isHeaderParam}}headerParams[U("{{baseName}}")] = ApiClient::parameterToString({{paramName}}); + {{/isHeaderParam}}{{#isFormParam}}{{#isFile}}fileParams[ U("{{baseName}}") ] = {{paramName}}; + {{/isFile}}{{^isFile}}formParams[ U("{{baseName}}") ] = ApiClient::parameterToString({{paramName}}); + {{/isFile}}{{/isFormParam}}{{/isContainer}} + } + {{/isBodyParam}}{{/allParams}} + + std::shared_ptr httpBody; + utility::string_t requestHttpContentType; + + // use JSON if possible + if ( consumeHttpContentTypes.size() == 0 || consumeHttpContentTypes.find(U("application/json")) != consumeHttpContentTypes.end() ) + { + requestHttpContentType = U("application/json"); + + {{#bodyParam}} + web::json::value json; + + {{#isPrimitiveType}} json = ModelBase::toJson({{paramName}}); + {{/isPrimitiveType}}{{^isPrimitiveType}}{{#isListContainer}} + { + std::vector jsonArray; + for( auto& item : {{paramName}} ) + { + {{#items.isPrimitiveType}}jsonArray.push_back(ModelBase::toJson(item)); + {{/items.isPrimitiveType}}{{^items.isPrimitiveType}}{{#items.isString}}jsonArray.push_back(ModelBase::toJson(item)); + {{/items.isString}}{{^items.isString}}{{#items.isDateTime}}jsonArray.push_back(ModelBase::toJson(item)); + {{/items.isDateTime}}{{^items.isDateTime}}jsonArray.push_back( item.get() ? item->toJson() : web::json::value::null() ); + {{/items.isDateTime}}{{/items.isString}}{{/items.isPrimitiveType}} + } + json = web::json::value::array(jsonArray); + } + {{/isListContainer}}{{^isListContainer}}json = ModelBase::toJson({{paramName}}); + {{/isListContainer}}{{/isPrimitiveType}} + + httpBody = std::shared_ptr( new JsonBody( json ) ); + + {{/bodyParam}} + } + // multipart formdata + else if( consumeHttpContentTypes.find(U("multipart/form-data")) != consumeHttpContentTypes.end() ) + { + requestHttpContentType = U("multipart/form-data"); + + {{#bodyParam}} + std::shared_ptr multipart(new MultipartFormData); + {{#isPrimitiveType}} multipart->add(ModelBase::toHttpContent("{{paramName}}", {{paramName}})); + {{/isPrimitiveType}}{{^isPrimitiveType}}{{#isListContainer}} + { + std::vector jsonArray; + for( auto& item : {{paramName}} ) + { + {{#items.isPrimitiveType}}jsonArray.push_back(ModelBase::toJson(item)); + {{/items.isPrimitiveType}}{{^items.isPrimitiveType}}{{#items.isString}}jsonArray.push_back(ModelBase::toJson(item)); + {{/items.isString}}{{^items.isString}}{{#items.isDateTime}}jsonArray.push_back(ModelBase::toJson(item)); + {{/items.isDateTime}}{{^items.isDateTime}}jsonArray.push_back( item.get() ? item->toJson() : web::json::value::null() ); + {{/items.isDateTime}}{{/items.isString}}{{/items.isPrimitiveType}} + } + multipart->add(ModelBase::toHttpContent(U("{{paramName}}"), web::json::value::array(jsonArray), U("application/json"))); + } + {{/isListContainer}}{{^isListContainer}}{{#isString}}multipart->add(ModelBase::toHttpContent(U("{{paramName}}"), {{paramName}})); + {{/isString}}{{^isString}} + if({{paramName}}.get()) + { + {{paramName}}->toMultipart(multipart, U("{{paramName}}")); + } + {{/isString}}{{/isListContainer}}{{/isPrimitiveType}} + + httpBody = multipart; + requestHttpContentType += U("; boundary=") + multipart->getBoundary(); + {{/bodyParam}} + } + else + { + throw ApiException(415, U("{{classname}}->{{operationId}} does not consume any supported media type")); + } + + {{#authMethods}} + // authentication ({{name}}) required + {{#isApiKey}} + {{#isKeyInHeader}} + { + utility::string_t apiKey = apiConfiguration->getApiKey(U("{{keyParamName}}")); + if ( apiKey.size() > 0 ) + { + headerParams[U("{{keyParamName}}")] = apiKey; + } + } + {{/isKeyInHeader}} + {{#isKeyInQuery}} + { + utility::string_t apiKey = apiConfiguration->getApiKey(U("{{keyParamName}}")); + if ( apiKey.size() > 0 ) + { + queryParams[U("{{keyParamName}}")] = apiKey; + } + } + {{/isKeyInQuery}} + {{/isApiKey}} + {{#isBasic}} + // Basic authentication is added automatically as part of the http_client_config + {{/isBasic}} + {{#isOAuth}} + // oauth2 authentication is added automatically as part of the http_client_config + {{/isOAuth}} + {{/authMethods}} + + return m_ApiClient->callApi(path, U("{{httpMethod}}"), queryParams, httpBody, headerParams, formParams, fileParams, requestHttpContentType) + .then([=](web::http::http_response response) + { + // 1xx - informational : OK + // 2xx - successful : OK + // 3xx - redirection : OK + // 4xx - client error : not OK + // 5xx - client error : not OK + if (response.status_code() >= 400) + { + throw ApiException(response.status_code() + , U("error calling {{operationId}}: ") + response.reason_phrase() + , std::make_shared(response.extract_utf8string(true).get())); + } + + // check response content type + if(response.headers().has(U("Content-Type"))) + { + utility::string_t contentType = response.headers()[U("Content-Type")]; + if( contentType.find(responseHttpContentType) == std::string::npos ) + { + throw ApiException(500 + , U("error calling {{operationId}}: unexpected response type: ") + contentType + , std::make_shared(response.extract_utf8string(true).get())); + } + } + + return response.extract_string(); + }) + .then([=](utility::string_t response) + { + {{^returnType}}return void(); + {{/returnType}}{{#returnType}}{{#returnContainer}}{{{returnType}}} result; + {{/returnContainer}}{{^returnContainer}}{{{returnType}}} result({{{defaultResponse}}});{{/returnContainer}} + + if(responseHttpContentType == U("application/json")) + { + web::json::value json = web::json::value::parse(response); + + {{#isListContainer}}for( auto& item : json.as_array() ) + { + {{#vendorExtensions.x-codegen-response.items.isPrimitiveType}}result.push_back(ModelBase::{{vendorExtensions.x-codegen-response.items.datatype}}FromJson(item)); + {{/vendorExtensions.x-codegen-response.items.isPrimitiveType}}{{^vendorExtensions.x-codegen-response.items.isPrimitiveType}}{{#vendorExtensions.x-codegen-response.items.isString}}result.push_back(ModelBase::stringFromJson(item)); + {{/vendorExtensions.x-codegen-response.items.isString}}{{^vendorExtensions.x-codegen-response.items.isString}}{{{vendorExtensions.x-codegen-response.items.datatype}}} itemObj({{{vendorExtensions.x-codegen-response.items.defaultValue}}}); + itemObj->fromJson(item); + result.push_back(itemObj); + {{/vendorExtensions.x-codegen-response.items.isString}}{{/vendorExtensions.x-codegen-response.items.isPrimitiveType}} + } + {{/isListContainer}}{{^isListContainer}}{{#isMapContainer}}for( auto& item : json.as_object() ) + { + {{#vendorExtensions.x-codegen-response.items.isPrimitiveType}}result[item.first] = ModelBase::{{vendorExtensions.x-codegen-response.items.datatype}}FromJson(item.second); + {{/vendorExtensions.x-codegen-response.items.isPrimitiveType}}{{^vendorExtensions.x-codegen-response.items.isPrimitiveType}}{{#vendorExtensions.x-codegen-response.items.isString}}result[item.first] = ModelBase::stringFromJson(item.second); + {{/vendorExtensions.x-codegen-response.items.isString}}{{^vendorExtensions.x-codegen-response.items.isString}}{{{vendorExtensions.x-codegen-response.items.datatype}}} itemObj({{{vendorExtensions.x-codegen-response.items.defaultValue}}}); + itemObj->fromJson(item); + result[item.first] = itemObj; + {{/vendorExtensions.x-codegen-response.items.isString}}{{/vendorExtensions.x-codegen-response.items.isPrimitiveType}} + } + {{/isMapContainer}}{{^isMapContainer}}{{#vendorExtensions.x-codegen-response.isPrimitiveType}}result = ModelBase::{{vendorExtensions.x-codegen-response.items.datatype}}FromJson(json); + {{/vendorExtensions.x-codegen-response.isPrimitiveType}}{{^vendorExtensions.x-codegen-response.isPrimitiveType}}{{#vendorExtensions.x-codegen-response.isString}}result = ModelBase::stringFromJson(json); + {{/vendorExtensions.x-codegen-response.isString}}{{^vendorExtensions.x-codegen-response.isString}}result->fromJson(json);{{/vendorExtensions.x-codegen-response.isString}}{{/vendorExtensions.x-codegen-response.isPrimitiveType}}{{/isMapContainer}}{{/isListContainer}} + } + // else if(responseHttpContentType == U("multipart/form-data")) + // { + // TODO multipart response parsing + // } + else + { + throw ApiException(500 + , U("error calling findPetsByStatus: unsupported response type")); + } + + return result; + {{/returnType}} + }); +} +{{/operation}} + +{{#apiNamespaceDeclarations}} +} +{{/apiNamespaceDeclarations}} + +{{/operations}} diff --git a/modules/swagger-codegen/src/main/resources/cpprest/apiclient-header.mustache b/modules/swagger-codegen/src/main/resources/cpprest/apiclient-header.mustache new file mode 100644 index 00000000000..97bd2f823e1 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/cpprest/apiclient-header.mustache @@ -0,0 +1,75 @@ +/* + * ApiClient.h + * + * This is an API client responsible for stating the HTTP calls + */ + +#ifndef ApiClient_H_ +#define ApiClient_H_ + +{{{defaultInclude}}} +#include "ApiConfiguration.h" +#include "ApiException.h" +#include "IHttpBody.h" +#include "HttpContent.h" + +#include +#include + +#include +#include + +{{#apiNamespaceDeclarations}} +namespace {{this}} { +{{/apiNamespaceDeclarations}} + +using namespace {{modelNamespace}}; + +class {{declspec}} ApiClient +{ +public: + ApiClient( std::shared_ptr configuration = nullptr ); + virtual ~ApiClient(); + + std::shared_ptr getConfiguration() const; + void setConfiguration(std::shared_ptr configuration); + + static utility::string_t parameterToString(utility::string_t value); + static utility::string_t parameterToString(int32_t value); + static utility::string_t parameterToString(int64_t value); + + template + static utility::string_t parameterToArrayString(std::vector value) + { + utility::stringstream_t ss; + + for( size_t i = 0; i < value.size(); i++) + { + if( i > 0) ss << U(", "); + ss << ApiClient::parameterToString(value[i]); + } + + return ss.str(); + } + + pplx::task callApi( + const utility::string_t& path, + const utility::string_t& method, + const std::map& queryParams, + const std::shared_ptr postBody, + const std::map& headerParams, + const std::map& formParams, + const std::map>& fileParams, + const utility::string_t& contentType + ) const; + +protected: + + std::shared_ptr m_Configuration; +}; + +{{#apiNamespaceDeclarations}} +} +{{/apiNamespaceDeclarations}} + +#endif /* ApiClient_H_ */ \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/cpprest/apiclient-source.mustache b/modules/swagger-codegen/src/main/resources/cpprest/apiclient-source.mustache new file mode 100644 index 00000000000..cdb62a507b4 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/cpprest/apiclient-source.mustache @@ -0,0 +1,131 @@ +#include "ApiClient.h" +#include "MultipartFormData.h" +#include "ModelBase.h" + +{{#apiNamespaceDeclarations}} +namespace {{this}} { +{{/apiNamespaceDeclarations}} + +using namespace {{modelNamespace}}; + +ApiClient::ApiClient(std::shared_ptr configuration ) + : m_Configuration(configuration) +{ +} +ApiClient::~ApiClient() +{ +} + +std::shared_ptr ApiClient::getConfiguration() const +{ + return m_Configuration; +} +void ApiClient::setConfiguration(std::shared_ptr configuration) +{ + m_Configuration = configuration; +} + + +utility::string_t ApiClient::parameterToString(utility::string_t value) +{ + return value; +} +utility::string_t ApiClient::parameterToString(int64_t value) +{ + return std::to_wstring(value); +} +utility::string_t ApiClient::parameterToString(int32_t value) +{ + return std::to_wstring(value); +} + +pplx::task ApiClient::callApi( + const utility::string_t& path, + const utility::string_t& method, + const std::map& queryParams, + const std::shared_ptr postBody, + const std::map& headerParams, + const std::map& formParams, + const std::map>& fileParams, + const utility::string_t& contentType +) const +{ + if (postBody != nullptr && formParams.size() != 0) + { + throw ApiException(400, U("Cannot have body and form params")); + } + + if (postBody != nullptr && fileParams.size() != 0) + { + throw ApiException(400, U("Cannot have body and file params")); + } + + if (fileParams.size() > 0 && contentType != U("multipart/form-data")) + { + throw ApiException(400, U("Operations with file parameters must be called with multipart/form-data")); + } + + web::http::client::http_client client(m_Configuration->getBaseUrl(), m_Configuration->getHttpConfig()); + + web::http::http_request request; + for ( auto& kvp : headerParams ) + { + request.headers().add(kvp.first, kvp.second); + } + + if (fileParams.size() > 0) + { + MultipartFormData uploadData; + for (auto& kvp : formParams) + { + uploadData.add(ModelBase::toHttpContent(kvp.first, kvp.second)); + } + for (auto& kvp : fileParams) + { + uploadData.add(ModelBase::toHttpContent(kvp.first, kvp.second)); + } + std::stringstream data; + postBody->writeTo(data); + auto bodyString = data.str(); + auto length = bodyString.size(); + request.set_body(concurrency::streams::bytestream::open_istream(std::move(bodyString)), length, contentType); + } + else + { + if (postBody != nullptr) + { + std::stringstream data; + postBody->writeTo(data); + auto bodyString = data.str(); + auto length = bodyString.size(); + request.set_body(concurrency::streams::bytestream::open_istream(std::move(bodyString)), length, contentType); + } + else + { + web::http::uri_builder formData; + for (auto& kvp : formParams) + { + formData.append_query(kvp.first, kvp.second); + } + request.set_body(formData.query(), U("application/x-www-form-urlencoded")); + } + } + + web::http::uri_builder builder(path); + for (auto& kvp : queryParams) + { + builder.append_query(kvp.first, kvp.second); + } + request.set_request_uri(builder.to_uri()); + request.set_method(method); + if ( !request.headers().has( web::http::header_names::user_agent ) ) + { + request.headers().add( web::http::header_names::user_agent, m_Configuration->getUserAgent() ); + } + + return client.request(request); +} + +{{#apiNamespaceDeclarations}} +} +{{/apiNamespaceDeclarations}} \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/cpprest/apiconfiguration-header.mustache b/modules/swagger-codegen/src/main/resources/cpprest/apiconfiguration-header.mustache new file mode 100644 index 00000000000..0463650572b --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/cpprest/apiconfiguration-header.mustache @@ -0,0 +1,51 @@ +/* + * ApiConfiguration.h + * + * This class represents a single item of a multipart-formdata request. + */ + +#ifndef ApiConfiguration_H_ +#define ApiConfiguration_H_ + +{{{defaultInclude}}} + +#include + +#include +#include +{{#apiNamespaceDeclarations}} +namespace {{this}} { +{{/apiNamespaceDeclarations}} + +class {{declspec}} ApiConfiguration +{ +public: + ApiConfiguration(); + virtual ~ApiConfiguration(); + + web::http::client::http_client_config& getHttpConfig(); + void setHttpConfig( web::http::client::http_client_config& value ); + + utility::string_t getBaseUrl() const; + void setBaseUrl( const utility::string_t value ); + + utility::string_t getUserAgent() const; + void setUserAgent( const utility::string_t value ); + + std::map& getDefaultHeaders(); + + utility::string_t getApiKey( const utility::string_t& prefix) const; + void setApiKey( const utility::string_t& prefix, const utility::string_t& apiKey ); + +protected: + utility::string_t m_BaseUrl; + std::map m_DefaultHeaders; + std::map m_ApiKeys; + web::http::client::http_client_config m_HttpConfig; + utility::string_t m_UserAgent; +}; + +{{#apiNamespaceDeclarations}} +} +{{/apiNamespaceDeclarations}} +#endif /* ApiConfiguration_H_ */ \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/cpprest/apiconfiguration-source.mustache b/modules/swagger-codegen/src/main/resources/cpprest/apiconfiguration-source.mustache new file mode 100644 index 00000000000..7585bc10924 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/cpprest/apiconfiguration-source.mustache @@ -0,0 +1,67 @@ +#include "ApiConfiguration.h" + +{{#apiNamespaceDeclarations}} +namespace {{this}} { +{{/apiNamespaceDeclarations}} + +ApiConfiguration::ApiConfiguration() +{ +} + +ApiConfiguration::~ApiConfiguration() +{ +} + +web::http::client::http_client_config& ApiConfiguration::getHttpConfig() +{ + return m_HttpConfig; +} + +void ApiConfiguration::setHttpConfig( web::http::client::http_client_config& value ) +{ + m_HttpConfig = value; +} + +utility::string_t ApiConfiguration::getBaseUrl() const +{ + return m_BaseUrl; +} + +void ApiConfiguration::setBaseUrl( const utility::string_t value ) +{ + m_BaseUrl = value; +} + +utility::string_t ApiConfiguration::getUserAgent() const +{ + return m_UserAgent; +} + +void ApiConfiguration::setUserAgent( const utility::string_t value ) +{ + m_UserAgent = value; +} + +std::map& ApiConfiguration::getDefaultHeaders() +{ + return m_DefaultHeaders; +} + +utility::string_t ApiConfiguration::getApiKey( const utility::string_t& prefix) const +{ + auto result = m_ApiKeys.find(prefix); + if( result != m_ApiKeys.end() ) + { + return result->second; + } + return U(""); +} + +void ApiConfiguration::setApiKey( const utility::string_t& prefix, const utility::string_t& apiKey ) +{ + m_ApiKeys[prefix] = apiKey; +} + +{{#apiNamespaceDeclarations}} +} +{{/apiNamespaceDeclarations}} \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/cpprest/apiexception-header.mustache b/modules/swagger-codegen/src/main/resources/cpprest/apiexception-header.mustache new file mode 100644 index 00000000000..94a46402858 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/cpprest/apiexception-header.mustache @@ -0,0 +1,48 @@ +/* + * ApiException.h + * + * This is the exception being thrown in case the api call was not successful + */ + +#ifndef ApiException_H_ +#define ApiException_H_ + +{{{defaultInclude}}} + +#include +#include + +#include +#include + + +{{#apiNamespaceDeclarations}} +namespace {{this}} { +{{/apiNamespaceDeclarations}} + +class {{declspec}} ApiException + : public web::http::http_exception +{ +public: + ApiException( int errorCode + , const utility::string_t& message + , std::shared_ptr content = nullptr ); + ApiException( int errorCode + , const utility::string_t& message + , std::map& headers + , std::shared_ptr content = nullptr ); + virtual ~ApiException(); + + std::map& getHeaders(); + std::shared_ptr getContent() const; + +protected: + std::shared_ptr m_Content; + std::map m_Headers; +}; + +{{#apiNamespaceDeclarations}} +} +{{/apiNamespaceDeclarations}} + +#endif /* ApiBase_H_ */ \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/cpprest/apiexception-source.mustache b/modules/swagger-codegen/src/main/resources/cpprest/apiexception-source.mustache new file mode 100644 index 00000000000..c6276211b61 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/cpprest/apiexception-source.mustache @@ -0,0 +1,40 @@ +#include "ApiException.h" + +{{#apiNamespaceDeclarations}} +namespace {{this}} { +{{/apiNamespaceDeclarations}} + +ApiException::ApiException( int errorCode + , const utility::string_t& message + , std::shared_ptr content /*= nullptr*/ ) + : web::http::http_exception( errorCode, message ) + , m_Content(content) +{ +} +ApiException::ApiException( int errorCode + , const utility::string_t& message + , std::map& headers + , std::shared_ptr content /*= nullptr*/ ) + : web::http::http_exception( errorCode, message ) + , m_Content(content) + , m_Headers(headers) +{ +} + +ApiException::~ApiException() +{ +} + +std::shared_ptr ApiException::getContent() const +{ + return m_Content; +} + +std::map& ApiException::getHeaders() +{ + return m_Headers; +} + +{{#apiNamespaceDeclarations}} +} +{{/apiNamespaceDeclarations}} \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/cpprest/git_push.sh.mustache b/modules/swagger-codegen/src/main/resources/cpprest/git_push.sh.mustache new file mode 100644 index 00000000000..2619d82f14d --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/cpprest/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/cpprest/gitignore.mustache b/modules/swagger-codegen/src/main/resources/cpprest/gitignore.mustache new file mode 100644 index 00000000000..4581ef2eeef --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/cpprest/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/cpprest/httpcontent-header.mustache b/modules/swagger-codegen/src/main/resources/cpprest/httpcontent-header.mustache new file mode 100644 index 00000000000..93130031118 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/cpprest/httpcontent-header.mustache @@ -0,0 +1,56 @@ +/* + * HttpContent.h + * + * This class represents a single item of a multipart-formdata request. + */ + +#ifndef HttpContent_H_ +#define HttpContent_H_ + +{{{defaultInclude}}} + +#include + +#include + +{{#modelNamespaceDeclarations}} +namespace {{this}} { +{{/modelNamespaceDeclarations}} + +class {{declspec}} HttpContent +{ +public: + HttpContent(); + virtual ~HttpContent(); + + virtual utility::string_t getContentDisposition(); + virtual void setContentDisposition( const utility::string_t& value ); + + virtual utility::string_t getName(); + virtual void setName( const utility::string_t& value ); + + virtual utility::string_t getFileName(); + virtual void setFileName( const utility::string_t& value ); + + virtual utility::string_t getContentType(); + virtual void setContentType( const utility::string_t& value ); + + virtual std::shared_ptr getData(); + virtual void setData( std::shared_ptr value ); + + virtual void writeTo( std::ostream& stream ); + +protected: + // NOTE: no utility::string_t here because those strings can only contain ascii + utility::string_t m_ContentDisposition; + utility::string_t m_Name; + utility::string_t m_FileName; + utility::string_t m_ContentType; + std::shared_ptr m_Data; +}; + +{{#modelNamespaceDeclarations}} +} +{{/modelNamespaceDeclarations}} + +#endif /* HttpContent_H_ */ \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/cpprest/httpcontent-source.mustache b/modules/swagger-codegen/src/main/resources/cpprest/httpcontent-source.mustache new file mode 100644 index 00000000000..c6d9c6da608 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/cpprest/httpcontent-source.mustache @@ -0,0 +1,73 @@ +#include "HttpContent.h" + +{{#modelNamespaceDeclarations}} +namespace {{this}} { +{{/modelNamespaceDeclarations}} + +HttpContent::HttpContent() +{ +} + +HttpContent::~HttpContent() +{ +} + +utility::string_t HttpContent::getContentDisposition() +{ + return m_ContentDisposition; +} + +void HttpContent::setContentDisposition( const utility::string_t & value ) +{ + m_ContentDisposition = value; +} + +utility::string_t HttpContent::getName() +{ + return m_Name; +} + +void HttpContent::setName( const utility::string_t & value ) +{ + m_Name = value; +} + +utility::string_t HttpContent::getFileName() +{ + return m_FileName; +} + +void HttpContent::setFileName( const utility::string_t & value ) +{ + m_FileName = value; +} + +utility::string_t HttpContent::getContentType() +{ + return m_ContentType; +} + +void HttpContent::setContentType( const utility::string_t & value ) +{ + m_ContentType = value; +} + +std::shared_ptr HttpContent::getData() +{ + return m_Data; +} + +void HttpContent::setData( std::shared_ptr value ) +{ + m_Data = value; +} + +void HttpContent::writeTo( std::ostream& stream ) +{ + m_Data->seekg( 0, m_Data->beg ); + stream << m_Data->rdbuf(); +} + +{{#modelNamespaceDeclarations}} +} +{{/modelNamespaceDeclarations}} \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/cpprest/ihttpbody-header.mustache b/modules/swagger-codegen/src/main/resources/cpprest/ihttpbody-header.mustache new file mode 100644 index 00000000000..50ccf4a4d63 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/cpprest/ihttpbody-header.mustache @@ -0,0 +1,29 @@ +/* + * IHttpBody.h + * + * This is the interface for contents that can be sent to a remote HTTP server. + */ + +#ifndef IHttpBody_H_ +#define IHttpBody_H_ + +{{{defaultInclude}}} +#include + +{{#modelNamespaceDeclarations}} +namespace {{this}} { +{{/modelNamespaceDeclarations}} + +class {{declspec}} IHttpBody +{ +public: + virtual ~IHttpBody() { } + + virtual void writeTo( std::ostream& stream ) = 0; +}; + +{{#modelNamespaceDeclarations}} +} +{{/modelNamespaceDeclarations}} + +#endif /* IHttpBody_H_ */ \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/cpprest/jsonbody-header.mustache b/modules/swagger-codegen/src/main/resources/cpprest/jsonbody-header.mustache new file mode 100644 index 00000000000..3dfcba1458e --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/cpprest/jsonbody-header.mustache @@ -0,0 +1,36 @@ +/* + * JsonBody.h + * + * This is a JSON http body which can be submitted via http + */ + +#ifndef JsonBody_H_ +#define JsonBody_H_ + +{{{defaultInclude}}} +#include "IHttpBody.h" + +#include + +{{#modelNamespaceDeclarations}} +namespace {{this}} { +{{/modelNamespaceDeclarations}} + +class {{declspec}} JsonBody + : public IHttpBody +{ +public: + JsonBody( const web::json::value& value ); + virtual ~JsonBody(); + + void writeTo( std::ostream& target ) override; + +protected: + web::json::value m_Json; +}; + +{{#modelNamespaceDeclarations}} +} +{{/modelNamespaceDeclarations}} + +#endif /* JsonBody_H_ */ \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/cpprest/jsonbody-source.mustache b/modules/swagger-codegen/src/main/resources/cpprest/jsonbody-source.mustache new file mode 100644 index 00000000000..c787471e5d4 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/cpprest/jsonbody-source.mustache @@ -0,0 +1,23 @@ +#include "JsonBody.h" + +{{#modelNamespaceDeclarations}} +namespace {{this}} { +{{/modelNamespaceDeclarations}} + +JsonBody::JsonBody( const web::json::value& json) + : m_Json(json) +{ +} + +JsonBody::~JsonBody() +{ +} + +void JsonBody::writeTo( std::ostream& target ) +{ + m_Json.serialize(target); +} + +{{#modelNamespaceDeclarations}} +} +{{/modelNamespaceDeclarations}} \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/cpprest/model-header.mustache b/modules/swagger-codegen/src/main/resources/cpprest/model-header.mustache new file mode 100644 index 00000000000..615a00f57e2 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/cpprest/model-header.mustache @@ -0,0 +1,69 @@ +{{#models}}{{#model}}/* + * {{classname}}.h + * + * {{description}} + */ + +#ifndef {{classname}}_H_ +#define {{classname}}_H_ + +{{{defaultInclude}}} +#include "ModelBase.h" + +{{#imports}}{{{this}}} +{{/imports}} + +{{#modelNamespaceDeclarations}} +namespace {{this}} { +{{/modelNamespaceDeclarations}} + +/// +/// {{description}} +/// +class {{declspec}} {{classname}} + : public ModelBase +{ +public: + {{classname}}(); + virtual ~{{classname}}(); + + ///////////////////////////////////////////// + /// ModelBase overrides + + void validate() override; + + web::json::value toJson() const override; + void fromJson(web::json::value& json) override; + + void toMultipart(std::shared_ptr multipart, const utility::string_t& namePrefix) const override; + void fromMultiPart(std::shared_ptr multipart, const utility::string_t& namePrefix) override; + + ///////////////////////////////////////////// + /// {{classname}} members + + {{#vars}} + /// + /// {{description}} + /// + {{^isNotContainer}}{{{datatype}}}& {{getter}}(); + {{/isNotContainer}}{{#isNotContainer}}{{{datatype}}} {{getter}}() const; + void {{setter}}({{{datatype}}} value); + {{/isNotContainer}}{{^required}}bool {{baseName}}IsSet() const; + void unset{{name}}(); + {{/required}} + {{/vars}} + +protected: + {{#vars}}{{{datatype}}} m_{{name}}; + {{^required}}bool m_{{name}}IsSet; + {{/required}} + {{/vars}} +}; + +{{#modelNamespaceDeclarations}} +} +{{/modelNamespaceDeclarations}} + +#endif /* {{classname}}_H_ */ +{{/model}} +{{/models}} \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/cpprest/model-source.mustache b/modules/swagger-codegen/src/main/resources/cpprest/model-source.mustache new file mode 100644 index 00000000000..c784bb4eb47 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/cpprest/model-source.mustache @@ -0,0 +1,254 @@ +{{#models}}{{#model}} + +#include "{{classname}}.h" + +{{#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}}{{^required}}m_{{name}}IsSet = false; + {{/required}}{{/vars}} +} + +{{classname}}::~{{classname}}() +{ +} + +void {{classname}}::validate() +{ + // TODO: implement validation +} + +web::json::value {{classname}}::toJson() const +{ + web::json::value val = web::json::value::object(); + + {{#vars}}{{#isPrimitiveType}}{{^required}}if(m_{{name}}IsSet) + { + val[U("{{baseName}}")] = ModelBase::toJson(m_{{name}}); + } + {{/required}}{{#required}}val[U("{{baseName}}")] = ModelBase::toJson(m_{{name}}); + {{/required}}{{/isPrimitiveType}}{{^isPrimitiveType}}{{#isListContainer}}{ + std::vector jsonArray; + for( auto& item : m_{{name}} ) + { + jsonArray.push_back(ModelBase::toJson(item)); + } + {{#required}}val[U("{{baseName}}")] = web::json::value::array(jsonArray); + {{/required}}{{^required}} + if(jsonArray.size() > 0) + { + val[U("{{baseName}}")] = web::json::value::array(jsonArray); + } + {{/required}} + } + {{/isListContainer}}{{^isListContainer}}{{^required}}if(m_{{name}}IsSet) + { + val[U("{{baseName}}")] = ModelBase::toJson(m_{{name}}); + } + {{/required}}{{#required}}val[U("{{baseName}}")] = ModelBase::toJson(m_{{name}}); + {{/required}}{{/isListContainer}}{{/isPrimitiveType}}{{/vars}} + + return val; +} + +void {{classname}}::fromJson(web::json::value& val) +{ + {{#vars}}{{#isPrimitiveType}}{{^required}}if(val.has_field(U("{{baseName}}"))) + { + {{setter}}(ModelBase::{{baseType}}FromJson(val[U("{{baseName}}")])); + } + {{/required}}{{#required}}{{setter}}(ModelBase::{{baseType}}FromJson(val[U("{{baseName}}")])); + {{/required}}{{/isPrimitiveType}}{{^isPrimitiveType}}{{#isListContainer}}{ + m_{{name}}.clear(); + std::vector jsonArray; + {{^required}}if(val.has_field(U("{{baseName}}"))) + { + {{/required}} + for( auto& item : val[U("{{baseName}}")].as_array() ) + { + {{#items.isPrimitiveType}}m_{{name}}.push_back(ModelBase::{{baseType}}FromJson(item)); + {{/items.isPrimitiveType}}{{^items.isPrimitiveType}}{{#items.isString}}m_{{name}}.push_back(ModelBase::stringFromJson(item)); + {{/items.isString}}{{^items.isString}}{{#items.isDateTime}}m_{{name}}.push_back(ModelBase::dateFromJson(item)); + {{/items.isDateTime}}{{^items.isDateTime}} + if(item.is_null()) + { + m_{{name}}.push_back( {{{items.datatype}}}(nullptr) ); + } + else + { + {{{items.datatype}}} newItem({{{items.defaultValue}}}); + newItem->fromJson(item); + m_{{name}}.push_back( newItem ); + } + {{/items.isDateTime}}{{/items.isString}}{{/items.isPrimitiveType}} + } + {{^required}} + } + {{/required}} + } + {{/isListContainer}}{{^isListContainer}}{{^required}}if(val.has_field(U("{{baseName}}"))) + { + {{#isString}}{{setter}}(ModelBase::stringFromJson(val[U("{{baseName}}")])); + {{/isString}}{{^isString}}{{#isDateTime}}{{setter}}(ModelBase::dateFromJson(val[U("{{baseName}}")])); + {{/isDateTime}}{{^isDateTime}}if(!val[U("{{baseName}}")].is_null()) + { + {{{datatype}}} newItem({{{defaultValue}}}); + newItem->fromJson(val[U("{{baseName}}")]); + {{setter}}( newItem ); + } + {{/isDateTime}}{{/isString}} + } + {{/required}}{{#required}}{{#isString}}{{setter}}(ModelBase::stringFromJson(val[U("{{baseName}}")])); + {{/isString}}{{^isString}}{{#isDateTime}}{{setter}}(ModelBase::dateFromJson(val[U("{{baseName}}")])); + {{/isDateTime}}{{^isDateTime}}{{#vendorExtensions.x-codegen-file}}{{setter}}(ModelBase::fileFromJson(val[U("{{baseName}}")])); + {{/vendorExtensions.x-codegen-file}}{{^vendorExtensions.x-codegen-file}}{{{datatype}}} new{{name}}({{{defaultValue}}}); + new{{name}}->fromJson(val[U("{{baseName}}")]); + {{setter}}( newItem ); + {{/vendorExtensions.x-codegen-file}}{{/isDateTime}}{{/isString}}{{/required}}{{/isListContainer}}{{/isPrimitiveType}}{{/vars}} +} + +void {{classname}}::toMultipart(std::shared_ptr multipart, const utility::string_t& prefix) const +{ + utility::string_t namePrefix = prefix; + if(namePrefix.size() > 0 && namePrefix[namePrefix.size() - 1] != U('.')) + { + namePrefix += U("."); + } + + {{#vars}}{{#isPrimitiveType}}{{^required}}if(m_{{name}}IsSet) + { + multipart->add(ModelBase::toHttpContent(namePrefix + U("{{baseName}}"), m_{{name}})); + } + {{/required}}{{#required}}multipart->add(ModelBase::toHttpContent(namePrefix + U("{{baseName}}"), m_{{name}})); + {{/required}}{{/isPrimitiveType}}{{^isPrimitiveType}}{{#isListContainer}}{ + std::vector jsonArray; + for( auto& item : m_{{name}} ) + { + jsonArray.push_back(ModelBase::toJson(item)); + } + {{#required}}multipart->add(ModelBase::toHttpContent(namePrefix + U("{{baseName}}"), web::json::value::array(jsonArray), U("application/json"))); + {{/required}}{{^required}} + if(jsonArray.size() > 0) + { + multipart->add(ModelBase::toHttpContent(namePrefix + U("{{baseName}}"), web::json::value::array(jsonArray), U("application/json"))); + } + {{/required}} + } + {{/isListContainer}}{{^isListContainer}}{{^required}}if(m_{{name}}IsSet) + { + {{#isString}}multipart->add(ModelBase::toHttpContent(namePrefix + U("{{baseName}}"), m_{{name}})); + {{/isString}}{{^isString}}{{#isDateTime}}multipart->add(ModelBase::toHttpContent(namePrefix + U("{{baseName}}"), m_{{name}})); + {{/isDateTime}}{{^isDateTime}}if (m_{{name}}.get()) + { + m_{{name}}->toMultipart(multipart, U("{{baseName}}.")); + } + {{/isDateTime}}{{/isString}} + } + {{/required}}{{#required}}{{#isString}}multipart->add(ModelBase::toHttpContent(namePrefix + U("{{baseName}}"), m_{{name}})); + {{/isString}}{{^isString}}{{#isDateTime}}multipart->add(ModelBase::toHttpContent(namePrefix + U("{{baseName}}"), m_{{name}})); + {{/isDateTime}}{{^isDateTime}}{{#vendorExtensions.x-codegen-file}}multipart->add(ModelBase::toHttpContent(namePrefix + U("{{baseName}}"), m_{{name}})); + {{/vendorExtensions.x-codegen-file}}{{^vendorExtensions.x-codegen-file}}m_{{name}}->toMultipart(multipart, U("{{baseName}}.")); + {{/vendorExtensions.x-codegen-file}}{{/isDateTime}}{{/isString}}{{/required}}{{/isListContainer}}{{/isPrimitiveType}}{{/vars}} +} + +void {{classname}}::fromMultiPart(std::shared_ptr multipart, const utility::string_t& prefix) +{ + utility::string_t namePrefix = prefix; + if(namePrefix.size() > 0 && namePrefix[namePrefix.size() - 1] != U('.')) + { + namePrefix += U("."); + } + + {{#vars}}{{#isPrimitiveType}}{{^required}}if(multipart->hasContent(U("{{baseName}}"))) + { + {{setter}}(ModelBase::{{baseType}}FromHttpContent(multipart->getContent(U("{{baseName}}")))); + } + {{/required}}{{#required}}{{setter}}(ModelBase::{{baseType}}FromHttpContent(multipart->getContent(U("{{baseName}}")))); + {{/required}}{{/isPrimitiveType}}{{^isPrimitiveType}}{{#isListContainer}}{ + m_{{name}}.clear(); + {{^required}}if(multipart->hasContent(U("{{baseName}}"))) + { + {{/required}} + + web::json::value jsonArray = web::json::value::parse(ModelBase::stringFromHttpContent(multipart->getContent(U("{{baseName}}")))); + for( auto& item : jsonArray.as_array() ) + { + {{#items.isPrimitiveType}}m_{{name}}.push_back(ModelBase::{{baseType}}FromJson(item)); + {{/items.isPrimitiveType}}{{^items.isPrimitiveType}}{{#items.isString}}m_{{name}}.push_back(ModelBase::stringFromJson(item)); + {{/items.isString}}{{^items.isString}}{{#items.isDateTime}}m_{{name}}.push_back(ModelBase::dateFromJson(item)); + {{/items.isDateTime}}{{^items.isDateTime}} + if(item.is_null()) + { + m_{{name}}.push_back( {{{items.datatype}}}(nullptr) ); + } + else + { + {{{items.datatype}}} newItem({{{items.defaultValue}}}); + newItem->fromJson(item); + m_{{name}}.push_back( newItem ); + } + {{/items.isDateTime}}{{/items.isString}}{{/items.isPrimitiveType}} + } + {{^required}} + } + {{/required}} + } + {{/isListContainer}}{{^isListContainer}}{{^required}}if(multipart->hasContent(U("{{baseName}}"))) + { + {{#isString}}{{setter}}(ModelBase::stringFromHttpContent(multipart->getContent(U("{{baseName}}")))); + {{/isString}}{{^isString}}{{#isDateTime}}{{setter}}(ModelBase::dateFromHttpContent(multipart->getContent(U("{{baseName}}")))); + {{/isDateTime}}{{^isDateTime}}if(multipart->hasContent(U("{{baseName}}"))) + { + {{{datatype}}} newItem({{{defaultValue}}}); + newItem->fromMultiPart(multipart, U("{{baseName}}.")); + {{setter}}( newItem ); + } + {{/isDateTime}}{{/isString}} + } + {{/required}}{{#required}}{{#isString}}{{setter}}(ModelBase::stringFromHttpContent(multipart->getContent(U("{{baseName}}")))); + {{/isString}}{{^isString}}{{#isDateTime}}{{setter}}(ModelBase::dateFromHttpContent(multipart->getContent(U("{{baseName}}")))); + {{/isDateTime}}{{^isDateTime}}{{#vendorExtensions.x-codegen-file}}{{setter}}(multipart->getContent(U("{{baseName}}"))); + {{/vendorExtensions.x-codegen-file}}{{^vendorExtensions.x-codegen-file}}{{{datatype}}} new{{name}}({{{defaultValue}}}); + new{{name}}->fromMultiPart(multipart, U("{{baseName}}.")); + {{setter}}( new{{name}} ); + {{/vendorExtensions.x-codegen-file}}{{/isDateTime}}{{/isString}}{{/required}}{{/isListContainer}}{{/isPrimitiveType}}{{/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; + {{^required}}m_{{name}}IsSet = true;{{/required}} +} +{{/isNotContainer}} +{{^required}}bool {{classname}}::{{baseName}}IsSet() const +{ + return m_{{name}}IsSet; +} +void {{classname}}::unset{{name}}() +{ + m_{{name}}IsSet = false; +} +{{/required}} +{{/vars}} + +{{#modelNamespaceDeclarations}} +} +{{/modelNamespaceDeclarations}} + +{{/model}} +{{/models}} \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/cpprest/modelbase-header.mustache b/modules/swagger-codegen/src/main/resources/cpprest/modelbase-header.mustache new file mode 100644 index 00000000000..9505286ec97 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/cpprest/modelbase-header.mustache @@ -0,0 +1,76 @@ +/* + * ModelBase.h + * + * This is the base class for all model classes + */ + +#ifndef ModelBase_H_ +#define ModelBase_H_ + +{{{defaultInclude}}} +#include "HttpContent.h" +#include "MultipartFormData.h" + +#include +#include + +{{#modelNamespaceDeclarations}} +namespace {{this}} { +{{/modelNamespaceDeclarations}} + +class {{declspec}} ModelBase +{ +public: + ModelBase(); + virtual ~ModelBase(); + + virtual void validate() = 0; + + virtual web::json::value toJson() const = 0; + virtual void fromJson(web::json::value& json) = 0; + + virtual void toMultipart(std::shared_ptr multipart, const utility::string_t& namePrefix) const = 0; + virtual void fromMultiPart(std::shared_ptr multipart, const utility::string_t& namePrefix) = 0; + + static web::json::value toJson( const utility::string_t& value ); + static web::json::value toJson( const utility::datetime& value ); + static web::json::value toJson( std::shared_ptr value ); + static web::json::value toJson( std::shared_ptr value ); + static web::json::value toJson( int32_t value ); + static web::json::value toJson( int64_t value ); + static web::json::value toJson( double value ); + + static int64_t int64_tFromJson(web::json::value& val); + static int32_t int32_tFromJson(web::json::value& val); + static utility::string_t stringFromJson(web::json::value& val); + static utility::datetime dateFromJson(web::json::value& val); + static double doubleFromJson(web::json::value& val); + static bool boolFromJson(web::json::value& val); + static std::shared_ptr fileFromJson(web::json::value& val); + + static std::shared_ptr toHttpContent( const utility::string_t& name, const utility::string_t& value, const utility::string_t& contentType = U("")); + static std::shared_ptr toHttpContent( const utility::string_t& name, const utility::datetime& value, const utility::string_t& contentType = U("")); + static std::shared_ptr toHttpContent( const utility::string_t& name, std::shared_ptr value ); + static std::shared_ptr toHttpContent( const utility::string_t& name, const web::json::value& value, const utility::string_t& contentType = U("application/json") ); + static std::shared_ptr toHttpContent( const utility::string_t& name, int32_t value, const utility::string_t& contentType = U("") ); + static std::shared_ptr toHttpContent( const utility::string_t& name, int64_t value, const utility::string_t& contentType = U("") ); + static std::shared_ptr toHttpContent( const utility::string_t& name, double value, const utility::string_t& contentType = U("") ); + + static int64_t int64_tFromHttpContent(std::shared_ptr val); + static int32_t int32_tFromHttpContent(std::shared_ptr val); + static utility::string_t stringFromHttpContent(std::shared_ptr val); + static utility::datetime dateFromHttpContent(std::shared_ptr val); + static bool boolFromHttpContent(std::shared_ptr val); + static double doubleFromHttpContent(std::shared_ptr val); + + + static utility::string_t toBase64( utility::string_t value ); + static utility::string_t toBase64( std::shared_ptr value ); + static std::shared_ptr fromBase64( const utility::string_t& encoded ); +}; + +{{#modelNamespaceDeclarations}} +} +{{/modelNamespaceDeclarations}} + +#endif /* ModelBase_H_ */ \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/cpprest/modelbase-source.mustache b/modules/swagger-codegen/src/main/resources/cpprest/modelbase-source.mustache new file mode 100644 index 00000000000..dce2c3eb3b4 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/cpprest/modelbase-source.mustache @@ -0,0 +1,337 @@ +#include "ModelBase.h" + +{{#modelNamespaceDeclarations}} +namespace {{this}} { +{{/modelNamespaceDeclarations}} + +ModelBase::ModelBase() +{ +} +ModelBase::~ModelBase() +{ +} + +web::json::value ModelBase::toJson( const utility::string_t& value ) +{ + return web::json::value::string(value); +} +web::json::value ModelBase::toJson( const utility::datetime& value ) +{ + return web::json::value::string(value.to_string(utility::datetime::ISO_8601)); +} +web::json::value ModelBase::toJson( int32_t value ) +{ + return web::json::value::number(value); +} +web::json::value ModelBase::toJson( int64_t value ) +{ + return web::json::value::number(value); +} +web::json::value ModelBase::toJson( double value ) +{ + return web::json::value::number(value); +} + +web::json::value ModelBase::toJson( std::shared_ptr content ) +{ + web::json::value value; + value[U("ContentDisposition")] = ModelBase::toJson(content->getContentDisposition()); + value[U("ContentType")] = ModelBase::toJson(content->getContentType()); + value[U("FileName")] = ModelBase::toJson(content->getFileName()); + value[U("InputStream")] = web::json::value::string( ModelBase::toBase64(content->getData()) ); + return value; +} + +std::shared_ptr ModelBase::fileFromJson(web::json::value& val) +{ + std::shared_ptr content(new HttpContent); + + if(val.has_field(U("ContentDisposition"))) + { + content->setContentDisposition( ModelBase::stringFromJson(val[U("ContentDisposition")]) ); + } + if(val.has_field(U("ContentType"))) + { + content->setContentType( ModelBase::stringFromJson(val[U("ContentType")]) ); + } + if(val.has_field(U("FileName"))) + { + content->setFileName( ModelBase::stringFromJson(val[U("FileName")]) ); + } + if(val.has_field(U("InputStream"))) + { + content->setData( ModelBase::fromBase64( ModelBase::stringFromJson(val[U("InputStream")]) ) ); + } + + return content; +} + +web::json::value ModelBase::toJson( std::shared_ptr content ) +{ + return content.get() ? content->toJson() : web::json::value::null(); +} + +std::shared_ptr ModelBase::toHttpContent( const utility::string_t& name, const utility::string_t& value, const utility::string_t& contentType) +{ + std::shared_ptr content(new HttpContent); + content->setName( name ); + content->setContentDisposition( U("form-data") ); + content->setContentType( contentType ); + content->setData( std::shared_ptr( new std::stringstream( utility::conversions::to_utf8string(value) ) ) ); + return content; +} +std::shared_ptr ModelBase::toHttpContent( const utility::string_t& name, const utility::datetime& value, const utility::string_t& contentType ) +{ + std::shared_ptr content( new HttpContent ); + content->setName( name ); + content->setContentDisposition( U("form-data") ); + content->setContentType( contentType ); + content->setData( std::shared_ptr( new std::stringstream( utility::conversions::to_utf8string(value.to_string(utility::datetime::ISO_8601) ) ) ) ); + return content; +} +std::shared_ptr ModelBase::toHttpContent( const utility::string_t& name, std::shared_ptr value ) +{ + std::shared_ptr content( new HttpContent ); + content->setName( name ); + content->setContentDisposition( value->getContentDisposition() ); + content->setContentType( value->getContentType() ); + content->setData( value->getData() ); + content->setFileName( value->getFileName() ); + return content; +} +std::shared_ptr ModelBase::toHttpContent( const utility::string_t& name, const web::json::value& value, const utility::string_t& contentType ) +{ + std::shared_ptr content( new HttpContent ); + content->setName( name ); + content->setContentDisposition( U("form-data") ); + content->setContentType( contentType ); + content->setData( std::shared_ptr( new std::stringstream( utility::conversions::to_utf8string(value.serialize()) ) ) ); + return content; +} +std::shared_ptr ModelBase::toHttpContent( const utility::string_t& name, int32_t value, const utility::string_t& contentType ) +{ + std::shared_ptr content( new HttpContent ); + content->setName( name ); + content->setContentDisposition( U("form-data") ); + content->setContentType( contentType ); + content->setData( std::shared_ptr( new std::stringstream( std::to_string( value ) ) ) ); + return content; +} +std::shared_ptr ModelBase::toHttpContent( const utility::string_t& name, int64_t value, const utility::string_t& contentType ) +{ + std::shared_ptr content( new HttpContent ); + content->setName( name ); + content->setContentDisposition( U("form-data") ); + content->setContentType( contentType ); + content->setData( std::shared_ptr( new std::stringstream( std::to_string( value ) ) ) ); + return content; +} +std::shared_ptr ModelBase::toHttpContent( const utility::string_t& name, double value, const utility::string_t& contentType ) +{ + std::shared_ptr content( new HttpContent ); + content->setName( name ); + content->setContentDisposition( U("form-data") ); + content->setContentType( contentType ); + content->setData( std::shared_ptr( new std::stringstream( std::to_string( value ) ) ) ); + return content; +} + +// base64 encoding/decoding based on : https://en.wikibooks.org/wiki/Algorithm_Implementation/Miscellaneous/Base64#C.2B.2B +const static char Base64Chars[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; +const static char Base64PadChar = '='; +utility::string_t ModelBase::toBase64( utility::string_t value ) +{ + std::shared_ptr source( new std::stringstream( utility::conversions::to_utf8string(value) ) ); + return ModelBase::toBase64(source); +} +utility::string_t ModelBase::toBase64( std::shared_ptr value ) +{ + value->seekg( 0, value->end ); + size_t length = value->tellg(); + value->seekg( 0, value->beg ); + utility::string_t base64; + base64.reserve( ((length / 3) + (length % 3 > 0)) * 4 ); + char read[3] = { 0 }; + uint32_t temp; + for ( size_t idx = 0; idx < length / 3; idx++ ) + { + value->read( read, 3 ); + temp = (read[0]) << 16; + temp += (read[1]) << 8; + temp += (read[2]); + base64.append( 1, Base64Chars[(temp & 0x00FC0000) >> 18] ); + base64.append( 1, Base64Chars[(temp & 0x0003F000) >> 12] ); + base64.append( 1, Base64Chars[(temp & 0x00000FC0) >> 6] ); + base64.append( 1, Base64Chars[(temp & 0x0000003F)] ); + } + switch ( length % 3 ) + { + case 1: + value->read( read, 1 ); + temp = read[0] << 16; + base64.append( 1, Base64Chars[(temp & 0x00FC0000) >> 18] ); + base64.append( 1, Base64Chars[(temp & 0x0003F000) >> 12] ); + base64.append( 2, Base64PadChar ); + break; + case 2: + value->read( read, 2 ); + temp = read[0] << 16; + temp += read[1] << 8; + base64.append( 1, Base64Chars[(temp & 0x00FC0000) >> 18] ); + base64.append( 1, Base64Chars[(temp & 0x0003F000) >> 12] ); + base64.append( 1, Base64Chars[(temp & 0x00000FC0) >> 6] ); + base64.append( 1, Base64PadChar ); + break; + } + return base64; +} + + +std::shared_ptr ModelBase::fromBase64( const utility::string_t& encoded ) +{ + std::shared_ptr result(new std::stringstream); + + char outBuf[3] = { 0 }; + uint32_t temp = 0; + + utility::string_t::const_iterator cursor = encoded.begin(); + while ( cursor < encoded.end() ) + { + for ( size_t quantumPosition = 0; quantumPosition < 4; quantumPosition++ ) + { + temp <<= 6; + if ( *cursor >= 0x41 && *cursor <= 0x5A ) + { + temp |= *cursor - 0x41; + } + else if ( *cursor >= 0x61 && *cursor <= 0x7A ) + { + temp |= *cursor - 0x47; + } + else if ( *cursor >= 0x30 && *cursor <= 0x39 ) + { + temp |= *cursor + 0x04; + } + else if ( *cursor == 0x2B ) + { + temp |= 0x3E; //change to 0x2D for URL alphabet + } + else if ( *cursor == 0x2F ) + { + temp |= 0x3F; //change to 0x5F for URL alphabet + } + else if ( *cursor == Base64PadChar ) //pad + { + switch ( encoded.end() - cursor ) + { + case 1: //One pad character + outBuf[0] = (temp >> 16) & 0x000000FF; + outBuf[1] = (temp >> 8) & 0x000000FF; + result->write( outBuf, 2 ); + return result; + case 2: //Two pad characters + outBuf[0] = (temp >> 10) & 0x000000FF; + result->write( outBuf, 1 ); + return result; + default: + throw web::json::json_exception( U( "Invalid Padding in Base 64!" ) ); + } + } + else + { + throw web::json::json_exception( U( "Non-Valid Character in Base 64!" ) ); + } + ++cursor; + } + + outBuf[0] = (temp >> 16) & 0x000000FF; + outBuf[1] = (temp >> 8) & 0x000000FF; + outBuf[2] = (temp) & 0x000000FF; + result->write( outBuf, 3 ); + } + + return result; +} + +int64_t ModelBase::int64_tFromJson(web::json::value& val) +{ + return val.as_number().to_int64(); +} +int32_t ModelBase::int32_tFromJson(web::json::value& val) +{ + return val.as_integer(); +} +utility::string_t ModelBase::stringFromJson(web::json::value& val) +{ + return val.is_string() ? val.as_string() : U(""); +} + +utility::datetime ModelBase::dateFromJson(web::json::value& val) +{ + return utility::datetime::from_string(val.as_string(), utility::datetime::ISO_8601); +} +bool ModelBase::boolFromJson(web::json::value& val) +{ + return val.as_bool(); +} +double ModelBase::doubleFromJson(web::json::value& val) +{ + return val.as_double(); +} + +int64_t ModelBase::int64_tFromHttpContent(std::shared_ptr val) +{ + utility::string_t str = ModelBase::stringFromHttpContent(val); + + utility::stringstream_t ss(str); + int64_t result = 0; + ss >> result; + return result; +} +int32_t ModelBase::int32_tFromHttpContent(std::shared_ptr val) +{ + utility::string_t str = ModelBase::stringFromHttpContent(val); + + utility::stringstream_t ss(str); + int32_t result = 0; + ss >> result; + return result; +} +utility::string_t ModelBase::stringFromHttpContent(std::shared_ptr val) +{ + std::shared_ptr data = val->getData(); + data->seekg( 0, data->beg ); + + std::string str((std::istreambuf_iterator(*data.get())), + std::istreambuf_iterator()); + + return utility::conversions::to_utf16string(str); +} +utility::datetime ModelBase::dateFromHttpContent(std::shared_ptr val) +{ + utility::string_t str = ModelBase::stringFromHttpContent(val); + return utility::datetime::from_string(str, utility::datetime::ISO_8601); +} + +bool ModelBase::boolFromHttpContent(std::shared_ptr val) +{ + utility::string_t str = ModelBase::stringFromHttpContent(val); + + utility::stringstream_t ss(str); + bool result = false; + ss >> result; + return result; +} +double ModelBase::doubleFromHttpContent(std::shared_ptr val) +{ + utility::string_t str = ModelBase::stringFromHttpContent(val); + + utility::stringstream_t ss(str); + double result = 0.0; + ss >> result; + return result; +} + +{{#modelNamespaceDeclarations}} +} +{{/modelNamespaceDeclarations}} \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/cpprest/multipart-header.mustache b/modules/swagger-codegen/src/main/resources/cpprest/multipart-header.mustache new file mode 100644 index 00000000000..f6e1b774379 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/cpprest/multipart-header.mustache @@ -0,0 +1,49 @@ +/* + * MultipartFormData.h + * + * This class represents a container for building a application/x-multipart-formdata requests. + */ + +#ifndef MultipartFormData_H_ +#define MultipartFormData_H_ + +{{{defaultInclude}}} +#include "IHttpBody.h" +#include "HttpContent.h" + +#include +#include +#include + +#include + + +{{#modelNamespaceDeclarations}} +namespace {{this}} { +{{/modelNamespaceDeclarations}} + +class {{declspec}} MultipartFormData + : public IHttpBody +{ +public: + MultipartFormData(); + MultipartFormData(const utility::string_t& boundary); + virtual ~MultipartFormData(); + + virtual void add( std::shared_ptr content ); + virtual utility::string_t getBoundary(); + virtual std::shared_ptr getContent(const utility::string_t& name) const; + virtual bool hasContent(const utility::string_t& name) const; + virtual void writeTo( std::ostream& target ); + +protected: + std::vector> m_Contents; + utility::string_t m_Boundary; + std::map> m_ContentLookup; +}; + +{{#modelNamespaceDeclarations}} +} +{{/modelNamespaceDeclarations}} + +#endif /* MultipartFormData_H_ */ \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/cpprest/multipart-source.mustache b/modules/swagger-codegen/src/main/resources/cpprest/multipart-source.mustache new file mode 100644 index 00000000000..64b59113050 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/cpprest/multipart-source.mustache @@ -0,0 +1,99 @@ +#include "MultipartFormData.h" +#include "ModelBase.h" + +#include +#include + +{{#modelNamespaceDeclarations}} +namespace {{this}} { +{{/modelNamespaceDeclarations}} + +MultipartFormData::MultipartFormData() +{ + utility::stringstream_t uuidString; + uuidString << boost::uuids::random_generator()(); + m_Boundary = uuidString.str(); +} + +MultipartFormData::MultipartFormData(const utility::string_t& boundary) + : m_Boundary(boundary) +{ + +} + +MultipartFormData::~MultipartFormData() +{ +} + +utility::string_t MultipartFormData::getBoundary() +{ + return m_Boundary; +} + +void MultipartFormData::add( std::shared_ptr content ) +{ + m_Contents.push_back( content ); + m_ContentLookup[content->getName()] = content; +} + +bool MultipartFormData::hasContent(const utility::string_t& name) const +{ + return m_ContentLookup.find(name) != m_ContentLookup.end(); +} + +std::shared_ptr MultipartFormData::getContent(const utility::string_t& name) const +{ + auto result = m_ContentLookup.find(name); + if(result == m_ContentLookup.end()) + { + return std::shared_ptr(nullptr); + } + return result->second; +} + +void MultipartFormData::writeTo( std::ostream& target ) +{ + for ( size_t i = 0; i < m_Contents.size(); i++ ) + { + std::shared_ptr content = m_Contents[i]; + + // boundary + target << "\r\n" << "--" << utility::conversions::to_utf8string( m_Boundary ) << "\r\n"; + + // headers + target << "Content-Disposition: " << utility::conversions::to_utf8string( content->getContentDisposition() ); + if ( content->getName().size() > 0 ) + { + target << "; name=\"" << utility::conversions::to_utf8string( content->getName() ) << "\""; + } + if ( content->getFileName().size() > 0 ) + { + target << "; filename=\"" << utility::conversions::to_utf8string( content->getFileName() ) << "\""; + } + target << "\r\n"; + + if ( content->getContentType().size() > 0 ) + { + target << "Content-Type: " << utility::conversions::to_utf8string( content->getContentType() ) << "\r\n"; + } + + target << "\r\n"; + + // body + std::shared_ptr data = content->getData(); + + data->seekg( 0, data->end ); + std::vector dataBytes( data->tellg() ); + + data->seekg( 0, data->beg ); + data->read( &dataBytes[0], dataBytes.size() ); + + std::copy( dataBytes.begin(), dataBytes.end(), std::ostreambuf_iterator( target ) ); + } + + target << "\r\n--" << utility::conversions::to_utf8string( m_Boundary ) << "--\r\n"; +} + +{{#modelNamespaceDeclarations}} +} +{{/modelNamespaceDeclarations}} \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/go-server/README.mustache b/modules/swagger-codegen/src/main/resources/go-server/README.mustache new file mode 100644 index 00000000000..8b66fe30f46 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/go-server/README.mustache @@ -0,0 +1,30 @@ +# Go API Server for {{packageName}} + +{{#appDescription}} +{{{appDescription}}} +{{/appDescription}} + +## Overview +This server was generated by the [swagger-codegen] +(https://github.com/swagger-api/swagger-codegen) project. +By using the [OpenAPI-Spec](https://github.com/OAI/OpenAPI-Specification) from a remote server, you can easily generate a server stub. +- + +To see how to make this your own, look here: + +[README](https://github.com/swagger-api/swagger-codegen/blob/master/README.md) + +- API version: {{appVersion}} +- Build date: {{generatedDate}} +{{#infoUrl}} +For more information, please visit [{{{infoUrl}}}]({{{infoUrl}}}) +{{/infoUrl}} + + +### Running the server +To run the server, follow these simple steps: + +``` +go run main.go +``` + diff --git a/modules/swagger-codegen/src/main/resources/go-server/app.mustache b/modules/swagger-codegen/src/main/resources/go-server/app.mustache new file mode 100644 index 00000000000..18774a8cd31 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/go-server/app.mustache @@ -0,0 +1 @@ +application: {{packageName}} \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/go-server/controller.mustache b/modules/swagger-codegen/src/main/resources/go-server/controller.mustache new file mode 100644 index 00000000000..b8efd5f50e7 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/go-server/controller.mustache @@ -0,0 +1,19 @@ +package {{packageName}} + +{{#operations}} +import ( + "net/http" +) + +type {{classname}} struct { + +} + +{{#operation}} +func {{nickname}}(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "application/json; charset=UTF-8") + w.WriteHeader(http.StatusOK) +} + +{{/operation}} +{{/operations}} \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/go-server/logger.mustache b/modules/swagger-codegen/src/main/resources/go-server/logger.mustache new file mode 100644 index 00000000000..6ccb2dafe81 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/go-server/logger.mustache @@ -0,0 +1,23 @@ +package {{packageName}} + +import ( + "log" + "net/http" + "time" +) + +func Logger(inner http.Handler, name string) http.Handler { + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + start := time.Now() + + inner.ServeHTTP(w, r) + + log.Printf( + "%s %s %s %s", + r.Method, + r.RequestURI, + name, + time.Since(start), + ) + }) +} \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/go-server/main.mustache b/modules/swagger-codegen/src/main/resources/go-server/main.mustache new file mode 100644 index 00000000000..17b6072ebfb --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/go-server/main.mustache @@ -0,0 +1,22 @@ +package main + +import ( + // WARNING! + // Change this to a fully-qualified import path + // once you place this file into your project. + // For example, + // + // sw "github.com/myname/myrepo/{{apiPath}}" + // + sw "./{{apiPath}}" + "log" + "net/http" +) + +func main() { + log.Printf("Server started") + + router := sw.NewRouter() + + log.Fatal(http.ListenAndServe(":{{serverPort}}", router)) +} diff --git a/modules/swagger-codegen/src/main/resources/go-server/routers.mustache b/modules/swagger-codegen/src/main/resources/go-server/routers.mustache new file mode 100644 index 00000000000..5999268a528 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/go-server/routers.mustache @@ -0,0 +1,54 @@ +package {{packageName}} + +import ( + "net/http" + "fmt" + "github.com/gorilla/mux" +) + +type Route struct { + Name string + Method string + Pattern string + HandlerFunc http.HandlerFunc +} + +type Routes []Route + +func NewRouter() *mux.Router { + router := mux.NewRouter().StrictSlash(true) + for _, route := range routes { + var handler http.Handler + handler = route.HandlerFunc + handler = Logger(handler, route.Name) + + router. + Methods(route.Method). + Path(route.Pattern). + Name(route.Name). + Handler(handler) + } + + return router +} + +func Index(w http.ResponseWriter, r *http.Request) { + fmt.Fprintf(w, "Hello World!") +} + +var routes = Routes{ + Route{ + "Index", + "GET", + "/", + Index, + }, +{{#apiInfo}}{{#apis}}{{#operations}}{{#operation}} + Route{ + "{{operationId}}", + "{{httpMethod}}", + "{{path}}", + {{operationId}}, + }, +{{/operation}}{{/operations}}{{/apis}}{{/apiInfo}} +} \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/go-server/swagger.mustache b/modules/swagger-codegen/src/main/resources/go-server/swagger.mustache new file mode 100644 index 00000000000..51560926bba --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/go-server/swagger.mustache @@ -0,0 +1 @@ +{{{swagger-yaml}}} \ No newline at end of file diff --git a/modules/swagger-codegen/src/test/java/io/swagger/codegen/options/GoServerOptionsProvider.java b/modules/swagger-codegen/src/test/java/io/swagger/codegen/options/GoServerOptionsProvider.java new file mode 100644 index 00000000000..71e47537f45 --- /dev/null +++ b/modules/swagger-codegen/src/test/java/io/swagger/codegen/options/GoServerOptionsProvider.java @@ -0,0 +1,30 @@ +package io.swagger.codegen.options; + +import io.swagger.codegen.CodegenConstants; + +import com.google.common.collect.ImmutableMap; + +import java.util.Map; + +public class GoServerOptionsProvider implements OptionsProvider { + public static final String SORT_PARAMS_VALUE = "false"; + public static final String ENSURE_UNIQUE_PARAMS_VALUE = "true"; + + @Override + public String getLanguage() { + return "go-server"; + } + + @Override + public Map createOptions() { + ImmutableMap.Builder builder = new ImmutableMap.Builder(); + return builder.put(CodegenConstants.SORT_PARAMS_BY_REQUIRED_FLAG, SORT_PARAMS_VALUE) + .put(CodegenConstants.ENSURE_UNIQUE_PARAMS, ENSURE_UNIQUE_PARAMS_VALUE) + .build(); + } + + @Override + public boolean isServer() { + return true; + } +} diff --git a/samples/client/petstore/cpprest/.gitignore b/samples/client/petstore/cpprest/.gitignore new file mode 100644 index 00000000000..4581ef2eeef --- /dev/null +++ b/samples/client/petstore/cpprest/.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/client/petstore/cpprest/.swagger-codegen-ignore b/samples/client/petstore/cpprest/.swagger-codegen-ignore new file mode 100644 index 00000000000..19d3377182e --- /dev/null +++ b/samples/client/petstore/cpprest/.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 +# Thsi 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/client/petstore/cpprest/ApiClient.cpp b/samples/client/petstore/cpprest/ApiClient.cpp new file mode 100644 index 00000000000..b04707e54c9 --- /dev/null +++ b/samples/client/petstore/cpprest/ApiClient.cpp @@ -0,0 +1,133 @@ +#include "ApiClient.h" +#include "MultipartFormData.h" +#include "ModelBase.h" + +namespace io { +namespace swagger { +namespace client { +namespace api { + +using namespace io::swagger::client::model; + +ApiClient::ApiClient(std::shared_ptr configuration ) + : m_Configuration(configuration) +{ +} +ApiClient::~ApiClient() +{ +} + +std::shared_ptr ApiClient::getConfiguration() const +{ + return m_Configuration; +} +void ApiClient::setConfiguration(std::shared_ptr configuration) +{ + m_Configuration = configuration; +} + + +utility::string_t ApiClient::parameterToString(utility::string_t value) +{ + return value; +} +utility::string_t ApiClient::parameterToString(int64_t value) +{ + return std::to_wstring(value); +} +utility::string_t ApiClient::parameterToString(int32_t value) +{ + return std::to_wstring(value); +} + +pplx::task ApiClient::callApi( + const utility::string_t& path, + const utility::string_t& method, + const std::map& queryParams, + const std::shared_ptr postBody, + const std::map& headerParams, + const std::map& formParams, + const std::map>& fileParams, + const utility::string_t& contentType +) const +{ + if (postBody != nullptr && formParams.size() != 0) + { + throw ApiException(400, U("Cannot have body and form params")); + } + + if (postBody != nullptr && fileParams.size() != 0) + { + throw ApiException(400, U("Cannot have body and file params")); + } + + if (fileParams.size() > 0 && contentType != U("multipart/form-data")) + { + throw ApiException(400, U("Operations with file parameters must be called with multipart/form-data")); + } + + web::http::client::http_client client(m_Configuration->getBaseUrl(), m_Configuration->getHttpConfig()); + + web::http::http_request request; + for ( auto& kvp : headerParams ) + { + request.headers().add(kvp.first, kvp.second); + } + + if (fileParams.size() > 0) + { + MultipartFormData uploadData; + for (auto& kvp : formParams) + { + uploadData.add(ModelBase::toHttpContent(kvp.first, kvp.second)); + } + for (auto& kvp : fileParams) + { + uploadData.add(ModelBase::toHttpContent(kvp.first, kvp.second)); + } + std::stringstream data; + postBody->writeTo(data); + auto bodyString = data.str(); + auto length = bodyString.size(); + request.set_body(concurrency::streams::bytestream::open_istream(std::move(bodyString)), length, contentType); + } + else + { + if (postBody != nullptr) + { + std::stringstream data; + postBody->writeTo(data); + auto bodyString = data.str(); + auto length = bodyString.size(); + request.set_body(concurrency::streams::bytestream::open_istream(std::move(bodyString)), length, contentType); + } + else + { + web::http::uri_builder formData; + for (auto& kvp : formParams) + { + formData.append_query(kvp.first, kvp.second); + } + request.set_body(formData.query(), U("application/x-www-form-urlencoded")); + } + } + + web::http::uri_builder builder(path); + for (auto& kvp : queryParams) + { + builder.append_query(kvp.first, kvp.second); + } + request.set_request_uri(builder.to_uri()); + request.set_method(method); + if ( !request.headers().has( web::http::header_names::user_agent ) ) + { + request.headers().add( web::http::header_names::user_agent, m_Configuration->getUserAgent() ); + } + + return client.request(request); +} + +} +} +} +} diff --git a/samples/client/petstore/cpprest/ApiClient.h b/samples/client/petstore/cpprest/ApiClient.h new file mode 100644 index 00000000000..cbbb91ce7db --- /dev/null +++ b/samples/client/petstore/cpprest/ApiClient.h @@ -0,0 +1,77 @@ +/* + * ApiClient.h + * + * This is an API client responsible for stating the HTTP calls + */ + +#ifndef ApiClient_H_ +#define ApiClient_H_ + + +#include "ApiConfiguration.h" +#include "ApiException.h" +#include "IHttpBody.h" +#include "HttpContent.h" + +#include +#include + +#include +#include + +namespace io { +namespace swagger { +namespace client { +namespace api { + +using namespace io::swagger::client::model; + +class ApiClient +{ +public: + ApiClient( std::shared_ptr configuration = nullptr ); + virtual ~ApiClient(); + + std::shared_ptr getConfiguration() const; + void setConfiguration(std::shared_ptr configuration); + + static utility::string_t parameterToString(utility::string_t value); + static utility::string_t parameterToString(int32_t value); + static utility::string_t parameterToString(int64_t value); + + template + static utility::string_t parameterToArrayString(std::vector value) + { + utility::stringstream_t ss; + + for( size_t i = 0; i < value.size(); i++) + { + if( i > 0) ss << U(", "); + ss << ApiClient::parameterToString(value[i]); + } + + return ss.str(); + } + + pplx::task callApi( + const utility::string_t& path, + const utility::string_t& method, + const std::map& queryParams, + const std::shared_ptr postBody, + const std::map& headerParams, + const std::map& formParams, + const std::map>& fileParams, + const utility::string_t& contentType + ) const; + +protected: + + std::shared_ptr m_Configuration; +}; + +} +} +} +} + +#endif /* ApiClient_H_ */ \ No newline at end of file diff --git a/samples/client/petstore/cpprest/ApiConfiguration.cpp b/samples/client/petstore/cpprest/ApiConfiguration.cpp new file mode 100644 index 00000000000..e66ce50a209 --- /dev/null +++ b/samples/client/petstore/cpprest/ApiConfiguration.cpp @@ -0,0 +1,69 @@ +#include "ApiConfiguration.h" + +namespace io { +namespace swagger { +namespace client { +namespace api { + +ApiConfiguration::ApiConfiguration() +{ +} + +ApiConfiguration::~ApiConfiguration() +{ +} + +web::http::client::http_client_config& ApiConfiguration::getHttpConfig() +{ + return m_HttpConfig; +} + +void ApiConfiguration::setHttpConfig( web::http::client::http_client_config& value ) +{ + m_HttpConfig = value; +} + +utility::string_t ApiConfiguration::getBaseUrl() const +{ + return m_BaseUrl; +} + +void ApiConfiguration::setBaseUrl( const utility::string_t value ) +{ + m_BaseUrl = value; +} + +utility::string_t ApiConfiguration::getUserAgent() const +{ + return m_UserAgent; +} + +void ApiConfiguration::setUserAgent( const utility::string_t value ) +{ + m_UserAgent = value; +} + +std::map& ApiConfiguration::getDefaultHeaders() +{ + return m_DefaultHeaders; +} + +utility::string_t ApiConfiguration::getApiKey( const utility::string_t& prefix) const +{ + auto result = m_ApiKeys.find(prefix); + if( result != m_ApiKeys.end() ) + { + return result->second; + } + return U(""); +} + +void ApiConfiguration::setApiKey( const utility::string_t& prefix, const utility::string_t& apiKey ) +{ + m_ApiKeys[prefix] = apiKey; +} + +} +} +} +} diff --git a/samples/client/petstore/cpprest/ApiConfiguration.h b/samples/client/petstore/cpprest/ApiConfiguration.h new file mode 100644 index 00000000000..d0011a82c9e --- /dev/null +++ b/samples/client/petstore/cpprest/ApiConfiguration.h @@ -0,0 +1,53 @@ +/* + * ApiConfiguration.h + * + * This class represents a single item of a multipart-formdata request. + */ + +#ifndef ApiConfiguration_H_ +#define ApiConfiguration_H_ + + + +#include + +#include +#include +namespace io { +namespace swagger { +namespace client { +namespace api { + +class ApiConfiguration +{ +public: + ApiConfiguration(); + virtual ~ApiConfiguration(); + + web::http::client::http_client_config& getHttpConfig(); + void setHttpConfig( web::http::client::http_client_config& value ); + + utility::string_t getBaseUrl() const; + void setBaseUrl( const utility::string_t value ); + + utility::string_t getUserAgent() const; + void setUserAgent( const utility::string_t value ); + + std::map& getDefaultHeaders(); + + utility::string_t getApiKey( const utility::string_t& prefix) const; + void setApiKey( const utility::string_t& prefix, const utility::string_t& apiKey ); + +protected: + utility::string_t m_BaseUrl; + std::map m_DefaultHeaders; + std::map m_ApiKeys; + web::http::client::http_client_config m_HttpConfig; + utility::string_t m_UserAgent; +}; + +} +} +} +} +#endif /* ApiConfiguration_H_ */ \ No newline at end of file diff --git a/samples/client/petstore/cpprest/ApiException.cpp b/samples/client/petstore/cpprest/ApiException.cpp new file mode 100644 index 00000000000..a2d5ba18da2 --- /dev/null +++ b/samples/client/petstore/cpprest/ApiException.cpp @@ -0,0 +1,42 @@ +#include "ApiException.h" + +namespace io { +namespace swagger { +namespace client { +namespace api { + +ApiException::ApiException( int errorCode + , const utility::string_t& message + , std::shared_ptr content /*= nullptr*/ ) + : web::http::http_exception( errorCode, message ) + , m_Content(content) +{ +} +ApiException::ApiException( int errorCode + , const utility::string_t& message + , std::map& headers + , std::shared_ptr content /*= nullptr*/ ) + : web::http::http_exception( errorCode, message ) + , m_Content(content) + , m_Headers(headers) +{ +} + +ApiException::~ApiException() +{ +} + +std::shared_ptr ApiException::getContent() const +{ + return m_Content; +} + +std::map& ApiException::getHeaders() +{ + return m_Headers; +} + +} +} +} +} diff --git a/samples/client/petstore/cpprest/ApiException.h b/samples/client/petstore/cpprest/ApiException.h new file mode 100644 index 00000000000..1c16a5c2d3b --- /dev/null +++ b/samples/client/petstore/cpprest/ApiException.h @@ -0,0 +1,50 @@ +/* + * ApiException.h + * + * This is the exception being thrown in case the api call was not successful + */ + +#ifndef ApiException_H_ +#define ApiException_H_ + + + +#include +#include + +#include +#include + + +namespace io { +namespace swagger { +namespace client { +namespace api { + +class ApiException + : public web::http::http_exception +{ +public: + ApiException( int errorCode + , const utility::string_t& message + , std::shared_ptr content = nullptr ); + ApiException( int errorCode + , const utility::string_t& message + , std::map& headers + , std::shared_ptr content = nullptr ); + virtual ~ApiException(); + + std::map& getHeaders(); + std::shared_ptr getContent() const; + +protected: + std::shared_ptr m_Content; + std::map m_Headers; +}; + +} +} +} +} + +#endif /* ApiBase_H_ */ \ No newline at end of file diff --git a/samples/client/petstore/cpprest/HttpContent.cpp b/samples/client/petstore/cpprest/HttpContent.cpp new file mode 100644 index 00000000000..c6697f6e0d2 --- /dev/null +++ b/samples/client/petstore/cpprest/HttpContent.cpp @@ -0,0 +1,75 @@ +#include "HttpContent.h" + +namespace io { +namespace swagger { +namespace client { +namespace model { + +HttpContent::HttpContent() +{ +} + +HttpContent::~HttpContent() +{ +} + +utility::string_t HttpContent::getContentDisposition() +{ + return m_ContentDisposition; +} + +void HttpContent::setContentDisposition( const utility::string_t & value ) +{ + m_ContentDisposition = value; +} + +utility::string_t HttpContent::getName() +{ + return m_Name; +} + +void HttpContent::setName( const utility::string_t & value ) +{ + m_Name = value; +} + +utility::string_t HttpContent::getFileName() +{ + return m_FileName; +} + +void HttpContent::setFileName( const utility::string_t & value ) +{ + m_FileName = value; +} + +utility::string_t HttpContent::getContentType() +{ + return m_ContentType; +} + +void HttpContent::setContentType( const utility::string_t & value ) +{ + m_ContentType = value; +} + +std::shared_ptr HttpContent::getData() +{ + return m_Data; +} + +void HttpContent::setData( std::shared_ptr value ) +{ + m_Data = value; +} + +void HttpContent::writeTo( std::ostream& stream ) +{ + m_Data->seekg( 0, m_Data->beg ); + stream << m_Data->rdbuf(); +} + +} +} +} +} diff --git a/samples/client/petstore/cpprest/HttpContent.h b/samples/client/petstore/cpprest/HttpContent.h new file mode 100644 index 00000000000..d8ec4ba51db --- /dev/null +++ b/samples/client/petstore/cpprest/HttpContent.h @@ -0,0 +1,58 @@ +/* + * HttpContent.h + * + * This class represents a single item of a multipart-formdata request. + */ + +#ifndef HttpContent_H_ +#define HttpContent_H_ + + + +#include + +#include + +namespace io { +namespace swagger { +namespace client { +namespace model { + +class HttpContent +{ +public: + HttpContent(); + virtual ~HttpContent(); + + virtual utility::string_t getContentDisposition(); + virtual void setContentDisposition( const utility::string_t& value ); + + virtual utility::string_t getName(); + virtual void setName( const utility::string_t& value ); + + virtual utility::string_t getFileName(); + virtual void setFileName( const utility::string_t& value ); + + virtual utility::string_t getContentType(); + virtual void setContentType( const utility::string_t& value ); + + virtual std::shared_ptr getData(); + virtual void setData( std::shared_ptr value ); + + virtual void writeTo( std::ostream& stream ); + +protected: + // NOTE: no utility::string_t here because those strings can only contain ascii + utility::string_t m_ContentDisposition; + utility::string_t m_Name; + utility::string_t m_FileName; + utility::string_t m_ContentType; + std::shared_ptr m_Data; +}; + +} +} +} +} + +#endif /* HttpContent_H_ */ \ No newline at end of file diff --git a/samples/client/petstore/cpprest/IHttpBody.h b/samples/client/petstore/cpprest/IHttpBody.h new file mode 100644 index 00000000000..a4e34b6e76a --- /dev/null +++ b/samples/client/petstore/cpprest/IHttpBody.h @@ -0,0 +1,31 @@ +/* + * IHttpBody.h + * + * This is the interface for contents that can be sent to a remote HTTP server. + */ + +#ifndef IHttpBody_H_ +#define IHttpBody_H_ + + +#include + +namespace io { +namespace swagger { +namespace client { +namespace model { + +class IHttpBody +{ +public: + virtual ~IHttpBody() { } + + virtual void writeTo( std::ostream& stream ) = 0; +}; + +} +} +} +} + +#endif /* IHttpBody_H_ */ \ No newline at end of file diff --git a/samples/client/petstore/cpprest/JsonBody.cpp b/samples/client/petstore/cpprest/JsonBody.cpp new file mode 100644 index 00000000000..43970e03f25 --- /dev/null +++ b/samples/client/petstore/cpprest/JsonBody.cpp @@ -0,0 +1,25 @@ +#include "JsonBody.h" + +namespace io { +namespace swagger { +namespace client { +namespace model { + +JsonBody::JsonBody( const web::json::value& json) + : m_Json(json) +{ +} + +JsonBody::~JsonBody() +{ +} + +void JsonBody::writeTo( std::ostream& target ) +{ + m_Json.serialize(target); +} + +} +} +} +} diff --git a/samples/client/petstore/cpprest/JsonBody.h b/samples/client/petstore/cpprest/JsonBody.h new file mode 100644 index 00000000000..a86d9a5177a --- /dev/null +++ b/samples/client/petstore/cpprest/JsonBody.h @@ -0,0 +1,38 @@ +/* + * JsonBody.h + * + * This is a JSON http body which can be submitted via http + */ + +#ifndef JsonBody_H_ +#define JsonBody_H_ + + +#include "IHttpBody.h" + +#include + +namespace io { +namespace swagger { +namespace client { +namespace model { + +class JsonBody + : public IHttpBody +{ +public: + JsonBody( const web::json::value& value ); + virtual ~JsonBody(); + + void writeTo( std::ostream& target ) override; + +protected: + web::json::value m_Json; +}; + +} +} +} +} + +#endif /* JsonBody_H_ */ \ No newline at end of file diff --git a/samples/client/petstore/cpprest/LICENSE b/samples/client/petstore/cpprest/LICENSE new file mode 100644 index 00000000000..8dada3edaf5 --- /dev/null +++ b/samples/client/petstore/cpprest/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "{}" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright {yyyy} {name of copyright owner} + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/samples/client/petstore/cpprest/ModelBase.cpp b/samples/client/petstore/cpprest/ModelBase.cpp new file mode 100644 index 00000000000..d8abe304fa5 --- /dev/null +++ b/samples/client/petstore/cpprest/ModelBase.cpp @@ -0,0 +1,339 @@ +#include "ModelBase.h" + +namespace io { +namespace swagger { +namespace client { +namespace model { + +ModelBase::ModelBase() +{ +} +ModelBase::~ModelBase() +{ +} + +web::json::value ModelBase::toJson( const utility::string_t& value ) +{ + return web::json::value::string(value); +} +web::json::value ModelBase::toJson( const utility::datetime& value ) +{ + return web::json::value::string(value.to_string(utility::datetime::ISO_8601)); +} +web::json::value ModelBase::toJson( int32_t value ) +{ + return web::json::value::number(value); +} +web::json::value ModelBase::toJson( int64_t value ) +{ + return web::json::value::number(value); +} +web::json::value ModelBase::toJson( double value ) +{ + return web::json::value::number(value); +} + +web::json::value ModelBase::toJson( std::shared_ptr content ) +{ + web::json::value value; + value[U("ContentDisposition")] = ModelBase::toJson(content->getContentDisposition()); + value[U("ContentType")] = ModelBase::toJson(content->getContentType()); + value[U("FileName")] = ModelBase::toJson(content->getFileName()); + value[U("InputStream")] = web::json::value::string( ModelBase::toBase64(content->getData()) ); + return value; +} + +std::shared_ptr ModelBase::fileFromJson(web::json::value& val) +{ + std::shared_ptr content(new HttpContent); + + if(val.has_field(U("ContentDisposition"))) + { + content->setContentDisposition( ModelBase::stringFromJson(val[U("ContentDisposition")]) ); + } + if(val.has_field(U("ContentType"))) + { + content->setContentType( ModelBase::stringFromJson(val[U("ContentType")]) ); + } + if(val.has_field(U("FileName"))) + { + content->setFileName( ModelBase::stringFromJson(val[U("FileName")]) ); + } + if(val.has_field(U("InputStream"))) + { + content->setData( ModelBase::fromBase64( ModelBase::stringFromJson(val[U("InputStream")]) ) ); + } + + return content; +} + +web::json::value ModelBase::toJson( std::shared_ptr content ) +{ + return content.get() ? content->toJson() : web::json::value::null(); +} + +std::shared_ptr ModelBase::toHttpContent( const utility::string_t& name, const utility::string_t& value, const utility::string_t& contentType) +{ + std::shared_ptr content(new HttpContent); + content->setName( name ); + content->setContentDisposition( U("form-data") ); + content->setContentType( contentType ); + content->setData( std::shared_ptr( new std::stringstream( utility::conversions::to_utf8string(value) ) ) ); + return content; +} +std::shared_ptr ModelBase::toHttpContent( const utility::string_t& name, const utility::datetime& value, const utility::string_t& contentType ) +{ + std::shared_ptr content( new HttpContent ); + content->setName( name ); + content->setContentDisposition( U("form-data") ); + content->setContentType( contentType ); + content->setData( std::shared_ptr( new std::stringstream( utility::conversions::to_utf8string(value.to_string(utility::datetime::ISO_8601) ) ) ) ); + return content; +} +std::shared_ptr ModelBase::toHttpContent( const utility::string_t& name, std::shared_ptr value ) +{ + std::shared_ptr content( new HttpContent ); + content->setName( name ); + content->setContentDisposition( value->getContentDisposition() ); + content->setContentType( value->getContentType() ); + content->setData( value->getData() ); + content->setFileName( value->getFileName() ); + return content; +} +std::shared_ptr ModelBase::toHttpContent( const utility::string_t& name, const web::json::value& value, const utility::string_t& contentType ) +{ + std::shared_ptr content( new HttpContent ); + content->setName( name ); + content->setContentDisposition( U("form-data") ); + content->setContentType( contentType ); + content->setData( std::shared_ptr( new std::stringstream( utility::conversions::to_utf8string(value.serialize()) ) ) ); + return content; +} +std::shared_ptr ModelBase::toHttpContent( const utility::string_t& name, int32_t value, const utility::string_t& contentType ) +{ + std::shared_ptr content( new HttpContent ); + content->setName( name ); + content->setContentDisposition( U("form-data") ); + content->setContentType( contentType ); + content->setData( std::shared_ptr( new std::stringstream( std::to_string( value ) ) ) ); + return content; +} +std::shared_ptr ModelBase::toHttpContent( const utility::string_t& name, int64_t value, const utility::string_t& contentType ) +{ + std::shared_ptr content( new HttpContent ); + content->setName( name ); + content->setContentDisposition( U("form-data") ); + content->setContentType( contentType ); + content->setData( std::shared_ptr( new std::stringstream( std::to_string( value ) ) ) ); + return content; +} +std::shared_ptr ModelBase::toHttpContent( const utility::string_t& name, double value, const utility::string_t& contentType ) +{ + std::shared_ptr content( new HttpContent ); + content->setName( name ); + content->setContentDisposition( U("form-data") ); + content->setContentType( contentType ); + content->setData( std::shared_ptr( new std::stringstream( std::to_string( value ) ) ) ); + return content; +} + +// base64 encoding/decoding based on : https://en.wikibooks.org/wiki/Algorithm_Implementation/Miscellaneous/Base64#C.2B.2B +const static char Base64Chars[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; +const static char Base64PadChar = '='; +utility::string_t ModelBase::toBase64( utility::string_t value ) +{ + std::shared_ptr source( new std::stringstream( utility::conversions::to_utf8string(value) ) ); + return ModelBase::toBase64(source); +} +utility::string_t ModelBase::toBase64( std::shared_ptr value ) +{ + value->seekg( 0, value->end ); + size_t length = value->tellg(); + value->seekg( 0, value->beg ); + utility::string_t base64; + base64.reserve( ((length / 3) + (length % 3 > 0)) * 4 ); + char read[3] = { 0 }; + uint32_t temp; + for ( size_t idx = 0; idx < length / 3; idx++ ) + { + value->read( read, 3 ); + temp = (read[0]) << 16; + temp += (read[1]) << 8; + temp += (read[2]); + base64.append( 1, Base64Chars[(temp & 0x00FC0000) >> 18] ); + base64.append( 1, Base64Chars[(temp & 0x0003F000) >> 12] ); + base64.append( 1, Base64Chars[(temp & 0x00000FC0) >> 6] ); + base64.append( 1, Base64Chars[(temp & 0x0000003F)] ); + } + switch ( length % 3 ) + { + case 1: + value->read( read, 1 ); + temp = read[0] << 16; + base64.append( 1, Base64Chars[(temp & 0x00FC0000) >> 18] ); + base64.append( 1, Base64Chars[(temp & 0x0003F000) >> 12] ); + base64.append( 2, Base64PadChar ); + break; + case 2: + value->read( read, 2 ); + temp = read[0] << 16; + temp += read[1] << 8; + base64.append( 1, Base64Chars[(temp & 0x00FC0000) >> 18] ); + base64.append( 1, Base64Chars[(temp & 0x0003F000) >> 12] ); + base64.append( 1, Base64Chars[(temp & 0x00000FC0) >> 6] ); + base64.append( 1, Base64PadChar ); + break; + } + return base64; +} + + +std::shared_ptr ModelBase::fromBase64( const utility::string_t& encoded ) +{ + std::shared_ptr result(new std::stringstream); + + char outBuf[3] = { 0 }; + uint32_t temp = 0; + + utility::string_t::const_iterator cursor = encoded.begin(); + while ( cursor < encoded.end() ) + { + for ( size_t quantumPosition = 0; quantumPosition < 4; quantumPosition++ ) + { + temp <<= 6; + if ( *cursor >= 0x41 && *cursor <= 0x5A ) + { + temp |= *cursor - 0x41; + } + else if ( *cursor >= 0x61 && *cursor <= 0x7A ) + { + temp |= *cursor - 0x47; + } + else if ( *cursor >= 0x30 && *cursor <= 0x39 ) + { + temp |= *cursor + 0x04; + } + else if ( *cursor == 0x2B ) + { + temp |= 0x3E; //change to 0x2D for URL alphabet + } + else if ( *cursor == 0x2F ) + { + temp |= 0x3F; //change to 0x5F for URL alphabet + } + else if ( *cursor == Base64PadChar ) //pad + { + switch ( encoded.end() - cursor ) + { + case 1: //One pad character + outBuf[0] = (temp >> 16) & 0x000000FF; + outBuf[1] = (temp >> 8) & 0x000000FF; + result->write( outBuf, 2 ); + return result; + case 2: //Two pad characters + outBuf[0] = (temp >> 10) & 0x000000FF; + result->write( outBuf, 1 ); + return result; + default: + throw web::json::json_exception( U( "Invalid Padding in Base 64!" ) ); + } + } + else + { + throw web::json::json_exception( U( "Non-Valid Character in Base 64!" ) ); + } + ++cursor; + } + + outBuf[0] = (temp >> 16) & 0x000000FF; + outBuf[1] = (temp >> 8) & 0x000000FF; + outBuf[2] = (temp) & 0x000000FF; + result->write( outBuf, 3 ); + } + + return result; +} + +int64_t ModelBase::int64_tFromJson(web::json::value& val) +{ + return val.as_number().to_int64(); +} +int32_t ModelBase::int32_tFromJson(web::json::value& val) +{ + return val.as_integer(); +} +utility::string_t ModelBase::stringFromJson(web::json::value& val) +{ + return val.is_string() ? val.as_string() : U(""); +} + +utility::datetime ModelBase::dateFromJson(web::json::value& val) +{ + return utility::datetime::from_string(val.as_string(), utility::datetime::ISO_8601); +} +bool ModelBase::boolFromJson(web::json::value& val) +{ + return val.as_bool(); +} +double ModelBase::doubleFromJson(web::json::value& val) +{ + return val.as_double(); +} + +int64_t ModelBase::int64_tFromHttpContent(std::shared_ptr val) +{ + utility::string_t str = ModelBase::stringFromHttpContent(val); + + utility::stringstream_t ss(str); + int64_t result = 0; + ss >> result; + return result; +} +int32_t ModelBase::int32_tFromHttpContent(std::shared_ptr val) +{ + utility::string_t str = ModelBase::stringFromHttpContent(val); + + utility::stringstream_t ss(str); + int32_t result = 0; + ss >> result; + return result; +} +utility::string_t ModelBase::stringFromHttpContent(std::shared_ptr val) +{ + std::shared_ptr data = val->getData(); + data->seekg( 0, data->beg ); + + std::string str((std::istreambuf_iterator(*data.get())), + std::istreambuf_iterator()); + + return utility::conversions::to_utf16string(str); +} +utility::datetime ModelBase::dateFromHttpContent(std::shared_ptr val) +{ + utility::string_t str = ModelBase::stringFromHttpContent(val); + return utility::datetime::from_string(str, utility::datetime::ISO_8601); +} + +bool ModelBase::boolFromHttpContent(std::shared_ptr val) +{ + utility::string_t str = ModelBase::stringFromHttpContent(val); + + utility::stringstream_t ss(str); + bool result = false; + ss >> result; + return result; +} +double ModelBase::doubleFromHttpContent(std::shared_ptr val) +{ + utility::string_t str = ModelBase::stringFromHttpContent(val); + + utility::stringstream_t ss(str); + double result = 0.0; + ss >> result; + return result; +} + +} +} +} +} diff --git a/samples/client/petstore/cpprest/ModelBase.h b/samples/client/petstore/cpprest/ModelBase.h new file mode 100644 index 00000000000..a3dccce65da --- /dev/null +++ b/samples/client/petstore/cpprest/ModelBase.h @@ -0,0 +1,78 @@ +/* + * ModelBase.h + * + * This is the base class for all model classes + */ + +#ifndef ModelBase_H_ +#define ModelBase_H_ + + +#include "HttpContent.h" +#include "MultipartFormData.h" + +#include +#include + +namespace io { +namespace swagger { +namespace client { +namespace model { + +class ModelBase +{ +public: + ModelBase(); + virtual ~ModelBase(); + + virtual void validate() = 0; + + virtual web::json::value toJson() const = 0; + virtual void fromJson(web::json::value& json) = 0; + + virtual void toMultipart(std::shared_ptr multipart, const utility::string_t& namePrefix) const = 0; + virtual void fromMultiPart(std::shared_ptr multipart, const utility::string_t& namePrefix) = 0; + + static web::json::value toJson( const utility::string_t& value ); + static web::json::value toJson( const utility::datetime& value ); + static web::json::value toJson( std::shared_ptr value ); + static web::json::value toJson( std::shared_ptr value ); + static web::json::value toJson( int32_t value ); + static web::json::value toJson( int64_t value ); + static web::json::value toJson( double value ); + + static int64_t int64_tFromJson(web::json::value& val); + static int32_t int32_tFromJson(web::json::value& val); + static utility::string_t stringFromJson(web::json::value& val); + static utility::datetime dateFromJson(web::json::value& val); + static double doubleFromJson(web::json::value& val); + static bool boolFromJson(web::json::value& val); + static std::shared_ptr fileFromJson(web::json::value& val); + + static std::shared_ptr toHttpContent( const utility::string_t& name, const utility::string_t& value, const utility::string_t& contentType = U("")); + static std::shared_ptr toHttpContent( const utility::string_t& name, const utility::datetime& value, const utility::string_t& contentType = U("")); + static std::shared_ptr toHttpContent( const utility::string_t& name, std::shared_ptr value ); + static std::shared_ptr toHttpContent( const utility::string_t& name, const web::json::value& value, const utility::string_t& contentType = U("application/json") ); + static std::shared_ptr toHttpContent( const utility::string_t& name, int32_t value, const utility::string_t& contentType = U("") ); + static std::shared_ptr toHttpContent( const utility::string_t& name, int64_t value, const utility::string_t& contentType = U("") ); + static std::shared_ptr toHttpContent( const utility::string_t& name, double value, const utility::string_t& contentType = U("") ); + + static int64_t int64_tFromHttpContent(std::shared_ptr val); + static int32_t int32_tFromHttpContent(std::shared_ptr val); + static utility::string_t stringFromHttpContent(std::shared_ptr val); + static utility::datetime dateFromHttpContent(std::shared_ptr val); + static bool boolFromHttpContent(std::shared_ptr val); + static double doubleFromHttpContent(std::shared_ptr val); + + + static utility::string_t toBase64( utility::string_t value ); + static utility::string_t toBase64( std::shared_ptr value ); + static std::shared_ptr fromBase64( const utility::string_t& encoded ); +}; + +} +} +} +} + +#endif /* ModelBase_H_ */ \ No newline at end of file diff --git a/samples/client/petstore/cpprest/MultipartFormData.cpp b/samples/client/petstore/cpprest/MultipartFormData.cpp new file mode 100644 index 00000000000..2637af6ed2e --- /dev/null +++ b/samples/client/petstore/cpprest/MultipartFormData.cpp @@ -0,0 +1,101 @@ +#include "MultipartFormData.h" +#include "ModelBase.h" + +#include +#include + +namespace io { +namespace swagger { +namespace client { +namespace model { + +MultipartFormData::MultipartFormData() +{ + utility::stringstream_t uuidString; + uuidString << boost::uuids::random_generator()(); + m_Boundary = uuidString.str(); +} + +MultipartFormData::MultipartFormData(const utility::string_t& boundary) + : m_Boundary(boundary) +{ + +} + +MultipartFormData::~MultipartFormData() +{ +} + +utility::string_t MultipartFormData::getBoundary() +{ + return m_Boundary; +} + +void MultipartFormData::add( std::shared_ptr content ) +{ + m_Contents.push_back( content ); + m_ContentLookup[content->getName()] = content; +} + +bool MultipartFormData::hasContent(const utility::string_t& name) const +{ + return m_ContentLookup.find(name) != m_ContentLookup.end(); +} + +std::shared_ptr MultipartFormData::getContent(const utility::string_t& name) const +{ + auto result = m_ContentLookup.find(name); + if(result == m_ContentLookup.end()) + { + return std::shared_ptr(nullptr); + } + return result->second; +} + +void MultipartFormData::writeTo( std::ostream& target ) +{ + for ( size_t i = 0; i < m_Contents.size(); i++ ) + { + std::shared_ptr content = m_Contents[i]; + + // boundary + target << "\r\n" << "--" << utility::conversions::to_utf8string( m_Boundary ) << "\r\n"; + + // headers + target << "Content-Disposition: " << utility::conversions::to_utf8string( content->getContentDisposition() ); + if ( content->getName().size() > 0 ) + { + target << "; name=\"" << utility::conversions::to_utf8string( content->getName() ) << "\""; + } + if ( content->getFileName().size() > 0 ) + { + target << "; filename=\"" << utility::conversions::to_utf8string( content->getFileName() ) << "\""; + } + target << "\r\n"; + + if ( content->getContentType().size() > 0 ) + { + target << "Content-Type: " << utility::conversions::to_utf8string( content->getContentType() ) << "\r\n"; + } + + target << "\r\n"; + + // body + std::shared_ptr data = content->getData(); + + data->seekg( 0, data->end ); + std::vector dataBytes( data->tellg() ); + + data->seekg( 0, data->beg ); + data->read( &dataBytes[0], dataBytes.size() ); + + std::copy( dataBytes.begin(), dataBytes.end(), std::ostreambuf_iterator( target ) ); + } + + target << "\r\n--" << utility::conversions::to_utf8string( m_Boundary ) << "--\r\n"; +} + +} +} +} +} diff --git a/samples/client/petstore/cpprest/MultipartFormData.h b/samples/client/petstore/cpprest/MultipartFormData.h new file mode 100644 index 00000000000..aab22d7467f --- /dev/null +++ b/samples/client/petstore/cpprest/MultipartFormData.h @@ -0,0 +1,51 @@ +/* + * MultipartFormData.h + * + * This class represents a container for building a application/x-multipart-formdata requests. + */ + +#ifndef MultipartFormData_H_ +#define MultipartFormData_H_ + + +#include "IHttpBody.h" +#include "HttpContent.h" + +#include +#include +#include + +#include + + +namespace io { +namespace swagger { +namespace client { +namespace model { + +class MultipartFormData + : public IHttpBody +{ +public: + MultipartFormData(); + MultipartFormData(const utility::string_t& boundary); + virtual ~MultipartFormData(); + + virtual void add( std::shared_ptr content ); + virtual utility::string_t getBoundary(); + virtual std::shared_ptr getContent(const utility::string_t& name) const; + virtual bool hasContent(const utility::string_t& name) const; + virtual void writeTo( std::ostream& target ); + +protected: + std::vector> m_Contents; + utility::string_t m_Boundary; + std::map> m_ContentLookup; +}; + +} +} +} +} + +#endif /* MultipartFormData_H_ */ \ No newline at end of file diff --git a/samples/client/petstore/cpprest/api/PetApi.cpp b/samples/client/petstore/cpprest/api/PetApi.cpp new file mode 100644 index 00000000000..fe197a14b10 --- /dev/null +++ b/samples/client/petstore/cpprest/api/PetApi.cpp @@ -0,0 +1,1000 @@ + +#include "PetApi.h" +#include "IHttpBody.h" +#include "JsonBody.h" +#include "MultipartFormData.h" + +#include + +#include + +namespace io { +namespace swagger { +namespace client { +namespace api { + +using namespace io::swagger::client::model; + +PetApi::PetApi( std::shared_ptr apiClient ) + : m_ApiClient(apiClient) +{ +} + +PetApi::~PetApi() +{ +} + +pplx::task PetApi::addPet(std::shared_ptr body) +{ + + // verify the required parameter 'body' is set + if (body == nullptr) + { + throw ApiException(400, U("Missing required parameter 'body' when calling PetApi->addPet")); + } + + + std::shared_ptr apiConfiguration( m_ApiClient->getConfiguration() ); + utility::string_t path = U("/pet"); + + std::map queryParams; + std::map headerParams( apiConfiguration->getDefaultHeaders() ); + std::map formParams; + std::map> fileParams; + + std::unordered_set responseHttpContentTypes; + responseHttpContentTypes.insert( U("application/xml") ); +responseHttpContentTypes.insert( U("application/json") ); + + utility::string_t responseHttpContentType; + + // use JSON if possible + if ( responseHttpContentTypes.size() == 0 || responseHttpContentTypes.find(U("application/json")) != responseHttpContentTypes.end() ) + { + responseHttpContentType = U("application/json"); + } + // multipart formdata + else if( responseHttpContentTypes.find(U("multipart/form-data")) != responseHttpContentTypes.end() ) + { + responseHttpContentType = U("multipart/form-data"); + } + else + { + throw ApiException(400, U("PetApi->addPet does not produce any supported media type")); + } + + headerParams[U("Accept")] = responseHttpContentType; + + std::unordered_set consumeHttpContentTypes; + consumeHttpContentTypes.insert( U("application/json") ); +consumeHttpContentTypes.insert( U("application/xml") ); + + + + std::shared_ptr httpBody; + utility::string_t requestHttpContentType; + + // use JSON if possible + if ( consumeHttpContentTypes.size() == 0 || consumeHttpContentTypes.find(U("application/json")) != consumeHttpContentTypes.end() ) + { + requestHttpContentType = U("application/json"); + + web::json::value json; + + json = ModelBase::toJson(body); + + + httpBody = std::shared_ptr( new JsonBody( json ) ); + + } + // multipart formdata + else if( consumeHttpContentTypes.find(U("multipart/form-data")) != consumeHttpContentTypes.end() ) + { + requestHttpContentType = U("multipart/form-data"); + + std::shared_ptr multipart(new MultipartFormData); + + if(body.get()) + { + body->toMultipart(multipart, U("body")); + } + + + httpBody = multipart; + requestHttpContentType += U("; boundary=") + multipart->getBoundary(); + } + else + { + throw ApiException(415, U("PetApi->addPet does not consume any supported media type")); + } + + // authentication (petstore_auth) required + // oauth2 authentication is added automatically as part of the http_client_config + + return m_ApiClient->callApi(path, U("POST"), queryParams, httpBody, headerParams, formParams, fileParams, requestHttpContentType) + .then([=](web::http::http_response response) + { + // 1xx - informational : OK + // 2xx - successful : OK + // 3xx - redirection : OK + // 4xx - client error : not OK + // 5xx - client error : not OK + if (response.status_code() >= 400) + { + throw ApiException(response.status_code() + , U("error calling addPet: ") + response.reason_phrase() + , std::make_shared(response.extract_utf8string(true).get())); + } + + // check response content type + if(response.headers().has(U("Content-Type"))) + { + utility::string_t contentType = response.headers()[U("Content-Type")]; + if( contentType.find(responseHttpContentType) == std::string::npos ) + { + throw ApiException(500 + , U("error calling addPet: unexpected response type: ") + contentType + , std::make_shared(response.extract_utf8string(true).get())); + } + } + + return response.extract_string(); + }) + .then([=](utility::string_t response) + { + return void(); + }); +} +pplx::task PetApi::deletePet(int64_t petId, utility::string_t apiKey) +{ + + + std::shared_ptr apiConfiguration( m_ApiClient->getConfiguration() ); + utility::string_t path = U("/pet/{petId}"); + boost::replace_all(path, U("{") U("petId") U("}"), ApiClient::parameterToString(petId)); + + std::map queryParams; + std::map headerParams( apiConfiguration->getDefaultHeaders() ); + std::map formParams; + std::map> fileParams; + + std::unordered_set responseHttpContentTypes; + responseHttpContentTypes.insert( U("application/xml") ); +responseHttpContentTypes.insert( U("application/json") ); + + utility::string_t responseHttpContentType; + + // use JSON if possible + if ( responseHttpContentTypes.size() == 0 || responseHttpContentTypes.find(U("application/json")) != responseHttpContentTypes.end() ) + { + responseHttpContentType = U("application/json"); + } + // multipart formdata + else if( responseHttpContentTypes.find(U("multipart/form-data")) != responseHttpContentTypes.end() ) + { + responseHttpContentType = U("multipart/form-data"); + } + else + { + throw ApiException(400, U("PetApi->deletePet does not produce any supported media type")); + } + + headerParams[U("Accept")] = responseHttpContentType; + + std::unordered_set consumeHttpContentTypes; + + + { + + } + + { + headerParams[U("api_key")] = ApiClient::parameterToString(apiKey); + + } + + + std::shared_ptr httpBody; + utility::string_t requestHttpContentType; + + // use JSON if possible + if ( consumeHttpContentTypes.size() == 0 || consumeHttpContentTypes.find(U("application/json")) != consumeHttpContentTypes.end() ) + { + requestHttpContentType = U("application/json"); + + } + // multipart formdata + else if( consumeHttpContentTypes.find(U("multipart/form-data")) != consumeHttpContentTypes.end() ) + { + requestHttpContentType = U("multipart/form-data"); + + } + else + { + throw ApiException(415, U("PetApi->deletePet does not consume any supported media type")); + } + + // authentication (petstore_auth) required + // oauth2 authentication is added automatically as part of the http_client_config + + return m_ApiClient->callApi(path, U("DELETE"), queryParams, httpBody, headerParams, formParams, fileParams, requestHttpContentType) + .then([=](web::http::http_response response) + { + // 1xx - informational : OK + // 2xx - successful : OK + // 3xx - redirection : OK + // 4xx - client error : not OK + // 5xx - client error : not OK + if (response.status_code() >= 400) + { + throw ApiException(response.status_code() + , U("error calling deletePet: ") + response.reason_phrase() + , std::make_shared(response.extract_utf8string(true).get())); + } + + // check response content type + if(response.headers().has(U("Content-Type"))) + { + utility::string_t contentType = response.headers()[U("Content-Type")]; + if( contentType.find(responseHttpContentType) == std::string::npos ) + { + throw ApiException(500 + , U("error calling deletePet: unexpected response type: ") + contentType + , std::make_shared(response.extract_utf8string(true).get())); + } + } + + return response.extract_string(); + }) + .then([=](utility::string_t response) + { + return void(); + }); +} +pplx::task>> PetApi::findPetsByStatus(std::vector status) +{ + + + std::shared_ptr apiConfiguration( m_ApiClient->getConfiguration() ); + utility::string_t path = U("/pet/findByStatus"); + + std::map queryParams; + std::map headerParams( apiConfiguration->getDefaultHeaders() ); + std::map formParams; + std::map> fileParams; + + std::unordered_set responseHttpContentTypes; + responseHttpContentTypes.insert( U("application/xml") ); +responseHttpContentTypes.insert( U("application/json") ); + + utility::string_t responseHttpContentType; + + // use JSON if possible + if ( responseHttpContentTypes.size() == 0 || responseHttpContentTypes.find(U("application/json")) != responseHttpContentTypes.end() ) + { + responseHttpContentType = U("application/json"); + } + // multipart formdata + else if( responseHttpContentTypes.find(U("multipart/form-data")) != responseHttpContentTypes.end() ) + { + responseHttpContentType = U("multipart/form-data"); + } + else + { + throw ApiException(400, U("PetApi->findPetsByStatus does not produce any supported media type")); + } + + headerParams[U("Accept")] = responseHttpContentType; + + std::unordered_set consumeHttpContentTypes; + + + { + queryParams[U("status")] = ApiClient::parameterToArrayString(status); + + } + + + std::shared_ptr httpBody; + utility::string_t requestHttpContentType; + + // use JSON if possible + if ( consumeHttpContentTypes.size() == 0 || consumeHttpContentTypes.find(U("application/json")) != consumeHttpContentTypes.end() ) + { + requestHttpContentType = U("application/json"); + + } + // multipart formdata + else if( consumeHttpContentTypes.find(U("multipart/form-data")) != consumeHttpContentTypes.end() ) + { + requestHttpContentType = U("multipart/form-data"); + + } + else + { + throw ApiException(415, U("PetApi->findPetsByStatus does not consume any supported media type")); + } + + // authentication (petstore_auth) required + // oauth2 authentication is added automatically as part of the http_client_config + + return m_ApiClient->callApi(path, U("GET"), queryParams, httpBody, headerParams, formParams, fileParams, requestHttpContentType) + .then([=](web::http::http_response response) + { + // 1xx - informational : OK + // 2xx - successful : OK + // 3xx - redirection : OK + // 4xx - client error : not OK + // 5xx - client error : not OK + if (response.status_code() >= 400) + { + throw ApiException(response.status_code() + , U("error calling findPetsByStatus: ") + response.reason_phrase() + , std::make_shared(response.extract_utf8string(true).get())); + } + + // check response content type + if(response.headers().has(U("Content-Type"))) + { + utility::string_t contentType = response.headers()[U("Content-Type")]; + if( contentType.find(responseHttpContentType) == std::string::npos ) + { + throw ApiException(500 + , U("error calling findPetsByStatus: unexpected response type: ") + contentType + , std::make_shared(response.extract_utf8string(true).get())); + } + } + + return response.extract_string(); + }) + .then([=](utility::string_t response) + { + std::vector> result; + + + if(responseHttpContentType == U("application/json")) + { + web::json::value json = web::json::value::parse(response); + + for( auto& item : json.as_array() ) + { + std::shared_ptr itemObj(new Pet()); + itemObj->fromJson(item); + result.push_back(itemObj); + + } + + } + // else if(responseHttpContentType == U("multipart/form-data")) + // { + // TODO multipart response parsing + // } + else + { + throw ApiException(500 + , U("error calling findPetsByStatus: unsupported response type")); + } + + return result; + }); +} +pplx::task>> PetApi::findPetsByTags(std::vector tags) +{ + + + std::shared_ptr apiConfiguration( m_ApiClient->getConfiguration() ); + utility::string_t path = U("/pet/findByTags"); + + std::map queryParams; + std::map headerParams( apiConfiguration->getDefaultHeaders() ); + std::map formParams; + std::map> fileParams; + + std::unordered_set responseHttpContentTypes; + responseHttpContentTypes.insert( U("application/xml") ); +responseHttpContentTypes.insert( U("application/json") ); + + utility::string_t responseHttpContentType; + + // use JSON if possible + if ( responseHttpContentTypes.size() == 0 || responseHttpContentTypes.find(U("application/json")) != responseHttpContentTypes.end() ) + { + responseHttpContentType = U("application/json"); + } + // multipart formdata + else if( responseHttpContentTypes.find(U("multipart/form-data")) != responseHttpContentTypes.end() ) + { + responseHttpContentType = U("multipart/form-data"); + } + else + { + throw ApiException(400, U("PetApi->findPetsByTags does not produce any supported media type")); + } + + headerParams[U("Accept")] = responseHttpContentType; + + std::unordered_set consumeHttpContentTypes; + + + { + queryParams[U("tags")] = ApiClient::parameterToArrayString<>(tags); + + } + + + std::shared_ptr httpBody; + utility::string_t requestHttpContentType; + + // use JSON if possible + if ( consumeHttpContentTypes.size() == 0 || consumeHttpContentTypes.find(U("application/json")) != consumeHttpContentTypes.end() ) + { + requestHttpContentType = U("application/json"); + + } + // multipart formdata + else if( consumeHttpContentTypes.find(U("multipart/form-data")) != consumeHttpContentTypes.end() ) + { + requestHttpContentType = U("multipart/form-data"); + + } + else + { + throw ApiException(415, U("PetApi->findPetsByTags does not consume any supported media type")); + } + + // authentication (petstore_auth) required + // oauth2 authentication is added automatically as part of the http_client_config + + return m_ApiClient->callApi(path, U("GET"), queryParams, httpBody, headerParams, formParams, fileParams, requestHttpContentType) + .then([=](web::http::http_response response) + { + // 1xx - informational : OK + // 2xx - successful : OK + // 3xx - redirection : OK + // 4xx - client error : not OK + // 5xx - client error : not OK + if (response.status_code() >= 400) + { + throw ApiException(response.status_code() + , U("error calling findPetsByTags: ") + response.reason_phrase() + , std::make_shared(response.extract_utf8string(true).get())); + } + + // check response content type + if(response.headers().has(U("Content-Type"))) + { + utility::string_t contentType = response.headers()[U("Content-Type")]; + if( contentType.find(responseHttpContentType) == std::string::npos ) + { + throw ApiException(500 + , U("error calling findPetsByTags: unexpected response type: ") + contentType + , std::make_shared(response.extract_utf8string(true).get())); + } + } + + return response.extract_string(); + }) + .then([=](utility::string_t response) + { + std::vector> result; + + + if(responseHttpContentType == U("application/json")) + { + web::json::value json = web::json::value::parse(response); + + for( auto& item : json.as_array() ) + { + std::shared_ptr itemObj(new Pet()); + itemObj->fromJson(item); + result.push_back(itemObj); + + } + + } + // else if(responseHttpContentType == U("multipart/form-data")) + // { + // TODO multipart response parsing + // } + else + { + throw ApiException(500 + , U("error calling findPetsByStatus: unsupported response type")); + } + + return result; + }); +} +pplx::task> PetApi::getPetById(int64_t petId) +{ + + + std::shared_ptr apiConfiguration( m_ApiClient->getConfiguration() ); + utility::string_t path = U("/pet/{petId}"); + boost::replace_all(path, U("{") U("petId") U("}"), ApiClient::parameterToString(petId)); + + std::map queryParams; + std::map headerParams( apiConfiguration->getDefaultHeaders() ); + std::map formParams; + std::map> fileParams; + + std::unordered_set responseHttpContentTypes; + responseHttpContentTypes.insert( U("application/xml") ); +responseHttpContentTypes.insert( U("application/json") ); + + utility::string_t responseHttpContentType; + + // use JSON if possible + if ( responseHttpContentTypes.size() == 0 || responseHttpContentTypes.find(U("application/json")) != responseHttpContentTypes.end() ) + { + responseHttpContentType = U("application/json"); + } + // multipart formdata + else if( responseHttpContentTypes.find(U("multipart/form-data")) != responseHttpContentTypes.end() ) + { + responseHttpContentType = U("multipart/form-data"); + } + else + { + throw ApiException(400, U("PetApi->getPetById does not produce any supported media type")); + } + + headerParams[U("Accept")] = responseHttpContentType; + + std::unordered_set consumeHttpContentTypes; + + + { + + } + + + std::shared_ptr httpBody; + utility::string_t requestHttpContentType; + + // use JSON if possible + if ( consumeHttpContentTypes.size() == 0 || consumeHttpContentTypes.find(U("application/json")) != consumeHttpContentTypes.end() ) + { + requestHttpContentType = U("application/json"); + + } + // multipart formdata + else if( consumeHttpContentTypes.find(U("multipart/form-data")) != consumeHttpContentTypes.end() ) + { + requestHttpContentType = U("multipart/form-data"); + + } + else + { + throw ApiException(415, U("PetApi->getPetById does not consume any supported media type")); + } + + // authentication (api_key) required + { + utility::string_t apiKey = apiConfiguration->getApiKey(U("api_key")); + if ( apiKey.size() > 0 ) + { + headerParams[U("api_key")] = apiKey; + } + } + + return m_ApiClient->callApi(path, U("GET"), queryParams, httpBody, headerParams, formParams, fileParams, requestHttpContentType) + .then([=](web::http::http_response response) + { + // 1xx - informational : OK + // 2xx - successful : OK + // 3xx - redirection : OK + // 4xx - client error : not OK + // 5xx - client error : not OK + if (response.status_code() >= 400) + { + throw ApiException(response.status_code() + , U("error calling getPetById: ") + response.reason_phrase() + , std::make_shared(response.extract_utf8string(true).get())); + } + + // check response content type + if(response.headers().has(U("Content-Type"))) + { + utility::string_t contentType = response.headers()[U("Content-Type")]; + if( contentType.find(responseHttpContentType) == std::string::npos ) + { + throw ApiException(500 + , U("error calling getPetById: unexpected response type: ") + contentType + , std::make_shared(response.extract_utf8string(true).get())); + } + } + + return response.extract_string(); + }) + .then([=](utility::string_t response) + { + std::shared_ptr result(new Pet()); + + if(responseHttpContentType == U("application/json")) + { + web::json::value json = web::json::value::parse(response); + + result->fromJson(json); + } + // else if(responseHttpContentType == U("multipart/form-data")) + // { + // TODO multipart response parsing + // } + else + { + throw ApiException(500 + , U("error calling findPetsByStatus: unsupported response type")); + } + + return result; + }); +} +pplx::task PetApi::updatePet(std::shared_ptr body) +{ + + // verify the required parameter 'body' is set + if (body == nullptr) + { + throw ApiException(400, U("Missing required parameter 'body' when calling PetApi->updatePet")); + } + + + std::shared_ptr apiConfiguration( m_ApiClient->getConfiguration() ); + utility::string_t path = U("/pet"); + + std::map queryParams; + std::map headerParams( apiConfiguration->getDefaultHeaders() ); + std::map formParams; + std::map> fileParams; + + std::unordered_set responseHttpContentTypes; + responseHttpContentTypes.insert( U("application/xml") ); +responseHttpContentTypes.insert( U("application/json") ); + + utility::string_t responseHttpContentType; + + // use JSON if possible + if ( responseHttpContentTypes.size() == 0 || responseHttpContentTypes.find(U("application/json")) != responseHttpContentTypes.end() ) + { + responseHttpContentType = U("application/json"); + } + // multipart formdata + else if( responseHttpContentTypes.find(U("multipart/form-data")) != responseHttpContentTypes.end() ) + { + responseHttpContentType = U("multipart/form-data"); + } + else + { + throw ApiException(400, U("PetApi->updatePet does not produce any supported media type")); + } + + headerParams[U("Accept")] = responseHttpContentType; + + std::unordered_set consumeHttpContentTypes; + consumeHttpContentTypes.insert( U("application/json") ); +consumeHttpContentTypes.insert( U("application/xml") ); + + + + std::shared_ptr httpBody; + utility::string_t requestHttpContentType; + + // use JSON if possible + if ( consumeHttpContentTypes.size() == 0 || consumeHttpContentTypes.find(U("application/json")) != consumeHttpContentTypes.end() ) + { + requestHttpContentType = U("application/json"); + + web::json::value json; + + json = ModelBase::toJson(body); + + + httpBody = std::shared_ptr( new JsonBody( json ) ); + + } + // multipart formdata + else if( consumeHttpContentTypes.find(U("multipart/form-data")) != consumeHttpContentTypes.end() ) + { + requestHttpContentType = U("multipart/form-data"); + + std::shared_ptr multipart(new MultipartFormData); + + if(body.get()) + { + body->toMultipart(multipart, U("body")); + } + + + httpBody = multipart; + requestHttpContentType += U("; boundary=") + multipart->getBoundary(); + } + else + { + throw ApiException(415, U("PetApi->updatePet does not consume any supported media type")); + } + + // authentication (petstore_auth) required + // oauth2 authentication is added automatically as part of the http_client_config + + return m_ApiClient->callApi(path, U("PUT"), queryParams, httpBody, headerParams, formParams, fileParams, requestHttpContentType) + .then([=](web::http::http_response response) + { + // 1xx - informational : OK + // 2xx - successful : OK + // 3xx - redirection : OK + // 4xx - client error : not OK + // 5xx - client error : not OK + if (response.status_code() >= 400) + { + throw ApiException(response.status_code() + , U("error calling updatePet: ") + response.reason_phrase() + , std::make_shared(response.extract_utf8string(true).get())); + } + + // check response content type + if(response.headers().has(U("Content-Type"))) + { + utility::string_t contentType = response.headers()[U("Content-Type")]; + if( contentType.find(responseHttpContentType) == std::string::npos ) + { + throw ApiException(500 + , U("error calling updatePet: unexpected response type: ") + contentType + , std::make_shared(response.extract_utf8string(true).get())); + } + } + + return response.extract_string(); + }) + .then([=](utility::string_t response) + { + return void(); + }); +} +pplx::task PetApi::updatePetWithForm(int64_t petId, utility::string_t name, utility::string_t status) +{ + + + std::shared_ptr apiConfiguration( m_ApiClient->getConfiguration() ); + utility::string_t path = U("/pet/{petId}"); + boost::replace_all(path, U("{") U("petId") U("}"), ApiClient::parameterToString(petId)); + + std::map queryParams; + std::map headerParams( apiConfiguration->getDefaultHeaders() ); + std::map formParams; + std::map> fileParams; + + std::unordered_set responseHttpContentTypes; + responseHttpContentTypes.insert( U("application/xml") ); +responseHttpContentTypes.insert( U("application/json") ); + + utility::string_t responseHttpContentType; + + // use JSON if possible + if ( responseHttpContentTypes.size() == 0 || responseHttpContentTypes.find(U("application/json")) != responseHttpContentTypes.end() ) + { + responseHttpContentType = U("application/json"); + } + // multipart formdata + else if( responseHttpContentTypes.find(U("multipart/form-data")) != responseHttpContentTypes.end() ) + { + responseHttpContentType = U("multipart/form-data"); + } + else + { + throw ApiException(400, U("PetApi->updatePetWithForm does not produce any supported media type")); + } + + headerParams[U("Accept")] = responseHttpContentType; + + std::unordered_set consumeHttpContentTypes; + consumeHttpContentTypes.insert( U("application/x-www-form-urlencoded") ); + + + { + + } + + { + formParams[ U("name") ] = ApiClient::parameterToString(name); + + } + + { + formParams[ U("status") ] = ApiClient::parameterToString(status); + + } + + + std::shared_ptr httpBody; + utility::string_t requestHttpContentType; + + // use JSON if possible + if ( consumeHttpContentTypes.size() == 0 || consumeHttpContentTypes.find(U("application/json")) != consumeHttpContentTypes.end() ) + { + requestHttpContentType = U("application/json"); + + } + // multipart formdata + else if( consumeHttpContentTypes.find(U("multipart/form-data")) != consumeHttpContentTypes.end() ) + { + requestHttpContentType = U("multipart/form-data"); + + } + else + { + throw ApiException(415, U("PetApi->updatePetWithForm does not consume any supported media type")); + } + + // authentication (petstore_auth) required + // oauth2 authentication is added automatically as part of the http_client_config + + return m_ApiClient->callApi(path, U("POST"), queryParams, httpBody, headerParams, formParams, fileParams, requestHttpContentType) + .then([=](web::http::http_response response) + { + // 1xx - informational : OK + // 2xx - successful : OK + // 3xx - redirection : OK + // 4xx - client error : not OK + // 5xx - client error : not OK + if (response.status_code() >= 400) + { + throw ApiException(response.status_code() + , U("error calling updatePetWithForm: ") + response.reason_phrase() + , std::make_shared(response.extract_utf8string(true).get())); + } + + // check response content type + if(response.headers().has(U("Content-Type"))) + { + utility::string_t contentType = response.headers()[U("Content-Type")]; + if( contentType.find(responseHttpContentType) == std::string::npos ) + { + throw ApiException(500 + , U("error calling updatePetWithForm: unexpected response type: ") + contentType + , std::make_shared(response.extract_utf8string(true).get())); + } + } + + return response.extract_string(); + }) + .then([=](utility::string_t response) + { + return void(); + }); +} +pplx::task> PetApi::uploadFile(int64_t petId, utility::string_t additionalMetadata, std::shared_ptr file) +{ + + + std::shared_ptr apiConfiguration( m_ApiClient->getConfiguration() ); + utility::string_t path = U("/pet/{petId}/uploadImage"); + boost::replace_all(path, U("{") U("petId") U("}"), ApiClient::parameterToString(petId)); + + std::map queryParams; + std::map headerParams( apiConfiguration->getDefaultHeaders() ); + std::map formParams; + std::map> fileParams; + + std::unordered_set responseHttpContentTypes; + responseHttpContentTypes.insert( U("application/json") ); + + utility::string_t responseHttpContentType; + + // use JSON if possible + if ( responseHttpContentTypes.size() == 0 || responseHttpContentTypes.find(U("application/json")) != responseHttpContentTypes.end() ) + { + responseHttpContentType = U("application/json"); + } + // multipart formdata + else if( responseHttpContentTypes.find(U("multipart/form-data")) != responseHttpContentTypes.end() ) + { + responseHttpContentType = U("multipart/form-data"); + } + else + { + throw ApiException(400, U("PetApi->uploadFile does not produce any supported media type")); + } + + headerParams[U("Accept")] = responseHttpContentType; + + std::unordered_set consumeHttpContentTypes; + consumeHttpContentTypes.insert( U("multipart/form-data") ); + + + { + + } + + { + formParams[ U("additionalMetadata") ] = ApiClient::parameterToString(additionalMetadata); + + } + if (file != nullptr) + { + fileParams[ U("file") ] = file; + + } + + + std::shared_ptr httpBody; + utility::string_t requestHttpContentType; + + // use JSON if possible + if ( consumeHttpContentTypes.size() == 0 || consumeHttpContentTypes.find(U("application/json")) != consumeHttpContentTypes.end() ) + { + requestHttpContentType = U("application/json"); + + } + // multipart formdata + else if( consumeHttpContentTypes.find(U("multipart/form-data")) != consumeHttpContentTypes.end() ) + { + requestHttpContentType = U("multipart/form-data"); + + } + else + { + throw ApiException(415, U("PetApi->uploadFile does not consume any supported media type")); + } + + // authentication (petstore_auth) required + // oauth2 authentication is added automatically as part of the http_client_config + + return m_ApiClient->callApi(path, U("POST"), queryParams, httpBody, headerParams, formParams, fileParams, requestHttpContentType) + .then([=](web::http::http_response response) + { + // 1xx - informational : OK + // 2xx - successful : OK + // 3xx - redirection : OK + // 4xx - client error : not OK + // 5xx - client error : not OK + if (response.status_code() >= 400) + { + throw ApiException(response.status_code() + , U("error calling uploadFile: ") + response.reason_phrase() + , std::make_shared(response.extract_utf8string(true).get())); + } + + // check response content type + if(response.headers().has(U("Content-Type"))) + { + utility::string_t contentType = response.headers()[U("Content-Type")]; + if( contentType.find(responseHttpContentType) == std::string::npos ) + { + throw ApiException(500 + , U("error calling uploadFile: unexpected response type: ") + contentType + , std::make_shared(response.extract_utf8string(true).get())); + } + } + + return response.extract_string(); + }) + .then([=](utility::string_t response) + { + std::shared_ptr result(new ApiResponse()); + + if(responseHttpContentType == U("application/json")) + { + web::json::value json = web::json::value::parse(response); + + result->fromJson(json); + } + // else if(responseHttpContentType == U("multipart/form-data")) + // { + // TODO multipart response parsing + // } + else + { + throw ApiException(500 + , U("error calling findPetsByStatus: unsupported response type")); + } + + return result; + }); +} + +} +} +} +} + diff --git a/samples/client/petstore/cpprest/api/PetApi.h b/samples/client/petstore/cpprest/api/PetApi.h new file mode 100644 index 00000000000..7aa37d09701 --- /dev/null +++ b/samples/client/petstore/cpprest/api/PetApi.h @@ -0,0 +1,105 @@ +/* + * PetApi.h + * + * + */ + +#ifndef PetApi_H_ +#define PetApi_H_ + + +#include "ApiClient.h" + +#include "Pet.h" +#include +#include "ApiResponse.h" +#include "HttpContent.h" + +namespace io { +namespace swagger { +namespace client { +namespace api { + +using namespace io::swagger::client::model; + +class PetApi +{ +public: + PetApi( std::shared_ptr apiClient ); + virtual ~PetApi(); + /// + /// Add a new pet to the store + /// + /// + /// + /// + /// Pet object that needs to be added to the store + pplx::task addPet(std::shared_ptr body); + /// + /// Deletes a pet + /// + /// + /// + /// + /// Pet id to delete/// (optional) + pplx::task deletePet(int64_t petId, utility::string_t apiKey); + /// + /// Finds Pets by status + /// + /// + /// Multiple status values can be provided with comma separated strings + /// + /// Status values that need to be considered for filter + pplx::task>> findPetsByStatus(std::vector status); + /// + /// Finds Pets by tags + /// + /// + /// Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. + /// + /// Tags to filter by + pplx::task>> findPetsByTags(std::vector tags); + /// + /// Find pet by ID + /// + /// + /// Returns a single pet + /// + /// ID of pet to return + pplx::task> getPetById(int64_t petId); + /// + /// Update an existing pet + /// + /// + /// + /// + /// Pet object that needs to be added to the store + pplx::task updatePet(std::shared_ptr body); + /// + /// Updates a pet in the store with form data + /// + /// + /// + /// + /// ID of pet that needs to be updated/// Updated name of the pet (optional)/// Updated status of the pet (optional) + pplx::task updatePetWithForm(int64_t petId, utility::string_t name, utility::string_t status); + /// + /// uploads an image + /// + /// + /// + /// + /// ID of pet to update/// Additional data to pass to server (optional)/// file to upload (optional) + pplx::task> uploadFile(int64_t petId, utility::string_t additionalMetadata, std::shared_ptr file); + +protected: + std::shared_ptr m_ApiClient; +}; + +} +} +} +} + +#endif /* PetApi_H_ */ + diff --git a/samples/client/petstore/cpprest/api/StoreApi.cpp b/samples/client/petstore/cpprest/api/StoreApi.cpp new file mode 100644 index 00000000000..ddb7e5b0067 --- /dev/null +++ b/samples/client/petstore/cpprest/api/StoreApi.cpp @@ -0,0 +1,508 @@ + +#include "StoreApi.h" +#include "IHttpBody.h" +#include "JsonBody.h" +#include "MultipartFormData.h" + +#include + +#include + +namespace io { +namespace swagger { +namespace client { +namespace api { + +using namespace io::swagger::client::model; + +StoreApi::StoreApi( std::shared_ptr apiClient ) + : m_ApiClient(apiClient) +{ +} + +StoreApi::~StoreApi() +{ +} + +pplx::task StoreApi::deleteOrder(utility::string_t orderId) +{ + + + std::shared_ptr apiConfiguration( m_ApiClient->getConfiguration() ); + utility::string_t path = U("/store/order/{orderId}"); + boost::replace_all(path, U("{") U("orderId") U("}"), ApiClient::parameterToString(orderId)); + + std::map queryParams; + std::map headerParams( apiConfiguration->getDefaultHeaders() ); + std::map formParams; + std::map> fileParams; + + std::unordered_set responseHttpContentTypes; + responseHttpContentTypes.insert( U("application/xml") ); +responseHttpContentTypes.insert( U("application/json") ); + + utility::string_t responseHttpContentType; + + // use JSON if possible + if ( responseHttpContentTypes.size() == 0 || responseHttpContentTypes.find(U("application/json")) != responseHttpContentTypes.end() ) + { + responseHttpContentType = U("application/json"); + } + // multipart formdata + else if( responseHttpContentTypes.find(U("multipart/form-data")) != responseHttpContentTypes.end() ) + { + responseHttpContentType = U("multipart/form-data"); + } + else + { + throw ApiException(400, U("StoreApi->deleteOrder does not produce any supported media type")); + } + + headerParams[U("Accept")] = responseHttpContentType; + + std::unordered_set consumeHttpContentTypes; + + + { + + } + + + std::shared_ptr httpBody; + utility::string_t requestHttpContentType; + + // use JSON if possible + if ( consumeHttpContentTypes.size() == 0 || consumeHttpContentTypes.find(U("application/json")) != consumeHttpContentTypes.end() ) + { + requestHttpContentType = U("application/json"); + + } + // multipart formdata + else if( consumeHttpContentTypes.find(U("multipart/form-data")) != consumeHttpContentTypes.end() ) + { + requestHttpContentType = U("multipart/form-data"); + + } + else + { + throw ApiException(415, U("StoreApi->deleteOrder does not consume any supported media type")); + } + + + return m_ApiClient->callApi(path, U("DELETE"), queryParams, httpBody, headerParams, formParams, fileParams, requestHttpContentType) + .then([=](web::http::http_response response) + { + // 1xx - informational : OK + // 2xx - successful : OK + // 3xx - redirection : OK + // 4xx - client error : not OK + // 5xx - client error : not OK + if (response.status_code() >= 400) + { + throw ApiException(response.status_code() + , U("error calling deleteOrder: ") + response.reason_phrase() + , std::make_shared(response.extract_utf8string(true).get())); + } + + // check response content type + if(response.headers().has(U("Content-Type"))) + { + utility::string_t contentType = response.headers()[U("Content-Type")]; + if( contentType.find(responseHttpContentType) == std::string::npos ) + { + throw ApiException(500 + , U("error calling deleteOrder: unexpected response type: ") + contentType + , std::make_shared(response.extract_utf8string(true).get())); + } + } + + return response.extract_string(); + }) + .then([=](utility::string_t response) + { + return void(); + }); +} +pplx::task> StoreApi::getInventory() +{ + + + std::shared_ptr apiConfiguration( m_ApiClient->getConfiguration() ); + utility::string_t path = U("/store/inventory"); + + std::map queryParams; + std::map headerParams( apiConfiguration->getDefaultHeaders() ); + std::map formParams; + std::map> fileParams; + + std::unordered_set responseHttpContentTypes; + responseHttpContentTypes.insert( U("application/json") ); + + utility::string_t responseHttpContentType; + + // use JSON if possible + if ( responseHttpContentTypes.size() == 0 || responseHttpContentTypes.find(U("application/json")) != responseHttpContentTypes.end() ) + { + responseHttpContentType = U("application/json"); + } + // multipart formdata + else if( responseHttpContentTypes.find(U("multipart/form-data")) != responseHttpContentTypes.end() ) + { + responseHttpContentType = U("multipart/form-data"); + } + else + { + throw ApiException(400, U("StoreApi->getInventory does not produce any supported media type")); + } + + headerParams[U("Accept")] = responseHttpContentType; + + std::unordered_set consumeHttpContentTypes; + + + + std::shared_ptr httpBody; + utility::string_t requestHttpContentType; + + // use JSON if possible + if ( consumeHttpContentTypes.size() == 0 || consumeHttpContentTypes.find(U("application/json")) != consumeHttpContentTypes.end() ) + { + requestHttpContentType = U("application/json"); + + } + // multipart formdata + else if( consumeHttpContentTypes.find(U("multipart/form-data")) != consumeHttpContentTypes.end() ) + { + requestHttpContentType = U("multipart/form-data"); + + } + else + { + throw ApiException(415, U("StoreApi->getInventory does not consume any supported media type")); + } + + // authentication (api_key) required + { + utility::string_t apiKey = apiConfiguration->getApiKey(U("api_key")); + if ( apiKey.size() > 0 ) + { + headerParams[U("api_key")] = apiKey; + } + } + + return m_ApiClient->callApi(path, U("GET"), queryParams, httpBody, headerParams, formParams, fileParams, requestHttpContentType) + .then([=](web::http::http_response response) + { + // 1xx - informational : OK + // 2xx - successful : OK + // 3xx - redirection : OK + // 4xx - client error : not OK + // 5xx - client error : not OK + if (response.status_code() >= 400) + { + throw ApiException(response.status_code() + , U("error calling getInventory: ") + response.reason_phrase() + , std::make_shared(response.extract_utf8string(true).get())); + } + + // check response content type + if(response.headers().has(U("Content-Type"))) + { + utility::string_t contentType = response.headers()[U("Content-Type")]; + if( contentType.find(responseHttpContentType) == std::string::npos ) + { + throw ApiException(500 + , U("error calling getInventory: unexpected response type: ") + contentType + , std::make_shared(response.extract_utf8string(true).get())); + } + } + + return response.extract_string(); + }) + .then([=](utility::string_t response) + { + std::map result; + + + if(responseHttpContentType == U("application/json")) + { + web::json::value json = web::json::value::parse(response); + + for( auto& item : json.as_object() ) + { + result[item.first] = ModelBase::int32_tFromJson(item.second); + + } + + } + // else if(responseHttpContentType == U("multipart/form-data")) + // { + // TODO multipart response parsing + // } + else + { + throw ApiException(500 + , U("error calling findPetsByStatus: unsupported response type")); + } + + return result; + }); +} +pplx::task> StoreApi::getOrderById(int64_t orderId) +{ + + + std::shared_ptr apiConfiguration( m_ApiClient->getConfiguration() ); + utility::string_t path = U("/store/order/{orderId}"); + boost::replace_all(path, U("{") U("orderId") U("}"), ApiClient::parameterToString(orderId)); + + std::map queryParams; + std::map headerParams( apiConfiguration->getDefaultHeaders() ); + std::map formParams; + std::map> fileParams; + + std::unordered_set responseHttpContentTypes; + responseHttpContentTypes.insert( U("application/xml") ); +responseHttpContentTypes.insert( U("application/json") ); + + utility::string_t responseHttpContentType; + + // use JSON if possible + if ( responseHttpContentTypes.size() == 0 || responseHttpContentTypes.find(U("application/json")) != responseHttpContentTypes.end() ) + { + responseHttpContentType = U("application/json"); + } + // multipart formdata + else if( responseHttpContentTypes.find(U("multipart/form-data")) != responseHttpContentTypes.end() ) + { + responseHttpContentType = U("multipart/form-data"); + } + else + { + throw ApiException(400, U("StoreApi->getOrderById does not produce any supported media type")); + } + + headerParams[U("Accept")] = responseHttpContentType; + + std::unordered_set consumeHttpContentTypes; + + + { + + } + + + std::shared_ptr httpBody; + utility::string_t requestHttpContentType; + + // use JSON if possible + if ( consumeHttpContentTypes.size() == 0 || consumeHttpContentTypes.find(U("application/json")) != consumeHttpContentTypes.end() ) + { + requestHttpContentType = U("application/json"); + + } + // multipart formdata + else if( consumeHttpContentTypes.find(U("multipart/form-data")) != consumeHttpContentTypes.end() ) + { + requestHttpContentType = U("multipart/form-data"); + + } + else + { + throw ApiException(415, U("StoreApi->getOrderById does not consume any supported media type")); + } + + + return m_ApiClient->callApi(path, U("GET"), queryParams, httpBody, headerParams, formParams, fileParams, requestHttpContentType) + .then([=](web::http::http_response response) + { + // 1xx - informational : OK + // 2xx - successful : OK + // 3xx - redirection : OK + // 4xx - client error : not OK + // 5xx - client error : not OK + if (response.status_code() >= 400) + { + throw ApiException(response.status_code() + , U("error calling getOrderById: ") + response.reason_phrase() + , std::make_shared(response.extract_utf8string(true).get())); + } + + // check response content type + if(response.headers().has(U("Content-Type"))) + { + utility::string_t contentType = response.headers()[U("Content-Type")]; + if( contentType.find(responseHttpContentType) == std::string::npos ) + { + throw ApiException(500 + , U("error calling getOrderById: unexpected response type: ") + contentType + , std::make_shared(response.extract_utf8string(true).get())); + } + } + + return response.extract_string(); + }) + .then([=](utility::string_t response) + { + std::shared_ptr result(new Order()); + + if(responseHttpContentType == U("application/json")) + { + web::json::value json = web::json::value::parse(response); + + result->fromJson(json); + } + // else if(responseHttpContentType == U("multipart/form-data")) + // { + // TODO multipart response parsing + // } + else + { + throw ApiException(500 + , U("error calling findPetsByStatus: unsupported response type")); + } + + return result; + }); +} +pplx::task> StoreApi::placeOrder(std::shared_ptr body) +{ + + // verify the required parameter 'body' is set + if (body == nullptr) + { + throw ApiException(400, U("Missing required parameter 'body' when calling StoreApi->placeOrder")); + } + + + std::shared_ptr apiConfiguration( m_ApiClient->getConfiguration() ); + utility::string_t path = U("/store/order"); + + std::map queryParams; + std::map headerParams( apiConfiguration->getDefaultHeaders() ); + std::map formParams; + std::map> fileParams; + + std::unordered_set responseHttpContentTypes; + responseHttpContentTypes.insert( U("application/xml") ); +responseHttpContentTypes.insert( U("application/json") ); + + utility::string_t responseHttpContentType; + + // use JSON if possible + if ( responseHttpContentTypes.size() == 0 || responseHttpContentTypes.find(U("application/json")) != responseHttpContentTypes.end() ) + { + responseHttpContentType = U("application/json"); + } + // multipart formdata + else if( responseHttpContentTypes.find(U("multipart/form-data")) != responseHttpContentTypes.end() ) + { + responseHttpContentType = U("multipart/form-data"); + } + else + { + throw ApiException(400, U("StoreApi->placeOrder does not produce any supported media type")); + } + + headerParams[U("Accept")] = responseHttpContentType; + + std::unordered_set consumeHttpContentTypes; + + + + std::shared_ptr httpBody; + utility::string_t requestHttpContentType; + + // use JSON if possible + if ( consumeHttpContentTypes.size() == 0 || consumeHttpContentTypes.find(U("application/json")) != consumeHttpContentTypes.end() ) + { + requestHttpContentType = U("application/json"); + + web::json::value json; + + json = ModelBase::toJson(body); + + + httpBody = std::shared_ptr( new JsonBody( json ) ); + + } + // multipart formdata + else if( consumeHttpContentTypes.find(U("multipart/form-data")) != consumeHttpContentTypes.end() ) + { + requestHttpContentType = U("multipart/form-data"); + + std::shared_ptr multipart(new MultipartFormData); + + if(body.get()) + { + body->toMultipart(multipart, U("body")); + } + + + httpBody = multipart; + requestHttpContentType += U("; boundary=") + multipart->getBoundary(); + } + else + { + throw ApiException(415, U("StoreApi->placeOrder does not consume any supported media type")); + } + + + return m_ApiClient->callApi(path, U("POST"), queryParams, httpBody, headerParams, formParams, fileParams, requestHttpContentType) + .then([=](web::http::http_response response) + { + // 1xx - informational : OK + // 2xx - successful : OK + // 3xx - redirection : OK + // 4xx - client error : not OK + // 5xx - client error : not OK + if (response.status_code() >= 400) + { + throw ApiException(response.status_code() + , U("error calling placeOrder: ") + response.reason_phrase() + , std::make_shared(response.extract_utf8string(true).get())); + } + + // check response content type + if(response.headers().has(U("Content-Type"))) + { + utility::string_t contentType = response.headers()[U("Content-Type")]; + if( contentType.find(responseHttpContentType) == std::string::npos ) + { + throw ApiException(500 + , U("error calling placeOrder: unexpected response type: ") + contentType + , std::make_shared(response.extract_utf8string(true).get())); + } + } + + return response.extract_string(); + }) + .then([=](utility::string_t response) + { + std::shared_ptr result(new Order()); + + if(responseHttpContentType == U("application/json")) + { + web::json::value json = web::json::value::parse(response); + + result->fromJson(json); + } + // else if(responseHttpContentType == U("multipart/form-data")) + // { + // TODO multipart response parsing + // } + else + { + throw ApiException(500 + , U("error calling findPetsByStatus: unsupported response type")); + } + + return result; + }); +} + +} +} +} +} + diff --git a/samples/client/petstore/cpprest/api/StoreApi.h b/samples/client/petstore/cpprest/api/StoreApi.h new file mode 100644 index 00000000000..c076a255359 --- /dev/null +++ b/samples/client/petstore/cpprest/api/StoreApi.h @@ -0,0 +1,72 @@ +/* + * StoreApi.h + * + * + */ + +#ifndef StoreApi_H_ +#define StoreApi_H_ + + +#include "ApiClient.h" + +#include +#include +#include "Order.h" + +namespace io { +namespace swagger { +namespace client { +namespace api { + +using namespace io::swagger::client::model; + +class StoreApi +{ +public: + StoreApi( std::shared_ptr apiClient ); + virtual ~StoreApi(); + /// + /// Delete purchase order by ID + /// + /// + /// For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors + /// + /// ID of the order that needs to be deleted + pplx::task deleteOrder(utility::string_t orderId); + /// + /// Returns pet inventories by status + /// + /// + /// Returns a map of status codes to quantities + /// + + pplx::task> getInventory(); + /// + /// Find purchase order by ID + /// + /// + /// For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions + /// + /// ID of pet that needs to be fetched + pplx::task> getOrderById(int64_t orderId); + /// + /// Place an order for a pet + /// + /// + /// + /// + /// order placed for purchasing the pet + pplx::task> placeOrder(std::shared_ptr body); + +protected: + std::shared_ptr m_ApiClient; +}; + +} +} +} +} + +#endif /* StoreApi_H_ */ + diff --git a/samples/client/petstore/cpprest/api/UserApi.cpp b/samples/client/petstore/cpprest/api/UserApi.cpp new file mode 100644 index 00000000000..e17a1acf42b --- /dev/null +++ b/samples/client/petstore/cpprest/api/UserApi.cpp @@ -0,0 +1,954 @@ + +#include "UserApi.h" +#include "IHttpBody.h" +#include "JsonBody.h" +#include "MultipartFormData.h" + +#include + +#include + +namespace io { +namespace swagger { +namespace client { +namespace api { + +using namespace io::swagger::client::model; + +UserApi::UserApi( std::shared_ptr apiClient ) + : m_ApiClient(apiClient) +{ +} + +UserApi::~UserApi() +{ +} + +pplx::task UserApi::createUser(std::shared_ptr body) +{ + + // verify the required parameter 'body' is set + if (body == nullptr) + { + throw ApiException(400, U("Missing required parameter 'body' when calling UserApi->createUser")); + } + + + std::shared_ptr apiConfiguration( m_ApiClient->getConfiguration() ); + utility::string_t path = U("/user"); + + std::map queryParams; + std::map headerParams( apiConfiguration->getDefaultHeaders() ); + std::map formParams; + std::map> fileParams; + + std::unordered_set responseHttpContentTypes; + responseHttpContentTypes.insert( U("application/xml") ); +responseHttpContentTypes.insert( U("application/json") ); + + utility::string_t responseHttpContentType; + + // use JSON if possible + if ( responseHttpContentTypes.size() == 0 || responseHttpContentTypes.find(U("application/json")) != responseHttpContentTypes.end() ) + { + responseHttpContentType = U("application/json"); + } + // multipart formdata + else if( responseHttpContentTypes.find(U("multipart/form-data")) != responseHttpContentTypes.end() ) + { + responseHttpContentType = U("multipart/form-data"); + } + else + { + throw ApiException(400, U("UserApi->createUser does not produce any supported media type")); + } + + headerParams[U("Accept")] = responseHttpContentType; + + std::unordered_set consumeHttpContentTypes; + + + + std::shared_ptr httpBody; + utility::string_t requestHttpContentType; + + // use JSON if possible + if ( consumeHttpContentTypes.size() == 0 || consumeHttpContentTypes.find(U("application/json")) != consumeHttpContentTypes.end() ) + { + requestHttpContentType = U("application/json"); + + web::json::value json; + + json = ModelBase::toJson(body); + + + httpBody = std::shared_ptr( new JsonBody( json ) ); + + } + // multipart formdata + else if( consumeHttpContentTypes.find(U("multipart/form-data")) != consumeHttpContentTypes.end() ) + { + requestHttpContentType = U("multipart/form-data"); + + std::shared_ptr multipart(new MultipartFormData); + + if(body.get()) + { + body->toMultipart(multipart, U("body")); + } + + + httpBody = multipart; + requestHttpContentType += U("; boundary=") + multipart->getBoundary(); + } + else + { + throw ApiException(415, U("UserApi->createUser does not consume any supported media type")); + } + + + return m_ApiClient->callApi(path, U("POST"), queryParams, httpBody, headerParams, formParams, fileParams, requestHttpContentType) + .then([=](web::http::http_response response) + { + // 1xx - informational : OK + // 2xx - successful : OK + // 3xx - redirection : OK + // 4xx - client error : not OK + // 5xx - client error : not OK + if (response.status_code() >= 400) + { + throw ApiException(response.status_code() + , U("error calling createUser: ") + response.reason_phrase() + , std::make_shared(response.extract_utf8string(true).get())); + } + + // check response content type + if(response.headers().has(U("Content-Type"))) + { + utility::string_t contentType = response.headers()[U("Content-Type")]; + if( contentType.find(responseHttpContentType) == std::string::npos ) + { + throw ApiException(500 + , U("error calling createUser: unexpected response type: ") + contentType + , std::make_shared(response.extract_utf8string(true).get())); + } + } + + return response.extract_string(); + }) + .then([=](utility::string_t response) + { + return void(); + }); +} +pplx::task UserApi::createUsersWithArrayInput(std::vector> body) +{ + + + std::shared_ptr apiConfiguration( m_ApiClient->getConfiguration() ); + utility::string_t path = U("/user/createWithArray"); + + std::map queryParams; + std::map headerParams( apiConfiguration->getDefaultHeaders() ); + std::map formParams; + std::map> fileParams; + + std::unordered_set responseHttpContentTypes; + responseHttpContentTypes.insert( U("application/xml") ); +responseHttpContentTypes.insert( U("application/json") ); + + utility::string_t responseHttpContentType; + + // use JSON if possible + if ( responseHttpContentTypes.size() == 0 || responseHttpContentTypes.find(U("application/json")) != responseHttpContentTypes.end() ) + { + responseHttpContentType = U("application/json"); + } + // multipart formdata + else if( responseHttpContentTypes.find(U("multipart/form-data")) != responseHttpContentTypes.end() ) + { + responseHttpContentType = U("multipart/form-data"); + } + else + { + throw ApiException(400, U("UserApi->createUsersWithArrayInput does not produce any supported media type")); + } + + headerParams[U("Accept")] = responseHttpContentType; + + std::unordered_set consumeHttpContentTypes; + + + + std::shared_ptr httpBody; + utility::string_t requestHttpContentType; + + // use JSON if possible + if ( consumeHttpContentTypes.size() == 0 || consumeHttpContentTypes.find(U("application/json")) != consumeHttpContentTypes.end() ) + { + requestHttpContentType = U("application/json"); + + web::json::value json; + + + { + std::vector jsonArray; + for( auto& item : body ) + { + jsonArray.push_back( item.get() ? item->toJson() : web::json::value::null() ); + + } + json = web::json::value::array(jsonArray); + } + + + httpBody = std::shared_ptr( new JsonBody( json ) ); + + } + // multipart formdata + else if( consumeHttpContentTypes.find(U("multipart/form-data")) != consumeHttpContentTypes.end() ) + { + requestHttpContentType = U("multipart/form-data"); + + std::shared_ptr multipart(new MultipartFormData); + + { + std::vector jsonArray; + for( auto& item : body ) + { + jsonArray.push_back( item.get() ? item->toJson() : web::json::value::null() ); + + } + multipart->add(ModelBase::toHttpContent(U("body"), web::json::value::array(jsonArray), U("application/json"))); + } + + + httpBody = multipart; + requestHttpContentType += U("; boundary=") + multipart->getBoundary(); + } + else + { + throw ApiException(415, U("UserApi->createUsersWithArrayInput does not consume any supported media type")); + } + + + return m_ApiClient->callApi(path, U("POST"), queryParams, httpBody, headerParams, formParams, fileParams, requestHttpContentType) + .then([=](web::http::http_response response) + { + // 1xx - informational : OK + // 2xx - successful : OK + // 3xx - redirection : OK + // 4xx - client error : not OK + // 5xx - client error : not OK + if (response.status_code() >= 400) + { + throw ApiException(response.status_code() + , U("error calling createUsersWithArrayInput: ") + response.reason_phrase() + , std::make_shared(response.extract_utf8string(true).get())); + } + + // check response content type + if(response.headers().has(U("Content-Type"))) + { + utility::string_t contentType = response.headers()[U("Content-Type")]; + if( contentType.find(responseHttpContentType) == std::string::npos ) + { + throw ApiException(500 + , U("error calling createUsersWithArrayInput: unexpected response type: ") + contentType + , std::make_shared(response.extract_utf8string(true).get())); + } + } + + return response.extract_string(); + }) + .then([=](utility::string_t response) + { + return void(); + }); +} +pplx::task UserApi::createUsersWithListInput(std::vector> body) +{ + + + std::shared_ptr apiConfiguration( m_ApiClient->getConfiguration() ); + utility::string_t path = U("/user/createWithList"); + + std::map queryParams; + std::map headerParams( apiConfiguration->getDefaultHeaders() ); + std::map formParams; + std::map> fileParams; + + std::unordered_set responseHttpContentTypes; + responseHttpContentTypes.insert( U("application/xml") ); +responseHttpContentTypes.insert( U("application/json") ); + + utility::string_t responseHttpContentType; + + // use JSON if possible + if ( responseHttpContentTypes.size() == 0 || responseHttpContentTypes.find(U("application/json")) != responseHttpContentTypes.end() ) + { + responseHttpContentType = U("application/json"); + } + // multipart formdata + else if( responseHttpContentTypes.find(U("multipart/form-data")) != responseHttpContentTypes.end() ) + { + responseHttpContentType = U("multipart/form-data"); + } + else + { + throw ApiException(400, U("UserApi->createUsersWithListInput does not produce any supported media type")); + } + + headerParams[U("Accept")] = responseHttpContentType; + + std::unordered_set consumeHttpContentTypes; + + + + std::shared_ptr httpBody; + utility::string_t requestHttpContentType; + + // use JSON if possible + if ( consumeHttpContentTypes.size() == 0 || consumeHttpContentTypes.find(U("application/json")) != consumeHttpContentTypes.end() ) + { + requestHttpContentType = U("application/json"); + + web::json::value json; + + + { + std::vector jsonArray; + for( auto& item : body ) + { + jsonArray.push_back( item.get() ? item->toJson() : web::json::value::null() ); + + } + json = web::json::value::array(jsonArray); + } + + + httpBody = std::shared_ptr( new JsonBody( json ) ); + + } + // multipart formdata + else if( consumeHttpContentTypes.find(U("multipart/form-data")) != consumeHttpContentTypes.end() ) + { + requestHttpContentType = U("multipart/form-data"); + + std::shared_ptr multipart(new MultipartFormData); + + { + std::vector jsonArray; + for( auto& item : body ) + { + jsonArray.push_back( item.get() ? item->toJson() : web::json::value::null() ); + + } + multipart->add(ModelBase::toHttpContent(U("body"), web::json::value::array(jsonArray), U("application/json"))); + } + + + httpBody = multipart; + requestHttpContentType += U("; boundary=") + multipart->getBoundary(); + } + else + { + throw ApiException(415, U("UserApi->createUsersWithListInput does not consume any supported media type")); + } + + + return m_ApiClient->callApi(path, U("POST"), queryParams, httpBody, headerParams, formParams, fileParams, requestHttpContentType) + .then([=](web::http::http_response response) + { + // 1xx - informational : OK + // 2xx - successful : OK + // 3xx - redirection : OK + // 4xx - client error : not OK + // 5xx - client error : not OK + if (response.status_code() >= 400) + { + throw ApiException(response.status_code() + , U("error calling createUsersWithListInput: ") + response.reason_phrase() + , std::make_shared(response.extract_utf8string(true).get())); + } + + // check response content type + if(response.headers().has(U("Content-Type"))) + { + utility::string_t contentType = response.headers()[U("Content-Type")]; + if( contentType.find(responseHttpContentType) == std::string::npos ) + { + throw ApiException(500 + , U("error calling createUsersWithListInput: unexpected response type: ") + contentType + , std::make_shared(response.extract_utf8string(true).get())); + } + } + + return response.extract_string(); + }) + .then([=](utility::string_t response) + { + return void(); + }); +} +pplx::task UserApi::deleteUser(utility::string_t username) +{ + + + std::shared_ptr apiConfiguration( m_ApiClient->getConfiguration() ); + utility::string_t path = U("/user/{username}"); + boost::replace_all(path, U("{") U("username") U("}"), ApiClient::parameterToString(username)); + + std::map queryParams; + std::map headerParams( apiConfiguration->getDefaultHeaders() ); + std::map formParams; + std::map> fileParams; + + std::unordered_set responseHttpContentTypes; + responseHttpContentTypes.insert( U("application/xml") ); +responseHttpContentTypes.insert( U("application/json") ); + + utility::string_t responseHttpContentType; + + // use JSON if possible + if ( responseHttpContentTypes.size() == 0 || responseHttpContentTypes.find(U("application/json")) != responseHttpContentTypes.end() ) + { + responseHttpContentType = U("application/json"); + } + // multipart formdata + else if( responseHttpContentTypes.find(U("multipart/form-data")) != responseHttpContentTypes.end() ) + { + responseHttpContentType = U("multipart/form-data"); + } + else + { + throw ApiException(400, U("UserApi->deleteUser does not produce any supported media type")); + } + + headerParams[U("Accept")] = responseHttpContentType; + + std::unordered_set consumeHttpContentTypes; + + + { + + } + + + std::shared_ptr httpBody; + utility::string_t requestHttpContentType; + + // use JSON if possible + if ( consumeHttpContentTypes.size() == 0 || consumeHttpContentTypes.find(U("application/json")) != consumeHttpContentTypes.end() ) + { + requestHttpContentType = U("application/json"); + + } + // multipart formdata + else if( consumeHttpContentTypes.find(U("multipart/form-data")) != consumeHttpContentTypes.end() ) + { + requestHttpContentType = U("multipart/form-data"); + + } + else + { + throw ApiException(415, U("UserApi->deleteUser does not consume any supported media type")); + } + + + return m_ApiClient->callApi(path, U("DELETE"), queryParams, httpBody, headerParams, formParams, fileParams, requestHttpContentType) + .then([=](web::http::http_response response) + { + // 1xx - informational : OK + // 2xx - successful : OK + // 3xx - redirection : OK + // 4xx - client error : not OK + // 5xx - client error : not OK + if (response.status_code() >= 400) + { + throw ApiException(response.status_code() + , U("error calling deleteUser: ") + response.reason_phrase() + , std::make_shared(response.extract_utf8string(true).get())); + } + + // check response content type + if(response.headers().has(U("Content-Type"))) + { + utility::string_t contentType = response.headers()[U("Content-Type")]; + if( contentType.find(responseHttpContentType) == std::string::npos ) + { + throw ApiException(500 + , U("error calling deleteUser: unexpected response type: ") + contentType + , std::make_shared(response.extract_utf8string(true).get())); + } + } + + return response.extract_string(); + }) + .then([=](utility::string_t response) + { + return void(); + }); +} +pplx::task> UserApi::getUserByName(utility::string_t username) +{ + + + std::shared_ptr apiConfiguration( m_ApiClient->getConfiguration() ); + utility::string_t path = U("/user/{username}"); + boost::replace_all(path, U("{") U("username") U("}"), ApiClient::parameterToString(username)); + + std::map queryParams; + std::map headerParams( apiConfiguration->getDefaultHeaders() ); + std::map formParams; + std::map> fileParams; + + std::unordered_set responseHttpContentTypes; + responseHttpContentTypes.insert( U("application/xml") ); +responseHttpContentTypes.insert( U("application/json") ); + + utility::string_t responseHttpContentType; + + // use JSON if possible + if ( responseHttpContentTypes.size() == 0 || responseHttpContentTypes.find(U("application/json")) != responseHttpContentTypes.end() ) + { + responseHttpContentType = U("application/json"); + } + // multipart formdata + else if( responseHttpContentTypes.find(U("multipart/form-data")) != responseHttpContentTypes.end() ) + { + responseHttpContentType = U("multipart/form-data"); + } + else + { + throw ApiException(400, U("UserApi->getUserByName does not produce any supported media type")); + } + + headerParams[U("Accept")] = responseHttpContentType; + + std::unordered_set consumeHttpContentTypes; + + + { + + } + + + std::shared_ptr httpBody; + utility::string_t requestHttpContentType; + + // use JSON if possible + if ( consumeHttpContentTypes.size() == 0 || consumeHttpContentTypes.find(U("application/json")) != consumeHttpContentTypes.end() ) + { + requestHttpContentType = U("application/json"); + + } + // multipart formdata + else if( consumeHttpContentTypes.find(U("multipart/form-data")) != consumeHttpContentTypes.end() ) + { + requestHttpContentType = U("multipart/form-data"); + + } + else + { + throw ApiException(415, U("UserApi->getUserByName does not consume any supported media type")); + } + + + return m_ApiClient->callApi(path, U("GET"), queryParams, httpBody, headerParams, formParams, fileParams, requestHttpContentType) + .then([=](web::http::http_response response) + { + // 1xx - informational : OK + // 2xx - successful : OK + // 3xx - redirection : OK + // 4xx - client error : not OK + // 5xx - client error : not OK + if (response.status_code() >= 400) + { + throw ApiException(response.status_code() + , U("error calling getUserByName: ") + response.reason_phrase() + , std::make_shared(response.extract_utf8string(true).get())); + } + + // check response content type + if(response.headers().has(U("Content-Type"))) + { + utility::string_t contentType = response.headers()[U("Content-Type")]; + if( contentType.find(responseHttpContentType) == std::string::npos ) + { + throw ApiException(500 + , U("error calling getUserByName: unexpected response type: ") + contentType + , std::make_shared(response.extract_utf8string(true).get())); + } + } + + return response.extract_string(); + }) + .then([=](utility::string_t response) + { + std::shared_ptr result(new User()); + + if(responseHttpContentType == U("application/json")) + { + web::json::value json = web::json::value::parse(response); + + result->fromJson(json); + } + // else if(responseHttpContentType == U("multipart/form-data")) + // { + // TODO multipart response parsing + // } + else + { + throw ApiException(500 + , U("error calling findPetsByStatus: unsupported response type")); + } + + return result; + }); +} +pplx::task UserApi::loginUser(utility::string_t username, utility::string_t password) +{ + + + std::shared_ptr apiConfiguration( m_ApiClient->getConfiguration() ); + utility::string_t path = U("/user/login"); + + std::map queryParams; + std::map headerParams( apiConfiguration->getDefaultHeaders() ); + std::map formParams; + std::map> fileParams; + + std::unordered_set responseHttpContentTypes; + responseHttpContentTypes.insert( U("application/xml") ); +responseHttpContentTypes.insert( U("application/json") ); + + utility::string_t responseHttpContentType; + + // use JSON if possible + if ( responseHttpContentTypes.size() == 0 || responseHttpContentTypes.find(U("application/json")) != responseHttpContentTypes.end() ) + { + responseHttpContentType = U("application/json"); + } + // multipart formdata + else if( responseHttpContentTypes.find(U("multipart/form-data")) != responseHttpContentTypes.end() ) + { + responseHttpContentType = U("multipart/form-data"); + } + else + { + throw ApiException(400, U("UserApi->loginUser does not produce any supported media type")); + } + + headerParams[U("Accept")] = responseHttpContentType; + + std::unordered_set consumeHttpContentTypes; + + + { + queryParams[U("username")] = ApiClient::parameterToString(username); + + } + + { + queryParams[U("password")] = ApiClient::parameterToString(password); + + } + + + std::shared_ptr httpBody; + utility::string_t requestHttpContentType; + + // use JSON if possible + if ( consumeHttpContentTypes.size() == 0 || consumeHttpContentTypes.find(U("application/json")) != consumeHttpContentTypes.end() ) + { + requestHttpContentType = U("application/json"); + + } + // multipart formdata + else if( consumeHttpContentTypes.find(U("multipart/form-data")) != consumeHttpContentTypes.end() ) + { + requestHttpContentType = U("multipart/form-data"); + + } + else + { + throw ApiException(415, U("UserApi->loginUser does not consume any supported media type")); + } + + + return m_ApiClient->callApi(path, U("GET"), queryParams, httpBody, headerParams, formParams, fileParams, requestHttpContentType) + .then([=](web::http::http_response response) + { + // 1xx - informational : OK + // 2xx - successful : OK + // 3xx - redirection : OK + // 4xx - client error : not OK + // 5xx - client error : not OK + if (response.status_code() >= 400) + { + throw ApiException(response.status_code() + , U("error calling loginUser: ") + response.reason_phrase() + , std::make_shared(response.extract_utf8string(true).get())); + } + + // check response content type + if(response.headers().has(U("Content-Type"))) + { + utility::string_t contentType = response.headers()[U("Content-Type")]; + if( contentType.find(responseHttpContentType) == std::string::npos ) + { + throw ApiException(500 + , U("error calling loginUser: unexpected response type: ") + contentType + , std::make_shared(response.extract_utf8string(true).get())); + } + } + + return response.extract_string(); + }) + .then([=](utility::string_t response) + { + utility::string_t result(U("")); + + if(responseHttpContentType == U("application/json")) + { + web::json::value json = web::json::value::parse(response); + + result = ModelBase::stringFromJson(json); + + } + // else if(responseHttpContentType == U("multipart/form-data")) + // { + // TODO multipart response parsing + // } + else + { + throw ApiException(500 + , U("error calling findPetsByStatus: unsupported response type")); + } + + return result; + }); +} +pplx::task UserApi::logoutUser() +{ + + + std::shared_ptr apiConfiguration( m_ApiClient->getConfiguration() ); + utility::string_t path = U("/user/logout"); + + std::map queryParams; + std::map headerParams( apiConfiguration->getDefaultHeaders() ); + std::map formParams; + std::map> fileParams; + + std::unordered_set responseHttpContentTypes; + responseHttpContentTypes.insert( U("application/xml") ); +responseHttpContentTypes.insert( U("application/json") ); + + utility::string_t responseHttpContentType; + + // use JSON if possible + if ( responseHttpContentTypes.size() == 0 || responseHttpContentTypes.find(U("application/json")) != responseHttpContentTypes.end() ) + { + responseHttpContentType = U("application/json"); + } + // multipart formdata + else if( responseHttpContentTypes.find(U("multipart/form-data")) != responseHttpContentTypes.end() ) + { + responseHttpContentType = U("multipart/form-data"); + } + else + { + throw ApiException(400, U("UserApi->logoutUser does not produce any supported media type")); + } + + headerParams[U("Accept")] = responseHttpContentType; + + std::unordered_set consumeHttpContentTypes; + + + + std::shared_ptr httpBody; + utility::string_t requestHttpContentType; + + // use JSON if possible + if ( consumeHttpContentTypes.size() == 0 || consumeHttpContentTypes.find(U("application/json")) != consumeHttpContentTypes.end() ) + { + requestHttpContentType = U("application/json"); + + } + // multipart formdata + else if( consumeHttpContentTypes.find(U("multipart/form-data")) != consumeHttpContentTypes.end() ) + { + requestHttpContentType = U("multipart/form-data"); + + } + else + { + throw ApiException(415, U("UserApi->logoutUser does not consume any supported media type")); + } + + + return m_ApiClient->callApi(path, U("GET"), queryParams, httpBody, headerParams, formParams, fileParams, requestHttpContentType) + .then([=](web::http::http_response response) + { + // 1xx - informational : OK + // 2xx - successful : OK + // 3xx - redirection : OK + // 4xx - client error : not OK + // 5xx - client error : not OK + if (response.status_code() >= 400) + { + throw ApiException(response.status_code() + , U("error calling logoutUser: ") + response.reason_phrase() + , std::make_shared(response.extract_utf8string(true).get())); + } + + // check response content type + if(response.headers().has(U("Content-Type"))) + { + utility::string_t contentType = response.headers()[U("Content-Type")]; + if( contentType.find(responseHttpContentType) == std::string::npos ) + { + throw ApiException(500 + , U("error calling logoutUser: unexpected response type: ") + contentType + , std::make_shared(response.extract_utf8string(true).get())); + } + } + + return response.extract_string(); + }) + .then([=](utility::string_t response) + { + return void(); + }); +} +pplx::task UserApi::updateUser(utility::string_t username, std::shared_ptr body) +{ + + // verify the required parameter 'body' is set + if (body == nullptr) + { + throw ApiException(400, U("Missing required parameter 'body' when calling UserApi->updateUser")); + } + + + std::shared_ptr apiConfiguration( m_ApiClient->getConfiguration() ); + utility::string_t path = U("/user/{username}"); + boost::replace_all(path, U("{") U("username") U("}"), ApiClient::parameterToString(username)); + + std::map queryParams; + std::map headerParams( apiConfiguration->getDefaultHeaders() ); + std::map formParams; + std::map> fileParams; + + std::unordered_set responseHttpContentTypes; + responseHttpContentTypes.insert( U("application/xml") ); +responseHttpContentTypes.insert( U("application/json") ); + + utility::string_t responseHttpContentType; + + // use JSON if possible + if ( responseHttpContentTypes.size() == 0 || responseHttpContentTypes.find(U("application/json")) != responseHttpContentTypes.end() ) + { + responseHttpContentType = U("application/json"); + } + // multipart formdata + else if( responseHttpContentTypes.find(U("multipart/form-data")) != responseHttpContentTypes.end() ) + { + responseHttpContentType = U("multipart/form-data"); + } + else + { + throw ApiException(400, U("UserApi->updateUser does not produce any supported media type")); + } + + headerParams[U("Accept")] = responseHttpContentType; + + std::unordered_set consumeHttpContentTypes; + + + { + + } + + + std::shared_ptr httpBody; + utility::string_t requestHttpContentType; + + // use JSON if possible + if ( consumeHttpContentTypes.size() == 0 || consumeHttpContentTypes.find(U("application/json")) != consumeHttpContentTypes.end() ) + { + requestHttpContentType = U("application/json"); + + web::json::value json; + + json = ModelBase::toJson(body); + + + httpBody = std::shared_ptr( new JsonBody( json ) ); + + } + // multipart formdata + else if( consumeHttpContentTypes.find(U("multipart/form-data")) != consumeHttpContentTypes.end() ) + { + requestHttpContentType = U("multipart/form-data"); + + std::shared_ptr multipart(new MultipartFormData); + + if(body.get()) + { + body->toMultipart(multipart, U("body")); + } + + + httpBody = multipart; + requestHttpContentType += U("; boundary=") + multipart->getBoundary(); + } + else + { + throw ApiException(415, U("UserApi->updateUser does not consume any supported media type")); + } + + + return m_ApiClient->callApi(path, U("PUT"), queryParams, httpBody, headerParams, formParams, fileParams, requestHttpContentType) + .then([=](web::http::http_response response) + { + // 1xx - informational : OK + // 2xx - successful : OK + // 3xx - redirection : OK + // 4xx - client error : not OK + // 5xx - client error : not OK + if (response.status_code() >= 400) + { + throw ApiException(response.status_code() + , U("error calling updateUser: ") + response.reason_phrase() + , std::make_shared(response.extract_utf8string(true).get())); + } + + // check response content type + if(response.headers().has(U("Content-Type"))) + { + utility::string_t contentType = response.headers()[U("Content-Type")]; + if( contentType.find(responseHttpContentType) == std::string::npos ) + { + throw ApiException(500 + , U("error calling updateUser: unexpected response type: ") + contentType + , std::make_shared(response.extract_utf8string(true).get())); + } + } + + return response.extract_string(); + }) + .then([=](utility::string_t response) + { + return void(); + }); +} + +} +} +} +} + diff --git a/samples/client/petstore/cpprest/api/UserApi.h b/samples/client/petstore/cpprest/api/UserApi.h new file mode 100644 index 00000000000..217ad44a12e --- /dev/null +++ b/samples/client/petstore/cpprest/api/UserApi.h @@ -0,0 +1,104 @@ +/* + * UserApi.h + * + * + */ + +#ifndef UserApi_H_ +#define UserApi_H_ + + +#include "ApiClient.h" + +#include "User.h" +#include +#include + +namespace io { +namespace swagger { +namespace client { +namespace api { + +using namespace io::swagger::client::model; + +class UserApi +{ +public: + UserApi( std::shared_ptr apiClient ); + virtual ~UserApi(); + /// + /// Create user + /// + /// + /// This can only be done by the logged in user. + /// + /// Created user object + pplx::task createUser(std::shared_ptr body); + /// + /// Creates list of users with given input array + /// + /// + /// + /// + /// List of user object + pplx::task createUsersWithArrayInput(std::vector> body); + /// + /// Creates list of users with given input array + /// + /// + /// + /// + /// List of user object + pplx::task createUsersWithListInput(std::vector> body); + /// + /// Delete user + /// + /// + /// This can only be done by the logged in user. + /// + /// The name that needs to be deleted + pplx::task deleteUser(utility::string_t username); + /// + /// Get user by user name + /// + /// + /// + /// + /// The name that needs to be fetched. Use user1 for testing. + pplx::task> getUserByName(utility::string_t username); + /// + /// Logs user into the system + /// + /// + /// + /// + /// The user name for login/// The password for login in clear text + pplx::task loginUser(utility::string_t username, utility::string_t password); + /// + /// Logs out current logged in user session + /// + /// + /// + /// + + pplx::task logoutUser(); + /// + /// Updated user + /// + /// + /// This can only be done by the logged in user. + /// + /// name that need to be deleted/// Updated user object + pplx::task updateUser(utility::string_t username, std::shared_ptr body); + +protected: + std::shared_ptr m_ApiClient; +}; + +} +} +} +} + +#endif /* UserApi_H_ */ + diff --git a/samples/client/petstore/cpprest/git_push.sh b/samples/client/petstore/cpprest/git_push.sh new file mode 100644 index 00000000000..970522bca1f --- /dev/null +++ b/samples/client/petstore/cpprest/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/client/petstore/cpprest/model/ApiResponse.cpp b/samples/client/petstore/cpprest/model/ApiResponse.cpp new file mode 100644 index 00000000000..66ee88ef464 --- /dev/null +++ b/samples/client/petstore/cpprest/model/ApiResponse.cpp @@ -0,0 +1,177 @@ + + +#include "ApiResponse.h" + +namespace io { +namespace swagger { +namespace client { +namespace model { + +ApiResponse::ApiResponse() +{ + m_Code = 0; + m_CodeIsSet = false; + m_Type = U(""); + m_TypeIsSet = false; + m_Message = U(""); + m_MessageIsSet = false; + +} + +ApiResponse::~ApiResponse() +{ +} + +void ApiResponse::validate() +{ + // TODO: implement validation +} + +web::json::value ApiResponse::toJson() const +{ + web::json::value val = web::json::value::object(); + + if(m_CodeIsSet) + { + val[U("code")] = ModelBase::toJson(m_Code); + } + if(m_TypeIsSet) + { + val[U("type")] = ModelBase::toJson(m_Type); + } + if(m_MessageIsSet) + { + val[U("message")] = ModelBase::toJson(m_Message); + } + + + return val; +} + +void ApiResponse::fromJson(web::json::value& val) +{ + if(val.has_field(U("code"))) + { + setCode(ModelBase::int32_tFromJson(val[U("code")])); + } + if(val.has_field(U("type"))) + { + setType(ModelBase::stringFromJson(val[U("type")])); + + } + if(val.has_field(U("message"))) + { + setMessage(ModelBase::stringFromJson(val[U("message")])); + + } + +} + +void ApiResponse::toMultipart(std::shared_ptr multipart, const utility::string_t& prefix) const +{ + utility::string_t namePrefix = prefix; + if(namePrefix.size() > 0 && namePrefix[namePrefix.size() - 1] != U('.')) + { + namePrefix += U("."); + } + + if(m_CodeIsSet) + { + multipart->add(ModelBase::toHttpContent(namePrefix + U("code"), m_Code)); + } + if(m_TypeIsSet) + { + multipart->add(ModelBase::toHttpContent(namePrefix + U("type"), m_Type)); + + } + if(m_MessageIsSet) + { + multipart->add(ModelBase::toHttpContent(namePrefix + U("message"), m_Message)); + + } + +} + +void ApiResponse::fromMultiPart(std::shared_ptr multipart, const utility::string_t& prefix) +{ + utility::string_t namePrefix = prefix; + if(namePrefix.size() > 0 && namePrefix[namePrefix.size() - 1] != U('.')) + { + namePrefix += U("."); + } + + if(multipart->hasContent(U("code"))) + { + setCode(ModelBase::int32_tFromHttpContent(multipart->getContent(U("code")))); + } + if(multipart->hasContent(U("type"))) + { + setType(ModelBase::stringFromHttpContent(multipart->getContent(U("type")))); + + } + if(multipart->hasContent(U("message"))) + { + setMessage(ModelBase::stringFromHttpContent(multipart->getContent(U("message")))); + + } + +} + + +int32_t ApiResponse::getCode() const +{ + return m_Code; +} +void ApiResponse::setCode(int32_t value) +{ + m_Code = value; + m_CodeIsSet = true; +} +bool ApiResponse::codeIsSet() const +{ + return m_CodeIsSet; +} +void ApiResponse::unsetCode() +{ + m_CodeIsSet = false; +} +utility::string_t ApiResponse::getType() const +{ + return m_Type; +} +void ApiResponse::setType(utility::string_t value) +{ + m_Type = value; + m_TypeIsSet = true; +} +bool ApiResponse::typeIsSet() const +{ + return m_TypeIsSet; +} +void ApiResponse::unsetType() +{ + m_TypeIsSet = false; +} +utility::string_t ApiResponse::getMessage() const +{ + return m_Message; +} +void ApiResponse::setMessage(utility::string_t value) +{ + m_Message = value; + m_MessageIsSet = true; +} +bool ApiResponse::messageIsSet() const +{ + return m_MessageIsSet; +} +void ApiResponse::unsetMessage() +{ + m_MessageIsSet = false; +} + +} +} +} +} + diff --git a/samples/client/petstore/cpprest/model/ApiResponse.h b/samples/client/petstore/cpprest/model/ApiResponse.h new file mode 100644 index 00000000000..ca9e137b6b2 --- /dev/null +++ b/samples/client/petstore/cpprest/model/ApiResponse.h @@ -0,0 +1,80 @@ +/* + * ApiResponse.h + * + * + */ + +#ifndef ApiResponse_H_ +#define ApiResponse_H_ + + +#include "ModelBase.h" + +#include + +namespace io { +namespace swagger { +namespace client { +namespace model { + +/// +/// +/// +class ApiResponse + : public ModelBase +{ +public: + ApiResponse(); + virtual ~ApiResponse(); + + ///////////////////////////////////////////// + /// ModelBase overrides + + void validate() override; + + web::json::value toJson() const override; + void fromJson(web::json::value& json) override; + + void toMultipart(std::shared_ptr multipart, const utility::string_t& namePrefix) const override; + void fromMultiPart(std::shared_ptr multipart, const utility::string_t& namePrefix) override; + + ///////////////////////////////////////////// + /// ApiResponse members + + /// + /// + /// + int32_t getCode() const; + void setCode(int32_t value); + bool codeIsSet() const; + void unsetCode(); + /// + /// + /// + utility::string_t getType() const; + void setType(utility::string_t value); + bool typeIsSet() const; + void unsetType(); + /// + /// + /// + utility::string_t getMessage() const; + void setMessage(utility::string_t value); + bool messageIsSet() const; + void unsetMessage(); + +protected: + int32_t m_Code; + bool m_CodeIsSet; +utility::string_t m_Type; + bool m_TypeIsSet; +utility::string_t m_Message; + bool m_MessageIsSet; +}; + +} +} +} +} + +#endif /* ApiResponse_H_ */ diff --git a/samples/client/petstore/cpprest/model/Category.cpp b/samples/client/petstore/cpprest/model/Category.cpp new file mode 100644 index 00000000000..3420df3392c --- /dev/null +++ b/samples/client/petstore/cpprest/model/Category.cpp @@ -0,0 +1,139 @@ + + +#include "Category.h" + +namespace io { +namespace swagger { +namespace client { +namespace model { + +Category::Category() +{ + m_Id = 0L; + m_IdIsSet = false; + m_Name = U(""); + m_NameIsSet = false; + +} + +Category::~Category() +{ +} + +void Category::validate() +{ + // TODO: implement validation +} + +web::json::value Category::toJson() const +{ + web::json::value val = web::json::value::object(); + + if(m_IdIsSet) + { + val[U("id")] = ModelBase::toJson(m_Id); + } + if(m_NameIsSet) + { + val[U("name")] = ModelBase::toJson(m_Name); + } + + + return val; +} + +void Category::fromJson(web::json::value& val) +{ + if(val.has_field(U("id"))) + { + setId(ModelBase::int64_tFromJson(val[U("id")])); + } + if(val.has_field(U("name"))) + { + setName(ModelBase::stringFromJson(val[U("name")])); + + } + +} + +void Category::toMultipart(std::shared_ptr multipart, const utility::string_t& prefix) const +{ + utility::string_t namePrefix = prefix; + if(namePrefix.size() > 0 && namePrefix[namePrefix.size() - 1] != U('.')) + { + namePrefix += U("."); + } + + if(m_IdIsSet) + { + multipart->add(ModelBase::toHttpContent(namePrefix + U("id"), m_Id)); + } + if(m_NameIsSet) + { + multipart->add(ModelBase::toHttpContent(namePrefix + U("name"), m_Name)); + + } + +} + +void Category::fromMultiPart(std::shared_ptr multipart, const utility::string_t& prefix) +{ + utility::string_t namePrefix = prefix; + if(namePrefix.size() > 0 && namePrefix[namePrefix.size() - 1] != U('.')) + { + namePrefix += U("."); + } + + if(multipart->hasContent(U("id"))) + { + setId(ModelBase::int64_tFromHttpContent(multipart->getContent(U("id")))); + } + if(multipart->hasContent(U("name"))) + { + setName(ModelBase::stringFromHttpContent(multipart->getContent(U("name")))); + + } + +} + + +int64_t Category::getId() const +{ + return m_Id; +} +void Category::setId(int64_t value) +{ + m_Id = value; + m_IdIsSet = true; +} +bool Category::idIsSet() const +{ + return m_IdIsSet; +} +void Category::unsetId() +{ + m_IdIsSet = false; +} +utility::string_t Category::getName() const +{ + return m_Name; +} +void Category::setName(utility::string_t value) +{ + m_Name = value; + m_NameIsSet = true; +} +bool Category::nameIsSet() const +{ + return m_NameIsSet; +} +void Category::unsetName() +{ + m_NameIsSet = false; +} + +} +} +} +} + diff --git a/samples/client/petstore/cpprest/model/Category.h b/samples/client/petstore/cpprest/model/Category.h new file mode 100644 index 00000000000..d472fb13927 --- /dev/null +++ b/samples/client/petstore/cpprest/model/Category.h @@ -0,0 +1,71 @@ +/* + * Category.h + * + * + */ + +#ifndef Category_H_ +#define Category_H_ + + +#include "ModelBase.h" + +#include + +namespace io { +namespace swagger { +namespace client { +namespace model { + +/// +/// +/// +class Category + : public ModelBase +{ +public: + Category(); + virtual ~Category(); + + ///////////////////////////////////////////// + /// ModelBase overrides + + void validate() override; + + web::json::value toJson() const override; + void fromJson(web::json::value& json) override; + + void toMultipart(std::shared_ptr multipart, const utility::string_t& namePrefix) const override; + void fromMultiPart(std::shared_ptr multipart, const utility::string_t& namePrefix) override; + + ///////////////////////////////////////////// + /// Category members + + /// + /// + /// + int64_t getId() const; + void setId(int64_t value); + bool idIsSet() const; + void unsetId(); + /// + /// + /// + utility::string_t getName() const; + void setName(utility::string_t value); + bool nameIsSet() const; + void unsetName(); + +protected: + int64_t m_Id; + bool m_IdIsSet; +utility::string_t m_Name; + bool m_NameIsSet; +}; + +} +} +} +} + +#endif /* Category_H_ */ diff --git a/samples/client/petstore/cpprest/model/Order.cpp b/samples/client/petstore/cpprest/model/Order.cpp new file mode 100644 index 00000000000..ca0ecf8f93b --- /dev/null +++ b/samples/client/petstore/cpprest/model/Order.cpp @@ -0,0 +1,282 @@ + + +#include "Order.h" + +namespace io { +namespace swagger { +namespace client { +namespace model { + +Order::Order() +{ + m_Id = 0L; + m_IdIsSet = false; + m_PetId = 0L; + m_PetIdIsSet = false; + m_Quantity = 0; + m_QuantityIsSet = false; + m_ShipDate = utility::datetime(); + m_ShipDateIsSet = false; + m_Status = U(""); + m_StatusIsSet = false; + m_Complete = false; + m_CompleteIsSet = false; + +} + +Order::~Order() +{ +} + +void Order::validate() +{ + // TODO: implement validation +} + +web::json::value Order::toJson() const +{ + web::json::value val = web::json::value::object(); + + if(m_IdIsSet) + { + val[U("id")] = ModelBase::toJson(m_Id); + } + if(m_PetIdIsSet) + { + val[U("petId")] = ModelBase::toJson(m_PetId); + } + if(m_QuantityIsSet) + { + val[U("quantity")] = ModelBase::toJson(m_Quantity); + } + if(m_ShipDateIsSet) + { + val[U("shipDate")] = ModelBase::toJson(m_ShipDate); + } + if(m_StatusIsSet) + { + val[U("status")] = ModelBase::toJson(m_Status); + } + if(m_CompleteIsSet) + { + val[U("complete")] = ModelBase::toJson(m_Complete); + } + + + return val; +} + +void Order::fromJson(web::json::value& val) +{ + if(val.has_field(U("id"))) + { + setId(ModelBase::int64_tFromJson(val[U("id")])); + } + if(val.has_field(U("petId"))) + { + setPetId(ModelBase::int64_tFromJson(val[U("petId")])); + } + if(val.has_field(U("quantity"))) + { + setQuantity(ModelBase::int32_tFromJson(val[U("quantity")])); + } + if(val.has_field(U("shipDate"))) + { + setShipDate(ModelBase::dateFromJson(val[U("shipDate")])); + + } + if(val.has_field(U("status"))) + { + setStatus(ModelBase::stringFromJson(val[U("status")])); + + } + if(val.has_field(U("complete"))) + { + setComplete(ModelBase::boolFromJson(val[U("complete")])); + } + +} + +void Order::toMultipart(std::shared_ptr multipart, const utility::string_t& prefix) const +{ + utility::string_t namePrefix = prefix; + if(namePrefix.size() > 0 && namePrefix[namePrefix.size() - 1] != U('.')) + { + namePrefix += U("."); + } + + if(m_IdIsSet) + { + multipart->add(ModelBase::toHttpContent(namePrefix + U("id"), m_Id)); + } + if(m_PetIdIsSet) + { + multipart->add(ModelBase::toHttpContent(namePrefix + U("petId"), m_PetId)); + } + if(m_QuantityIsSet) + { + multipart->add(ModelBase::toHttpContent(namePrefix + U("quantity"), m_Quantity)); + } + if(m_ShipDateIsSet) + { + multipart->add(ModelBase::toHttpContent(namePrefix + U("shipDate"), m_ShipDate)); + + } + if(m_StatusIsSet) + { + multipart->add(ModelBase::toHttpContent(namePrefix + U("status"), m_Status)); + + } + if(m_CompleteIsSet) + { + multipart->add(ModelBase::toHttpContent(namePrefix + U("complete"), m_Complete)); + } + +} + +void Order::fromMultiPart(std::shared_ptr multipart, const utility::string_t& prefix) +{ + utility::string_t namePrefix = prefix; + if(namePrefix.size() > 0 && namePrefix[namePrefix.size() - 1] != U('.')) + { + namePrefix += U("."); + } + + if(multipart->hasContent(U("id"))) + { + setId(ModelBase::int64_tFromHttpContent(multipart->getContent(U("id")))); + } + if(multipart->hasContent(U("petId"))) + { + setPetId(ModelBase::int64_tFromHttpContent(multipart->getContent(U("petId")))); + } + if(multipart->hasContent(U("quantity"))) + { + setQuantity(ModelBase::int32_tFromHttpContent(multipart->getContent(U("quantity")))); + } + if(multipart->hasContent(U("shipDate"))) + { + setShipDate(ModelBase::dateFromHttpContent(multipart->getContent(U("shipDate")))); + + } + if(multipart->hasContent(U("status"))) + { + setStatus(ModelBase::stringFromHttpContent(multipart->getContent(U("status")))); + + } + if(multipart->hasContent(U("complete"))) + { + setComplete(ModelBase::boolFromHttpContent(multipart->getContent(U("complete")))); + } + +} + + +int64_t Order::getId() const +{ + return m_Id; +} +void Order::setId(int64_t value) +{ + m_Id = value; + m_IdIsSet = true; +} +bool Order::idIsSet() const +{ + return m_IdIsSet; +} +void Order::unsetId() +{ + m_IdIsSet = false; +} +int64_t Order::getPetId() const +{ + return m_PetId; +} +void Order::setPetId(int64_t value) +{ + m_PetId = value; + m_PetIdIsSet = true; +} +bool Order::petIdIsSet() const +{ + return m_PetIdIsSet; +} +void Order::unsetPetId() +{ + m_PetIdIsSet = false; +} +int32_t Order::getQuantity() const +{ + return m_Quantity; +} +void Order::setQuantity(int32_t value) +{ + m_Quantity = value; + m_QuantityIsSet = true; +} +bool Order::quantityIsSet() const +{ + return m_QuantityIsSet; +} +void Order::unsetQuantity() +{ + m_QuantityIsSet = false; +} +utility::datetime Order::getShipDate() const +{ + return m_ShipDate; +} +void Order::setShipDate(utility::datetime value) +{ + m_ShipDate = value; + m_ShipDateIsSet = true; +} +bool Order::shipDateIsSet() const +{ + return m_ShipDateIsSet; +} +void Order::unsetShipDate() +{ + m_ShipDateIsSet = false; +} +utility::string_t Order::getStatus() const +{ + return m_Status; +} +void Order::setStatus(utility::string_t value) +{ + m_Status = value; + m_StatusIsSet = true; +} +bool Order::statusIsSet() const +{ + return m_StatusIsSet; +} +void Order::unsetStatus() +{ + m_StatusIsSet = false; +} +bool Order::getComplete() const +{ + return m_Complete; +} +void Order::setComplete(bool value) +{ + m_Complete = value; + m_CompleteIsSet = true; +} +bool Order::completeIsSet() const +{ + return m_CompleteIsSet; +} +void Order::unsetComplete() +{ + m_CompleteIsSet = false; +} + +} +} +} +} + diff --git a/samples/client/petstore/cpprest/model/Order.h b/samples/client/petstore/cpprest/model/Order.h new file mode 100644 index 00000000000..8fe54141d10 --- /dev/null +++ b/samples/client/petstore/cpprest/model/Order.h @@ -0,0 +1,107 @@ +/* + * Order.h + * + * + */ + +#ifndef Order_H_ +#define Order_H_ + + +#include "ModelBase.h" + +#include + +namespace io { +namespace swagger { +namespace client { +namespace model { + +/// +/// +/// +class Order + : public ModelBase +{ +public: + Order(); + virtual ~Order(); + + ///////////////////////////////////////////// + /// ModelBase overrides + + void validate() override; + + web::json::value toJson() const override; + void fromJson(web::json::value& json) override; + + void toMultipart(std::shared_ptr multipart, const utility::string_t& namePrefix) const override; + void fromMultiPart(std::shared_ptr multipart, const utility::string_t& namePrefix) override; + + ///////////////////////////////////////////// + /// Order members + + /// + /// + /// + int64_t getId() const; + void setId(int64_t value); + bool idIsSet() const; + void unsetId(); + /// + /// + /// + int64_t getPetId() const; + void setPetId(int64_t value); + bool petIdIsSet() const; + void unsetPetId(); + /// + /// + /// + int32_t getQuantity() const; + void setQuantity(int32_t value); + bool quantityIsSet() const; + void unsetQuantity(); + /// + /// + /// + utility::datetime getShipDate() const; + void setShipDate(utility::datetime value); + bool shipDateIsSet() const; + void unsetShipDate(); + /// + /// Order Status + /// + utility::string_t getStatus() const; + void setStatus(utility::string_t value); + bool statusIsSet() const; + void unsetStatus(); + /// + /// + /// + bool getComplete() const; + void setComplete(bool value); + bool completeIsSet() const; + void unsetComplete(); + +protected: + int64_t m_Id; + bool m_IdIsSet; +int64_t m_PetId; + bool m_PetIdIsSet; +int32_t m_Quantity; + bool m_QuantityIsSet; +utility::datetime m_ShipDate; + bool m_ShipDateIsSet; +utility::string_t m_Status; + bool m_StatusIsSet; +bool m_Complete; + bool m_CompleteIsSet; +}; + +} +} +} +} + +#endif /* Order_H_ */ diff --git a/samples/client/petstore/cpprest/model/Pet.cpp b/samples/client/petstore/cpprest/model/Pet.cpp new file mode 100644 index 00000000000..4589b73d871 --- /dev/null +++ b/samples/client/petstore/cpprest/model/Pet.cpp @@ -0,0 +1,324 @@ + + +#include "Pet.h" + +namespace io { +namespace swagger { +namespace client { +namespace model { + +Pet::Pet() +{ + m_Id = 0L; + m_IdIsSet = false; + m_CategoryIsSet = false; + m_Name = U(""); + m_TagsIsSet = false; + m_Status = U(""); + m_StatusIsSet = false; + +} + +Pet::~Pet() +{ +} + +void Pet::validate() +{ + // TODO: implement validation +} + +web::json::value Pet::toJson() const +{ + web::json::value val = web::json::value::object(); + + if(m_IdIsSet) + { + val[U("id")] = ModelBase::toJson(m_Id); + } + if(m_CategoryIsSet) + { + val[U("category")] = ModelBase::toJson(m_Category); + } + val[U("name")] = ModelBase::toJson(m_Name); + { + std::vector jsonArray; + for( auto& item : m_PhotoUrls ) + { + jsonArray.push_back(ModelBase::toJson(item)); + } + val[U("photoUrls")] = web::json::value::array(jsonArray); + } + { + std::vector jsonArray; + for( auto& item : m_Tags ) + { + jsonArray.push_back(ModelBase::toJson(item)); + } + + if(jsonArray.size() > 0) + { + val[U("tags")] = web::json::value::array(jsonArray); + } + } + if(m_StatusIsSet) + { + val[U("status")] = ModelBase::toJson(m_Status); + } + + + return val; +} + +void Pet::fromJson(web::json::value& val) +{ + if(val.has_field(U("id"))) + { + setId(ModelBase::int64_tFromJson(val[U("id")])); + } + if(val.has_field(U("category"))) + { + if(!val[U("category")].is_null()) + { + std::shared_ptr newItem(new Category()); + newItem->fromJson(val[U("category")]); + setCategory( newItem ); + } + + } + setName(ModelBase::stringFromJson(val[U("name")])); + { + m_PhotoUrls.clear(); + std::vector jsonArray; + for( auto& item : val[U("photoUrls")].as_array() ) + { + m_PhotoUrls.push_back(ModelBase::stringFromJson(item)); + + } + } + { + m_Tags.clear(); + std::vector jsonArray; + if(val.has_field(U("tags"))) + { + for( auto& item : val[U("tags")].as_array() ) + { + + if(item.is_null()) + { + m_Tags.push_back( std::shared_ptr(nullptr) ); + } + else + { + std::shared_ptr newItem(new Tag()); + newItem->fromJson(item); + m_Tags.push_back( newItem ); + } + + } + } + } + if(val.has_field(U("status"))) + { + setStatus(ModelBase::stringFromJson(val[U("status")])); + + } + +} + +void Pet::toMultipart(std::shared_ptr multipart, const utility::string_t& prefix) const +{ + utility::string_t namePrefix = prefix; + if(namePrefix.size() > 0 && namePrefix[namePrefix.size() - 1] != U('.')) + { + namePrefix += U("."); + } + + if(m_IdIsSet) + { + multipart->add(ModelBase::toHttpContent(namePrefix + U("id"), m_Id)); + } + if(m_CategoryIsSet) + { + if (m_Category.get()) + { + m_Category->toMultipart(multipart, U("category.")); + } + + } + multipart->add(ModelBase::toHttpContent(namePrefix + U("name"), m_Name)); + { + std::vector jsonArray; + for( auto& item : m_PhotoUrls ) + { + jsonArray.push_back(ModelBase::toJson(item)); + } + multipart->add(ModelBase::toHttpContent(namePrefix + U("photoUrls"), web::json::value::array(jsonArray), U("application/json"))); + } + { + std::vector jsonArray; + for( auto& item : m_Tags ) + { + jsonArray.push_back(ModelBase::toJson(item)); + } + + if(jsonArray.size() > 0) + { + multipart->add(ModelBase::toHttpContent(namePrefix + U("tags"), web::json::value::array(jsonArray), U("application/json"))); + } + } + if(m_StatusIsSet) + { + multipart->add(ModelBase::toHttpContent(namePrefix + U("status"), m_Status)); + + } + +} + +void Pet::fromMultiPart(std::shared_ptr multipart, const utility::string_t& prefix) +{ + utility::string_t namePrefix = prefix; + if(namePrefix.size() > 0 && namePrefix[namePrefix.size() - 1] != U('.')) + { + namePrefix += U("."); + } + + if(multipart->hasContent(U("id"))) + { + setId(ModelBase::int64_tFromHttpContent(multipart->getContent(U("id")))); + } + if(multipart->hasContent(U("category"))) + { + if(multipart->hasContent(U("category"))) + { + std::shared_ptr newItem(new Category()); + newItem->fromMultiPart(multipart, U("category.")); + setCategory( newItem ); + } + + } + setName(ModelBase::stringFromHttpContent(multipart->getContent(U("name")))); + { + m_PhotoUrls.clear(); + + web::json::value jsonArray = web::json::value::parse(ModelBase::stringFromHttpContent(multipart->getContent(U("photoUrls")))); + for( auto& item : jsonArray.as_array() ) + { + m_PhotoUrls.push_back(ModelBase::stringFromJson(item)); + + } + } + { + m_Tags.clear(); + if(multipart->hasContent(U("tags"))) + { + + web::json::value jsonArray = web::json::value::parse(ModelBase::stringFromHttpContent(multipart->getContent(U("tags")))); + for( auto& item : jsonArray.as_array() ) + { + + if(item.is_null()) + { + m_Tags.push_back( std::shared_ptr(nullptr) ); + } + else + { + std::shared_ptr newItem(new Tag()); + newItem->fromJson(item); + m_Tags.push_back( newItem ); + } + + } + } + } + if(multipart->hasContent(U("status"))) + { + setStatus(ModelBase::stringFromHttpContent(multipart->getContent(U("status")))); + + } + +} + + +int64_t Pet::getId() const +{ + return m_Id; +} +void Pet::setId(int64_t value) +{ + m_Id = value; + m_IdIsSet = true; +} +bool Pet::idIsSet() const +{ + return m_IdIsSet; +} +void Pet::unsetId() +{ + m_IdIsSet = false; +} +std::shared_ptr Pet::getCategory() const +{ + return m_Category; +} +void Pet::setCategory(std::shared_ptr value) +{ + m_Category = value; + m_CategoryIsSet = true; +} +bool Pet::categoryIsSet() const +{ + return m_CategoryIsSet; +} +void Pet::unsetCategory() +{ + m_CategoryIsSet = false; +} +utility::string_t Pet::getName() const +{ + return m_Name; +} +void Pet::setName(utility::string_t value) +{ + m_Name = value; + +} +std::vector& Pet::getPhotoUrls() +{ + return m_PhotoUrls; +} +std::vector>& Pet::getTags() +{ + return m_Tags; +} +bool Pet::tagsIsSet() const +{ + return m_TagsIsSet; +} +void Pet::unsetTags() +{ + m_TagsIsSet = false; +} +utility::string_t Pet::getStatus() const +{ + return m_Status; +} +void Pet::setStatus(utility::string_t value) +{ + m_Status = value; + m_StatusIsSet = true; +} +bool Pet::statusIsSet() const +{ + return m_StatusIsSet; +} +void Pet::unsetStatus() +{ + m_StatusIsSet = false; +} + +} +} +} +} + diff --git a/samples/client/petstore/cpprest/model/Pet.h b/samples/client/petstore/cpprest/model/Pet.h new file mode 100644 index 00000000000..3152cd580f7 --- /dev/null +++ b/samples/client/petstore/cpprest/model/Pet.h @@ -0,0 +1,102 @@ +/* + * Pet.h + * + * + */ + +#ifndef Pet_H_ +#define Pet_H_ + + +#include "ModelBase.h" + +#include "Category.h" +#include +#include +#include "Tag.h" + +namespace io { +namespace swagger { +namespace client { +namespace model { + +/// +/// +/// +class Pet + : public ModelBase +{ +public: + Pet(); + virtual ~Pet(); + + ///////////////////////////////////////////// + /// ModelBase overrides + + void validate() override; + + web::json::value toJson() const override; + void fromJson(web::json::value& json) override; + + void toMultipart(std::shared_ptr multipart, const utility::string_t& namePrefix) const override; + void fromMultiPart(std::shared_ptr multipart, const utility::string_t& namePrefix) override; + + ///////////////////////////////////////////// + /// Pet members + + /// + /// + /// + int64_t getId() const; + void setId(int64_t value); + bool idIsSet() const; + void unsetId(); + /// + /// + /// + std::shared_ptr getCategory() const; + void setCategory(std::shared_ptr value); + bool categoryIsSet() const; + void unsetCategory(); + /// + /// + /// + utility::string_t getName() const; + void setName(utility::string_t value); + /// + /// + /// + std::vector& getPhotoUrls(); + /// + /// + /// + std::vector>& getTags(); + bool tagsIsSet() const; + void unsetTags(); + /// + /// pet status in the store + /// + utility::string_t getStatus() const; + void setStatus(utility::string_t value); + bool statusIsSet() const; + void unsetStatus(); + +protected: + int64_t m_Id; + bool m_IdIsSet; +std::shared_ptr m_Category; + bool m_CategoryIsSet; +utility::string_t m_Name; + std::vector m_PhotoUrls; + std::vector> m_Tags; + bool m_TagsIsSet; +utility::string_t m_Status; + bool m_StatusIsSet; +}; + +} +} +} +} + +#endif /* Pet_H_ */ diff --git a/samples/client/petstore/cpprest/model/Tag.cpp b/samples/client/petstore/cpprest/model/Tag.cpp new file mode 100644 index 00000000000..115cc6bb899 --- /dev/null +++ b/samples/client/petstore/cpprest/model/Tag.cpp @@ -0,0 +1,139 @@ + + +#include "Tag.h" + +namespace io { +namespace swagger { +namespace client { +namespace model { + +Tag::Tag() +{ + m_Id = 0L; + m_IdIsSet = false; + m_Name = U(""); + m_NameIsSet = false; + +} + +Tag::~Tag() +{ +} + +void Tag::validate() +{ + // TODO: implement validation +} + +web::json::value Tag::toJson() const +{ + web::json::value val = web::json::value::object(); + + if(m_IdIsSet) + { + val[U("id")] = ModelBase::toJson(m_Id); + } + if(m_NameIsSet) + { + val[U("name")] = ModelBase::toJson(m_Name); + } + + + return val; +} + +void Tag::fromJson(web::json::value& val) +{ + if(val.has_field(U("id"))) + { + setId(ModelBase::int64_tFromJson(val[U("id")])); + } + if(val.has_field(U("name"))) + { + setName(ModelBase::stringFromJson(val[U("name")])); + + } + +} + +void Tag::toMultipart(std::shared_ptr multipart, const utility::string_t& prefix) const +{ + utility::string_t namePrefix = prefix; + if(namePrefix.size() > 0 && namePrefix[namePrefix.size() - 1] != U('.')) + { + namePrefix += U("."); + } + + if(m_IdIsSet) + { + multipart->add(ModelBase::toHttpContent(namePrefix + U("id"), m_Id)); + } + if(m_NameIsSet) + { + multipart->add(ModelBase::toHttpContent(namePrefix + U("name"), m_Name)); + + } + +} + +void Tag::fromMultiPart(std::shared_ptr multipart, const utility::string_t& prefix) +{ + utility::string_t namePrefix = prefix; + if(namePrefix.size() > 0 && namePrefix[namePrefix.size() - 1] != U('.')) + { + namePrefix += U("."); + } + + if(multipart->hasContent(U("id"))) + { + setId(ModelBase::int64_tFromHttpContent(multipart->getContent(U("id")))); + } + if(multipart->hasContent(U("name"))) + { + setName(ModelBase::stringFromHttpContent(multipart->getContent(U("name")))); + + } + +} + + +int64_t Tag::getId() const +{ + return m_Id; +} +void Tag::setId(int64_t value) +{ + m_Id = value; + m_IdIsSet = true; +} +bool Tag::idIsSet() const +{ + return m_IdIsSet; +} +void Tag::unsetId() +{ + m_IdIsSet = false; +} +utility::string_t Tag::getName() const +{ + return m_Name; +} +void Tag::setName(utility::string_t value) +{ + m_Name = value; + m_NameIsSet = true; +} +bool Tag::nameIsSet() const +{ + return m_NameIsSet; +} +void Tag::unsetName() +{ + m_NameIsSet = false; +} + +} +} +} +} + diff --git a/samples/client/petstore/cpprest/model/Tag.h b/samples/client/petstore/cpprest/model/Tag.h new file mode 100644 index 00000000000..e657692ea35 --- /dev/null +++ b/samples/client/petstore/cpprest/model/Tag.h @@ -0,0 +1,71 @@ +/* + * Tag.h + * + * + */ + +#ifndef Tag_H_ +#define Tag_H_ + + +#include "ModelBase.h" + +#include + +namespace io { +namespace swagger { +namespace client { +namespace model { + +/// +/// +/// +class Tag + : public ModelBase +{ +public: + Tag(); + virtual ~Tag(); + + ///////////////////////////////////////////// + /// ModelBase overrides + + void validate() override; + + web::json::value toJson() const override; + void fromJson(web::json::value& json) override; + + void toMultipart(std::shared_ptr multipart, const utility::string_t& namePrefix) const override; + void fromMultiPart(std::shared_ptr multipart, const utility::string_t& namePrefix) override; + + ///////////////////////////////////////////// + /// Tag members + + /// + /// + /// + int64_t getId() const; + void setId(int64_t value); + bool idIsSet() const; + void unsetId(); + /// + /// + /// + utility::string_t getName() const; + void setName(utility::string_t value); + bool nameIsSet() const; + void unsetName(); + +protected: + int64_t m_Id; + bool m_IdIsSet; +utility::string_t m_Name; + bool m_NameIsSet; +}; + +} +} +} +} + +#endif /* Tag_H_ */ diff --git a/samples/client/petstore/cpprest/model/User.cpp b/samples/client/petstore/cpprest/model/User.cpp new file mode 100644 index 00000000000..39c17dfd964 --- /dev/null +++ b/samples/client/petstore/cpprest/model/User.cpp @@ -0,0 +1,364 @@ + + +#include "User.h" + +namespace io { +namespace swagger { +namespace client { +namespace model { + +User::User() +{ + m_Id = 0L; + m_IdIsSet = false; + m_Username = U(""); + m_UsernameIsSet = false; + m_FirstName = U(""); + m_FirstNameIsSet = false; + m_LastName = U(""); + m_LastNameIsSet = false; + m_Email = U(""); + m_EmailIsSet = false; + m_Password = U(""); + m_PasswordIsSet = false; + m_Phone = U(""); + m_PhoneIsSet = false; + m_UserStatus = 0; + m_UserStatusIsSet = false; + +} + +User::~User() +{ +} + +void User::validate() +{ + // TODO: implement validation +} + +web::json::value User::toJson() const +{ + web::json::value val = web::json::value::object(); + + if(m_IdIsSet) + { + val[U("id")] = ModelBase::toJson(m_Id); + } + if(m_UsernameIsSet) + { + val[U("username")] = ModelBase::toJson(m_Username); + } + if(m_FirstNameIsSet) + { + val[U("firstName")] = ModelBase::toJson(m_FirstName); + } + if(m_LastNameIsSet) + { + val[U("lastName")] = ModelBase::toJson(m_LastName); + } + if(m_EmailIsSet) + { + val[U("email")] = ModelBase::toJson(m_Email); + } + if(m_PasswordIsSet) + { + val[U("password")] = ModelBase::toJson(m_Password); + } + if(m_PhoneIsSet) + { + val[U("phone")] = ModelBase::toJson(m_Phone); + } + if(m_UserStatusIsSet) + { + val[U("userStatus")] = ModelBase::toJson(m_UserStatus); + } + + + return val; +} + +void User::fromJson(web::json::value& val) +{ + if(val.has_field(U("id"))) + { + setId(ModelBase::int64_tFromJson(val[U("id")])); + } + if(val.has_field(U("username"))) + { + setUsername(ModelBase::stringFromJson(val[U("username")])); + + } + if(val.has_field(U("firstName"))) + { + setFirstName(ModelBase::stringFromJson(val[U("firstName")])); + + } + if(val.has_field(U("lastName"))) + { + setLastName(ModelBase::stringFromJson(val[U("lastName")])); + + } + if(val.has_field(U("email"))) + { + setEmail(ModelBase::stringFromJson(val[U("email")])); + + } + if(val.has_field(U("password"))) + { + setPassword(ModelBase::stringFromJson(val[U("password")])); + + } + if(val.has_field(U("phone"))) + { + setPhone(ModelBase::stringFromJson(val[U("phone")])); + + } + if(val.has_field(U("userStatus"))) + { + setUserStatus(ModelBase::int32_tFromJson(val[U("userStatus")])); + } + +} + +void User::toMultipart(std::shared_ptr multipart, const utility::string_t& prefix) const +{ + utility::string_t namePrefix = prefix; + if(namePrefix.size() > 0 && namePrefix[namePrefix.size() - 1] != U('.')) + { + namePrefix += U("."); + } + + if(m_IdIsSet) + { + multipart->add(ModelBase::toHttpContent(namePrefix + U("id"), m_Id)); + } + if(m_UsernameIsSet) + { + multipart->add(ModelBase::toHttpContent(namePrefix + U("username"), m_Username)); + + } + if(m_FirstNameIsSet) + { + multipart->add(ModelBase::toHttpContent(namePrefix + U("firstName"), m_FirstName)); + + } + if(m_LastNameIsSet) + { + multipart->add(ModelBase::toHttpContent(namePrefix + U("lastName"), m_LastName)); + + } + if(m_EmailIsSet) + { + multipart->add(ModelBase::toHttpContent(namePrefix + U("email"), m_Email)); + + } + if(m_PasswordIsSet) + { + multipart->add(ModelBase::toHttpContent(namePrefix + U("password"), m_Password)); + + } + if(m_PhoneIsSet) + { + multipart->add(ModelBase::toHttpContent(namePrefix + U("phone"), m_Phone)); + + } + if(m_UserStatusIsSet) + { + multipart->add(ModelBase::toHttpContent(namePrefix + U("userStatus"), m_UserStatus)); + } + +} + +void User::fromMultiPart(std::shared_ptr multipart, const utility::string_t& prefix) +{ + utility::string_t namePrefix = prefix; + if(namePrefix.size() > 0 && namePrefix[namePrefix.size() - 1] != U('.')) + { + namePrefix += U("."); + } + + if(multipart->hasContent(U("id"))) + { + setId(ModelBase::int64_tFromHttpContent(multipart->getContent(U("id")))); + } + if(multipart->hasContent(U("username"))) + { + setUsername(ModelBase::stringFromHttpContent(multipart->getContent(U("username")))); + + } + if(multipart->hasContent(U("firstName"))) + { + setFirstName(ModelBase::stringFromHttpContent(multipart->getContent(U("firstName")))); + + } + if(multipart->hasContent(U("lastName"))) + { + setLastName(ModelBase::stringFromHttpContent(multipart->getContent(U("lastName")))); + + } + if(multipart->hasContent(U("email"))) + { + setEmail(ModelBase::stringFromHttpContent(multipart->getContent(U("email")))); + + } + if(multipart->hasContent(U("password"))) + { + setPassword(ModelBase::stringFromHttpContent(multipart->getContent(U("password")))); + + } + if(multipart->hasContent(U("phone"))) + { + setPhone(ModelBase::stringFromHttpContent(multipart->getContent(U("phone")))); + + } + if(multipart->hasContent(U("userStatus"))) + { + setUserStatus(ModelBase::int32_tFromHttpContent(multipart->getContent(U("userStatus")))); + } + +} + + +int64_t User::getId() const +{ + return m_Id; +} +void User::setId(int64_t value) +{ + m_Id = value; + m_IdIsSet = true; +} +bool User::idIsSet() const +{ + return m_IdIsSet; +} +void User::unsetId() +{ + m_IdIsSet = false; +} +utility::string_t User::getUsername() const +{ + return m_Username; +} +void User::setUsername(utility::string_t value) +{ + m_Username = value; + m_UsernameIsSet = true; +} +bool User::usernameIsSet() const +{ + return m_UsernameIsSet; +} +void User::unsetUsername() +{ + m_UsernameIsSet = false; +} +utility::string_t User::getFirstName() const +{ + return m_FirstName; +} +void User::setFirstName(utility::string_t value) +{ + m_FirstName = value; + m_FirstNameIsSet = true; +} +bool User::firstNameIsSet() const +{ + return m_FirstNameIsSet; +} +void User::unsetFirstName() +{ + m_FirstNameIsSet = false; +} +utility::string_t User::getLastName() const +{ + return m_LastName; +} +void User::setLastName(utility::string_t value) +{ + m_LastName = value; + m_LastNameIsSet = true; +} +bool User::lastNameIsSet() const +{ + return m_LastNameIsSet; +} +void User::unsetLastName() +{ + m_LastNameIsSet = false; +} +utility::string_t User::getEmail() const +{ + return m_Email; +} +void User::setEmail(utility::string_t value) +{ + m_Email = value; + m_EmailIsSet = true; +} +bool User::emailIsSet() const +{ + return m_EmailIsSet; +} +void User::unsetEmail() +{ + m_EmailIsSet = false; +} +utility::string_t User::getPassword() const +{ + return m_Password; +} +void User::setPassword(utility::string_t value) +{ + m_Password = value; + m_PasswordIsSet = true; +} +bool User::passwordIsSet() const +{ + return m_PasswordIsSet; +} +void User::unsetPassword() +{ + m_PasswordIsSet = false; +} +utility::string_t User::getPhone() const +{ + return m_Phone; +} +void User::setPhone(utility::string_t value) +{ + m_Phone = value; + m_PhoneIsSet = true; +} +bool User::phoneIsSet() const +{ + return m_PhoneIsSet; +} +void User::unsetPhone() +{ + m_PhoneIsSet = false; +} +int32_t User::getUserStatus() const +{ + return m_UserStatus; +} +void User::setUserStatus(int32_t value) +{ + m_UserStatus = value; + m_UserStatusIsSet = true; +} +bool User::userStatusIsSet() const +{ + return m_UserStatusIsSet; +} +void User::unsetUserStatus() +{ + m_UserStatusIsSet = false; +} + +} +} +} +} + diff --git a/samples/client/petstore/cpprest/model/User.h b/samples/client/petstore/cpprest/model/User.h new file mode 100644 index 00000000000..ba90e464cca --- /dev/null +++ b/samples/client/petstore/cpprest/model/User.h @@ -0,0 +1,125 @@ +/* + * User.h + * + * + */ + +#ifndef User_H_ +#define User_H_ + + +#include "ModelBase.h" + +#include + +namespace io { +namespace swagger { +namespace client { +namespace model { + +/// +/// +/// +class User + : public ModelBase +{ +public: + User(); + virtual ~User(); + + ///////////////////////////////////////////// + /// ModelBase overrides + + void validate() override; + + web::json::value toJson() const override; + void fromJson(web::json::value& json) override; + + void toMultipart(std::shared_ptr multipart, const utility::string_t& namePrefix) const override; + void fromMultiPart(std::shared_ptr multipart, const utility::string_t& namePrefix) override; + + ///////////////////////////////////////////// + /// User members + + /// + /// + /// + int64_t getId() const; + void setId(int64_t value); + bool idIsSet() const; + void unsetId(); + /// + /// + /// + utility::string_t getUsername() const; + void setUsername(utility::string_t value); + bool usernameIsSet() const; + void unsetUsername(); + /// + /// + /// + utility::string_t getFirstName() const; + void setFirstName(utility::string_t value); + bool firstNameIsSet() const; + void unsetFirstName(); + /// + /// + /// + utility::string_t getLastName() const; + void setLastName(utility::string_t value); + bool lastNameIsSet() const; + void unsetLastName(); + /// + /// + /// + utility::string_t getEmail() const; + void setEmail(utility::string_t value); + bool emailIsSet() const; + void unsetEmail(); + /// + /// + /// + utility::string_t getPassword() const; + void setPassword(utility::string_t value); + bool passwordIsSet() const; + void unsetPassword(); + /// + /// + /// + utility::string_t getPhone() const; + void setPhone(utility::string_t value); + bool phoneIsSet() const; + void unsetPhone(); + /// + /// User Status + /// + int32_t getUserStatus() const; + void setUserStatus(int32_t value); + bool userStatusIsSet() const; + void unsetUserStatus(); + +protected: + int64_t m_Id; + bool m_IdIsSet; +utility::string_t m_Username; + bool m_UsernameIsSet; +utility::string_t m_FirstName; + bool m_FirstNameIsSet; +utility::string_t m_LastName; + bool m_LastNameIsSet; +utility::string_t m_Email; + bool m_EmailIsSet; +utility::string_t m_Password; + bool m_PasswordIsSet; +utility::string_t m_Phone; + bool m_PhoneIsSet; +int32_t m_UserStatus; + bool m_UserStatusIsSet; +}; + +} +} +} +} + +#endif /* User_H_ */ diff --git a/samples/client/petstore/go/go-petstore/README.md b/samples/client/petstore/go/go-petstore/README.md index 20083469110..5d6a957aa1e 100644 --- a/samples/client/petstore/go/go-petstore/README.md +++ b/samples/client/petstore/go/go-petstore/README.md @@ -7,7 +7,7 @@ This API client was generated by the [swagger-codegen](https://github.com/swagge - API version: 1.0.0 - Package version: 1.0.0 -- Build date: 2016-05-25T10:00:28.559-07:00 +- Build date: 2016-05-26T21:47:25.590-07:00 - Build package: class io.swagger.codegen.languages.GoClientCodegen ## Installation diff --git a/samples/client/petstore/javascript-promise/.swagger-codegen-ignore b/samples/client/petstore/javascript-promise/.swagger-codegen-ignore new file mode 100644 index 00000000000..19d3377182e --- /dev/null +++ b/samples/client/petstore/javascript-promise/.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 +# Thsi 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/client/petstore/javascript-promise/.travis.yml b/samples/client/petstore/javascript-promise/.travis.yml new file mode 100644 index 00000000000..e49f4692f7c --- /dev/null +++ b/samples/client/petstore/javascript-promise/.travis.yml @@ -0,0 +1,7 @@ +language: node_js +node_js: + - "6" + - "6.1" + - "5" + - "5.11" + diff --git a/samples/client/petstore/javascript-promise/LICENSE b/samples/client/petstore/javascript-promise/LICENSE new file mode 100644 index 00000000000..8dada3edaf5 --- /dev/null +++ b/samples/client/petstore/javascript-promise/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "{}" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright {yyyy} {name of copyright owner} + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/samples/client/petstore/javascript-promise/README.md b/samples/client/petstore/javascript-promise/README.md index ba181cae089..c081f0f3cda 100644 --- a/samples/client/petstore/javascript-promise/README.md +++ b/samples/client/petstore/javascript-promise/README.md @@ -1,12 +1,12 @@ # swagger-petstore SwaggerPetstore - JavaScript client for swagger-petstore -This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. +This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ This SDK is automatically generated by the [Swagger Codegen](https://github.com/swagger-api/swagger-codegen) project: - API version: 1.0.0 - Package version: 1.0.0 -- Build date: 2016-05-06T17:51:36.114+08:00 +- Build date: 2016-06-15T01:16:30.521+08:00 - Build package: class io.swagger.codegen.languages.JavascriptClientCodegen ## Installation @@ -88,7 +88,7 @@ All URIs are relative to *http://petstore.swagger.io/v2* Class | Method | HTTP request | Description ------------ | ------------- | ------------- | ------------- -*SwaggerPetstore.FakeApi* | [**testEndpointParameters**](docs/FakeApi.md#testEndpointParameters) | **POST** /fake | Fake endpoint for testing various parameters +*SwaggerPetstore.FakeApi* | [**testEndpointParameters**](docs/FakeApi.md#testEndpointParameters) | **POST** /fake | Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 *SwaggerPetstore.PetApi* | [**addPet**](docs/PetApi.md#addPet) | **POST** /pet | Add a new pet to the store *SwaggerPetstore.PetApi* | [**deletePet**](docs/PetApi.md#deletePet) | **DELETE** /pet/{petId} | Deletes a pet *SwaggerPetstore.PetApi* | [**findPetsByStatus**](docs/PetApi.md#findPetsByStatus) | **GET** /pet/findByStatus | Finds Pets by status @@ -113,20 +113,24 @@ Class | Method | HTTP request | Description ## Documentation for Models + - [SwaggerPetstore.AdditionalPropertiesClass](docs/AdditionalPropertiesClass.md) - [SwaggerPetstore.Animal](docs/Animal.md) - [SwaggerPetstore.AnimalFarm](docs/AnimalFarm.md) - [SwaggerPetstore.ApiResponse](docs/ApiResponse.md) + - [SwaggerPetstore.ArrayTest](docs/ArrayTest.md) - [SwaggerPetstore.Cat](docs/Cat.md) - [SwaggerPetstore.Category](docs/Category.md) - [SwaggerPetstore.Dog](docs/Dog.md) - [SwaggerPetstore.EnumClass](docs/EnumClass.md) - [SwaggerPetstore.EnumTest](docs/EnumTest.md) - [SwaggerPetstore.FormatTest](docs/FormatTest.md) + - [SwaggerPetstore.MixedPropertiesAndAdditionalPropertiesClass](docs/MixedPropertiesAndAdditionalPropertiesClass.md) - [SwaggerPetstore.Model200Response](docs/Model200Response.md) - [SwaggerPetstore.ModelReturn](docs/ModelReturn.md) - [SwaggerPetstore.Name](docs/Name.md) - [SwaggerPetstore.Order](docs/Order.md) - [SwaggerPetstore.Pet](docs/Pet.md) + - [SwaggerPetstore.ReadOnlyFirst](docs/ReadOnlyFirst.md) - [SwaggerPetstore.SpecialModelName](docs/SpecialModelName.md) - [SwaggerPetstore.Tag](docs/Tag.md) - [SwaggerPetstore.User](docs/User.md) @@ -135,6 +139,12 @@ Class | Method | HTTP request | Description ## Documentation for Authorization +### api_key + +- **Type**: API key +- **API key parameter name**: api_key +- **Location**: HTTP header + ### petstore_auth - **Type**: OAuth @@ -144,9 +154,3 @@ Class | Method | HTTP request | Description - write:pets: modify pets in your account - read:pets: read your pets -### api_key - -- **Type**: API key -- **API key parameter name**: api_key -- **Location**: HTTP header - diff --git a/samples/client/petstore/javascript-promise/docs/AdditionalPropertiesClass.md b/samples/client/petstore/javascript-promise/docs/AdditionalPropertiesClass.md new file mode 100644 index 00000000000..0ea13d4bb64 --- /dev/null +++ b/samples/client/petstore/javascript-promise/docs/AdditionalPropertiesClass.md @@ -0,0 +1,9 @@ +# SwaggerPetstore.AdditionalPropertiesClass + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**mapProperty** | **{String: String}** | | [optional] +**mapOfMapProperty** | **{String: {String: String}}** | | [optional] + + diff --git a/samples/client/petstore/javascript-promise/docs/Animal.md b/samples/client/petstore/javascript-promise/docs/Animal.md index c37d95695a0..3ae52d9db17 100644 --- a/samples/client/petstore/javascript-promise/docs/Animal.md +++ b/samples/client/petstore/javascript-promise/docs/Animal.md @@ -4,5 +4,6 @@ Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- **className** | **String** | | +**color** | **String** | | [optional] [default to 'red'] diff --git a/samples/client/petstore/javascript-promise/docs/ArrayTest.md b/samples/client/petstore/javascript-promise/docs/ArrayTest.md new file mode 100644 index 00000000000..a2576512243 --- /dev/null +++ b/samples/client/petstore/javascript-promise/docs/ArrayTest.md @@ -0,0 +1,10 @@ +# SwaggerPetstore.ArrayTest + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**arrayOfString** | **[String]** | | [optional] +**arrayArrayOfInteger** | **[[Integer]]** | | [optional] +**arrayArrayOfModel** | **[[ReadOnlyFirst]]** | | [optional] + + diff --git a/samples/client/petstore/javascript-promise/docs/FakeApi.md b/samples/client/petstore/javascript-promise/docs/FakeApi.md index 83925c1266d..873139e3165 100644 --- a/samples/client/petstore/javascript-promise/docs/FakeApi.md +++ b/samples/client/petstore/javascript-promise/docs/FakeApi.md @@ -4,16 +4,16 @@ All URIs are relative to *http://petstore.swagger.io/v2* Method | HTTP request | Description ------------- | ------------- | ------------- -[**testEndpointParameters**](FakeApi.md#testEndpointParameters) | **POST** /fake | Fake endpoint for testing various parameters +[**testEndpointParameters**](FakeApi.md#testEndpointParameters) | **POST** /fake | Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 # **testEndpointParameters** > testEndpointParameters(_number, _double, _string, _byte, opts) -Fake endpoint for testing various parameters +Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 -Fake endpoint for testing various parameters +Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 ### Example ```javascript @@ -74,6 +74,6 @@ No authorization required ### HTTP request headers - - **Content-Type**: Not defined - - **Accept**: application/xml, application/json + - **Content-Type**: application/xml; charset=utf-8, application/json; charset=utf-8 + - **Accept**: application/xml; charset=utf-8, application/json; charset=utf-8 diff --git a/samples/client/petstore/javascript-promise/docs/MixedPropertiesAndAdditionalPropertiesClass.md b/samples/client/petstore/javascript-promise/docs/MixedPropertiesAndAdditionalPropertiesClass.md new file mode 100644 index 00000000000..31bf8b314ca --- /dev/null +++ b/samples/client/petstore/javascript-promise/docs/MixedPropertiesAndAdditionalPropertiesClass.md @@ -0,0 +1,10 @@ +# SwaggerPetstore.MixedPropertiesAndAdditionalPropertiesClass + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**uuid** | **String** | | [optional] +**dateTime** | **Date** | | [optional] +**map** | [**{String: Animal}**](Animal.md) | | [optional] + + diff --git a/samples/client/petstore/javascript-promise/docs/Name.md b/samples/client/petstore/javascript-promise/docs/Name.md index 3bdb76be085..6c47d402743 100644 --- a/samples/client/petstore/javascript-promise/docs/Name.md +++ b/samples/client/petstore/javascript-promise/docs/Name.md @@ -6,5 +6,6 @@ Name | Type | Description | Notes **name** | **Integer** | | **snakeCase** | **Integer** | | [optional] **property** | **String** | | [optional] +**_123Number** | **Integer** | | [optional] diff --git a/samples/client/petstore/javascript-promise/docs/ReadOnlyFirst.md b/samples/client/petstore/javascript-promise/docs/ReadOnlyFirst.md new file mode 100644 index 00000000000..5a16f8acce0 --- /dev/null +++ b/samples/client/petstore/javascript-promise/docs/ReadOnlyFirst.md @@ -0,0 +1,9 @@ +# SwaggerPetstore.ReadOnlyFirst + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**bar** | **String** | | [optional] +**baz** | **String** | | [optional] + + diff --git a/samples/client/petstore/javascript-promise/mocha.opts b/samples/client/petstore/javascript-promise/mocha.opts new file mode 100644 index 00000000000..907011807d6 --- /dev/null +++ b/samples/client/petstore/javascript-promise/mocha.opts @@ -0,0 +1 @@ +--timeout 10000 diff --git a/samples/client/petstore/javascript-promise/package.json b/samples/client/petstore/javascript-promise/package.json index 8ff02a78ae3..53ea2d8faf9 100644 --- a/samples/client/petstore/javascript-promise/package.json +++ b/samples/client/petstore/javascript-promise/package.json @@ -1,8 +1,8 @@ { "name": "swagger-petstore", "version": "1.0.0", - "description": "This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose.", - "license": "Apache 2.0", + "description": "This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ ", + "license": "Apache-2.0", "main": "src/index.js", "scripts": { "test": "./node_modules/mocha/bin/mocha --recursive" diff --git a/samples/client/petstore/javascript-promise/src/ApiClient.js b/samples/client/petstore/javascript-promise/src/ApiClient.js index 4033ad41e00..d89eb4f4460 100644 --- a/samples/client/petstore/javascript-promise/src/ApiClient.js +++ b/samples/client/petstore/javascript-promise/src/ApiClient.js @@ -1,3 +1,27 @@ +/** + * Swagger Petstore + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * 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. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + (function(root, factory) { if (typeof define === 'function' && define.amd) { // AMD. Register as an anonymous module. @@ -40,8 +64,8 @@ * @type {Array.} */ this.authentications = { - 'petstore_auth': {type: 'oauth2'}, - 'api_key': {type: 'apiKey', 'in': 'header', name: 'api_key'} + 'api_key': {type: 'apiKey', 'in': 'header', name: 'api_key'}, + 'petstore_auth': {type: 'oauth2'} }; /** * The default HTTP headers to be included for all API calls. diff --git a/samples/client/petstore/javascript-promise/src/api/FakeApi.js b/samples/client/petstore/javascript-promise/src/api/FakeApi.js index 84d262725a2..9512bbf1fb8 100644 --- a/samples/client/petstore/javascript-promise/src/api/FakeApi.js +++ b/samples/client/petstore/javascript-promise/src/api/FakeApi.js @@ -1,3 +1,27 @@ +/** + * Swagger Petstore + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * 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. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + (function(root, factory) { if (typeof define === 'function' && define.amd) { // AMD. Register as an anonymous module. @@ -34,8 +58,8 @@ /** - * Fake endpoint for testing various parameters - * Fake endpoint for testing various parameters + * Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 + * Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 * @param {Number} _number None * @param {Number} _double None * @param {String} _string None @@ -97,8 +121,8 @@ }; var authNames = []; - var contentTypes = []; - var accepts = ['application/xml', 'application/json']; + var contentTypes = ['application/xml; charset=utf-8', 'application/json; charset=utf-8']; + var accepts = ['application/xml; charset=utf-8', 'application/json; charset=utf-8']; var returnType = null; return this.apiClient.callApi( diff --git a/samples/client/petstore/javascript-promise/src/api/PetApi.js b/samples/client/petstore/javascript-promise/src/api/PetApi.js index 572fe19dbf2..62be498b179 100644 --- a/samples/client/petstore/javascript-promise/src/api/PetApi.js +++ b/samples/client/petstore/javascript-promise/src/api/PetApi.js @@ -1,3 +1,27 @@ +/** + * Swagger Petstore + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * 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. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + (function(root, factory) { if (typeof define === 'function' && define.amd) { // AMD. Register as an anonymous module. diff --git a/samples/client/petstore/javascript-promise/src/api/StoreApi.js b/samples/client/petstore/javascript-promise/src/api/StoreApi.js index f8b889256b2..b980cdd6784 100644 --- a/samples/client/petstore/javascript-promise/src/api/StoreApi.js +++ b/samples/client/petstore/javascript-promise/src/api/StoreApi.js @@ -1,3 +1,27 @@ +/** + * Swagger Petstore + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * 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. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + (function(root, factory) { if (typeof define === 'function' && define.amd) { // AMD. Register as an anonymous module. diff --git a/samples/client/petstore/javascript-promise/src/api/UserApi.js b/samples/client/petstore/javascript-promise/src/api/UserApi.js index ff8f745735d..7ffd940184b 100644 --- a/samples/client/petstore/javascript-promise/src/api/UserApi.js +++ b/samples/client/petstore/javascript-promise/src/api/UserApi.js @@ -1,3 +1,27 @@ +/** + * Swagger Petstore + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * 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. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + (function(root, factory) { if (typeof define === 'function' && define.amd) { // AMD. Register as an anonymous module. diff --git a/samples/client/petstore/javascript-promise/src/index.js b/samples/client/petstore/javascript-promise/src/index.js index 727b4782f45..93f2e6cd4b8 100644 --- a/samples/client/petstore/javascript-promise/src/index.js +++ b/samples/client/petstore/javascript-promise/src/index.js @@ -1,16 +1,40 @@ +/** + * Swagger Petstore + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * 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. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + (function(factory) { if (typeof define === 'function' && define.amd) { // AMD. Register as an anonymous module. - define(['ApiClient', 'model/Animal', 'model/AnimalFarm', 'model/ApiResponse', 'model/Cat', 'model/Category', 'model/Dog', 'model/EnumClass', 'model/EnumTest', 'model/FormatTest', 'model/Model200Response', 'model/ModelReturn', 'model/Name', 'model/Order', 'model/Pet', 'model/SpecialModelName', 'model/Tag', 'model/User', 'api/FakeApi', 'api/PetApi', 'api/StoreApi', 'api/UserApi'], factory); + define(['ApiClient', 'model/AdditionalPropertiesClass', 'model/Animal', 'model/AnimalFarm', 'model/ApiResponse', 'model/ArrayTest', 'model/Cat', 'model/Category', 'model/Dog', 'model/EnumClass', 'model/EnumTest', 'model/FormatTest', 'model/MixedPropertiesAndAdditionalPropertiesClass', 'model/Model200Response', 'model/ModelReturn', 'model/Name', 'model/Order', 'model/Pet', 'model/ReadOnlyFirst', 'model/SpecialModelName', 'model/Tag', 'model/User', 'api/FakeApi', 'api/PetApi', 'api/StoreApi', 'api/UserApi'], factory); } else if (typeof module === 'object' && module.exports) { // CommonJS-like environments that support module.exports, like Node. - module.exports = factory(require('./ApiClient'), require('./model/Animal'), require('./model/AnimalFarm'), require('./model/ApiResponse'), require('./model/Cat'), require('./model/Category'), require('./model/Dog'), require('./model/EnumClass'), require('./model/EnumTest'), require('./model/FormatTest'), require('./model/Model200Response'), require('./model/ModelReturn'), require('./model/Name'), require('./model/Order'), require('./model/Pet'), require('./model/SpecialModelName'), require('./model/Tag'), require('./model/User'), require('./api/FakeApi'), require('./api/PetApi'), require('./api/StoreApi'), require('./api/UserApi')); + module.exports = factory(require('./ApiClient'), require('./model/AdditionalPropertiesClass'), require('./model/Animal'), require('./model/AnimalFarm'), require('./model/ApiResponse'), require('./model/ArrayTest'), require('./model/Cat'), require('./model/Category'), require('./model/Dog'), require('./model/EnumClass'), require('./model/EnumTest'), require('./model/FormatTest'), require('./model/MixedPropertiesAndAdditionalPropertiesClass'), require('./model/Model200Response'), require('./model/ModelReturn'), require('./model/Name'), require('./model/Order'), require('./model/Pet'), require('./model/ReadOnlyFirst'), require('./model/SpecialModelName'), require('./model/Tag'), require('./model/User'), require('./api/FakeApi'), require('./api/PetApi'), require('./api/StoreApi'), require('./api/UserApi')); } -}(function(ApiClient, Animal, AnimalFarm, ApiResponse, Cat, Category, Dog, EnumClass, EnumTest, FormatTest, Model200Response, ModelReturn, Name, Order, Pet, SpecialModelName, Tag, User, FakeApi, PetApi, StoreApi, UserApi) { +}(function(ApiClient, AdditionalPropertiesClass, Animal, AnimalFarm, ApiResponse, ArrayTest, Cat, Category, Dog, EnumClass, EnumTest, FormatTest, MixedPropertiesAndAdditionalPropertiesClass, Model200Response, ModelReturn, Name, Order, Pet, ReadOnlyFirst, SpecialModelName, Tag, User, FakeApi, PetApi, StoreApi, UserApi) { 'use strict'; /** - * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose..
+ * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ .
* The index module provides access to constructors for all the classes which comprise the public API. *

* An AMD (recommended!) or CommonJS application will generally do something equivalent to the following: @@ -46,6 +70,11 @@ * @property {module:ApiClient} */ ApiClient: ApiClient, + /** + * The AdditionalPropertiesClass model constructor. + * @property {module:model/AdditionalPropertiesClass} + */ + AdditionalPropertiesClass: AdditionalPropertiesClass, /** * The Animal model constructor. * @property {module:model/Animal} @@ -61,6 +90,11 @@ * @property {module:model/ApiResponse} */ ApiResponse: ApiResponse, + /** + * The ArrayTest model constructor. + * @property {module:model/ArrayTest} + */ + ArrayTest: ArrayTest, /** * The Cat model constructor. * @property {module:model/Cat} @@ -91,6 +125,11 @@ * @property {module:model/FormatTest} */ FormatTest: FormatTest, + /** + * The MixedPropertiesAndAdditionalPropertiesClass model constructor. + * @property {module:model/MixedPropertiesAndAdditionalPropertiesClass} + */ + MixedPropertiesAndAdditionalPropertiesClass: MixedPropertiesAndAdditionalPropertiesClass, /** * The Model200Response model constructor. * @property {module:model/Model200Response} @@ -116,6 +155,11 @@ * @property {module:model/Pet} */ Pet: Pet, + /** + * The ReadOnlyFirst model constructor. + * @property {module:model/ReadOnlyFirst} + */ + ReadOnlyFirst: ReadOnlyFirst, /** * The SpecialModelName model constructor. * @property {module:model/SpecialModelName} diff --git a/samples/client/petstore/javascript-promise/src/model/AdditionalPropertiesClass.js b/samples/client/petstore/javascript-promise/src/model/AdditionalPropertiesClass.js new file mode 100644 index 00000000000..10183b1ea43 --- /dev/null +++ b/samples/client/petstore/javascript-promise/src/model/AdditionalPropertiesClass.js @@ -0,0 +1,99 @@ +/** + * Swagger Petstore + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * 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. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +(function(root, factory) { + if (typeof define === 'function' && define.amd) { + // AMD. Register as an anonymous module. + define(['ApiClient'], factory); + } else if (typeof module === 'object' && module.exports) { + // CommonJS-like environments that support module.exports, like Node. + module.exports = factory(require('../ApiClient')); + } else { + // Browser globals (root is window) + if (!root.SwaggerPetstore) { + root.SwaggerPetstore = {}; + } + root.SwaggerPetstore.AdditionalPropertiesClass = factory(root.SwaggerPetstore.ApiClient); + } +}(this, function(ApiClient) { + 'use strict'; + + + + + /** + * The AdditionalPropertiesClass model module. + * @module model/AdditionalPropertiesClass + * @version 1.0.0 + */ + + /** + * Constructs a new AdditionalPropertiesClass. + * @alias module:model/AdditionalPropertiesClass + * @class + */ + var exports = function() { + var _this = this; + + + + }; + + /** + * Constructs a AdditionalPropertiesClass from a plain JavaScript object, optionally creating a new instance. + * Copies all relevant properties from data to obj if supplied or a new instance if not. + * @param {Object} data The plain JavaScript object bearing properties of interest. + * @param {module:model/AdditionalPropertiesClass} obj Optional instance to populate. + * @return {module:model/AdditionalPropertiesClass} The populated AdditionalPropertiesClass instance. + */ + exports.constructFromObject = function(data, obj) { + if (data) { + obj = obj || new exports(); + + if (data.hasOwnProperty('map_property')) { + obj['map_property'] = ApiClient.convertToType(data['map_property'], {'String': 'String'}); + } + if (data.hasOwnProperty('map_of_map_property')) { + obj['map_of_map_property'] = ApiClient.convertToType(data['map_of_map_property'], {'String': {'String': 'String'}}); + } + } + return obj; + } + + /** + * @member {Object.} map_property + */ + exports.prototype['map_property'] = undefined; + /** + * @member {Object.>} map_of_map_property + */ + exports.prototype['map_of_map_property'] = undefined; + + + + + return exports; +})); + + diff --git a/samples/client/petstore/javascript-promise/src/model/Animal.js b/samples/client/petstore/javascript-promise/src/model/Animal.js index e42874c669b..32042951cb1 100644 --- a/samples/client/petstore/javascript-promise/src/model/Animal.js +++ b/samples/client/petstore/javascript-promise/src/model/Animal.js @@ -1,3 +1,27 @@ +/** + * Swagger Petstore + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * 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. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + (function(root, factory) { if (typeof define === 'function' && define.amd) { // AMD. Register as an anonymous module. @@ -34,6 +58,7 @@ var _this = this; _this['className'] = className; + }; /** @@ -50,6 +75,9 @@ if (data.hasOwnProperty('className')) { obj['className'] = ApiClient.convertToType(data['className'], 'String'); } + if (data.hasOwnProperty('color')) { + obj['color'] = ApiClient.convertToType(data['color'], 'String'); + } } return obj; } @@ -58,6 +86,11 @@ * @member {String} className */ exports.prototype['className'] = undefined; + /** + * @member {String} color + * @default 'red' + */ + exports.prototype['color'] = 'red'; diff --git a/samples/client/petstore/javascript-promise/src/model/AnimalFarm.js b/samples/client/petstore/javascript-promise/src/model/AnimalFarm.js index d5f6aa2a424..1a54e0d611a 100644 --- a/samples/client/petstore/javascript-promise/src/model/AnimalFarm.js +++ b/samples/client/petstore/javascript-promise/src/model/AnimalFarm.js @@ -1,3 +1,27 @@ +/** + * Swagger Petstore + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * 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. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + (function(root, factory) { if (typeof define === 'function' && define.amd) { // AMD. Register as an anonymous module. diff --git a/samples/client/petstore/javascript-promise/src/model/ApiResponse.js b/samples/client/petstore/javascript-promise/src/model/ApiResponse.js index 6d4c970264b..1cb041898d4 100644 --- a/samples/client/petstore/javascript-promise/src/model/ApiResponse.js +++ b/samples/client/petstore/javascript-promise/src/model/ApiResponse.js @@ -1,3 +1,27 @@ +/** + * Swagger Petstore + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * 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. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + (function(root, factory) { if (typeof define === 'function' && define.amd) { // AMD. Register as an anonymous module. diff --git a/samples/client/petstore/javascript-promise/src/model/ArrayTest.js b/samples/client/petstore/javascript-promise/src/model/ArrayTest.js new file mode 100644 index 00000000000..a2589f7ea0a --- /dev/null +++ b/samples/client/petstore/javascript-promise/src/model/ArrayTest.js @@ -0,0 +1,107 @@ +/** + * Swagger Petstore + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * 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. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +(function(root, factory) { + if (typeof define === 'function' && define.amd) { + // AMD. Register as an anonymous module. + define(['ApiClient'], factory); + } else if (typeof module === 'object' && module.exports) { + // CommonJS-like environments that support module.exports, like Node. + module.exports = factory(require('../ApiClient')); + } else { + // Browser globals (root is window) + if (!root.SwaggerPetstore) { + root.SwaggerPetstore = {}; + } + root.SwaggerPetstore.ArrayTest = factory(root.SwaggerPetstore.ApiClient); + } +}(this, function(ApiClient) { + 'use strict'; + + + + + /** + * The ArrayTest model module. + * @module model/ArrayTest + * @version 1.0.0 + */ + + /** + * Constructs a new ArrayTest. + * @alias module:model/ArrayTest + * @class + */ + var exports = function() { + var _this = this; + + + + + }; + + /** + * Constructs a ArrayTest from a plain JavaScript object, optionally creating a new instance. + * Copies all relevant properties from data to obj if supplied or a new instance if not. + * @param {Object} data The plain JavaScript object bearing properties of interest. + * @param {module:model/ArrayTest} obj Optional instance to populate. + * @return {module:model/ArrayTest} The populated ArrayTest instance. + */ + exports.constructFromObject = function(data, obj) { + if (data) { + obj = obj || new exports(); + + if (data.hasOwnProperty('array_of_string')) { + obj['array_of_string'] = ApiClient.convertToType(data['array_of_string'], ['String']); + } + if (data.hasOwnProperty('array_array_of_integer')) { + obj['array_array_of_integer'] = ApiClient.convertToType(data['array_array_of_integer'], [['Integer']]); + } + if (data.hasOwnProperty('array_array_of_model')) { + obj['array_array_of_model'] = ApiClient.convertToType(data['array_array_of_model'], [[ReadOnlyFirst]]); + } + } + return obj; + } + + /** + * @member {Array.} array_of_string + */ + exports.prototype['array_of_string'] = undefined; + /** + * @member {Array.>} array_array_of_integer + */ + exports.prototype['array_array_of_integer'] = undefined; + /** + * @member {Array.>} array_array_of_model + */ + exports.prototype['array_array_of_model'] = undefined; + + + + + return exports; +})); + + diff --git a/samples/client/petstore/javascript-promise/src/model/Cat.js b/samples/client/petstore/javascript-promise/src/model/Cat.js index a6b25bc6d58..e6a771019f3 100644 --- a/samples/client/petstore/javascript-promise/src/model/Cat.js +++ b/samples/client/petstore/javascript-promise/src/model/Cat.js @@ -1,3 +1,27 @@ +/** + * Swagger Petstore + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * 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. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + (function(root, factory) { if (typeof define === 'function' && define.amd) { // AMD. Register as an anonymous module. diff --git a/samples/client/petstore/javascript-promise/src/model/Category.js b/samples/client/petstore/javascript-promise/src/model/Category.js index 9e2e19ac5bb..c415cbd1943 100644 --- a/samples/client/petstore/javascript-promise/src/model/Category.js +++ b/samples/client/petstore/javascript-promise/src/model/Category.js @@ -1,3 +1,27 @@ +/** + * Swagger Petstore + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * 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. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + (function(root, factory) { if (typeof define === 'function' && define.amd) { // AMD. Register as an anonymous module. diff --git a/samples/client/petstore/javascript-promise/src/model/Dog.js b/samples/client/petstore/javascript-promise/src/model/Dog.js index ee17ae3467f..719237dadd7 100644 --- a/samples/client/petstore/javascript-promise/src/model/Dog.js +++ b/samples/client/petstore/javascript-promise/src/model/Dog.js @@ -1,3 +1,27 @@ +/** + * Swagger Petstore + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * 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. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + (function(root, factory) { if (typeof define === 'function' && define.amd) { // AMD. Register as an anonymous module. diff --git a/samples/client/petstore/javascript-promise/src/model/EnumClass.js b/samples/client/petstore/javascript-promise/src/model/EnumClass.js index e9bf5219ee5..b0bb7813e7d 100644 --- a/samples/client/petstore/javascript-promise/src/model/EnumClass.js +++ b/samples/client/petstore/javascript-promise/src/model/EnumClass.js @@ -1,3 +1,27 @@ +/** + * Swagger Petstore + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * 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. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + (function(root, factory) { if (typeof define === 'function' && define.amd) { // AMD. Register as an anonymous module. diff --git a/samples/client/petstore/javascript-promise/src/model/EnumTest.js b/samples/client/petstore/javascript-promise/src/model/EnumTest.js index 6f8f0de3836..0ab961078b0 100644 --- a/samples/client/petstore/javascript-promise/src/model/EnumTest.js +++ b/samples/client/petstore/javascript-promise/src/model/EnumTest.js @@ -1,3 +1,27 @@ +/** + * Swagger Petstore + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * 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. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + (function(root, factory) { if (typeof define === 'function' && define.amd) { // AMD. Register as an anonymous module. diff --git a/samples/client/petstore/javascript-promise/src/model/FormatTest.js b/samples/client/petstore/javascript-promise/src/model/FormatTest.js index ed9e0cfcaf8..7a941cb5ffa 100644 --- a/samples/client/petstore/javascript-promise/src/model/FormatTest.js +++ b/samples/client/petstore/javascript-promise/src/model/FormatTest.js @@ -1,3 +1,27 @@ +/** + * Swagger Petstore + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * 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. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + (function(root, factory) { if (typeof define === 'function' && define.amd) { // AMD. Register as an anonymous module. diff --git a/samples/client/petstore/javascript-promise/src/model/MixedPropertiesAndAdditionalPropertiesClass.js b/samples/client/petstore/javascript-promise/src/model/MixedPropertiesAndAdditionalPropertiesClass.js new file mode 100644 index 00000000000..1db531b401f --- /dev/null +++ b/samples/client/petstore/javascript-promise/src/model/MixedPropertiesAndAdditionalPropertiesClass.js @@ -0,0 +1,107 @@ +/** + * Swagger Petstore + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * 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. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +(function(root, factory) { + if (typeof define === 'function' && define.amd) { + // AMD. Register as an anonymous module. + define(['ApiClient', 'model/Animal'], factory); + } else if (typeof module === 'object' && module.exports) { + // CommonJS-like environments that support module.exports, like Node. + module.exports = factory(require('../ApiClient'), require('./Animal')); + } else { + // Browser globals (root is window) + if (!root.SwaggerPetstore) { + root.SwaggerPetstore = {}; + } + root.SwaggerPetstore.MixedPropertiesAndAdditionalPropertiesClass = factory(root.SwaggerPetstore.ApiClient, root.SwaggerPetstore.Animal); + } +}(this, function(ApiClient, Animal) { + 'use strict'; + + + + + /** + * The MixedPropertiesAndAdditionalPropertiesClass model module. + * @module model/MixedPropertiesAndAdditionalPropertiesClass + * @version 1.0.0 + */ + + /** + * Constructs a new MixedPropertiesAndAdditionalPropertiesClass. + * @alias module:model/MixedPropertiesAndAdditionalPropertiesClass + * @class + */ + var exports = function() { + var _this = this; + + + + + }; + + /** + * Constructs a MixedPropertiesAndAdditionalPropertiesClass from a plain JavaScript object, optionally creating a new instance. + * Copies all relevant properties from data to obj if supplied or a new instance if not. + * @param {Object} data The plain JavaScript object bearing properties of interest. + * @param {module:model/MixedPropertiesAndAdditionalPropertiesClass} obj Optional instance to populate. + * @return {module:model/MixedPropertiesAndAdditionalPropertiesClass} The populated MixedPropertiesAndAdditionalPropertiesClass instance. + */ + exports.constructFromObject = function(data, obj) { + if (data) { + obj = obj || new exports(); + + if (data.hasOwnProperty('uuid')) { + obj['uuid'] = ApiClient.convertToType(data['uuid'], 'String'); + } + if (data.hasOwnProperty('dateTime')) { + obj['dateTime'] = ApiClient.convertToType(data['dateTime'], 'Date'); + } + if (data.hasOwnProperty('map')) { + obj['map'] = ApiClient.convertToType(data['map'], {'String': Animal}); + } + } + return obj; + } + + /** + * @member {String} uuid + */ + exports.prototype['uuid'] = undefined; + /** + * @member {Date} dateTime + */ + exports.prototype['dateTime'] = undefined; + /** + * @member {Object.} map + */ + exports.prototype['map'] = undefined; + + + + + return exports; +})); + + diff --git a/samples/client/petstore/javascript-promise/src/model/Model200Response.js b/samples/client/petstore/javascript-promise/src/model/Model200Response.js index 1d83d420287..21ea07b2c39 100644 --- a/samples/client/petstore/javascript-promise/src/model/Model200Response.js +++ b/samples/client/petstore/javascript-promise/src/model/Model200Response.js @@ -1,3 +1,27 @@ +/** + * Swagger Petstore + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * 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. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + (function(root, factory) { if (typeof define === 'function' && define.amd) { // AMD. Register as an anonymous module. diff --git a/samples/client/petstore/javascript-promise/src/model/ModelReturn.js b/samples/client/petstore/javascript-promise/src/model/ModelReturn.js index d0236e77b17..b9dec2d30c4 100644 --- a/samples/client/petstore/javascript-promise/src/model/ModelReturn.js +++ b/samples/client/petstore/javascript-promise/src/model/ModelReturn.js @@ -1,3 +1,27 @@ +/** + * Swagger Petstore + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * 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. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + (function(root, factory) { if (typeof define === 'function' && define.amd) { // AMD. Register as an anonymous module. diff --git a/samples/client/petstore/javascript-promise/src/model/Name.js b/samples/client/petstore/javascript-promise/src/model/Name.js index 93d1d55deb2..cae738e0d90 100644 --- a/samples/client/petstore/javascript-promise/src/model/Name.js +++ b/samples/client/petstore/javascript-promise/src/model/Name.js @@ -1,3 +1,27 @@ +/** + * Swagger Petstore + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * 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. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + (function(root, factory) { if (typeof define === 'function' && define.amd) { // AMD. Register as an anonymous module. @@ -37,6 +61,7 @@ _this['name'] = name; + }; /** @@ -59,6 +84,9 @@ if (data.hasOwnProperty('property')) { obj['property'] = ApiClient.convertToType(data['property'], 'String'); } + if (data.hasOwnProperty('123Number')) { + obj['123Number'] = ApiClient.convertToType(data['123Number'], 'Integer'); + } } return obj; } @@ -75,6 +103,10 @@ * @member {String} property */ exports.prototype['property'] = undefined; + /** + * @member {Integer} 123Number + */ + exports.prototype['123Number'] = undefined; diff --git a/samples/client/petstore/javascript-promise/src/model/Order.js b/samples/client/petstore/javascript-promise/src/model/Order.js index 57f77d84ccd..f2b3726a04c 100644 --- a/samples/client/petstore/javascript-promise/src/model/Order.js +++ b/samples/client/petstore/javascript-promise/src/model/Order.js @@ -1,3 +1,27 @@ +/** + * Swagger Petstore + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * 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. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + (function(root, factory) { if (typeof define === 'function' && define.amd) { // AMD. Register as an anonymous module. diff --git a/samples/client/petstore/javascript-promise/src/model/Pet.js b/samples/client/petstore/javascript-promise/src/model/Pet.js index fe14361dbf2..19ed2096877 100644 --- a/samples/client/petstore/javascript-promise/src/model/Pet.js +++ b/samples/client/petstore/javascript-promise/src/model/Pet.js @@ -1,3 +1,27 @@ +/** + * Swagger Petstore + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * 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. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + (function(root, factory) { if (typeof define === 'function' && define.amd) { // AMD. Register as an anonymous module. diff --git a/samples/client/petstore/javascript-promise/src/model/ReadOnlyFirst.js b/samples/client/petstore/javascript-promise/src/model/ReadOnlyFirst.js new file mode 100644 index 00000000000..8ceb17f58bb --- /dev/null +++ b/samples/client/petstore/javascript-promise/src/model/ReadOnlyFirst.js @@ -0,0 +1,99 @@ +/** + * Swagger Petstore + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * 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. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +(function(root, factory) { + if (typeof define === 'function' && define.amd) { + // AMD. Register as an anonymous module. + define(['ApiClient'], factory); + } else if (typeof module === 'object' && module.exports) { + // CommonJS-like environments that support module.exports, like Node. + module.exports = factory(require('../ApiClient')); + } else { + // Browser globals (root is window) + if (!root.SwaggerPetstore) { + root.SwaggerPetstore = {}; + } + root.SwaggerPetstore.ReadOnlyFirst = factory(root.SwaggerPetstore.ApiClient); + } +}(this, function(ApiClient) { + 'use strict'; + + + + + /** + * The ReadOnlyFirst model module. + * @module model/ReadOnlyFirst + * @version 1.0.0 + */ + + /** + * Constructs a new ReadOnlyFirst. + * @alias module:model/ReadOnlyFirst + * @class + */ + var exports = function() { + var _this = this; + + + + }; + + /** + * Constructs a ReadOnlyFirst from a plain JavaScript object, optionally creating a new instance. + * Copies all relevant properties from data to obj if supplied or a new instance if not. + * @param {Object} data The plain JavaScript object bearing properties of interest. + * @param {module:model/ReadOnlyFirst} obj Optional instance to populate. + * @return {module:model/ReadOnlyFirst} The populated ReadOnlyFirst instance. + */ + exports.constructFromObject = function(data, obj) { + if (data) { + obj = obj || new exports(); + + if (data.hasOwnProperty('bar')) { + obj['bar'] = ApiClient.convertToType(data['bar'], 'String'); + } + if (data.hasOwnProperty('baz')) { + obj['baz'] = ApiClient.convertToType(data['baz'], 'String'); + } + } + return obj; + } + + /** + * @member {String} bar + */ + exports.prototype['bar'] = undefined; + /** + * @member {String} baz + */ + exports.prototype['baz'] = undefined; + + + + + return exports; +})); + + diff --git a/samples/client/petstore/javascript-promise/src/model/SpecialModelName.js b/samples/client/petstore/javascript-promise/src/model/SpecialModelName.js index d5a0e992a73..f06c2e46556 100644 --- a/samples/client/petstore/javascript-promise/src/model/SpecialModelName.js +++ b/samples/client/petstore/javascript-promise/src/model/SpecialModelName.js @@ -1,3 +1,27 @@ +/** + * Swagger Petstore + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * 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. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + (function(root, factory) { if (typeof define === 'function' && define.amd) { // AMD. Register as an anonymous module. diff --git a/samples/client/petstore/javascript-promise/src/model/Tag.js b/samples/client/petstore/javascript-promise/src/model/Tag.js index 443d312b76a..8e188616107 100644 --- a/samples/client/petstore/javascript-promise/src/model/Tag.js +++ b/samples/client/petstore/javascript-promise/src/model/Tag.js @@ -1,3 +1,27 @@ +/** + * Swagger Petstore + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * 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. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + (function(root, factory) { if (typeof define === 'function' && define.amd) { // AMD. Register as an anonymous module. diff --git a/samples/client/petstore/javascript-promise/src/model/User.js b/samples/client/petstore/javascript-promise/src/model/User.js index 2360c7c6314..df334f1e623 100644 --- a/samples/client/petstore/javascript-promise/src/model/User.js +++ b/samples/client/petstore/javascript-promise/src/model/User.js @@ -1,3 +1,27 @@ +/** + * Swagger Petstore + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * 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. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + (function(root, factory) { if (typeof define === 'function' && define.amd) { // AMD. Register as an anonymous module. diff --git a/samples/client/petstore/javascript-promise/test/api/FakeApi.spec.js b/samples/client/petstore/javascript-promise/test/api/FakeApi.spec.js new file mode 100644 index 00000000000..47725845b51 --- /dev/null +++ b/samples/client/petstore/javascript-promise/test/api/FakeApi.spec.js @@ -0,0 +1,74 @@ +/** + * Swagger Petstore + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * 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. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +(function(root, factory) { + if (typeof define === 'function' && define.amd) { + // AMD. + define(['expect.js', '../../src/index'], factory); + } else if (typeof module === 'object' && module.exports) { + // CommonJS-like environments that support module.exports, like Node. + factory(require('expect.js'), require('../../src/index')); + } else { + // Browser globals (root is window) + factory(root.expect, root.SwaggerPetstore); + } +}(this, function(expect, SwaggerPetstore) { + 'use strict'; + + var instance; + + beforeEach(function() { + instance = new SwaggerPetstore.FakeApi(); + }); + + var getProperty = function(object, getter, property) { + // Use getter method if present; otherwise, get the property directly. + if (typeof object[getter] === 'function') + return object[getter](); + else + return object[property]; + } + + var setProperty = function(object, setter, property, value) { + // Use setter method if present; otherwise, set the property directly. + if (typeof object[setter] === 'function') + object[setter](value); + else + object[property] = value; + } + + describe('FakeApi', function() { + describe('testEndpointParameters', function() { + it('should call testEndpointParameters successfully', function(done) { + //uncomment below and update the code to test testEndpointParameters + //instance.testEndpointParameters(pet, function(error) { + // if (error) throw error; + //expect().to.be(); + //}); + done(); + }); + }); + }); + +})); diff --git a/samples/client/petstore/javascript-promise/test/api/PetApiTest.js b/samples/client/petstore/javascript-promise/test/api/PetApi.spec.js similarity index 100% rename from samples/client/petstore/javascript-promise/test/api/PetApiTest.js rename to samples/client/petstore/javascript-promise/test/api/PetApi.spec.js diff --git a/samples/client/petstore/javascript-promise/test/api/StoreApi.spec.js b/samples/client/petstore/javascript-promise/test/api/StoreApi.spec.js new file mode 100644 index 00000000000..d4fd52c56a5 --- /dev/null +++ b/samples/client/petstore/javascript-promise/test/api/StoreApi.spec.js @@ -0,0 +1,104 @@ +/** + * Swagger Petstore + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * 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. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +(function(root, factory) { + if (typeof define === 'function' && define.amd) { + // AMD. + define(['expect.js', '../../src/index'], factory); + } else if (typeof module === 'object' && module.exports) { + // CommonJS-like environments that support module.exports, like Node. + factory(require('expect.js'), require('../../src/index')); + } else { + // Browser globals (root is window) + factory(root.expect, root.SwaggerPetstore); + } +}(this, function(expect, SwaggerPetstore) { + 'use strict'; + + var instance; + + beforeEach(function() { + instance = new SwaggerPetstore.StoreApi(); + }); + + var getProperty = function(object, getter, property) { + // Use getter method if present; otherwise, get the property directly. + if (typeof object[getter] === 'function') + return object[getter](); + else + return object[property]; + } + + var setProperty = function(object, setter, property, value) { + // Use setter method if present; otherwise, set the property directly. + if (typeof object[setter] === 'function') + object[setter](value); + else + object[property] = value; + } + + describe('StoreApi', function() { + describe('deleteOrder', function() { + it('should call deleteOrder successfully', function(done) { + //uncomment below and update the code to test deleteOrder + //instance.deleteOrder(pet, function(error) { + // if (error) throw error; + //expect().to.be(); + //}); + done(); + }); + }); + describe('getInventory', function() { + it('should call getInventory successfully', function(done) { + //uncomment below and update the code to test getInventory + //instance.getInventory(pet, function(error) { + // if (error) throw error; + //expect().to.be(); + //}); + done(); + }); + }); + describe('getOrderById', function() { + it('should call getOrderById successfully', function(done) { + //uncomment below and update the code to test getOrderById + //instance.getOrderById(pet, function(error) { + // if (error) throw error; + //expect().to.be(); + //}); + done(); + }); + }); + describe('placeOrder', function() { + it('should call placeOrder successfully', function(done) { + //uncomment below and update the code to test placeOrder + //instance.placeOrder(pet, function(error) { + // if (error) throw error; + //expect().to.be(); + //}); + done(); + }); + }); + }); + +})); diff --git a/samples/client/petstore/javascript-promise/test/api/UserApi.spec.js b/samples/client/petstore/javascript-promise/test/api/UserApi.spec.js new file mode 100644 index 00000000000..f020f612b5b --- /dev/null +++ b/samples/client/petstore/javascript-promise/test/api/UserApi.spec.js @@ -0,0 +1,144 @@ +/** + * Swagger Petstore + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * 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. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +(function(root, factory) { + if (typeof define === 'function' && define.amd) { + // AMD. + define(['expect.js', '../../src/index'], factory); + } else if (typeof module === 'object' && module.exports) { + // CommonJS-like environments that support module.exports, like Node. + factory(require('expect.js'), require('../../src/index')); + } else { + // Browser globals (root is window) + factory(root.expect, root.SwaggerPetstore); + } +}(this, function(expect, SwaggerPetstore) { + 'use strict'; + + var instance; + + beforeEach(function() { + instance = new SwaggerPetstore.UserApi(); + }); + + var getProperty = function(object, getter, property) { + // Use getter method if present; otherwise, get the property directly. + if (typeof object[getter] === 'function') + return object[getter](); + else + return object[property]; + } + + var setProperty = function(object, setter, property, value) { + // Use setter method if present; otherwise, set the property directly. + if (typeof object[setter] === 'function') + object[setter](value); + else + object[property] = value; + } + + describe('UserApi', function() { + describe('createUser', function() { + it('should call createUser successfully', function(done) { + //uncomment below and update the code to test createUser + //instance.createUser(pet, function(error) { + // if (error) throw error; + //expect().to.be(); + //}); + done(); + }); + }); + describe('createUsersWithArrayInput', function() { + it('should call createUsersWithArrayInput successfully', function(done) { + //uncomment below and update the code to test createUsersWithArrayInput + //instance.createUsersWithArrayInput(pet, function(error) { + // if (error) throw error; + //expect().to.be(); + //}); + done(); + }); + }); + describe('createUsersWithListInput', function() { + it('should call createUsersWithListInput successfully', function(done) { + //uncomment below and update the code to test createUsersWithListInput + //instance.createUsersWithListInput(pet, function(error) { + // if (error) throw error; + //expect().to.be(); + //}); + done(); + }); + }); + describe('deleteUser', function() { + it('should call deleteUser successfully', function(done) { + //uncomment below and update the code to test deleteUser + //instance.deleteUser(pet, function(error) { + // if (error) throw error; + //expect().to.be(); + //}); + done(); + }); + }); + describe('getUserByName', function() { + it('should call getUserByName successfully', function(done) { + //uncomment below and update the code to test getUserByName + //instance.getUserByName(pet, function(error) { + // if (error) throw error; + //expect().to.be(); + //}); + done(); + }); + }); + describe('loginUser', function() { + it('should call loginUser successfully', function(done) { + //uncomment below and update the code to test loginUser + //instance.loginUser(pet, function(error) { + // if (error) throw error; + //expect().to.be(); + //}); + done(); + }); + }); + describe('logoutUser', function() { + it('should call logoutUser successfully', function(done) { + //uncomment below and update the code to test logoutUser + //instance.logoutUser(pet, function(error) { + // if (error) throw error; + //expect().to.be(); + //}); + done(); + }); + }); + describe('updateUser', function() { + it('should call updateUser successfully', function(done) { + //uncomment below and update the code to test updateUser + //instance.updateUser(pet, function(error) { + // if (error) throw error; + //expect().to.be(); + //}); + done(); + }); + }); + }); + +})); diff --git a/samples/client/petstore/javascript-promise/test/model/AdditionalPropertiesClass.spec.js b/samples/client/petstore/javascript-promise/test/model/AdditionalPropertiesClass.spec.js new file mode 100644 index 00000000000..cb5bdef3e4f --- /dev/null +++ b/samples/client/petstore/javascript-promise/test/model/AdditionalPropertiesClass.spec.js @@ -0,0 +1,82 @@ +/** + * Swagger Petstore + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * 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. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +(function(root, factory) { + if (typeof define === 'function' && define.amd) { + // AMD. + define(['expect.js', '../../src/index'], factory); + } else if (typeof module === 'object' && module.exports) { + // CommonJS-like environments that support module.exports, like Node. + factory(require('expect.js'), require('../../src/index')); + } else { + // Browser globals (root is window) + factory(root.expect, root.SwaggerPetstore); + } +}(this, function(expect, SwaggerPetstore) { + 'use strict'; + + var instance; + + beforeEach(function() { + instance = new SwaggerPetstore.AdditionalPropertiesClass(); + }); + + var getProperty = function(object, getter, property) { + // Use getter method if present; otherwise, get the property directly. + if (typeof object[getter] === 'function') + return object[getter](); + else + return object[property]; + } + + var setProperty = function(object, setter, property, value) { + // Use setter method if present; otherwise, set the property directly. + if (typeof object[setter] === 'function') + object[setter](value); + else + object[property] = value; + } + + describe('AdditionalPropertiesClass', function() { + it('should create an instance of AdditionalPropertiesClass', function() { + // uncomment below and update the code to test AdditionalPropertiesClass + //var instane = new SwaggerPetstore.AdditionalPropertiesClass(); + //expect(instance).to.be.a(SwaggerPetstore.AdditionalPropertiesClass); + }); + + it('should have the property mapProperty (base name: "map_property")', function() { + // uncomment below and update the code to test the property mapProperty + //var instane = new SwaggerPetstore.AdditionalPropertiesClass(); + //expect(instance).to.be(); + }); + + it('should have the property mapOfMapProperty (base name: "map_of_map_property")', function() { + // uncomment below and update the code to test the property mapOfMapProperty + //var instane = new SwaggerPetstore.AdditionalPropertiesClass(); + //expect(instance).to.be(); + }); + + }); + +})); diff --git a/samples/client/petstore/javascript-promise/test/model/Animal.spec.js b/samples/client/petstore/javascript-promise/test/model/Animal.spec.js new file mode 100644 index 00000000000..8995fe76806 --- /dev/null +++ b/samples/client/petstore/javascript-promise/test/model/Animal.spec.js @@ -0,0 +1,82 @@ +/** + * Swagger Petstore + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * 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. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +(function(root, factory) { + if (typeof define === 'function' && define.amd) { + // AMD. + define(['expect.js', '../../src/index'], factory); + } else if (typeof module === 'object' && module.exports) { + // CommonJS-like environments that support module.exports, like Node. + factory(require('expect.js'), require('../../src/index')); + } else { + // Browser globals (root is window) + factory(root.expect, root.SwaggerPetstore); + } +}(this, function(expect, SwaggerPetstore) { + 'use strict'; + + var instance; + + beforeEach(function() { + instance = new SwaggerPetstore.Animal(); + }); + + var getProperty = function(object, getter, property) { + // Use getter method if present; otherwise, get the property directly. + if (typeof object[getter] === 'function') + return object[getter](); + else + return object[property]; + } + + var setProperty = function(object, setter, property, value) { + // Use setter method if present; otherwise, set the property directly. + if (typeof object[setter] === 'function') + object[setter](value); + else + object[property] = value; + } + + describe('Animal', function() { + it('should create an instance of Animal', function() { + // uncomment below and update the code to test Animal + //var instane = new SwaggerPetstore.Animal(); + //expect(instance).to.be.a(SwaggerPetstore.Animal); + }); + + it('should have the property className (base name: "className")', function() { + // uncomment below and update the code to test the property className + //var instane = new SwaggerPetstore.Animal(); + //expect(instance).to.be(); + }); + + it('should have the property color (base name: "color")', function() { + // uncomment below and update the code to test the property color + //var instane = new SwaggerPetstore.Animal(); + //expect(instance).to.be(); + }); + + }); + +})); diff --git a/samples/client/petstore/javascript-promise/test/model/AnimalFarm.spec.js b/samples/client/petstore/javascript-promise/test/model/AnimalFarm.spec.js new file mode 100644 index 00000000000..f030047b563 --- /dev/null +++ b/samples/client/petstore/javascript-promise/test/model/AnimalFarm.spec.js @@ -0,0 +1,70 @@ +/** + * Swagger Petstore + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * 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. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +(function(root, factory) { + if (typeof define === 'function' && define.amd) { + // AMD. + define(['expect.js', '../../src/index'], factory); + } else if (typeof module === 'object' && module.exports) { + // CommonJS-like environments that support module.exports, like Node. + factory(require('expect.js'), require('../../src/index')); + } else { + // Browser globals (root is window) + factory(root.expect, root.SwaggerPetstore); + } +}(this, function(expect, SwaggerPetstore) { + 'use strict'; + + var instance; + + beforeEach(function() { + instance = new SwaggerPetstore.AnimalFarm(); + }); + + var getProperty = function(object, getter, property) { + // Use getter method if present; otherwise, get the property directly. + if (typeof object[getter] === 'function') + return object[getter](); + else + return object[property]; + } + + var setProperty = function(object, setter, property, value) { + // Use setter method if present; otherwise, set the property directly. + if (typeof object[setter] === 'function') + object[setter](value); + else + object[property] = value; + } + + describe('AnimalFarm', function() { + it('should create an instance of AnimalFarm', function() { + // uncomment below and update the code to test AnimalFarm + //var instane = new SwaggerPetstore.AnimalFarm(); + //expect(instance).to.be.a(SwaggerPetstore.AnimalFarm); + }); + + }); + +})); diff --git a/samples/client/petstore/javascript-promise/test/model/ApiResponse.spec.js b/samples/client/petstore/javascript-promise/test/model/ApiResponse.spec.js new file mode 100644 index 00000000000..a5c3b354318 --- /dev/null +++ b/samples/client/petstore/javascript-promise/test/model/ApiResponse.spec.js @@ -0,0 +1,88 @@ +/** + * Swagger Petstore + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * 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. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +(function(root, factory) { + if (typeof define === 'function' && define.amd) { + // AMD. + define(['expect.js', '../../src/index'], factory); + } else if (typeof module === 'object' && module.exports) { + // CommonJS-like environments that support module.exports, like Node. + factory(require('expect.js'), require('../../src/index')); + } else { + // Browser globals (root is window) + factory(root.expect, root.SwaggerPetstore); + } +}(this, function(expect, SwaggerPetstore) { + 'use strict'; + + var instance; + + beforeEach(function() { + instance = new SwaggerPetstore.ApiResponse(); + }); + + var getProperty = function(object, getter, property) { + // Use getter method if present; otherwise, get the property directly. + if (typeof object[getter] === 'function') + return object[getter](); + else + return object[property]; + } + + var setProperty = function(object, setter, property, value) { + // Use setter method if present; otherwise, set the property directly. + if (typeof object[setter] === 'function') + object[setter](value); + else + object[property] = value; + } + + describe('ApiResponse', function() { + it('should create an instance of ApiResponse', function() { + // uncomment below and update the code to test ApiResponse + //var instane = new SwaggerPetstore.ApiResponse(); + //expect(instance).to.be.a(SwaggerPetstore.ApiResponse); + }); + + it('should have the property code (base name: "code")', function() { + // uncomment below and update the code to test the property code + //var instane = new SwaggerPetstore.ApiResponse(); + //expect(instance).to.be(); + }); + + it('should have the property type (base name: "type")', function() { + // uncomment below and update the code to test the property type + //var instane = new SwaggerPetstore.ApiResponse(); + //expect(instance).to.be(); + }); + + it('should have the property message (base name: "message")', function() { + // uncomment below and update the code to test the property message + //var instane = new SwaggerPetstore.ApiResponse(); + //expect(instance).to.be(); + }); + + }); + +})); diff --git a/samples/client/petstore/javascript-promise/test/model/ArrayTest.spec.js b/samples/client/petstore/javascript-promise/test/model/ArrayTest.spec.js new file mode 100644 index 00000000000..3db84909832 --- /dev/null +++ b/samples/client/petstore/javascript-promise/test/model/ArrayTest.spec.js @@ -0,0 +1,88 @@ +/** + * Swagger Petstore + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * 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. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +(function(root, factory) { + if (typeof define === 'function' && define.amd) { + // AMD. + define(['expect.js', '../../src/index'], factory); + } else if (typeof module === 'object' && module.exports) { + // CommonJS-like environments that support module.exports, like Node. + factory(require('expect.js'), require('../../src/index')); + } else { + // Browser globals (root is window) + factory(root.expect, root.SwaggerPetstore); + } +}(this, function(expect, SwaggerPetstore) { + 'use strict'; + + var instance; + + beforeEach(function() { + instance = new SwaggerPetstore.ArrayTest(); + }); + + var getProperty = function(object, getter, property) { + // Use getter method if present; otherwise, get the property directly. + if (typeof object[getter] === 'function') + return object[getter](); + else + return object[property]; + } + + var setProperty = function(object, setter, property, value) { + // Use setter method if present; otherwise, set the property directly. + if (typeof object[setter] === 'function') + object[setter](value); + else + object[property] = value; + } + + describe('ArrayTest', function() { + it('should create an instance of ArrayTest', function() { + // uncomment below and update the code to test ArrayTest + //var instane = new SwaggerPetstore.ArrayTest(); + //expect(instance).to.be.a(SwaggerPetstore.ArrayTest); + }); + + it('should have the property arrayOfString (base name: "array_of_string")', function() { + // uncomment below and update the code to test the property arrayOfString + //var instane = new SwaggerPetstore.ArrayTest(); + //expect(instance).to.be(); + }); + + it('should have the property arrayArrayOfInteger (base name: "array_array_of_integer")', function() { + // uncomment below and update the code to test the property arrayArrayOfInteger + //var instane = new SwaggerPetstore.ArrayTest(); + //expect(instance).to.be(); + }); + + it('should have the property arrayArrayOfModel (base name: "array_array_of_model")', function() { + // uncomment below and update the code to test the property arrayArrayOfModel + //var instane = new SwaggerPetstore.ArrayTest(); + //expect(instance).to.be(); + }); + + }); + +})); diff --git a/samples/client/petstore/javascript-promise/test/model/Cat.spec.js b/samples/client/petstore/javascript-promise/test/model/Cat.spec.js new file mode 100644 index 00000000000..6d95151915a --- /dev/null +++ b/samples/client/petstore/javascript-promise/test/model/Cat.spec.js @@ -0,0 +1,76 @@ +/** + * Swagger Petstore + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * 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. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +(function(root, factory) { + if (typeof define === 'function' && define.amd) { + // AMD. + define(['expect.js', '../../src/index'], factory); + } else if (typeof module === 'object' && module.exports) { + // CommonJS-like environments that support module.exports, like Node. + factory(require('expect.js'), require('../../src/index')); + } else { + // Browser globals (root is window) + factory(root.expect, root.SwaggerPetstore); + } +}(this, function(expect, SwaggerPetstore) { + 'use strict'; + + var instance; + + beforeEach(function() { + instance = new SwaggerPetstore.Cat(); + }); + + var getProperty = function(object, getter, property) { + // Use getter method if present; otherwise, get the property directly. + if (typeof object[getter] === 'function') + return object[getter](); + else + return object[property]; + } + + var setProperty = function(object, setter, property, value) { + // Use setter method if present; otherwise, set the property directly. + if (typeof object[setter] === 'function') + object[setter](value); + else + object[property] = value; + } + + describe('Cat', function() { + it('should create an instance of Cat', function() { + // uncomment below and update the code to test Cat + //var instane = new SwaggerPetstore.Cat(); + //expect(instance).to.be.a(SwaggerPetstore.Cat); + }); + + it('should have the property declawed (base name: "declawed")', function() { + // uncomment below and update the code to test the property declawed + //var instane = new SwaggerPetstore.Cat(); + //expect(instance).to.be(); + }); + + }); + +})); diff --git a/samples/client/petstore/javascript-promise/test/model/Category.spec.js b/samples/client/petstore/javascript-promise/test/model/Category.spec.js new file mode 100644 index 00000000000..dfd425f001c --- /dev/null +++ b/samples/client/petstore/javascript-promise/test/model/Category.spec.js @@ -0,0 +1,82 @@ +/** + * Swagger Petstore + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * 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. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +(function(root, factory) { + if (typeof define === 'function' && define.amd) { + // AMD. + define(['expect.js', '../../src/index'], factory); + } else if (typeof module === 'object' && module.exports) { + // CommonJS-like environments that support module.exports, like Node. + factory(require('expect.js'), require('../../src/index')); + } else { + // Browser globals (root is window) + factory(root.expect, root.SwaggerPetstore); + } +}(this, function(expect, SwaggerPetstore) { + 'use strict'; + + var instance; + + beforeEach(function() { + instance = new SwaggerPetstore.Category(); + }); + + var getProperty = function(object, getter, property) { + // Use getter method if present; otherwise, get the property directly. + if (typeof object[getter] === 'function') + return object[getter](); + else + return object[property]; + } + + var setProperty = function(object, setter, property, value) { + // Use setter method if present; otherwise, set the property directly. + if (typeof object[setter] === 'function') + object[setter](value); + else + object[property] = value; + } + + describe('Category', function() { + it('should create an instance of Category', function() { + // uncomment below and update the code to test Category + //var instane = new SwaggerPetstore.Category(); + //expect(instance).to.be.a(SwaggerPetstore.Category); + }); + + it('should have the property id (base name: "id")', function() { + // uncomment below and update the code to test the property id + //var instane = new SwaggerPetstore.Category(); + //expect(instance).to.be(); + }); + + it('should have the property name (base name: "name")', function() { + // uncomment below and update the code to test the property name + //var instane = new SwaggerPetstore.Category(); + //expect(instance).to.be(); + }); + + }); + +})); diff --git a/samples/client/petstore/javascript-promise/test/model/Dog.spec.js b/samples/client/petstore/javascript-promise/test/model/Dog.spec.js new file mode 100644 index 00000000000..35beb92fbad --- /dev/null +++ b/samples/client/petstore/javascript-promise/test/model/Dog.spec.js @@ -0,0 +1,76 @@ +/** + * Swagger Petstore + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * 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. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +(function(root, factory) { + if (typeof define === 'function' && define.amd) { + // AMD. + define(['expect.js', '../../src/index'], factory); + } else if (typeof module === 'object' && module.exports) { + // CommonJS-like environments that support module.exports, like Node. + factory(require('expect.js'), require('../../src/index')); + } else { + // Browser globals (root is window) + factory(root.expect, root.SwaggerPetstore); + } +}(this, function(expect, SwaggerPetstore) { + 'use strict'; + + var instance; + + beforeEach(function() { + instance = new SwaggerPetstore.Dog(); + }); + + var getProperty = function(object, getter, property) { + // Use getter method if present; otherwise, get the property directly. + if (typeof object[getter] === 'function') + return object[getter](); + else + return object[property]; + } + + var setProperty = function(object, setter, property, value) { + // Use setter method if present; otherwise, set the property directly. + if (typeof object[setter] === 'function') + object[setter](value); + else + object[property] = value; + } + + describe('Dog', function() { + it('should create an instance of Dog', function() { + // uncomment below and update the code to test Dog + //var instane = new SwaggerPetstore.Dog(); + //expect(instance).to.be.a(SwaggerPetstore.Dog); + }); + + it('should have the property breed (base name: "breed")', function() { + // uncomment below and update the code to test the property breed + //var instane = new SwaggerPetstore.Dog(); + //expect(instance).to.be(); + }); + + }); + +})); diff --git a/samples/client/petstore/javascript-promise/test/model/EnumClass.spec.js b/samples/client/petstore/javascript-promise/test/model/EnumClass.spec.js new file mode 100644 index 00000000000..3f7f5365c05 --- /dev/null +++ b/samples/client/petstore/javascript-promise/test/model/EnumClass.spec.js @@ -0,0 +1,69 @@ +/** + * Swagger Petstore + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * 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. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +(function(root, factory) { + if (typeof define === 'function' && define.amd) { + // AMD. + define(['expect.js', '../../src/index'], factory); + } else if (typeof module === 'object' && module.exports) { + // CommonJS-like environments that support module.exports, like Node. + factory(require('expect.js'), require('../../src/index')); + } else { + // Browser globals (root is window) + factory(root.expect, root.SwaggerPetstore); + } +}(this, function(expect, SwaggerPetstore) { + 'use strict'; + + var instance; + + beforeEach(function() { + }); + + var getProperty = function(object, getter, property) { + // Use getter method if present; otherwise, get the property directly. + if (typeof object[getter] === 'function') + return object[getter](); + else + return object[property]; + } + + var setProperty = function(object, setter, property, value) { + // Use setter method if present; otherwise, set the property directly. + if (typeof object[setter] === 'function') + object[setter](value); + else + object[property] = value; + } + + describe('EnumClass', function() { + it('should create an instance of EnumClass', function() { + // uncomment below and update the code to test EnumClass + //var instane = new SwaggerPetstore.EnumClass(); + //expect(instance).to.be.a(SwaggerPetstore.EnumClass); + }); + + }); + +})); diff --git a/samples/client/petstore/javascript-promise/test/model/EnumTest.spec.js b/samples/client/petstore/javascript-promise/test/model/EnumTest.spec.js new file mode 100644 index 00000000000..4aacb403ba9 --- /dev/null +++ b/samples/client/petstore/javascript-promise/test/model/EnumTest.spec.js @@ -0,0 +1,88 @@ +/** + * Swagger Petstore + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * 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. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +(function(root, factory) { + if (typeof define === 'function' && define.amd) { + // AMD. + define(['expect.js', '../../src/index'], factory); + } else if (typeof module === 'object' && module.exports) { + // CommonJS-like environments that support module.exports, like Node. + factory(require('expect.js'), require('../../src/index')); + } else { + // Browser globals (root is window) + factory(root.expect, root.SwaggerPetstore); + } +}(this, function(expect, SwaggerPetstore) { + 'use strict'; + + var instance; + + beforeEach(function() { + instance = new SwaggerPetstore.EnumTest(); + }); + + var getProperty = function(object, getter, property) { + // Use getter method if present; otherwise, get the property directly. + if (typeof object[getter] === 'function') + return object[getter](); + else + return object[property]; + } + + var setProperty = function(object, setter, property, value) { + // Use setter method if present; otherwise, set the property directly. + if (typeof object[setter] === 'function') + object[setter](value); + else + object[property] = value; + } + + describe('EnumTest', function() { + it('should create an instance of EnumTest', function() { + // uncomment below and update the code to test EnumTest + //var instane = new SwaggerPetstore.EnumTest(); + //expect(instance).to.be.a(SwaggerPetstore.EnumTest); + }); + + it('should have the property enumString (base name: "enum_string")', function() { + // uncomment below and update the code to test the property enumString + //var instane = new SwaggerPetstore.EnumTest(); + //expect(instance).to.be(); + }); + + it('should have the property enumInteger (base name: "enum_integer")', function() { + // uncomment below and update the code to test the property enumInteger + //var instane = new SwaggerPetstore.EnumTest(); + //expect(instance).to.be(); + }); + + it('should have the property enumNumber (base name: "enum_number")', function() { + // uncomment below and update the code to test the property enumNumber + //var instane = new SwaggerPetstore.EnumTest(); + //expect(instance).to.be(); + }); + + }); + +})); diff --git a/samples/client/petstore/javascript-promise/test/model/FormatTest.spec.js b/samples/client/petstore/javascript-promise/test/model/FormatTest.spec.js new file mode 100644 index 00000000000..b4c3d199b47 --- /dev/null +++ b/samples/client/petstore/javascript-promise/test/model/FormatTest.spec.js @@ -0,0 +1,148 @@ +/** + * Swagger Petstore + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * 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. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +(function(root, factory) { + if (typeof define === 'function' && define.amd) { + // AMD. + define(['expect.js', '../../src/index'], factory); + } else if (typeof module === 'object' && module.exports) { + // CommonJS-like environments that support module.exports, like Node. + factory(require('expect.js'), require('../../src/index')); + } else { + // Browser globals (root is window) + factory(root.expect, root.SwaggerPetstore); + } +}(this, function(expect, SwaggerPetstore) { + 'use strict'; + + var instance; + + beforeEach(function() { + instance = new SwaggerPetstore.FormatTest(); + }); + + var getProperty = function(object, getter, property) { + // Use getter method if present; otherwise, get the property directly. + if (typeof object[getter] === 'function') + return object[getter](); + else + return object[property]; + } + + var setProperty = function(object, setter, property, value) { + // Use setter method if present; otherwise, set the property directly. + if (typeof object[setter] === 'function') + object[setter](value); + else + object[property] = value; + } + + describe('FormatTest', function() { + it('should create an instance of FormatTest', function() { + // uncomment below and update the code to test FormatTest + //var instane = new SwaggerPetstore.FormatTest(); + //expect(instance).to.be.a(SwaggerPetstore.FormatTest); + }); + + it('should have the property integer (base name: "integer")', function() { + // uncomment below and update the code to test the property integer + //var instane = new SwaggerPetstore.FormatTest(); + //expect(instance).to.be(); + }); + + it('should have the property int32 (base name: "int32")', function() { + // uncomment below and update the code to test the property int32 + //var instane = new SwaggerPetstore.FormatTest(); + //expect(instance).to.be(); + }); + + it('should have the property int64 (base name: "int64")', function() { + // uncomment below and update the code to test the property int64 + //var instane = new SwaggerPetstore.FormatTest(); + //expect(instance).to.be(); + }); + + it('should have the property _number (base name: "number")', function() { + // uncomment below and update the code to test the property _number + //var instane = new SwaggerPetstore.FormatTest(); + //expect(instance).to.be(); + }); + + it('should have the property _float (base name: "float")', function() { + // uncomment below and update the code to test the property _float + //var instane = new SwaggerPetstore.FormatTest(); + //expect(instance).to.be(); + }); + + it('should have the property _double (base name: "double")', function() { + // uncomment below and update the code to test the property _double + //var instane = new SwaggerPetstore.FormatTest(); + //expect(instance).to.be(); + }); + + it('should have the property _string (base name: "string")', function() { + // uncomment below and update the code to test the property _string + //var instane = new SwaggerPetstore.FormatTest(); + //expect(instance).to.be(); + }); + + it('should have the property _byte (base name: "byte")', function() { + // uncomment below and update the code to test the property _byte + //var instane = new SwaggerPetstore.FormatTest(); + //expect(instance).to.be(); + }); + + it('should have the property binary (base name: "binary")', function() { + // uncomment below and update the code to test the property binary + //var instane = new SwaggerPetstore.FormatTest(); + //expect(instance).to.be(); + }); + + it('should have the property _date (base name: "date")', function() { + // uncomment below and update the code to test the property _date + //var instane = new SwaggerPetstore.FormatTest(); + //expect(instance).to.be(); + }); + + it('should have the property dateTime (base name: "dateTime")', function() { + // uncomment below and update the code to test the property dateTime + //var instane = new SwaggerPetstore.FormatTest(); + //expect(instance).to.be(); + }); + + it('should have the property uuid (base name: "uuid")', function() { + // uncomment below and update the code to test the property uuid + //var instane = new SwaggerPetstore.FormatTest(); + //expect(instance).to.be(); + }); + + it('should have the property password (base name: "password")', function() { + // uncomment below and update the code to test the property password + //var instane = new SwaggerPetstore.FormatTest(); + //expect(instance).to.be(); + }); + + }); + +})); diff --git a/samples/client/petstore/javascript-promise/test/model/MixedPropertiesAndAdditionalPropertiesClass.spec.js b/samples/client/petstore/javascript-promise/test/model/MixedPropertiesAndAdditionalPropertiesClass.spec.js new file mode 100644 index 00000000000..4cc81eb67d6 --- /dev/null +++ b/samples/client/petstore/javascript-promise/test/model/MixedPropertiesAndAdditionalPropertiesClass.spec.js @@ -0,0 +1,88 @@ +/** + * Swagger Petstore + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * 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. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +(function(root, factory) { + if (typeof define === 'function' && define.amd) { + // AMD. + define(['expect.js', '../../src/index'], factory); + } else if (typeof module === 'object' && module.exports) { + // CommonJS-like environments that support module.exports, like Node. + factory(require('expect.js'), require('../../src/index')); + } else { + // Browser globals (root is window) + factory(root.expect, root.SwaggerPetstore); + } +}(this, function(expect, SwaggerPetstore) { + 'use strict'; + + var instance; + + beforeEach(function() { + instance = new SwaggerPetstore.MixedPropertiesAndAdditionalPropertiesClass(); + }); + + var getProperty = function(object, getter, property) { + // Use getter method if present; otherwise, get the property directly. + if (typeof object[getter] === 'function') + return object[getter](); + else + return object[property]; + } + + var setProperty = function(object, setter, property, value) { + // Use setter method if present; otherwise, set the property directly. + if (typeof object[setter] === 'function') + object[setter](value); + else + object[property] = value; + } + + describe('MixedPropertiesAndAdditionalPropertiesClass', function() { + it('should create an instance of MixedPropertiesAndAdditionalPropertiesClass', function() { + // uncomment below and update the code to test MixedPropertiesAndAdditionalPropertiesClass + //var instane = new SwaggerPetstore.MixedPropertiesAndAdditionalPropertiesClass(); + //expect(instance).to.be.a(SwaggerPetstore.MixedPropertiesAndAdditionalPropertiesClass); + }); + + it('should have the property uuid (base name: "uuid")', function() { + // uncomment below and update the code to test the property uuid + //var instane = new SwaggerPetstore.MixedPropertiesAndAdditionalPropertiesClass(); + //expect(instance).to.be(); + }); + + it('should have the property dateTime (base name: "dateTime")', function() { + // uncomment below and update the code to test the property dateTime + //var instane = new SwaggerPetstore.MixedPropertiesAndAdditionalPropertiesClass(); + //expect(instance).to.be(); + }); + + it('should have the property map (base name: "map")', function() { + // uncomment below and update the code to test the property map + //var instane = new SwaggerPetstore.MixedPropertiesAndAdditionalPropertiesClass(); + //expect(instance).to.be(); + }); + + }); + +})); diff --git a/samples/client/petstore/javascript-promise/test/model/Model200Response.spec.js b/samples/client/petstore/javascript-promise/test/model/Model200Response.spec.js new file mode 100644 index 00000000000..1c984438224 --- /dev/null +++ b/samples/client/petstore/javascript-promise/test/model/Model200Response.spec.js @@ -0,0 +1,76 @@ +/** + * Swagger Petstore + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * 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. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +(function(root, factory) { + if (typeof define === 'function' && define.amd) { + // AMD. + define(['expect.js', '../../src/index'], factory); + } else if (typeof module === 'object' && module.exports) { + // CommonJS-like environments that support module.exports, like Node. + factory(require('expect.js'), require('../../src/index')); + } else { + // Browser globals (root is window) + factory(root.expect, root.SwaggerPetstore); + } +}(this, function(expect, SwaggerPetstore) { + 'use strict'; + + var instance; + + beforeEach(function() { + instance = new SwaggerPetstore.Model200Response(); + }); + + var getProperty = function(object, getter, property) { + // Use getter method if present; otherwise, get the property directly. + if (typeof object[getter] === 'function') + return object[getter](); + else + return object[property]; + } + + var setProperty = function(object, setter, property, value) { + // Use setter method if present; otherwise, set the property directly. + if (typeof object[setter] === 'function') + object[setter](value); + else + object[property] = value; + } + + describe('Model200Response', function() { + it('should create an instance of Model200Response', function() { + // uncomment below and update the code to test Model200Response + //var instane = new SwaggerPetstore.Model200Response(); + //expect(instance).to.be.a(SwaggerPetstore.Model200Response); + }); + + it('should have the property name (base name: "name")', function() { + // uncomment below and update the code to test the property name + //var instane = new SwaggerPetstore.Model200Response(); + //expect(instance).to.be(); + }); + + }); + +})); diff --git a/samples/client/petstore/javascript-promise/test/model/ModelReturn.spec.js b/samples/client/petstore/javascript-promise/test/model/ModelReturn.spec.js new file mode 100644 index 00000000000..4dafa0d1446 --- /dev/null +++ b/samples/client/petstore/javascript-promise/test/model/ModelReturn.spec.js @@ -0,0 +1,76 @@ +/** + * Swagger Petstore + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * 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. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +(function(root, factory) { + if (typeof define === 'function' && define.amd) { + // AMD. + define(['expect.js', '../../src/index'], factory); + } else if (typeof module === 'object' && module.exports) { + // CommonJS-like environments that support module.exports, like Node. + factory(require('expect.js'), require('../../src/index')); + } else { + // Browser globals (root is window) + factory(root.expect, root.SwaggerPetstore); + } +}(this, function(expect, SwaggerPetstore) { + 'use strict'; + + var instance; + + beforeEach(function() { + instance = new SwaggerPetstore.ModelReturn(); + }); + + var getProperty = function(object, getter, property) { + // Use getter method if present; otherwise, get the property directly. + if (typeof object[getter] === 'function') + return object[getter](); + else + return object[property]; + } + + var setProperty = function(object, setter, property, value) { + // Use setter method if present; otherwise, set the property directly. + if (typeof object[setter] === 'function') + object[setter](value); + else + object[property] = value; + } + + describe('ModelReturn', function() { + it('should create an instance of ModelReturn', function() { + // uncomment below and update the code to test ModelReturn + //var instane = new SwaggerPetstore.ModelReturn(); + //expect(instance).to.be.a(SwaggerPetstore.ModelReturn); + }); + + it('should have the property _return (base name: "return")', function() { + // uncomment below and update the code to test the property _return + //var instane = new SwaggerPetstore.ModelReturn(); + //expect(instance).to.be(); + }); + + }); + +})); diff --git a/samples/client/petstore/javascript-promise/test/model/Name.spec.js b/samples/client/petstore/javascript-promise/test/model/Name.spec.js new file mode 100644 index 00000000000..ba66272d894 --- /dev/null +++ b/samples/client/petstore/javascript-promise/test/model/Name.spec.js @@ -0,0 +1,94 @@ +/** + * Swagger Petstore + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * 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. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +(function(root, factory) { + if (typeof define === 'function' && define.amd) { + // AMD. + define(['expect.js', '../../src/index'], factory); + } else if (typeof module === 'object' && module.exports) { + // CommonJS-like environments that support module.exports, like Node. + factory(require('expect.js'), require('../../src/index')); + } else { + // Browser globals (root is window) + factory(root.expect, root.SwaggerPetstore); + } +}(this, function(expect, SwaggerPetstore) { + 'use strict'; + + var instance; + + beforeEach(function() { + instance = new SwaggerPetstore.Name(); + }); + + var getProperty = function(object, getter, property) { + // Use getter method if present; otherwise, get the property directly. + if (typeof object[getter] === 'function') + return object[getter](); + else + return object[property]; + } + + var setProperty = function(object, setter, property, value) { + // Use setter method if present; otherwise, set the property directly. + if (typeof object[setter] === 'function') + object[setter](value); + else + object[property] = value; + } + + describe('Name', function() { + it('should create an instance of Name', function() { + // uncomment below and update the code to test Name + //var instane = new SwaggerPetstore.Name(); + //expect(instance).to.be.a(SwaggerPetstore.Name); + }); + + it('should have the property name (base name: "name")', function() { + // uncomment below and update the code to test the property name + //var instane = new SwaggerPetstore.Name(); + //expect(instance).to.be(); + }); + + it('should have the property snakeCase (base name: "snake_case")', function() { + // uncomment below and update the code to test the property snakeCase + //var instane = new SwaggerPetstore.Name(); + //expect(instance).to.be(); + }); + + it('should have the property property (base name: "property")', function() { + // uncomment below and update the code to test the property property + //var instane = new SwaggerPetstore.Name(); + //expect(instance).to.be(); + }); + + it('should have the property _123Number (base name: "123Number")', function() { + // uncomment below and update the code to test the property _123Number + //var instane = new SwaggerPetstore.Name(); + //expect(instance).to.be(); + }); + + }); + +})); diff --git a/samples/client/petstore/javascript-promise/test/model/Order.spec.js b/samples/client/petstore/javascript-promise/test/model/Order.spec.js new file mode 100644 index 00000000000..bc27c00cabd --- /dev/null +++ b/samples/client/petstore/javascript-promise/test/model/Order.spec.js @@ -0,0 +1,106 @@ +/** + * Swagger Petstore + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * 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. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +(function(root, factory) { + if (typeof define === 'function' && define.amd) { + // AMD. + define(['expect.js', '../../src/index'], factory); + } else if (typeof module === 'object' && module.exports) { + // CommonJS-like environments that support module.exports, like Node. + factory(require('expect.js'), require('../../src/index')); + } else { + // Browser globals (root is window) + factory(root.expect, root.SwaggerPetstore); + } +}(this, function(expect, SwaggerPetstore) { + 'use strict'; + + var instance; + + beforeEach(function() { + instance = new SwaggerPetstore.Order(); + }); + + var getProperty = function(object, getter, property) { + // Use getter method if present; otherwise, get the property directly. + if (typeof object[getter] === 'function') + return object[getter](); + else + return object[property]; + } + + var setProperty = function(object, setter, property, value) { + // Use setter method if present; otherwise, set the property directly. + if (typeof object[setter] === 'function') + object[setter](value); + else + object[property] = value; + } + + describe('Order', function() { + it('should create an instance of Order', function() { + // uncomment below and update the code to test Order + //var instane = new SwaggerPetstore.Order(); + //expect(instance).to.be.a(SwaggerPetstore.Order); + }); + + it('should have the property id (base name: "id")', function() { + // uncomment below and update the code to test the property id + //var instane = new SwaggerPetstore.Order(); + //expect(instance).to.be(); + }); + + it('should have the property petId (base name: "petId")', function() { + // uncomment below and update the code to test the property petId + //var instane = new SwaggerPetstore.Order(); + //expect(instance).to.be(); + }); + + it('should have the property quantity (base name: "quantity")', function() { + // uncomment below and update the code to test the property quantity + //var instane = new SwaggerPetstore.Order(); + //expect(instance).to.be(); + }); + + it('should have the property shipDate (base name: "shipDate")', function() { + // uncomment below and update the code to test the property shipDate + //var instane = new SwaggerPetstore.Order(); + //expect(instance).to.be(); + }); + + it('should have the property status (base name: "status")', function() { + // uncomment below and update the code to test the property status + //var instane = new SwaggerPetstore.Order(); + //expect(instance).to.be(); + }); + + it('should have the property complete (base name: "complete")', function() { + // uncomment below and update the code to test the property complete + //var instane = new SwaggerPetstore.Order(); + //expect(instance).to.be(); + }); + + }); + +})); diff --git a/samples/client/petstore/javascript-promise/test/model/Pet.spec.js b/samples/client/petstore/javascript-promise/test/model/Pet.spec.js new file mode 100644 index 00000000000..f6c68015682 --- /dev/null +++ b/samples/client/petstore/javascript-promise/test/model/Pet.spec.js @@ -0,0 +1,106 @@ +/** + * Swagger Petstore + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * 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. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +(function(root, factory) { + if (typeof define === 'function' && define.amd) { + // AMD. + define(['expect.js', '../../src/index'], factory); + } else if (typeof module === 'object' && module.exports) { + // CommonJS-like environments that support module.exports, like Node. + factory(require('expect.js'), require('../../src/index')); + } else { + // Browser globals (root is window) + factory(root.expect, root.SwaggerPetstore); + } +}(this, function(expect, SwaggerPetstore) { + 'use strict'; + + var instance; + + beforeEach(function() { + instance = new SwaggerPetstore.Pet(); + }); + + var getProperty = function(object, getter, property) { + // Use getter method if present; otherwise, get the property directly. + if (typeof object[getter] === 'function') + return object[getter](); + else + return object[property]; + } + + var setProperty = function(object, setter, property, value) { + // Use setter method if present; otherwise, set the property directly. + if (typeof object[setter] === 'function') + object[setter](value); + else + object[property] = value; + } + + describe('Pet', function() { + it('should create an instance of Pet', function() { + // uncomment below and update the code to test Pet + //var instane = new SwaggerPetstore.Pet(); + //expect(instance).to.be.a(SwaggerPetstore.Pet); + }); + + it('should have the property id (base name: "id")', function() { + // uncomment below and update the code to test the property id + //var instane = new SwaggerPetstore.Pet(); + //expect(instance).to.be(); + }); + + it('should have the property category (base name: "category")', function() { + // uncomment below and update the code to test the property category + //var instane = new SwaggerPetstore.Pet(); + //expect(instance).to.be(); + }); + + it('should have the property name (base name: "name")', function() { + // uncomment below and update the code to test the property name + //var instane = new SwaggerPetstore.Pet(); + //expect(instance).to.be(); + }); + + it('should have the property photoUrls (base name: "photoUrls")', function() { + // uncomment below and update the code to test the property photoUrls + //var instane = new SwaggerPetstore.Pet(); + //expect(instance).to.be(); + }); + + it('should have the property tags (base name: "tags")', function() { + // uncomment below and update the code to test the property tags + //var instane = new SwaggerPetstore.Pet(); + //expect(instance).to.be(); + }); + + it('should have the property status (base name: "status")', function() { + // uncomment below and update the code to test the property status + //var instane = new SwaggerPetstore.Pet(); + //expect(instance).to.be(); + }); + + }); + +})); diff --git a/samples/client/petstore/javascript-promise/test/model/ReadOnlyFirst.spec.js b/samples/client/petstore/javascript-promise/test/model/ReadOnlyFirst.spec.js new file mode 100644 index 00000000000..2a576c59f8c --- /dev/null +++ b/samples/client/petstore/javascript-promise/test/model/ReadOnlyFirst.spec.js @@ -0,0 +1,82 @@ +/** + * Swagger Petstore + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * 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. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +(function(root, factory) { + if (typeof define === 'function' && define.amd) { + // AMD. + define(['expect.js', '../../src/index'], factory); + } else if (typeof module === 'object' && module.exports) { + // CommonJS-like environments that support module.exports, like Node. + factory(require('expect.js'), require('../../src/index')); + } else { + // Browser globals (root is window) + factory(root.expect, root.SwaggerPetstore); + } +}(this, function(expect, SwaggerPetstore) { + 'use strict'; + + var instance; + + beforeEach(function() { + instance = new SwaggerPetstore.ReadOnlyFirst(); + }); + + var getProperty = function(object, getter, property) { + // Use getter method if present; otherwise, get the property directly. + if (typeof object[getter] === 'function') + return object[getter](); + else + return object[property]; + } + + var setProperty = function(object, setter, property, value) { + // Use setter method if present; otherwise, set the property directly. + if (typeof object[setter] === 'function') + object[setter](value); + else + object[property] = value; + } + + describe('ReadOnlyFirst', function() { + it('should create an instance of ReadOnlyFirst', function() { + // uncomment below and update the code to test ReadOnlyFirst + //var instane = new SwaggerPetstore.ReadOnlyFirst(); + //expect(instance).to.be.a(SwaggerPetstore.ReadOnlyFirst); + }); + + it('should have the property bar (base name: "bar")', function() { + // uncomment below and update the code to test the property bar + //var instane = new SwaggerPetstore.ReadOnlyFirst(); + //expect(instance).to.be(); + }); + + it('should have the property baz (base name: "baz")', function() { + // uncomment below and update the code to test the property baz + //var instane = new SwaggerPetstore.ReadOnlyFirst(); + //expect(instance).to.be(); + }); + + }); + +})); diff --git a/samples/client/petstore/javascript-promise/test/model/SpecialModelName.spec.js b/samples/client/petstore/javascript-promise/test/model/SpecialModelName.spec.js new file mode 100644 index 00000000000..0f6b7cbb8ef --- /dev/null +++ b/samples/client/petstore/javascript-promise/test/model/SpecialModelName.spec.js @@ -0,0 +1,76 @@ +/** + * Swagger Petstore + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * 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. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +(function(root, factory) { + if (typeof define === 'function' && define.amd) { + // AMD. + define(['expect.js', '../../src/index'], factory); + } else if (typeof module === 'object' && module.exports) { + // CommonJS-like environments that support module.exports, like Node. + factory(require('expect.js'), require('../../src/index')); + } else { + // Browser globals (root is window) + factory(root.expect, root.SwaggerPetstore); + } +}(this, function(expect, SwaggerPetstore) { + 'use strict'; + + var instance; + + beforeEach(function() { + instance = new SwaggerPetstore.SpecialModelName(); + }); + + var getProperty = function(object, getter, property) { + // Use getter method if present; otherwise, get the property directly. + if (typeof object[getter] === 'function') + return object[getter](); + else + return object[property]; + } + + var setProperty = function(object, setter, property, value) { + // Use setter method if present; otherwise, set the property directly. + if (typeof object[setter] === 'function') + object[setter](value); + else + object[property] = value; + } + + describe('SpecialModelName', function() { + it('should create an instance of SpecialModelName', function() { + // uncomment below and update the code to test SpecialModelName + //var instane = new SwaggerPetstore.SpecialModelName(); + //expect(instance).to.be.a(SwaggerPetstore.SpecialModelName); + }); + + it('should have the property specialPropertyName (base name: "$special[property.name]")', function() { + // uncomment below and update the code to test the property specialPropertyName + //var instane = new SwaggerPetstore.SpecialModelName(); + //expect(instance).to.be(); + }); + + }); + +})); diff --git a/samples/client/petstore/javascript-promise/test/model/Tag.spec.js b/samples/client/petstore/javascript-promise/test/model/Tag.spec.js new file mode 100644 index 00000000000..6ab32cf5b1f --- /dev/null +++ b/samples/client/petstore/javascript-promise/test/model/Tag.spec.js @@ -0,0 +1,82 @@ +/** + * Swagger Petstore + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * 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. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +(function(root, factory) { + if (typeof define === 'function' && define.amd) { + // AMD. + define(['expect.js', '../../src/index'], factory); + } else if (typeof module === 'object' && module.exports) { + // CommonJS-like environments that support module.exports, like Node. + factory(require('expect.js'), require('../../src/index')); + } else { + // Browser globals (root is window) + factory(root.expect, root.SwaggerPetstore); + } +}(this, function(expect, SwaggerPetstore) { + 'use strict'; + + var instance; + + beforeEach(function() { + instance = new SwaggerPetstore.Tag(); + }); + + var getProperty = function(object, getter, property) { + // Use getter method if present; otherwise, get the property directly. + if (typeof object[getter] === 'function') + return object[getter](); + else + return object[property]; + } + + var setProperty = function(object, setter, property, value) { + // Use setter method if present; otherwise, set the property directly. + if (typeof object[setter] === 'function') + object[setter](value); + else + object[property] = value; + } + + describe('Tag', function() { + it('should create an instance of Tag', function() { + // uncomment below and update the code to test Tag + //var instane = new SwaggerPetstore.Tag(); + //expect(instance).to.be.a(SwaggerPetstore.Tag); + }); + + it('should have the property id (base name: "id")', function() { + // uncomment below and update the code to test the property id + //var instane = new SwaggerPetstore.Tag(); + //expect(instance).to.be(); + }); + + it('should have the property name (base name: "name")', function() { + // uncomment below and update the code to test the property name + //var instane = new SwaggerPetstore.Tag(); + //expect(instance).to.be(); + }); + + }); + +})); diff --git a/samples/client/petstore/javascript-promise/test/model/User.spec.js b/samples/client/petstore/javascript-promise/test/model/User.spec.js new file mode 100644 index 00000000000..42ae42a3d68 --- /dev/null +++ b/samples/client/petstore/javascript-promise/test/model/User.spec.js @@ -0,0 +1,118 @@ +/** + * Swagger Petstore + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * 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. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +(function(root, factory) { + if (typeof define === 'function' && define.amd) { + // AMD. + define(['expect.js', '../../src/index'], factory); + } else if (typeof module === 'object' && module.exports) { + // CommonJS-like environments that support module.exports, like Node. + factory(require('expect.js'), require('../../src/index')); + } else { + // Browser globals (root is window) + factory(root.expect, root.SwaggerPetstore); + } +}(this, function(expect, SwaggerPetstore) { + 'use strict'; + + var instance; + + beforeEach(function() { + instance = new SwaggerPetstore.User(); + }); + + var getProperty = function(object, getter, property) { + // Use getter method if present; otherwise, get the property directly. + if (typeof object[getter] === 'function') + return object[getter](); + else + return object[property]; + } + + var setProperty = function(object, setter, property, value) { + // Use setter method if present; otherwise, set the property directly. + if (typeof object[setter] === 'function') + object[setter](value); + else + object[property] = value; + } + + describe('User', function() { + it('should create an instance of User', function() { + // uncomment below and update the code to test User + //var instane = new SwaggerPetstore.User(); + //expect(instance).to.be.a(SwaggerPetstore.User); + }); + + it('should have the property id (base name: "id")', function() { + // uncomment below and update the code to test the property id + //var instane = new SwaggerPetstore.User(); + //expect(instance).to.be(); + }); + + it('should have the property username (base name: "username")', function() { + // uncomment below and update the code to test the property username + //var instane = new SwaggerPetstore.User(); + //expect(instance).to.be(); + }); + + it('should have the property firstName (base name: "firstName")', function() { + // uncomment below and update the code to test the property firstName + //var instane = new SwaggerPetstore.User(); + //expect(instance).to.be(); + }); + + it('should have the property lastName (base name: "lastName")', function() { + // uncomment below and update the code to test the property lastName + //var instane = new SwaggerPetstore.User(); + //expect(instance).to.be(); + }); + + it('should have the property email (base name: "email")', function() { + // uncomment below and update the code to test the property email + //var instane = new SwaggerPetstore.User(); + //expect(instance).to.be(); + }); + + it('should have the property password (base name: "password")', function() { + // uncomment below and update the code to test the property password + //var instane = new SwaggerPetstore.User(); + //expect(instance).to.be(); + }); + + it('should have the property phone (base name: "phone")', function() { + // uncomment below and update the code to test the property phone + //var instane = new SwaggerPetstore.User(); + //expect(instance).to.be(); + }); + + it('should have the property userStatus (base name: "userStatus")', function() { + // uncomment below and update the code to test the property userStatus + //var instane = new SwaggerPetstore.User(); + //expect(instance).to.be(); + }); + + }); + +})); diff --git a/samples/client/petstore/javascript/README.md b/samples/client/petstore/javascript/README.md index 6f3ecf43de9..bba1f871bcf 100644 --- a/samples/client/petstore/javascript/README.md +++ b/samples/client/petstore/javascript/README.md @@ -6,7 +6,7 @@ This SDK is automatically generated by the [Swagger Codegen](https://github.com/ - API version: 1.0.0 - Package version: 1.0.0 -- Build date: 2016-06-15T00:01:43.395+08:00 +- Build date: 2016-06-15T01:15:37.147+08:00 - Build package: class io.swagger.codegen.languages.JavascriptClientCodegen ## Installation diff --git a/samples/client/petstore/javascript/src/ApiClient.js b/samples/client/petstore/javascript/src/ApiClient.js index d45704dcdac..9187f89af01 100644 --- a/samples/client/petstore/javascript/src/ApiClient.js +++ b/samples/client/petstore/javascript/src/ApiClient.js @@ -1,3 +1,27 @@ +/** + * Swagger Petstore + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * 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. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + (function(root, factory) { if (typeof define === 'function' && define.amd) { // AMD. Register as an anonymous module. diff --git a/samples/client/petstore/javascript/src/api/FakeApi.js b/samples/client/petstore/javascript/src/api/FakeApi.js index 9db45d334f5..95ffb2bd8c6 100644 --- a/samples/client/petstore/javascript/src/api/FakeApi.js +++ b/samples/client/petstore/javascript/src/api/FakeApi.js @@ -1,3 +1,27 @@ +/** + * Swagger Petstore + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * 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. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + (function(root, factory) { if (typeof define === 'function' && define.amd) { // AMD. Register as an anonymous module. diff --git a/samples/client/petstore/javascript/src/api/PetApi.js b/samples/client/petstore/javascript/src/api/PetApi.js index 6e7193bd53e..a90880c8f46 100644 --- a/samples/client/petstore/javascript/src/api/PetApi.js +++ b/samples/client/petstore/javascript/src/api/PetApi.js @@ -1,3 +1,27 @@ +/** + * Swagger Petstore + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * 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. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + (function(root, factory) { if (typeof define === 'function' && define.amd) { // AMD. Register as an anonymous module. diff --git a/samples/client/petstore/javascript/src/api/StoreApi.js b/samples/client/petstore/javascript/src/api/StoreApi.js index 8b9aa077de7..58cdb3a9c08 100644 --- a/samples/client/petstore/javascript/src/api/StoreApi.js +++ b/samples/client/petstore/javascript/src/api/StoreApi.js @@ -1,3 +1,27 @@ +/** + * Swagger Petstore + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * 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. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + (function(root, factory) { if (typeof define === 'function' && define.amd) { // AMD. Register as an anonymous module. diff --git a/samples/client/petstore/javascript/src/api/UserApi.js b/samples/client/petstore/javascript/src/api/UserApi.js index 4bc7218fdce..f9b8fb4a118 100644 --- a/samples/client/petstore/javascript/src/api/UserApi.js +++ b/samples/client/petstore/javascript/src/api/UserApi.js @@ -1,3 +1,27 @@ +/** + * Swagger Petstore + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * 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. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + (function(root, factory) { if (typeof define === 'function' && define.amd) { // AMD. Register as an anonymous module. diff --git a/samples/client/petstore/javascript/src/index.js b/samples/client/petstore/javascript/src/index.js index 2c3e34b4efd..93f2e6cd4b8 100644 --- a/samples/client/petstore/javascript/src/index.js +++ b/samples/client/petstore/javascript/src/index.js @@ -1,3 +1,27 @@ +/** + * Swagger Petstore + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * 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. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + (function(factory) { if (typeof define === 'function' && define.amd) { // AMD. Register as an anonymous module. diff --git a/samples/client/petstore/javascript/src/model/AdditionalPropertiesClass.js b/samples/client/petstore/javascript/src/model/AdditionalPropertiesClass.js index 922254fa175..10183b1ea43 100644 --- a/samples/client/petstore/javascript/src/model/AdditionalPropertiesClass.js +++ b/samples/client/petstore/javascript/src/model/AdditionalPropertiesClass.js @@ -1,3 +1,27 @@ +/** + * Swagger Petstore + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * 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. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + (function(root, factory) { if (typeof define === 'function' && define.amd) { // AMD. Register as an anonymous module. diff --git a/samples/client/petstore/javascript/src/model/Animal.js b/samples/client/petstore/javascript/src/model/Animal.js index 28e5904e840..32042951cb1 100644 --- a/samples/client/petstore/javascript/src/model/Animal.js +++ b/samples/client/petstore/javascript/src/model/Animal.js @@ -1,3 +1,27 @@ +/** + * Swagger Petstore + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * 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. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + (function(root, factory) { if (typeof define === 'function' && define.amd) { // AMD. Register as an anonymous module. diff --git a/samples/client/petstore/javascript/src/model/AnimalFarm.js b/samples/client/petstore/javascript/src/model/AnimalFarm.js index d5f6aa2a424..1a54e0d611a 100644 --- a/samples/client/petstore/javascript/src/model/AnimalFarm.js +++ b/samples/client/petstore/javascript/src/model/AnimalFarm.js @@ -1,3 +1,27 @@ +/** + * Swagger Petstore + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * 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. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + (function(root, factory) { if (typeof define === 'function' && define.amd) { // AMD. Register as an anonymous module. diff --git a/samples/client/petstore/javascript/src/model/ApiResponse.js b/samples/client/petstore/javascript/src/model/ApiResponse.js index 6d4c970264b..1cb041898d4 100644 --- a/samples/client/petstore/javascript/src/model/ApiResponse.js +++ b/samples/client/petstore/javascript/src/model/ApiResponse.js @@ -1,3 +1,27 @@ +/** + * Swagger Petstore + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * 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. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + (function(root, factory) { if (typeof define === 'function' && define.amd) { // AMD. Register as an anonymous module. diff --git a/samples/client/petstore/javascript/src/model/ArrayTest.js b/samples/client/petstore/javascript/src/model/ArrayTest.js index 247c9174781..a2589f7ea0a 100644 --- a/samples/client/petstore/javascript/src/model/ArrayTest.js +++ b/samples/client/petstore/javascript/src/model/ArrayTest.js @@ -1,3 +1,27 @@ +/** + * Swagger Petstore + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * 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. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + (function(root, factory) { if (typeof define === 'function' && define.amd) { // AMD. Register as an anonymous module. diff --git a/samples/client/petstore/javascript/src/model/Cat.js b/samples/client/petstore/javascript/src/model/Cat.js index a6b25bc6d58..e6a771019f3 100644 --- a/samples/client/petstore/javascript/src/model/Cat.js +++ b/samples/client/petstore/javascript/src/model/Cat.js @@ -1,3 +1,27 @@ +/** + * Swagger Petstore + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * 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. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + (function(root, factory) { if (typeof define === 'function' && define.amd) { // AMD. Register as an anonymous module. diff --git a/samples/client/petstore/javascript/src/model/Category.js b/samples/client/petstore/javascript/src/model/Category.js index 9e2e19ac5bb..c415cbd1943 100644 --- a/samples/client/petstore/javascript/src/model/Category.js +++ b/samples/client/petstore/javascript/src/model/Category.js @@ -1,3 +1,27 @@ +/** + * Swagger Petstore + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * 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. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + (function(root, factory) { if (typeof define === 'function' && define.amd) { // AMD. Register as an anonymous module. diff --git a/samples/client/petstore/javascript/src/model/Dog.js b/samples/client/petstore/javascript/src/model/Dog.js index ee17ae3467f..719237dadd7 100644 --- a/samples/client/petstore/javascript/src/model/Dog.js +++ b/samples/client/petstore/javascript/src/model/Dog.js @@ -1,3 +1,27 @@ +/** + * Swagger Petstore + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * 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. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + (function(root, factory) { if (typeof define === 'function' && define.amd) { // AMD. Register as an anonymous module. diff --git a/samples/client/petstore/javascript/src/model/EnumClass.js b/samples/client/petstore/javascript/src/model/EnumClass.js index e9bf5219ee5..b0bb7813e7d 100644 --- a/samples/client/petstore/javascript/src/model/EnumClass.js +++ b/samples/client/petstore/javascript/src/model/EnumClass.js @@ -1,3 +1,27 @@ +/** + * Swagger Petstore + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * 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. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + (function(root, factory) { if (typeof define === 'function' && define.amd) { // AMD. Register as an anonymous module. diff --git a/samples/client/petstore/javascript/src/model/EnumTest.js b/samples/client/petstore/javascript/src/model/EnumTest.js index 6f8f0de3836..0ab961078b0 100644 --- a/samples/client/petstore/javascript/src/model/EnumTest.js +++ b/samples/client/petstore/javascript/src/model/EnumTest.js @@ -1,3 +1,27 @@ +/** + * Swagger Petstore + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * 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. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + (function(root, factory) { if (typeof define === 'function' && define.amd) { // AMD. Register as an anonymous module. diff --git a/samples/client/petstore/javascript/src/model/FormatTest.js b/samples/client/petstore/javascript/src/model/FormatTest.js index ed9e0cfcaf8..7a941cb5ffa 100644 --- a/samples/client/petstore/javascript/src/model/FormatTest.js +++ b/samples/client/petstore/javascript/src/model/FormatTest.js @@ -1,3 +1,27 @@ +/** + * Swagger Petstore + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * 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. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + (function(root, factory) { if (typeof define === 'function' && define.amd) { // AMD. Register as an anonymous module. diff --git a/samples/client/petstore/javascript/src/model/MixedPropertiesAndAdditionalPropertiesClass.js b/samples/client/petstore/javascript/src/model/MixedPropertiesAndAdditionalPropertiesClass.js index 0cdc6c8728f..1db531b401f 100644 --- a/samples/client/petstore/javascript/src/model/MixedPropertiesAndAdditionalPropertiesClass.js +++ b/samples/client/petstore/javascript/src/model/MixedPropertiesAndAdditionalPropertiesClass.js @@ -1,3 +1,27 @@ +/** + * Swagger Petstore + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * 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. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + (function(root, factory) { if (typeof define === 'function' && define.amd) { // AMD. Register as an anonymous module. diff --git a/samples/client/petstore/javascript/src/model/Model200Response.js b/samples/client/petstore/javascript/src/model/Model200Response.js index 1d83d420287..21ea07b2c39 100644 --- a/samples/client/petstore/javascript/src/model/Model200Response.js +++ b/samples/client/petstore/javascript/src/model/Model200Response.js @@ -1,3 +1,27 @@ +/** + * Swagger Petstore + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * 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. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + (function(root, factory) { if (typeof define === 'function' && define.amd) { // AMD. Register as an anonymous module. diff --git a/samples/client/petstore/javascript/src/model/ModelReturn.js b/samples/client/petstore/javascript/src/model/ModelReturn.js index d0236e77b17..b9dec2d30c4 100644 --- a/samples/client/petstore/javascript/src/model/ModelReturn.js +++ b/samples/client/petstore/javascript/src/model/ModelReturn.js @@ -1,3 +1,27 @@ +/** + * Swagger Petstore + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * 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. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + (function(root, factory) { if (typeof define === 'function' && define.amd) { // AMD. Register as an anonymous module. diff --git a/samples/client/petstore/javascript/src/model/Name.js b/samples/client/petstore/javascript/src/model/Name.js index f8c24ef770c..cae738e0d90 100644 --- a/samples/client/petstore/javascript/src/model/Name.js +++ b/samples/client/petstore/javascript/src/model/Name.js @@ -1,3 +1,27 @@ +/** + * Swagger Petstore + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * 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. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + (function(root, factory) { if (typeof define === 'function' && define.amd) { // AMD. Register as an anonymous module. diff --git a/samples/client/petstore/javascript/src/model/Order.js b/samples/client/petstore/javascript/src/model/Order.js index 57f77d84ccd..f2b3726a04c 100644 --- a/samples/client/petstore/javascript/src/model/Order.js +++ b/samples/client/petstore/javascript/src/model/Order.js @@ -1,3 +1,27 @@ +/** + * Swagger Petstore + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * 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. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + (function(root, factory) { if (typeof define === 'function' && define.amd) { // AMD. Register as an anonymous module. diff --git a/samples/client/petstore/javascript/src/model/Pet.js b/samples/client/petstore/javascript/src/model/Pet.js index fe14361dbf2..19ed2096877 100644 --- a/samples/client/petstore/javascript/src/model/Pet.js +++ b/samples/client/petstore/javascript/src/model/Pet.js @@ -1,3 +1,27 @@ +/** + * Swagger Petstore + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * 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. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + (function(root, factory) { if (typeof define === 'function' && define.amd) { // AMD. Register as an anonymous module. diff --git a/samples/client/petstore/javascript/src/model/ReadOnlyFirst.js b/samples/client/petstore/javascript/src/model/ReadOnlyFirst.js index 394af906e73..8ceb17f58bb 100644 --- a/samples/client/petstore/javascript/src/model/ReadOnlyFirst.js +++ b/samples/client/petstore/javascript/src/model/ReadOnlyFirst.js @@ -1,3 +1,27 @@ +/** + * Swagger Petstore + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * 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. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + (function(root, factory) { if (typeof define === 'function' && define.amd) { // AMD. Register as an anonymous module. diff --git a/samples/client/petstore/javascript/src/model/SpecialModelName.js b/samples/client/petstore/javascript/src/model/SpecialModelName.js index d5a0e992a73..f06c2e46556 100644 --- a/samples/client/petstore/javascript/src/model/SpecialModelName.js +++ b/samples/client/petstore/javascript/src/model/SpecialModelName.js @@ -1,3 +1,27 @@ +/** + * Swagger Petstore + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * 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. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + (function(root, factory) { if (typeof define === 'function' && define.amd) { // AMD. Register as an anonymous module. diff --git a/samples/client/petstore/javascript/src/model/Tag.js b/samples/client/petstore/javascript/src/model/Tag.js index 443d312b76a..8e188616107 100644 --- a/samples/client/petstore/javascript/src/model/Tag.js +++ b/samples/client/petstore/javascript/src/model/Tag.js @@ -1,3 +1,27 @@ +/** + * Swagger Petstore + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * 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. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + (function(root, factory) { if (typeof define === 'function' && define.amd) { // AMD. Register as an anonymous module. diff --git a/samples/client/petstore/javascript/src/model/User.js b/samples/client/petstore/javascript/src/model/User.js index 2360c7c6314..df334f1e623 100644 --- a/samples/client/petstore/javascript/src/model/User.js +++ b/samples/client/petstore/javascript/src/model/User.js @@ -1,3 +1,27 @@ +/** + * Swagger Petstore + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * 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. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + (function(root, factory) { if (typeof define === 'function' && define.amd) { // AMD. Register as an anonymous module. diff --git a/samples/client/petstore/ruby/lib/petstore/models/array_test.rb b/samples/client/petstore/ruby/lib/petstore/models/array_test.rb index 35d498fc9af..58bc4b1ae28 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/array_test.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/array_test.rb @@ -26,15 +26,28 @@ require 'date' module Petstore class ArrayTest + attr_accessor :array_of_string + + attr_accessor :array_array_of_integer + + attr_accessor :array_array_of_model + + # Attribute mapping from ruby-style variable name to JSON key. def self.attribute_map { + :'array_of_string' => :'array_of_string', + :'array_array_of_integer' => :'array_array_of_integer', + :'array_array_of_model' => :'array_array_of_model' } end # Attribute type mapping. def self.swagger_types { + :'array_of_string' => :'Array', + :'array_array_of_integer' => :'Array>', + :'array_array_of_model' => :'Array>' } end @@ -46,6 +59,24 @@ module Petstore # convert string to symbol for hash key attributes = attributes.each_with_object({}){|(k,v), h| h[k.to_sym] = v} + if attributes.has_key?(:'array_of_string') + if (value = attributes[:'array_of_string']).is_a?(Array) + self.array_of_string = value + end + end + + if attributes.has_key?(:'array_array_of_integer') + if (value = attributes[:'array_array_of_integer']).is_a?(Array) + self.array_array_of_integer = value + end + end + + if attributes.has_key?(:'array_array_of_model') + if (value = attributes[:'array_array_of_model']).is_a?(Array) + self.array_array_of_model = value + end + end + end # Show invalid properties with the reasons. Usually used together with valid? @@ -58,13 +89,17 @@ module Petstore # Check to see if the all the properties in the model are valid # @return true if the model is valid def valid? + return true end # Checks equality by comparing each attribute. # @param [Object] Object to be compared def ==(o) return true if self.equal?(o) - self.class == o.class + self.class == o.class && + array_of_string == o.array_of_string && + array_array_of_integer == o.array_array_of_integer && + array_array_of_model == o.array_array_of_model end # @see the `==` method @@ -76,7 +111,7 @@ module Petstore # Calculates hash code according to all attributes. # @return [Fixnum] Hash code def hash - [].hash + [array_of_string, array_array_of_integer, array_array_of_model].hash end # Builds the object from hash diff --git a/samples/server/petstore/go-api-server/.swagger-codegen-ignore b/samples/server/petstore/go-api-server/.swagger-codegen-ignore new file mode 100644 index 00000000000..19d3377182e --- /dev/null +++ b/samples/server/petstore/go-api-server/.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 +# Thsi 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/go-api-server/api/swagger.yaml b/samples/server/petstore/go-api-server/api/swagger.yaml new file mode 100644 index 00000000000..e69de29bb2d diff --git a/samples/server/petstore/go-api-server/go/README.md b/samples/server/petstore/go-api-server/go/README.md new file mode 100644 index 00000000000..62ca0d76901 --- /dev/null +++ b/samples/server/petstore/go-api-server/go/README.md @@ -0,0 +1,25 @@ +# Go API Server for petstoreserver + +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. + +## Overview +This server was generated by the [swagger-codegen] +(https://github.com/swagger-api/swagger-codegen) project. +By using the [OpenAPI-Spec](https://github.com/OAI/OpenAPI-Specification) from a remote server, you can easily generate a server stub. +- + +To see how to make this your own, look here: + +[README](https://github.com/swagger-api/swagger-codegen/blob/master/README.md) + +- API version: 1.0.0 +- Build date: 2016-05-27T09:17:10.992-07:00 + + +### Running the server +To run the server, follow these simple steps: + +``` +go run main.go +``` + diff --git a/samples/server/petstore/go-api-server/go/app.yaml b/samples/server/petstore/go-api-server/go/app.yaml new file mode 100644 index 00000000000..ea684a7280a --- /dev/null +++ b/samples/server/petstore/go-api-server/go/app.yaml @@ -0,0 +1 @@ +application: petstoreserver \ No newline at end of file diff --git a/samples/server/petstore/go-api-server/go/logger.go b/samples/server/petstore/go-api-server/go/logger.go new file mode 100644 index 00000000000..1ff51c3f16d --- /dev/null +++ b/samples/server/petstore/go-api-server/go/logger.go @@ -0,0 +1,23 @@ +package petstoreserver + +import ( + "log" + "net/http" + "time" +) + +func Logger(inner http.Handler, name string) http.Handler { + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + start := time.Now() + + inner.ServeHTTP(w, r) + + log.Printf( + "%s %s %s %s", + r.Method, + r.RequestURI, + name, + time.Since(start), + ) + }) +} \ No newline at end of file diff --git a/samples/server/petstore/go-api-server/go/pet.go b/samples/server/petstore/go-api-server/go/pet.go new file mode 100644 index 00000000000..21252983217 --- /dev/null +++ b/samples/server/petstore/go-api-server/go/pet.go @@ -0,0 +1,50 @@ +package petstoreserver + +import ( + "net/http" +) + +type Pet struct { + +} + +func AddPet(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "application/json; charset=UTF-8") + w.WriteHeader(http.StatusOK) +} + +func DeletePet(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "application/json; charset=UTF-8") + w.WriteHeader(http.StatusOK) +} + +func FindPetsByStatus(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "application/json; charset=UTF-8") + w.WriteHeader(http.StatusOK) +} + +func FindPetsByTags(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "application/json; charset=UTF-8") + w.WriteHeader(http.StatusOK) +} + +func GetPetById(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "application/json; charset=UTF-8") + w.WriteHeader(http.StatusOK) +} + +func UpdatePet(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "application/json; charset=UTF-8") + w.WriteHeader(http.StatusOK) +} + +func UpdatePetWithForm(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "application/json; charset=UTF-8") + w.WriteHeader(http.StatusOK) +} + +func UploadFile(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "application/json; charset=UTF-8") + w.WriteHeader(http.StatusOK) +} + diff --git a/samples/server/petstore/go-api-server/go/routers.go b/samples/server/petstore/go-api-server/go/routers.go new file mode 100644 index 00000000000..8704c12c4bd --- /dev/null +++ b/samples/server/petstore/go-api-server/go/routers.go @@ -0,0 +1,187 @@ +package petstoreserver + +import ( + "net/http" + "fmt" + "github.com/gorilla/mux" +) + +type Route struct { + Name string + Method string + Pattern string + HandlerFunc http.HandlerFunc +} + +type Routes []Route + +func NewRouter() *mux.Router { + router := mux.NewRouter().StrictSlash(true) + for _, route := range routes { + var handler http.Handler + handler = route.HandlerFunc + handler = Logger(handler, route.Name) + + router. + Methods(route.Method). + Path(route.Pattern). + Name(route.Name). + Handler(handler) + } + + return router +} + +func Index(w http.ResponseWriter, r *http.Request) { + fmt.Fprintf(w, "Hello World!") +} + +var routes = Routes{ + Route{ + "Index", + "GET", + "/", + Index, + }, + + Route{ + "AddPet", + "POST", + "/pet", + AddPet, + }, + + Route{ + "DeletePet", + "DELETE", + "/pet/{petId}", + DeletePet, + }, + + Route{ + "FindPetsByStatus", + "GET", + "/pet/findByStatus", + FindPetsByStatus, + }, + + Route{ + "FindPetsByTags", + "GET", + "/pet/findByTags", + FindPetsByTags, + }, + + Route{ + "GetPetById", + "GET", + "/pet/{petId}", + GetPetById, + }, + + Route{ + "UpdatePet", + "PUT", + "/pet", + UpdatePet, + }, + + Route{ + "UpdatePetWithForm", + "POST", + "/pet/{petId}", + UpdatePetWithForm, + }, + + Route{ + "UploadFile", + "POST", + "/pet/{petId}/uploadImage", + UploadFile, + }, + + Route{ + "DeleteOrder", + "DELETE", + "/store/order/{orderId}", + DeleteOrder, + }, + + Route{ + "GetInventory", + "GET", + "/store/inventory", + GetInventory, + }, + + Route{ + "GetOrderById", + "GET", + "/store/order/{orderId}", + GetOrderById, + }, + + Route{ + "PlaceOrder", + "POST", + "/store/order", + PlaceOrder, + }, + + Route{ + "CreateUser", + "POST", + "/user", + CreateUser, + }, + + Route{ + "CreateUsersWithArrayInput", + "POST", + "/user/createWithArray", + CreateUsersWithArrayInput, + }, + + Route{ + "CreateUsersWithListInput", + "POST", + "/user/createWithList", + CreateUsersWithListInput, + }, + + Route{ + "DeleteUser", + "DELETE", + "/user/{username}", + DeleteUser, + }, + + Route{ + "GetUserByName", + "GET", + "/user/{username}", + GetUserByName, + }, + + Route{ + "LoginUser", + "GET", + "/user/login", + LoginUser, + }, + + Route{ + "LogoutUser", + "GET", + "/user/logout", + LogoutUser, + }, + + Route{ + "UpdateUser", + "PUT", + "/user/{username}", + UpdateUser, + }, + +} \ No newline at end of file diff --git a/samples/server/petstore/go-api-server/go/store.go b/samples/server/petstore/go-api-server/go/store.go new file mode 100644 index 00000000000..9af921d3a54 --- /dev/null +++ b/samples/server/petstore/go-api-server/go/store.go @@ -0,0 +1,30 @@ +package petstoreserver + +import ( + "net/http" +) + +type Store struct { + +} + +func DeleteOrder(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "application/json; charset=UTF-8") + w.WriteHeader(http.StatusOK) +} + +func GetInventory(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "application/json; charset=UTF-8") + w.WriteHeader(http.StatusOK) +} + +func GetOrderById(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "application/json; charset=UTF-8") + w.WriteHeader(http.StatusOK) +} + +func PlaceOrder(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "application/json; charset=UTF-8") + w.WriteHeader(http.StatusOK) +} + diff --git a/samples/server/petstore/go-api-server/go/user.go b/samples/server/petstore/go-api-server/go/user.go new file mode 100644 index 00000000000..5c7d0cd2f1b --- /dev/null +++ b/samples/server/petstore/go-api-server/go/user.go @@ -0,0 +1,50 @@ +package petstoreserver + +import ( + "net/http" +) + +type User struct { + +} + +func CreateUser(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "application/json; charset=UTF-8") + w.WriteHeader(http.StatusOK) +} + +func CreateUsersWithArrayInput(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "application/json; charset=UTF-8") + w.WriteHeader(http.StatusOK) +} + +func CreateUsersWithListInput(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "application/json; charset=UTF-8") + w.WriteHeader(http.StatusOK) +} + +func DeleteUser(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "application/json; charset=UTF-8") + w.WriteHeader(http.StatusOK) +} + +func GetUserByName(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "application/json; charset=UTF-8") + w.WriteHeader(http.StatusOK) +} + +func LoginUser(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "application/json; charset=UTF-8") + w.WriteHeader(http.StatusOK) +} + +func LogoutUser(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "application/json; charset=UTF-8") + w.WriteHeader(http.StatusOK) +} + +func UpdateUser(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "application/json; charset=UTF-8") + w.WriteHeader(http.StatusOK) +} + diff --git a/samples/server/petstore/go-api-server/main.go b/samples/server/petstore/go-api-server/main.go new file mode 100644 index 00000000000..915963a6095 --- /dev/null +++ b/samples/server/petstore/go-api-server/main.go @@ -0,0 +1,22 @@ +package main + +import ( + // WARNING! + // Change this to a fully-qualified import path + // once you place this file into your project. + // For example, + // + // sw "github.com/myname/myrepo/go" + // + sw "./go" + "log" + "net/http" +) + +func main() { + log.Printf("Server started") + + router := sw.NewRouter() + + log.Fatal(http.ListenAndServe(":8080", router)) +}