forked from loafle/openapi-generator-original
Merge remote-tracking branch 'refs/remotes/swagger-api/master'
This commit is contained in:
commit
0980261709
@ -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
|
||||
|
31
bin/cpprest-petstore.sh
Executable file
31
bin/cpprest-petstore.sh
Executable file
@ -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
|
31
bin/go-petstore-server.sh
Executable file
31
bin/go-petstore-server.sh
Executable file
@ -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
|
10
bin/windows/cpprest-petstore.bat
Executable file
10
bin/windows/cpprest-petstore.bat
Executable file
@ -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%
|
@ -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<String>();
|
||||
|
||||
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<String>(
|
||||
Arrays.asList("int", "char", "bool", "long", "float", "double", "int32_t", "int64_t"));
|
||||
|
||||
typeMapping = new HashMap<String, String>();
|
||||
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<String, String>();
|
||||
importMapping.put("std::vector", "#include <vector>");
|
||||
importMapping.put("std::map", "#include <map>");
|
||||
importMapping.put("std::string", "#include <string>");
|
||||
importMapping.put("HttpContent", "#include \"HttpContent.h\"");
|
||||
importMapping.put("Object", "#include \"Object.h\"");
|
||||
importMapping.put("utility::string_t", "#include <cpprest/details/basic_types.h>");
|
||||
importMapping.put("utility::datetime", "#include <cpprest/details/basic_types.h>");
|
||||
}
|
||||
|
||||
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<String, Model> allDefinitions) {
|
||||
CodegenModel codegenModel = super.fromModel(name, model, allDefinitions);
|
||||
|
||||
Set<String> oldImports = codegenModel.imports;
|
||||
codegenModel.imports = new HashSet<String>();
|
||||
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<String, Model> 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) + "<utility::string_t, " + getTypeDeclaration(inner) + ">";
|
||||
}
|
||||
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<utility::string_t, " + inner + ">()";
|
||||
} 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";
|
||||
}
|
||||
}
|
@ -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<String>(
|
||||
Arrays.asList(
|
||||
"map",
|
||||
"array")
|
||||
);
|
||||
|
||||
languageSpecificPrimitives = new HashSet<String>(
|
||||
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<String, String>();
|
||||
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);
|
||||
}
|
||||
}
|
@ -1,3 +1,4 @@
|
||||
{{>licenseInfo}}
|
||||
(function(root, factory) {
|
||||
if (typeof define === 'function' && define.amd) {
|
||||
// AMD. Register as an anonymous module.
|
||||
|
@ -1,3 +1,4 @@
|
||||
{{>licenseInfo}}
|
||||
{{=< >=}}(function(root, factory) {
|
||||
if (typeof define === 'function' && define.amd) {
|
||||
// AMD. Register as an anonymous module.
|
||||
|
@ -1,3 +1,4 @@
|
||||
{{>licenseInfo}}
|
||||
(function(root, factory) {
|
||||
if (typeof define === 'function' && define.amd) {
|
||||
// AMD.
|
||||
|
@ -1,3 +1,4 @@
|
||||
{{>licenseInfo}}
|
||||
(function(factory) {
|
||||
if (typeof define === 'function' && define.amd) {
|
||||
// AMD. Register as an anonymous module.
|
||||
|
@ -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.
|
||||
*/
|
@ -1,3 +1,4 @@
|
||||
{{>licenseInfo}}
|
||||
(function(root, factory) {
|
||||
if (typeof define === 'function' && define.amd) {
|
||||
// AMD. Register as an anonymous module.
|
||||
|
@ -1,3 +1,4 @@
|
||||
{{>licenseInfo}}
|
||||
(function(root, factory) {
|
||||
if (typeof define === 'function' && define.amd) {
|
||||
// AMD.
|
||||
|
@ -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
|
@ -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> apiClient );
|
||||
virtual ~{{classname}}();
|
||||
{{#operation}}
|
||||
/// <summary>
|
||||
/// {{summary}}
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// {{notes}}
|
||||
/// </remarks>
|
||||
{{#allParams}}/// <param name="{{paramName}}">{{description}}{{^required}} (optional{{#defaultValue}}, default to {{.}}{{/defaultValue}}){{/required}}</param>{{/allParams}}
|
||||
pplx::task<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}}> {{operationId}}({{#allParams}}{{{dataType}}} {{paramName}}{{^required}}{{/required}}{{#hasMore}}, {{/hasMore}}{{/allParams}});
|
||||
{{/operation}}
|
||||
|
||||
protected:
|
||||
std::shared_ptr<ApiClient> m_ApiClient;
|
||||
};
|
||||
|
||||
{{#apiNamespaceDeclarations}}
|
||||
}
|
||||
{{/apiNamespaceDeclarations}}
|
||||
|
||||
#endif /* {{classname}}_H_ */
|
||||
|
||||
{{/operations}}
|
@ -0,0 +1,269 @@
|
||||
{{#operations}}
|
||||
|
||||
#include "{{classname}}.h"
|
||||
#include "IHttpBody.h"
|
||||
#include "JsonBody.h"
|
||||
#include "MultipartFormData.h"
|
||||
|
||||
#include <unordered_set>
|
||||
|
||||
#include <boost/algorithm/string/replace.hpp>
|
||||
|
||||
{{#apiNamespaceDeclarations}}
|
||||
namespace {{this}} {
|
||||
{{/apiNamespaceDeclarations}}
|
||||
|
||||
using namespace {{modelNamespace}};
|
||||
|
||||
{{classname}}::{{classname}}( std::shared_ptr<ApiClient> 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> 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<utility::string_t, utility::string_t> queryParams;
|
||||
std::map<utility::string_t, utility::string_t> headerParams( apiConfiguration->getDefaultHeaders() );
|
||||
std::map<utility::string_t, utility::string_t> formParams;
|
||||
std::map<utility::string_t, std::shared_ptr<HttpContent>> fileParams;
|
||||
|
||||
std::unordered_set<utility::string_t> 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<utility::string_t> 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<IHttpBody> 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<web::json::value> 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<IHttpBody>( 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<MultipartFormData> multipart(new MultipartFormData);
|
||||
{{#isPrimitiveType}} multipart->add(ModelBase::toHttpContent("{{paramName}}", {{paramName}}));
|
||||
{{/isPrimitiveType}}{{^isPrimitiveType}}{{#isListContainer}}
|
||||
{
|
||||
std::vector<web::json::value> 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<std::stringstream>(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<std::stringstream>(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}}
|
@ -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 <memory>
|
||||
#include <vector>
|
||||
|
||||
#include <cpprest/details/basic_types.h>
|
||||
#include <cpprest/http_client.h>
|
||||
|
||||
{{#apiNamespaceDeclarations}}
|
||||
namespace {{this}} {
|
||||
{{/apiNamespaceDeclarations}}
|
||||
|
||||
using namespace {{modelNamespace}};
|
||||
|
||||
class {{declspec}} ApiClient
|
||||
{
|
||||
public:
|
||||
ApiClient( std::shared_ptr<ApiConfiguration> configuration = nullptr );
|
||||
virtual ~ApiClient();
|
||||
|
||||
std::shared_ptr<ApiConfiguration> getConfiguration() const;
|
||||
void setConfiguration(std::shared_ptr<ApiConfiguration> 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<class T>
|
||||
static utility::string_t parameterToArrayString(std::vector<T> 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<web::http::http_response> callApi(
|
||||
const utility::string_t& path,
|
||||
const utility::string_t& method,
|
||||
const std::map<utility::string_t, utility::string_t>& queryParams,
|
||||
const std::shared_ptr<IHttpBody> postBody,
|
||||
const std::map<utility::string_t, utility::string_t>& headerParams,
|
||||
const std::map<utility::string_t, utility::string_t>& formParams,
|
||||
const std::map<utility::string_t, std::shared_ptr<HttpContent>>& fileParams,
|
||||
const utility::string_t& contentType
|
||||
) const;
|
||||
|
||||
protected:
|
||||
|
||||
std::shared_ptr<ApiConfiguration> m_Configuration;
|
||||
};
|
||||
|
||||
{{#apiNamespaceDeclarations}}
|
||||
}
|
||||
{{/apiNamespaceDeclarations}}
|
||||
|
||||
#endif /* ApiClient_H_ */
|
@ -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<ApiConfiguration> configuration )
|
||||
: m_Configuration(configuration)
|
||||
{
|
||||
}
|
||||
ApiClient::~ApiClient()
|
||||
{
|
||||
}
|
||||
|
||||
std::shared_ptr<ApiConfiguration> ApiClient::getConfiguration() const
|
||||
{
|
||||
return m_Configuration;
|
||||
}
|
||||
void ApiClient::setConfiguration(std::shared_ptr<ApiConfiguration> 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<web::http::http_response> ApiClient::callApi(
|
||||
const utility::string_t& path,
|
||||
const utility::string_t& method,
|
||||
const std::map<utility::string_t, utility::string_t>& queryParams,
|
||||
const std::shared_ptr<IHttpBody> postBody,
|
||||
const std::map<utility::string_t, utility::string_t>& headerParams,
|
||||
const std::map<utility::string_t, utility::string_t>& formParams,
|
||||
const std::map<utility::string_t, std::shared_ptr<HttpContent>>& 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}}
|
@ -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 <map>
|
||||
|
||||
#include <cpprest/details/basic_types.h>
|
||||
#include <cpprest/http_client.h>
|
||||
{{#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<utility::string_t, utility::string_t>& 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<utility::string_t, utility::string_t> m_DefaultHeaders;
|
||||
std::map<utility::string_t, utility::string_t> m_ApiKeys;
|
||||
web::http::client::http_client_config m_HttpConfig;
|
||||
utility::string_t m_UserAgent;
|
||||
};
|
||||
|
||||
{{#apiNamespaceDeclarations}}
|
||||
}
|
||||
{{/apiNamespaceDeclarations}}
|
||||
#endif /* ApiConfiguration_H_ */
|
@ -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<utility::string_t, utility::string_t>& 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}}
|
@ -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 <memory>
|
||||
#include <map>
|
||||
|
||||
#include <cpprest/details/basic_types.h>
|
||||
#include <cpprest/http_msg.h>
|
||||
|
||||
|
||||
{{#apiNamespaceDeclarations}}
|
||||
namespace {{this}} {
|
||||
{{/apiNamespaceDeclarations}}
|
||||
|
||||
class {{declspec}} ApiException
|
||||
: public web::http::http_exception
|
||||
{
|
||||
public:
|
||||
ApiException( int errorCode
|
||||
, const utility::string_t& message
|
||||
, std::shared_ptr<std::istream> content = nullptr );
|
||||
ApiException( int errorCode
|
||||
, const utility::string_t& message
|
||||
, std::map<utility::string_t, utility::string_t>& headers
|
||||
, std::shared_ptr<std::istream> content = nullptr );
|
||||
virtual ~ApiException();
|
||||
|
||||
std::map<utility::string_t, utility::string_t>& getHeaders();
|
||||
std::shared_ptr<std::istream> getContent() const;
|
||||
|
||||
protected:
|
||||
std::shared_ptr<std::istream> m_Content;
|
||||
std::map<utility::string_t, utility::string_t> m_Headers;
|
||||
};
|
||||
|
||||
{{#apiNamespaceDeclarations}}
|
||||
}
|
||||
{{/apiNamespaceDeclarations}}
|
||||
|
||||
#endif /* ApiBase_H_ */
|
@ -0,0 +1,40 @@
|
||||
#include "ApiException.h"
|
||||
|
||||
{{#apiNamespaceDeclarations}}
|
||||
namespace {{this}} {
|
||||
{{/apiNamespaceDeclarations}}
|
||||
|
||||
ApiException::ApiException( int errorCode
|
||||
, const utility::string_t& message
|
||||
, std::shared_ptr<std::istream> content /*= nullptr*/ )
|
||||
: web::http::http_exception( errorCode, message )
|
||||
, m_Content(content)
|
||||
{
|
||||
}
|
||||
ApiException::ApiException( int errorCode
|
||||
, const utility::string_t& message
|
||||
, std::map<utility::string_t, utility::string_t>& headers
|
||||
, std::shared_ptr<std::istream> content /*= nullptr*/ )
|
||||
: web::http::http_exception( errorCode, message )
|
||||
, m_Content(content)
|
||||
, m_Headers(headers)
|
||||
{
|
||||
}
|
||||
|
||||
ApiException::~ApiException()
|
||||
{
|
||||
}
|
||||
|
||||
std::shared_ptr<std::istream> ApiException::getContent() const
|
||||
{
|
||||
return m_Content;
|
||||
}
|
||||
|
||||
std::map<utility::string_t, utility::string_t>& ApiException::getHeaders()
|
||||
{
|
||||
return m_Headers;
|
||||
}
|
||||
|
||||
{{#apiNamespaceDeclarations}}
|
||||
}
|
||||
{{/apiNamespaceDeclarations}}
|
@ -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'
|
@ -0,0 +1,29 @@
|
||||
# Compiled Object files
|
||||
*.slo
|
||||
*.lo
|
||||
*.o
|
||||
*.obj
|
||||
|
||||
# Precompiled Headers
|
||||
*.gch
|
||||
*.pch
|
||||
|
||||
# Compiled Dynamic libraries
|
||||
*.so
|
||||
*.dylib
|
||||
*.dll
|
||||
|
||||
# Fortran module files
|
||||
*.mod
|
||||
*.smod
|
||||
|
||||
# Compiled Static libraries
|
||||
*.lai
|
||||
*.la
|
||||
*.a
|
||||
*.lib
|
||||
|
||||
# Executables
|
||||
*.exe
|
||||
*.out
|
||||
*.app
|
@ -0,0 +1,56 @@
|
||||
/*
|
||||
* HttpContent.h
|
||||
*
|
||||
* This class represents a single item of a multipart-formdata request.
|
||||
*/
|
||||
|
||||
#ifndef HttpContent_H_
|
||||
#define HttpContent_H_
|
||||
|
||||
{{{defaultInclude}}}
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <cpprest/details/basic_types.h>
|
||||
|
||||
{{#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<std::istream> getData();
|
||||
virtual void setData( std::shared_ptr<std::istream> 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<std::istream> m_Data;
|
||||
};
|
||||
|
||||
{{#modelNamespaceDeclarations}}
|
||||
}
|
||||
{{/modelNamespaceDeclarations}}
|
||||
|
||||
#endif /* HttpContent_H_ */
|
@ -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<std::istream> HttpContent::getData()
|
||||
{
|
||||
return m_Data;
|
||||
}
|
||||
|
||||
void HttpContent::setData( std::shared_ptr<std::istream> value )
|
||||
{
|
||||
m_Data = value;
|
||||
}
|
||||
|
||||
void HttpContent::writeTo( std::ostream& stream )
|
||||
{
|
||||
m_Data->seekg( 0, m_Data->beg );
|
||||
stream << m_Data->rdbuf();
|
||||
}
|
||||
|
||||
{{#modelNamespaceDeclarations}}
|
||||
}
|
||||
{{/modelNamespaceDeclarations}}
|
@ -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 <iostream>
|
||||
|
||||
{{#modelNamespaceDeclarations}}
|
||||
namespace {{this}} {
|
||||
{{/modelNamespaceDeclarations}}
|
||||
|
||||
class {{declspec}} IHttpBody
|
||||
{
|
||||
public:
|
||||
virtual ~IHttpBody() { }
|
||||
|
||||
virtual void writeTo( std::ostream& stream ) = 0;
|
||||
};
|
||||
|
||||
{{#modelNamespaceDeclarations}}
|
||||
}
|
||||
{{/modelNamespaceDeclarations}}
|
||||
|
||||
#endif /* IHttpBody_H_ */
|
@ -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 <cpprest/json.h>
|
||||
|
||||
{{#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_ */
|
@ -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}}
|
@ -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}}
|
||||
|
||||
/// <summary>
|
||||
/// {{description}}
|
||||
/// </summary>
|
||||
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<MultipartFormData> multipart, const utility::string_t& namePrefix) const override;
|
||||
void fromMultiPart(std::shared_ptr<MultipartFormData> multipart, const utility::string_t& namePrefix) override;
|
||||
|
||||
/////////////////////////////////////////////
|
||||
/// {{classname}} members
|
||||
|
||||
{{#vars}}
|
||||
/// <summary>
|
||||
/// {{description}}
|
||||
/// </summary>
|
||||
{{^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}}
|
@ -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<web::json::value> 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<web::json::value> 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<MultipartFormData> 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<web::json::value> 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<MultipartFormData> 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}}
|
@ -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 <cpprest/details/basic_types.h>
|
||||
#include <cpprest/json.h>
|
||||
|
||||
{{#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<MultipartFormData> multipart, const utility::string_t& namePrefix) const = 0;
|
||||
virtual void fromMultiPart(std::shared_ptr<MultipartFormData> 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<HttpContent> value );
|
||||
static web::json::value toJson( std::shared_ptr<ModelBase> 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<HttpContent> fileFromJson(web::json::value& val);
|
||||
|
||||
static std::shared_ptr<HttpContent> toHttpContent( const utility::string_t& name, const utility::string_t& value, const utility::string_t& contentType = U(""));
|
||||
static std::shared_ptr<HttpContent> toHttpContent( const utility::string_t& name, const utility::datetime& value, const utility::string_t& contentType = U(""));
|
||||
static std::shared_ptr<HttpContent> toHttpContent( const utility::string_t& name, std::shared_ptr<HttpContent> value );
|
||||
static std::shared_ptr<HttpContent> toHttpContent( const utility::string_t& name, const web::json::value& value, const utility::string_t& contentType = U("application/json") );
|
||||
static std::shared_ptr<HttpContent> toHttpContent( const utility::string_t& name, int32_t value, const utility::string_t& contentType = U("") );
|
||||
static std::shared_ptr<HttpContent> toHttpContent( const utility::string_t& name, int64_t value, const utility::string_t& contentType = U("") );
|
||||
static std::shared_ptr<HttpContent> toHttpContent( const utility::string_t& name, double value, const utility::string_t& contentType = U("") );
|
||||
|
||||
static int64_t int64_tFromHttpContent(std::shared_ptr<HttpContent> val);
|
||||
static int32_t int32_tFromHttpContent(std::shared_ptr<HttpContent> val);
|
||||
static utility::string_t stringFromHttpContent(std::shared_ptr<HttpContent> val);
|
||||
static utility::datetime dateFromHttpContent(std::shared_ptr<HttpContent> val);
|
||||
static bool boolFromHttpContent(std::shared_ptr<HttpContent> val);
|
||||
static double doubleFromHttpContent(std::shared_ptr<HttpContent> val);
|
||||
|
||||
|
||||
static utility::string_t toBase64( utility::string_t value );
|
||||
static utility::string_t toBase64( std::shared_ptr<std::istream> value );
|
||||
static std::shared_ptr<std::istream> fromBase64( const utility::string_t& encoded );
|
||||
};
|
||||
|
||||
{{#modelNamespaceDeclarations}}
|
||||
}
|
||||
{{/modelNamespaceDeclarations}}
|
||||
|
||||
#endif /* ModelBase_H_ */
|
@ -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<HttpContent> 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<HttpContent> ModelBase::fileFromJson(web::json::value& val)
|
||||
{
|
||||
std::shared_ptr<HttpContent> 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<ModelBase> content )
|
||||
{
|
||||
return content.get() ? content->toJson() : web::json::value::null();
|
||||
}
|
||||
|
||||
std::shared_ptr<HttpContent> ModelBase::toHttpContent( const utility::string_t& name, const utility::string_t& value, const utility::string_t& contentType)
|
||||
{
|
||||
std::shared_ptr<HttpContent> content(new HttpContent);
|
||||
content->setName( name );
|
||||
content->setContentDisposition( U("form-data") );
|
||||
content->setContentType( contentType );
|
||||
content->setData( std::shared_ptr<std::istream>( new std::stringstream( utility::conversions::to_utf8string(value) ) ) );
|
||||
return content;
|
||||
}
|
||||
std::shared_ptr<HttpContent> ModelBase::toHttpContent( const utility::string_t& name, const utility::datetime& value, const utility::string_t& contentType )
|
||||
{
|
||||
std::shared_ptr<HttpContent> content( new HttpContent );
|
||||
content->setName( name );
|
||||
content->setContentDisposition( U("form-data") );
|
||||
content->setContentType( contentType );
|
||||
content->setData( std::shared_ptr<std::istream>( new std::stringstream( utility::conversions::to_utf8string(value.to_string(utility::datetime::ISO_8601) ) ) ) );
|
||||
return content;
|
||||
}
|
||||
std::shared_ptr<HttpContent> ModelBase::toHttpContent( const utility::string_t& name, std::shared_ptr<HttpContent> value )
|
||||
{
|
||||
std::shared_ptr<HttpContent> 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<HttpContent> ModelBase::toHttpContent( const utility::string_t& name, const web::json::value& value, const utility::string_t& contentType )
|
||||
{
|
||||
std::shared_ptr<HttpContent> content( new HttpContent );
|
||||
content->setName( name );
|
||||
content->setContentDisposition( U("form-data") );
|
||||
content->setContentType( contentType );
|
||||
content->setData( std::shared_ptr<std::istream>( new std::stringstream( utility::conversions::to_utf8string(value.serialize()) ) ) );
|
||||
return content;
|
||||
}
|
||||
std::shared_ptr<HttpContent> ModelBase::toHttpContent( const utility::string_t& name, int32_t value, const utility::string_t& contentType )
|
||||
{
|
||||
std::shared_ptr<HttpContent> content( new HttpContent );
|
||||
content->setName( name );
|
||||
content->setContentDisposition( U("form-data") );
|
||||
content->setContentType( contentType );
|
||||
content->setData( std::shared_ptr<std::istream>( new std::stringstream( std::to_string( value ) ) ) );
|
||||
return content;
|
||||
}
|
||||
std::shared_ptr<HttpContent> ModelBase::toHttpContent( const utility::string_t& name, int64_t value, const utility::string_t& contentType )
|
||||
{
|
||||
std::shared_ptr<HttpContent> content( new HttpContent );
|
||||
content->setName( name );
|
||||
content->setContentDisposition( U("form-data") );
|
||||
content->setContentType( contentType );
|
||||
content->setData( std::shared_ptr<std::istream>( new std::stringstream( std::to_string( value ) ) ) );
|
||||
return content;
|
||||
}
|
||||
std::shared_ptr<HttpContent> ModelBase::toHttpContent( const utility::string_t& name, double value, const utility::string_t& contentType )
|
||||
{
|
||||
std::shared_ptr<HttpContent> content( new HttpContent );
|
||||
content->setName( name );
|
||||
content->setContentDisposition( U("form-data") );
|
||||
content->setContentType( contentType );
|
||||
content->setData( std::shared_ptr<std::istream>( 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<std::istream> source( new std::stringstream( utility::conversions::to_utf8string(value) ) );
|
||||
return ModelBase::toBase64(source);
|
||||
}
|
||||
utility::string_t ModelBase::toBase64( std::shared_ptr<std::istream> 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<std::istream> ModelBase::fromBase64( const utility::string_t& encoded )
|
||||
{
|
||||
std::shared_ptr<std::stringstream> 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<HttpContent> 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<HttpContent> 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<HttpContent> val)
|
||||
{
|
||||
std::shared_ptr<std::istream> data = val->getData();
|
||||
data->seekg( 0, data->beg );
|
||||
|
||||
std::string str((std::istreambuf_iterator<char>(*data.get())),
|
||||
std::istreambuf_iterator<char>());
|
||||
|
||||
return utility::conversions::to_utf16string(str);
|
||||
}
|
||||
utility::datetime ModelBase::dateFromHttpContent(std::shared_ptr<HttpContent> val)
|
||||
{
|
||||
utility::string_t str = ModelBase::stringFromHttpContent(val);
|
||||
return utility::datetime::from_string(str, utility::datetime::ISO_8601);
|
||||
}
|
||||
|
||||
bool ModelBase::boolFromHttpContent(std::shared_ptr<HttpContent> 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<HttpContent> val)
|
||||
{
|
||||
utility::string_t str = ModelBase::stringFromHttpContent(val);
|
||||
|
||||
utility::stringstream_t ss(str);
|
||||
double result = 0.0;
|
||||
ss >> result;
|
||||
return result;
|
||||
}
|
||||
|
||||
{{#modelNamespaceDeclarations}}
|
||||
}
|
||||
{{/modelNamespaceDeclarations}}
|
@ -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 <vector>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
|
||||
#include <cpprest/details/basic_types.h>
|
||||
|
||||
|
||||
{{#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<HttpContent> content );
|
||||
virtual utility::string_t getBoundary();
|
||||
virtual std::shared_ptr<HttpContent> 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<std::shared_ptr<HttpContent>> m_Contents;
|
||||
utility::string_t m_Boundary;
|
||||
std::map<utility::string_t, std::shared_ptr<HttpContent>> m_ContentLookup;
|
||||
};
|
||||
|
||||
{{#modelNamespaceDeclarations}}
|
||||
}
|
||||
{{/modelNamespaceDeclarations}}
|
||||
|
||||
#endif /* MultipartFormData_H_ */
|
@ -0,0 +1,99 @@
|
||||
#include "MultipartFormData.h"
|
||||
#include "ModelBase.h"
|
||||
|
||||
#include <boost/uuid/random_generator.hpp>
|
||||
#include <boost/uuid/uuid_io.hpp>
|
||||
|
||||
{{#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<HttpContent> 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<HttpContent> MultipartFormData::getContent(const utility::string_t& name) const
|
||||
{
|
||||
auto result = m_ContentLookup.find(name);
|
||||
if(result == m_ContentLookup.end())
|
||||
{
|
||||
return std::shared_ptr<HttpContent>(nullptr);
|
||||
}
|
||||
return result->second;
|
||||
}
|
||||
|
||||
void MultipartFormData::writeTo( std::ostream& target )
|
||||
{
|
||||
for ( size_t i = 0; i < m_Contents.size(); i++ )
|
||||
{
|
||||
std::shared_ptr<HttpContent> 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<std::istream> data = content->getData();
|
||||
|
||||
data->seekg( 0, data->end );
|
||||
std::vector<char> dataBytes( data->tellg() );
|
||||
|
||||
data->seekg( 0, data->beg );
|
||||
data->read( &dataBytes[0], dataBytes.size() );
|
||||
|
||||
std::copy( dataBytes.begin(), dataBytes.end(), std::ostreambuf_iterator<char>( target ) );
|
||||
}
|
||||
|
||||
target << "\r\n--" << utility::conversions::to_utf8string( m_Boundary ) << "--\r\n";
|
||||
}
|
||||
|
||||
{{#modelNamespaceDeclarations}}
|
||||
}
|
||||
{{/modelNamespaceDeclarations}}
|
@ -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
|
||||
```
|
||||
|
@ -0,0 +1 @@
|
||||
application: {{packageName}}
|
@ -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}}
|
@ -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),
|
||||
)
|
||||
})
|
||||
}
|
@ -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))
|
||||
}
|
@ -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}}
|
||||
}
|
@ -0,0 +1 @@
|
||||
{{{swagger-yaml}}}
|
@ -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<String, String> createOptions() {
|
||||
ImmutableMap.Builder<String, String> builder = new ImmutableMap.Builder<String, String>();
|
||||
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;
|
||||
}
|
||||
}
|
29
samples/client/petstore/cpprest/.gitignore
vendored
Normal file
29
samples/client/petstore/cpprest/.gitignore
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
# Compiled Object files
|
||||
*.slo
|
||||
*.lo
|
||||
*.o
|
||||
*.obj
|
||||
|
||||
# Precompiled Headers
|
||||
*.gch
|
||||
*.pch
|
||||
|
||||
# Compiled Dynamic libraries
|
||||
*.so
|
||||
*.dylib
|
||||
*.dll
|
||||
|
||||
# Fortran module files
|
||||
*.mod
|
||||
*.smod
|
||||
|
||||
# Compiled Static libraries
|
||||
*.lai
|
||||
*.la
|
||||
*.a
|
||||
*.lib
|
||||
|
||||
# Executables
|
||||
*.exe
|
||||
*.out
|
||||
*.app
|
23
samples/client/petstore/cpprest/.swagger-codegen-ignore
Normal file
23
samples/client/petstore/cpprest/.swagger-codegen-ignore
Normal file
@ -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
|
133
samples/client/petstore/cpprest/ApiClient.cpp
Normal file
133
samples/client/petstore/cpprest/ApiClient.cpp
Normal file
@ -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<ApiConfiguration> configuration )
|
||||
: m_Configuration(configuration)
|
||||
{
|
||||
}
|
||||
ApiClient::~ApiClient()
|
||||
{
|
||||
}
|
||||
|
||||
std::shared_ptr<ApiConfiguration> ApiClient::getConfiguration() const
|
||||
{
|
||||
return m_Configuration;
|
||||
}
|
||||
void ApiClient::setConfiguration(std::shared_ptr<ApiConfiguration> 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<web::http::http_response> ApiClient::callApi(
|
||||
const utility::string_t& path,
|
||||
const utility::string_t& method,
|
||||
const std::map<utility::string_t, utility::string_t>& queryParams,
|
||||
const std::shared_ptr<IHttpBody> postBody,
|
||||
const std::map<utility::string_t, utility::string_t>& headerParams,
|
||||
const std::map<utility::string_t, utility::string_t>& formParams,
|
||||
const std::map<utility::string_t, std::shared_ptr<HttpContent>>& 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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
77
samples/client/petstore/cpprest/ApiClient.h
Normal file
77
samples/client/petstore/cpprest/ApiClient.h
Normal file
@ -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 <memory>
|
||||
#include <vector>
|
||||
|
||||
#include <cpprest/details/basic_types.h>
|
||||
#include <cpprest/http_client.h>
|
||||
|
||||
namespace io {
|
||||
namespace swagger {
|
||||
namespace client {
|
||||
namespace api {
|
||||
|
||||
using namespace io::swagger::client::model;
|
||||
|
||||
class ApiClient
|
||||
{
|
||||
public:
|
||||
ApiClient( std::shared_ptr<ApiConfiguration> configuration = nullptr );
|
||||
virtual ~ApiClient();
|
||||
|
||||
std::shared_ptr<ApiConfiguration> getConfiguration() const;
|
||||
void setConfiguration(std::shared_ptr<ApiConfiguration> 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<class T>
|
||||
static utility::string_t parameterToArrayString(std::vector<T> 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<web::http::http_response> callApi(
|
||||
const utility::string_t& path,
|
||||
const utility::string_t& method,
|
||||
const std::map<utility::string_t, utility::string_t>& queryParams,
|
||||
const std::shared_ptr<IHttpBody> postBody,
|
||||
const std::map<utility::string_t, utility::string_t>& headerParams,
|
||||
const std::map<utility::string_t, utility::string_t>& formParams,
|
||||
const std::map<utility::string_t, std::shared_ptr<HttpContent>>& fileParams,
|
||||
const utility::string_t& contentType
|
||||
) const;
|
||||
|
||||
protected:
|
||||
|
||||
std::shared_ptr<ApiConfiguration> m_Configuration;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* ApiClient_H_ */
|
69
samples/client/petstore/cpprest/ApiConfiguration.cpp
Normal file
69
samples/client/petstore/cpprest/ApiConfiguration.cpp
Normal file
@ -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<utility::string_t, utility::string_t>& 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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
53
samples/client/petstore/cpprest/ApiConfiguration.h
Normal file
53
samples/client/petstore/cpprest/ApiConfiguration.h
Normal file
@ -0,0 +1,53 @@
|
||||
/*
|
||||
* ApiConfiguration.h
|
||||
*
|
||||
* This class represents a single item of a multipart-formdata request.
|
||||
*/
|
||||
|
||||
#ifndef ApiConfiguration_H_
|
||||
#define ApiConfiguration_H_
|
||||
|
||||
|
||||
|
||||
#include <map>
|
||||
|
||||
#include <cpprest/details/basic_types.h>
|
||||
#include <cpprest/http_client.h>
|
||||
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<utility::string_t, utility::string_t>& 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<utility::string_t, utility::string_t> m_DefaultHeaders;
|
||||
std::map<utility::string_t, utility::string_t> m_ApiKeys;
|
||||
web::http::client::http_client_config m_HttpConfig;
|
||||
utility::string_t m_UserAgent;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif /* ApiConfiguration_H_ */
|
42
samples/client/petstore/cpprest/ApiException.cpp
Normal file
42
samples/client/petstore/cpprest/ApiException.cpp
Normal file
@ -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<std::istream> content /*= nullptr*/ )
|
||||
: web::http::http_exception( errorCode, message )
|
||||
, m_Content(content)
|
||||
{
|
||||
}
|
||||
ApiException::ApiException( int errorCode
|
||||
, const utility::string_t& message
|
||||
, std::map<utility::string_t, utility::string_t>& headers
|
||||
, std::shared_ptr<std::istream> content /*= nullptr*/ )
|
||||
: web::http::http_exception( errorCode, message )
|
||||
, m_Content(content)
|
||||
, m_Headers(headers)
|
||||
{
|
||||
}
|
||||
|
||||
ApiException::~ApiException()
|
||||
{
|
||||
}
|
||||
|
||||
std::shared_ptr<std::istream> ApiException::getContent() const
|
||||
{
|
||||
return m_Content;
|
||||
}
|
||||
|
||||
std::map<utility::string_t, utility::string_t>& ApiException::getHeaders()
|
||||
{
|
||||
return m_Headers;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
50
samples/client/petstore/cpprest/ApiException.h
Normal file
50
samples/client/petstore/cpprest/ApiException.h
Normal file
@ -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 <memory>
|
||||
#include <map>
|
||||
|
||||
#include <cpprest/details/basic_types.h>
|
||||
#include <cpprest/http_msg.h>
|
||||
|
||||
|
||||
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<std::istream> content = nullptr );
|
||||
ApiException( int errorCode
|
||||
, const utility::string_t& message
|
||||
, std::map<utility::string_t, utility::string_t>& headers
|
||||
, std::shared_ptr<std::istream> content = nullptr );
|
||||
virtual ~ApiException();
|
||||
|
||||
std::map<utility::string_t, utility::string_t>& getHeaders();
|
||||
std::shared_ptr<std::istream> getContent() const;
|
||||
|
||||
protected:
|
||||
std::shared_ptr<std::istream> m_Content;
|
||||
std::map<utility::string_t, utility::string_t> m_Headers;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* ApiBase_H_ */
|
75
samples/client/petstore/cpprest/HttpContent.cpp
Normal file
75
samples/client/petstore/cpprest/HttpContent.cpp
Normal file
@ -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<std::istream> HttpContent::getData()
|
||||
{
|
||||
return m_Data;
|
||||
}
|
||||
|
||||
void HttpContent::setData( std::shared_ptr<std::istream> value )
|
||||
{
|
||||
m_Data = value;
|
||||
}
|
||||
|
||||
void HttpContent::writeTo( std::ostream& stream )
|
||||
{
|
||||
m_Data->seekg( 0, m_Data->beg );
|
||||
stream << m_Data->rdbuf();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
58
samples/client/petstore/cpprest/HttpContent.h
Normal file
58
samples/client/petstore/cpprest/HttpContent.h
Normal file
@ -0,0 +1,58 @@
|
||||
/*
|
||||
* HttpContent.h
|
||||
*
|
||||
* This class represents a single item of a multipart-formdata request.
|
||||
*/
|
||||
|
||||
#ifndef HttpContent_H_
|
||||
#define HttpContent_H_
|
||||
|
||||
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <cpprest/details/basic_types.h>
|
||||
|
||||
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<std::istream> getData();
|
||||
virtual void setData( std::shared_ptr<std::istream> 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<std::istream> m_Data;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* HttpContent_H_ */
|
31
samples/client/petstore/cpprest/IHttpBody.h
Normal file
31
samples/client/petstore/cpprest/IHttpBody.h
Normal file
@ -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 <iostream>
|
||||
|
||||
namespace io {
|
||||
namespace swagger {
|
||||
namespace client {
|
||||
namespace model {
|
||||
|
||||
class IHttpBody
|
||||
{
|
||||
public:
|
||||
virtual ~IHttpBody() { }
|
||||
|
||||
virtual void writeTo( std::ostream& stream ) = 0;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* IHttpBody_H_ */
|
25
samples/client/petstore/cpprest/JsonBody.cpp
Normal file
25
samples/client/petstore/cpprest/JsonBody.cpp
Normal file
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
38
samples/client/petstore/cpprest/JsonBody.h
Normal file
38
samples/client/petstore/cpprest/JsonBody.h
Normal file
@ -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 <cpprest/json.h>
|
||||
|
||||
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_ */
|
201
samples/client/petstore/cpprest/LICENSE
Normal file
201
samples/client/petstore/cpprest/LICENSE
Normal file
@ -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.
|
339
samples/client/petstore/cpprest/ModelBase.cpp
Normal file
339
samples/client/petstore/cpprest/ModelBase.cpp
Normal file
@ -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<HttpContent> 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<HttpContent> ModelBase::fileFromJson(web::json::value& val)
|
||||
{
|
||||
std::shared_ptr<HttpContent> 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<ModelBase> content )
|
||||
{
|
||||
return content.get() ? content->toJson() : web::json::value::null();
|
||||
}
|
||||
|
||||
std::shared_ptr<HttpContent> ModelBase::toHttpContent( const utility::string_t& name, const utility::string_t& value, const utility::string_t& contentType)
|
||||
{
|
||||
std::shared_ptr<HttpContent> content(new HttpContent);
|
||||
content->setName( name );
|
||||
content->setContentDisposition( U("form-data") );
|
||||
content->setContentType( contentType );
|
||||
content->setData( std::shared_ptr<std::istream>( new std::stringstream( utility::conversions::to_utf8string(value) ) ) );
|
||||
return content;
|
||||
}
|
||||
std::shared_ptr<HttpContent> ModelBase::toHttpContent( const utility::string_t& name, const utility::datetime& value, const utility::string_t& contentType )
|
||||
{
|
||||
std::shared_ptr<HttpContent> content( new HttpContent );
|
||||
content->setName( name );
|
||||
content->setContentDisposition( U("form-data") );
|
||||
content->setContentType( contentType );
|
||||
content->setData( std::shared_ptr<std::istream>( new std::stringstream( utility::conversions::to_utf8string(value.to_string(utility::datetime::ISO_8601) ) ) ) );
|
||||
return content;
|
||||
}
|
||||
std::shared_ptr<HttpContent> ModelBase::toHttpContent( const utility::string_t& name, std::shared_ptr<HttpContent> value )
|
||||
{
|
||||
std::shared_ptr<HttpContent> 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<HttpContent> ModelBase::toHttpContent( const utility::string_t& name, const web::json::value& value, const utility::string_t& contentType )
|
||||
{
|
||||
std::shared_ptr<HttpContent> content( new HttpContent );
|
||||
content->setName( name );
|
||||
content->setContentDisposition( U("form-data") );
|
||||
content->setContentType( contentType );
|
||||
content->setData( std::shared_ptr<std::istream>( new std::stringstream( utility::conversions::to_utf8string(value.serialize()) ) ) );
|
||||
return content;
|
||||
}
|
||||
std::shared_ptr<HttpContent> ModelBase::toHttpContent( const utility::string_t& name, int32_t value, const utility::string_t& contentType )
|
||||
{
|
||||
std::shared_ptr<HttpContent> content( new HttpContent );
|
||||
content->setName( name );
|
||||
content->setContentDisposition( U("form-data") );
|
||||
content->setContentType( contentType );
|
||||
content->setData( std::shared_ptr<std::istream>( new std::stringstream( std::to_string( value ) ) ) );
|
||||
return content;
|
||||
}
|
||||
std::shared_ptr<HttpContent> ModelBase::toHttpContent( const utility::string_t& name, int64_t value, const utility::string_t& contentType )
|
||||
{
|
||||
std::shared_ptr<HttpContent> content( new HttpContent );
|
||||
content->setName( name );
|
||||
content->setContentDisposition( U("form-data") );
|
||||
content->setContentType( contentType );
|
||||
content->setData( std::shared_ptr<std::istream>( new std::stringstream( std::to_string( value ) ) ) );
|
||||
return content;
|
||||
}
|
||||
std::shared_ptr<HttpContent> ModelBase::toHttpContent( const utility::string_t& name, double value, const utility::string_t& contentType )
|
||||
{
|
||||
std::shared_ptr<HttpContent> content( new HttpContent );
|
||||
content->setName( name );
|
||||
content->setContentDisposition( U("form-data") );
|
||||
content->setContentType( contentType );
|
||||
content->setData( std::shared_ptr<std::istream>( 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<std::istream> source( new std::stringstream( utility::conversions::to_utf8string(value) ) );
|
||||
return ModelBase::toBase64(source);
|
||||
}
|
||||
utility::string_t ModelBase::toBase64( std::shared_ptr<std::istream> 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<std::istream> ModelBase::fromBase64( const utility::string_t& encoded )
|
||||
{
|
||||
std::shared_ptr<std::stringstream> 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<HttpContent> 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<HttpContent> 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<HttpContent> val)
|
||||
{
|
||||
std::shared_ptr<std::istream> data = val->getData();
|
||||
data->seekg( 0, data->beg );
|
||||
|
||||
std::string str((std::istreambuf_iterator<char>(*data.get())),
|
||||
std::istreambuf_iterator<char>());
|
||||
|
||||
return utility::conversions::to_utf16string(str);
|
||||
}
|
||||
utility::datetime ModelBase::dateFromHttpContent(std::shared_ptr<HttpContent> val)
|
||||
{
|
||||
utility::string_t str = ModelBase::stringFromHttpContent(val);
|
||||
return utility::datetime::from_string(str, utility::datetime::ISO_8601);
|
||||
}
|
||||
|
||||
bool ModelBase::boolFromHttpContent(std::shared_ptr<HttpContent> 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<HttpContent> val)
|
||||
{
|
||||
utility::string_t str = ModelBase::stringFromHttpContent(val);
|
||||
|
||||
utility::stringstream_t ss(str);
|
||||
double result = 0.0;
|
||||
ss >> result;
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
78
samples/client/petstore/cpprest/ModelBase.h
Normal file
78
samples/client/petstore/cpprest/ModelBase.h
Normal file
@ -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 <cpprest/details/basic_types.h>
|
||||
#include <cpprest/json.h>
|
||||
|
||||
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<MultipartFormData> multipart, const utility::string_t& namePrefix) const = 0;
|
||||
virtual void fromMultiPart(std::shared_ptr<MultipartFormData> 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<HttpContent> value );
|
||||
static web::json::value toJson( std::shared_ptr<ModelBase> 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<HttpContent> fileFromJson(web::json::value& val);
|
||||
|
||||
static std::shared_ptr<HttpContent> toHttpContent( const utility::string_t& name, const utility::string_t& value, const utility::string_t& contentType = U(""));
|
||||
static std::shared_ptr<HttpContent> toHttpContent( const utility::string_t& name, const utility::datetime& value, const utility::string_t& contentType = U(""));
|
||||
static std::shared_ptr<HttpContent> toHttpContent( const utility::string_t& name, std::shared_ptr<HttpContent> value );
|
||||
static std::shared_ptr<HttpContent> toHttpContent( const utility::string_t& name, const web::json::value& value, const utility::string_t& contentType = U("application/json") );
|
||||
static std::shared_ptr<HttpContent> toHttpContent( const utility::string_t& name, int32_t value, const utility::string_t& contentType = U("") );
|
||||
static std::shared_ptr<HttpContent> toHttpContent( const utility::string_t& name, int64_t value, const utility::string_t& contentType = U("") );
|
||||
static std::shared_ptr<HttpContent> toHttpContent( const utility::string_t& name, double value, const utility::string_t& contentType = U("") );
|
||||
|
||||
static int64_t int64_tFromHttpContent(std::shared_ptr<HttpContent> val);
|
||||
static int32_t int32_tFromHttpContent(std::shared_ptr<HttpContent> val);
|
||||
static utility::string_t stringFromHttpContent(std::shared_ptr<HttpContent> val);
|
||||
static utility::datetime dateFromHttpContent(std::shared_ptr<HttpContent> val);
|
||||
static bool boolFromHttpContent(std::shared_ptr<HttpContent> val);
|
||||
static double doubleFromHttpContent(std::shared_ptr<HttpContent> val);
|
||||
|
||||
|
||||
static utility::string_t toBase64( utility::string_t value );
|
||||
static utility::string_t toBase64( std::shared_ptr<std::istream> value );
|
||||
static std::shared_ptr<std::istream> fromBase64( const utility::string_t& encoded );
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* ModelBase_H_ */
|
101
samples/client/petstore/cpprest/MultipartFormData.cpp
Normal file
101
samples/client/petstore/cpprest/MultipartFormData.cpp
Normal file
@ -0,0 +1,101 @@
|
||||
#include "MultipartFormData.h"
|
||||
#include "ModelBase.h"
|
||||
|
||||
#include <boost/uuid/random_generator.hpp>
|
||||
#include <boost/uuid/uuid_io.hpp>
|
||||
|
||||
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<HttpContent> 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<HttpContent> MultipartFormData::getContent(const utility::string_t& name) const
|
||||
{
|
||||
auto result = m_ContentLookup.find(name);
|
||||
if(result == m_ContentLookup.end())
|
||||
{
|
||||
return std::shared_ptr<HttpContent>(nullptr);
|
||||
}
|
||||
return result->second;
|
||||
}
|
||||
|
||||
void MultipartFormData::writeTo( std::ostream& target )
|
||||
{
|
||||
for ( size_t i = 0; i < m_Contents.size(); i++ )
|
||||
{
|
||||
std::shared_ptr<HttpContent> 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<std::istream> data = content->getData();
|
||||
|
||||
data->seekg( 0, data->end );
|
||||
std::vector<char> dataBytes( data->tellg() );
|
||||
|
||||
data->seekg( 0, data->beg );
|
||||
data->read( &dataBytes[0], dataBytes.size() );
|
||||
|
||||
std::copy( dataBytes.begin(), dataBytes.end(), std::ostreambuf_iterator<char>( target ) );
|
||||
}
|
||||
|
||||
target << "\r\n--" << utility::conversions::to_utf8string( m_Boundary ) << "--\r\n";
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
51
samples/client/petstore/cpprest/MultipartFormData.h
Normal file
51
samples/client/petstore/cpprest/MultipartFormData.h
Normal file
@ -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 <vector>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
|
||||
#include <cpprest/details/basic_types.h>
|
||||
|
||||
|
||||
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<HttpContent> content );
|
||||
virtual utility::string_t getBoundary();
|
||||
virtual std::shared_ptr<HttpContent> 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<std::shared_ptr<HttpContent>> m_Contents;
|
||||
utility::string_t m_Boundary;
|
||||
std::map<utility::string_t, std::shared_ptr<HttpContent>> m_ContentLookup;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* MultipartFormData_H_ */
|
1000
samples/client/petstore/cpprest/api/PetApi.cpp
Normal file
1000
samples/client/petstore/cpprest/api/PetApi.cpp
Normal file
File diff suppressed because it is too large
Load Diff
105
samples/client/petstore/cpprest/api/PetApi.h
Normal file
105
samples/client/petstore/cpprest/api/PetApi.h
Normal file
@ -0,0 +1,105 @@
|
||||
/*
|
||||
* PetApi.h
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef PetApi_H_
|
||||
#define PetApi_H_
|
||||
|
||||
|
||||
#include "ApiClient.h"
|
||||
|
||||
#include "Pet.h"
|
||||
#include <cpprest/details/basic_types.h>
|
||||
#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> apiClient );
|
||||
virtual ~PetApi();
|
||||
/// <summary>
|
||||
/// Add a new pet to the store
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
///
|
||||
/// </remarks>
|
||||
/// <param name="body">Pet object that needs to be added to the store</param>
|
||||
pplx::task<void> addPet(std::shared_ptr<Pet> body);
|
||||
/// <summary>
|
||||
/// Deletes a pet
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
///
|
||||
/// </remarks>
|
||||
/// <param name="petId">Pet id to delete</param>/// <param name="apiKey"> (optional)</param>
|
||||
pplx::task<void> deletePet(int64_t petId, utility::string_t apiKey);
|
||||
/// <summary>
|
||||
/// Finds Pets by status
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Multiple status values can be provided with comma separated strings
|
||||
/// </remarks>
|
||||
/// <param name="status">Status values that need to be considered for filter</param>
|
||||
pplx::task<std::vector<std::shared_ptr<Pet>>> findPetsByStatus(std::vector<utility::string_t> status);
|
||||
/// <summary>
|
||||
/// Finds Pets by tags
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
|
||||
/// </remarks>
|
||||
/// <param name="tags">Tags to filter by</param>
|
||||
pplx::task<std::vector<std::shared_ptr<Pet>>> findPetsByTags(std::vector<utility::string_t> tags);
|
||||
/// <summary>
|
||||
/// Find pet by ID
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Returns a single pet
|
||||
/// </remarks>
|
||||
/// <param name="petId">ID of pet to return</param>
|
||||
pplx::task<std::shared_ptr<Pet>> getPetById(int64_t petId);
|
||||
/// <summary>
|
||||
/// Update an existing pet
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
///
|
||||
/// </remarks>
|
||||
/// <param name="body">Pet object that needs to be added to the store</param>
|
||||
pplx::task<void> updatePet(std::shared_ptr<Pet> body);
|
||||
/// <summary>
|
||||
/// Updates a pet in the store with form data
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
///
|
||||
/// </remarks>
|
||||
/// <param name="petId">ID of pet that needs to be updated</param>/// <param name="name">Updated name of the pet (optional)</param>/// <param name="status">Updated status of the pet (optional)</param>
|
||||
pplx::task<void> updatePetWithForm(int64_t petId, utility::string_t name, utility::string_t status);
|
||||
/// <summary>
|
||||
/// uploads an image
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
///
|
||||
/// </remarks>
|
||||
/// <param name="petId">ID of pet to update</param>/// <param name="additionalMetadata">Additional data to pass to server (optional)</param>/// <param name="file">file to upload (optional)</param>
|
||||
pplx::task<std::shared_ptr<ApiResponse>> uploadFile(int64_t petId, utility::string_t additionalMetadata, std::shared_ptr<HttpContent> file);
|
||||
|
||||
protected:
|
||||
std::shared_ptr<ApiClient> m_ApiClient;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* PetApi_H_ */
|
||||
|
508
samples/client/petstore/cpprest/api/StoreApi.cpp
Normal file
508
samples/client/petstore/cpprest/api/StoreApi.cpp
Normal file
@ -0,0 +1,508 @@
|
||||
|
||||
#include "StoreApi.h"
|
||||
#include "IHttpBody.h"
|
||||
#include "JsonBody.h"
|
||||
#include "MultipartFormData.h"
|
||||
|
||||
#include <unordered_set>
|
||||
|
||||
#include <boost/algorithm/string/replace.hpp>
|
||||
|
||||
namespace io {
|
||||
namespace swagger {
|
||||
namespace client {
|
||||
namespace api {
|
||||
|
||||
using namespace io::swagger::client::model;
|
||||
|
||||
StoreApi::StoreApi( std::shared_ptr<ApiClient> apiClient )
|
||||
: m_ApiClient(apiClient)
|
||||
{
|
||||
}
|
||||
|
||||
StoreApi::~StoreApi()
|
||||
{
|
||||
}
|
||||
|
||||
pplx::task<void> StoreApi::deleteOrder(utility::string_t orderId)
|
||||
{
|
||||
|
||||
|
||||
std::shared_ptr<ApiConfiguration> 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<utility::string_t, utility::string_t> queryParams;
|
||||
std::map<utility::string_t, utility::string_t> headerParams( apiConfiguration->getDefaultHeaders() );
|
||||
std::map<utility::string_t, utility::string_t> formParams;
|
||||
std::map<utility::string_t, std::shared_ptr<HttpContent>> fileParams;
|
||||
|
||||
std::unordered_set<utility::string_t> 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<utility::string_t> consumeHttpContentTypes;
|
||||
|
||||
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
std::shared_ptr<IHttpBody> 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<std::stringstream>(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<std::stringstream>(response.extract_utf8string(true).get()));
|
||||
}
|
||||
}
|
||||
|
||||
return response.extract_string();
|
||||
})
|
||||
.then([=](utility::string_t response)
|
||||
{
|
||||
return void();
|
||||
});
|
||||
}
|
||||
pplx::task<std::map<utility::string_t, int32_t>> StoreApi::getInventory()
|
||||
{
|
||||
|
||||
|
||||
std::shared_ptr<ApiConfiguration> apiConfiguration( m_ApiClient->getConfiguration() );
|
||||
utility::string_t path = U("/store/inventory");
|
||||
|
||||
std::map<utility::string_t, utility::string_t> queryParams;
|
||||
std::map<utility::string_t, utility::string_t> headerParams( apiConfiguration->getDefaultHeaders() );
|
||||
std::map<utility::string_t, utility::string_t> formParams;
|
||||
std::map<utility::string_t, std::shared_ptr<HttpContent>> fileParams;
|
||||
|
||||
std::unordered_set<utility::string_t> 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<utility::string_t> consumeHttpContentTypes;
|
||||
|
||||
|
||||
|
||||
std::shared_ptr<IHttpBody> 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<std::stringstream>(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<std::stringstream>(response.extract_utf8string(true).get()));
|
||||
}
|
||||
}
|
||||
|
||||
return response.extract_string();
|
||||
})
|
||||
.then([=](utility::string_t response)
|
||||
{
|
||||
std::map<utility::string_t, int32_t> 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<std::shared_ptr<Order>> StoreApi::getOrderById(int64_t orderId)
|
||||
{
|
||||
|
||||
|
||||
std::shared_ptr<ApiConfiguration> 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<utility::string_t, utility::string_t> queryParams;
|
||||
std::map<utility::string_t, utility::string_t> headerParams( apiConfiguration->getDefaultHeaders() );
|
||||
std::map<utility::string_t, utility::string_t> formParams;
|
||||
std::map<utility::string_t, std::shared_ptr<HttpContent>> fileParams;
|
||||
|
||||
std::unordered_set<utility::string_t> 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<utility::string_t> consumeHttpContentTypes;
|
||||
|
||||
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
std::shared_ptr<IHttpBody> 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<std::stringstream>(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<std::stringstream>(response.extract_utf8string(true).get()));
|
||||
}
|
||||
}
|
||||
|
||||
return response.extract_string();
|
||||
})
|
||||
.then([=](utility::string_t response)
|
||||
{
|
||||
std::shared_ptr<Order> 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<std::shared_ptr<Order>> StoreApi::placeOrder(std::shared_ptr<Order> 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> apiConfiguration( m_ApiClient->getConfiguration() );
|
||||
utility::string_t path = U("/store/order");
|
||||
|
||||
std::map<utility::string_t, utility::string_t> queryParams;
|
||||
std::map<utility::string_t, utility::string_t> headerParams( apiConfiguration->getDefaultHeaders() );
|
||||
std::map<utility::string_t, utility::string_t> formParams;
|
||||
std::map<utility::string_t, std::shared_ptr<HttpContent>> fileParams;
|
||||
|
||||
std::unordered_set<utility::string_t> 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<utility::string_t> consumeHttpContentTypes;
|
||||
|
||||
|
||||
|
||||
std::shared_ptr<IHttpBody> 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<IHttpBody>( new JsonBody( json ) );
|
||||
|
||||
}
|
||||
// multipart formdata
|
||||
else if( consumeHttpContentTypes.find(U("multipart/form-data")) != consumeHttpContentTypes.end() )
|
||||
{
|
||||
requestHttpContentType = U("multipart/form-data");
|
||||
|
||||
std::shared_ptr<MultipartFormData> 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<std::stringstream>(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<std::stringstream>(response.extract_utf8string(true).get()));
|
||||
}
|
||||
}
|
||||
|
||||
return response.extract_string();
|
||||
})
|
||||
.then([=](utility::string_t response)
|
||||
{
|
||||
std::shared_ptr<Order> 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;
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
72
samples/client/petstore/cpprest/api/StoreApi.h
Normal file
72
samples/client/petstore/cpprest/api/StoreApi.h
Normal file
@ -0,0 +1,72 @@
|
||||
/*
|
||||
* StoreApi.h
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef StoreApi_H_
|
||||
#define StoreApi_H_
|
||||
|
||||
|
||||
#include "ApiClient.h"
|
||||
|
||||
#include <cpprest/details/basic_types.h>
|
||||
#include <map>
|
||||
#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> apiClient );
|
||||
virtual ~StoreApi();
|
||||
/// <summary>
|
||||
/// Delete purchase order by ID
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors
|
||||
/// </remarks>
|
||||
/// <param name="orderId">ID of the order that needs to be deleted</param>
|
||||
pplx::task<void> deleteOrder(utility::string_t orderId);
|
||||
/// <summary>
|
||||
/// Returns pet inventories by status
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Returns a map of status codes to quantities
|
||||
/// </remarks>
|
||||
|
||||
pplx::task<std::map<utility::string_t, int32_t>> getInventory();
|
||||
/// <summary>
|
||||
/// Find purchase order by ID
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions
|
||||
/// </remarks>
|
||||
/// <param name="orderId">ID of pet that needs to be fetched</param>
|
||||
pplx::task<std::shared_ptr<Order>> getOrderById(int64_t orderId);
|
||||
/// <summary>
|
||||
/// Place an order for a pet
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
///
|
||||
/// </remarks>
|
||||
/// <param name="body">order placed for purchasing the pet</param>
|
||||
pplx::task<std::shared_ptr<Order>> placeOrder(std::shared_ptr<Order> body);
|
||||
|
||||
protected:
|
||||
std::shared_ptr<ApiClient> m_ApiClient;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* StoreApi_H_ */
|
||||
|
954
samples/client/petstore/cpprest/api/UserApi.cpp
Normal file
954
samples/client/petstore/cpprest/api/UserApi.cpp
Normal file
@ -0,0 +1,954 @@
|
||||
|
||||
#include "UserApi.h"
|
||||
#include "IHttpBody.h"
|
||||
#include "JsonBody.h"
|
||||
#include "MultipartFormData.h"
|
||||
|
||||
#include <unordered_set>
|
||||
|
||||
#include <boost/algorithm/string/replace.hpp>
|
||||
|
||||
namespace io {
|
||||
namespace swagger {
|
||||
namespace client {
|
||||
namespace api {
|
||||
|
||||
using namespace io::swagger::client::model;
|
||||
|
||||
UserApi::UserApi( std::shared_ptr<ApiClient> apiClient )
|
||||
: m_ApiClient(apiClient)
|
||||
{
|
||||
}
|
||||
|
||||
UserApi::~UserApi()
|
||||
{
|
||||
}
|
||||
|
||||
pplx::task<void> UserApi::createUser(std::shared_ptr<User> 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> apiConfiguration( m_ApiClient->getConfiguration() );
|
||||
utility::string_t path = U("/user");
|
||||
|
||||
std::map<utility::string_t, utility::string_t> queryParams;
|
||||
std::map<utility::string_t, utility::string_t> headerParams( apiConfiguration->getDefaultHeaders() );
|
||||
std::map<utility::string_t, utility::string_t> formParams;
|
||||
std::map<utility::string_t, std::shared_ptr<HttpContent>> fileParams;
|
||||
|
||||
std::unordered_set<utility::string_t> 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<utility::string_t> consumeHttpContentTypes;
|
||||
|
||||
|
||||
|
||||
std::shared_ptr<IHttpBody> 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<IHttpBody>( new JsonBody( json ) );
|
||||
|
||||
}
|
||||
// multipart formdata
|
||||
else if( consumeHttpContentTypes.find(U("multipart/form-data")) != consumeHttpContentTypes.end() )
|
||||
{
|
||||
requestHttpContentType = U("multipart/form-data");
|
||||
|
||||
std::shared_ptr<MultipartFormData> 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<std::stringstream>(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<std::stringstream>(response.extract_utf8string(true).get()));
|
||||
}
|
||||
}
|
||||
|
||||
return response.extract_string();
|
||||
})
|
||||
.then([=](utility::string_t response)
|
||||
{
|
||||
return void();
|
||||
});
|
||||
}
|
||||
pplx::task<void> UserApi::createUsersWithArrayInput(std::vector<std::shared_ptr<User>> body)
|
||||
{
|
||||
|
||||
|
||||
std::shared_ptr<ApiConfiguration> apiConfiguration( m_ApiClient->getConfiguration() );
|
||||
utility::string_t path = U("/user/createWithArray");
|
||||
|
||||
std::map<utility::string_t, utility::string_t> queryParams;
|
||||
std::map<utility::string_t, utility::string_t> headerParams( apiConfiguration->getDefaultHeaders() );
|
||||
std::map<utility::string_t, utility::string_t> formParams;
|
||||
std::map<utility::string_t, std::shared_ptr<HttpContent>> fileParams;
|
||||
|
||||
std::unordered_set<utility::string_t> 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<utility::string_t> consumeHttpContentTypes;
|
||||
|
||||
|
||||
|
||||
std::shared_ptr<IHttpBody> 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<web::json::value> 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<IHttpBody>( new JsonBody( json ) );
|
||||
|
||||
}
|
||||
// multipart formdata
|
||||
else if( consumeHttpContentTypes.find(U("multipart/form-data")) != consumeHttpContentTypes.end() )
|
||||
{
|
||||
requestHttpContentType = U("multipart/form-data");
|
||||
|
||||
std::shared_ptr<MultipartFormData> multipart(new MultipartFormData);
|
||||
|
||||
{
|
||||
std::vector<web::json::value> 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<std::stringstream>(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<std::stringstream>(response.extract_utf8string(true).get()));
|
||||
}
|
||||
}
|
||||
|
||||
return response.extract_string();
|
||||
})
|
||||
.then([=](utility::string_t response)
|
||||
{
|
||||
return void();
|
||||
});
|
||||
}
|
||||
pplx::task<void> UserApi::createUsersWithListInput(std::vector<std::shared_ptr<User>> body)
|
||||
{
|
||||
|
||||
|
||||
std::shared_ptr<ApiConfiguration> apiConfiguration( m_ApiClient->getConfiguration() );
|
||||
utility::string_t path = U("/user/createWithList");
|
||||
|
||||
std::map<utility::string_t, utility::string_t> queryParams;
|
||||
std::map<utility::string_t, utility::string_t> headerParams( apiConfiguration->getDefaultHeaders() );
|
||||
std::map<utility::string_t, utility::string_t> formParams;
|
||||
std::map<utility::string_t, std::shared_ptr<HttpContent>> fileParams;
|
||||
|
||||
std::unordered_set<utility::string_t> 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<utility::string_t> consumeHttpContentTypes;
|
||||
|
||||
|
||||
|
||||
std::shared_ptr<IHttpBody> 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<web::json::value> 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<IHttpBody>( new JsonBody( json ) );
|
||||
|
||||
}
|
||||
// multipart formdata
|
||||
else if( consumeHttpContentTypes.find(U("multipart/form-data")) != consumeHttpContentTypes.end() )
|
||||
{
|
||||
requestHttpContentType = U("multipart/form-data");
|
||||
|
||||
std::shared_ptr<MultipartFormData> multipart(new MultipartFormData);
|
||||
|
||||
{
|
||||
std::vector<web::json::value> 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<std::stringstream>(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<std::stringstream>(response.extract_utf8string(true).get()));
|
||||
}
|
||||
}
|
||||
|
||||
return response.extract_string();
|
||||
})
|
||||
.then([=](utility::string_t response)
|
||||
{
|
||||
return void();
|
||||
});
|
||||
}
|
||||
pplx::task<void> UserApi::deleteUser(utility::string_t username)
|
||||
{
|
||||
|
||||
|
||||
std::shared_ptr<ApiConfiguration> apiConfiguration( m_ApiClient->getConfiguration() );
|
||||
utility::string_t path = U("/user/{username}");
|
||||
boost::replace_all(path, U("{") U("username") U("}"), ApiClient::parameterToString(username));
|
||||
|
||||
std::map<utility::string_t, utility::string_t> queryParams;
|
||||
std::map<utility::string_t, utility::string_t> headerParams( apiConfiguration->getDefaultHeaders() );
|
||||
std::map<utility::string_t, utility::string_t> formParams;
|
||||
std::map<utility::string_t, std::shared_ptr<HttpContent>> fileParams;
|
||||
|
||||
std::unordered_set<utility::string_t> 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<utility::string_t> consumeHttpContentTypes;
|
||||
|
||||
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
std::shared_ptr<IHttpBody> 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<std::stringstream>(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<std::stringstream>(response.extract_utf8string(true).get()));
|
||||
}
|
||||
}
|
||||
|
||||
return response.extract_string();
|
||||
})
|
||||
.then([=](utility::string_t response)
|
||||
{
|
||||
return void();
|
||||
});
|
||||
}
|
||||
pplx::task<std::shared_ptr<User>> UserApi::getUserByName(utility::string_t username)
|
||||
{
|
||||
|
||||
|
||||
std::shared_ptr<ApiConfiguration> apiConfiguration( m_ApiClient->getConfiguration() );
|
||||
utility::string_t path = U("/user/{username}");
|
||||
boost::replace_all(path, U("{") U("username") U("}"), ApiClient::parameterToString(username));
|
||||
|
||||
std::map<utility::string_t, utility::string_t> queryParams;
|
||||
std::map<utility::string_t, utility::string_t> headerParams( apiConfiguration->getDefaultHeaders() );
|
||||
std::map<utility::string_t, utility::string_t> formParams;
|
||||
std::map<utility::string_t, std::shared_ptr<HttpContent>> fileParams;
|
||||
|
||||
std::unordered_set<utility::string_t> 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<utility::string_t> consumeHttpContentTypes;
|
||||
|
||||
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
std::shared_ptr<IHttpBody> 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<std::stringstream>(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<std::stringstream>(response.extract_utf8string(true).get()));
|
||||
}
|
||||
}
|
||||
|
||||
return response.extract_string();
|
||||
})
|
||||
.then([=](utility::string_t response)
|
||||
{
|
||||
std::shared_ptr<User> 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<utility::string_t> UserApi::loginUser(utility::string_t username, utility::string_t password)
|
||||
{
|
||||
|
||||
|
||||
std::shared_ptr<ApiConfiguration> apiConfiguration( m_ApiClient->getConfiguration() );
|
||||
utility::string_t path = U("/user/login");
|
||||
|
||||
std::map<utility::string_t, utility::string_t> queryParams;
|
||||
std::map<utility::string_t, utility::string_t> headerParams( apiConfiguration->getDefaultHeaders() );
|
||||
std::map<utility::string_t, utility::string_t> formParams;
|
||||
std::map<utility::string_t, std::shared_ptr<HttpContent>> fileParams;
|
||||
|
||||
std::unordered_set<utility::string_t> 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<utility::string_t> consumeHttpContentTypes;
|
||||
|
||||
|
||||
{
|
||||
queryParams[U("username")] = ApiClient::parameterToString(username);
|
||||
|
||||
}
|
||||
|
||||
{
|
||||
queryParams[U("password")] = ApiClient::parameterToString(password);
|
||||
|
||||
}
|
||||
|
||||
|
||||
std::shared_ptr<IHttpBody> 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<std::stringstream>(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<std::stringstream>(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<void> UserApi::logoutUser()
|
||||
{
|
||||
|
||||
|
||||
std::shared_ptr<ApiConfiguration> apiConfiguration( m_ApiClient->getConfiguration() );
|
||||
utility::string_t path = U("/user/logout");
|
||||
|
||||
std::map<utility::string_t, utility::string_t> queryParams;
|
||||
std::map<utility::string_t, utility::string_t> headerParams( apiConfiguration->getDefaultHeaders() );
|
||||
std::map<utility::string_t, utility::string_t> formParams;
|
||||
std::map<utility::string_t, std::shared_ptr<HttpContent>> fileParams;
|
||||
|
||||
std::unordered_set<utility::string_t> 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<utility::string_t> consumeHttpContentTypes;
|
||||
|
||||
|
||||
|
||||
std::shared_ptr<IHttpBody> 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<std::stringstream>(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<std::stringstream>(response.extract_utf8string(true).get()));
|
||||
}
|
||||
}
|
||||
|
||||
return response.extract_string();
|
||||
})
|
||||
.then([=](utility::string_t response)
|
||||
{
|
||||
return void();
|
||||
});
|
||||
}
|
||||
pplx::task<void> UserApi::updateUser(utility::string_t username, std::shared_ptr<User> 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> apiConfiguration( m_ApiClient->getConfiguration() );
|
||||
utility::string_t path = U("/user/{username}");
|
||||
boost::replace_all(path, U("{") U("username") U("}"), ApiClient::parameterToString(username));
|
||||
|
||||
std::map<utility::string_t, utility::string_t> queryParams;
|
||||
std::map<utility::string_t, utility::string_t> headerParams( apiConfiguration->getDefaultHeaders() );
|
||||
std::map<utility::string_t, utility::string_t> formParams;
|
||||
std::map<utility::string_t, std::shared_ptr<HttpContent>> fileParams;
|
||||
|
||||
std::unordered_set<utility::string_t> 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<utility::string_t> consumeHttpContentTypes;
|
||||
|
||||
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
std::shared_ptr<IHttpBody> 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<IHttpBody>( new JsonBody( json ) );
|
||||
|
||||
}
|
||||
// multipart formdata
|
||||
else if( consumeHttpContentTypes.find(U("multipart/form-data")) != consumeHttpContentTypes.end() )
|
||||
{
|
||||
requestHttpContentType = U("multipart/form-data");
|
||||
|
||||
std::shared_ptr<MultipartFormData> 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<std::stringstream>(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<std::stringstream>(response.extract_utf8string(true).get()));
|
||||
}
|
||||
}
|
||||
|
||||
return response.extract_string();
|
||||
})
|
||||
.then([=](utility::string_t response)
|
||||
{
|
||||
return void();
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
104
samples/client/petstore/cpprest/api/UserApi.h
Normal file
104
samples/client/petstore/cpprest/api/UserApi.h
Normal file
@ -0,0 +1,104 @@
|
||||
/*
|
||||
* UserApi.h
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef UserApi_H_
|
||||
#define UserApi_H_
|
||||
|
||||
|
||||
#include "ApiClient.h"
|
||||
|
||||
#include "User.h"
|
||||
#include <vector>
|
||||
#include <cpprest/details/basic_types.h>
|
||||
|
||||
namespace io {
|
||||
namespace swagger {
|
||||
namespace client {
|
||||
namespace api {
|
||||
|
||||
using namespace io::swagger::client::model;
|
||||
|
||||
class UserApi
|
||||
{
|
||||
public:
|
||||
UserApi( std::shared_ptr<ApiClient> apiClient );
|
||||
virtual ~UserApi();
|
||||
/// <summary>
|
||||
/// Create user
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This can only be done by the logged in user.
|
||||
/// </remarks>
|
||||
/// <param name="body">Created user object</param>
|
||||
pplx::task<void> createUser(std::shared_ptr<User> body);
|
||||
/// <summary>
|
||||
/// Creates list of users with given input array
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
///
|
||||
/// </remarks>
|
||||
/// <param name="body">List of user object</param>
|
||||
pplx::task<void> createUsersWithArrayInput(std::vector<std::shared_ptr<User>> body);
|
||||
/// <summary>
|
||||
/// Creates list of users with given input array
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
///
|
||||
/// </remarks>
|
||||
/// <param name="body">List of user object</param>
|
||||
pplx::task<void> createUsersWithListInput(std::vector<std::shared_ptr<User>> body);
|
||||
/// <summary>
|
||||
/// Delete user
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This can only be done by the logged in user.
|
||||
/// </remarks>
|
||||
/// <param name="username">The name that needs to be deleted</param>
|
||||
pplx::task<void> deleteUser(utility::string_t username);
|
||||
/// <summary>
|
||||
/// Get user by user name
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
///
|
||||
/// </remarks>
|
||||
/// <param name="username">The name that needs to be fetched. Use user1 for testing. </param>
|
||||
pplx::task<std::shared_ptr<User>> getUserByName(utility::string_t username);
|
||||
/// <summary>
|
||||
/// Logs user into the system
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
///
|
||||
/// </remarks>
|
||||
/// <param name="username">The user name for login</param>/// <param name="password">The password for login in clear text</param>
|
||||
pplx::task<utility::string_t> loginUser(utility::string_t username, utility::string_t password);
|
||||
/// <summary>
|
||||
/// Logs out current logged in user session
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
///
|
||||
/// </remarks>
|
||||
|
||||
pplx::task<void> logoutUser();
|
||||
/// <summary>
|
||||
/// Updated user
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This can only be done by the logged in user.
|
||||
/// </remarks>
|
||||
/// <param name="username">name that need to be deleted</param>/// <param name="body">Updated user object</param>
|
||||
pplx::task<void> updateUser(utility::string_t username, std::shared_ptr<User> body);
|
||||
|
||||
protected:
|
||||
std::shared_ptr<ApiClient> m_ApiClient;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* UserApi_H_ */
|
||||
|
51
samples/client/petstore/cpprest/git_push.sh
Normal file
51
samples/client/petstore/cpprest/git_push.sh
Normal file
@ -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'
|
177
samples/client/petstore/cpprest/model/ApiResponse.cpp
Normal file
177
samples/client/petstore/cpprest/model/ApiResponse.cpp
Normal file
@ -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<MultipartFormData> 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<MultipartFormData> 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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
80
samples/client/petstore/cpprest/model/ApiResponse.h
Normal file
80
samples/client/petstore/cpprest/model/ApiResponse.h
Normal file
@ -0,0 +1,80 @@
|
||||
/*
|
||||
* ApiResponse.h
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef ApiResponse_H_
|
||||
#define ApiResponse_H_
|
||||
|
||||
|
||||
#include "ModelBase.h"
|
||||
|
||||
#include <cpprest/details/basic_types.h>
|
||||
|
||||
namespace io {
|
||||
namespace swagger {
|
||||
namespace client {
|
||||
namespace model {
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
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<MultipartFormData> multipart, const utility::string_t& namePrefix) const override;
|
||||
void fromMultiPart(std::shared_ptr<MultipartFormData> multipart, const utility::string_t& namePrefix) override;
|
||||
|
||||
/////////////////////////////////////////////
|
||||
/// ApiResponse members
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
int32_t getCode() const;
|
||||
void setCode(int32_t value);
|
||||
bool codeIsSet() const;
|
||||
void unsetCode();
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
utility::string_t getType() const;
|
||||
void setType(utility::string_t value);
|
||||
bool typeIsSet() const;
|
||||
void unsetType();
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
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_ */
|
139
samples/client/petstore/cpprest/model/Category.cpp
Normal file
139
samples/client/petstore/cpprest/model/Category.cpp
Normal file
@ -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<MultipartFormData> 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<MultipartFormData> 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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
71
samples/client/petstore/cpprest/model/Category.h
Normal file
71
samples/client/petstore/cpprest/model/Category.h
Normal file
@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Category.h
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef Category_H_
|
||||
#define Category_H_
|
||||
|
||||
|
||||
#include "ModelBase.h"
|
||||
|
||||
#include <cpprest/details/basic_types.h>
|
||||
|
||||
namespace io {
|
||||
namespace swagger {
|
||||
namespace client {
|
||||
namespace model {
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
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<MultipartFormData> multipart, const utility::string_t& namePrefix) const override;
|
||||
void fromMultiPart(std::shared_ptr<MultipartFormData> multipart, const utility::string_t& namePrefix) override;
|
||||
|
||||
/////////////////////////////////////////////
|
||||
/// Category members
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
int64_t getId() const;
|
||||
void setId(int64_t value);
|
||||
bool idIsSet() const;
|
||||
void unsetId();
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
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_ */
|
282
samples/client/petstore/cpprest/model/Order.cpp
Normal file
282
samples/client/petstore/cpprest/model/Order.cpp
Normal file
@ -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<MultipartFormData> 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<MultipartFormData> 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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
107
samples/client/petstore/cpprest/model/Order.h
Normal file
107
samples/client/petstore/cpprest/model/Order.h
Normal file
@ -0,0 +1,107 @@
|
||||
/*
|
||||
* Order.h
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef Order_H_
|
||||
#define Order_H_
|
||||
|
||||
|
||||
#include "ModelBase.h"
|
||||
|
||||
#include <cpprest/details/basic_types.h>
|
||||
|
||||
namespace io {
|
||||
namespace swagger {
|
||||
namespace client {
|
||||
namespace model {
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
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<MultipartFormData> multipart, const utility::string_t& namePrefix) const override;
|
||||
void fromMultiPart(std::shared_ptr<MultipartFormData> multipart, const utility::string_t& namePrefix) override;
|
||||
|
||||
/////////////////////////////////////////////
|
||||
/// Order members
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
int64_t getId() const;
|
||||
void setId(int64_t value);
|
||||
bool idIsSet() const;
|
||||
void unsetId();
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
int64_t getPetId() const;
|
||||
void setPetId(int64_t value);
|
||||
bool petIdIsSet() const;
|
||||
void unsetPetId();
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
int32_t getQuantity() const;
|
||||
void setQuantity(int32_t value);
|
||||
bool quantityIsSet() const;
|
||||
void unsetQuantity();
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
utility::datetime getShipDate() const;
|
||||
void setShipDate(utility::datetime value);
|
||||
bool shipDateIsSet() const;
|
||||
void unsetShipDate();
|
||||
/// <summary>
|
||||
/// Order Status
|
||||
/// </summary>
|
||||
utility::string_t getStatus() const;
|
||||
void setStatus(utility::string_t value);
|
||||
bool statusIsSet() const;
|
||||
void unsetStatus();
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
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_ */
|
324
samples/client/petstore/cpprest/model/Pet.cpp
Normal file
324
samples/client/petstore/cpprest/model/Pet.cpp
Normal file
@ -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<web::json::value> jsonArray;
|
||||
for( auto& item : m_PhotoUrls )
|
||||
{
|
||||
jsonArray.push_back(ModelBase::toJson(item));
|
||||
}
|
||||
val[U("photoUrls")] = web::json::value::array(jsonArray);
|
||||
}
|
||||
{
|
||||
std::vector<web::json::value> 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<Category> newItem(new Category());
|
||||
newItem->fromJson(val[U("category")]);
|
||||
setCategory( newItem );
|
||||
}
|
||||
|
||||
}
|
||||
setName(ModelBase::stringFromJson(val[U("name")]));
|
||||
{
|
||||
m_PhotoUrls.clear();
|
||||
std::vector<web::json::value> jsonArray;
|
||||
for( auto& item : val[U("photoUrls")].as_array() )
|
||||
{
|
||||
m_PhotoUrls.push_back(ModelBase::stringFromJson(item));
|
||||
|
||||
}
|
||||
}
|
||||
{
|
||||
m_Tags.clear();
|
||||
std::vector<web::json::value> 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<Tag>(nullptr) );
|
||||
}
|
||||
else
|
||||
{
|
||||
std::shared_ptr<Tag> 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<MultipartFormData> 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<web::json::value> 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<web::json::value> 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<MultipartFormData> 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<Category> 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<Tag>(nullptr) );
|
||||
}
|
||||
else
|
||||
{
|
||||
std::shared_ptr<Tag> 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<Category> Pet::getCategory() const
|
||||
{
|
||||
return m_Category;
|
||||
}
|
||||
void Pet::setCategory(std::shared_ptr<Category> 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<utility::string_t>& Pet::getPhotoUrls()
|
||||
{
|
||||
return m_PhotoUrls;
|
||||
}
|
||||
std::vector<std::shared_ptr<Tag>>& 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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
102
samples/client/petstore/cpprest/model/Pet.h
Normal file
102
samples/client/petstore/cpprest/model/Pet.h
Normal file
@ -0,0 +1,102 @@
|
||||
/*
|
||||
* Pet.h
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef Pet_H_
|
||||
#define Pet_H_
|
||||
|
||||
|
||||
#include "ModelBase.h"
|
||||
|
||||
#include "Category.h"
|
||||
#include <cpprest/details/basic_types.h>
|
||||
#include <vector>
|
||||
#include "Tag.h"
|
||||
|
||||
namespace io {
|
||||
namespace swagger {
|
||||
namespace client {
|
||||
namespace model {
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
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<MultipartFormData> multipart, const utility::string_t& namePrefix) const override;
|
||||
void fromMultiPart(std::shared_ptr<MultipartFormData> multipart, const utility::string_t& namePrefix) override;
|
||||
|
||||
/////////////////////////////////////////////
|
||||
/// Pet members
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
int64_t getId() const;
|
||||
void setId(int64_t value);
|
||||
bool idIsSet() const;
|
||||
void unsetId();
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
std::shared_ptr<Category> getCategory() const;
|
||||
void setCategory(std::shared_ptr<Category> value);
|
||||
bool categoryIsSet() const;
|
||||
void unsetCategory();
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
utility::string_t getName() const;
|
||||
void setName(utility::string_t value);
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
std::vector<utility::string_t>& getPhotoUrls();
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
std::vector<std::shared_ptr<Tag>>& getTags();
|
||||
bool tagsIsSet() const;
|
||||
void unsetTags();
|
||||
/// <summary>
|
||||
/// pet status in the store
|
||||
/// </summary>
|
||||
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<Category> m_Category;
|
||||
bool m_CategoryIsSet;
|
||||
utility::string_t m_Name;
|
||||
std::vector<utility::string_t> m_PhotoUrls;
|
||||
std::vector<std::shared_ptr<Tag>> m_Tags;
|
||||
bool m_TagsIsSet;
|
||||
utility::string_t m_Status;
|
||||
bool m_StatusIsSet;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* Pet_H_ */
|
139
samples/client/petstore/cpprest/model/Tag.cpp
Normal file
139
samples/client/petstore/cpprest/model/Tag.cpp
Normal file
@ -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<MultipartFormData> 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<MultipartFormData> 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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
71
samples/client/petstore/cpprest/model/Tag.h
Normal file
71
samples/client/petstore/cpprest/model/Tag.h
Normal file
@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Tag.h
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef Tag_H_
|
||||
#define Tag_H_
|
||||
|
||||
|
||||
#include "ModelBase.h"
|
||||
|
||||
#include <cpprest/details/basic_types.h>
|
||||
|
||||
namespace io {
|
||||
namespace swagger {
|
||||
namespace client {
|
||||
namespace model {
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
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<MultipartFormData> multipart, const utility::string_t& namePrefix) const override;
|
||||
void fromMultiPart(std::shared_ptr<MultipartFormData> multipart, const utility::string_t& namePrefix) override;
|
||||
|
||||
/////////////////////////////////////////////
|
||||
/// Tag members
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
int64_t getId() const;
|
||||
void setId(int64_t value);
|
||||
bool idIsSet() const;
|
||||
void unsetId();
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
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_ */
|
364
samples/client/petstore/cpprest/model/User.cpp
Normal file
364
samples/client/petstore/cpprest/model/User.cpp
Normal file
@ -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<MultipartFormData> 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<MultipartFormData> 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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
125
samples/client/petstore/cpprest/model/User.h
Normal file
125
samples/client/petstore/cpprest/model/User.h
Normal file
@ -0,0 +1,125 @@
|
||||
/*
|
||||
* User.h
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef User_H_
|
||||
#define User_H_
|
||||
|
||||
|
||||
#include "ModelBase.h"
|
||||
|
||||
#include <cpprest/details/basic_types.h>
|
||||
|
||||
namespace io {
|
||||
namespace swagger {
|
||||
namespace client {
|
||||
namespace model {
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
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<MultipartFormData> multipart, const utility::string_t& namePrefix) const override;
|
||||
void fromMultiPart(std::shared_ptr<MultipartFormData> multipart, const utility::string_t& namePrefix) override;
|
||||
|
||||
/////////////////////////////////////////////
|
||||
/// User members
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
int64_t getId() const;
|
||||
void setId(int64_t value);
|
||||
bool idIsSet() const;
|
||||
void unsetId();
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
utility::string_t getUsername() const;
|
||||
void setUsername(utility::string_t value);
|
||||
bool usernameIsSet() const;
|
||||
void unsetUsername();
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
utility::string_t getFirstName() const;
|
||||
void setFirstName(utility::string_t value);
|
||||
bool firstNameIsSet() const;
|
||||
void unsetFirstName();
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
utility::string_t getLastName() const;
|
||||
void setLastName(utility::string_t value);
|
||||
bool lastNameIsSet() const;
|
||||
void unsetLastName();
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
utility::string_t getEmail() const;
|
||||
void setEmail(utility::string_t value);
|
||||
bool emailIsSet() const;
|
||||
void unsetEmail();
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
utility::string_t getPassword() const;
|
||||
void setPassword(utility::string_t value);
|
||||
bool passwordIsSet() const;
|
||||
void unsetPassword();
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
utility::string_t getPhone() const;
|
||||
void setPhone(utility::string_t value);
|
||||
bool phoneIsSet() const;
|
||||
void unsetPhone();
|
||||
/// <summary>
|
||||
/// User Status
|
||||
/// </summary>
|
||||
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_ */
|
@ -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
|
||||
|
@ -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
|
7
samples/client/petstore/javascript-promise/.travis.yml
Normal file
7
samples/client/petstore/javascript-promise/.travis.yml
Normal file
@ -0,0 +1,7 @@
|
||||
language: node_js
|
||||
node_js:
|
||||
- "6"
|
||||
- "6.1"
|
||||
- "5"
|
||||
- "5.11"
|
||||
|
201
samples/client/petstore/javascript-promise/LICENSE
Normal file
201
samples/client/petstore/javascript-promise/LICENSE
Normal file
@ -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.
|
@ -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
|
||||
|
||||
|
@ -0,0 +1,9 @@
|
||||
# SwaggerPetstore.AdditionalPropertiesClass
|
||||
|
||||
## Properties
|
||||
Name | Type | Description | Notes
|
||||
------------ | ------------- | ------------- | -------------
|
||||
**mapProperty** | **{String: String}** | | [optional]
|
||||
**mapOfMapProperty** | **{String: {String: String}}** | | [optional]
|
||||
|
||||
|
@ -4,5 +4,6 @@
|
||||
Name | Type | Description | Notes
|
||||
------------ | ------------- | ------------- | -------------
|
||||
**className** | **String** | |
|
||||
**color** | **String** | | [optional] [default to 'red']
|
||||
|
||||
|
||||
|
10
samples/client/petstore/javascript-promise/docs/ArrayTest.md
Normal file
10
samples/client/petstore/javascript-promise/docs/ArrayTest.md
Normal file
@ -0,0 +1,10 @@
|
||||
# SwaggerPetstore.ArrayTest
|
||||
|
||||
## Properties
|
||||
Name | Type | Description | Notes
|
||||
------------ | ------------- | ------------- | -------------
|
||||
**arrayOfString** | **[String]** | | [optional]
|
||||
**arrayArrayOfInteger** | **[[Integer]]** | | [optional]
|
||||
**arrayArrayOfModel** | **[[ReadOnlyFirst]]** | | [optional]
|
||||
|
||||
|
@ -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 假端點 偽のエンドポイント 가짜 엔드 포인트
|
||||
|
||||
|
||||
<a name="testEndpointParameters"></a>
|
||||
# **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
|
||||
|
||||
|
@ -0,0 +1,10 @@
|
||||
# SwaggerPetstore.MixedPropertiesAndAdditionalPropertiesClass
|
||||
|
||||
## Properties
|
||||
Name | Type | Description | Notes
|
||||
------------ | ------------- | ------------- | -------------
|
||||
**uuid** | **String** | | [optional]
|
||||
**dateTime** | **Date** | | [optional]
|
||||
**map** | [**{String: Animal}**](Animal.md) | | [optional]
|
||||
|
||||
|
@ -6,5 +6,6 @@ Name | Type | Description | Notes
|
||||
**name** | **Integer** | |
|
||||
**snakeCase** | **Integer** | | [optional]
|
||||
**property** | **String** | | [optional]
|
||||
**_123Number** | **Integer** | | [optional]
|
||||
|
||||
|
||||
|
@ -0,0 +1,9 @@
|
||||
# SwaggerPetstore.ReadOnlyFirst
|
||||
|
||||
## Properties
|
||||
Name | Type | Description | Notes
|
||||
------------ | ------------- | ------------- | -------------
|
||||
**bar** | **String** | | [optional]
|
||||
**baz** | **String** | | [optional]
|
||||
|
||||
|
1
samples/client/petstore/javascript-promise/mocha.opts
Normal file
1
samples/client/petstore/javascript-promise/mocha.opts
Normal file
@ -0,0 +1 @@
|
||||
--timeout 10000
|
@ -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"
|
||||
|
@ -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.<String>}
|
||||
*/
|
||||
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.
|
||||
|
@ -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(
|
||||
|
@ -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.
|
||||
|
@ -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.
|
||||
|
@ -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.
|
||||
|
@ -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..<br>
|
||||
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ .<br>
|
||||
* The <code>index</code> module provides access to constructors for all the classes which comprise the public API.
|
||||
* <p>
|
||||
* 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}
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user