mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-06-03 07:20:51 +00:00
Merge branch 'develop_2.0' into library-template-jersey2
Conflicts: modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JavaClientCodegen.java modules/swagger-codegen/src/main/resources/Java/api.mustache
This commit is contained in:
commit
af2ec4cf85
@ -188,6 +188,7 @@ AkkaScalaClientCodegen.java
|
|||||||
AndroidClientCodegen.java
|
AndroidClientCodegen.java
|
||||||
AsyncScalaClientCodegen.java
|
AsyncScalaClientCodegen.java
|
||||||
CSharpClientCodegen.java
|
CSharpClientCodegen.java
|
||||||
|
FlashClientCodegen.java
|
||||||
JavaClientCodegen.java
|
JavaClientCodegen.java
|
||||||
JaxRSServerCodegen.java
|
JaxRSServerCodegen.java
|
||||||
NodeJSServerCodegen.java
|
NodeJSServerCodegen.java
|
||||||
|
31
bin/flash-petstore.sh
Executable file
31
bin/flash-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/flash -i modules/swagger-codegen/src/test/resources/2_0/petstore.json -l flash -o samples/client/petstore/flash"
|
||||||
|
|
||||||
|
java $JAVA_OPTS -jar $executable $ags
|
@ -34,4 +34,108 @@ public class CodegenProperty {
|
|||||||
public boolean isEnum;
|
public boolean isEnum;
|
||||||
public List<String> _enum;
|
public List<String> _enum;
|
||||||
public Map<String, Object> allowableValues;
|
public Map<String, Object> allowableValues;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (obj == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (getClass() != obj.getClass()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
final CodegenProperty other = (CodegenProperty) obj;
|
||||||
|
if ((this.baseName == null) ? (other.baseName != null) : !this.baseName.equals(other.baseName)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if ((this.complexType == null) ? (other.complexType != null) : !this.complexType.equals(other.complexType)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if ((this.getter == null) ? (other.getter != null) : !this.getter.equals(other.getter)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if ((this.setter == null) ? (other.setter != null) : !this.setter.equals(other.setter)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if ((this.description == null) ? (other.description != null) : !this.description.equals(other.description)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if ((this.datatype == null) ? (other.datatype != null) : !this.datatype.equals(other.datatype)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if ((this.datatypeWithEnum == null) ? (other.datatypeWithEnum != null) : !this.datatypeWithEnum.equals(other.datatypeWithEnum)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if ((this.name == null) ? (other.name != null) : !this.name.equals(other.name)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if ((this.min == null) ? (other.min != null) : !this.min.equals(other.min)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if ((this.max == null) ? (other.max != null) : !this.max.equals(other.max)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if ((this.defaultValue == null) ? (other.defaultValue != null) : !this.defaultValue.equals(other.defaultValue)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if ((this.baseType == null) ? (other.baseType != null) : !this.baseType.equals(other.baseType)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if ((this.containerType == null) ? (other.containerType != null) : !this.containerType.equals(other.containerType)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (this.maxLength != other.maxLength && (this.maxLength == null || !this.maxLength.equals(other.maxLength))) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (this.minLength != other.minLength && (this.minLength == null || !this.minLength.equals(other.minLength))) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if ((this.pattern == null) ? (other.pattern != null) : !this.pattern.equals(other.pattern)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if ((this.example == null) ? (other.example != null) : !this.example.equals(other.example)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if ((this.jsonSchema == null) ? (other.jsonSchema != null) : !this.jsonSchema.equals(other.jsonSchema)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (this.minimum != other.minimum && (this.minimum == null || !this.minimum.equals(other.minimum))) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (this.maximum != other.maximum && (this.maximum == null || !this.maximum.equals(other.maximum))) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (this.exclusiveMinimum != other.exclusiveMinimum && (this.exclusiveMinimum == null || !this.exclusiveMinimum.equals(other.exclusiveMinimum))) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (this.exclusiveMaximum != other.exclusiveMaximum && (this.exclusiveMaximum == null || !this.exclusiveMaximum.equals(other.exclusiveMaximum))) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (this.required != other.required && (this.required == null || !this.required.equals(other.required))) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (this.secondaryParam != other.secondaryParam && (this.secondaryParam == null || !this.secondaryParam.equals(other.secondaryParam))) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (this.isPrimitiveType != other.isPrimitiveType && (this.isPrimitiveType == null || !this.isPrimitiveType.equals(other.isPrimitiveType))) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (this.isContainer != other.isContainer && (this.isContainer == null || !this.isContainer.equals(other.isContainer))) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (this.isNotContainer != other.isNotContainer && (this.isNotContainer == null || !this.isNotContainer.equals(other.isNotContainer))) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (this.isEnum != other.isEnum) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (this._enum != other._enum && (this._enum == null || !this._enum.equals(other._enum))) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (this.allowableValues != other.allowableValues && (this.allowableValues == null || !this.allowableValues.equals(other.allowableValues))) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -64,7 +64,7 @@ import java.util.regex.Pattern;
|
|||||||
|
|
||||||
|
|
||||||
public class DefaultCodegen {
|
public class DefaultCodegen {
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(DefaultCodegen.class);
|
protected static final Logger LOGGER = LoggerFactory.getLogger(DefaultCodegen.class);
|
||||||
|
|
||||||
protected String outputFolder = "";
|
protected String outputFolder = "";
|
||||||
protected Set<String> defaultIncludes = new HashSet<String>();
|
protected Set<String> defaultIncludes = new HashSet<String>();
|
||||||
|
@ -13,6 +13,7 @@ import io.swagger.models.Path;
|
|||||||
import io.swagger.models.Swagger;
|
import io.swagger.models.Swagger;
|
||||||
import io.swagger.models.auth.OAuth2Definition;
|
import io.swagger.models.auth.OAuth2Definition;
|
||||||
import io.swagger.models.auth.SecuritySchemeDefinition;
|
import io.swagger.models.auth.SecuritySchemeDefinition;
|
||||||
|
import io.swagger.models.parameters.Parameter;
|
||||||
import io.swagger.util.Json;
|
import io.swagger.util.Json;
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
@ -387,12 +388,12 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
|
|||||||
|
|
||||||
for (String resourcePath : paths.keySet()) {
|
for (String resourcePath : paths.keySet()) {
|
||||||
Path path = paths.get(resourcePath);
|
Path path = paths.get(resourcePath);
|
||||||
processOperation(resourcePath, "get", path.getGet(), ops);
|
processOperation(resourcePath, "get", path.getGet(), ops, path);
|
||||||
processOperation(resourcePath, "put", path.getPut(), ops);
|
processOperation(resourcePath, "put", path.getPut(), ops, path);
|
||||||
processOperation(resourcePath, "post", path.getPost(), ops);
|
processOperation(resourcePath, "post", path.getPost(), ops, path);
|
||||||
processOperation(resourcePath, "delete", path.getDelete(), ops);
|
processOperation(resourcePath, "delete", path.getDelete(), ops, path);
|
||||||
processOperation(resourcePath, "patch", path.getPatch(), ops);
|
processOperation(resourcePath, "patch", path.getPatch(), ops, path);
|
||||||
processOperation(resourcePath, "options", path.getOptions(), ops);
|
processOperation(resourcePath, "options", path.getOptions(), ops, path);
|
||||||
}
|
}
|
||||||
return ops;
|
return ops;
|
||||||
}
|
}
|
||||||
@ -405,14 +406,35 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
|
|||||||
return map.get(name);
|
return map.get(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void processOperation(String resourcePath, String httpMethod, Operation operation, Map<String, List<CodegenOperation>> operations, Path path) {
|
||||||
public void processOperation(String resourcePath, String httpMethod, Operation operation, Map<String, List<CodegenOperation>> operations) {
|
|
||||||
if (operation != null) {
|
if (operation != null) {
|
||||||
List<String> tags = operation.getTags();
|
List<String> tags = operation.getTags();
|
||||||
if (tags == null) {
|
if (tags == null) {
|
||||||
tags = new ArrayList<String>();
|
tags = new ArrayList<String>();
|
||||||
tags.add("default");
|
tags.add("default");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
build up a set of parameter "ids" defined at the operation level
|
||||||
|
per the swagger 2.0 spec "A unique parameter is defined by a combination of a name and location"
|
||||||
|
i'm assuming "location" == "in"
|
||||||
|
*/
|
||||||
|
Set<String> operationParameters = new HashSet<String>();
|
||||||
|
if (operation.getParameters() != null) {
|
||||||
|
for (Parameter parameter : operation.getParameters()) {
|
||||||
|
operationParameters.add(generateParameterId(parameter));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//need to propagate path level down to the operation
|
||||||
|
if(path.getParameters() != null) {
|
||||||
|
for (Parameter parameter : path.getParameters()) {
|
||||||
|
//skip propagation if a parameter with the same name is already defined at the operation level
|
||||||
|
if (!operationParameters.contains(generateParameterId(parameter))) {
|
||||||
|
operation.addParameter(parameter);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (String tag : tags) {
|
for (String tag : tags) {
|
||||||
CodegenOperation co = config.fromOperation(resourcePath, httpMethod, operation, swagger.getDefinitions());
|
CodegenOperation co = config.fromOperation(resourcePath, httpMethod, operation, swagger.getDefinitions());
|
||||||
@ -458,6 +480,10 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String generateParameterId(Parameter parameter) {
|
||||||
|
return parameter.getName() + ":" + parameter.getIn();
|
||||||
|
}
|
||||||
|
|
||||||
protected String sanitizeTag(String tag) {
|
protected String sanitizeTag(String tag) {
|
||||||
// remove spaces and make strong case
|
// remove spaces and make strong case
|
||||||
String[] parts = tag.split(" ");
|
String[] parts = tag.split(" ");
|
||||||
|
@ -0,0 +1,367 @@
|
|||||||
|
package io.swagger.codegen.languages;
|
||||||
|
|
||||||
|
import io.swagger.codegen.CliOption;
|
||||||
|
import io.swagger.codegen.CodegenConfig;
|
||||||
|
import io.swagger.codegen.CodegenType;
|
||||||
|
import io.swagger.codegen.DefaultCodegen;
|
||||||
|
import io.swagger.codegen.SupportingFile;
|
||||||
|
import io.swagger.models.properties.ArrayProperty;
|
||||||
|
import io.swagger.models.properties.MapProperty;
|
||||||
|
import io.swagger.models.properties.Property;
|
||||||
|
import io.swagger.models.properties.AbstractNumericProperty;
|
||||||
|
import io.swagger.models.properties.ArrayProperty;
|
||||||
|
import io.swagger.models.properties.BooleanProperty;
|
||||||
|
import io.swagger.models.properties.DateProperty;
|
||||||
|
import io.swagger.models.properties.DateTimeProperty;
|
||||||
|
import io.swagger.models.properties.DecimalProperty;
|
||||||
|
import io.swagger.models.properties.DoubleProperty;
|
||||||
|
import io.swagger.models.properties.FloatProperty;
|
||||||
|
import io.swagger.models.properties.IntegerProperty;
|
||||||
|
import io.swagger.models.properties.LongProperty;
|
||||||
|
import io.swagger.models.properties.MapProperty;
|
||||||
|
import io.swagger.models.properties.Property;
|
||||||
|
import io.swagger.models.properties.PropertyBuilder;
|
||||||
|
import io.swagger.models.properties.RefProperty;
|
||||||
|
import io.swagger.models.properties.StringProperty;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
|
||||||
|
public class FlashClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||||
|
protected String packageName = "io.swagger";
|
||||||
|
protected String packageVersion = null;
|
||||||
|
|
||||||
|
protected String invokerPackage = "io.swagger";
|
||||||
|
protected String sourceFolder = "src/main/flex";
|
||||||
|
|
||||||
|
public FlashClientCodegen() {
|
||||||
|
super();
|
||||||
|
|
||||||
|
modelPackage = "io.swagger.client.model";
|
||||||
|
apiPackage = "io.swagger.client.api";
|
||||||
|
outputFolder = "generated-code" + File.separatorChar + "flash";
|
||||||
|
modelTemplateFiles.put("model.mustache", ".as");
|
||||||
|
modelTemplateFiles.put("modelList.mustache", "List.as");
|
||||||
|
apiTemplateFiles.put("api.mustache", ".as");
|
||||||
|
templateDir = "flash";
|
||||||
|
|
||||||
|
languageSpecificPrimitives.clear();
|
||||||
|
languageSpecificPrimitives.add("Number");
|
||||||
|
languageSpecificPrimitives.add("Boolean");
|
||||||
|
languageSpecificPrimitives.add("String");
|
||||||
|
languageSpecificPrimitives.add("Date");
|
||||||
|
languageSpecificPrimitives.add("Array");
|
||||||
|
languageSpecificPrimitives.add("Dictionary");
|
||||||
|
|
||||||
|
typeMapping.clear();
|
||||||
|
typeMapping.put("integer", "Number");
|
||||||
|
typeMapping.put("float", "Number");
|
||||||
|
typeMapping.put("long", "Number");
|
||||||
|
typeMapping.put("double", "Number");
|
||||||
|
typeMapping.put("array", "Array");
|
||||||
|
typeMapping.put("map", "Dictionary");
|
||||||
|
typeMapping.put("boolean", "Boolean");
|
||||||
|
typeMapping.put("string", "String");
|
||||||
|
typeMapping.put("date", "Date");
|
||||||
|
typeMapping.put("DateTime", "Date");
|
||||||
|
typeMapping.put("object", "Object");
|
||||||
|
typeMapping.put("file", "File");
|
||||||
|
|
||||||
|
importMapping = new HashMap<String, String>();
|
||||||
|
importMapping.put("File", "flash.filesystem.File");
|
||||||
|
|
||||||
|
// from
|
||||||
|
reservedWords = new HashSet<String>(
|
||||||
|
Arrays.asList(
|
||||||
|
"add", "for", "lt", "tellTarget", "and", "function", "ne", "this", "break", "ge", "new", "typeof", "continue", "gt", "not", "var", "delete", "if", "on", "void", "do", "ifFrameLoaded", "onClipEvent", "while", "else", "in", "or", "with", "eq", "le", "return"));
|
||||||
|
|
||||||
|
cliOptions.clear();
|
||||||
|
cliOptions.add(new CliOption("packageName", "flash package name (convention: package.name), default: io.swagger"));
|
||||||
|
cliOptions.add(new CliOption("packageVersion", "flash package version, default: 1.0.0"));
|
||||||
|
cliOptions.add(new CliOption("invokerPackage", "root package for generated code"));
|
||||||
|
cliOptions.add(new CliOption("sourceFolder", "source folder for generated code. e.g. src/main/flex"));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void processOpts() {
|
||||||
|
super.processOpts();
|
||||||
|
|
||||||
|
if (additionalProperties.containsKey("invokerPackage")) {
|
||||||
|
this.setInvokerPackage((String) additionalProperties.get("invokerPackage"));
|
||||||
|
} else {
|
||||||
|
//not set, use default to be passed to template
|
||||||
|
additionalProperties.put("invokerPackage", invokerPackage);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (additionalProperties.containsKey("sourceFolder")) {
|
||||||
|
this.setSourceFolder((String) additionalProperties.get("sourceFolder"));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (additionalProperties.containsKey("packageName")) {
|
||||||
|
setPackageName((String) additionalProperties.get("packageName"));
|
||||||
|
apiPackage = packageName + ".client.api";
|
||||||
|
modelPackage = packageName + ".client.model";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
setPackageName("io.swagger");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (additionalProperties.containsKey("packageVersion")) {
|
||||||
|
setPackageVersion((String) additionalProperties.get("packageVersion"));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
setPackageVersion("1.0.0");
|
||||||
|
}
|
||||||
|
|
||||||
|
additionalProperties.put("packageName", packageName);
|
||||||
|
additionalProperties.put("packageVersion", packageVersion);
|
||||||
|
|
||||||
|
//modelPackage = invokerPackage + File.separatorChar + "client" + File.separatorChar + "model";
|
||||||
|
//apiPackage = invokerPackage + File.separatorChar + "client" + File.separatorChar + "api";
|
||||||
|
|
||||||
|
final String invokerFolder = (sourceFolder + File.separator + invokerPackage + File.separator + "swagger" + File.separator).replace(".", File.separator).replace('.', File.separatorChar);
|
||||||
|
|
||||||
|
supportingFiles.add(new SupportingFile("ApiInvoker.as", invokerFolder + "common", "ApiInvoker.as"));
|
||||||
|
supportingFiles.add(new SupportingFile("ApiUrlHelper.as", invokerFolder + "common", "ApiUrlHelper.as"));
|
||||||
|
supportingFiles.add(new SupportingFile("ApiUserCredentials.as", invokerFolder + "common", "ApiUserCredentials.as"));
|
||||||
|
supportingFiles.add(new SupportingFile("ListWrapper.as", invokerFolder + "common", "ListWrapper.as"));
|
||||||
|
supportingFiles.add(new SupportingFile("SwaggerApi.as", invokerFolder + "common", "SwaggerApi.as"));
|
||||||
|
supportingFiles.add(new SupportingFile("XMLWriter.as", invokerFolder + "common", "XMLWriter.as"));
|
||||||
|
supportingFiles.add(new SupportingFile("ApiError.as", invokerFolder + "exception", "ApiErrors.as"));
|
||||||
|
supportingFiles.add(new SupportingFile("ApiErrorCodes.as", invokerFolder + "exception", "ApiErrorCodes.as"));
|
||||||
|
supportingFiles.add(new SupportingFile("ApiClientEvent.as", invokerFolder + "event", "ApiClientEvent.as"));
|
||||||
|
supportingFiles.add(new SupportingFile("Response.as", invokerFolder + "event", "Response.as"));
|
||||||
|
supportingFiles.add(new SupportingFile("build.properties", sourceFolder, "build.properties"));
|
||||||
|
supportingFiles.add(new SupportingFile("build.xml", sourceFolder, "build.xml"));
|
||||||
|
supportingFiles.add(new SupportingFile("AirExecutorApp-app.xml", sourceFolder + File.separatorChar + "bin", "AirExecutorApp-app.xml"));
|
||||||
|
supportingFiles.add(new SupportingFile("ASAXB-0.1.1.swc", sourceFolder + File.separatorChar + "lib", "ASAXB-0.1.1.swc"));
|
||||||
|
supportingFiles.add(new SupportingFile("as3corelib.swc", sourceFolder + File.separatorChar + "lib", "as3corelib.swc"));
|
||||||
|
supportingFiles.add(new SupportingFile("flexunit-4.1.0_RC2-28-flex_3.5.0.12683.swc", sourceFolder + File.separator + "lib" + File.separator + "ext", "flexunit-4.1.0_RC2-28-flex_3.5.0.12683.swc"));
|
||||||
|
supportingFiles.add(new SupportingFile("flexunit-aircilistener-4.1.0_RC2-28-3.5.0.12683.swc", sourceFolder + File.separator + "lib" + File.separator + "ext", "flexunit-aircilistener-4.1.0_RC2-28-3.5.0.12683.swc"));
|
||||||
|
supportingFiles.add(new SupportingFile("flexunit-cilistener-4.1.0_RC2-28-3.5.0.12683.swc", sourceFolder + File.separator + "lib" + File.separator + "ext", "flexunit-cilistener-4.1.0_RC2-28-3.5.0.12683.swc"));
|
||||||
|
supportingFiles.add(new SupportingFile("flexunit-core-flex-4.0.0.2-sdk3.5.0.12683.swc", sourceFolder + File.separator + "lib" + File.separator + "ext", "flexunit-core-flex-4.0.0.2-sdk3.5.0.12683.swc"));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String dropDots(String str) {
|
||||||
|
return str.replaceAll("\\.", "_");
|
||||||
|
}
|
||||||
|
|
||||||
|
public CodegenType getTag() {
|
||||||
|
return CodegenType.CLIENT;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return "flash";
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getHelp() {
|
||||||
|
return "Generates a Flash client library.";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String escapeReservedWord(String name) {
|
||||||
|
return name + "_";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String apiFileFolder() {
|
||||||
|
return (outputFolder + File.separatorChar + sourceFolder + File.separatorChar + apiPackage().replace('.', File.separatorChar)).replace('/', File.separatorChar);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String modelFileFolder() {
|
||||||
|
return (outputFolder + File.separatorChar + sourceFolder + File.separatorChar + modelPackage().replace('.', File.separatorChar)).replace('/', File.separatorChar);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getTypeDeclaration(Property p) {
|
||||||
|
if (p instanceof ArrayProperty) {
|
||||||
|
ArrayProperty ap = (ArrayProperty) p;
|
||||||
|
Property inner = ap.getItems();
|
||||||
|
return getSwaggerType(p);
|
||||||
|
} else if (p instanceof MapProperty) {
|
||||||
|
MapProperty mp = (MapProperty) p;
|
||||||
|
Property inner = mp.getAdditionalProperties();
|
||||||
|
|
||||||
|
return getSwaggerType(p);
|
||||||
|
}
|
||||||
|
return super.getTypeDeclaration(p);
|
||||||
|
}
|
||||||
|
|
||||||
|
@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 type;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
type = toModelName(swaggerType);
|
||||||
|
}
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toDefaultValue(Property p) {
|
||||||
|
if (p instanceof StringProperty) {
|
||||||
|
return "null";
|
||||||
|
} else if (p instanceof BooleanProperty) {
|
||||||
|
return "false";
|
||||||
|
} else if (p instanceof DateProperty) {
|
||||||
|
return "null";
|
||||||
|
} else if (p instanceof DateTimeProperty) {
|
||||||
|
return "null";
|
||||||
|
} else if (p instanceof DoubleProperty) {
|
||||||
|
DoubleProperty dp = (DoubleProperty) p;
|
||||||
|
if (dp.getDefault() != null) {
|
||||||
|
return dp.getDefault().toString();
|
||||||
|
}
|
||||||
|
return "0.0";
|
||||||
|
} else if (p instanceof FloatProperty) {
|
||||||
|
FloatProperty dp = (FloatProperty) p;
|
||||||
|
if (dp.getDefault() != null) {
|
||||||
|
return dp.getDefault().toString();
|
||||||
|
}
|
||||||
|
return "0.0";
|
||||||
|
} else if (p instanceof IntegerProperty) {
|
||||||
|
IntegerProperty dp = (IntegerProperty) p;
|
||||||
|
if (dp.getDefault() != null) {
|
||||||
|
return dp.getDefault().toString();
|
||||||
|
}
|
||||||
|
return "0";
|
||||||
|
} else if (p instanceof LongProperty) {
|
||||||
|
LongProperty dp = (LongProperty) p;
|
||||||
|
if (dp.getDefault() != null) {
|
||||||
|
return dp.getDefault().toString();
|
||||||
|
}
|
||||||
|
return "0";
|
||||||
|
} else if (p instanceof MapProperty) {
|
||||||
|
MapProperty ap = (MapProperty) p;
|
||||||
|
String inner = getSwaggerType(ap.getAdditionalProperties());
|
||||||
|
return "new Dictionary()";
|
||||||
|
} else if (p instanceof ArrayProperty) {
|
||||||
|
ArrayProperty ap = (ArrayProperty) p;
|
||||||
|
String inner = getSwaggerType(ap.getItems());
|
||||||
|
return "new Array()";
|
||||||
|
} else {
|
||||||
|
return "null";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toVarName(String name) {
|
||||||
|
// replace - with _ e.g. created-at => created_at
|
||||||
|
name = name.replaceAll("-", "_");
|
||||||
|
|
||||||
|
// if it's all uppper case, convert to lower case
|
||||||
|
if (name.matches("^[A-Z_]*$")) {
|
||||||
|
name = name.toLowerCase();
|
||||||
|
}
|
||||||
|
|
||||||
|
// underscore the variable name
|
||||||
|
// petId => pet_id
|
||||||
|
name = camelize(dropDots(name), true);
|
||||||
|
|
||||||
|
// for reserved word or word starting with number, append _
|
||||||
|
if (reservedWords.contains(name) || name.matches("^\\d.*")) {
|
||||||
|
name = escapeReservedWord(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toParamName(String name) {
|
||||||
|
// should be the same as variable name
|
||||||
|
return toVarName(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toModelName(String name) {
|
||||||
|
// model name cannot use reserved keyword, e.g. return
|
||||||
|
if (reservedWords.contains(name)) {
|
||||||
|
throw new RuntimeException(name + " (reserved word) cannot be used as a model name");
|
||||||
|
}
|
||||||
|
|
||||||
|
// camelize the model name
|
||||||
|
// phone_number => PhoneNumber
|
||||||
|
return camelize(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toModelFilename(String name) {
|
||||||
|
// model name cannot use reserved keyword, e.g. return
|
||||||
|
if (reservedWords.contains(name)) {
|
||||||
|
throw new RuntimeException(name + " (reserved word) cannot be used as a model name");
|
||||||
|
}
|
||||||
|
|
||||||
|
// underscore the model file name
|
||||||
|
// PhoneNumber => phone_number
|
||||||
|
return camelize(dropDots(name));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toApiFilename(String name) {
|
||||||
|
// replace - with _ e.g. created-at => created_at
|
||||||
|
name = name.replaceAll("-", "_");
|
||||||
|
|
||||||
|
// e.g. PhoneNumberApi.rb => phone_number_api.rb
|
||||||
|
return camelize(name) + "Api";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toApiName(String name) {
|
||||||
|
if (name.length() == 0) {
|
||||||
|
return "DefaultApi";
|
||||||
|
}
|
||||||
|
// e.g. phone_number_api => PhoneNumberApi
|
||||||
|
return camelize(name) + "Api";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toApiVarName(String name) {
|
||||||
|
if (name.length() == 0) {
|
||||||
|
return "DefaultApi";
|
||||||
|
}
|
||||||
|
return camelize(name) + "Api";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toOperationId(String operationId) {
|
||||||
|
// throw exception if method name is empty
|
||||||
|
if (StringUtils.isEmpty(operationId)) {
|
||||||
|
throw new RuntimeException("Empty method name (operationId) not allowed");
|
||||||
|
}
|
||||||
|
|
||||||
|
// method name cannot use reserved keyword, e.g. return
|
||||||
|
if (reservedWords.contains(operationId)) {
|
||||||
|
throw new RuntimeException(operationId + " (reserved word) cannot be used as method name");
|
||||||
|
}
|
||||||
|
|
||||||
|
return underscore(operationId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPackageName(String packageName) {
|
||||||
|
this.packageName = packageName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPackageVersion(String packageVersion) {
|
||||||
|
this.packageVersion = packageVersion;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setInvokerPackage(String invokerPackage) {
|
||||||
|
this.invokerPackage = invokerPackage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSourceFolder(String sourceFolder) {
|
||||||
|
this.sourceFolder = sourceFolder;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -1,17 +1,30 @@
|
|||||||
package io.swagger.codegen.languages;
|
package io.swagger.codegen.languages;
|
||||||
|
|
||||||
|
import com.google.common.base.Strings;
|
||||||
import io.swagger.codegen.CliOption;
|
import io.swagger.codegen.CliOption;
|
||||||
import io.swagger.codegen.CodegenConfig;
|
import io.swagger.codegen.CodegenConfig;
|
||||||
|
import io.swagger.codegen.CodegenModel;
|
||||||
|
import io.swagger.codegen.CodegenProperty;
|
||||||
import io.swagger.codegen.CodegenType;
|
import io.swagger.codegen.CodegenType;
|
||||||
import io.swagger.codegen.DefaultCodegen;
|
import io.swagger.codegen.DefaultCodegen;
|
||||||
import io.swagger.codegen.SupportingFile;
|
import io.swagger.codegen.SupportingFile;
|
||||||
|
import io.swagger.models.ComposedModel;
|
||||||
|
import io.swagger.models.Model;
|
||||||
|
import io.swagger.models.ModelImpl;
|
||||||
|
import io.swagger.models.RefModel;
|
||||||
import io.swagger.models.properties.ArrayProperty;
|
import io.swagger.models.properties.ArrayProperty;
|
||||||
import io.swagger.models.properties.MapProperty;
|
import io.swagger.models.properties.MapProperty;
|
||||||
import io.swagger.models.properties.Property;
|
import io.swagger.models.properties.Property;
|
||||||
|
import io.swagger.models.properties.StringProperty;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
|
||||||
@ -21,7 +34,7 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
protected String artifactId = "swagger-java-client";
|
protected String artifactId = "swagger-java-client";
|
||||||
protected String artifactVersion = "1.0.0";
|
protected String artifactVersion = "1.0.0";
|
||||||
protected String sourceFolder = "src/main/java";
|
protected String sourceFolder = "src/main/java";
|
||||||
|
protected String localVariablePrefix = "";
|
||||||
public JavaClientCodegen() {
|
public JavaClientCodegen() {
|
||||||
super();
|
super();
|
||||||
outputFolder = "generated-code/java";
|
outputFolder = "generated-code/java";
|
||||||
@ -61,6 +74,7 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
cliOptions.add(new CliOption("artifactId", "artifactId in generated pom.xml"));
|
cliOptions.add(new CliOption("artifactId", "artifactId in generated pom.xml"));
|
||||||
cliOptions.add(new CliOption("artifactVersion", "artifact version in generated pom.xml"));
|
cliOptions.add(new CliOption("artifactVersion", "artifact version in generated pom.xml"));
|
||||||
cliOptions.add(new CliOption("sourceFolder", "source folder for generated code"));
|
cliOptions.add(new CliOption("sourceFolder", "source folder for generated code"));
|
||||||
|
cliOptions.add(new CliOption("localVariablePrefix", "prefix for generated code members and local variables"));
|
||||||
|
|
||||||
supportedLibraries.put("<default>", "HTTP client: Jersey client 1.18. JSON processing: Jackson 2.4.2");
|
supportedLibraries.put("<default>", "HTTP client: Jersey client 1.18. JSON processing: Jackson 2.4.2");
|
||||||
supportedLibraries.put("jersey2", "HTTP client: Jersey client 2.6");
|
supportedLibraries.put("jersey2", "HTTP client: Jersey client 2.6");
|
||||||
@ -115,6 +129,11 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
this.setSourceFolder((String) additionalProperties.get("sourceFolder"));
|
this.setSourceFolder((String) additionalProperties.get("sourceFolder"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (additionalProperties.containsKey("localVariablePrefix")) {
|
||||||
|
this.setLocalVariablePrefix((String) additionalProperties.get("localVariablePrefix"));
|
||||||
|
}
|
||||||
|
|
||||||
final String invokerFolder = (sourceFolder + File.separator + invokerPackage).replace(".", File.separator);
|
final String invokerFolder = (sourceFolder + File.separator + invokerPackage).replace(".", File.separator);
|
||||||
supportingFiles.add(new SupportingFile("pom.mustache", "", "pom.xml"));
|
supportingFiles.add(new SupportingFile("pom.mustache", "", "pom.xml"));
|
||||||
supportingFiles.add(new SupportingFile("ApiClient.mustache", invokerFolder, "ApiClient.java"));
|
supportingFiles.add(new SupportingFile("ApiClient.mustache", invokerFolder, "ApiClient.java"));
|
||||||
@ -254,6 +273,57 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
return camelize(operationId, true);
|
return camelize(operationId, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CodegenModel fromModel(String name, Model model, Map<String, Model> allDefinitions) {
|
||||||
|
CodegenModel codegenModel = super.fromModel(name, model, allDefinitions);
|
||||||
|
|
||||||
|
if (allDefinitions != null && codegenModel != null && codegenModel.parent != null && codegenModel.hasEnums) {
|
||||||
|
final Model parentModel = allDefinitions.get(toModelName(codegenModel.parent));
|
||||||
|
final CodegenModel parentCodegenModel = super.fromModel(codegenModel.parent, parentModel);
|
||||||
|
codegenModel = this.reconcileInlineEnums(codegenModel, parentCodegenModel);
|
||||||
|
}
|
||||||
|
|
||||||
|
return codegenModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
private CodegenModel reconcileInlineEnums(CodegenModel codegenModel, CodegenModel parentCodegenModel) {
|
||||||
|
// This generator uses inline classes to define enums, which breaks when
|
||||||
|
// dealing with models that have subTypes. To clean this up, we will analyze
|
||||||
|
// the parent and child models, look for enums that match, and remove
|
||||||
|
// them from the child models and leave them in the parent.
|
||||||
|
// Because the child models extend the parents, the enums will be available via the parent.
|
||||||
|
|
||||||
|
// Only bother with reconciliation if the parent model has enums.
|
||||||
|
if (parentCodegenModel.hasEnums) {
|
||||||
|
|
||||||
|
// Get the properties for the parent and child models
|
||||||
|
final List<CodegenProperty> parentModelCodegenProperties = parentCodegenModel.vars;
|
||||||
|
List<CodegenProperty> codegenProperties = codegenModel.vars;
|
||||||
|
|
||||||
|
// Iterate over all of the parent model properties
|
||||||
|
for (CodegenProperty parentModelCodegenPropery : parentModelCodegenProperties) {
|
||||||
|
// Look for enums
|
||||||
|
if (parentModelCodegenPropery.isEnum) {
|
||||||
|
// Now that we have found an enum in the parent class,
|
||||||
|
// and search the child class for the same enum.
|
||||||
|
Iterator<CodegenProperty> iterator = codegenProperties.iterator();
|
||||||
|
while (iterator.hasNext()) {
|
||||||
|
CodegenProperty codegenProperty = iterator.next();
|
||||||
|
if (codegenProperty.isEnum && codegenProperty.equals(parentModelCodegenPropery)) {
|
||||||
|
// We found an enum in the child class that is
|
||||||
|
// a duplicate of the one in the parent, so remove it.
|
||||||
|
iterator.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
codegenModel.vars = codegenProperties;
|
||||||
|
}
|
||||||
|
|
||||||
|
return codegenModel;
|
||||||
|
}
|
||||||
|
|
||||||
public void setInvokerPackage(String invokerPackage) {
|
public void setInvokerPackage(String invokerPackage) {
|
||||||
this.invokerPackage = invokerPackage;
|
this.invokerPackage = invokerPackage;
|
||||||
}
|
}
|
||||||
@ -273,4 +343,8 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
public void setSourceFolder(String sourceFolder) {
|
public void setSourceFolder(String sourceFolder) {
|
||||||
this.sourceFolder = sourceFolder;
|
this.sourceFolder = sourceFolder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setLocalVariablePrefix(String localVariablePrefix) {
|
||||||
|
this.localVariablePrefix = localVariablePrefix;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -89,21 +89,6 @@ public class JaxRSServerCodegen extends JavaClientCodegen implements CodegenConf
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getTypeDeclaration(Property p) {
|
|
||||||
if (p instanceof ArrayProperty) {
|
|
||||||
ArrayProperty ap = (ArrayProperty) p;
|
|
||||||
Property inner = ap.getItems();
|
|
||||||
return getSwaggerType(p) + "<" + getTypeDeclaration(inner) + ">";
|
|
||||||
} else if (p instanceof MapProperty) {
|
|
||||||
MapProperty mp = (MapProperty) p;
|
|
||||||
Property inner = mp.getAdditionalProperties();
|
|
||||||
|
|
||||||
return getTypeDeclaration(inner);
|
|
||||||
}
|
|
||||||
return super.getTypeDeclaration(p);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addOperationToGroup(String tag, String resourcePath, Operation operation, CodegenOperation co, Map<String, List<CodegenOperation>> operations) {
|
public void addOperationToGroup(String tag, String resourcePath, Operation operation, CodegenOperation co, Map<String, List<CodegenOperation>> operations) {
|
||||||
String basePath = resourcePath;
|
String basePath = resourcePath;
|
||||||
|
@ -9,11 +9,19 @@ import io.swagger.codegen.DefaultCodegen;
|
|||||||
import io.swagger.codegen.SupportingFile;
|
import io.swagger.codegen.SupportingFile;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
|
import com.google.common.collect.ArrayListMultimap;
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
|
import com.google.common.collect.Multimap;
|
||||||
|
|
||||||
public class NodeJSServerCodegen extends DefaultCodegen implements CodegenConfig {
|
public class NodeJSServerCodegen extends DefaultCodegen implements CodegenConfig {
|
||||||
protected String apiVersion = "1.0.0";
|
protected String apiVersion = "1.0.0";
|
||||||
@ -197,4 +205,50 @@ public class NodeJSServerCodegen extends DefaultCodegen implements CodegenConfig
|
|||||||
}
|
}
|
||||||
return objs;
|
return objs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
private Map<String, Object> getOperations(Map<String, Object> objs) {
|
||||||
|
Map<String, Object> apiInfo = (Map<String, Object>) objs.get("apiInfo");
|
||||||
|
List<Map<String, Object>> apis = (List<Map<String, Object>>) apiInfo.get("apis");
|
||||||
|
Map<String, Object> api = apis.get(0);
|
||||||
|
return (Map<String, Object>) api.get("operations");
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<Map<String, Object>> sortOperationsByPath(List<CodegenOperation> ops) {
|
||||||
|
Multimap<String, CodegenOperation> opsByPath = ArrayListMultimap.create();
|
||||||
|
|
||||||
|
for (CodegenOperation op : ops) {
|
||||||
|
opsByPath.put(op.path, op);
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Map<String, Object>> opsByPathList = new ArrayList<Map<String, Object>>();
|
||||||
|
for (Entry<String, Collection<CodegenOperation>> entry : opsByPath.asMap().entrySet()) {
|
||||||
|
Map<String, Object> opsByPathEntry = new HashMap<String, Object>();
|
||||||
|
opsByPathList.add(opsByPathEntry);
|
||||||
|
opsByPathEntry.put("path", entry.getKey());
|
||||||
|
opsByPathEntry.put("operation", entry.getValue());
|
||||||
|
List<CodegenOperation> operationsForThisPath = Lists.newArrayList(entry.getValue());
|
||||||
|
operationsForThisPath.get(operationsForThisPath.size() - 1).hasMore = null;
|
||||||
|
if (opsByPathList.size() < opsByPath.asMap().size()) {
|
||||||
|
opsByPathEntry.put("hasMore", "true");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return opsByPathList;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, Object> postProcessSupportingFileData(Map<String, Object> objs) {
|
||||||
|
Map<String, Object> operations = getOperations(objs);
|
||||||
|
|
||||||
|
if (operations != null) {
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
List<CodegenOperation> ops = (List<CodegenOperation>) operations.get("operation");
|
||||||
|
|
||||||
|
List<Map<String, Object>> opsByPathList = sortOperationsByPath(ops);
|
||||||
|
operations.put("operationsByPath", opsByPathList);
|
||||||
|
}
|
||||||
|
|
||||||
|
return super.postProcessSupportingFileData(objs);
|
||||||
|
}
|
||||||
}
|
}
|
@ -159,15 +159,17 @@ public class PerlClientCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toVarName(String name) {
|
public String toVarName(String name) {
|
||||||
|
// return the name in underscore style
|
||||||
|
// PhoneNumber => phone_number
|
||||||
|
name = underscore(name);
|
||||||
|
|
||||||
// parameter name starting with number won't compile
|
// parameter name starting with number won't compile
|
||||||
// need to escape it by appending _ at the beginning
|
// need to escape it by appending _ at the beginning
|
||||||
if (name.matches("^[0-9]")) {
|
if (name.matches("^\\d.*")) {
|
||||||
name = "_" + name;
|
name = "_" + name;
|
||||||
}
|
}
|
||||||
|
|
||||||
// return the name in underscore style
|
return name;
|
||||||
// PhoneNumber => phone_number
|
|
||||||
return underscore(name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -79,12 +79,12 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
typeMapping.put("object", "object");
|
typeMapping.put("object", "object");
|
||||||
typeMapping.put("DateTime", "\\DateTime");
|
typeMapping.put("DateTime", "\\DateTime");
|
||||||
|
|
||||||
cliOptions.add(new CliOption("invokerPackage", "The main namespace to use for all classes."));
|
cliOptions.add(new CliOption("invokerPackage", "The main namespace to use for all classes. e.g. Yay\\Pets"));
|
||||||
cliOptions.add(new CliOption("packagePath", "The main package name for classes."));
|
cliOptions.add(new CliOption("packagePath", "The main package name for classes. e.g. GeneratedPetstore"));
|
||||||
cliOptions.add(new CliOption("srcBasePath", "The directory under packagePath to serve as source root."));
|
cliOptions.add(new CliOption("srcBasePath", "The directory under packagePath to serve as source root."));
|
||||||
cliOptions.add(new CliOption("composerVendorName", "The vendor name used in the composer package name. The template uses {{composerVendorName}}/{{composerProjectName}} for the composer package name."));
|
cliOptions.add(new CliOption("composerVendorName", "The vendor name used in the composer package name. The template uses {{composerVendorName}}/{{composerProjectName}} for the composer package name. e.g. yaypets"));
|
||||||
cliOptions.add(new CliOption("composerProjectName", "The project name used in the composer package name. The template uses {{composerVendorName}}/{{composerProjectName}} for the composer package name."));
|
cliOptions.add(new CliOption("composerProjectName", "The project name used in the composer package name. The template uses {{composerVendorName}}/{{composerProjectName}} for the composer package name. e.g. petstore-client"));
|
||||||
cliOptions.add(new CliOption("artifactVersion", "The version to use in the composer package version field."));
|
cliOptions.add(new CliOption("artifactVersion", "The version to use in the composer package version field. e.g. 1.2.3"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getPackagePath() {
|
public String getPackagePath() {
|
||||||
@ -284,15 +284,17 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toVarName(String name) {
|
public String toVarName(String name) {
|
||||||
|
// return the name in underscore style
|
||||||
|
// PhoneNumber => phone_number
|
||||||
|
name = underscore(name);
|
||||||
|
|
||||||
// parameter name starting with number won't compile
|
// parameter name starting with number won't compile
|
||||||
// need to escape it by appending _ at the beginning
|
// need to escape it by appending _ at the beginning
|
||||||
if (name.matches("^[0-9]")) {
|
if (name.matches("^\\d.*")) {
|
||||||
name = "_" + name;
|
name = "_" + name;
|
||||||
}
|
}
|
||||||
|
|
||||||
// return the name in underscore style
|
return name;
|
||||||
// PhoneNumber => phone_number
|
|
||||||
return underscore(name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -154,15 +154,17 @@ public class SilexServerCodegen extends DefaultCodegen implements CodegenConfig
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toVarName(String name) {
|
public String toVarName(String name) {
|
||||||
|
// return the name in underscore style
|
||||||
|
// PhoneNumber => phone_number
|
||||||
|
name = underscore(name);
|
||||||
|
|
||||||
// parameter name starting with number won't compile
|
// parameter name starting with number won't compile
|
||||||
// need to escape it by appending _ at the beginning
|
// need to escape it by appending _ at the beginning
|
||||||
if (name.matches("^[0-9]")) {
|
if (name.matches("^\\d.*")) {
|
||||||
name = "_" + name;
|
name = "_" + name;
|
||||||
}
|
}
|
||||||
|
|
||||||
// return the name in underscore style
|
return name;
|
||||||
// PhoneNumber => phone_number
|
|
||||||
return underscore(name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -19,22 +19,22 @@ import java.util.HashMap;
|
|||||||
|
|
||||||
{{#operations}}
|
{{#operations}}
|
||||||
public class {{classname}} {
|
public class {{classname}} {
|
||||||
private ApiClient apiClient;
|
private ApiClient {{localVariablePrefix}}apiClient;
|
||||||
|
|
||||||
public {{classname}}() {
|
public {{classname}}() {
|
||||||
this(Configuration.getDefaultApiClient());
|
this(Configuration.getDefaultApiClient());
|
||||||
}
|
}
|
||||||
|
|
||||||
public {{classname}}(ApiClient apiClient) {
|
public {{classname}}(ApiClient apiClient) {
|
||||||
this.apiClient = apiClient;
|
this.{{localVariablePrefix}}apiClient = apiClient;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ApiClient getApiClient() {
|
public ApiClient getApiClient() {
|
||||||
return apiClient;
|
return {{localVariablePrefix}}apiClient;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setApiClient(ApiClient apiClient) {
|
public void setApiClient(ApiClient apiClient) {
|
||||||
this.apiClient = apiClient;
|
this.{{localVariablePrefix}}apiClient = apiClient;
|
||||||
}
|
}
|
||||||
|
|
||||||
{{#operation}}
|
{{#operation}}
|
||||||
@ -45,7 +45,7 @@ public class {{classname}} {
|
|||||||
{{/allParams}} * @return {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}}
|
{{/allParams}} * @return {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}}
|
||||||
*/
|
*/
|
||||||
public {{#returnType}}{{{returnType}}} {{/returnType}}{{^returnType}}void {{/returnType}}{{nickname}} ({{#allParams}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) throws ApiException {
|
public {{#returnType}}{{{returnType}}} {{/returnType}}{{^returnType}}void {{/returnType}}{{nickname}} ({{#allParams}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) throws ApiException {
|
||||||
Object postBody = {{#bodyParam}}{{paramName}}{{/bodyParam}}{{^bodyParam}}null{{/bodyParam}};
|
Object {{localVariablePrefix}}postBody = {{#bodyParam}}{{paramName}}{{/bodyParam}}{{^bodyParam}}null{{/bodyParam}};
|
||||||
{{#allParams}}{{#required}}
|
{{#allParams}}{{#required}}
|
||||||
// verify the required parameter '{{paramName}}' is set
|
// verify the required parameter '{{paramName}}' is set
|
||||||
if ({{paramName}} == null) {
|
if ({{paramName}} == null) {
|
||||||
@ -54,42 +54,42 @@ public class {{classname}} {
|
|||||||
{{/required}}{{/allParams}}
|
{{/required}}{{/allParams}}
|
||||||
|
|
||||||
// create path and map variables
|
// create path and map variables
|
||||||
String path = "{{path}}".replaceAll("\\{format\\}","json"){{#pathParams}}
|
String {{localVariablePrefix}}path = "{{path}}".replaceAll("\\{format\\}","json"){{#pathParams}}
|
||||||
.replaceAll("\\{" + "{{baseName}}" + "\\}", apiClient.escapeString({{{paramName}}}.toString())){{/pathParams}};
|
.replaceAll("\\{" + "{{baseName}}" + "\\}", {{localVariablePrefix}}apiClient.escapeString({{{paramName}}}.toString())){{/pathParams}};
|
||||||
|
|
||||||
// query params
|
// query params
|
||||||
List<Pair> queryParams = new ArrayList<Pair>();
|
List<Pair> {{localVariablePrefix}}queryParams = new ArrayList<Pair>();
|
||||||
Map<String, String> headerParams = new HashMap<String, String>();
|
Map<String, String> {{localVariablePrefix}}headerParams = new HashMap<String, String>();
|
||||||
Map<String, Object> formParams = new HashMap<String, Object>();
|
Map<String, Object> {{localVariablePrefix}}formParams = new HashMap<String, Object>();
|
||||||
|
|
||||||
{{#queryParams}}
|
{{#queryParams}}
|
||||||
queryParams.addAll(apiClient.parameterToPairs("{{#collectionFormat}}{{{collectionFormat}}}{{/collectionFormat}}", "{{baseName}}", {{paramName}}));
|
{{localVariablePrefix}}queryParams.addAll({{localVariablePrefix}}apiClient.parameterToPairs("{{#collectionFormat}}{{{collectionFormat}}}{{/collectionFormat}}", "{{baseName}}", {{paramName}}));
|
||||||
{{/queryParams}}
|
{{/queryParams}}
|
||||||
|
|
||||||
{{#headerParams}}if ({{paramName}} != null)
|
{{#headerParams}}if ({{paramName}} != null)
|
||||||
headerParams.put("{{baseName}}", apiClient.parameterToString({{paramName}}));
|
{{localVariablePrefix}}headerParams.put("{{baseName}}", {{localVariablePrefix}}apiClient.parameterToString({{paramName}}));
|
||||||
{{/headerParams}}
|
{{/headerParams}}
|
||||||
|
|
||||||
{{#formParams}}if ({{paramName}} != null)
|
{{#formParams}}if ({{paramName}} != null)
|
||||||
formParams.put("{{baseName}}", {{paramName}});
|
{{localVariablePrefix}}formParams.put("{{baseName}}", {{paramName}});
|
||||||
{{/formParams}}
|
{{/formParams}}
|
||||||
|
|
||||||
final String[] accepts = {
|
final String[] {{localVariablePrefix}}accepts = {
|
||||||
{{#produces}}"{{mediaType}}"{{#hasMore}}, {{/hasMore}}{{/produces}}
|
{{#produces}}"{{mediaType}}"{{#hasMore}}, {{/hasMore}}{{/produces}}
|
||||||
};
|
};
|
||||||
final String accept = apiClient.selectHeaderAccept(accepts);
|
final String {{localVariablePrefix}}accept = {{localVariablePrefix}}apiClient.selectHeaderAccept({{localVariablePrefix}}accepts);
|
||||||
|
|
||||||
final String[] contentTypes = {
|
final String[] {{localVariablePrefix}}contentTypes = {
|
||||||
{{#consumes}}"{{mediaType}}"{{#hasMore}}, {{/hasMore}}{{/consumes}}
|
{{#consumes}}"{{mediaType}}"{{#hasMore}}, {{/hasMore}}{{/consumes}}
|
||||||
};
|
};
|
||||||
final String contentType = apiClient.selectHeaderContentType(contentTypes);
|
final String {{localVariablePrefix}}contentType = {{localVariablePrefix}}apiClient.selectHeaderContentType({{localVariablePrefix}}contentTypes);
|
||||||
|
|
||||||
String[] authNames = new String[] { {{#authMethods}}"{{name}}"{{#hasMore}}, {{/hasMore}}{{/authMethods}} };
|
String[] {{localVariablePrefix}}authNames = new String[] { {{#authMethods}}"{{name}}"{{#hasMore}}, {{/hasMore}}{{/authMethods}} };
|
||||||
{{#returnType}}
|
{{#returnType}}
|
||||||
TypeRef returnType = new TypeRef<{{{returnType}}}>() {};
|
TypeRef {{localVariablePrefix}}returnType = new TypeRef<{{{returnType}}}>() {};
|
||||||
return apiClient.invokeAPI(path, "{{httpMethod}}", queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType);
|
return {{localVariablePrefix}}apiClient.invokeAPI({{localVariablePrefix}}path, "{{httpMethod}}", {{localVariablePrefix}}queryParams, {{localVariablePrefix}}postBody, {{localVariablePrefix}}headerParams, {{localVariablePrefix}}formParams, {{localVariablePrefix}}accept, {{localVariablePrefix}}contentType, {{localVariablePrefix}}authNames, {{localVariablePrefix}}returnType);
|
||||||
{{/returnType}}{{^returnType}}
|
{{/returnType}}{{^returnType}}
|
||||||
apiClient.invokeAPI(path, "{{httpMethod}}", queryParams, postBody, headerParams, formParams, accept, contentType, authNames, null);
|
{{localVariablePrefix}}apiClient.invokeAPI({{localVariablePrefix}}path, "{{httpMethod}}", {{localVariablePrefix}}queryParams, {{localVariablePrefix}}postBody, {{localVariablePrefix}}headerParams, {{localVariablePrefix}}formParams, {{localVariablePrefix}}accept, {{localVariablePrefix}}contentType, {{localVariablePrefix}}authNames, null);
|
||||||
{{/returnType}}
|
{{/returnType}}
|
||||||
}
|
}
|
||||||
{{/operation}}
|
{{/operation}}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
io.swagger.codegen.languages.AndroidClientCodegen
|
io.swagger.codegen.languages.AndroidClientCodegen
|
||||||
io.swagger.codegen.languages.AsyncScalaClientCodegen
|
io.swagger.codegen.languages.AsyncScalaClientCodegen
|
||||||
io.swagger.codegen.languages.CSharpClientCodegen
|
io.swagger.codegen.languages.CSharpClientCodegen
|
||||||
|
io.swagger.codegen.languages.FlashClientCodegen
|
||||||
io.swagger.codegen.languages.JavaClientCodegen
|
io.swagger.codegen.languages.JavaClientCodegen
|
||||||
io.swagger.codegen.languages.JaxRSServerCodegen
|
io.swagger.codegen.languages.JaxRSServerCodegen
|
||||||
io.swagger.codegen.languages.JavaInflectorServerCodegen
|
io.swagger.codegen.languages.JavaInflectorServerCodegen
|
||||||
|
@ -56,7 +56,7 @@ public class {{classname}} extends SwaggerApi {
|
|||||||
{{#headerParams}}headerParams["{{paramName}}"] = toPathValue({{paramName}});
|
{{#headerParams}}headerParams["{{paramName}}"] = toPathValue({{paramName}});
|
||||||
{{/headerParams}}
|
{{/headerParams}}
|
||||||
|
|
||||||
var token:AsyncToken = getApiInvoker().invokeAPI(path, "{{httpMethod}}", queryParams, {{#bodyParam}}{{bodyParam}}{{/bodyParam}}{{^bodyParam}}null{{/bodyParam}}, headerParams);
|
var token:AsyncToken = getApiInvoker().invokeAPI(path, "{{httpMethod}}", queryParams, {{#bodyParam}}{{paramName}}{{/bodyParam}}{{^bodyParam}}null{{/bodyParam}}, headerParams);
|
||||||
|
|
||||||
var requestId: String = getUniqueId();
|
var requestId: String = getUniqueId();
|
||||||
|
|
||||||
@ -70,4 +70,4 @@ public class {{classname}} extends SwaggerApi {
|
|||||||
{{/operation}}
|
{{/operation}}
|
||||||
}
|
}
|
||||||
{{/operations}}
|
{{/operations}}
|
||||||
}
|
}
|
||||||
|
@ -7,34 +7,30 @@ package {{package}} {
|
|||||||
{{#model}}
|
{{#model}}
|
||||||
[XmlRootNode(name="{{classname}}")]
|
[XmlRootNode(name="{{classname}}")]
|
||||||
public class {{classname}} {
|
public class {{classname}} {
|
||||||
{{#vars}}
|
{{#vars}}
|
||||||
|
{{#description}}/* {{description}} */
|
||||||
{{#description}}/* {{description}} */
|
{{/description}}
|
||||||
{{/description}}
|
{{#isContainer}}
|
||||||
|
|
||||||
{{#isList}}
|
|
||||||
// This declaration below of _{{name}}_obj_class is to force flash compiler to include this class
|
// This declaration below of _{{name}}_obj_class is to force flash compiler to include this class
|
||||||
private var _{{name}}_obj_class: {{baseType}} = null;
|
private var _{{name}}_obj_class: {{baseType}} = null;
|
||||||
[XmlElementWrapper(name="{{name}}")]
|
[XmlElementWrapper(name="{{baseName}}")]
|
||||||
[XmlElements(name="{{nameSingular}}", type="{{baseType}}")]
|
[XmlElements(name="{{name}}", type="{{baseType}}")]
|
||||||
{{/isList}}
|
{{/isContainer}}
|
||||||
{{#isNotContainer}}[XmlElement(name="{{name}}")]
|
{{^isContainer}}[XmlElement(name="{{baseName}}")]
|
||||||
{{/isNotContainer}}
|
{{/isContainer}}
|
||||||
public var {{name}}: {{{datatype}}} = {{{defaultValue}}};
|
public var {{name}}: {{{datatype}}} = {{{defaultValue}}};
|
||||||
|
|
||||||
{{/vars}}
|
{{/vars}}
|
||||||
|
|
||||||
public function toString(): String {
|
public function toString(): String {
|
||||||
var str: String = "{{classname}}: ";
|
var str: String = "{{classname}}: ";
|
||||||
{{#vars}}
|
{{#vars}}
|
||||||
str += " ({{name}}: " + {{name}} + ")";
|
str += " ({{name}}: " + {{name}} + ")";
|
||||||
{{/vars}}
|
{{/vars}}
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
{{/model}}
|
{{/model}}
|
||||||
{{/models}}
|
{{/models}}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -12,8 +12,9 @@
|
|||||||
"paths": {
|
"paths": {
|
||||||
{{#apis}}
|
{{#apis}}
|
||||||
{{#operations}}
|
{{#operations}}
|
||||||
{{#operation}}
|
{{#operationsByPath}}
|
||||||
"{{{path}}}": {
|
"{{{path}}}": {
|
||||||
|
{{#operation}}
|
||||||
"{{httpMethod}}": {
|
"{{httpMethod}}": {
|
||||||
"summary": "{{summary}}",
|
"summary": "{{summary}}",
|
||||||
"description":"{{notes}}",
|
"description":"{{notes}}",
|
||||||
@ -29,9 +30,10 @@
|
|||||||
{{#hasMore}},{{/hasMore}}
|
{{#hasMore}},{{/hasMore}}
|
||||||
{{/responses}}
|
{{/responses}}
|
||||||
}
|
}
|
||||||
}
|
} {{#hasMore}},{{/hasMore}}
|
||||||
|
{{/operation}}
|
||||||
} {{#hasMore}},{{/hasMore}}
|
} {{#hasMore}},{{/hasMore}}
|
||||||
{{/operation}}
|
{{/operationsByPath}}
|
||||||
{{#hasMore}},{{/hasMore}}
|
{{#hasMore}},{{/hasMore}}
|
||||||
{{/operations}}
|
{{/operations}}
|
||||||
{{/apis}}
|
{{/apis}}
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
#import "{{classPrefix}}ApiClient.h"
|
#import "{{classPrefix}}ApiClient.h"
|
||||||
|
|
||||||
@implementation {{classPrefix}}ApiClient
|
|
||||||
|
|
||||||
NSString *const {{classPrefix}}ResponseObjectErrorKey = @"{{classPrefix}}ResponseObject";
|
NSString *const {{classPrefix}}ResponseObjectErrorKey = @"{{classPrefix}}ResponseObject";
|
||||||
|
|
||||||
static long requestId = 0;
|
static long requestId = 0;
|
||||||
@ -9,41 +7,75 @@ static bool offlineState = false;
|
|||||||
static NSMutableSet * queuedRequests = nil;
|
static NSMutableSet * queuedRequests = nil;
|
||||||
static bool cacheEnabled = false;
|
static bool cacheEnabled = false;
|
||||||
static AFNetworkReachabilityStatus reachabilityStatus = AFNetworkReachabilityStatusNotReachable;
|
static AFNetworkReachabilityStatus reachabilityStatus = AFNetworkReachabilityStatusNotReachable;
|
||||||
static NSOperationQueue* sharedQueue;
|
|
||||||
static void (^reachabilityChangeBlock)(int);
|
static void (^reachabilityChangeBlock)(int);
|
||||||
|
|
||||||
|
@implementation {{classPrefix}}ApiClient
|
||||||
|
|
||||||
|
- (instancetype)init {
|
||||||
|
NSString *baseUrl = [[{{classPrefix}}Configuration sharedConfig] host];
|
||||||
|
return [self initWithBaseURL:[NSURL URLWithString:baseUrl]];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (instancetype)initWithBaseURL:(NSURL *)url {
|
||||||
|
self = [super initWithBaseURL:url];
|
||||||
|
if (self) {
|
||||||
|
self.requestSerializer = [AFJSONRequestSerializer serializer];
|
||||||
|
self.responseSerializer = [AFJSONResponseSerializer serializer];
|
||||||
|
// configure reachability
|
||||||
|
[self configureCacheReachibility];
|
||||||
|
}
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
+ (void)initialize {
|
||||||
|
if (self == [{{classPrefix}}ApiClient class]) {
|
||||||
|
queuedRequests = [[NSMutableSet alloc] init];
|
||||||
|
// initialize URL cache
|
||||||
|
[self configureCacheWithMemoryAndDiskCapacity:4*1024*1024 diskSize:32*1024*1024];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#pragma mark - Setter Methods
|
||||||
|
|
||||||
|
+ (void) setOfflineState:(BOOL) state {
|
||||||
|
offlineState = state;
|
||||||
|
}
|
||||||
|
|
||||||
|
+ (void) setCacheEnabled:(BOOL)enabled {
|
||||||
|
cacheEnabled = enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)setHeaderValue:(NSString*) value
|
||||||
|
forKey:(NSString*) forKey {
|
||||||
|
[self.requestSerializer setValue:value forHTTPHeaderField:forKey];
|
||||||
|
}
|
||||||
|
|
||||||
#pragma mark - Log Methods
|
#pragma mark - Log Methods
|
||||||
|
|
||||||
- (void)logResponse:(AFHTTPRequestOperation *)operation
|
- (void)logResponse:(AFHTTPRequestOperation *)operation
|
||||||
forRequest:(NSURLRequest *)request
|
forRequest:(NSURLRequest *)request
|
||||||
error:(NSError*)error {
|
error:(NSError*)error {
|
||||||
{{classPrefix}}Configuration *config = [{{classPrefix}}Configuration sharedConfig];
|
{{classPrefix}}Configuration *config = [{{classPrefix}}Configuration sharedConfig];
|
||||||
|
|
||||||
NSString *message = [NSString stringWithFormat:@"\n[DEBUG] Request body \n~BEGIN~\n %@\n~END~\n"\
|
NSString *message = [NSString stringWithFormat:@"\n[DEBUG] Request body \n~BEGIN~\n %@\n~END~\n"\
|
||||||
"[DEBUG] HTTP Response body \n~BEGIN~\n %@\n~END~\n",
|
"[DEBUG] HTTP Response body \n~BEGIN~\n %@\n~END~\n",
|
||||||
[[NSString alloc] initWithData:request.HTTPBody encoding:NSUTF8StringEncoding],
|
[[NSString alloc] initWithData:request.HTTPBody encoding:NSUTF8StringEncoding],
|
||||||
operation.responseString];
|
operation.responseString];
|
||||||
|
|
||||||
if (config.loggingFileHanlder) {
|
if (config.loggingFileHanlder) {
|
||||||
[config.loggingFileHanlder seekToEndOfFile];
|
[config.loggingFileHanlder seekToEndOfFile];
|
||||||
[config.loggingFileHanlder writeData:[message dataUsingEncoding:NSUTF8StringEncoding]];
|
[config.loggingFileHanlder writeData:[message dataUsingEncoding:NSUTF8StringEncoding]];
|
||||||
}
|
}
|
||||||
|
|
||||||
NSLog(@"%@", message);
|
NSLog(@"%@", message);
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma mark - Cache Methods
|
#pragma mark - Cache Methods
|
||||||
|
|
||||||
+ (void) setCacheEnabled:(BOOL)enabled {
|
|
||||||
cacheEnabled = enabled;
|
|
||||||
}
|
|
||||||
|
|
||||||
+(void)clearCache {
|
+(void)clearCache {
|
||||||
[[NSURLCache sharedURLCache] removeAllCachedResponses];
|
[[NSURLCache sharedURLCache] removeAllCachedResponses];
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma mark -
|
|
||||||
|
|
||||||
+(void)configureCacheWithMemoryAndDiskCapacity: (unsigned long) memorySize
|
+(void)configureCacheWithMemoryAndDiskCapacity: (unsigned long) memorySize
|
||||||
diskSize: (unsigned long) diskSize {
|
diskSize: (unsigned long) diskSize {
|
||||||
NSAssert(memorySize > 0, @"invalid in-memory cache size");
|
NSAssert(memorySize > 0, @"invalid in-memory cache size");
|
||||||
@ -58,43 +90,7 @@ static void (^reachabilityChangeBlock)(int);
|
|||||||
[NSURLCache setSharedURLCache:cache];
|
[NSURLCache setSharedURLCache:cache];
|
||||||
}
|
}
|
||||||
|
|
||||||
+(NSOperationQueue*) sharedQueue {
|
#pragma mark - Utility Methods
|
||||||
return sharedQueue;
|
|
||||||
}
|
|
||||||
|
|
||||||
+({{classPrefix}}ApiClient *)sharedClientFromPool:(NSString *)baseUrl {
|
|
||||||
static NSMutableDictionary *_pool = nil;
|
|
||||||
if (queuedRequests == nil) {
|
|
||||||
queuedRequests = [[NSMutableSet alloc]init];
|
|
||||||
}
|
|
||||||
if(_pool == nil) {
|
|
||||||
// setup static vars
|
|
||||||
// create queue
|
|
||||||
sharedQueue = [[NSOperationQueue alloc] init];
|
|
||||||
|
|
||||||
// create pool
|
|
||||||
_pool = [[NSMutableDictionary alloc] init];
|
|
||||||
|
|
||||||
// initialize URL cache
|
|
||||||
[{{classPrefix}}ApiClient configureCacheWithMemoryAndDiskCapacity:4*1024*1024 diskSize:32*1024*1024];
|
|
||||||
|
|
||||||
// configure reachability
|
|
||||||
[{{classPrefix}}ApiClient configureCacheReachibilityForHost:baseUrl];
|
|
||||||
}
|
|
||||||
|
|
||||||
@synchronized(self) {
|
|
||||||
{{classPrefix}}ApiClient * client = [_pool objectForKey:baseUrl];
|
|
||||||
if (client == nil) {
|
|
||||||
client = [[{{classPrefix}}ApiClient alloc] initWithBaseURL:[NSURL URLWithString:baseUrl]];
|
|
||||||
[_pool setValue:client forKey:baseUrl ];
|
|
||||||
if([[{{classPrefix}}Configuration sharedConfig] debug])
|
|
||||||
NSLog(@"new client for path %@", baseUrl);
|
|
||||||
}
|
|
||||||
if([[{{classPrefix}}Configuration sharedConfig] debug])
|
|
||||||
NSLog(@"returning client for path %@", baseUrl);
|
|
||||||
return client;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Detect `Accept` from accepts
|
* Detect `Accept` from accepts
|
||||||
@ -104,13 +100,13 @@ static void (^reachabilityChangeBlock)(int);
|
|||||||
if (accepts == nil || [accepts count] == 0) {
|
if (accepts == nil || [accepts count] == 0) {
|
||||||
return @"";
|
return @"";
|
||||||
}
|
}
|
||||||
|
|
||||||
NSMutableArray *lowerAccepts = [[NSMutableArray alloc] initWithCapacity:[accepts count]];
|
NSMutableArray *lowerAccepts = [[NSMutableArray alloc] initWithCapacity:[accepts count]];
|
||||||
[accepts enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
|
[accepts enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
|
||||||
[lowerAccepts addObject:[obj lowercaseString]];
|
[lowerAccepts addObject:[obj lowercaseString]];
|
||||||
}];
|
}];
|
||||||
|
|
||||||
|
|
||||||
if ([lowerAccepts containsObject:@"application/json"]) {
|
if ([lowerAccepts containsObject:@"application/json"]) {
|
||||||
return @"application/json";
|
return @"application/json";
|
||||||
}
|
}
|
||||||
@ -127,7 +123,7 @@ static void (^reachabilityChangeBlock)(int);
|
|||||||
if (contentTypes == nil || [contentTypes count] == 0) {
|
if (contentTypes == nil || [contentTypes count] == 0) {
|
||||||
return @"application/json";
|
return @"application/json";
|
||||||
}
|
}
|
||||||
|
|
||||||
NSMutableArray *lowerContentTypes = [[NSMutableArray alloc] initWithCapacity:[contentTypes count]];
|
NSMutableArray *lowerContentTypes = [[NSMutableArray alloc] initWithCapacity:[contentTypes count]];
|
||||||
[contentTypes enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
|
[contentTypes enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
|
||||||
[lowerContentTypes addObject:[obj lowercaseString]];
|
[lowerContentTypes addObject:[obj lowercaseString]];
|
||||||
@ -141,11 +137,23 @@ static void (^reachabilityChangeBlock)(int);
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
-(void)setHeaderValue:(NSString*) value
|
+ (NSString*)escape:(id)unescaped {
|
||||||
forKey:(NSString*) forKey {
|
if([unescaped isKindOfClass:[NSString class]]){
|
||||||
[self.requestSerializer setValue:value forHTTPHeaderField:forKey];
|
return (NSString *)CFBridgingRelease
|
||||||
|
(CFURLCreateStringByAddingPercentEscapes(
|
||||||
|
NULL,
|
||||||
|
(__bridge CFStringRef) unescaped,
|
||||||
|
NULL,
|
||||||
|
(CFStringRef)@"!*'();:@&=+$,/?%#[]",
|
||||||
|
kCFStringEncodingUTF8));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return [NSString stringWithFormat:@"%@", unescaped];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#pragma mark - Request Methods
|
||||||
|
|
||||||
+(unsigned long)requestQueueSize {
|
+(unsigned long)requestQueueSize {
|
||||||
return [queuedRequests count];
|
return [queuedRequests count];
|
||||||
}
|
}
|
||||||
@ -171,46 +179,28 @@ static void (^reachabilityChangeBlock)(int);
|
|||||||
[queuedRequests removeObject:requestId];
|
[queuedRequests removeObject:requestId];
|
||||||
}
|
}
|
||||||
|
|
||||||
+(NSString*) escape:(id)unescaped {
|
|
||||||
if([unescaped isKindOfClass:[NSString class]]){
|
|
||||||
return (NSString *)CFBridgingRelease
|
|
||||||
(CFURLCreateStringByAddingPercentEscapes(
|
|
||||||
NULL,
|
|
||||||
(__bridge CFStringRef) unescaped,
|
|
||||||
NULL,
|
|
||||||
(CFStringRef)@"!*'();:@&=+$,/?%#[]",
|
|
||||||
kCFStringEncodingUTF8));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return [NSString stringWithFormat:@"%@", unescaped];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
-(Boolean) executeRequestWithId:(NSNumber*) requestId {
|
-(Boolean) executeRequestWithId:(NSNumber*) requestId {
|
||||||
NSSet* matchingItems = [queuedRequests objectsPassingTest:^BOOL(id obj, BOOL *stop) {
|
NSSet* matchingItems = [queuedRequests objectsPassingTest:^BOOL(id obj, BOOL *stop) {
|
||||||
if([obj intValue] == [requestId intValue])
|
if([obj intValue] == [requestId intValue]) {
|
||||||
return TRUE;
|
return YES;
|
||||||
else return FALSE;
|
}
|
||||||
|
else {
|
||||||
|
return NO;
|
||||||
|
}
|
||||||
}];
|
}];
|
||||||
|
|
||||||
if(matchingItems.count == 1) {
|
if(matchingItems.count == 1) {
|
||||||
if([[{{classPrefix}}Configuration sharedConfig] debug])
|
if([[{{classPrefix}}Configuration sharedConfig] debug])
|
||||||
NSLog(@"removing request id %@", requestId);
|
NSLog(@"removing request id %@", requestId);
|
||||||
[queuedRequests removeObject:requestId];
|
[queuedRequests removeObject:requestId];
|
||||||
return true;
|
return YES;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return NO;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
-(id)initWithBaseURL:(NSURL *)url {
|
#pragma mark - Reachability Methods
|
||||||
self = [super initWithBaseURL:url];
|
|
||||||
self.requestSerializer = [AFJSONRequestSerializer serializer];
|
|
||||||
self.responseSerializer = [AFJSONResponseSerializer serializer];
|
|
||||||
if (!self)
|
|
||||||
return nil;
|
|
||||||
return self;
|
|
||||||
}
|
|
||||||
|
|
||||||
+(AFNetworkReachabilityStatus) getReachabilityStatus {
|
+(AFNetworkReachabilityStatus) getReachabilityStatus {
|
||||||
return reachabilityStatus;
|
return reachabilityStatus;
|
||||||
@ -220,12 +210,8 @@ static void (^reachabilityChangeBlock)(int);
|
|||||||
reachabilityChangeBlock = changeBlock;
|
reachabilityChangeBlock = changeBlock;
|
||||||
}
|
}
|
||||||
|
|
||||||
+(void) setOfflineState:(BOOL) state {
|
- (void) configureCacheReachibility {
|
||||||
offlineState = state;
|
[self.reachabilityManager setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
|
||||||
}
|
|
||||||
|
|
||||||
+(void) configureCacheReachibilityForHost:(NSString*)host {
|
|
||||||
[[{{classPrefix}}ApiClient sharedClientFromPool:host].reachabilityManager setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
|
|
||||||
reachabilityStatus = status;
|
reachabilityStatus = status;
|
||||||
switch (status) {
|
switch (status) {
|
||||||
case AFNetworkReachabilityStatusUnknown:
|
case AFNetworkReachabilityStatusUnknown:
|
||||||
@ -254,16 +240,352 @@ static void (^reachabilityChangeBlock)(int);
|
|||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// call the reachability block, if configured
|
// call the reachability block, if configured
|
||||||
if(reachabilityChangeBlock != nil) {
|
if(reachabilityChangeBlock != nil) {
|
||||||
reachabilityChangeBlock(status);
|
reachabilityChangeBlock(status);
|
||||||
}
|
}
|
||||||
}];
|
}];
|
||||||
[[{{classPrefix}}ApiClient sharedClientFromPool:host].reachabilityManager startMonitoring];
|
|
||||||
|
[self.reachabilityManager startMonitoring];
|
||||||
}
|
}
|
||||||
|
|
||||||
-(NSString*) pathWithQueryParamsToString:(NSString*) path
|
#pragma mark - Deserialize methods
|
||||||
queryParams:(NSDictionary*) queryParams {
|
|
||||||
|
- (id) deserialize:(id) data class:(NSString *) class {
|
||||||
|
NSRegularExpression *regexp = nil;
|
||||||
|
NSTextCheckingResult *match = nil;
|
||||||
|
NSMutableArray *resultArray = nil;
|
||||||
|
NSMutableDictionary *resultDict = nil;
|
||||||
|
NSString *innerType = nil;
|
||||||
|
|
||||||
|
// return nil if data is nil or class is nil
|
||||||
|
if (!data || !class) {
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
|
||||||
|
// remove "*" from class, if ends with "*"
|
||||||
|
if ([class hasSuffix:@"*"]) {
|
||||||
|
class = [class substringToIndex:[class length] - 1];
|
||||||
|
}
|
||||||
|
|
||||||
|
// pure object
|
||||||
|
if ([class isEqualToString:@"NSObject"]) {
|
||||||
|
return [[NSObject alloc] init];
|
||||||
|
}
|
||||||
|
|
||||||
|
// list of models
|
||||||
|
NSString *arrayOfModelsPat = @"NSArray<(.+)>";
|
||||||
|
regexp = [NSRegularExpression regularExpressionWithPattern:arrayOfModelsPat
|
||||||
|
options:NSRegularExpressionCaseInsensitive
|
||||||
|
error:nil];
|
||||||
|
|
||||||
|
match = [regexp firstMatchInString:class
|
||||||
|
options:0
|
||||||
|
range:NSMakeRange(0, [class length])];
|
||||||
|
|
||||||
|
if (match) {
|
||||||
|
innerType = [class substringWithRange:[match rangeAtIndex:1]];
|
||||||
|
|
||||||
|
resultArray = [NSMutableArray arrayWithCapacity:[data count]];
|
||||||
|
[data enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
|
||||||
|
[resultArray addObject:[self deserialize:obj class:innerType]];
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
return resultArray;
|
||||||
|
}
|
||||||
|
|
||||||
|
// list of primitives
|
||||||
|
NSString *arrayOfPrimitivesPat = @"NSArray\\* /\\* (.+) \\*/";
|
||||||
|
regexp = [NSRegularExpression regularExpressionWithPattern:arrayOfPrimitivesPat
|
||||||
|
options:NSRegularExpressionCaseInsensitive
|
||||||
|
error:nil];
|
||||||
|
match = [regexp firstMatchInString:class
|
||||||
|
options:0
|
||||||
|
range:NSMakeRange(0, [class length])];
|
||||||
|
|
||||||
|
if (match) {
|
||||||
|
innerType = [class substringWithRange:[match rangeAtIndex:1]];
|
||||||
|
|
||||||
|
resultArray = [NSMutableArray arrayWithCapacity:[data count]];
|
||||||
|
[data enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
|
||||||
|
[resultArray addObject:[self deserialize:obj class:innerType]];
|
||||||
|
}];
|
||||||
|
|
||||||
|
return resultArray;
|
||||||
|
}
|
||||||
|
|
||||||
|
// map
|
||||||
|
NSString *dictPat = @"NSDictionary\\* /\\* (.+?), (.+) \\*/";
|
||||||
|
regexp = [NSRegularExpression regularExpressionWithPattern:dictPat
|
||||||
|
options:NSRegularExpressionCaseInsensitive
|
||||||
|
error:nil];
|
||||||
|
match = [regexp firstMatchInString:class
|
||||||
|
options:0
|
||||||
|
range:NSMakeRange(0, [class length])];
|
||||||
|
|
||||||
|
if (match) {
|
||||||
|
NSString *valueType = [class substringWithRange:[match rangeAtIndex:2]];
|
||||||
|
|
||||||
|
resultDict = [NSMutableDictionary dictionaryWithCapacity:[data count]];
|
||||||
|
[data enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
|
||||||
|
[resultDict setValue:[self deserialize:obj class:valueType] forKey:key];
|
||||||
|
}];
|
||||||
|
|
||||||
|
return resultDict;
|
||||||
|
}
|
||||||
|
|
||||||
|
// primitives
|
||||||
|
NSArray *primitiveTypes = @[@"NSString", @"NSDate", @"NSNumber"];
|
||||||
|
|
||||||
|
if ([primitiveTypes containsObject:class]) {
|
||||||
|
if ([class isEqualToString:@"NSString"]) {
|
||||||
|
return [NSString stringWithString:data];
|
||||||
|
}
|
||||||
|
else if ([class isEqualToString:@"NSDate"]) {
|
||||||
|
return [NSDate dateWithISO8601String:data];
|
||||||
|
}
|
||||||
|
else if ([class isEqualToString:@"NSNumber"]) {
|
||||||
|
// NSNumber from NSNumber
|
||||||
|
if ([data isKindOfClass:[NSNumber class]]) {
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
else if ([data isKindOfClass:[NSString class]]) {
|
||||||
|
// NSNumber (NSCFBoolean) from NSString
|
||||||
|
if ([[data lowercaseString] isEqualToString:@"true"] || [[data lowercaseString] isEqualToString:@"false"]) {
|
||||||
|
return [NSNumber numberWithBool:[data boolValue]];
|
||||||
|
// NSNumber from NSString
|
||||||
|
} else {
|
||||||
|
NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
|
||||||
|
formatter.numberStyle = NSNumberFormatterDecimalStyle;
|
||||||
|
return [formatter numberFromString:data];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// model
|
||||||
|
Class ModelClass = NSClassFromString(class);
|
||||||
|
if ([ModelClass instancesRespondToSelector:@selector(initWithDictionary:error:)]) {
|
||||||
|
return [[ModelClass alloc] initWithDictionary:data error:nil];
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
|
||||||
|
#pragma mark - Operation Methods
|
||||||
|
|
||||||
|
- (void) operationWithCompletionBlock: (NSURLRequest *)request
|
||||||
|
requestId: (NSNumber *) requestId
|
||||||
|
completionBlock: (void (^)(id, NSError *))completionBlock {
|
||||||
|
AFHTTPRequestOperation *op = [self HTTPRequestOperationWithRequest:request
|
||||||
|
success:^(AFHTTPRequestOperation *operation, id response) {
|
||||||
|
if([self executeRequestWithId:requestId]) {
|
||||||
|
if([[{{classPrefix}}Configuration sharedConfig] debug]) {
|
||||||
|
[self logResponse:operation forRequest:request error:nil];
|
||||||
|
}
|
||||||
|
completionBlock(response, nil);
|
||||||
|
}
|
||||||
|
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
|
||||||
|
if([self executeRequestWithId:requestId]) {
|
||||||
|
NSMutableDictionary *userInfo = [error.userInfo mutableCopy];
|
||||||
|
if(operation.responseObject) {
|
||||||
|
// Add in the (parsed) response body.
|
||||||
|
userInfo[{{classPrefix}}ResponseObjectErrorKey] = operation.responseObject;
|
||||||
|
}
|
||||||
|
NSError *augmentedError = [error initWithDomain:error.domain code:error.code userInfo:userInfo];
|
||||||
|
|
||||||
|
if([[{{classPrefix}}Configuration sharedConfig] debug])
|
||||||
|
[self logResponse:nil forRequest:request error:augmentedError];
|
||||||
|
completionBlock(nil, augmentedError);
|
||||||
|
}
|
||||||
|
}];
|
||||||
|
|
||||||
|
[self.operationQueue addOperation:op];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) downloadOperationWithCompletionBlock: (NSURLRequest *)request
|
||||||
|
requestId: (NSNumber *) requestId
|
||||||
|
completionBlock: (void (^)(id, NSError *))completionBlock {
|
||||||
|
AFHTTPRequestOperation *op = [self HTTPRequestOperationWithRequest:request
|
||||||
|
success:^(AFHTTPRequestOperation *operation, id responseObject) {
|
||||||
|
{{classPrefix}}Configuration *config = [{{classPrefix}}Configuration sharedConfig];
|
||||||
|
NSString *directory = nil;
|
||||||
|
if (config.tempFolderPath) {
|
||||||
|
directory = config.tempFolderPath;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
directory = NSTemporaryDirectory();
|
||||||
|
}
|
||||||
|
|
||||||
|
NSDictionary *headers = operation.response.allHeaderFields;
|
||||||
|
NSString *filename = nil;
|
||||||
|
if ([headers objectForKey:@"Content-Disposition"]) {
|
||||||
|
|
||||||
|
NSString *pattern = @"filename=['\"]?([^'\"\\s]+)['\"]?";
|
||||||
|
NSRegularExpression *regexp = [NSRegularExpression regularExpressionWithPattern:pattern
|
||||||
|
options:NSRegularExpressionCaseInsensitive
|
||||||
|
error:nil];
|
||||||
|
NSString *contentDispositionHeader = [headers objectForKey:@"Content-Disposition"];
|
||||||
|
NSTextCheckingResult *match = [regexp firstMatchInString:contentDispositionHeader
|
||||||
|
options:0
|
||||||
|
range:NSMakeRange(0, [contentDispositionHeader length])];
|
||||||
|
filename = [contentDispositionHeader substringWithRange:[match rangeAtIndex:1]];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
filename = [NSString stringWithFormat:@"%@", [[NSProcessInfo processInfo] globallyUniqueString]];
|
||||||
|
}
|
||||||
|
|
||||||
|
NSString *filepath = [directory stringByAppendingPathComponent:filename];
|
||||||
|
NSURL *file = [NSURL fileURLWithPath:filepath];
|
||||||
|
|
||||||
|
[operation.responseData writeToURL:file atomically:YES];
|
||||||
|
completionBlock(file, nil);
|
||||||
|
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
|
||||||
|
|
||||||
|
if ([self executeRequestWithId:requestId]) {
|
||||||
|
NSMutableDictionary *userInfo = [error.userInfo mutableCopy];
|
||||||
|
if (operation.responseObject) {
|
||||||
|
userInfo[{{classPrefix}}ResponseObjectErrorKey] = operation.responseObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
NSError *augmentedError = [error initWithDomain:error.domain code:error.code userInfo:userInfo];
|
||||||
|
|
||||||
|
if ([[{{classPrefix}}Configuration sharedConfig] debug]) {
|
||||||
|
[self logResponse:nil forRequest:request error:augmentedError];
|
||||||
|
}
|
||||||
|
|
||||||
|
completionBlock(nil, augmentedError);
|
||||||
|
}
|
||||||
|
}];
|
||||||
|
|
||||||
|
[self.operationQueue addOperation:op];
|
||||||
|
}
|
||||||
|
|
||||||
|
#pragma mark - Perform Request Methods
|
||||||
|
|
||||||
|
-(NSNumber*) requestWithCompletionBlock: (NSString*) path
|
||||||
|
method: (NSString*) method
|
||||||
|
queryParams: (NSDictionary*) queryParams
|
||||||
|
formParams: (NSDictionary *) formParams
|
||||||
|
files: (NSDictionary *) files
|
||||||
|
body: (id) body
|
||||||
|
headerParams: (NSDictionary*) headerParams
|
||||||
|
authSettings: (NSArray *) authSettings
|
||||||
|
requestContentType: (NSString*) requestContentType
|
||||||
|
responseContentType: (NSString*) responseContentType
|
||||||
|
responseType: (NSString *) responseType
|
||||||
|
completionBlock: (void (^)(id, NSError *))completionBlock {
|
||||||
|
// setting request serializer
|
||||||
|
if ([requestContentType isEqualToString:@"application/json"]) {
|
||||||
|
self.requestSerializer = [{{classPrefix}}JSONRequestSerializer serializer];
|
||||||
|
}
|
||||||
|
else if ([requestContentType isEqualToString:@"application/x-www-form-urlencoded"]) {
|
||||||
|
self.requestSerializer = [AFHTTPRequestSerializer serializer];
|
||||||
|
}
|
||||||
|
else if ([requestContentType isEqualToString:@"multipart/form-data"]) {
|
||||||
|
self.requestSerializer = [AFHTTPRequestSerializer serializer];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
NSAssert(false, @"unsupport request type %@", requestContentType);
|
||||||
|
}
|
||||||
|
|
||||||
|
// setting response serializer
|
||||||
|
if ([responseContentType isEqualToString:@"application/json"]) {
|
||||||
|
self.responseSerializer = [{{classPrefix}}JSONResponseSerializer serializer];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
self.responseSerializer = [AFHTTPResponseSerializer serializer];
|
||||||
|
}
|
||||||
|
|
||||||
|
// auth setting
|
||||||
|
[self updateHeaderParams:&headerParams queryParams:&queryParams WithAuthSettings:authSettings];
|
||||||
|
|
||||||
|
NSMutableURLRequest * request = nil;
|
||||||
|
|
||||||
|
NSString* pathWithQueryParams = [self pathWithQueryParamsToString:path queryParams:queryParams];
|
||||||
|
if ([pathWithQueryParams hasPrefix:@"/"]) {
|
||||||
|
pathWithQueryParams = [pathWithQueryParams substringFromIndex:1];
|
||||||
|
}
|
||||||
|
|
||||||
|
NSString* urlString = [[NSURL URLWithString:pathWithQueryParams relativeToURL:self.baseURL] absoluteString];
|
||||||
|
if (files.count > 0) {
|
||||||
|
request = [self.requestSerializer multipartFormRequestWithMethod:@"POST"
|
||||||
|
URLString:urlString
|
||||||
|
parameters:nil
|
||||||
|
constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
|
||||||
|
[formParams enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
|
||||||
|
NSData *data = [obj dataUsingEncoding:NSUTF8StringEncoding];
|
||||||
|
[formData appendPartWithFormData:data name:key];
|
||||||
|
}];
|
||||||
|
[files enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
|
||||||
|
NSURL *filePath = (NSURL *)obj;
|
||||||
|
[formData appendPartWithFileURL:filePath name:key error:nil];
|
||||||
|
}];
|
||||||
|
} error:nil];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (formParams) {
|
||||||
|
request = [self.requestSerializer requestWithMethod:method
|
||||||
|
URLString:urlString
|
||||||
|
parameters:formParams
|
||||||
|
error:nil];
|
||||||
|
}
|
||||||
|
if (body) {
|
||||||
|
request = [self.requestSerializer requestWithMethod:method
|
||||||
|
URLString:urlString
|
||||||
|
parameters:body
|
||||||
|
error:nil];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOL hasHeaderParams = false;
|
||||||
|
if(headerParams != nil && [headerParams count] > 0) {
|
||||||
|
hasHeaderParams = true;
|
||||||
|
}
|
||||||
|
if(offlineState) {
|
||||||
|
NSLog(@"%@ cache forced", path);
|
||||||
|
[request setCachePolicy:NSURLRequestReturnCacheDataDontLoad];
|
||||||
|
}
|
||||||
|
else if(!hasHeaderParams && [method isEqualToString:@"GET"] && cacheEnabled) {
|
||||||
|
NSLog(@"%@ cache enabled", path);
|
||||||
|
[request setCachePolicy:NSURLRequestUseProtocolCachePolicy];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
NSLog(@"%@ cache disabled", path);
|
||||||
|
[request setCachePolicy:NSURLRequestReloadIgnoringLocalCacheData];
|
||||||
|
}
|
||||||
|
|
||||||
|
if(hasHeaderParams){
|
||||||
|
for(NSString * key in [headerParams keyEnumerator]){
|
||||||
|
[request setValue:[headerParams valueForKey:key] forHTTPHeaderField:key];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
[self.requestSerializer setValue:responseContentType forHTTPHeaderField:@"Accept"];
|
||||||
|
|
||||||
|
|
||||||
|
// Always disable cookies!
|
||||||
|
[request setHTTPShouldHandleCookies:NO];
|
||||||
|
|
||||||
|
NSNumber* requestId = [{{classPrefix}}ApiClient queueRequest];
|
||||||
|
if ([responseType isEqualToString:@"NSURL*"]) {
|
||||||
|
[self downloadOperationWithCompletionBlock:request requestId:requestId completionBlock:^(id data, NSError *error) {
|
||||||
|
completionBlock(data, error);
|
||||||
|
}];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
[self operationWithCompletionBlock:request requestId:requestId completionBlock:^(id data, NSError *error) {
|
||||||
|
completionBlock([self deserialize:data class:responseType], error);
|
||||||
|
}];
|
||||||
|
}
|
||||||
|
return requestId;
|
||||||
|
}
|
||||||
|
|
||||||
|
#pragma mark -
|
||||||
|
|
||||||
|
- (NSString*) pathWithQueryParamsToString:(NSString*) path
|
||||||
|
queryParams:(NSDictionary*) queryParams {
|
||||||
NSString * separator = nil;
|
NSString * separator = nil;
|
||||||
int counter = 0;
|
int counter = 0;
|
||||||
|
|
||||||
@ -323,18 +645,18 @@ static void (^reachabilityChangeBlock)(int);
|
|||||||
- (void) updateHeaderParams:(NSDictionary *__autoreleasing *)headers
|
- (void) updateHeaderParams:(NSDictionary *__autoreleasing *)headers
|
||||||
queryParams:(NSDictionary *__autoreleasing *)querys
|
queryParams:(NSDictionary *__autoreleasing *)querys
|
||||||
WithAuthSettings:(NSArray *)authSettings {
|
WithAuthSettings:(NSArray *)authSettings {
|
||||||
|
|
||||||
if (!authSettings || [authSettings count] == 0) {
|
if (!authSettings || [authSettings count] == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
NSMutableDictionary *headersWithAuth = [NSMutableDictionary dictionaryWithDictionary:*headers];
|
NSMutableDictionary *headersWithAuth = [NSMutableDictionary dictionaryWithDictionary:*headers];
|
||||||
NSMutableDictionary *querysWithAuth = [NSMutableDictionary dictionaryWithDictionary:*querys];
|
NSMutableDictionary *querysWithAuth = [NSMutableDictionary dictionaryWithDictionary:*querys];
|
||||||
|
|
||||||
{{classPrefix}}Configuration *config = [{{classPrefix}}Configuration sharedConfig];
|
{{classPrefix}}Configuration *config = [{{classPrefix}}Configuration sharedConfig];
|
||||||
for (NSString *auth in authSettings) {
|
for (NSString *auth in authSettings) {
|
||||||
NSDictionary *authSetting = [[config authSettings] objectForKey:auth];
|
NSDictionary *authSetting = [[config authSettings] objectForKey:auth];
|
||||||
|
|
||||||
if (authSetting) {
|
if (authSetting) {
|
||||||
if ([authSetting[@"in"] isEqualToString:@"header"]) {
|
if ([authSetting[@"in"] isEqualToString:@"header"]) {
|
||||||
[headersWithAuth setObject:authSetting[@"value"] forKey:authSetting[@"key"]];
|
[headersWithAuth setObject:authSetting[@"value"] forKey:authSetting[@"key"]];
|
||||||
@ -344,341 +666,9 @@ static void (^reachabilityChangeBlock)(int);
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
*headers = [NSDictionary dictionaryWithDictionary:headersWithAuth];
|
*headers = [NSDictionary dictionaryWithDictionary:headersWithAuth];
|
||||||
*querys = [NSDictionary dictionaryWithDictionary:querysWithAuth];
|
*querys = [NSDictionary dictionaryWithDictionary:querysWithAuth];
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma mark - Deserialize methods
|
|
||||||
|
|
||||||
- (id) deserialize:(id) data class:(NSString *) class {
|
|
||||||
NSRegularExpression *regexp = nil;
|
|
||||||
NSTextCheckingResult *match = nil;
|
|
||||||
NSMutableArray *resultArray = nil;
|
|
||||||
NSMutableDictionary *resultDict = nil;
|
|
||||||
NSString *innerType = nil;
|
|
||||||
|
|
||||||
// return nil if data is nil or class is nil
|
|
||||||
if (!data || !class) {
|
|
||||||
return nil;
|
|
||||||
}
|
|
||||||
|
|
||||||
// remove "*" from class, if ends with "*"
|
|
||||||
if ([class hasSuffix:@"*"]) {
|
|
||||||
class = [class substringToIndex:[class length] - 1];
|
|
||||||
}
|
|
||||||
|
|
||||||
// pure object
|
|
||||||
if ([class isEqualToString:@"NSObject"]) {
|
|
||||||
return [[NSObject alloc] init];
|
|
||||||
}
|
|
||||||
|
|
||||||
// list of models
|
|
||||||
NSString *arrayOfModelsPat = @"NSArray<(.+)>";
|
|
||||||
regexp = [NSRegularExpression regularExpressionWithPattern:arrayOfModelsPat
|
|
||||||
options:NSRegularExpressionCaseInsensitive
|
|
||||||
error:nil];
|
|
||||||
|
|
||||||
match = [regexp firstMatchInString:class
|
|
||||||
options:0
|
|
||||||
range:NSMakeRange(0, [class length])];
|
|
||||||
|
|
||||||
if (match) {
|
|
||||||
innerType = [class substringWithRange:[match rangeAtIndex:1]];
|
|
||||||
|
|
||||||
resultArray = [NSMutableArray arrayWithCapacity:[data count]];
|
|
||||||
[data enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
|
|
||||||
[resultArray addObject:[self deserialize:obj class:innerType]];
|
|
||||||
}
|
|
||||||
];
|
|
||||||
|
|
||||||
return resultArray;
|
|
||||||
}
|
|
||||||
|
|
||||||
// list of primitives
|
|
||||||
NSString *arrayOfPrimitivesPat = @"NSArray\\* /\\* (.+) \\*/";
|
|
||||||
regexp = [NSRegularExpression regularExpressionWithPattern:arrayOfPrimitivesPat
|
|
||||||
options:NSRegularExpressionCaseInsensitive
|
|
||||||
error:nil];
|
|
||||||
match = [regexp firstMatchInString:class
|
|
||||||
options:0
|
|
||||||
range:NSMakeRange(0, [class length])];
|
|
||||||
|
|
||||||
if (match) {
|
|
||||||
innerType = [class substringWithRange:[match rangeAtIndex:1]];
|
|
||||||
|
|
||||||
resultArray = [NSMutableArray arrayWithCapacity:[data count]];
|
|
||||||
[data enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
|
|
||||||
[resultArray addObject:[self deserialize:obj class:innerType]];
|
|
||||||
}];
|
|
||||||
|
|
||||||
return resultArray;
|
|
||||||
}
|
|
||||||
|
|
||||||
// map
|
|
||||||
NSString *dictPat = @"NSDictionary\\* /\\* (.+?), (.+) \\*/";
|
|
||||||
regexp = [NSRegularExpression regularExpressionWithPattern:dictPat
|
|
||||||
options:NSRegularExpressionCaseInsensitive
|
|
||||||
error:nil];
|
|
||||||
match = [regexp firstMatchInString:class
|
|
||||||
options:0
|
|
||||||
range:NSMakeRange(0, [class length])];
|
|
||||||
|
|
||||||
if (match) {
|
|
||||||
NSString *valueType = [class substringWithRange:[match rangeAtIndex:2]];
|
|
||||||
|
|
||||||
resultDict = [NSMutableDictionary dictionaryWithCapacity:[data count]];
|
|
||||||
[data enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
|
|
||||||
[resultDict setValue:[self deserialize:obj class:valueType] forKey:key];
|
|
||||||
}];
|
|
||||||
|
|
||||||
return resultDict;
|
|
||||||
}
|
|
||||||
|
|
||||||
// primitives
|
|
||||||
NSArray *primitiveTypes = @[@"NSString", @"NSDate", @"BOOL", @"NSNumber"];
|
|
||||||
|
|
||||||
if ([primitiveTypes containsObject:class]) {
|
|
||||||
if ([class isEqualToString:@"NSString"]) {
|
|
||||||
return [NSString stringWithString:data];
|
|
||||||
}
|
|
||||||
else if ([class isEqualToString:@"NSDate"]) {
|
|
||||||
return [NSDate dateWithISO8601String:data];
|
|
||||||
}
|
|
||||||
else if ([class isEqualToString:@"BOOL"]) {
|
|
||||||
// Returns YES on encountering one of "Y", "y", "T", "t", or a
|
|
||||||
// digit 1-9—the method ignores any trailing characters
|
|
||||||
// NSString => BOOL => NSNumber
|
|
||||||
return [NSNumber numberWithBool:[data boolValue]];
|
|
||||||
}
|
|
||||||
else if ([class isEqualToString:@"NSNumber"]) {
|
|
||||||
// NSNumber from NSNumber
|
|
||||||
if ([data isKindOfClass:[NSNumber class]]) {
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
// NSNumber from NSString
|
|
||||||
else {
|
|
||||||
NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
|
|
||||||
formatter.numberStyle = NSNumberFormatterDecimalStyle;
|
|
||||||
return [formatter numberFromString:data];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// model
|
|
||||||
Class ModelClass = NSClassFromString(class);
|
|
||||||
if ([ModelClass instancesRespondToSelector:@selector(initWithDictionary:error:)]) {
|
|
||||||
return [[ModelClass alloc] initWithDictionary:data error:nil];
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil;
|
|
||||||
}
|
|
||||||
|
|
||||||
#pragma mark - Operation Methods
|
|
||||||
|
|
||||||
- (void) operationWithCompletionBlock: (NSURLRequest *)request
|
|
||||||
requestId: (NSNumber *) requestId
|
|
||||||
completionBlock: (void (^)(id, NSError *))completionBlock {
|
|
||||||
AFHTTPRequestOperation *op = [self HTTPRequestOperationWithRequest:request
|
|
||||||
success:^(AFHTTPRequestOperation *operation, id response) {
|
|
||||||
if([self executeRequestWithId:requestId]) {
|
|
||||||
if([[{{classPrefix}}Configuration sharedConfig] debug]) {
|
|
||||||
[self logResponse:operation forRequest:request error:nil];
|
|
||||||
}
|
|
||||||
completionBlock(response, nil);
|
|
||||||
}
|
|
||||||
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
|
|
||||||
if([self executeRequestWithId:requestId]) {
|
|
||||||
NSMutableDictionary *userInfo = [error.userInfo mutableCopy];
|
|
||||||
if(operation.responseObject) {
|
|
||||||
// Add in the (parsed) response body.
|
|
||||||
userInfo[{{classPrefix}}ResponseObjectErrorKey] = operation.responseObject;
|
|
||||||
}
|
|
||||||
NSError *augmentedError = [error initWithDomain:error.domain code:error.code userInfo:userInfo];
|
|
||||||
|
|
||||||
if([[{{classPrefix}}Configuration sharedConfig] debug])
|
|
||||||
[self logResponse:nil forRequest:request error:augmentedError];
|
|
||||||
completionBlock(nil, augmentedError);
|
|
||||||
}
|
|
||||||
}];
|
|
||||||
|
|
||||||
[self.operationQueue addOperation:op];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void) downloadOperationWithCompletionBlock: (NSURLRequest *)request
|
|
||||||
requestId: (NSNumber *) requestId
|
|
||||||
completionBlock: (void (^)(id, NSError *))completionBlock {
|
|
||||||
AFHTTPRequestOperation *op = [self HTTPRequestOperationWithRequest:request
|
|
||||||
success:^(AFHTTPRequestOperation *operation, id responseObject) {
|
|
||||||
{{classPrefix}}Configuration *config = [{{classPrefix}}Configuration sharedConfig];
|
|
||||||
NSString *directory = nil;
|
|
||||||
if (config.tempFolderPath) {
|
|
||||||
directory = config.tempFolderPath;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
directory = NSTemporaryDirectory();
|
|
||||||
}
|
|
||||||
|
|
||||||
NSDictionary *headers = operation.response.allHeaderFields;
|
|
||||||
NSString *filename = nil;
|
|
||||||
if ([headers objectForKey:@"Content-Disposition"]) {
|
|
||||||
|
|
||||||
NSString *pattern = @"filename=['\"]?([^'\"\\s]+)['\"]?";
|
|
||||||
NSRegularExpression *regexp = [NSRegularExpression regularExpressionWithPattern:pattern
|
|
||||||
options:NSRegularExpressionCaseInsensitive
|
|
||||||
error:nil];
|
|
||||||
NSString *contentDispositionHeader = [headers objectForKey:@"Content-Disposition"];
|
|
||||||
NSTextCheckingResult *match = [regexp firstMatchInString:contentDispositionHeader
|
|
||||||
options:0
|
|
||||||
range:NSMakeRange(0, [contentDispositionHeader length])];
|
|
||||||
filename = [contentDispositionHeader substringWithRange:[match rangeAtIndex:1]];
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
filename = [NSString stringWithFormat:@"%@", [[NSProcessInfo processInfo] globallyUniqueString]];
|
|
||||||
}
|
|
||||||
|
|
||||||
NSString *filepath = [directory stringByAppendingPathComponent:filename];
|
|
||||||
NSURL *file = [NSURL fileURLWithPath:filepath];
|
|
||||||
|
|
||||||
[operation.responseData writeToURL:file atomically:YES];
|
|
||||||
completionBlock(file, nil);
|
|
||||||
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
|
|
||||||
|
|
||||||
if ([self executeRequestWithId:requestId]) {
|
|
||||||
NSMutableDictionary *userInfo = [error.userInfo mutableCopy];
|
|
||||||
if (operation.responseObject) {
|
|
||||||
userInfo[{{classPrefix}}ResponseObjectErrorKey] = operation.responseObject;
|
|
||||||
}
|
|
||||||
|
|
||||||
NSError *augmentedError = [error initWithDomain:error.domain code:error.code userInfo:userInfo];
|
|
||||||
|
|
||||||
if ([[{{classPrefix}}Configuration sharedConfig] debug]) {
|
|
||||||
[self logResponse:nil forRequest:request error:augmentedError];
|
|
||||||
}
|
|
||||||
|
|
||||||
completionBlock(nil, augmentedError);
|
|
||||||
}
|
|
||||||
}];
|
|
||||||
|
|
||||||
[self.operationQueue addOperation:op];
|
|
||||||
}
|
|
||||||
|
|
||||||
#pragma mark - Perform Request Methods
|
|
||||||
|
|
||||||
-(NSNumber*) requestWithCompletionBlock: (NSString*) path
|
|
||||||
method: (NSString*) method
|
|
||||||
queryParams: (NSDictionary*) queryParams
|
|
||||||
formParams: (NSDictionary *) formParams
|
|
||||||
files: (NSDictionary *) files
|
|
||||||
body: (id) body
|
|
||||||
headerParams: (NSDictionary*) headerParams
|
|
||||||
authSettings: (NSArray *) authSettings
|
|
||||||
requestContentType: (NSString*) requestContentType
|
|
||||||
responseContentType: (NSString*) responseContentType
|
|
||||||
responseType: (NSString *) responseType
|
|
||||||
completionBlock: (void (^)(id, NSError *))completionBlock {
|
|
||||||
// setting request serializer
|
|
||||||
if ([requestContentType isEqualToString:@"application/json"]) {
|
|
||||||
self.requestSerializer = [{{classPrefix}}JSONRequestSerializer serializer];
|
|
||||||
}
|
|
||||||
else if ([requestContentType isEqualToString:@"application/x-www-form-urlencoded"]) {
|
|
||||||
self.requestSerializer = [AFHTTPRequestSerializer serializer];
|
|
||||||
}
|
|
||||||
else if ([requestContentType isEqualToString:@"multipart/form-data"]) {
|
|
||||||
self.requestSerializer = [AFHTTPRequestSerializer serializer];
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
NSAssert(false, @"unsupport request type %@", requestContentType);
|
|
||||||
}
|
|
||||||
|
|
||||||
// setting response serializer
|
|
||||||
if ([responseContentType isEqualToString:@"application/json"]) {
|
|
||||||
self.responseSerializer = [{{classPrefix}}JSONResponseSerializer serializer];
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
self.responseSerializer = [AFHTTPResponseSerializer serializer];
|
|
||||||
}
|
|
||||||
|
|
||||||
// auth setting
|
|
||||||
[self updateHeaderParams:&headerParams queryParams:&queryParams WithAuthSettings:authSettings];
|
|
||||||
|
|
||||||
NSMutableURLRequest * request = nil;
|
|
||||||
NSString* pathWithQueryParams = [self pathWithQueryParamsToString:path queryParams:queryParams];
|
|
||||||
NSString* urlString = [[NSURL URLWithString:pathWithQueryParams relativeToURL:self.baseURL] absoluteString];
|
|
||||||
if (files.count > 0) {
|
|
||||||
request = [self.requestSerializer multipartFormRequestWithMethod:@"POST"
|
|
||||||
URLString:urlString
|
|
||||||
parameters:nil
|
|
||||||
constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
|
|
||||||
[formParams enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
|
|
||||||
NSData *data = [obj dataUsingEncoding:NSUTF8StringEncoding];
|
|
||||||
[formData appendPartWithFormData:data name:key];
|
|
||||||
}];
|
|
||||||
[files enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
|
|
||||||
NSURL *filePath = (NSURL *)obj;
|
|
||||||
[formData appendPartWithFileURL:filePath name:key error:nil];
|
|
||||||
}];
|
|
||||||
} error:nil];
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if (formParams) {
|
|
||||||
request = [self.requestSerializer requestWithMethod:method
|
|
||||||
URLString:urlString
|
|
||||||
parameters:formParams
|
|
||||||
error:nil];
|
|
||||||
}
|
|
||||||
if (body) {
|
|
||||||
request = [self.requestSerializer requestWithMethod:method
|
|
||||||
URLString:urlString
|
|
||||||
parameters:body
|
|
||||||
error:nil];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
BOOL hasHeaderParams = false;
|
|
||||||
if(headerParams != nil && [headerParams count] > 0) {
|
|
||||||
hasHeaderParams = true;
|
|
||||||
}
|
|
||||||
if(offlineState) {
|
|
||||||
NSLog(@"%@ cache forced", path);
|
|
||||||
[request setCachePolicy:NSURLRequestReturnCacheDataDontLoad];
|
|
||||||
}
|
|
||||||
else if(!hasHeaderParams && [method isEqualToString:@"GET"] && cacheEnabled) {
|
|
||||||
NSLog(@"%@ cache enabled", path);
|
|
||||||
[request setCachePolicy:NSURLRequestUseProtocolCachePolicy];
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
NSLog(@"%@ cache disabled", path);
|
|
||||||
[request setCachePolicy:NSURLRequestReloadIgnoringLocalCacheData];
|
|
||||||
}
|
|
||||||
|
|
||||||
if(hasHeaderParams){
|
|
||||||
for(NSString * key in [headerParams keyEnumerator]){
|
|
||||||
[request setValue:[headerParams valueForKey:key] forHTTPHeaderField:key];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
[self.requestSerializer setValue:responseContentType forHTTPHeaderField:@"Accept"];
|
|
||||||
|
|
||||||
|
|
||||||
// Always disable cookies!
|
|
||||||
[request setHTTPShouldHandleCookies:NO];
|
|
||||||
|
|
||||||
NSNumber* requestId = [{{classPrefix}}ApiClient queueRequest];
|
|
||||||
if ([responseType isEqualToString:@"NSURL*"]) {
|
|
||||||
[self downloadOperationWithCompletionBlock:request requestId:requestId completionBlock:^(id data, NSError *error) {
|
|
||||||
completionBlock(data, error);
|
|
||||||
}];
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
[self operationWithCompletionBlock:request requestId:requestId completionBlock:^(id data, NSError *error) {
|
|
||||||
completionBlock([self deserialize:data class:responseType], error);
|
|
||||||
}];
|
|
||||||
}
|
|
||||||
return requestId;
|
|
||||||
}
|
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -15,6 +15,8 @@
|
|||||||
{{#models}}{{#model}}#import "{{classname}}.h"
|
{{#models}}{{#model}}#import "{{classname}}.h"
|
||||||
{{/model}}{{/models}}
|
{{/model}}{{/models}}
|
||||||
|
|
||||||
|
@class {{classPrefix}}Configuration;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A key for `NSError` user info dictionaries.
|
* A key for `NSError` user info dictionaries.
|
||||||
*
|
*
|
||||||
@ -29,22 +31,6 @@ extern NSString *const {{classPrefix}}ResponseObjectErrorKey;
|
|||||||
@property(nonatomic, assign) NSTimeInterval timeoutInterval;
|
@property(nonatomic, assign) NSTimeInterval timeoutInterval;
|
||||||
@property(nonatomic, readonly) NSOperationQueue* queue;
|
@property(nonatomic, readonly) NSOperationQueue* queue;
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the Api Client instance from pool
|
|
||||||
*
|
|
||||||
* @param baseUrl The base url of api client.
|
|
||||||
*
|
|
||||||
* @return The {{classPrefix}}ApiClient instance.
|
|
||||||
*/
|
|
||||||
+({{classPrefix}}ApiClient *)sharedClientFromPool:(NSString *)baseUrl;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the operations queue
|
|
||||||
*
|
|
||||||
* @return The `shardQueue` static variable.
|
|
||||||
*/
|
|
||||||
+(NSOperationQueue*) sharedQueue;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clears Cache
|
* Clears Cache
|
||||||
*/
|
*/
|
||||||
@ -116,11 +102,9 @@ extern NSString *const {{classPrefix}}ResponseObjectErrorKey;
|
|||||||
+(void) setReachabilityChangeBlock:(void(^)(int))changeBlock;
|
+(void) setReachabilityChangeBlock:(void(^)(int))changeBlock;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the client reachability strategy
|
* Sets the api client reachability strategy
|
||||||
*
|
|
||||||
* @param host The host of {{classPrefix}}ApiClient.
|
|
||||||
*/
|
*/
|
||||||
+(void) configureCacheReachibilityForHost:(NSString*)host;
|
- (void)configureCacheReachibility;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Detects Accept header from accepts NSArray
|
* Detects Accept header from accepts NSArray
|
||||||
|
@ -25,6 +25,8 @@
|
|||||||
- (instancetype) init {
|
- (instancetype) init {
|
||||||
self = [super init];
|
self = [super init];
|
||||||
if (self) {
|
if (self) {
|
||||||
|
self.apiClient = nil;
|
||||||
|
self.host = @"{{basePath}}";
|
||||||
self.username = @"";
|
self.username = @"";
|
||||||
self.password = @"";
|
self.password = @"";
|
||||||
self.tempFolderPath = nil;
|
self.tempFolderPath = nil;
|
||||||
|
@ -1,13 +1,26 @@
|
|||||||
#import <Foundation/Foundation.h>
|
#import <Foundation/Foundation.h>
|
||||||
|
#import "{{classPrefix}}ApiClient.h"
|
||||||
|
|
||||||
/** The `{{classPrefix}}Configuration` class manages the configurations for the sdk.
|
/** The `{{classPrefix}}Configuration` class manages the configurations for the sdk.
|
||||||
*
|
*
|
||||||
* NOTE: This class is auto generated by the swagger code generator program.
|
* NOTE: This class is auto generated by the swagger code generator program.
|
||||||
* https://github.com/swagger-api/swagger-codegen
|
* https://github.com/swagger-api/swagger-codegen
|
||||||
* Do not edit the class manually.
|
* Do not edit the class manually.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@class {{classPrefix}}ApiClient;
|
||||||
|
|
||||||
@interface {{classPrefix}}Configuration : NSObject
|
@interface {{classPrefix}}Configuration : NSObject
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default api client
|
||||||
|
*/
|
||||||
|
@property (nonatomic) {{classPrefix}}ApiClient *apiClient;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default base url
|
||||||
|
*/
|
||||||
|
@property (nonatomic) NSString *host;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Api key values for Api Key type Authentication
|
* Api key values for Api Key type Authentication
|
||||||
|
@ -12,6 +12,10 @@ To install it, put the API client library in your project and then simply add th
|
|||||||
pod "{{podName}}", :path => "/path/to/lib"
|
pod "{{podName}}", :path => "/path/to/lib"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Recommendation
|
||||||
|
|
||||||
|
It's recommended to create an instance of ApiClient per thread in a multithreaded environment to avoid any potential issue.
|
||||||
|
|
||||||
## Author
|
## Author
|
||||||
|
|
||||||
{{#apiInfo}}{{#apis}}{{^hasMore}}{{infoEmail}}
|
{{#apiInfo}}{{#apis}}{{^hasMore}}{{infoEmail}}
|
||||||
|
@ -11,14 +11,16 @@
|
|||||||
|
|
||||||
@implementation {{classname}}
|
@implementation {{classname}}
|
||||||
|
|
||||||
static NSString * basePath = @"{{basePath}}";
|
|
||||||
|
|
||||||
#pragma mark - Initialize methods
|
#pragma mark - Initialize methods
|
||||||
|
|
||||||
- (id) init {
|
- (id) init {
|
||||||
self = [super init];
|
self = [super init];
|
||||||
if (self) {
|
if (self) {
|
||||||
self.apiClient = [{{classPrefix}}ApiClient sharedClientFromPool:basePath];
|
{{classPrefix}}Configuration *config = [{{classPrefix}}Configuration sharedConfig];
|
||||||
|
if (config.apiClient == nil) {
|
||||||
|
config.apiClient = [[{{classPrefix}}ApiClient alloc] init];
|
||||||
|
}
|
||||||
|
self.apiClient = config.apiClient;
|
||||||
self.defaultHeaders = [NSMutableDictionary dictionary];
|
self.defaultHeaders = [NSMutableDictionary dictionary];
|
||||||
}
|
}
|
||||||
return self;
|
return self;
|
||||||
@ -27,12 +29,7 @@ static NSString * basePath = @"{{basePath}}";
|
|||||||
- (id) initWithApiClient:({{classPrefix}}ApiClient *)apiClient {
|
- (id) initWithApiClient:({{classPrefix}}ApiClient *)apiClient {
|
||||||
self = [super init];
|
self = [super init];
|
||||||
if (self) {
|
if (self) {
|
||||||
if (apiClient) {
|
self.apiClient = apiClient;
|
||||||
self.apiClient = apiClient;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
self.apiClient = [{{classPrefix}}ApiClient sharedClientFromPool:basePath];
|
|
||||||
}
|
|
||||||
self.defaultHeaders = [NSMutableDictionary dictionary];
|
self.defaultHeaders = [NSMutableDictionary dictionary];
|
||||||
}
|
}
|
||||||
return self;
|
return self;
|
||||||
@ -50,14 +47,6 @@ static NSString * basePath = @"{{basePath}}";
|
|||||||
return singletonAPI;
|
return singletonAPI;
|
||||||
}
|
}
|
||||||
|
|
||||||
+(void) setBasePath:(NSString*)path {
|
|
||||||
basePath = path;
|
|
||||||
}
|
|
||||||
|
|
||||||
+(NSString*) getBasePath {
|
|
||||||
return basePath;
|
|
||||||
}
|
|
||||||
|
|
||||||
-(void) addHeader:(NSString*)value forKey:(NSString*)key {
|
-(void) addHeader:(NSString*)value forKey:(NSString*)key {
|
||||||
[self.defaultHeaders setValue:value forKey:key];
|
[self.defaultHeaders setValue:value forKey:key];
|
||||||
}
|
}
|
||||||
@ -93,13 +82,14 @@ static NSString * basePath = @"{{basePath}}";
|
|||||||
}
|
}
|
||||||
{{/required}}{{/allParams}}
|
{{/required}}{{/allParams}}
|
||||||
|
|
||||||
NSMutableString* requestUrl = [NSMutableString stringWithFormat:@"%@{{path}}", basePath];
|
NSMutableString* resourcePath = [NSMutableString stringWithFormat:@"{{path}}"];
|
||||||
|
|
||||||
// remove format in URL if needed
|
// remove format in URL if needed
|
||||||
if ([requestUrl rangeOfString:@".{format}"].location != NSNotFound)
|
if ([resourcePath rangeOfString:@".{format}"].location != NSNotFound) {
|
||||||
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:@".{format}"] withString:@".json"];
|
[resourcePath replaceCharactersInRange: [resourcePath rangeOfString:@".{format}"] withString:@".json"];
|
||||||
|
}
|
||||||
{{#pathParams}}[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:[NSString stringWithFormat:@"%@%@%@", @"{", @"{{baseName}}", @"}"]] withString: [{{classPrefix}}ApiClient escape:{{paramName}}]];
|
|
||||||
|
{{#pathParams}}[resourcePath replaceCharactersInRange: [resourcePath rangeOfString:[NSString stringWithFormat:@"%@%@%@", @"{", @"{{baseName}}", @"}"]] withString: [{{classPrefix}}ApiClient escape:{{paramName}}]];
|
||||||
{{/pathParams}}
|
{{/pathParams}}
|
||||||
|
|
||||||
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
|
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
|
||||||
@ -175,7 +165,7 @@ static NSString * basePath = @"{{basePath}}";
|
|||||||
}
|
}
|
||||||
{{/requiredParams}}
|
{{/requiredParams}}
|
||||||
{{/requiredParamCount}}
|
{{/requiredParamCount}}
|
||||||
return [self.apiClient requestWithCompletionBlock: requestUrl
|
return [self.apiClient requestWithCompletionBlock: resourcePath
|
||||||
method: @"{{httpMethod}}"
|
method: @"{{httpMethod}}"
|
||||||
queryParams: queryParams
|
queryParams: queryParams
|
||||||
formParams: formParams
|
formParams: formParams
|
||||||
|
@ -20,8 +20,6 @@
|
|||||||
-(void) addHeader:(NSString*)value forKey:(NSString*)key;
|
-(void) addHeader:(NSString*)value forKey:(NSString*)key;
|
||||||
-(unsigned long) requestQueueSize;
|
-(unsigned long) requestQueueSize;
|
||||||
+({{classname}}*) apiWithHeader:(NSString*)headerValue key:(NSString*)key;
|
+({{classname}}*) apiWithHeader:(NSString*)headerValue key:(NSString*)key;
|
||||||
+(void) setBasePath:(NSString*)basePath;
|
|
||||||
+(NSString*) getBasePath;
|
|
||||||
{{#operation}}
|
{{#operation}}
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
|
@ -89,7 +89,7 @@ class Configuration
|
|||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $host = 'http://localhost';
|
protected $host = '{{basePath}}';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Timeout (second) of the HTTP request, by default set to 0, no timeout
|
* Timeout (second) of the HTTP request, by default set to 0, no timeout
|
||||||
@ -103,7 +103,7 @@ class Configuration
|
|||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $userAgent = "PHP-Swagger";
|
protected $userAgent = "PHP-Swagger/{{artifactVersion}}";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Debug switch (default set to false)
|
* Debug switch (default set to false)
|
||||||
|
@ -247,12 +247,12 @@ class ApiClient(object):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
if type(klass) == str:
|
if type(klass) == str:
|
||||||
if 'list[' in klass:
|
if klass.startswith('list['):
|
||||||
sub_kls = re.match('list\[(.*)\]', klass).group(1)
|
sub_kls = re.match('list\[(.*)\]', klass).group(1)
|
||||||
return [self.__deserialize(sub_data, sub_kls)
|
return [self.__deserialize(sub_data, sub_kls)
|
||||||
for sub_data in data]
|
for sub_data in data]
|
||||||
|
|
||||||
if 'dict(' in klass:
|
if klass.startswith('dict('):
|
||||||
sub_kls = re.match('dict\(([^,]*), (.*)\)', klass).group(2)
|
sub_kls = re.match('dict\(([^,]*), (.*)\)', klass).group(2)
|
||||||
return {k: self.__deserialize(v, sub_kls)
|
return {k: self.__deserialize(v, sub_kls)
|
||||||
for k, v in iteritems(data)}
|
for k, v in iteritems(data)}
|
||||||
|
@ -19,7 +19,13 @@ Copyright 2015 SmartBear Software
|
|||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
import base64
|
import base64
|
||||||
import urllib3
|
import urllib3
|
||||||
import httplib
|
|
||||||
|
try:
|
||||||
|
import httplib
|
||||||
|
except ImportError:
|
||||||
|
# python3
|
||||||
|
import http.client as httplib
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
@ -216,10 +216,10 @@ class ApiException(Exception):
|
|||||||
error_message = "({0})\n"\
|
error_message = "({0})\n"\
|
||||||
"Reason: {1}\n".format(self.status, self.reason)
|
"Reason: {1}\n".format(self.status, self.reason)
|
||||||
if self.headers:
|
if self.headers:
|
||||||
error_message += "HTTP response headers: {0}".format(self.headers)
|
error_message += "HTTP response headers: {0}\n".format(self.headers)
|
||||||
|
|
||||||
if self.body:
|
if self.body:
|
||||||
error_message += "HTTP response body: {0}".format(self.body)
|
error_message += "HTTP response body: {0}\n".format(self.body)
|
||||||
|
|
||||||
return error_message
|
return error_message
|
||||||
|
|
||||||
|
@ -31,4 +31,55 @@ class JavaModelEnumTest extends FlatSpec with Matchers {
|
|||||||
enumVar.baseType should be("String")
|
enumVar.baseType should be("String")
|
||||||
enumVar.isEnum should equal(true)
|
enumVar.isEnum should equal(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
it should "not override identical parent enums" in {
|
||||||
|
|
||||||
|
val identicalEnumProperty = new StringProperty()
|
||||||
|
identicalEnumProperty.setEnum(List("VALUE1", "VALUE2", "VALUE3").asJava)
|
||||||
|
|
||||||
|
val subEnumProperty = new StringProperty()
|
||||||
|
subEnumProperty.setEnum(List("SUB1", "SUB2", "SUB3").asJava)
|
||||||
|
|
||||||
|
// Add one enum ptoperty to the parent
|
||||||
|
val parentProperties = new java.util.HashMap[String, Property]()
|
||||||
|
parentProperties.put("sharedThing", identicalEnumProperty)
|
||||||
|
|
||||||
|
// Add TWO enums to the subType model; one of which is identical to the one in parent class
|
||||||
|
val subProperties = new java.util.HashMap[String, Property]()
|
||||||
|
subProperties.put("sharedThing", identicalEnumProperty)
|
||||||
|
subProperties.put("unsharedThing", identicalEnumProperty)
|
||||||
|
|
||||||
|
val parentModel = new ModelImpl();
|
||||||
|
parentModel.setProperties(parentProperties);
|
||||||
|
parentModel.name("parentModel");
|
||||||
|
|
||||||
|
val subModel = new ModelImpl();
|
||||||
|
subModel.setProperties(subProperties);
|
||||||
|
subModel.name("subModel");
|
||||||
|
|
||||||
|
val model = new ComposedModel()
|
||||||
|
.parent(new RefModel(parentModel.getName()))
|
||||||
|
.child(subModel)
|
||||||
|
.interfaces(new java.util.ArrayList[RefModel]())
|
||||||
|
|
||||||
|
val codegen = new JavaClientCodegen()
|
||||||
|
val allModels = new java.util.HashMap[String, Model]()
|
||||||
|
allModels.put(codegen.toModelName(parentModel.getName()), parentModel)
|
||||||
|
allModels.put(codegen.toModelName(subModel.getName()), subModel)
|
||||||
|
|
||||||
|
val cm = codegen.fromModel("sample", model, allModels)
|
||||||
|
|
||||||
|
cm.name should be("sample")
|
||||||
|
cm.classname should be("Sample")
|
||||||
|
cm.parent should be("ParentModel")
|
||||||
|
cm.imports.asScala should be(Set("ParentModel"))
|
||||||
|
|
||||||
|
// Assert that only the unshared/uninherited enum remains
|
||||||
|
cm.vars.size should be (1)
|
||||||
|
val enumVar = cm.vars.get(0)
|
||||||
|
enumVar.baseName should be("unsharedThing")
|
||||||
|
enumVar.datatype should be("String")
|
||||||
|
enumVar.datatypeWithEnum should be("UnsharedThingEnum")
|
||||||
|
enumVar.isEnum should equal(true)
|
||||||
|
}
|
||||||
}
|
}
|
4
pom.xml
4
pom.xml
@ -469,10 +469,10 @@
|
|||||||
</repository>
|
</repository>
|
||||||
</repositories>
|
</repositories>
|
||||||
<properties>
|
<properties>
|
||||||
<swagger-parser-version>1.0.10-SNAPSHOT</swagger-parser-version>
|
<swagger-parser-version>1.0.10</swagger-parser-version>
|
||||||
<scala-version>2.11.1</scala-version>
|
<scala-version>2.11.1</scala-version>
|
||||||
<felix-version>2.3.4</felix-version>
|
<felix-version>2.3.4</felix-version>
|
||||||
<swagger-core-version>1.5.3-SNAPSHOT</swagger-core-version>
|
<swagger-core-version>1.5.4-SNAPSHOT</swagger-core-version>
|
||||||
<scala-test-version>2.1.4</scala-test-version>
|
<scala-test-version>2.1.4</scala-test-version>
|
||||||
<commons-io-version>2.3</commons-io-version>
|
<commons-io-version>2.3</commons-io-version>
|
||||||
<commons-cli-version>1.2</commons-cli-version>
|
<commons-cli-version>1.2</commons-cli-version>
|
||||||
|
@ -1,35 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright 2014 Wordnik, Inc.
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
object FlashPetstoreCodegen extends BasicFlashCodegen {
|
|
||||||
def main(args: Array[String]) = generateClient(args)
|
|
||||||
|
|
||||||
override def packageName = "io.swagger.client"
|
|
||||||
|
|
||||||
// where to write generated code
|
|
||||||
override def destinationDir = destinationRoot + "/src/main/flex"
|
|
||||||
|
|
||||||
override def destinationRoot = "samples/client/petstore/flash"
|
|
||||||
|
|
||||||
// package for models
|
|
||||||
override def modelPackage = Some("com.wordnik.client.model")
|
|
||||||
|
|
||||||
// package for api classes
|
|
||||||
override def apiPackage = Some("com.wordnik.client.api")
|
|
||||||
|
|
||||||
// supporting classes
|
|
||||||
override def supportingFiles = baseSupportingFiles ++ List()
|
|
||||||
}
|
|
@ -1,146 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8" standalone="no"?>
|
|
||||||
<application xmlns="http://ns.adobe.com/air/application/2.0">
|
|
||||||
|
|
||||||
<!-- Adobe AIR Application Descriptor File Template.
|
|
||||||
|
|
||||||
Specifies parameters for identifying, installing, and launching AIR applications.
|
|
||||||
|
|
||||||
xmlns - The Adobe AIR namespace: http://ns.adobe.com/air/application/2.0
|
|
||||||
The last segment of the namespace specifies the version
|
|
||||||
of the AIR runtime required for this application to run.
|
|
||||||
|
|
||||||
minimumPatchLevel - The minimum patch level of the AIR runtime required to run
|
|
||||||
the application. Optional.
|
|
||||||
-->
|
|
||||||
|
|
||||||
<!-- A universally unique application identifier. Must be unique across all AIR applications.
|
|
||||||
Using a reverse DNS-style name as the id is recommended. (Eg. com.example.ExampleApplication.) Required. -->
|
|
||||||
<id>AirExecutorApp</id>
|
|
||||||
|
|
||||||
<!-- Used as the filename for the application. Required. -->
|
|
||||||
<filename>AirExecutorApp</filename>
|
|
||||||
|
|
||||||
<!-- The name that is displayed in the AIR application installer.
|
|
||||||
May have multiple values for each language. See samples or xsd schema file. Optional. -->
|
|
||||||
<name>AirExecutorApp</name>
|
|
||||||
|
|
||||||
<!-- An application version designator (such as "v1", "2.5", or "Alpha 1"). Required. -->
|
|
||||||
<version>v1</version>
|
|
||||||
|
|
||||||
<!-- Description, displayed in the AIR application installer.
|
|
||||||
May have multiple values for each language. See samples or xsd schema file. Optional. -->
|
|
||||||
<!-- <description></description> -->
|
|
||||||
|
|
||||||
<!-- Copyright information. Optional -->
|
|
||||||
<!-- <copyright></copyright> -->
|
|
||||||
|
|
||||||
<!-- Publisher ID. Used if you're updating an application created prior to 1.5.3 -->
|
|
||||||
<!-- <publisherID></publisherID> -->
|
|
||||||
|
|
||||||
<!-- Settings for the application's initial window. Required. -->
|
|
||||||
<initialWindow>
|
|
||||||
<!-- The main SWF or HTML file of the application. Required. -->
|
|
||||||
<!-- Note: In Flash Builder, the SWF reference is set automatically. -->
|
|
||||||
<content>AirExecutorApp.swf</content>
|
|
||||||
|
|
||||||
<!-- The title of the main window. Optional. -->
|
|
||||||
<!-- <title></title> -->
|
|
||||||
|
|
||||||
<!-- The type of system chrome to use (either "standard" or "none"). Optional. Default standard. -->
|
|
||||||
<!-- <systemChrome></systemChrome> -->
|
|
||||||
|
|
||||||
<!-- Whether the window is transparent. Only applicable when systemChrome is none. Optional. Default false. -->
|
|
||||||
<!-- <transparent></transparent> -->
|
|
||||||
|
|
||||||
<!-- Whether the window is initially visible. Optional. Default false. -->
|
|
||||||
<!-- <visible></visible> -->
|
|
||||||
|
|
||||||
<!-- Whether the user can minimize the window. Optional. Default true. -->
|
|
||||||
<!-- <minimizable></minimizable> -->
|
|
||||||
|
|
||||||
<!-- Whether the user can maximize the window. Optional. Default true. -->
|
|
||||||
<!-- <maximizable></maximizable> -->
|
|
||||||
|
|
||||||
<!-- Whether the user can resize the window. Optional. Default true. -->
|
|
||||||
<!-- <resizable></resizable> -->
|
|
||||||
|
|
||||||
<!-- The window's initial width in pixels. Optional. -->
|
|
||||||
<!-- <width></width> -->
|
|
||||||
|
|
||||||
<!-- The window's initial height in pixels. Optional. -->
|
|
||||||
<!-- <height></height> -->
|
|
||||||
|
|
||||||
<!-- The window's initial x position. Optional. -->
|
|
||||||
<!-- <x></x> -->
|
|
||||||
|
|
||||||
<!-- The window's initial y position. Optional. -->
|
|
||||||
<!-- <y></y> -->
|
|
||||||
|
|
||||||
<!-- The window's minimum size, specified as a width/height pair in pixels, such as "400 200". Optional. -->
|
|
||||||
<!-- <minSize></minSize> -->
|
|
||||||
|
|
||||||
<!-- The window's initial maximum size, specified as a width/height pair in pixels, such as "1600 1200". Optional. -->
|
|
||||||
<!-- <maxSize></maxSize> -->
|
|
||||||
</initialWindow>
|
|
||||||
|
|
||||||
<!-- We recommend omitting the supportedProfiles element, -->
|
|
||||||
<!-- which in turn permits your application to be deployed to all -->
|
|
||||||
<!-- devices supported by AIR. If you wish to restrict deployment -->
|
|
||||||
<!-- (i.e., to only mobile devices) then add this element and list -->
|
|
||||||
<!-- only the profiles which your application does support. -->
|
|
||||||
<!-- <supportedProfiles>desktop extendedDesktop mobileDevice extendedMobileDevice</supportedProfiles> -->
|
|
||||||
|
|
||||||
<!-- The subpath of the standard default installation location to use. Optional. -->
|
|
||||||
<!-- <installFolder></installFolder> -->
|
|
||||||
|
|
||||||
<!-- The subpath of the Programs menu to use. (Ignored on operating systems without a Programs menu.) Optional. -->
|
|
||||||
<!-- <programMenuFolder></programMenuFolder> -->
|
|
||||||
|
|
||||||
<!-- The icon the system uses for the application. For at least one resolution,
|
|
||||||
specify the path to a PNG file included in the AIR package. Optional. -->
|
|
||||||
<!-- <icon>
|
|
||||||
<image16x16></image16x16>
|
|
||||||
<image32x32></image32x32>
|
|
||||||
<image48x48></image48x48>
|
|
||||||
<image128x128></image128x128>
|
|
||||||
</icon> -->
|
|
||||||
|
|
||||||
<!-- Whether the application handles the update when a user double-clicks an update version
|
|
||||||
of the AIR file (true), or the default AIR application installer handles the update (false).
|
|
||||||
Optional. Default false. -->
|
|
||||||
<!-- <customUpdateUI></customUpdateUI> -->
|
|
||||||
|
|
||||||
<!-- Whether the application can be launched when the user clicks a link in a web browser.
|
|
||||||
Optional. Default false. -->
|
|
||||||
<!-- <allowBrowserInvocation></allowBrowserInvocation> -->
|
|
||||||
|
|
||||||
<!-- Listing of file types for which the application can register. Optional. -->
|
|
||||||
<!-- <fileTypes> -->
|
|
||||||
|
|
||||||
<!-- Defines one file type. Optional. -->
|
|
||||||
<!-- <fileType> -->
|
|
||||||
|
|
||||||
<!-- The name that the system displays for the registered file type. Required. -->
|
|
||||||
<!-- <name></name> -->
|
|
||||||
|
|
||||||
<!-- The extension to register. Required. -->
|
|
||||||
<!-- <extension></extension> -->
|
|
||||||
|
|
||||||
<!-- The description of the file type. Optional. -->
|
|
||||||
<!-- <description></description> -->
|
|
||||||
|
|
||||||
<!-- The MIME content type. -->
|
|
||||||
<!-- <contentType></contentType> -->
|
|
||||||
|
|
||||||
<!-- The icon to display for the file type. Optional. -->
|
|
||||||
<!-- <icon>
|
|
||||||
<image16x16></image16x16>
|
|
||||||
<image32x32></image32x32>
|
|
||||||
<image48x48></image48x48>
|
|
||||||
<image128x128></image128x128>
|
|
||||||
</icon> -->
|
|
||||||
|
|
||||||
<!-- </fileType> -->
|
|
||||||
<!-- </fileTypes> -->
|
|
||||||
|
|
||||||
</application>
|
|
@ -0,0 +1,146 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8" standalone="no"?>
|
||||||
|
<application xmlns="http://ns.adobe.com/air/application/2.0">
|
||||||
|
|
||||||
|
<!-- Adobe AIR Application Descriptor File Template.
|
||||||
|
|
||||||
|
Specifies parameters for identifying, installing, and launching AIR applications.
|
||||||
|
|
||||||
|
xmlns - The Adobe AIR namespace: http://ns.adobe.com/air/application/2.0
|
||||||
|
The last segment of the namespace specifies the version
|
||||||
|
of the AIR runtime required for this application to run.
|
||||||
|
|
||||||
|
minimumPatchLevel - The minimum patch level of the AIR runtime required to run
|
||||||
|
the application. Optional.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<!-- A universally unique application identifier. Must be unique across all AIR applications.
|
||||||
|
Using a reverse DNS-style name as the id is recommended. (Eg. com.example.ExampleApplication.) Required. -->
|
||||||
|
<id>AirExecutorApp</id>
|
||||||
|
|
||||||
|
<!-- Used as the filename for the application. Required. -->
|
||||||
|
<filename>AirExecutorApp</filename>
|
||||||
|
|
||||||
|
<!-- The name that is displayed in the AIR application installer.
|
||||||
|
May have multiple values for each language. See samples or xsd schema file. Optional. -->
|
||||||
|
<name>AirExecutorApp</name>
|
||||||
|
|
||||||
|
<!-- An application version designator (such as "v1", "2.5", or "Alpha 1"). Required. -->
|
||||||
|
<version>v1</version>
|
||||||
|
|
||||||
|
<!-- Description, displayed in the AIR application installer.
|
||||||
|
May have multiple values for each language. See samples or xsd schema file. Optional. -->
|
||||||
|
<!-- <description></description> -->
|
||||||
|
|
||||||
|
<!-- Copyright information. Optional -->
|
||||||
|
<!-- <copyright></copyright> -->
|
||||||
|
|
||||||
|
<!-- Publisher ID. Used if you're updating an application created prior to 1.5.3 -->
|
||||||
|
<!-- <publisherID></publisherID> -->
|
||||||
|
|
||||||
|
<!-- Settings for the application's initial window. Required. -->
|
||||||
|
<initialWindow>
|
||||||
|
<!-- The main SWF or HTML file of the application. Required. -->
|
||||||
|
<!-- Note: In Flash Builder, the SWF reference is set automatically. -->
|
||||||
|
<content>AirExecutorApp.swf</content>
|
||||||
|
|
||||||
|
<!-- The title of the main window. Optional. -->
|
||||||
|
<!-- <title></title> -->
|
||||||
|
|
||||||
|
<!-- The type of system chrome to use (either "standard" or "none"). Optional. Default standard. -->
|
||||||
|
<!-- <systemChrome></systemChrome> -->
|
||||||
|
|
||||||
|
<!-- Whether the window is transparent. Only applicable when systemChrome is none. Optional. Default false. -->
|
||||||
|
<!-- <transparent></transparent> -->
|
||||||
|
|
||||||
|
<!-- Whether the window is initially visible. Optional. Default false. -->
|
||||||
|
<!-- <visible></visible> -->
|
||||||
|
|
||||||
|
<!-- Whether the user can minimize the window. Optional. Default true. -->
|
||||||
|
<!-- <minimizable></minimizable> -->
|
||||||
|
|
||||||
|
<!-- Whether the user can maximize the window. Optional. Default true. -->
|
||||||
|
<!-- <maximizable></maximizable> -->
|
||||||
|
|
||||||
|
<!-- Whether the user can resize the window. Optional. Default true. -->
|
||||||
|
<!-- <resizable></resizable> -->
|
||||||
|
|
||||||
|
<!-- The window's initial width in pixels. Optional. -->
|
||||||
|
<!-- <width></width> -->
|
||||||
|
|
||||||
|
<!-- The window's initial height in pixels. Optional. -->
|
||||||
|
<!-- <height></height> -->
|
||||||
|
|
||||||
|
<!-- The window's initial x position. Optional. -->
|
||||||
|
<!-- <x></x> -->
|
||||||
|
|
||||||
|
<!-- The window's initial y position. Optional. -->
|
||||||
|
<!-- <y></y> -->
|
||||||
|
|
||||||
|
<!-- The window's minimum size, specified as a width/height pair in pixels, such as "400 200". Optional. -->
|
||||||
|
<!-- <minSize></minSize> -->
|
||||||
|
|
||||||
|
<!-- The window's initial maximum size, specified as a width/height pair in pixels, such as "1600 1200". Optional. -->
|
||||||
|
<!-- <maxSize></maxSize> -->
|
||||||
|
</initialWindow>
|
||||||
|
|
||||||
|
<!-- We recommend omitting the supportedProfiles element, -->
|
||||||
|
<!-- which in turn permits your application to be deployed to all -->
|
||||||
|
<!-- devices supported by AIR. If you wish to restrict deployment -->
|
||||||
|
<!-- (i.e., to only mobile devices) then add this element and list -->
|
||||||
|
<!-- only the profiles which your application does support. -->
|
||||||
|
<!-- <supportedProfiles>desktop extendedDesktop mobileDevice extendedMobileDevice</supportedProfiles> -->
|
||||||
|
|
||||||
|
<!-- The subpath of the standard default installation location to use. Optional. -->
|
||||||
|
<!-- <installFolder></installFolder> -->
|
||||||
|
|
||||||
|
<!-- The subpath of the Programs menu to use. (Ignored on operating systems without a Programs menu.) Optional. -->
|
||||||
|
<!-- <programMenuFolder></programMenuFolder> -->
|
||||||
|
|
||||||
|
<!-- The icon the system uses for the application. For at least one resolution,
|
||||||
|
specify the path to a PNG file included in the AIR package. Optional. -->
|
||||||
|
<!-- <icon>
|
||||||
|
<image16x16></image16x16>
|
||||||
|
<image32x32></image32x32>
|
||||||
|
<image48x48></image48x48>
|
||||||
|
<image128x128></image128x128>
|
||||||
|
</icon> -->
|
||||||
|
|
||||||
|
<!-- Whether the application handles the update when a user double-clicks an update version
|
||||||
|
of the AIR file (true), or the default AIR application installer handles the update (false).
|
||||||
|
Optional. Default false. -->
|
||||||
|
<!-- <customUpdateUI></customUpdateUI> -->
|
||||||
|
|
||||||
|
<!-- Whether the application can be launched when the user clicks a link in a web browser.
|
||||||
|
Optional. Default false. -->
|
||||||
|
<!-- <allowBrowserInvocation></allowBrowserInvocation> -->
|
||||||
|
|
||||||
|
<!-- Listing of file types for which the application can register. Optional. -->
|
||||||
|
<!-- <fileTypes> -->
|
||||||
|
|
||||||
|
<!-- Defines one file type. Optional. -->
|
||||||
|
<!-- <fileType> -->
|
||||||
|
|
||||||
|
<!-- The name that the system displays for the registered file type. Required. -->
|
||||||
|
<!-- <name></name> -->
|
||||||
|
|
||||||
|
<!-- The extension to register. Required. -->
|
||||||
|
<!-- <extension></extension> -->
|
||||||
|
|
||||||
|
<!-- The description of the file type. Optional. -->
|
||||||
|
<!-- <description></description> -->
|
||||||
|
|
||||||
|
<!-- The MIME content type. -->
|
||||||
|
<!-- <contentType></contentType> -->
|
||||||
|
|
||||||
|
<!-- The icon to display for the file type. Optional. -->
|
||||||
|
<!-- <icon>
|
||||||
|
<image16x16></image16x16>
|
||||||
|
<image32x32></image32x32>
|
||||||
|
<image48x48></image48x48>
|
||||||
|
<image128x128></image128x128>
|
||||||
|
</icon> -->
|
||||||
|
|
||||||
|
<!-- </fileType> -->
|
||||||
|
<!-- </fileTypes> -->
|
||||||
|
|
||||||
|
</application>
|
@ -62,11 +62,11 @@
|
|||||||
<arg line="-doc-sources ${sourcepath}"/>
|
<arg line="-doc-sources ${sourcepath}"/>
|
||||||
<arg line="-source-path ${sourcepath}"/>
|
<arg line="-source-path ${sourcepath}"/>
|
||||||
<arg line="-footer 'Copyright Wordnik'"/>
|
<arg line="-footer 'Copyright Wordnik'"/>
|
||||||
<arg line="-package com.wordnik.swagger.api 'Contains the apis which are used by clients to make calls to the services deployed'"/>
|
<arg line="-package io.swagger.api 'Contains the apis which are used by clients to make calls to the services deployed'"/>
|
||||||
<arg line="-package com.wordnik.swagger.codegen.model 'Contains common classes which encapsulate data elements required'"/>
|
<arg line="-package io.swagger.codegen.model 'Contains common classes which encapsulate data elements required'"/>
|
||||||
<arg line="-package com.wordnik.swagger.common 'Contains classes which are used by the api classes to invoke the deployed api like SwaggerApi - a base class, ApiUserCredentials, etc.'"/>
|
<arg line="-package io.swagger.common 'Contains classes which are used by the api classes to invoke the deployed api like SwaggerApi - a base class, ApiUserCredentials, etc.'"/>
|
||||||
<arg line="-package com.wordnik.swagger.event 'Results of calls made to Wordnik are returned via dispatched events. This package contains such event classes. Right now thats just ApiClientEvent and Response.'"/>
|
<arg line="-package io.swagger.event 'Results of calls made to Wordnik are returned via dispatched events. This package contains such event classes. Right now thats just ApiClientEvent and Response.'"/>
|
||||||
<arg line="-package com.wordnik.swagger.exception 'Contains classes that encapsulate the errors generated'"/>
|
<arg line="-package io.swagger.exception 'Contains classes that encapsulate the errors generated'"/>
|
||||||
|
|
||||||
<arg value="-window-title"/>
|
<arg value="-window-title"/>
|
||||||
<arg value="${title}"/>
|
<arg value="${title}"/>
|
@ -1,272 +0,0 @@
|
|||||||
package com.wordnik.client.api {
|
|
||||||
|
|
||||||
import com.wordnik.swagger.common.ApiInvoker;
|
|
||||||
import com.wordnik.swagger.exception.ApiErrorCodes;
|
|
||||||
import com.wordnik.swagger.exception.ApiError;
|
|
||||||
import com.wordnik.swagger.common.ApiUserCredentials;
|
|
||||||
import com.wordnik.swagger.event.Response;
|
|
||||||
import com.wordnik.swagger.common.SwaggerApi;
|
|
||||||
import com.wordnik.client.model.Pet;
|
|
||||||
import com.wordnik.client.model.File;
|
|
||||||
|
|
||||||
import mx.rpc.AsyncToken;
|
|
||||||
import mx.utils.UIDUtil;
|
|
||||||
|
|
||||||
import flash.utils.Dictionary;
|
|
||||||
import flash.events.EventDispatcher;
|
|
||||||
|
|
||||||
public class PetApi extends SwaggerApi {
|
|
||||||
public static const event_getPetById:String = "getPetById";
|
|
||||||
public static const event_deletePet:String = "deletePet";
|
|
||||||
public static const event_partialUpdate:String = "partialUpdate";
|
|
||||||
public static const event_updatePetWithForm:String = "updatePetWithForm";
|
|
||||||
public static const event_uploadFile:String = "uploadFile";
|
|
||||||
public static const event_addPet:String = "addPet";
|
|
||||||
public static const event_updatePet:String = "updatePet";
|
|
||||||
public static const event_findPetsByStatus:String = "findPetsByStatus";
|
|
||||||
public static const event_findPetsByTags:String = "findPetsByTags";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructor for the PetApi api client
|
|
||||||
* @param apiCredentials Wrapper object for tokens and hostName required towards authentication
|
|
||||||
* @param eventDispatcher Optional event dispatcher that when provided is used by the SDK to dispatch any Response
|
|
||||||
*/
|
|
||||||
public function PetApi(apiCredentials:ApiUserCredentials, eventDispatcher:EventDispatcher = null) {
|
|
||||||
super(apiCredentials, eventDispatcher);
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
* Returns Pet */
|
|
||||||
|
|
||||||
public function getPetById(petId:Number):String {
|
|
||||||
// create path and map variables
|
|
||||||
var path:String = "/pet/{petId}".replace(/{format}/g, "xml").replace("{" + "petId" + "}", getApiInvoker().escapeString(petId));
|
|
||||||
|
|
||||||
// query params
|
|
||||||
var queryParams:Dictionary = new Dictionary();
|
|
||||||
var headerParams:Dictionary = new Dictionary();
|
|
||||||
|
|
||||||
// verify required params are set
|
|
||||||
if (petId == null) {
|
|
||||||
throw new ApiError(400, "missing required params");
|
|
||||||
}
|
|
||||||
var token:AsyncToken = getApiInvoker().invokeAPI(path, "GET", queryParams, null, headerParams);
|
|
||||||
|
|
||||||
var requestId:String = getUniqueId();
|
|
||||||
|
|
||||||
token.requestId = requestId;
|
|
||||||
token.completionEventType = "getPetById";
|
|
||||||
|
|
||||||
token.returnType = Pet;
|
|
||||||
return requestId;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Returns void */
|
|
||||||
public function deletePet(petId:String):String {
|
|
||||||
// create path and map variables
|
|
||||||
var path:String = "/pet/{petId}".replace(/{format}/g, "xml").replace("{" + "petId" + "}", getApiInvoker().escapeString(petId));
|
|
||||||
|
|
||||||
// query params
|
|
||||||
var queryParams:Dictionary = new Dictionary();
|
|
||||||
var headerParams:Dictionary = new Dictionary();
|
|
||||||
|
|
||||||
// verify required params are set
|
|
||||||
if (petId == null) {
|
|
||||||
throw new ApiError(400, "missing required params");
|
|
||||||
}
|
|
||||||
var token:AsyncToken = getApiInvoker().invokeAPI(path, "DELETE", queryParams, null, headerParams);
|
|
||||||
|
|
||||||
var requestId:String = getUniqueId();
|
|
||||||
|
|
||||||
token.requestId = requestId;
|
|
||||||
token.completionEventType = "deletePet";
|
|
||||||
|
|
||||||
token.returnType = null;
|
|
||||||
return requestId;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Returns Array[Pet] */
|
|
||||||
public function partialUpdate(petId:String, body:Pet):String {
|
|
||||||
// create path and map variables
|
|
||||||
var path:String = "/pet/{petId}".replace(/{format}/g, "xml").replace("{" + "petId" + "}", getApiInvoker().escapeString(petId));
|
|
||||||
|
|
||||||
// query params
|
|
||||||
var queryParams:Dictionary = new Dictionary();
|
|
||||||
var headerParams:Dictionary = new Dictionary();
|
|
||||||
|
|
||||||
// verify required params are set
|
|
||||||
if (petId == null || body == null) {
|
|
||||||
throw new ApiError(400, "missing required params");
|
|
||||||
}
|
|
||||||
var token:AsyncToken = getApiInvoker().invokeAPI(path, "PATCH", queryParams, body, headerParams);
|
|
||||||
|
|
||||||
var requestId:String = getUniqueId();
|
|
||||||
|
|
||||||
token.requestId = requestId;
|
|
||||||
token.completionEventType = "partialUpdate";
|
|
||||||
|
|
||||||
token.returnType = Array[Pet];
|
|
||||||
return requestId;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Returns void */
|
|
||||||
public function updatePetWithForm(petId:String, name:String, status:String):String {
|
|
||||||
// create path and map variables
|
|
||||||
var path:String = "/pet/{petId}".replace(/{format}/g, "xml").replace("{" + "petId" + "}", getApiInvoker().escapeString(petId));
|
|
||||||
|
|
||||||
// query params
|
|
||||||
var queryParams:Dictionary = new Dictionary();
|
|
||||||
var headerParams:Dictionary = new Dictionary();
|
|
||||||
|
|
||||||
// verify required params are set
|
|
||||||
if (petId == null) {
|
|
||||||
throw new ApiError(400, "missing required params");
|
|
||||||
}
|
|
||||||
var token:AsyncToken = getApiInvoker().invokeAPI(path, "POST", queryParams, null, headerParams);
|
|
||||||
|
|
||||||
var requestId:String = getUniqueId();
|
|
||||||
|
|
||||||
token.requestId = requestId;
|
|
||||||
token.completionEventType = "updatePetWithForm";
|
|
||||||
|
|
||||||
token.returnType = null;
|
|
||||||
return requestId;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Returns void */
|
|
||||||
public function uploadFile(additionalMetadata:String, body:File):String {
|
|
||||||
// create path and map variables
|
|
||||||
var path:String = "/pet/uploadImage".replace(/{format}/g, "xml");
|
|
||||||
|
|
||||||
// query params
|
|
||||||
var queryParams:Dictionary = new Dictionary();
|
|
||||||
var headerParams:Dictionary = new Dictionary();
|
|
||||||
|
|
||||||
var token:AsyncToken = getApiInvoker().invokeAPI(path, "POST", queryParams, body, headerParams);
|
|
||||||
|
|
||||||
var requestId:String = getUniqueId();
|
|
||||||
|
|
||||||
token.requestId = requestId;
|
|
||||||
token.completionEventType = "uploadFile";
|
|
||||||
|
|
||||||
token.returnType = null;
|
|
||||||
return requestId;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Returns void */
|
|
||||||
public function addPet(body:Pet):String {
|
|
||||||
// create path and map variables
|
|
||||||
var path:String = "/pet".replace(/{format}/g, "xml");
|
|
||||||
|
|
||||||
// query params
|
|
||||||
var queryParams:Dictionary = new Dictionary();
|
|
||||||
var headerParams:Dictionary = new Dictionary();
|
|
||||||
|
|
||||||
// verify required params are set
|
|
||||||
if (body == null) {
|
|
||||||
throw new ApiError(400, "missing required params");
|
|
||||||
}
|
|
||||||
var token:AsyncToken = getApiInvoker().invokeAPI(path, "POST", queryParams, body, headerParams);
|
|
||||||
|
|
||||||
var requestId:String = getUniqueId();
|
|
||||||
|
|
||||||
token.requestId = requestId;
|
|
||||||
token.completionEventType = "addPet";
|
|
||||||
|
|
||||||
token.returnType = null;
|
|
||||||
return requestId;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Returns void */
|
|
||||||
public function updatePet(body:Pet):String {
|
|
||||||
// create path and map variables
|
|
||||||
var path:String = "/pet".replace(/{format}/g, "xml");
|
|
||||||
|
|
||||||
// query params
|
|
||||||
var queryParams:Dictionary = new Dictionary();
|
|
||||||
var headerParams:Dictionary = new Dictionary();
|
|
||||||
|
|
||||||
// verify required params are set
|
|
||||||
if (body == null) {
|
|
||||||
throw new ApiError(400, "missing required params");
|
|
||||||
}
|
|
||||||
var token:AsyncToken = getApiInvoker().invokeAPI(path, "PUT", queryParams, body, headerParams);
|
|
||||||
|
|
||||||
var requestId:String = getUniqueId();
|
|
||||||
|
|
||||||
token.requestId = requestId;
|
|
||||||
token.completionEventType = "updatePet";
|
|
||||||
|
|
||||||
token.returnType = null;
|
|
||||||
return requestId;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Returns Array[Pet] */
|
|
||||||
public function findPetsByStatus(status:String = "available"):String {
|
|
||||||
// create path and map variables
|
|
||||||
var path:String = "/pet/findByStatus".replace(/{format}/g, "xml");
|
|
||||||
|
|
||||||
// query params
|
|
||||||
var queryParams:Dictionary = new Dictionary();
|
|
||||||
var headerParams:Dictionary = new Dictionary();
|
|
||||||
|
|
||||||
// verify required params are set
|
|
||||||
if (status == null) {
|
|
||||||
throw new ApiError(400, "missing required params");
|
|
||||||
}
|
|
||||||
if ("null" != String(status))
|
|
||||||
queryParams["status"] = toPathValue(status);
|
|
||||||
var token:AsyncToken = getApiInvoker().invokeAPI(path, "GET", queryParams, null, headerParams);
|
|
||||||
|
|
||||||
var requestId:String = getUniqueId();
|
|
||||||
|
|
||||||
token.requestId = requestId;
|
|
||||||
token.completionEventType = "findPetsByStatus";
|
|
||||||
|
|
||||||
token.returnType = Array[Pet];
|
|
||||||
return requestId;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Returns Array[Pet] */
|
|
||||||
public function findPetsByTags(tags:String):String {
|
|
||||||
// create path and map variables
|
|
||||||
var path:String = "/pet/findByTags".replace(/{format}/g, "xml");
|
|
||||||
|
|
||||||
// query params
|
|
||||||
var queryParams:Dictionary = new Dictionary();
|
|
||||||
var headerParams:Dictionary = new Dictionary();
|
|
||||||
|
|
||||||
// verify required params are set
|
|
||||||
if (tags == null) {
|
|
||||||
throw new ApiError(400, "missing required params");
|
|
||||||
}
|
|
||||||
if ("null" != String(tags))
|
|
||||||
queryParams["tags"] = toPathValue(tags);
|
|
||||||
var token:AsyncToken = getApiInvoker().invokeAPI(path, "GET", queryParams, null, headerParams);
|
|
||||||
|
|
||||||
var requestId:String = getUniqueId();
|
|
||||||
|
|
||||||
token.requestId = requestId;
|
|
||||||
token.completionEventType = "findPetsByTags";
|
|
||||||
|
|
||||||
token.returnType = Array[Pet];
|
|
||||||
return requestId;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,109 +0,0 @@
|
|||||||
package com.wordnik.client.api {
|
|
||||||
|
|
||||||
import com.wordnik.swagger.common.ApiInvoker;
|
|
||||||
import com.wordnik.swagger.exception.ApiErrorCodes;
|
|
||||||
import com.wordnik.swagger.exception.ApiError;
|
|
||||||
import com.wordnik.swagger.common.ApiUserCredentials;
|
|
||||||
import com.wordnik.swagger.event.Response;
|
|
||||||
import com.wordnik.swagger.common.SwaggerApi;
|
|
||||||
import com.wordnik.client.model.Order;
|
|
||||||
|
|
||||||
import mx.rpc.AsyncToken;
|
|
||||||
import mx.utils.UIDUtil;
|
|
||||||
|
|
||||||
import flash.utils.Dictionary;
|
|
||||||
import flash.events.EventDispatcher;
|
|
||||||
|
|
||||||
public class StoreApi extends SwaggerApi {
|
|
||||||
public static const event_getOrderById:String = "getOrderById";
|
|
||||||
public static const event_deleteOrder:String = "deleteOrder";
|
|
||||||
public static const event_placeOrder:String = "placeOrder";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructor for the StoreApi api client
|
|
||||||
* @param apiCredentials Wrapper object for tokens and hostName required towards authentication
|
|
||||||
* @param eventDispatcher Optional event dispatcher that when provided is used by the SDK to dispatch any Response
|
|
||||||
*/
|
|
||||||
public function StoreApi(apiCredentials:ApiUserCredentials, eventDispatcher:EventDispatcher = null) {
|
|
||||||
super(apiCredentials, eventDispatcher);
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
* Returns Order */
|
|
||||||
|
|
||||||
public function getOrderById(orderId:String):String {
|
|
||||||
// create path and map variables
|
|
||||||
var path:String = "/store/order/{orderId}".replace(/{format}/g, "xml").replace("{" + "orderId" + "}", getApiInvoker().escapeString(orderId));
|
|
||||||
|
|
||||||
// query params
|
|
||||||
var queryParams:Dictionary = new Dictionary();
|
|
||||||
var headerParams:Dictionary = new Dictionary();
|
|
||||||
|
|
||||||
// verify required params are set
|
|
||||||
if (orderId == null) {
|
|
||||||
throw new ApiError(400, "missing required params");
|
|
||||||
}
|
|
||||||
var token:AsyncToken = getApiInvoker().invokeAPI(path, "GET", queryParams, null, headerParams);
|
|
||||||
|
|
||||||
var requestId:String = getUniqueId();
|
|
||||||
|
|
||||||
token.requestId = requestId;
|
|
||||||
token.completionEventType = "getOrderById";
|
|
||||||
|
|
||||||
token.returnType = Order;
|
|
||||||
return requestId;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Returns void */
|
|
||||||
public function deleteOrder(orderId:String):String {
|
|
||||||
// create path and map variables
|
|
||||||
var path:String = "/store/order/{orderId}".replace(/{format}/g, "xml").replace("{" + "orderId" + "}", getApiInvoker().escapeString(orderId));
|
|
||||||
|
|
||||||
// query params
|
|
||||||
var queryParams:Dictionary = new Dictionary();
|
|
||||||
var headerParams:Dictionary = new Dictionary();
|
|
||||||
|
|
||||||
// verify required params are set
|
|
||||||
if (orderId == null) {
|
|
||||||
throw new ApiError(400, "missing required params");
|
|
||||||
}
|
|
||||||
var token:AsyncToken = getApiInvoker().invokeAPI(path, "DELETE", queryParams, null, headerParams);
|
|
||||||
|
|
||||||
var requestId:String = getUniqueId();
|
|
||||||
|
|
||||||
token.requestId = requestId;
|
|
||||||
token.completionEventType = "deleteOrder";
|
|
||||||
|
|
||||||
token.returnType = null;
|
|
||||||
return requestId;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Returns void */
|
|
||||||
public function placeOrder(body:Order):String {
|
|
||||||
// create path and map variables
|
|
||||||
var path:String = "/store/order".replace(/{format}/g, "xml");
|
|
||||||
|
|
||||||
// query params
|
|
||||||
var queryParams:Dictionary = new Dictionary();
|
|
||||||
var headerParams:Dictionary = new Dictionary();
|
|
||||||
|
|
||||||
// verify required params are set
|
|
||||||
if (body == null) {
|
|
||||||
throw new ApiError(400, "missing required params");
|
|
||||||
}
|
|
||||||
var token:AsyncToken = getApiInvoker().invokeAPI(path, "POST", queryParams, body, headerParams);
|
|
||||||
|
|
||||||
var requestId:String = getUniqueId();
|
|
||||||
|
|
||||||
token.requestId = requestId;
|
|
||||||
token.completionEventType = "placeOrder";
|
|
||||||
|
|
||||||
token.returnType = null;
|
|
||||||
return requestId;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,244 +0,0 @@
|
|||||||
package com.wordnik.client.api {
|
|
||||||
|
|
||||||
import com.wordnik.swagger.common.ApiInvoker;
|
|
||||||
import com.wordnik.swagger.exception.ApiErrorCodes;
|
|
||||||
import com.wordnik.swagger.exception.ApiError;
|
|
||||||
import com.wordnik.swagger.common.ApiUserCredentials;
|
|
||||||
import com.wordnik.swagger.event.Response;
|
|
||||||
import com.wordnik.swagger.common.SwaggerApi;
|
|
||||||
import com.wordnik.client.model.User;
|
|
||||||
|
|
||||||
import mx.rpc.AsyncToken;
|
|
||||||
import mx.utils.UIDUtil;
|
|
||||||
|
|
||||||
import flash.utils.Dictionary;
|
|
||||||
import flash.events.EventDispatcher;
|
|
||||||
|
|
||||||
public class UserApi extends SwaggerApi {
|
|
||||||
public static const event_updateUser:String = "updateUser";
|
|
||||||
public static const event_deleteUser:String = "deleteUser";
|
|
||||||
public static const event_getUserByName:String = "getUserByName";
|
|
||||||
public static const event_loginUser:String = "loginUser";
|
|
||||||
public static const event_logoutUser:String = "logoutUser";
|
|
||||||
public static const event_createUser:String = "createUser";
|
|
||||||
public static const event_createUsersWithArrayInput:String = "createUsersWithArrayInput";
|
|
||||||
public static const event_createUsersWithListInput:String = "createUsersWithListInput";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructor for the UserApi api client
|
|
||||||
* @param apiCredentials Wrapper object for tokens and hostName required towards authentication
|
|
||||||
* @param eventDispatcher Optional event dispatcher that when provided is used by the SDK to dispatch any Response
|
|
||||||
*/
|
|
||||||
public function UserApi(apiCredentials:ApiUserCredentials, eventDispatcher:EventDispatcher = null) {
|
|
||||||
super(apiCredentials, eventDispatcher);
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
* Returns void */
|
|
||||||
|
|
||||||
public function updateUser(username:String, body:User):String {
|
|
||||||
// create path and map variables
|
|
||||||
var path:String = "/user/{username}".replace(/{format}/g, "xml").replace("{" + "username" + "}", getApiInvoker().escapeString(username));
|
|
||||||
|
|
||||||
// query params
|
|
||||||
var queryParams:Dictionary = new Dictionary();
|
|
||||||
var headerParams:Dictionary = new Dictionary();
|
|
||||||
|
|
||||||
// verify required params are set
|
|
||||||
if (username == null || body == null) {
|
|
||||||
throw new ApiError(400, "missing required params");
|
|
||||||
}
|
|
||||||
var token:AsyncToken = getApiInvoker().invokeAPI(path, "PUT", queryParams, body, headerParams);
|
|
||||||
|
|
||||||
var requestId:String = getUniqueId();
|
|
||||||
|
|
||||||
token.requestId = requestId;
|
|
||||||
token.completionEventType = "updateUser";
|
|
||||||
|
|
||||||
token.returnType = null;
|
|
||||||
return requestId;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Returns void */
|
|
||||||
public function deleteUser(username:String):String {
|
|
||||||
// create path and map variables
|
|
||||||
var path:String = "/user/{username}".replace(/{format}/g, "xml").replace("{" + "username" + "}", getApiInvoker().escapeString(username));
|
|
||||||
|
|
||||||
// query params
|
|
||||||
var queryParams:Dictionary = new Dictionary();
|
|
||||||
var headerParams:Dictionary = new Dictionary();
|
|
||||||
|
|
||||||
// verify required params are set
|
|
||||||
if (username == null) {
|
|
||||||
throw new ApiError(400, "missing required params");
|
|
||||||
}
|
|
||||||
var token:AsyncToken = getApiInvoker().invokeAPI(path, "DELETE", queryParams, null, headerParams);
|
|
||||||
|
|
||||||
var requestId:String = getUniqueId();
|
|
||||||
|
|
||||||
token.requestId = requestId;
|
|
||||||
token.completionEventType = "deleteUser";
|
|
||||||
|
|
||||||
token.returnType = null;
|
|
||||||
return requestId;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Returns User */
|
|
||||||
public function getUserByName(username:String):String {
|
|
||||||
// create path and map variables
|
|
||||||
var path:String = "/user/{username}".replace(/{format}/g, "xml").replace("{" + "username" + "}", getApiInvoker().escapeString(username));
|
|
||||||
|
|
||||||
// query params
|
|
||||||
var queryParams:Dictionary = new Dictionary();
|
|
||||||
var headerParams:Dictionary = new Dictionary();
|
|
||||||
|
|
||||||
// verify required params are set
|
|
||||||
if (username == null) {
|
|
||||||
throw new ApiError(400, "missing required params");
|
|
||||||
}
|
|
||||||
var token:AsyncToken = getApiInvoker().invokeAPI(path, "GET", queryParams, null, headerParams);
|
|
||||||
|
|
||||||
var requestId:String = getUniqueId();
|
|
||||||
|
|
||||||
token.requestId = requestId;
|
|
||||||
token.completionEventType = "getUserByName";
|
|
||||||
|
|
||||||
token.returnType = User;
|
|
||||||
return requestId;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Returns string */
|
|
||||||
public function loginUser(username:String, password:String):String {
|
|
||||||
// create path and map variables
|
|
||||||
var path:String = "/user/login".replace(/{format}/g, "xml");
|
|
||||||
|
|
||||||
// query params
|
|
||||||
var queryParams:Dictionary = new Dictionary();
|
|
||||||
var headerParams:Dictionary = new Dictionary();
|
|
||||||
|
|
||||||
// verify required params are set
|
|
||||||
if (username == null || password == null) {
|
|
||||||
throw new ApiError(400, "missing required params");
|
|
||||||
}
|
|
||||||
if ("null" != String(username))
|
|
||||||
queryParams["username"] = toPathValue(username);
|
|
||||||
if ("null" != String(password))
|
|
||||||
queryParams["password"] = toPathValue(password);
|
|
||||||
var token:AsyncToken = getApiInvoker().invokeAPI(path, "GET", queryParams, null, headerParams);
|
|
||||||
|
|
||||||
var requestId:String = getUniqueId();
|
|
||||||
|
|
||||||
token.requestId = requestId;
|
|
||||||
token.completionEventType = "loginUser";
|
|
||||||
|
|
||||||
token.returnType = string;
|
|
||||||
return requestId;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Returns void */
|
|
||||||
public function logoutUser():String {
|
|
||||||
// create path and map variables
|
|
||||||
var path:String = "/user/logout".replace(/{format}/g, "xml");
|
|
||||||
|
|
||||||
// query params
|
|
||||||
var queryParams:Dictionary = new Dictionary();
|
|
||||||
var headerParams:Dictionary = new Dictionary();
|
|
||||||
|
|
||||||
var token:AsyncToken = getApiInvoker().invokeAPI(path, "GET", queryParams, null, headerParams);
|
|
||||||
|
|
||||||
var requestId:String = getUniqueId();
|
|
||||||
|
|
||||||
token.requestId = requestId;
|
|
||||||
token.completionEventType = "logoutUser";
|
|
||||||
|
|
||||||
token.returnType = null;
|
|
||||||
return requestId;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Returns void */
|
|
||||||
public function createUser(body:User):String {
|
|
||||||
// create path and map variables
|
|
||||||
var path:String = "/user".replace(/{format}/g, "xml");
|
|
||||||
|
|
||||||
// query params
|
|
||||||
var queryParams:Dictionary = new Dictionary();
|
|
||||||
var headerParams:Dictionary = new Dictionary();
|
|
||||||
|
|
||||||
// verify required params are set
|
|
||||||
if (body == null) {
|
|
||||||
throw new ApiError(400, "missing required params");
|
|
||||||
}
|
|
||||||
var token:AsyncToken = getApiInvoker().invokeAPI(path, "POST", queryParams, body, headerParams);
|
|
||||||
|
|
||||||
var requestId:String = getUniqueId();
|
|
||||||
|
|
||||||
token.requestId = requestId;
|
|
||||||
token.completionEventType = "createUser";
|
|
||||||
|
|
||||||
token.returnType = null;
|
|
||||||
return requestId;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Returns void */
|
|
||||||
public function createUsersWithArrayInput(body:Array):String {
|
|
||||||
// create path and map variables
|
|
||||||
var path:String = "/user/createWithArray".replace(/{format}/g, "xml");
|
|
||||||
|
|
||||||
// query params
|
|
||||||
var queryParams:Dictionary = new Dictionary();
|
|
||||||
var headerParams:Dictionary = new Dictionary();
|
|
||||||
|
|
||||||
// verify required params are set
|
|
||||||
if (body == null) {
|
|
||||||
throw new ApiError(400, "missing required params");
|
|
||||||
}
|
|
||||||
var token:AsyncToken = getApiInvoker().invokeAPI(path, "POST", queryParams, body, headerParams);
|
|
||||||
|
|
||||||
var requestId:String = getUniqueId();
|
|
||||||
|
|
||||||
token.requestId = requestId;
|
|
||||||
token.completionEventType = "createUsersWithArrayInput";
|
|
||||||
|
|
||||||
token.returnType = null;
|
|
||||||
return requestId;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Returns void */
|
|
||||||
public function createUsersWithListInput(body:Array):String {
|
|
||||||
// create path and map variables
|
|
||||||
var path:String = "/user/createWithList".replace(/{format}/g, "xml");
|
|
||||||
|
|
||||||
// query params
|
|
||||||
var queryParams:Dictionary = new Dictionary();
|
|
||||||
var headerParams:Dictionary = new Dictionary();
|
|
||||||
|
|
||||||
// verify required params are set
|
|
||||||
if (body == null) {
|
|
||||||
throw new ApiError(400, "missing required params");
|
|
||||||
}
|
|
||||||
var token:AsyncToken = getApiInvoker().invokeAPI(path, "POST", queryParams, body, headerParams);
|
|
||||||
|
|
||||||
var requestId:String = getUniqueId();
|
|
||||||
|
|
||||||
token.requestId = requestId;
|
|
||||||
token.completionEventType = "createUsersWithListInput";
|
|
||||||
|
|
||||||
token.returnType = null;
|
|
||||||
return requestId;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,21 +0,0 @@
|
|||||||
package com.wordnik.client.model {
|
|
||||||
|
|
||||||
[XmlRootNode(name="Category")]
|
|
||||||
public class Category {
|
|
||||||
[XmlElement(name="id")]
|
|
||||||
public var id:Number = 0.0;
|
|
||||||
|
|
||||||
[XmlElement(name="name")]
|
|
||||||
public var name:String = null;
|
|
||||||
|
|
||||||
public function toString():String {
|
|
||||||
var str:String = "Category: ";
|
|
||||||
str += " (id: " + id + ")";
|
|
||||||
str += " (name: " + name + ")";
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,17 +0,0 @@
|
|||||||
package com.wordnik.client.model {
|
|
||||||
|
|
||||||
import com.wordnik.swagger.common.ListWrapper;
|
|
||||||
|
|
||||||
public class CategoryList implements ListWrapper {
|
|
||||||
// This declaration below of _Category_obj_class is to force flash compiler to include this class
|
|
||||||
[XmlElements(name="category", type="com.wordnik.client.model.Category")]
|
|
||||||
public var category:Array = new Array();
|
|
||||||
private var _category_obj_class:com.wordnik.client.model.Category = null;
|
|
||||||
|
|
||||||
public function getList():Array {
|
|
||||||
return category;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,34 +0,0 @@
|
|||||||
package com.wordnik.client.model {
|
|
||||||
|
|
||||||
[XmlRootNode(name="Order")]
|
|
||||||
public class Order {
|
|
||||||
[XmlElement(name="id")]
|
|
||||||
public var id:Number = 0.0;
|
|
||||||
|
|
||||||
[XmlElement(name="petId")]
|
|
||||||
public var petId:Number = 0.0;
|
|
||||||
|
|
||||||
[XmlElement(name="quantity")]
|
|
||||||
public var quantity:Number = 0.0;
|
|
||||||
|
|
||||||
/* Order Status */
|
|
||||||
[XmlElement(name="status")]
|
|
||||||
public var status:String = null;
|
|
||||||
|
|
||||||
[XmlElement(name="shipDate")]
|
|
||||||
public var shipDate:Date = null;
|
|
||||||
|
|
||||||
public function toString():String {
|
|
||||||
var str:String = "Order: ";
|
|
||||||
str += " (id: " + id + ")";
|
|
||||||
str += " (petId: " + petId + ")";
|
|
||||||
str += " (quantity: " + quantity + ")";
|
|
||||||
str += " (status: " + status + ")";
|
|
||||||
str += " (shipDate: " + shipDate + ")";
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,17 +0,0 @@
|
|||||||
package com.wordnik.client.model {
|
|
||||||
|
|
||||||
import com.wordnik.swagger.common.ListWrapper;
|
|
||||||
|
|
||||||
public class OrderList implements ListWrapper {
|
|
||||||
// This declaration below of _Order_obj_class is to force flash compiler to include this class
|
|
||||||
[XmlElements(name="order", type="com.wordnik.client.model.Order")]
|
|
||||||
public var order:Array = new Array();
|
|
||||||
private var _order_obj_class:com.wordnik.client.model.Order = null;
|
|
||||||
|
|
||||||
public function getList():Array {
|
|
||||||
return order;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,48 +0,0 @@
|
|||||||
package com.wordnik.client.model {
|
|
||||||
|
|
||||||
import com.wordnik.client.model.Category;
|
|
||||||
import com.wordnik.client.model.Tag;
|
|
||||||
|
|
||||||
[XmlRootNode(name="Pet")]
|
|
||||||
public class Pet {
|
|
||||||
/* unique identifier for the pet */
|
|
||||||
[XmlElement(name="id")]
|
|
||||||
public var id:Number = 0.0;
|
|
||||||
|
|
||||||
[XmlElement(name="category")]
|
|
||||||
public var category:Category = null;
|
|
||||||
|
|
||||||
[XmlElement(name="name")]
|
|
||||||
public var name:String = null;
|
|
||||||
|
|
||||||
// This declaration below of _photoUrls_obj_class is to force flash compiler to include this class
|
|
||||||
[XmlElementWrapper(name="photoUrls")]
|
|
||||||
[XmlElements(name="photoUrl", type="com.wordnik.client.model.String")]
|
|
||||||
public var photoUrls:Array = new Array();
|
|
||||||
[XmlElementWrapper(name="tags")]
|
|
||||||
[XmlElements(name="tag", type="com.wordnik.client.model.Tag")]
|
|
||||||
public var tags:Array = new Array();
|
|
||||||
|
|
||||||
// This declaration below of _tags_obj_class is to force flash compiler to include this class
|
|
||||||
[XmlElement(name="status")]
|
|
||||||
public var status:String = null;
|
|
||||||
private var _photoUrls_obj_class:com.wordnik.client.model.String = null;
|
|
||||||
|
|
||||||
/* pet status in the store */
|
|
||||||
private var _tags_obj_class:com.wordnik.client.model.Tag = null;
|
|
||||||
|
|
||||||
public function toString():String {
|
|
||||||
var str:String = "Pet: ";
|
|
||||||
str += " (id: " + id + ")";
|
|
||||||
str += " (category: " + category + ")";
|
|
||||||
str += " (name: " + name + ")";
|
|
||||||
str += " (photoUrls: " + photoUrls + ")";
|
|
||||||
str += " (tags: " + tags + ")";
|
|
||||||
str += " (status: " + status + ")";
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,19 +0,0 @@
|
|||||||
package com.wordnik.client.model {
|
|
||||||
|
|
||||||
import com.wordnik.swagger.common.ListWrapper;
|
|
||||||
import com.wordnik.client.model.Category;
|
|
||||||
import com.wordnik.client.model.Tag;
|
|
||||||
|
|
||||||
public class PetList implements ListWrapper {
|
|
||||||
// This declaration below of _Pet_obj_class is to force flash compiler to include this class
|
|
||||||
[XmlElements(name="pet", type="com.wordnik.client.model.Pet")]
|
|
||||||
public var pet:Array = new Array();
|
|
||||||
private var _pet_obj_class:com.wordnik.client.model.Pet = null;
|
|
||||||
|
|
||||||
public function getList():Array {
|
|
||||||
return pet;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,21 +0,0 @@
|
|||||||
package com.wordnik.client.model {
|
|
||||||
|
|
||||||
[XmlRootNode(name="Tag")]
|
|
||||||
public class Tag {
|
|
||||||
[XmlElement(name="id")]
|
|
||||||
public var id:Number = 0.0;
|
|
||||||
|
|
||||||
[XmlElement(name="name")]
|
|
||||||
public var name:String = null;
|
|
||||||
|
|
||||||
public function toString():String {
|
|
||||||
var str:String = "Tag: ";
|
|
||||||
str += " (id: " + id + ")";
|
|
||||||
str += " (name: " + name + ")";
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,17 +0,0 @@
|
|||||||
package com.wordnik.client.model {
|
|
||||||
|
|
||||||
import com.wordnik.swagger.common.ListWrapper;
|
|
||||||
|
|
||||||
public class TagList implements ListWrapper {
|
|
||||||
// This declaration below of _Tag_obj_class is to force flash compiler to include this class
|
|
||||||
[XmlElements(name="tag", type="com.wordnik.client.model.Tag")]
|
|
||||||
public var tag:Array = new Array();
|
|
||||||
private var _tag_obj_class:com.wordnik.client.model.Tag = null;
|
|
||||||
|
|
||||||
public function getList():Array {
|
|
||||||
return tag;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,46 +0,0 @@
|
|||||||
package com.wordnik.client.model {
|
|
||||||
|
|
||||||
[XmlRootNode(name="User")]
|
|
||||||
public class User {
|
|
||||||
[XmlElement(name="id")]
|
|
||||||
public var id:Number = 0.0;
|
|
||||||
|
|
||||||
[XmlElement(name="firstName")]
|
|
||||||
public var firstName:String = null;
|
|
||||||
|
|
||||||
[XmlElement(name="username")]
|
|
||||||
public var username:String = null;
|
|
||||||
|
|
||||||
[XmlElement(name="lastName")]
|
|
||||||
public var lastName:String = null;
|
|
||||||
|
|
||||||
[XmlElement(name="email")]
|
|
||||||
public var email:String = null;
|
|
||||||
|
|
||||||
[XmlElement(name="password")]
|
|
||||||
public var password:String = null;
|
|
||||||
|
|
||||||
[XmlElement(name="phone")]
|
|
||||||
public var phone:String = null;
|
|
||||||
|
|
||||||
/* User Status */
|
|
||||||
[XmlElement(name="userStatus")]
|
|
||||||
public var userStatus:Number = 0.0;
|
|
||||||
|
|
||||||
public function toString():String {
|
|
||||||
var str:String = "User: ";
|
|
||||||
str += " (id: " + id + ")";
|
|
||||||
str += " (firstName: " + firstName + ")";
|
|
||||||
str += " (username: " + username + ")";
|
|
||||||
str += " (lastName: " + lastName + ")";
|
|
||||||
str += " (email: " + email + ")";
|
|
||||||
str += " (password: " + password + ")";
|
|
||||||
str += " (phone: " + phone + ")";
|
|
||||||
str += " (userStatus: " + userStatus + ")";
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,17 +0,0 @@
|
|||||||
package com.wordnik.client.model {
|
|
||||||
|
|
||||||
import com.wordnik.swagger.common.ListWrapper;
|
|
||||||
|
|
||||||
public class UserList implements ListWrapper {
|
|
||||||
// This declaration below of _User_obj_class is to force flash compiler to include this class
|
|
||||||
[XmlElements(name="user", type="com.wordnik.client.model.User")]
|
|
||||||
public var user:Array = new Array();
|
|
||||||
private var _user_obj_class:com.wordnik.client.model.User = null;
|
|
||||||
|
|
||||||
public function getList():Array {
|
|
||||||
return user;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,7 +0,0 @@
|
|||||||
package com.wordnik.swagger.common {
|
|
||||||
public interface ListWrapper {
|
|
||||||
|
|
||||||
function getList():Array;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,70 +0,0 @@
|
|||||||
package com.wordnik.swagger.common {
|
|
||||||
import com.wordnik.swagger.common.ApiUserCredentials;
|
|
||||||
|
|
||||||
import flash.events.EventDispatcher;
|
|
||||||
import flash.events.IEventDispatcher;
|
|
||||||
|
|
||||||
import mx.utils.UIDUtil;
|
|
||||||
|
|
||||||
public class SwaggerApi extends EventDispatcher {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method for returning the path value
|
|
||||||
* For a string value an empty value is returned if the value is null
|
|
||||||
* @param value
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
protected static function toPathValue(value:Object):String {
|
|
||||||
if (value is Array) {
|
|
||||||
return arrayToPathValue(value as Array);
|
|
||||||
}
|
|
||||||
return value == null ? "" : value.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method for returning a path value
|
|
||||||
* For a list of objects a comma separated string is returned
|
|
||||||
* @param objects
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
protected static function arrayToPathValue(objects:Array):String {
|
|
||||||
var out:String = "";
|
|
||||||
|
|
||||||
return objects.join(",");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructor for the api client
|
|
||||||
* @param apiCredentials Wrapper object for tokens and hostName required towards authentication
|
|
||||||
* @param eventDispatcher Optional event dispatcher that when provided is used by the SDK to dispatch any Response
|
|
||||||
*/
|
|
||||||
public function SwaggerApi(apiCredentials:ApiUserCredentials, eventDispatcher:EventDispatcher = null) {
|
|
||||||
super();
|
|
||||||
_apiUsageCredentials = apiCredentials;
|
|
||||||
_apiEventNotifier = eventDispatcher;
|
|
||||||
}
|
|
||||||
protected var _apiUsageCredentials:ApiUserCredentials;
|
|
||||||
protected var _apiEventNotifier:EventDispatcher;
|
|
||||||
protected var _apiInvoker:ApiInvoker;
|
|
||||||
protected var _useProxyServer:Boolean = false;
|
|
||||||
|
|
||||||
public function useProxyServer(value:Boolean, proxyServerUrl:String = null):void {
|
|
||||||
_useProxyServer = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function getApiInvoker():ApiInvoker {
|
|
||||||
if (_apiInvoker == null) {
|
|
||||||
if (_apiEventNotifier == null) {
|
|
||||||
_apiEventNotifier = this;
|
|
||||||
}
|
|
||||||
_apiInvoker = new ApiInvoker(_apiUsageCredentials, _apiEventNotifier, _useProxyServer);
|
|
||||||
}
|
|
||||||
return _apiInvoker;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function getUniqueId():String {
|
|
||||||
return UIDUtil.createUID();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,24 +0,0 @@
|
|||||||
package com.wordnik.swagger.common {
|
|
||||||
public class XMLWriter {
|
|
||||||
public function XMLWriter() {
|
|
||||||
xml = <obj/>;
|
|
||||||
}
|
|
||||||
public var xml:XML;
|
|
||||||
|
|
||||||
public function reset():void {
|
|
||||||
xml = new XML();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function addProperty(propertyName:String, propertyValue:String):XML {
|
|
||||||
var xmlProperty:XML = <new/>
|
|
||||||
xmlProperty.setName(propertyName);
|
|
||||||
xmlProperty.appendChild(propertyValue);
|
|
||||||
xml.appendChild(xmlProperty);
|
|
||||||
return xmlProperty;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function addAttribute(propertyName:String, attribute:String, attributeValue:String):void {
|
|
||||||
xml.elements(propertyName)[0].@[attribute] = attributeValue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,7 +0,0 @@
|
|||||||
package com.wordnik.swagger.exception {
|
|
||||||
public class ApiError extends Error {
|
|
||||||
public function ApiError(id:* = 0, message:* = "") {
|
|
||||||
super(message, id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,32 +0,0 @@
|
|||||||
package com.wordnik.swagger.exception {
|
|
||||||
public class ApiErrorCodes {
|
|
||||||
/**
|
|
||||||
* System exception.
|
|
||||||
*/
|
|
||||||
public static const SYSTEM_EXCEPTION:Number = 0;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* With Arguments as current key.
|
|
||||||
*/
|
|
||||||
public static const API_KEY_NOT_VALID:Number = 1000;
|
|
||||||
/**
|
|
||||||
* With arguments as current token value
|
|
||||||
*/
|
|
||||||
public static const AUTH_TOKEN_NOT_VALID:Number = 1001;
|
|
||||||
/**
|
|
||||||
* With arguments as input JSON and output class anme
|
|
||||||
*/
|
|
||||||
public static const ERROR_CONVERTING_JSON_TO_JAVA:Number = 1002;
|
|
||||||
/**
|
|
||||||
* With arguments as JAVA class name
|
|
||||||
*/
|
|
||||||
public static const ERROR_CONVERTING_JAVA_TO_JSON:Number = 1003;
|
|
||||||
|
|
||||||
public static const ERROR_FROM_WEBSERVICE_CALL:Number = 1004;
|
|
||||||
/**
|
|
||||||
* With arguments as current API server name
|
|
||||||
*/
|
|
||||||
public static const API_SERVER_NOT_VALID:Number = 1005;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,276 @@
|
|||||||
|
package io.swagger.client.api {
|
||||||
|
|
||||||
|
import io.swagger.common.ApiInvoker;
|
||||||
|
import io.swagger.exception.ApiErrorCodes;
|
||||||
|
import io.swagger.exception.ApiError;
|
||||||
|
import io.swagger.common.ApiUserCredentials;
|
||||||
|
import io.swagger.event.Response;
|
||||||
|
import io.swagger.common.SwaggerApi;
|
||||||
|
import io.swagger.client.model.Pet;
|
||||||
|
import flash.filesystem.File;
|
||||||
|
|
||||||
|
import mx.rpc.AsyncToken;
|
||||||
|
import mx.utils.UIDUtil;
|
||||||
|
import flash.utils.Dictionary;
|
||||||
|
import flash.events.EventDispatcher;
|
||||||
|
|
||||||
|
public class PetApi extends SwaggerApi {
|
||||||
|
/**
|
||||||
|
* Constructor for the PetApi api client
|
||||||
|
* @param apiCredentials Wrapper object for tokens and hostName required towards authentication
|
||||||
|
* @param eventDispatcher Optional event dispatcher that when provided is used by the SDK to dispatch any Response
|
||||||
|
*/
|
||||||
|
public function PetApi(apiCredentials: ApiUserCredentials, eventDispatcher: EventDispatcher = null) {
|
||||||
|
super(apiCredentials, eventDispatcher);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static const event_update_pet: String = "update_pet";
|
||||||
|
public static const event_add_pet: String = "add_pet";
|
||||||
|
public static const event_find_pets_by_status: String = "find_pets_by_status";
|
||||||
|
public static const event_find_pets_by_tags: String = "find_pets_by_tags";
|
||||||
|
public static const event_get_pet_by_id: String = "get_pet_by_id";
|
||||||
|
public static const event_update_pet_with_form: String = "update_pet_with_form";
|
||||||
|
public static const event_delete_pet: String = "delete_pet";
|
||||||
|
public static const event_upload_file: String = "upload_file";
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Returns void
|
||||||
|
*/
|
||||||
|
public function update_pet (body: Pet): String {
|
||||||
|
// create path and map variables
|
||||||
|
var path: String = "/pet".replace(/{format}/g,"xml");
|
||||||
|
|
||||||
|
// query params
|
||||||
|
var queryParams: Dictionary = new Dictionary();
|
||||||
|
var headerParams: Dictionary = new Dictionary();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
var token:AsyncToken = getApiInvoker().invokeAPI(path, "PUT", queryParams, body, headerParams);
|
||||||
|
|
||||||
|
var requestId: String = getUniqueId();
|
||||||
|
|
||||||
|
token.requestId = requestId;
|
||||||
|
token.completionEventType = "update_pet";
|
||||||
|
|
||||||
|
token.returnType = null ;
|
||||||
|
return requestId;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Returns void
|
||||||
|
*/
|
||||||
|
public function add_pet (body: Pet): String {
|
||||||
|
// create path and map variables
|
||||||
|
var path: String = "/pet".replace(/{format}/g,"xml");
|
||||||
|
|
||||||
|
// query params
|
||||||
|
var queryParams: Dictionary = new Dictionary();
|
||||||
|
var headerParams: Dictionary = new Dictionary();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
var token:AsyncToken = getApiInvoker().invokeAPI(path, "POST", queryParams, body, headerParams);
|
||||||
|
|
||||||
|
var requestId: String = getUniqueId();
|
||||||
|
|
||||||
|
token.requestId = requestId;
|
||||||
|
token.completionEventType = "add_pet";
|
||||||
|
|
||||||
|
token.returnType = null ;
|
||||||
|
return requestId;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Returns Array
|
||||||
|
*/
|
||||||
|
public function find_pets_by_status (status: Array = available): String {
|
||||||
|
// create path and map variables
|
||||||
|
var path: String = "/pet/findByStatus".replace(/{format}/g,"xml");
|
||||||
|
|
||||||
|
// query params
|
||||||
|
var queryParams: Dictionary = new Dictionary();
|
||||||
|
var headerParams: Dictionary = new Dictionary();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if("null" != String(status))
|
||||||
|
queryParams["status"] = toPathValue(status);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
var token:AsyncToken = getApiInvoker().invokeAPI(path, "GET", queryParams, null, headerParams);
|
||||||
|
|
||||||
|
var requestId: String = getUniqueId();
|
||||||
|
|
||||||
|
token.requestId = requestId;
|
||||||
|
token.completionEventType = "find_pets_by_status";
|
||||||
|
|
||||||
|
token.returnType = Array;
|
||||||
|
return requestId;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Returns Array
|
||||||
|
*/
|
||||||
|
public function find_pets_by_tags (tags: Array): String {
|
||||||
|
// create path and map variables
|
||||||
|
var path: String = "/pet/findByTags".replace(/{format}/g,"xml");
|
||||||
|
|
||||||
|
// query params
|
||||||
|
var queryParams: Dictionary = new Dictionary();
|
||||||
|
var headerParams: Dictionary = new Dictionary();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if("null" != String(tags))
|
||||||
|
queryParams["tags"] = toPathValue(tags);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
var token:AsyncToken = getApiInvoker().invokeAPI(path, "GET", queryParams, null, headerParams);
|
||||||
|
|
||||||
|
var requestId: String = getUniqueId();
|
||||||
|
|
||||||
|
token.requestId = requestId;
|
||||||
|
token.completionEventType = "find_pets_by_tags";
|
||||||
|
|
||||||
|
token.returnType = Array;
|
||||||
|
return requestId;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Returns Pet
|
||||||
|
*/
|
||||||
|
public function get_pet_by_id (petId: Number): String {
|
||||||
|
// create path and map variables
|
||||||
|
var path: String = "/pet/{petId}".replace(/{format}/g,"xml").replace("{" + "petId" + "}", getApiInvoker().escapeString(petId));
|
||||||
|
|
||||||
|
// query params
|
||||||
|
var queryParams: Dictionary = new Dictionary();
|
||||||
|
var headerParams: Dictionary = new Dictionary();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
var token:AsyncToken = getApiInvoker().invokeAPI(path, "GET", queryParams, null, headerParams);
|
||||||
|
|
||||||
|
var requestId: String = getUniqueId();
|
||||||
|
|
||||||
|
token.requestId = requestId;
|
||||||
|
token.completionEventType = "get_pet_by_id";
|
||||||
|
|
||||||
|
token.returnType = Pet;
|
||||||
|
return requestId;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Returns void
|
||||||
|
*/
|
||||||
|
public function update_pet_with_form (petId: String, name: String, status: String): String {
|
||||||
|
// create path and map variables
|
||||||
|
var path: String = "/pet/{petId}".replace(/{format}/g,"xml").replace("{" + "petId" + "}", getApiInvoker().escapeString(petId));
|
||||||
|
|
||||||
|
// query params
|
||||||
|
var queryParams: Dictionary = new Dictionary();
|
||||||
|
var headerParams: Dictionary = new Dictionary();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
var token:AsyncToken = getApiInvoker().invokeAPI(path, "POST", queryParams, null, headerParams);
|
||||||
|
|
||||||
|
var requestId: String = getUniqueId();
|
||||||
|
|
||||||
|
token.requestId = requestId;
|
||||||
|
token.completionEventType = "update_pet_with_form";
|
||||||
|
|
||||||
|
token.returnType = null ;
|
||||||
|
return requestId;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Returns void
|
||||||
|
*/
|
||||||
|
public function delete_pet (petId: Number, apiKey: String): String {
|
||||||
|
// create path and map variables
|
||||||
|
var path: String = "/pet/{petId}".replace(/{format}/g,"xml").replace("{" + "petId" + "}", getApiInvoker().escapeString(petId));
|
||||||
|
|
||||||
|
// query params
|
||||||
|
var queryParams: Dictionary = new Dictionary();
|
||||||
|
var headerParams: Dictionary = new Dictionary();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
headerParams["apiKey"] = toPathValue(apiKey);
|
||||||
|
|
||||||
|
|
||||||
|
var token:AsyncToken = getApiInvoker().invokeAPI(path, "DELETE", queryParams, null, headerParams);
|
||||||
|
|
||||||
|
var requestId: String = getUniqueId();
|
||||||
|
|
||||||
|
token.requestId = requestId;
|
||||||
|
token.completionEventType = "delete_pet";
|
||||||
|
|
||||||
|
token.returnType = null ;
|
||||||
|
return requestId;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Returns void
|
||||||
|
*/
|
||||||
|
public function upload_file (petId: Number, additionalMetadata: String, file: File): String {
|
||||||
|
// create path and map variables
|
||||||
|
var path: String = "/pet/{petId}/uploadImage".replace(/{format}/g,"xml").replace("{" + "petId" + "}", getApiInvoker().escapeString(petId));
|
||||||
|
|
||||||
|
// query params
|
||||||
|
var queryParams: Dictionary = new Dictionary();
|
||||||
|
var headerParams: Dictionary = new Dictionary();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
var token:AsyncToken = getApiInvoker().invokeAPI(path, "POST", queryParams, null, headerParams);
|
||||||
|
|
||||||
|
var requestId: String = getUniqueId();
|
||||||
|
|
||||||
|
token.requestId = requestId;
|
||||||
|
token.completionEventType = "upload_file";
|
||||||
|
|
||||||
|
token.returnType = null ;
|
||||||
|
return requestId;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,150 @@
|
|||||||
|
package io.swagger.client.api {
|
||||||
|
|
||||||
|
import io.swagger.common.ApiInvoker;
|
||||||
|
import io.swagger.exception.ApiErrorCodes;
|
||||||
|
import io.swagger.exception.ApiError;
|
||||||
|
import io.swagger.common.ApiUserCredentials;
|
||||||
|
import io.swagger.event.Response;
|
||||||
|
import io.swagger.common.SwaggerApi;
|
||||||
|
import io.swagger.client.model.Order;
|
||||||
|
|
||||||
|
import mx.rpc.AsyncToken;
|
||||||
|
import mx.utils.UIDUtil;
|
||||||
|
import flash.utils.Dictionary;
|
||||||
|
import flash.events.EventDispatcher;
|
||||||
|
|
||||||
|
public class StoreApi extends SwaggerApi {
|
||||||
|
/**
|
||||||
|
* Constructor for the StoreApi api client
|
||||||
|
* @param apiCredentials Wrapper object for tokens and hostName required towards authentication
|
||||||
|
* @param eventDispatcher Optional event dispatcher that when provided is used by the SDK to dispatch any Response
|
||||||
|
*/
|
||||||
|
public function StoreApi(apiCredentials: ApiUserCredentials, eventDispatcher: EventDispatcher = null) {
|
||||||
|
super(apiCredentials, eventDispatcher);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static const event_get_inventory: String = "get_inventory";
|
||||||
|
public static const event_place_order: String = "place_order";
|
||||||
|
public static const event_get_order_by_id: String = "get_order_by_id";
|
||||||
|
public static const event_delete_order: String = "delete_order";
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Returns Dictionary
|
||||||
|
*/
|
||||||
|
public function get_inventory (): String {
|
||||||
|
// create path and map variables
|
||||||
|
var path: String = "/store/inventory".replace(/{format}/g,"xml");
|
||||||
|
|
||||||
|
// query params
|
||||||
|
var queryParams: Dictionary = new Dictionary();
|
||||||
|
var headerParams: Dictionary = new Dictionary();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
var token:AsyncToken = getApiInvoker().invokeAPI(path, "GET", queryParams, null, headerParams);
|
||||||
|
|
||||||
|
var requestId: String = getUniqueId();
|
||||||
|
|
||||||
|
token.requestId = requestId;
|
||||||
|
token.completionEventType = "get_inventory";
|
||||||
|
|
||||||
|
token.returnType = Dictionary;
|
||||||
|
return requestId;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Returns Order
|
||||||
|
*/
|
||||||
|
public function place_order (body: Order): String {
|
||||||
|
// create path and map variables
|
||||||
|
var path: String = "/store/order".replace(/{format}/g,"xml");
|
||||||
|
|
||||||
|
// query params
|
||||||
|
var queryParams: Dictionary = new Dictionary();
|
||||||
|
var headerParams: Dictionary = new Dictionary();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
var token:AsyncToken = getApiInvoker().invokeAPI(path, "POST", queryParams, body, headerParams);
|
||||||
|
|
||||||
|
var requestId: String = getUniqueId();
|
||||||
|
|
||||||
|
token.requestId = requestId;
|
||||||
|
token.completionEventType = "place_order";
|
||||||
|
|
||||||
|
token.returnType = Order;
|
||||||
|
return requestId;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Returns Order
|
||||||
|
*/
|
||||||
|
public function get_order_by_id (orderId: String): String {
|
||||||
|
// create path and map variables
|
||||||
|
var path: String = "/store/order/{orderId}".replace(/{format}/g,"xml").replace("{" + "orderId" + "}", getApiInvoker().escapeString(orderId));
|
||||||
|
|
||||||
|
// query params
|
||||||
|
var queryParams: Dictionary = new Dictionary();
|
||||||
|
var headerParams: Dictionary = new Dictionary();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
var token:AsyncToken = getApiInvoker().invokeAPI(path, "GET", queryParams, null, headerParams);
|
||||||
|
|
||||||
|
var requestId: String = getUniqueId();
|
||||||
|
|
||||||
|
token.requestId = requestId;
|
||||||
|
token.completionEventType = "get_order_by_id";
|
||||||
|
|
||||||
|
token.returnType = Order;
|
||||||
|
return requestId;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Returns void
|
||||||
|
*/
|
||||||
|
public function delete_order (orderId: String): String {
|
||||||
|
// create path and map variables
|
||||||
|
var path: String = "/store/order/{orderId}".replace(/{format}/g,"xml").replace("{" + "orderId" + "}", getApiInvoker().escapeString(orderId));
|
||||||
|
|
||||||
|
// query params
|
||||||
|
var queryParams: Dictionary = new Dictionary();
|
||||||
|
var headerParams: Dictionary = new Dictionary();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
var token:AsyncToken = getApiInvoker().invokeAPI(path, "DELETE", queryParams, null, headerParams);
|
||||||
|
|
||||||
|
var requestId: String = getUniqueId();
|
||||||
|
|
||||||
|
token.requestId = requestId;
|
||||||
|
token.completionEventType = "delete_order";
|
||||||
|
|
||||||
|
token.returnType = null ;
|
||||||
|
return requestId;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,274 @@
|
|||||||
|
package io.swagger.client.api {
|
||||||
|
|
||||||
|
import io.swagger.common.ApiInvoker;
|
||||||
|
import io.swagger.exception.ApiErrorCodes;
|
||||||
|
import io.swagger.exception.ApiError;
|
||||||
|
import io.swagger.common.ApiUserCredentials;
|
||||||
|
import io.swagger.event.Response;
|
||||||
|
import io.swagger.common.SwaggerApi;
|
||||||
|
import io.swagger.client.model.User;
|
||||||
|
|
||||||
|
import mx.rpc.AsyncToken;
|
||||||
|
import mx.utils.UIDUtil;
|
||||||
|
import flash.utils.Dictionary;
|
||||||
|
import flash.events.EventDispatcher;
|
||||||
|
|
||||||
|
public class UserApi extends SwaggerApi {
|
||||||
|
/**
|
||||||
|
* Constructor for the UserApi api client
|
||||||
|
* @param apiCredentials Wrapper object for tokens and hostName required towards authentication
|
||||||
|
* @param eventDispatcher Optional event dispatcher that when provided is used by the SDK to dispatch any Response
|
||||||
|
*/
|
||||||
|
public function UserApi(apiCredentials: ApiUserCredentials, eventDispatcher: EventDispatcher = null) {
|
||||||
|
super(apiCredentials, eventDispatcher);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static const event_create_user: String = "create_user";
|
||||||
|
public static const event_create_users_with_array_input: String = "create_users_with_array_input";
|
||||||
|
public static const event_create_users_with_list_input: String = "create_users_with_list_input";
|
||||||
|
public static const event_login_user: String = "login_user";
|
||||||
|
public static const event_logout_user: String = "logout_user";
|
||||||
|
public static const event_get_user_by_name: String = "get_user_by_name";
|
||||||
|
public static const event_update_user: String = "update_user";
|
||||||
|
public static const event_delete_user: String = "delete_user";
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Returns void
|
||||||
|
*/
|
||||||
|
public function create_user (body: User): String {
|
||||||
|
// create path and map variables
|
||||||
|
var path: String = "/user".replace(/{format}/g,"xml");
|
||||||
|
|
||||||
|
// query params
|
||||||
|
var queryParams: Dictionary = new Dictionary();
|
||||||
|
var headerParams: Dictionary = new Dictionary();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
var token:AsyncToken = getApiInvoker().invokeAPI(path, "POST", queryParams, body, headerParams);
|
||||||
|
|
||||||
|
var requestId: String = getUniqueId();
|
||||||
|
|
||||||
|
token.requestId = requestId;
|
||||||
|
token.completionEventType = "create_user";
|
||||||
|
|
||||||
|
token.returnType = null ;
|
||||||
|
return requestId;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Returns void
|
||||||
|
*/
|
||||||
|
public function create_users_with_array_input (body: Array): String {
|
||||||
|
// create path and map variables
|
||||||
|
var path: String = "/user/createWithArray".replace(/{format}/g,"xml");
|
||||||
|
|
||||||
|
// query params
|
||||||
|
var queryParams: Dictionary = new Dictionary();
|
||||||
|
var headerParams: Dictionary = new Dictionary();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
var token:AsyncToken = getApiInvoker().invokeAPI(path, "POST", queryParams, body, headerParams);
|
||||||
|
|
||||||
|
var requestId: String = getUniqueId();
|
||||||
|
|
||||||
|
token.requestId = requestId;
|
||||||
|
token.completionEventType = "create_users_with_array_input";
|
||||||
|
|
||||||
|
token.returnType = null ;
|
||||||
|
return requestId;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Returns void
|
||||||
|
*/
|
||||||
|
public function create_users_with_list_input (body: Array): String {
|
||||||
|
// create path and map variables
|
||||||
|
var path: String = "/user/createWithList".replace(/{format}/g,"xml");
|
||||||
|
|
||||||
|
// query params
|
||||||
|
var queryParams: Dictionary = new Dictionary();
|
||||||
|
var headerParams: Dictionary = new Dictionary();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
var token:AsyncToken = getApiInvoker().invokeAPI(path, "POST", queryParams, body, headerParams);
|
||||||
|
|
||||||
|
var requestId: String = getUniqueId();
|
||||||
|
|
||||||
|
token.requestId = requestId;
|
||||||
|
token.completionEventType = "create_users_with_list_input";
|
||||||
|
|
||||||
|
token.returnType = null ;
|
||||||
|
return requestId;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Returns String
|
||||||
|
*/
|
||||||
|
public function login_user (username: String, password: String): String {
|
||||||
|
// create path and map variables
|
||||||
|
var path: String = "/user/login".replace(/{format}/g,"xml");
|
||||||
|
|
||||||
|
// query params
|
||||||
|
var queryParams: Dictionary = new Dictionary();
|
||||||
|
var headerParams: Dictionary = new Dictionary();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if("null" != String(username))
|
||||||
|
queryParams["username"] = toPathValue(username);
|
||||||
|
if("null" != String(password))
|
||||||
|
queryParams["password"] = toPathValue(password);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
var token:AsyncToken = getApiInvoker().invokeAPI(path, "GET", queryParams, null, headerParams);
|
||||||
|
|
||||||
|
var requestId: String = getUniqueId();
|
||||||
|
|
||||||
|
token.requestId = requestId;
|
||||||
|
token.completionEventType = "login_user";
|
||||||
|
|
||||||
|
token.returnType = String;
|
||||||
|
return requestId;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Returns void
|
||||||
|
*/
|
||||||
|
public function logout_user (): String {
|
||||||
|
// create path and map variables
|
||||||
|
var path: String = "/user/logout".replace(/{format}/g,"xml");
|
||||||
|
|
||||||
|
// query params
|
||||||
|
var queryParams: Dictionary = new Dictionary();
|
||||||
|
var headerParams: Dictionary = new Dictionary();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
var token:AsyncToken = getApiInvoker().invokeAPI(path, "GET", queryParams, null, headerParams);
|
||||||
|
|
||||||
|
var requestId: String = getUniqueId();
|
||||||
|
|
||||||
|
token.requestId = requestId;
|
||||||
|
token.completionEventType = "logout_user";
|
||||||
|
|
||||||
|
token.returnType = null ;
|
||||||
|
return requestId;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Returns User
|
||||||
|
*/
|
||||||
|
public function get_user_by_name (username: String): String {
|
||||||
|
// create path and map variables
|
||||||
|
var path: String = "/user/{username}".replace(/{format}/g,"xml").replace("{" + "username" + "}", getApiInvoker().escapeString(username));
|
||||||
|
|
||||||
|
// query params
|
||||||
|
var queryParams: Dictionary = new Dictionary();
|
||||||
|
var headerParams: Dictionary = new Dictionary();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
var token:AsyncToken = getApiInvoker().invokeAPI(path, "GET", queryParams, null, headerParams);
|
||||||
|
|
||||||
|
var requestId: String = getUniqueId();
|
||||||
|
|
||||||
|
token.requestId = requestId;
|
||||||
|
token.completionEventType = "get_user_by_name";
|
||||||
|
|
||||||
|
token.returnType = User;
|
||||||
|
return requestId;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Returns void
|
||||||
|
*/
|
||||||
|
public function update_user (username: String, body: User): String {
|
||||||
|
// create path and map variables
|
||||||
|
var path: String = "/user/{username}".replace(/{format}/g,"xml").replace("{" + "username" + "}", getApiInvoker().escapeString(username));
|
||||||
|
|
||||||
|
// query params
|
||||||
|
var queryParams: Dictionary = new Dictionary();
|
||||||
|
var headerParams: Dictionary = new Dictionary();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
var token:AsyncToken = getApiInvoker().invokeAPI(path, "PUT", queryParams, body, headerParams);
|
||||||
|
|
||||||
|
var requestId: String = getUniqueId();
|
||||||
|
|
||||||
|
token.requestId = requestId;
|
||||||
|
token.completionEventType = "update_user";
|
||||||
|
|
||||||
|
token.returnType = null ;
|
||||||
|
return requestId;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Returns void
|
||||||
|
*/
|
||||||
|
public function delete_user (username: String): String {
|
||||||
|
// create path and map variables
|
||||||
|
var path: String = "/user/{username}".replace(/{format}/g,"xml").replace("{" + "username" + "}", getApiInvoker().escapeString(username));
|
||||||
|
|
||||||
|
// query params
|
||||||
|
var queryParams: Dictionary = new Dictionary();
|
||||||
|
var headerParams: Dictionary = new Dictionary();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
var token:AsyncToken = getApiInvoker().invokeAPI(path, "DELETE", queryParams, null, headerParams);
|
||||||
|
|
||||||
|
var requestId: String = getUniqueId();
|
||||||
|
|
||||||
|
token.requestId = requestId;
|
||||||
|
token.completionEventType = "delete_user";
|
||||||
|
|
||||||
|
token.returnType = null ;
|
||||||
|
return requestId;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,32 @@
|
|||||||
|
package io.swagger.client.model {
|
||||||
|
|
||||||
|
|
||||||
|
[XmlRootNode(name="Category")]
|
||||||
|
public class Category {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
[XmlElement(name="id")]
|
||||||
|
|
||||||
|
public var id: Number = 0;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
[XmlElement(name="name")]
|
||||||
|
|
||||||
|
public var name: String = null;
|
||||||
|
|
||||||
|
|
||||||
|
public function toString(): String {
|
||||||
|
var str: String = "Category: ";
|
||||||
|
|
||||||
|
str += " (id: " + id + ")";
|
||||||
|
|
||||||
|
str += " (name: " + name + ")";
|
||||||
|
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,18 @@
|
|||||||
|
package io.swagger.client.model {
|
||||||
|
|
||||||
|
import io.swagger.common.ListWrapper;
|
||||||
|
|
||||||
|
public class CategoryList implements ListWrapper {
|
||||||
|
// This declaration below of _Category_obj_class is to force flash compiler to include this class
|
||||||
|
private var _category_obj_class: io.swagger.client.model.Category = null;
|
||||||
|
[XmlElements(name="category", type="io.swagger.client.model.Category")]
|
||||||
|
public var category: Array = new Array();
|
||||||
|
|
||||||
|
public function getList(): Array{
|
||||||
|
return category;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,65 @@
|
|||||||
|
package io.swagger.client.model {
|
||||||
|
|
||||||
|
|
||||||
|
[XmlRootNode(name="Order")]
|
||||||
|
public class Order {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
[XmlElement(name="id")]
|
||||||
|
|
||||||
|
public var id: Number = 0;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
[XmlElement(name="petId")]
|
||||||
|
|
||||||
|
public var petId: Number = 0;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
[XmlElement(name="quantity")]
|
||||||
|
|
||||||
|
public var quantity: Number = 0;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
[XmlElement(name="shipDate")]
|
||||||
|
|
||||||
|
public var shipDate: Date = null;
|
||||||
|
|
||||||
|
/* Order Status */
|
||||||
|
|
||||||
|
|
||||||
|
[XmlElement(name="status")]
|
||||||
|
|
||||||
|
public var status: String = null;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
[XmlElement(name="complete")]
|
||||||
|
|
||||||
|
public var complete: Boolean = false;
|
||||||
|
|
||||||
|
|
||||||
|
public function toString(): String {
|
||||||
|
var str: String = "Order: ";
|
||||||
|
|
||||||
|
str += " (id: " + id + ")";
|
||||||
|
|
||||||
|
str += " (petId: " + petId + ")";
|
||||||
|
|
||||||
|
str += " (quantity: " + quantity + ")";
|
||||||
|
|
||||||
|
str += " (shipDate: " + shipDate + ")";
|
||||||
|
|
||||||
|
str += " (status: " + status + ")";
|
||||||
|
|
||||||
|
str += " (complete: " + complete + ")";
|
||||||
|
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,18 @@
|
|||||||
|
package io.swagger.client.model {
|
||||||
|
|
||||||
|
import io.swagger.common.ListWrapper;
|
||||||
|
|
||||||
|
public class OrderList implements ListWrapper {
|
||||||
|
// This declaration below of _Order_obj_class is to force flash compiler to include this class
|
||||||
|
private var _order_obj_class: io.swagger.client.model.Order = null;
|
||||||
|
[XmlElements(name="order", type="io.swagger.client.model.Order")]
|
||||||
|
public var order: Array = new Array();
|
||||||
|
|
||||||
|
public function getList(): Array{
|
||||||
|
return order;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,75 @@
|
|||||||
|
package io.swagger.client.model {
|
||||||
|
|
||||||
|
import io.swagger.client.model.Category;
|
||||||
|
import io.swagger.client.model.Tag;
|
||||||
|
|
||||||
|
[XmlRootNode(name="Pet")]
|
||||||
|
public class Pet {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
[XmlElement(name="id")]
|
||||||
|
|
||||||
|
public var id: Number = 0;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
[XmlElement(name="category")]
|
||||||
|
|
||||||
|
public var category: Category = null;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
[XmlElement(name="name")]
|
||||||
|
|
||||||
|
public var name: String = null;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// This declaration below of _photoUrls_obj_class is to force flash compiler to include this class
|
||||||
|
private var _photoUrls_obj_class: Array = null;
|
||||||
|
[XmlElementWrapper(name="photoUrls")]
|
||||||
|
[XmlElements(name="photoUrls", type="Array")]
|
||||||
|
|
||||||
|
|
||||||
|
public var photoUrls: Array = new Array();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// This declaration below of _tags_obj_class is to force flash compiler to include this class
|
||||||
|
private var _tags_obj_class: Array = null;
|
||||||
|
[XmlElementWrapper(name="tags")]
|
||||||
|
[XmlElements(name="tags", type="Array")]
|
||||||
|
|
||||||
|
|
||||||
|
public var tags: Array = new Array();
|
||||||
|
|
||||||
|
/* pet status in the store */
|
||||||
|
|
||||||
|
|
||||||
|
[XmlElement(name="status")]
|
||||||
|
|
||||||
|
public var status: String = null;
|
||||||
|
|
||||||
|
|
||||||
|
public function toString(): String {
|
||||||
|
var str: String = "Pet: ";
|
||||||
|
|
||||||
|
str += " (id: " + id + ")";
|
||||||
|
|
||||||
|
str += " (category: " + category + ")";
|
||||||
|
|
||||||
|
str += " (name: " + name + ")";
|
||||||
|
|
||||||
|
str += " (photoUrls: " + photoUrls + ")";
|
||||||
|
|
||||||
|
str += " (tags: " + tags + ")";
|
||||||
|
|
||||||
|
str += " (status: " + status + ")";
|
||||||
|
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,20 @@
|
|||||||
|
package io.swagger.client.model {
|
||||||
|
|
||||||
|
import io.swagger.common.ListWrapper;
|
||||||
|
import io.swagger.client.model.Category;
|
||||||
|
import io.swagger.client.model.Tag;
|
||||||
|
|
||||||
|
public class PetList implements ListWrapper {
|
||||||
|
// This declaration below of _Pet_obj_class is to force flash compiler to include this class
|
||||||
|
private var _pet_obj_class: io.swagger.client.model.Pet = null;
|
||||||
|
[XmlElements(name="pet", type="io.swagger.client.model.Pet")]
|
||||||
|
public var pet: Array = new Array();
|
||||||
|
|
||||||
|
public function getList(): Array{
|
||||||
|
return pet;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,32 @@
|
|||||||
|
package io.swagger.client.model {
|
||||||
|
|
||||||
|
|
||||||
|
[XmlRootNode(name="Tag")]
|
||||||
|
public class Tag {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
[XmlElement(name="id")]
|
||||||
|
|
||||||
|
public var id: Number = 0;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
[XmlElement(name="name")]
|
||||||
|
|
||||||
|
public var name: String = null;
|
||||||
|
|
||||||
|
|
||||||
|
public function toString(): String {
|
||||||
|
var str: String = "Tag: ";
|
||||||
|
|
||||||
|
str += " (id: " + id + ")";
|
||||||
|
|
||||||
|
str += " (name: " + name + ")";
|
||||||
|
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,18 @@
|
|||||||
|
package io.swagger.client.model {
|
||||||
|
|
||||||
|
import io.swagger.common.ListWrapper;
|
||||||
|
|
||||||
|
public class TagList implements ListWrapper {
|
||||||
|
// This declaration below of _Tag_obj_class is to force flash compiler to include this class
|
||||||
|
private var _tag_obj_class: io.swagger.client.model.Tag = null;
|
||||||
|
[XmlElements(name="tag", type="io.swagger.client.model.Tag")]
|
||||||
|
public var tag: Array = new Array();
|
||||||
|
|
||||||
|
public function getList(): Array{
|
||||||
|
return tag;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,81 @@
|
|||||||
|
package io.swagger.client.model {
|
||||||
|
|
||||||
|
|
||||||
|
[XmlRootNode(name="User")]
|
||||||
|
public class User {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
[XmlElement(name="id")]
|
||||||
|
|
||||||
|
public var id: Number = 0;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
[XmlElement(name="username")]
|
||||||
|
|
||||||
|
public var username: String = null;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
[XmlElement(name="firstName")]
|
||||||
|
|
||||||
|
public var firstName: String = null;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
[XmlElement(name="lastName")]
|
||||||
|
|
||||||
|
public var lastName: String = null;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
[XmlElement(name="email")]
|
||||||
|
|
||||||
|
public var email: String = null;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
[XmlElement(name="password")]
|
||||||
|
|
||||||
|
public var password: String = null;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
[XmlElement(name="phone")]
|
||||||
|
|
||||||
|
public var phone: String = null;
|
||||||
|
|
||||||
|
/* User Status */
|
||||||
|
|
||||||
|
|
||||||
|
[XmlElement(name="userStatus")]
|
||||||
|
|
||||||
|
public var userStatus: Number = 0;
|
||||||
|
|
||||||
|
|
||||||
|
public function toString(): String {
|
||||||
|
var str: String = "User: ";
|
||||||
|
|
||||||
|
str += " (id: " + id + ")";
|
||||||
|
|
||||||
|
str += " (username: " + username + ")";
|
||||||
|
|
||||||
|
str += " (firstName: " + firstName + ")";
|
||||||
|
|
||||||
|
str += " (lastName: " + lastName + ")";
|
||||||
|
|
||||||
|
str += " (email: " + email + ")";
|
||||||
|
|
||||||
|
str += " (password: " + password + ")";
|
||||||
|
|
||||||
|
str += " (phone: " + phone + ")";
|
||||||
|
|
||||||
|
str += " (userStatus: " + userStatus + ")";
|
||||||
|
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,18 @@
|
|||||||
|
package io.swagger.client.model {
|
||||||
|
|
||||||
|
import io.swagger.common.ListWrapper;
|
||||||
|
|
||||||
|
public class UserList implements ListWrapper {
|
||||||
|
// This declaration below of _User_obj_class is to force flash compiler to include this class
|
||||||
|
private var _user_obj_class: io.swagger.client.model.User = null;
|
||||||
|
[XmlElements(name="user", type="io.swagger.client.model.User")]
|
||||||
|
public var user: Array = new Array();
|
||||||
|
|
||||||
|
public function getList(): Array{
|
||||||
|
return user;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -1,27 +1,6 @@
|
|||||||
package com.wordnik.swagger.common {
|
package io.swagger.common {
|
||||||
import asaxb.xml.bind.ASAXBContext;
|
import io.swagger.event.ApiClientEvent;
|
||||||
import asaxb.xml.bind.Unmarshaller;
|
import io.swagger.event.Response;
|
||||||
|
|
||||||
import com.wordnik.swagger.event.ApiClientEvent;
|
|
||||||
import com.wordnik.swagger.event.Response;
|
|
||||||
import com.wordnik.swagger.common.ApiUserCredentials;
|
|
||||||
|
|
||||||
import flash.events.EventDispatcher;
|
|
||||||
import flash.utils.Dictionary;
|
|
||||||
import flash.utils.describeType;
|
|
||||||
import flash.xml.XMLDocument;
|
|
||||||
import flash.xml.XMLNode;
|
|
||||||
|
|
||||||
import mx.messaging.ChannelSet;
|
|
||||||
import mx.messaging.channels.HTTPChannel;
|
|
||||||
import mx.messaging.messages.HTTPRequestMessage;
|
|
||||||
import mx.rpc.AsyncToken;
|
|
||||||
import mx.rpc.events.FaultEvent;
|
|
||||||
import mx.rpc.events.ResultEvent;
|
|
||||||
import mx.rpc.http.HTTPService;
|
|
||||||
import mx.rpc.xml.SimpleXMLEncoder;
|
|
||||||
import mx.utils.ObjectUtil;
|
|
||||||
|
|
||||||
|
|
||||||
public class ApiInvoker extends EventDispatcher {
|
public class ApiInvoker extends EventDispatcher {
|
||||||
|
|
@ -1,5 +1,5 @@
|
|||||||
package com.wordnik.swagger.common {
|
package io.swagger.common {
|
||||||
import com.wordnik.swagger.common.ApiUserCredentials;
|
import io.swagger.common.ApiUserCredentials;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
@ -12,17 +12,17 @@ internal class ApiUrlHelper {
|
|||||||
|
|
||||||
private static const HTTP_URL_PREFIX:String = "http://";
|
private static const HTTP_URL_PREFIX:String = "http://";
|
||||||
|
|
||||||
internal static function appendTokenInfo(restUrl:String, requestHeader:Object, credentials:ApiUserCredentials):String {
|
internal static function appendTokenInfo(restUrl:String, requestHeader: Object, credentials: ApiUserCredentials): String {
|
||||||
//checks for the presence api credentials on client initialization and not repeated here
|
//checks for the presence api credentials on client initialization and not repeated here
|
||||||
if (restUrl.indexOf("?") == -1) {
|
if(restUrl.indexOf("?") == -1){
|
||||||
restUrl += ( "?" + API_URL_KEY + "=" + credentials.apiToken );
|
restUrl += ( "?" + API_URL_KEY + "=" + credentials.apiToken );
|
||||||
}
|
}
|
||||||
else {
|
else{
|
||||||
restUrl += ( "&" + API_URL_KEY + "=" + credentials.apiToken );
|
restUrl += ( "&" + API_URL_KEY + "=" + credentials.apiToken );
|
||||||
}
|
}
|
||||||
requestHeader.api_key = credentials.apiToken;
|
requestHeader.api_key = credentials.apiToken;
|
||||||
|
|
||||||
if (credentials.authToken != null && credentials.authToken != "") {
|
if(credentials.authToken != null && credentials.authToken != ""){
|
||||||
restUrl += ( "&" + AUTH_TOKEN_URL_KEY + "=" + credentials.authToken );
|
restUrl += ( "&" + AUTH_TOKEN_URL_KEY + "=" + credentials.authToken );
|
||||||
requestHeader.auth_token = credentials.authToken;
|
requestHeader.auth_token = credentials.authToken;
|
||||||
}
|
}
|
||||||
@ -30,7 +30,7 @@ internal class ApiUrlHelper {
|
|||||||
return restUrl;
|
return restUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static function getProxyUrl(hostName:String, proxyPath:String):String {
|
internal static function getProxyUrl(hostName: String, proxyPath: String): String{
|
||||||
if (hostName(hostName.length - 1) == "/") //remove trailing slash
|
if (hostName(hostName.length - 1) == "/") //remove trailing slash
|
||||||
{
|
{
|
||||||
hostName = hostName.substring(0, hostName.length - 1);
|
hostName = hostName.substring(0, hostName.length - 1);
|
@ -1,28 +1,10 @@
|
|||||||
package com.wordnik.swagger.common {
|
package io.swagger.common {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Api account credentials.
|
* Api account credentials.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class ApiUserCredentials {
|
public class ApiUserCredentials {
|
||||||
/**
|
|
||||||
* Constructor of ApiUserCredentials
|
|
||||||
* @param apiToken An apitoken that is passed along with the requests
|
|
||||||
* @param authToken A valid auth_token which could necessary for certain operations
|
|
||||||
* @param hostName The host name for the Rest API eg. api.companyName.com
|
|
||||||
* @param userId The userId which is required for certain operations - currently, get user lists
|
|
||||||
*/
|
|
||||||
public function ApiUserCredentials(hostName:String, apiPath:String, apiToken:String,
|
|
||||||
authToken:String = null, userId:Number = -1, apiProxyServerUrl:String = "",
|
|
||||||
proxyPath:String = null) {
|
|
||||||
this.hostName = hostName;
|
|
||||||
this.apiToken = apiToken;
|
|
||||||
this.authToken = authToken;
|
|
||||||
this.userId = userId;
|
|
||||||
this.apiPath = apiPath;
|
|
||||||
this.apiProxyServerUrl = apiProxyServerUrl;
|
|
||||||
this.proxyPath = proxyPath;
|
|
||||||
}
|
|
||||||
/**
|
/**
|
||||||
* An apitoken that is passed along with the requests
|
* An apitoken that is passed along with the requests
|
||||||
*/
|
*/
|
||||||
@ -39,21 +21,43 @@ public class ApiUserCredentials {
|
|||||||
* The host name for the Rest API eg. api.companyName.com
|
* The host name for the Rest API eg. api.companyName.com
|
||||||
*/
|
*/
|
||||||
public var hostName:String;
|
public var hostName:String;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The base path to the api resources - used along with the hostname
|
||||||
|
* eg. /v4
|
||||||
|
*/
|
||||||
|
public var apiPath: String;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The base path to the blazeds proxy
|
||||||
|
* eg. /v4/messagebroker/restproxy
|
||||||
|
*/
|
||||||
|
public var proxyPath: String;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If a proxy server has been set up for the services specify the URL here. This value is used when the Api is invoked with
|
||||||
|
* the value useProxy as true
|
||||||
|
*/
|
||||||
|
public var apiProxyServerUrl: String;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The base path to the api resources - used along with the hostname
|
* Constructor of ApiUserCredentials
|
||||||
* eg. /v4
|
* @param apiToken An apitoken that is passed along with the requests
|
||||||
|
* @param authToken A valid auth_token which could necessary for certain operations
|
||||||
|
* @param hostName The host name for the Rest API eg. api.companyName.com
|
||||||
|
* @param userId The userId which is required for certain operations - currently, get user lists
|
||||||
*/
|
*/
|
||||||
public var apiPath:String;
|
public function ApiUserCredentials(hostName: String, apiPath: String, apiToken: String,
|
||||||
/**
|
authToken: String = null, userId: Number = -1, apiProxyServerUrl: String="",
|
||||||
* The base path to the blazeds proxy
|
proxyPath: String = null) {
|
||||||
* eg. /v4/messagebroker/restproxy
|
this.hostName = hostName;
|
||||||
*/
|
this.apiToken = apiToken;
|
||||||
public var proxyPath:String;
|
this.authToken = authToken;
|
||||||
/**
|
this.userId = userId;
|
||||||
* If a proxy server has been set up for the services specify the URL here. This value is used when the Api is invoked with
|
this.apiPath = apiPath;
|
||||||
* the value useProxy as true
|
this.apiProxyServerUrl = apiProxyServerUrl;
|
||||||
*/
|
this.proxyPath = proxyPath;
|
||||||
public var apiProxyServerUrl:String;
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
package io.swagger.common
|
||||||
|
{
|
||||||
|
public interface ListWrapper
|
||||||
|
{
|
||||||
|
|
||||||
|
function getList(): Array;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,75 @@
|
|||||||
|
package io.swagger.common
|
||||||
|
{
|
||||||
|
import io.swagger.common.ApiUserCredentials;
|
||||||
|
|
||||||
|
import flash.events.EventDispatcher;
|
||||||
|
import flash.events.IEventDispatcher;
|
||||||
|
|
||||||
|
import mx.utils.UIDUtil;
|
||||||
|
|
||||||
|
public class SwaggerApi extends EventDispatcher
|
||||||
|
{
|
||||||
|
|
||||||
|
protected var _apiUsageCredentials:ApiUserCredentials;
|
||||||
|
protected var _apiEventNotifier:EventDispatcher;
|
||||||
|
protected var _apiInvoker: ApiInvoker;
|
||||||
|
|
||||||
|
protected var _useProxyServer: Boolean = false;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for the api client
|
||||||
|
* @param apiCredentials Wrapper object for tokens and hostName required towards authentication
|
||||||
|
* @param eventDispatcher Optional event dispatcher that when provided is used by the SDK to dispatch any Response
|
||||||
|
*/
|
||||||
|
public function SwaggerApi(apiCredentials: ApiUserCredentials, eventDispatcher: EventDispatcher = null) {
|
||||||
|
super();
|
||||||
|
_apiUsageCredentials = apiCredentials;
|
||||||
|
_apiEventNotifier = eventDispatcher;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function useProxyServer(value:Boolean, proxyServerUrl: String = null):void {
|
||||||
|
_useProxyServer = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getApiInvoker():ApiInvoker {
|
||||||
|
if(_apiInvoker == null){
|
||||||
|
if(_apiEventNotifier == null){
|
||||||
|
_apiEventNotifier = this;
|
||||||
|
}
|
||||||
|
_apiInvoker = new ApiInvoker(_apiUsageCredentials, _apiEventNotifier, _useProxyServer);
|
||||||
|
}
|
||||||
|
return _apiInvoker;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getUniqueId():String {
|
||||||
|
return UIDUtil.createUID();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method for returning the path value
|
||||||
|
* For a string value an empty value is returned if the value is null
|
||||||
|
* @param value
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
protected static function toPathValue(value: Object): String {
|
||||||
|
if(value is Array){
|
||||||
|
return arrayToPathValue(value as Array);
|
||||||
|
}
|
||||||
|
return value == null ? "" : value.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method for returning a path value
|
||||||
|
* For a list of objects a comma separated string is returned
|
||||||
|
* @param objects
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
protected static function arrayToPathValue(objects: Array): String {
|
||||||
|
var out: String = "";
|
||||||
|
|
||||||
|
return objects.join(",");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,28 @@
|
|||||||
|
package io.swagger.common
|
||||||
|
{
|
||||||
|
public class XMLWriter
|
||||||
|
{
|
||||||
|
public var xml:XML;
|
||||||
|
|
||||||
|
public function XMLWriter()
|
||||||
|
{
|
||||||
|
xml=<obj/>;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function reset():void {
|
||||||
|
xml=new XML();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addProperty(propertyName:String, propertyValue:String):XML {
|
||||||
|
var xmlProperty:XML=<new/>
|
||||||
|
xmlProperty.setName(propertyName);
|
||||||
|
xmlProperty.appendChild(propertyValue);
|
||||||
|
xml.appendChild(xmlProperty);
|
||||||
|
return xmlProperty;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addAttribute(propertyName:String, attribute:String, attributeValue:String):void {
|
||||||
|
xml.elements(propertyName)[0].@[attribute]=attributeValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,5 @@
|
|||||||
package com.wordnik.swagger.event {
|
package io.swagger.event {
|
||||||
import com.wordnik.swagger.event.Response;
|
import io.swagger.event.Response;
|
||||||
|
|
||||||
import flash.events.Event;
|
import flash.events.Event;
|
||||||
|
|
||||||
@ -8,7 +8,7 @@ import flash.events.Event;
|
|||||||
* If a custom dispatcher has been assigned by the consumer on the generated client then the dispatcher dispatches
|
* If a custom dispatcher has been assigned by the consumer on the generated client then the dispatcher dispatches
|
||||||
* the ApiClientEvent to indicate success or failure of the invocation using the Response
|
* the ApiClientEvent to indicate success or failure of the invocation using the Response
|
||||||
*/
|
*/
|
||||||
public class ApiClientEvent extends Event {
|
public class ApiClientEvent extends Event{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Event type to indicate a unsuccessful invocation
|
* Event type to indicate a unsuccessful invocation
|
||||||
@ -19,17 +19,18 @@ public class ApiClientEvent extends Event {
|
|||||||
* Event type to indicate a successful invocation
|
* Event type to indicate a successful invocation
|
||||||
*/
|
*/
|
||||||
public static const SUCCESS_EVENT:String = "successfulInvocation";
|
public static const SUCCESS_EVENT:String = "successfulInvocation";
|
||||||
|
|
||||||
public function ApiClientEvent(type:String, bubbles:Boolean = false, cancelable:Boolean = false) {
|
|
||||||
super(type, bubbles, cancelable);
|
|
||||||
}
|
|
||||||
/**
|
/**
|
||||||
* The Response object which contains response info
|
* The Response object which contains response info
|
||||||
*/
|
*/
|
||||||
public var response:Response;
|
public var response: Response;
|
||||||
/**
|
/**
|
||||||
* Any additional info
|
* Any additional info
|
||||||
*/
|
*/
|
||||||
public var message:String;
|
public var message:String;
|
||||||
|
|
||||||
|
public function ApiClientEvent(type:String,bubbles:Boolean = false,cancelable:Boolean = false) {
|
||||||
|
super(type, bubbles, cancelable);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package com.wordnik.swagger.event {
|
package io.swagger.event {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Response contains info on the result of an API invocation.
|
* Response contains info on the result of an API invocation.
|
||||||
@ -6,47 +6,50 @@ package com.wordnik.swagger.event {
|
|||||||
*/
|
*/
|
||||||
public class Response {
|
public class Response {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates whether the invoked operation failed or succeeded
|
||||||
|
*/
|
||||||
|
public var isSuccess:Boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The payload of the succesful operation eg. a Word in a WordRequest
|
||||||
|
*/
|
||||||
|
public var payload:Object;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Error message in case of failure
|
||||||
|
*/
|
||||||
|
public var errorMessage:String;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A request Id that was passed in by the user as a param when invoking the operation
|
||||||
|
*/
|
||||||
|
public var requestId:String;
|
||||||
private static const API_ERROR_MSG:String = "Api error response: ";
|
private static const API_ERROR_MSG:String = "Api error response: ";
|
||||||
|
|
||||||
private static function getFriendlyMessage(errorMessage:String):String {
|
public function Response(isSuccessful: Boolean, payload: Object = null, errorMessage: String = null, requestId: String = null) {
|
||||||
var result:String = errorMessage;
|
this.isSuccess = isSuccessful;
|
||||||
if (errorMessage == null)
|
this.payload = payload;
|
||||||
|
this.errorMessage = getFriendlyMessage(errorMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static function getFriendlyMessage(errorMessage: String): String{
|
||||||
|
var result: String = errorMessage;
|
||||||
|
if(errorMessage == null)
|
||||||
return null;
|
return null;
|
||||||
var errorCode:String;
|
var errorCode: String;
|
||||||
var errorCodeArray:Array = errorMessage.match(/(?<=HTTP\/1.1 )[0-9][0-9][0-9]/);
|
var errorCodeArray: Array = errorMessage.match(/(?<=HTTP\/1.1 )[0-9][0-9][0-9]/);
|
||||||
if (errorCodeArray != null && errorCodeArray.length == 1) {
|
if(errorCodeArray != null && errorCodeArray.length == 1){
|
||||||
errorCode = String(errorCodeArray[0]);
|
errorCode = String(errorCodeArray[0]);
|
||||||
}
|
}
|
||||||
var msgArray:Array = errorMessage.match(/(?<=HTTP\/1.1 [0-9][0-9][0-9] )[^]*/);
|
var msgArray: Array = errorMessage.match(/(?<=HTTP\/1.1 [0-9][0-9][0-9] )[^]*/);
|
||||||
if (msgArray != null && msgArray.length == 1) {
|
if(msgArray != null && msgArray.length == 1){
|
||||||
result = API_ERROR_MSG + String(msgArray[0]);
|
result = API_ERROR_MSG + String(msgArray[0]);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function Response(isSuccessful:Boolean, payload:Object = null, errorMessage:String = null, requestId:String = null) {
|
public function toString(): String {
|
||||||
this.isSuccess = isSuccessful;
|
|
||||||
this.payload = payload;
|
|
||||||
this.errorMessage = getFriendlyMessage(errorMessage);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Indicates whether the invoked operation failed or succeeded
|
|
||||||
*/
|
|
||||||
public var isSuccess:Boolean;
|
|
||||||
/**
|
|
||||||
* The payload of the succesful operation eg. a Word in a WordRequest
|
|
||||||
*/
|
|
||||||
public var payload:Object;
|
|
||||||
/**
|
|
||||||
* Error message in case of failure
|
|
||||||
*/
|
|
||||||
public var errorMessage:String;
|
|
||||||
/**
|
|
||||||
* A request Id that was passed in by the user as a param when invoking the operation
|
|
||||||
*/
|
|
||||||
public var requestId:String;
|
|
||||||
|
|
||||||
public function toString():String {
|
|
||||||
return "Response (requestId:" + requestId + "; isSuccess:" + isSuccess + "; errorMessage:" + errorMessage + "; payload:" + payload + ")";
|
return "Response (requestId:" + requestId + "; isSuccess:" + isSuccess + "; errorMessage:" + errorMessage + "; payload:" + payload + ")";
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -0,0 +1,34 @@
|
|||||||
|
package io.swagger.exception
|
||||||
|
{
|
||||||
|
public class ApiErrorCodes
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* System exception.
|
||||||
|
*/
|
||||||
|
public static const SYSTEM_EXCEPTION: Number = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* With Arguments as current key.
|
||||||
|
*/
|
||||||
|
public static const API_KEY_NOT_VALID: Number = 1000;
|
||||||
|
/**
|
||||||
|
* With arguments as current token value
|
||||||
|
*/
|
||||||
|
public static const AUTH_TOKEN_NOT_VALID: Number = 1001;
|
||||||
|
/**
|
||||||
|
* With arguments as input JSON and output class anme
|
||||||
|
*/
|
||||||
|
public static const ERROR_CONVERTING_JSON_TO_JAVA: Number = 1002;
|
||||||
|
/**
|
||||||
|
* With arguments as JAVA class name
|
||||||
|
*/
|
||||||
|
public static const ERROR_CONVERTING_JAVA_TO_JSON: Number = 1003;
|
||||||
|
|
||||||
|
public static const ERROR_FROM_WEBSERVICE_CALL: Number = 1004;
|
||||||
|
/**
|
||||||
|
* With arguments as current API server name
|
||||||
|
*/
|
||||||
|
public static const API_SERVER_NOT_VALID: Number = 1005;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,10 @@
|
|||||||
|
package io.swagger.exception
|
||||||
|
{
|
||||||
|
public class ApiError extends Error
|
||||||
|
{
|
||||||
|
public function ApiError(id:*=0, message:*="")
|
||||||
|
{
|
||||||
|
super(message,id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -243,7 +243,7 @@ public class PetApi {
|
|||||||
};
|
};
|
||||||
final String contentType = apiClient.selectHeaderContentType(contentTypes);
|
final String contentType = apiClient.selectHeaderContentType(contentTypes);
|
||||||
|
|
||||||
String[] authNames = new String[] { "api_key", "petstore_auth" };
|
String[] authNames = new String[] { "petstore_auth", "api_key" };
|
||||||
|
|
||||||
TypeRef returnType = new TypeRef<Pet>() {};
|
TypeRef returnType = new TypeRef<Pet>() {};
|
||||||
return apiClient.invokeAPI(path, "GET", queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType);
|
return apiClient.invokeAPI(path, "GET", queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType);
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
package io.swagger.client.model;
|
package io.swagger.client.model;
|
||||||
|
|
||||||
import io.swagger.client.model.Category;
|
import io.swagger.client.model.Category;
|
||||||
import io.swagger.client.model.Tag;
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import io.swagger.client.model.Tag;
|
||||||
|
|
||||||
import io.swagger.annotations.*;
|
import io.swagger.annotations.*;
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
@ -243,7 +243,7 @@ public class PetApi {
|
|||||||
};
|
};
|
||||||
final String contentType = apiClient.selectHeaderContentType(contentTypes);
|
final String contentType = apiClient.selectHeaderContentType(contentTypes);
|
||||||
|
|
||||||
String[] authNames = new String[] { "api_key", "petstore_auth" };
|
String[] authNames = new String[] { "petstore_auth", "api_key" };
|
||||||
|
|
||||||
TypeRef returnType = new TypeRef<Pet>() {};
|
TypeRef returnType = new TypeRef<Pet>() {};
|
||||||
return apiClient.invokeAPI(path, "GET", queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType);
|
return apiClient.invokeAPI(path, "GET", queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType);
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
package io.swagger.client.model;
|
package io.swagger.client.model;
|
||||||
|
|
||||||
import io.swagger.client.model.Category;
|
import io.swagger.client.model.Category;
|
||||||
import io.swagger.client.model.Tag;
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import io.swagger.client.model.Tag;
|
||||||
|
|
||||||
import io.swagger.annotations.*;
|
import io.swagger.annotations.*;
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
@ -19,6 +19,8 @@
|
|||||||
#import "SWGOrder.h"
|
#import "SWGOrder.h"
|
||||||
|
|
||||||
|
|
||||||
|
@class SWGConfiguration;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A key for `NSError` user info dictionaries.
|
* A key for `NSError` user info dictionaries.
|
||||||
*
|
*
|
||||||
@ -33,22 +35,6 @@ extern NSString *const SWGResponseObjectErrorKey;
|
|||||||
@property(nonatomic, assign) NSTimeInterval timeoutInterval;
|
@property(nonatomic, assign) NSTimeInterval timeoutInterval;
|
||||||
@property(nonatomic, readonly) NSOperationQueue* queue;
|
@property(nonatomic, readonly) NSOperationQueue* queue;
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the Api Client instance from pool
|
|
||||||
*
|
|
||||||
* @param baseUrl The base url of api client.
|
|
||||||
*
|
|
||||||
* @return The SWGApiClient instance.
|
|
||||||
*/
|
|
||||||
+(SWGApiClient *)sharedClientFromPool:(NSString *)baseUrl;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the operations queue
|
|
||||||
*
|
|
||||||
* @return The `shardQueue` static variable.
|
|
||||||
*/
|
|
||||||
+(NSOperationQueue*) sharedQueue;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clears Cache
|
* Clears Cache
|
||||||
*/
|
*/
|
||||||
@ -120,11 +106,9 @@ extern NSString *const SWGResponseObjectErrorKey;
|
|||||||
+(void) setReachabilityChangeBlock:(void(^)(int))changeBlock;
|
+(void) setReachabilityChangeBlock:(void(^)(int))changeBlock;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the client reachability strategy
|
* Sets the api client reachability strategy
|
||||||
*
|
|
||||||
* @param host The host of SWGApiClient.
|
|
||||||
*/
|
*/
|
||||||
+(void) configureCacheReachibilityForHost:(NSString*)host;
|
- (void)configureCacheReachibility;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Detects Accept header from accepts NSArray
|
* Detects Accept header from accepts NSArray
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
#import "SWGApiClient.h"
|
#import "SWGApiClient.h"
|
||||||
|
|
||||||
@implementation SWGApiClient
|
|
||||||
|
|
||||||
NSString *const SWGResponseObjectErrorKey = @"SWGResponseObject";
|
NSString *const SWGResponseObjectErrorKey = @"SWGResponseObject";
|
||||||
|
|
||||||
static long requestId = 0;
|
static long requestId = 0;
|
||||||
@ -9,41 +7,75 @@ static bool offlineState = false;
|
|||||||
static NSMutableSet * queuedRequests = nil;
|
static NSMutableSet * queuedRequests = nil;
|
||||||
static bool cacheEnabled = false;
|
static bool cacheEnabled = false;
|
||||||
static AFNetworkReachabilityStatus reachabilityStatus = AFNetworkReachabilityStatusNotReachable;
|
static AFNetworkReachabilityStatus reachabilityStatus = AFNetworkReachabilityStatusNotReachable;
|
||||||
static NSOperationQueue* sharedQueue;
|
|
||||||
static void (^reachabilityChangeBlock)(int);
|
static void (^reachabilityChangeBlock)(int);
|
||||||
|
|
||||||
|
@implementation SWGApiClient
|
||||||
|
|
||||||
|
- (instancetype)init {
|
||||||
|
NSString *baseUrl = [[SWGConfiguration sharedConfig] host];
|
||||||
|
return [self initWithBaseURL:[NSURL URLWithString:baseUrl]];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (instancetype)initWithBaseURL:(NSURL *)url {
|
||||||
|
self = [super initWithBaseURL:url];
|
||||||
|
if (self) {
|
||||||
|
self.requestSerializer = [AFJSONRequestSerializer serializer];
|
||||||
|
self.responseSerializer = [AFJSONResponseSerializer serializer];
|
||||||
|
// configure reachability
|
||||||
|
[self configureCacheReachibility];
|
||||||
|
}
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
+ (void)initialize {
|
||||||
|
if (self == [SWGApiClient class]) {
|
||||||
|
queuedRequests = [[NSMutableSet alloc] init];
|
||||||
|
// initialize URL cache
|
||||||
|
[self configureCacheWithMemoryAndDiskCapacity:4*1024*1024 diskSize:32*1024*1024];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#pragma mark - Setter Methods
|
||||||
|
|
||||||
|
+ (void) setOfflineState:(BOOL) state {
|
||||||
|
offlineState = state;
|
||||||
|
}
|
||||||
|
|
||||||
|
+ (void) setCacheEnabled:(BOOL)enabled {
|
||||||
|
cacheEnabled = enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)setHeaderValue:(NSString*) value
|
||||||
|
forKey:(NSString*) forKey {
|
||||||
|
[self.requestSerializer setValue:value forHTTPHeaderField:forKey];
|
||||||
|
}
|
||||||
|
|
||||||
#pragma mark - Log Methods
|
#pragma mark - Log Methods
|
||||||
|
|
||||||
- (void)logResponse:(AFHTTPRequestOperation *)operation
|
- (void)logResponse:(AFHTTPRequestOperation *)operation
|
||||||
forRequest:(NSURLRequest *)request
|
forRequest:(NSURLRequest *)request
|
||||||
error:(NSError*)error {
|
error:(NSError*)error {
|
||||||
SWGConfiguration *config = [SWGConfiguration sharedConfig];
|
SWGConfiguration *config = [SWGConfiguration sharedConfig];
|
||||||
|
|
||||||
NSString *message = [NSString stringWithFormat:@"\n[DEBUG] Request body \n~BEGIN~\n %@\n~END~\n"\
|
NSString *message = [NSString stringWithFormat:@"\n[DEBUG] Request body \n~BEGIN~\n %@\n~END~\n"\
|
||||||
"[DEBUG] HTTP Response body \n~BEGIN~\n %@\n~END~\n",
|
"[DEBUG] HTTP Response body \n~BEGIN~\n %@\n~END~\n",
|
||||||
[[NSString alloc] initWithData:request.HTTPBody encoding:NSUTF8StringEncoding],
|
[[NSString alloc] initWithData:request.HTTPBody encoding:NSUTF8StringEncoding],
|
||||||
operation.responseString];
|
operation.responseString];
|
||||||
|
|
||||||
if (config.loggingFileHanlder) {
|
if (config.loggingFileHanlder) {
|
||||||
[config.loggingFileHanlder seekToEndOfFile];
|
[config.loggingFileHanlder seekToEndOfFile];
|
||||||
[config.loggingFileHanlder writeData:[message dataUsingEncoding:NSUTF8StringEncoding]];
|
[config.loggingFileHanlder writeData:[message dataUsingEncoding:NSUTF8StringEncoding]];
|
||||||
}
|
}
|
||||||
|
|
||||||
NSLog(@"%@", message);
|
NSLog(@"%@", message);
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma mark - Cache Methods
|
#pragma mark - Cache Methods
|
||||||
|
|
||||||
+ (void) setCacheEnabled:(BOOL)enabled {
|
|
||||||
cacheEnabled = enabled;
|
|
||||||
}
|
|
||||||
|
|
||||||
+(void)clearCache {
|
+(void)clearCache {
|
||||||
[[NSURLCache sharedURLCache] removeAllCachedResponses];
|
[[NSURLCache sharedURLCache] removeAllCachedResponses];
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma mark -
|
|
||||||
|
|
||||||
+(void)configureCacheWithMemoryAndDiskCapacity: (unsigned long) memorySize
|
+(void)configureCacheWithMemoryAndDiskCapacity: (unsigned long) memorySize
|
||||||
diskSize: (unsigned long) diskSize {
|
diskSize: (unsigned long) diskSize {
|
||||||
NSAssert(memorySize > 0, @"invalid in-memory cache size");
|
NSAssert(memorySize > 0, @"invalid in-memory cache size");
|
||||||
@ -58,43 +90,7 @@ static void (^reachabilityChangeBlock)(int);
|
|||||||
[NSURLCache setSharedURLCache:cache];
|
[NSURLCache setSharedURLCache:cache];
|
||||||
}
|
}
|
||||||
|
|
||||||
+(NSOperationQueue*) sharedQueue {
|
#pragma mark - Utility Methods
|
||||||
return sharedQueue;
|
|
||||||
}
|
|
||||||
|
|
||||||
+(SWGApiClient *)sharedClientFromPool:(NSString *)baseUrl {
|
|
||||||
static NSMutableDictionary *_pool = nil;
|
|
||||||
if (queuedRequests == nil) {
|
|
||||||
queuedRequests = [[NSMutableSet alloc]init];
|
|
||||||
}
|
|
||||||
if(_pool == nil) {
|
|
||||||
// setup static vars
|
|
||||||
// create queue
|
|
||||||
sharedQueue = [[NSOperationQueue alloc] init];
|
|
||||||
|
|
||||||
// create pool
|
|
||||||
_pool = [[NSMutableDictionary alloc] init];
|
|
||||||
|
|
||||||
// initialize URL cache
|
|
||||||
[SWGApiClient configureCacheWithMemoryAndDiskCapacity:4*1024*1024 diskSize:32*1024*1024];
|
|
||||||
|
|
||||||
// configure reachability
|
|
||||||
[SWGApiClient configureCacheReachibilityForHost:baseUrl];
|
|
||||||
}
|
|
||||||
|
|
||||||
@synchronized(self) {
|
|
||||||
SWGApiClient * client = [_pool objectForKey:baseUrl];
|
|
||||||
if (client == nil) {
|
|
||||||
client = [[SWGApiClient alloc] initWithBaseURL:[NSURL URLWithString:baseUrl]];
|
|
||||||
[_pool setValue:client forKey:baseUrl ];
|
|
||||||
if([[SWGConfiguration sharedConfig] debug])
|
|
||||||
NSLog(@"new client for path %@", baseUrl);
|
|
||||||
}
|
|
||||||
if([[SWGConfiguration sharedConfig] debug])
|
|
||||||
NSLog(@"returning client for path %@", baseUrl);
|
|
||||||
return client;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Detect `Accept` from accepts
|
* Detect `Accept` from accepts
|
||||||
@ -104,13 +100,13 @@ static void (^reachabilityChangeBlock)(int);
|
|||||||
if (accepts == nil || [accepts count] == 0) {
|
if (accepts == nil || [accepts count] == 0) {
|
||||||
return @"";
|
return @"";
|
||||||
}
|
}
|
||||||
|
|
||||||
NSMutableArray *lowerAccepts = [[NSMutableArray alloc] initWithCapacity:[accepts count]];
|
NSMutableArray *lowerAccepts = [[NSMutableArray alloc] initWithCapacity:[accepts count]];
|
||||||
[accepts enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
|
[accepts enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
|
||||||
[lowerAccepts addObject:[obj lowercaseString]];
|
[lowerAccepts addObject:[obj lowercaseString]];
|
||||||
}];
|
}];
|
||||||
|
|
||||||
|
|
||||||
if ([lowerAccepts containsObject:@"application/json"]) {
|
if ([lowerAccepts containsObject:@"application/json"]) {
|
||||||
return @"application/json";
|
return @"application/json";
|
||||||
}
|
}
|
||||||
@ -127,7 +123,7 @@ static void (^reachabilityChangeBlock)(int);
|
|||||||
if (contentTypes == nil || [contentTypes count] == 0) {
|
if (contentTypes == nil || [contentTypes count] == 0) {
|
||||||
return @"application/json";
|
return @"application/json";
|
||||||
}
|
}
|
||||||
|
|
||||||
NSMutableArray *lowerContentTypes = [[NSMutableArray alloc] initWithCapacity:[contentTypes count]];
|
NSMutableArray *lowerContentTypes = [[NSMutableArray alloc] initWithCapacity:[contentTypes count]];
|
||||||
[contentTypes enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
|
[contentTypes enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
|
||||||
[lowerContentTypes addObject:[obj lowercaseString]];
|
[lowerContentTypes addObject:[obj lowercaseString]];
|
||||||
@ -141,11 +137,23 @@ static void (^reachabilityChangeBlock)(int);
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
-(void)setHeaderValue:(NSString*) value
|
+ (NSString*)escape:(id)unescaped {
|
||||||
forKey:(NSString*) forKey {
|
if([unescaped isKindOfClass:[NSString class]]){
|
||||||
[self.requestSerializer setValue:value forHTTPHeaderField:forKey];
|
return (NSString *)CFBridgingRelease
|
||||||
|
(CFURLCreateStringByAddingPercentEscapes(
|
||||||
|
NULL,
|
||||||
|
(__bridge CFStringRef) unescaped,
|
||||||
|
NULL,
|
||||||
|
(CFStringRef)@"!*'();:@&=+$,/?%#[]",
|
||||||
|
kCFStringEncodingUTF8));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return [NSString stringWithFormat:@"%@", unescaped];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#pragma mark - Request Methods
|
||||||
|
|
||||||
+(unsigned long)requestQueueSize {
|
+(unsigned long)requestQueueSize {
|
||||||
return [queuedRequests count];
|
return [queuedRequests count];
|
||||||
}
|
}
|
||||||
@ -171,46 +179,28 @@ static void (^reachabilityChangeBlock)(int);
|
|||||||
[queuedRequests removeObject:requestId];
|
[queuedRequests removeObject:requestId];
|
||||||
}
|
}
|
||||||
|
|
||||||
+(NSString*) escape:(id)unescaped {
|
|
||||||
if([unescaped isKindOfClass:[NSString class]]){
|
|
||||||
return (NSString *)CFBridgingRelease
|
|
||||||
(CFURLCreateStringByAddingPercentEscapes(
|
|
||||||
NULL,
|
|
||||||
(__bridge CFStringRef) unescaped,
|
|
||||||
NULL,
|
|
||||||
(CFStringRef)@"!*'();:@&=+$,/?%#[]",
|
|
||||||
kCFStringEncodingUTF8));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return [NSString stringWithFormat:@"%@", unescaped];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
-(Boolean) executeRequestWithId:(NSNumber*) requestId {
|
-(Boolean) executeRequestWithId:(NSNumber*) requestId {
|
||||||
NSSet* matchingItems = [queuedRequests objectsPassingTest:^BOOL(id obj, BOOL *stop) {
|
NSSet* matchingItems = [queuedRequests objectsPassingTest:^BOOL(id obj, BOOL *stop) {
|
||||||
if([obj intValue] == [requestId intValue])
|
if([obj intValue] == [requestId intValue]) {
|
||||||
return TRUE;
|
return YES;
|
||||||
else return FALSE;
|
}
|
||||||
|
else {
|
||||||
|
return NO;
|
||||||
|
}
|
||||||
}];
|
}];
|
||||||
|
|
||||||
if(matchingItems.count == 1) {
|
if(matchingItems.count == 1) {
|
||||||
if([[SWGConfiguration sharedConfig] debug])
|
if([[SWGConfiguration sharedConfig] debug])
|
||||||
NSLog(@"removing request id %@", requestId);
|
NSLog(@"removing request id %@", requestId);
|
||||||
[queuedRequests removeObject:requestId];
|
[queuedRequests removeObject:requestId];
|
||||||
return true;
|
return YES;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return NO;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
-(id)initWithBaseURL:(NSURL *)url {
|
#pragma mark - Reachability Methods
|
||||||
self = [super initWithBaseURL:url];
|
|
||||||
self.requestSerializer = [AFJSONRequestSerializer serializer];
|
|
||||||
self.responseSerializer = [AFJSONResponseSerializer serializer];
|
|
||||||
if (!self)
|
|
||||||
return nil;
|
|
||||||
return self;
|
|
||||||
}
|
|
||||||
|
|
||||||
+(AFNetworkReachabilityStatus) getReachabilityStatus {
|
+(AFNetworkReachabilityStatus) getReachabilityStatus {
|
||||||
return reachabilityStatus;
|
return reachabilityStatus;
|
||||||
@ -220,12 +210,8 @@ static void (^reachabilityChangeBlock)(int);
|
|||||||
reachabilityChangeBlock = changeBlock;
|
reachabilityChangeBlock = changeBlock;
|
||||||
}
|
}
|
||||||
|
|
||||||
+(void) setOfflineState:(BOOL) state {
|
- (void) configureCacheReachibility {
|
||||||
offlineState = state;
|
[self.reachabilityManager setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
|
||||||
}
|
|
||||||
|
|
||||||
+(void) configureCacheReachibilityForHost:(NSString*)host {
|
|
||||||
[[SWGApiClient sharedClientFromPool:host].reachabilityManager setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
|
|
||||||
reachabilityStatus = status;
|
reachabilityStatus = status;
|
||||||
switch (status) {
|
switch (status) {
|
||||||
case AFNetworkReachabilityStatusUnknown:
|
case AFNetworkReachabilityStatusUnknown:
|
||||||
@ -254,16 +240,352 @@ static void (^reachabilityChangeBlock)(int);
|
|||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// call the reachability block, if configured
|
// call the reachability block, if configured
|
||||||
if(reachabilityChangeBlock != nil) {
|
if(reachabilityChangeBlock != nil) {
|
||||||
reachabilityChangeBlock(status);
|
reachabilityChangeBlock(status);
|
||||||
}
|
}
|
||||||
}];
|
}];
|
||||||
[[SWGApiClient sharedClientFromPool:host].reachabilityManager startMonitoring];
|
|
||||||
|
[self.reachabilityManager startMonitoring];
|
||||||
}
|
}
|
||||||
|
|
||||||
-(NSString*) pathWithQueryParamsToString:(NSString*) path
|
#pragma mark - Deserialize methods
|
||||||
queryParams:(NSDictionary*) queryParams {
|
|
||||||
|
- (id) deserialize:(id) data class:(NSString *) class {
|
||||||
|
NSRegularExpression *regexp = nil;
|
||||||
|
NSTextCheckingResult *match = nil;
|
||||||
|
NSMutableArray *resultArray = nil;
|
||||||
|
NSMutableDictionary *resultDict = nil;
|
||||||
|
NSString *innerType = nil;
|
||||||
|
|
||||||
|
// return nil if data is nil or class is nil
|
||||||
|
if (!data || !class) {
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
|
||||||
|
// remove "*" from class, if ends with "*"
|
||||||
|
if ([class hasSuffix:@"*"]) {
|
||||||
|
class = [class substringToIndex:[class length] - 1];
|
||||||
|
}
|
||||||
|
|
||||||
|
// pure object
|
||||||
|
if ([class isEqualToString:@"NSObject"]) {
|
||||||
|
return [[NSObject alloc] init];
|
||||||
|
}
|
||||||
|
|
||||||
|
// list of models
|
||||||
|
NSString *arrayOfModelsPat = @"NSArray<(.+)>";
|
||||||
|
regexp = [NSRegularExpression regularExpressionWithPattern:arrayOfModelsPat
|
||||||
|
options:NSRegularExpressionCaseInsensitive
|
||||||
|
error:nil];
|
||||||
|
|
||||||
|
match = [regexp firstMatchInString:class
|
||||||
|
options:0
|
||||||
|
range:NSMakeRange(0, [class length])];
|
||||||
|
|
||||||
|
if (match) {
|
||||||
|
innerType = [class substringWithRange:[match rangeAtIndex:1]];
|
||||||
|
|
||||||
|
resultArray = [NSMutableArray arrayWithCapacity:[data count]];
|
||||||
|
[data enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
|
||||||
|
[resultArray addObject:[self deserialize:obj class:innerType]];
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
return resultArray;
|
||||||
|
}
|
||||||
|
|
||||||
|
// list of primitives
|
||||||
|
NSString *arrayOfPrimitivesPat = @"NSArray\\* /\\* (.+) \\*/";
|
||||||
|
regexp = [NSRegularExpression regularExpressionWithPattern:arrayOfPrimitivesPat
|
||||||
|
options:NSRegularExpressionCaseInsensitive
|
||||||
|
error:nil];
|
||||||
|
match = [regexp firstMatchInString:class
|
||||||
|
options:0
|
||||||
|
range:NSMakeRange(0, [class length])];
|
||||||
|
|
||||||
|
if (match) {
|
||||||
|
innerType = [class substringWithRange:[match rangeAtIndex:1]];
|
||||||
|
|
||||||
|
resultArray = [NSMutableArray arrayWithCapacity:[data count]];
|
||||||
|
[data enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
|
||||||
|
[resultArray addObject:[self deserialize:obj class:innerType]];
|
||||||
|
}];
|
||||||
|
|
||||||
|
return resultArray;
|
||||||
|
}
|
||||||
|
|
||||||
|
// map
|
||||||
|
NSString *dictPat = @"NSDictionary\\* /\\* (.+?), (.+) \\*/";
|
||||||
|
regexp = [NSRegularExpression regularExpressionWithPattern:dictPat
|
||||||
|
options:NSRegularExpressionCaseInsensitive
|
||||||
|
error:nil];
|
||||||
|
match = [regexp firstMatchInString:class
|
||||||
|
options:0
|
||||||
|
range:NSMakeRange(0, [class length])];
|
||||||
|
|
||||||
|
if (match) {
|
||||||
|
NSString *valueType = [class substringWithRange:[match rangeAtIndex:2]];
|
||||||
|
|
||||||
|
resultDict = [NSMutableDictionary dictionaryWithCapacity:[data count]];
|
||||||
|
[data enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
|
||||||
|
[resultDict setValue:[self deserialize:obj class:valueType] forKey:key];
|
||||||
|
}];
|
||||||
|
|
||||||
|
return resultDict;
|
||||||
|
}
|
||||||
|
|
||||||
|
// primitives
|
||||||
|
NSArray *primitiveTypes = @[@"NSString", @"NSDate", @"NSNumber"];
|
||||||
|
|
||||||
|
if ([primitiveTypes containsObject:class]) {
|
||||||
|
if ([class isEqualToString:@"NSString"]) {
|
||||||
|
return [NSString stringWithString:data];
|
||||||
|
}
|
||||||
|
else if ([class isEqualToString:@"NSDate"]) {
|
||||||
|
return [NSDate dateWithISO8601String:data];
|
||||||
|
}
|
||||||
|
else if ([class isEqualToString:@"NSNumber"]) {
|
||||||
|
// NSNumber from NSNumber
|
||||||
|
if ([data isKindOfClass:[NSNumber class]]) {
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
else if ([data isKindOfClass:[NSString class]]) {
|
||||||
|
// NSNumber (NSCFBoolean) from NSString
|
||||||
|
if ([[data lowercaseString] isEqualToString:@"true"] || [[data lowercaseString] isEqualToString:@"false"]) {
|
||||||
|
return [NSNumber numberWithBool:[data boolValue]];
|
||||||
|
// NSNumber from NSString
|
||||||
|
} else {
|
||||||
|
NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
|
||||||
|
formatter.numberStyle = NSNumberFormatterDecimalStyle;
|
||||||
|
return [formatter numberFromString:data];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// model
|
||||||
|
Class ModelClass = NSClassFromString(class);
|
||||||
|
if ([ModelClass instancesRespondToSelector:@selector(initWithDictionary:error:)]) {
|
||||||
|
return [[ModelClass alloc] initWithDictionary:data error:nil];
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
|
||||||
|
#pragma mark - Operation Methods
|
||||||
|
|
||||||
|
- (void) operationWithCompletionBlock: (NSURLRequest *)request
|
||||||
|
requestId: (NSNumber *) requestId
|
||||||
|
completionBlock: (void (^)(id, NSError *))completionBlock {
|
||||||
|
AFHTTPRequestOperation *op = [self HTTPRequestOperationWithRequest:request
|
||||||
|
success:^(AFHTTPRequestOperation *operation, id response) {
|
||||||
|
if([self executeRequestWithId:requestId]) {
|
||||||
|
if([[SWGConfiguration sharedConfig] debug]) {
|
||||||
|
[self logResponse:operation forRequest:request error:nil];
|
||||||
|
}
|
||||||
|
completionBlock(response, nil);
|
||||||
|
}
|
||||||
|
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
|
||||||
|
if([self executeRequestWithId:requestId]) {
|
||||||
|
NSMutableDictionary *userInfo = [error.userInfo mutableCopy];
|
||||||
|
if(operation.responseObject) {
|
||||||
|
// Add in the (parsed) response body.
|
||||||
|
userInfo[SWGResponseObjectErrorKey] = operation.responseObject;
|
||||||
|
}
|
||||||
|
NSError *augmentedError = [error initWithDomain:error.domain code:error.code userInfo:userInfo];
|
||||||
|
|
||||||
|
if([[SWGConfiguration sharedConfig] debug])
|
||||||
|
[self logResponse:nil forRequest:request error:augmentedError];
|
||||||
|
completionBlock(nil, augmentedError);
|
||||||
|
}
|
||||||
|
}];
|
||||||
|
|
||||||
|
[self.operationQueue addOperation:op];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) downloadOperationWithCompletionBlock: (NSURLRequest *)request
|
||||||
|
requestId: (NSNumber *) requestId
|
||||||
|
completionBlock: (void (^)(id, NSError *))completionBlock {
|
||||||
|
AFHTTPRequestOperation *op = [self HTTPRequestOperationWithRequest:request
|
||||||
|
success:^(AFHTTPRequestOperation *operation, id responseObject) {
|
||||||
|
SWGConfiguration *config = [SWGConfiguration sharedConfig];
|
||||||
|
NSString *directory = nil;
|
||||||
|
if (config.tempFolderPath) {
|
||||||
|
directory = config.tempFolderPath;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
directory = NSTemporaryDirectory();
|
||||||
|
}
|
||||||
|
|
||||||
|
NSDictionary *headers = operation.response.allHeaderFields;
|
||||||
|
NSString *filename = nil;
|
||||||
|
if ([headers objectForKey:@"Content-Disposition"]) {
|
||||||
|
|
||||||
|
NSString *pattern = @"filename=['\"]?([^'\"\\s]+)['\"]?";
|
||||||
|
NSRegularExpression *regexp = [NSRegularExpression regularExpressionWithPattern:pattern
|
||||||
|
options:NSRegularExpressionCaseInsensitive
|
||||||
|
error:nil];
|
||||||
|
NSString *contentDispositionHeader = [headers objectForKey:@"Content-Disposition"];
|
||||||
|
NSTextCheckingResult *match = [regexp firstMatchInString:contentDispositionHeader
|
||||||
|
options:0
|
||||||
|
range:NSMakeRange(0, [contentDispositionHeader length])];
|
||||||
|
filename = [contentDispositionHeader substringWithRange:[match rangeAtIndex:1]];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
filename = [NSString stringWithFormat:@"%@", [[NSProcessInfo processInfo] globallyUniqueString]];
|
||||||
|
}
|
||||||
|
|
||||||
|
NSString *filepath = [directory stringByAppendingPathComponent:filename];
|
||||||
|
NSURL *file = [NSURL fileURLWithPath:filepath];
|
||||||
|
|
||||||
|
[operation.responseData writeToURL:file atomically:YES];
|
||||||
|
completionBlock(file, nil);
|
||||||
|
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
|
||||||
|
|
||||||
|
if ([self executeRequestWithId:requestId]) {
|
||||||
|
NSMutableDictionary *userInfo = [error.userInfo mutableCopy];
|
||||||
|
if (operation.responseObject) {
|
||||||
|
userInfo[SWGResponseObjectErrorKey] = operation.responseObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
NSError *augmentedError = [error initWithDomain:error.domain code:error.code userInfo:userInfo];
|
||||||
|
|
||||||
|
if ([[SWGConfiguration sharedConfig] debug]) {
|
||||||
|
[self logResponse:nil forRequest:request error:augmentedError];
|
||||||
|
}
|
||||||
|
|
||||||
|
completionBlock(nil, augmentedError);
|
||||||
|
}
|
||||||
|
}];
|
||||||
|
|
||||||
|
[self.operationQueue addOperation:op];
|
||||||
|
}
|
||||||
|
|
||||||
|
#pragma mark - Perform Request Methods
|
||||||
|
|
||||||
|
-(NSNumber*) requestWithCompletionBlock: (NSString*) path
|
||||||
|
method: (NSString*) method
|
||||||
|
queryParams: (NSDictionary*) queryParams
|
||||||
|
formParams: (NSDictionary *) formParams
|
||||||
|
files: (NSDictionary *) files
|
||||||
|
body: (id) body
|
||||||
|
headerParams: (NSDictionary*) headerParams
|
||||||
|
authSettings: (NSArray *) authSettings
|
||||||
|
requestContentType: (NSString*) requestContentType
|
||||||
|
responseContentType: (NSString*) responseContentType
|
||||||
|
responseType: (NSString *) responseType
|
||||||
|
completionBlock: (void (^)(id, NSError *))completionBlock {
|
||||||
|
// setting request serializer
|
||||||
|
if ([requestContentType isEqualToString:@"application/json"]) {
|
||||||
|
self.requestSerializer = [SWGJSONRequestSerializer serializer];
|
||||||
|
}
|
||||||
|
else if ([requestContentType isEqualToString:@"application/x-www-form-urlencoded"]) {
|
||||||
|
self.requestSerializer = [AFHTTPRequestSerializer serializer];
|
||||||
|
}
|
||||||
|
else if ([requestContentType isEqualToString:@"multipart/form-data"]) {
|
||||||
|
self.requestSerializer = [AFHTTPRequestSerializer serializer];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
NSAssert(false, @"unsupport request type %@", requestContentType);
|
||||||
|
}
|
||||||
|
|
||||||
|
// setting response serializer
|
||||||
|
if ([responseContentType isEqualToString:@"application/json"]) {
|
||||||
|
self.responseSerializer = [SWGJSONResponseSerializer serializer];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
self.responseSerializer = [AFHTTPResponseSerializer serializer];
|
||||||
|
}
|
||||||
|
|
||||||
|
// auth setting
|
||||||
|
[self updateHeaderParams:&headerParams queryParams:&queryParams WithAuthSettings:authSettings];
|
||||||
|
|
||||||
|
NSMutableURLRequest * request = nil;
|
||||||
|
|
||||||
|
NSString* pathWithQueryParams = [self pathWithQueryParamsToString:path queryParams:queryParams];
|
||||||
|
if ([pathWithQueryParams hasPrefix:@"/"]) {
|
||||||
|
pathWithQueryParams = [pathWithQueryParams substringFromIndex:1];
|
||||||
|
}
|
||||||
|
|
||||||
|
NSString* urlString = [[NSURL URLWithString:pathWithQueryParams relativeToURL:self.baseURL] absoluteString];
|
||||||
|
if (files.count > 0) {
|
||||||
|
request = [self.requestSerializer multipartFormRequestWithMethod:@"POST"
|
||||||
|
URLString:urlString
|
||||||
|
parameters:nil
|
||||||
|
constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
|
||||||
|
[formParams enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
|
||||||
|
NSData *data = [obj dataUsingEncoding:NSUTF8StringEncoding];
|
||||||
|
[formData appendPartWithFormData:data name:key];
|
||||||
|
}];
|
||||||
|
[files enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
|
||||||
|
NSURL *filePath = (NSURL *)obj;
|
||||||
|
[formData appendPartWithFileURL:filePath name:key error:nil];
|
||||||
|
}];
|
||||||
|
} error:nil];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (formParams) {
|
||||||
|
request = [self.requestSerializer requestWithMethod:method
|
||||||
|
URLString:urlString
|
||||||
|
parameters:formParams
|
||||||
|
error:nil];
|
||||||
|
}
|
||||||
|
if (body) {
|
||||||
|
request = [self.requestSerializer requestWithMethod:method
|
||||||
|
URLString:urlString
|
||||||
|
parameters:body
|
||||||
|
error:nil];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOL hasHeaderParams = false;
|
||||||
|
if(headerParams != nil && [headerParams count] > 0) {
|
||||||
|
hasHeaderParams = true;
|
||||||
|
}
|
||||||
|
if(offlineState) {
|
||||||
|
NSLog(@"%@ cache forced", path);
|
||||||
|
[request setCachePolicy:NSURLRequestReturnCacheDataDontLoad];
|
||||||
|
}
|
||||||
|
else if(!hasHeaderParams && [method isEqualToString:@"GET"] && cacheEnabled) {
|
||||||
|
NSLog(@"%@ cache enabled", path);
|
||||||
|
[request setCachePolicy:NSURLRequestUseProtocolCachePolicy];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
NSLog(@"%@ cache disabled", path);
|
||||||
|
[request setCachePolicy:NSURLRequestReloadIgnoringLocalCacheData];
|
||||||
|
}
|
||||||
|
|
||||||
|
if(hasHeaderParams){
|
||||||
|
for(NSString * key in [headerParams keyEnumerator]){
|
||||||
|
[request setValue:[headerParams valueForKey:key] forHTTPHeaderField:key];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
[self.requestSerializer setValue:responseContentType forHTTPHeaderField:@"Accept"];
|
||||||
|
|
||||||
|
|
||||||
|
// Always disable cookies!
|
||||||
|
[request setHTTPShouldHandleCookies:NO];
|
||||||
|
|
||||||
|
NSNumber* requestId = [SWGApiClient queueRequest];
|
||||||
|
if ([responseType isEqualToString:@"NSURL*"]) {
|
||||||
|
[self downloadOperationWithCompletionBlock:request requestId:requestId completionBlock:^(id data, NSError *error) {
|
||||||
|
completionBlock(data, error);
|
||||||
|
}];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
[self operationWithCompletionBlock:request requestId:requestId completionBlock:^(id data, NSError *error) {
|
||||||
|
completionBlock([self deserialize:data class:responseType], error);
|
||||||
|
}];
|
||||||
|
}
|
||||||
|
return requestId;
|
||||||
|
}
|
||||||
|
|
||||||
|
#pragma mark -
|
||||||
|
|
||||||
|
- (NSString*) pathWithQueryParamsToString:(NSString*) path
|
||||||
|
queryParams:(NSDictionary*) queryParams {
|
||||||
NSString * separator = nil;
|
NSString * separator = nil;
|
||||||
int counter = 0;
|
int counter = 0;
|
||||||
|
|
||||||
@ -323,18 +645,18 @@ static void (^reachabilityChangeBlock)(int);
|
|||||||
- (void) updateHeaderParams:(NSDictionary *__autoreleasing *)headers
|
- (void) updateHeaderParams:(NSDictionary *__autoreleasing *)headers
|
||||||
queryParams:(NSDictionary *__autoreleasing *)querys
|
queryParams:(NSDictionary *__autoreleasing *)querys
|
||||||
WithAuthSettings:(NSArray *)authSettings {
|
WithAuthSettings:(NSArray *)authSettings {
|
||||||
|
|
||||||
if (!authSettings || [authSettings count] == 0) {
|
if (!authSettings || [authSettings count] == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
NSMutableDictionary *headersWithAuth = [NSMutableDictionary dictionaryWithDictionary:*headers];
|
NSMutableDictionary *headersWithAuth = [NSMutableDictionary dictionaryWithDictionary:*headers];
|
||||||
NSMutableDictionary *querysWithAuth = [NSMutableDictionary dictionaryWithDictionary:*querys];
|
NSMutableDictionary *querysWithAuth = [NSMutableDictionary dictionaryWithDictionary:*querys];
|
||||||
|
|
||||||
SWGConfiguration *config = [SWGConfiguration sharedConfig];
|
SWGConfiguration *config = [SWGConfiguration sharedConfig];
|
||||||
for (NSString *auth in authSettings) {
|
for (NSString *auth in authSettings) {
|
||||||
NSDictionary *authSetting = [[config authSettings] objectForKey:auth];
|
NSDictionary *authSetting = [[config authSettings] objectForKey:auth];
|
||||||
|
|
||||||
if (authSetting) {
|
if (authSetting) {
|
||||||
if ([authSetting[@"in"] isEqualToString:@"header"]) {
|
if ([authSetting[@"in"] isEqualToString:@"header"]) {
|
||||||
[headersWithAuth setObject:authSetting[@"value"] forKey:authSetting[@"key"]];
|
[headersWithAuth setObject:authSetting[@"value"] forKey:authSetting[@"key"]];
|
||||||
@ -344,341 +666,9 @@ static void (^reachabilityChangeBlock)(int);
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
*headers = [NSDictionary dictionaryWithDictionary:headersWithAuth];
|
*headers = [NSDictionary dictionaryWithDictionary:headersWithAuth];
|
||||||
*querys = [NSDictionary dictionaryWithDictionary:querysWithAuth];
|
*querys = [NSDictionary dictionaryWithDictionary:querysWithAuth];
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma mark - Deserialize methods
|
|
||||||
|
|
||||||
- (id) deserialize:(id) data class:(NSString *) class {
|
|
||||||
NSRegularExpression *regexp = nil;
|
|
||||||
NSTextCheckingResult *match = nil;
|
|
||||||
NSMutableArray *resultArray = nil;
|
|
||||||
NSMutableDictionary *resultDict = nil;
|
|
||||||
NSString *innerType = nil;
|
|
||||||
|
|
||||||
// return nil if data is nil or class is nil
|
|
||||||
if (!data || !class) {
|
|
||||||
return nil;
|
|
||||||
}
|
|
||||||
|
|
||||||
// remove "*" from class, if ends with "*"
|
|
||||||
if ([class hasSuffix:@"*"]) {
|
|
||||||
class = [class substringToIndex:[class length] - 1];
|
|
||||||
}
|
|
||||||
|
|
||||||
// pure object
|
|
||||||
if ([class isEqualToString:@"NSObject"]) {
|
|
||||||
return [[NSObject alloc] init];
|
|
||||||
}
|
|
||||||
|
|
||||||
// list of models
|
|
||||||
NSString *arrayOfModelsPat = @"NSArray<(.+)>";
|
|
||||||
regexp = [NSRegularExpression regularExpressionWithPattern:arrayOfModelsPat
|
|
||||||
options:NSRegularExpressionCaseInsensitive
|
|
||||||
error:nil];
|
|
||||||
|
|
||||||
match = [regexp firstMatchInString:class
|
|
||||||
options:0
|
|
||||||
range:NSMakeRange(0, [class length])];
|
|
||||||
|
|
||||||
if (match) {
|
|
||||||
innerType = [class substringWithRange:[match rangeAtIndex:1]];
|
|
||||||
|
|
||||||
resultArray = [NSMutableArray arrayWithCapacity:[data count]];
|
|
||||||
[data enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
|
|
||||||
[resultArray addObject:[self deserialize:obj class:innerType]];
|
|
||||||
}
|
|
||||||
];
|
|
||||||
|
|
||||||
return resultArray;
|
|
||||||
}
|
|
||||||
|
|
||||||
// list of primitives
|
|
||||||
NSString *arrayOfPrimitivesPat = @"NSArray\\* /\\* (.+) \\*/";
|
|
||||||
regexp = [NSRegularExpression regularExpressionWithPattern:arrayOfPrimitivesPat
|
|
||||||
options:NSRegularExpressionCaseInsensitive
|
|
||||||
error:nil];
|
|
||||||
match = [regexp firstMatchInString:class
|
|
||||||
options:0
|
|
||||||
range:NSMakeRange(0, [class length])];
|
|
||||||
|
|
||||||
if (match) {
|
|
||||||
innerType = [class substringWithRange:[match rangeAtIndex:1]];
|
|
||||||
|
|
||||||
resultArray = [NSMutableArray arrayWithCapacity:[data count]];
|
|
||||||
[data enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
|
|
||||||
[resultArray addObject:[self deserialize:obj class:innerType]];
|
|
||||||
}];
|
|
||||||
|
|
||||||
return resultArray;
|
|
||||||
}
|
|
||||||
|
|
||||||
// map
|
|
||||||
NSString *dictPat = @"NSDictionary\\* /\\* (.+?), (.+) \\*/";
|
|
||||||
regexp = [NSRegularExpression regularExpressionWithPattern:dictPat
|
|
||||||
options:NSRegularExpressionCaseInsensitive
|
|
||||||
error:nil];
|
|
||||||
match = [regexp firstMatchInString:class
|
|
||||||
options:0
|
|
||||||
range:NSMakeRange(0, [class length])];
|
|
||||||
|
|
||||||
if (match) {
|
|
||||||
NSString *valueType = [class substringWithRange:[match rangeAtIndex:2]];
|
|
||||||
|
|
||||||
resultDict = [NSMutableDictionary dictionaryWithCapacity:[data count]];
|
|
||||||
[data enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
|
|
||||||
[resultDict setValue:[self deserialize:obj class:valueType] forKey:key];
|
|
||||||
}];
|
|
||||||
|
|
||||||
return resultDict;
|
|
||||||
}
|
|
||||||
|
|
||||||
// primitives
|
|
||||||
NSArray *primitiveTypes = @[@"NSString", @"NSDate", @"BOOL", @"NSNumber"];
|
|
||||||
|
|
||||||
if ([primitiveTypes containsObject:class]) {
|
|
||||||
if ([class isEqualToString:@"NSString"]) {
|
|
||||||
return [NSString stringWithString:data];
|
|
||||||
}
|
|
||||||
else if ([class isEqualToString:@"NSDate"]) {
|
|
||||||
return [NSDate dateWithISO8601String:data];
|
|
||||||
}
|
|
||||||
else if ([class isEqualToString:@"BOOL"]) {
|
|
||||||
// Returns YES on encountering one of "Y", "y", "T", "t", or a
|
|
||||||
// digit 1-9—the method ignores any trailing characters
|
|
||||||
// NSString => BOOL => NSNumber
|
|
||||||
return [NSNumber numberWithBool:[data boolValue]];
|
|
||||||
}
|
|
||||||
else if ([class isEqualToString:@"NSNumber"]) {
|
|
||||||
// NSNumber from NSNumber
|
|
||||||
if ([data isKindOfClass:[NSNumber class]]) {
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
// NSNumber from NSString
|
|
||||||
else {
|
|
||||||
NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
|
|
||||||
formatter.numberStyle = NSNumberFormatterDecimalStyle;
|
|
||||||
return [formatter numberFromString:data];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// model
|
|
||||||
Class ModelClass = NSClassFromString(class);
|
|
||||||
if ([ModelClass instancesRespondToSelector:@selector(initWithDictionary:error:)]) {
|
|
||||||
return [[ModelClass alloc] initWithDictionary:data error:nil];
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil;
|
|
||||||
}
|
|
||||||
|
|
||||||
#pragma mark - Operation Methods
|
|
||||||
|
|
||||||
- (void) operationWithCompletionBlock: (NSURLRequest *)request
|
|
||||||
requestId: (NSNumber *) requestId
|
|
||||||
completionBlock: (void (^)(id, NSError *))completionBlock {
|
|
||||||
AFHTTPRequestOperation *op = [self HTTPRequestOperationWithRequest:request
|
|
||||||
success:^(AFHTTPRequestOperation *operation, id response) {
|
|
||||||
if([self executeRequestWithId:requestId]) {
|
|
||||||
if([[SWGConfiguration sharedConfig] debug]) {
|
|
||||||
[self logResponse:operation forRequest:request error:nil];
|
|
||||||
}
|
|
||||||
completionBlock(response, nil);
|
|
||||||
}
|
|
||||||
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
|
|
||||||
if([self executeRequestWithId:requestId]) {
|
|
||||||
NSMutableDictionary *userInfo = [error.userInfo mutableCopy];
|
|
||||||
if(operation.responseObject) {
|
|
||||||
// Add in the (parsed) response body.
|
|
||||||
userInfo[SWGResponseObjectErrorKey] = operation.responseObject;
|
|
||||||
}
|
|
||||||
NSError *augmentedError = [error initWithDomain:error.domain code:error.code userInfo:userInfo];
|
|
||||||
|
|
||||||
if([[SWGConfiguration sharedConfig] debug])
|
|
||||||
[self logResponse:nil forRequest:request error:augmentedError];
|
|
||||||
completionBlock(nil, augmentedError);
|
|
||||||
}
|
|
||||||
}];
|
|
||||||
|
|
||||||
[self.operationQueue addOperation:op];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void) downloadOperationWithCompletionBlock: (NSURLRequest *)request
|
|
||||||
requestId: (NSNumber *) requestId
|
|
||||||
completionBlock: (void (^)(id, NSError *))completionBlock {
|
|
||||||
AFHTTPRequestOperation *op = [self HTTPRequestOperationWithRequest:request
|
|
||||||
success:^(AFHTTPRequestOperation *operation, id responseObject) {
|
|
||||||
SWGConfiguration *config = [SWGConfiguration sharedConfig];
|
|
||||||
NSString *directory = nil;
|
|
||||||
if (config.tempFolderPath) {
|
|
||||||
directory = config.tempFolderPath;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
directory = NSTemporaryDirectory();
|
|
||||||
}
|
|
||||||
|
|
||||||
NSDictionary *headers = operation.response.allHeaderFields;
|
|
||||||
NSString *filename = nil;
|
|
||||||
if ([headers objectForKey:@"Content-Disposition"]) {
|
|
||||||
|
|
||||||
NSString *pattern = @"filename=['\"]?([^'\"\\s]+)['\"]?";
|
|
||||||
NSRegularExpression *regexp = [NSRegularExpression regularExpressionWithPattern:pattern
|
|
||||||
options:NSRegularExpressionCaseInsensitive
|
|
||||||
error:nil];
|
|
||||||
NSString *contentDispositionHeader = [headers objectForKey:@"Content-Disposition"];
|
|
||||||
NSTextCheckingResult *match = [regexp firstMatchInString:contentDispositionHeader
|
|
||||||
options:0
|
|
||||||
range:NSMakeRange(0, [contentDispositionHeader length])];
|
|
||||||
filename = [contentDispositionHeader substringWithRange:[match rangeAtIndex:1]];
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
filename = [NSString stringWithFormat:@"%@", [[NSProcessInfo processInfo] globallyUniqueString]];
|
|
||||||
}
|
|
||||||
|
|
||||||
NSString *filepath = [directory stringByAppendingPathComponent:filename];
|
|
||||||
NSURL *file = [NSURL fileURLWithPath:filepath];
|
|
||||||
|
|
||||||
[operation.responseData writeToURL:file atomically:YES];
|
|
||||||
completionBlock(file, nil);
|
|
||||||
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
|
|
||||||
|
|
||||||
if ([self executeRequestWithId:requestId]) {
|
|
||||||
NSMutableDictionary *userInfo = [error.userInfo mutableCopy];
|
|
||||||
if (operation.responseObject) {
|
|
||||||
userInfo[SWGResponseObjectErrorKey] = operation.responseObject;
|
|
||||||
}
|
|
||||||
|
|
||||||
NSError *augmentedError = [error initWithDomain:error.domain code:error.code userInfo:userInfo];
|
|
||||||
|
|
||||||
if ([[SWGConfiguration sharedConfig] debug]) {
|
|
||||||
[self logResponse:nil forRequest:request error:augmentedError];
|
|
||||||
}
|
|
||||||
|
|
||||||
completionBlock(nil, augmentedError);
|
|
||||||
}
|
|
||||||
}];
|
|
||||||
|
|
||||||
[self.operationQueue addOperation:op];
|
|
||||||
}
|
|
||||||
|
|
||||||
#pragma mark - Perform Request Methods
|
|
||||||
|
|
||||||
-(NSNumber*) requestWithCompletionBlock: (NSString*) path
|
|
||||||
method: (NSString*) method
|
|
||||||
queryParams: (NSDictionary*) queryParams
|
|
||||||
formParams: (NSDictionary *) formParams
|
|
||||||
files: (NSDictionary *) files
|
|
||||||
body: (id) body
|
|
||||||
headerParams: (NSDictionary*) headerParams
|
|
||||||
authSettings: (NSArray *) authSettings
|
|
||||||
requestContentType: (NSString*) requestContentType
|
|
||||||
responseContentType: (NSString*) responseContentType
|
|
||||||
responseType: (NSString *) responseType
|
|
||||||
completionBlock: (void (^)(id, NSError *))completionBlock {
|
|
||||||
// setting request serializer
|
|
||||||
if ([requestContentType isEqualToString:@"application/json"]) {
|
|
||||||
self.requestSerializer = [SWGJSONRequestSerializer serializer];
|
|
||||||
}
|
|
||||||
else if ([requestContentType isEqualToString:@"application/x-www-form-urlencoded"]) {
|
|
||||||
self.requestSerializer = [AFHTTPRequestSerializer serializer];
|
|
||||||
}
|
|
||||||
else if ([requestContentType isEqualToString:@"multipart/form-data"]) {
|
|
||||||
self.requestSerializer = [AFHTTPRequestSerializer serializer];
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
NSAssert(false, @"unsupport request type %@", requestContentType);
|
|
||||||
}
|
|
||||||
|
|
||||||
// setting response serializer
|
|
||||||
if ([responseContentType isEqualToString:@"application/json"]) {
|
|
||||||
self.responseSerializer = [SWGJSONResponseSerializer serializer];
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
self.responseSerializer = [AFHTTPResponseSerializer serializer];
|
|
||||||
}
|
|
||||||
|
|
||||||
// auth setting
|
|
||||||
[self updateHeaderParams:&headerParams queryParams:&queryParams WithAuthSettings:authSettings];
|
|
||||||
|
|
||||||
NSMutableURLRequest * request = nil;
|
|
||||||
NSString* pathWithQueryParams = [self pathWithQueryParamsToString:path queryParams:queryParams];
|
|
||||||
NSString* urlString = [[NSURL URLWithString:pathWithQueryParams relativeToURL:self.baseURL] absoluteString];
|
|
||||||
if (files.count > 0) {
|
|
||||||
request = [self.requestSerializer multipartFormRequestWithMethod:@"POST"
|
|
||||||
URLString:urlString
|
|
||||||
parameters:nil
|
|
||||||
constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
|
|
||||||
[formParams enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
|
|
||||||
NSData *data = [obj dataUsingEncoding:NSUTF8StringEncoding];
|
|
||||||
[formData appendPartWithFormData:data name:key];
|
|
||||||
}];
|
|
||||||
[files enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
|
|
||||||
NSURL *filePath = (NSURL *)obj;
|
|
||||||
[formData appendPartWithFileURL:filePath name:key error:nil];
|
|
||||||
}];
|
|
||||||
} error:nil];
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if (formParams) {
|
|
||||||
request = [self.requestSerializer requestWithMethod:method
|
|
||||||
URLString:urlString
|
|
||||||
parameters:formParams
|
|
||||||
error:nil];
|
|
||||||
}
|
|
||||||
if (body) {
|
|
||||||
request = [self.requestSerializer requestWithMethod:method
|
|
||||||
URLString:urlString
|
|
||||||
parameters:body
|
|
||||||
error:nil];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
BOOL hasHeaderParams = false;
|
|
||||||
if(headerParams != nil && [headerParams count] > 0) {
|
|
||||||
hasHeaderParams = true;
|
|
||||||
}
|
|
||||||
if(offlineState) {
|
|
||||||
NSLog(@"%@ cache forced", path);
|
|
||||||
[request setCachePolicy:NSURLRequestReturnCacheDataDontLoad];
|
|
||||||
}
|
|
||||||
else if(!hasHeaderParams && [method isEqualToString:@"GET"] && cacheEnabled) {
|
|
||||||
NSLog(@"%@ cache enabled", path);
|
|
||||||
[request setCachePolicy:NSURLRequestUseProtocolCachePolicy];
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
NSLog(@"%@ cache disabled", path);
|
|
||||||
[request setCachePolicy:NSURLRequestReloadIgnoringLocalCacheData];
|
|
||||||
}
|
|
||||||
|
|
||||||
if(hasHeaderParams){
|
|
||||||
for(NSString * key in [headerParams keyEnumerator]){
|
|
||||||
[request setValue:[headerParams valueForKey:key] forHTTPHeaderField:key];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
[self.requestSerializer setValue:responseContentType forHTTPHeaderField:@"Accept"];
|
|
||||||
|
|
||||||
|
|
||||||
// Always disable cookies!
|
|
||||||
[request setHTTPShouldHandleCookies:NO];
|
|
||||||
|
|
||||||
NSNumber* requestId = [SWGApiClient queueRequest];
|
|
||||||
if ([responseType isEqualToString:@"NSURL*"]) {
|
|
||||||
[self downloadOperationWithCompletionBlock:request requestId:requestId completionBlock:^(id data, NSError *error) {
|
|
||||||
completionBlock(data, error);
|
|
||||||
}];
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
[self operationWithCompletionBlock:request requestId:requestId completionBlock:^(id data, NSError *error) {
|
|
||||||
completionBlock([self deserialize:data class:responseType], error);
|
|
||||||
}];
|
|
||||||
}
|
|
||||||
return requestId;
|
|
||||||
}
|
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,13 +1,26 @@
|
|||||||
#import <Foundation/Foundation.h>
|
#import <Foundation/Foundation.h>
|
||||||
|
#import "SWGApiClient.h"
|
||||||
|
|
||||||
/** The `SWGConfiguration` class manages the configurations for the sdk.
|
/** The `SWGConfiguration` class manages the configurations for the sdk.
|
||||||
*
|
*
|
||||||
* NOTE: This class is auto generated by the swagger code generator program.
|
* NOTE: This class is auto generated by the swagger code generator program.
|
||||||
* https://github.com/swagger-api/swagger-codegen
|
* https://github.com/swagger-api/swagger-codegen
|
||||||
* Do not edit the class manually.
|
* Do not edit the class manually.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@class SWGApiClient;
|
||||||
|
|
||||||
@interface SWGConfiguration : NSObject
|
@interface SWGConfiguration : NSObject
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default api client
|
||||||
|
*/
|
||||||
|
@property (nonatomic) SWGApiClient *apiClient;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default base url
|
||||||
|
*/
|
||||||
|
@property (nonatomic) NSString *host;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Api key values for Api Key type Authentication
|
* Api key values for Api Key type Authentication
|
||||||
|
@ -25,6 +25,8 @@
|
|||||||
- (instancetype) init {
|
- (instancetype) init {
|
||||||
self = [super init];
|
self = [super init];
|
||||||
if (self) {
|
if (self) {
|
||||||
|
self.apiClient = nil;
|
||||||
|
self.host = @"http://petstore.swagger.io/v2";
|
||||||
self.username = @"";
|
self.username = @"";
|
||||||
self.password = @"";
|
self.password = @"";
|
||||||
self.tempFolderPath = nil;
|
self.tempFolderPath = nil;
|
||||||
|
@ -18,8 +18,6 @@
|
|||||||
-(void) addHeader:(NSString*)value forKey:(NSString*)key;
|
-(void) addHeader:(NSString*)value forKey:(NSString*)key;
|
||||||
-(unsigned long) requestQueueSize;
|
-(unsigned long) requestQueueSize;
|
||||||
+(SWGPetApi*) apiWithHeader:(NSString*)headerValue key:(NSString*)key;
|
+(SWGPetApi*) apiWithHeader:(NSString*)headerValue key:(NSString*)key;
|
||||||
+(void) setBasePath:(NSString*)basePath;
|
|
||||||
+(NSString*) getBasePath;
|
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
/// Update an existing pet
|
/// Update an existing pet
|
||||||
|
@ -9,14 +9,16 @@
|
|||||||
|
|
||||||
@implementation SWGPetApi
|
@implementation SWGPetApi
|
||||||
|
|
||||||
static NSString * basePath = @"http://petstore.swagger.io/v2";
|
|
||||||
|
|
||||||
#pragma mark - Initialize methods
|
#pragma mark - Initialize methods
|
||||||
|
|
||||||
- (id) init {
|
- (id) init {
|
||||||
self = [super init];
|
self = [super init];
|
||||||
if (self) {
|
if (self) {
|
||||||
self.apiClient = [SWGApiClient sharedClientFromPool:basePath];
|
SWGConfiguration *config = [SWGConfiguration sharedConfig];
|
||||||
|
if (config.apiClient == nil) {
|
||||||
|
config.apiClient = [[SWGApiClient alloc] init];
|
||||||
|
}
|
||||||
|
self.apiClient = config.apiClient;
|
||||||
self.defaultHeaders = [NSMutableDictionary dictionary];
|
self.defaultHeaders = [NSMutableDictionary dictionary];
|
||||||
}
|
}
|
||||||
return self;
|
return self;
|
||||||
@ -25,12 +27,7 @@ static NSString * basePath = @"http://petstore.swagger.io/v2";
|
|||||||
- (id) initWithApiClient:(SWGApiClient *)apiClient {
|
- (id) initWithApiClient:(SWGApiClient *)apiClient {
|
||||||
self = [super init];
|
self = [super init];
|
||||||
if (self) {
|
if (self) {
|
||||||
if (apiClient) {
|
self.apiClient = apiClient;
|
||||||
self.apiClient = apiClient;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
self.apiClient = [SWGApiClient sharedClientFromPool:basePath];
|
|
||||||
}
|
|
||||||
self.defaultHeaders = [NSMutableDictionary dictionary];
|
self.defaultHeaders = [NSMutableDictionary dictionary];
|
||||||
}
|
}
|
||||||
return self;
|
return self;
|
||||||
@ -48,14 +45,6 @@ static NSString * basePath = @"http://petstore.swagger.io/v2";
|
|||||||
return singletonAPI;
|
return singletonAPI;
|
||||||
}
|
}
|
||||||
|
|
||||||
+(void) setBasePath:(NSString*)path {
|
|
||||||
basePath = path;
|
|
||||||
}
|
|
||||||
|
|
||||||
+(NSString*) getBasePath {
|
|
||||||
return basePath;
|
|
||||||
}
|
|
||||||
|
|
||||||
-(void) addHeader:(NSString*)value forKey:(NSString*)key {
|
-(void) addHeader:(NSString*)value forKey:(NSString*)key {
|
||||||
[self.defaultHeaders setValue:value forKey:key];
|
[self.defaultHeaders setValue:value forKey:key];
|
||||||
}
|
}
|
||||||
@ -85,12 +74,13 @@ static NSString * basePath = @"http://petstore.swagger.io/v2";
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
NSMutableString* requestUrl = [NSMutableString stringWithFormat:@"%@/pet", basePath];
|
NSMutableString* resourcePath = [NSMutableString stringWithFormat:@"/pet"];
|
||||||
|
|
||||||
// remove format in URL if needed
|
// remove format in URL if needed
|
||||||
if ([requestUrl rangeOfString:@".{format}"].location != NSNotFound)
|
if ([resourcePath rangeOfString:@".{format}"].location != NSNotFound) {
|
||||||
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:@".{format}"] withString:@".json"];
|
[resourcePath replaceCharactersInRange: [resourcePath rangeOfString:@".{format}"] withString:@".json"];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
|
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
|
||||||
@ -144,7 +134,7 @@ static NSString * basePath = @"http://petstore.swagger.io/v2";
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
return [self.apiClient requestWithCompletionBlock: requestUrl
|
return [self.apiClient requestWithCompletionBlock: resourcePath
|
||||||
method: @"PUT"
|
method: @"PUT"
|
||||||
queryParams: queryParams
|
queryParams: queryParams
|
||||||
formParams: formParams
|
formParams: formParams
|
||||||
@ -176,12 +166,13 @@ static NSString * basePath = @"http://petstore.swagger.io/v2";
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
NSMutableString* requestUrl = [NSMutableString stringWithFormat:@"%@/pet", basePath];
|
NSMutableString* resourcePath = [NSMutableString stringWithFormat:@"/pet"];
|
||||||
|
|
||||||
// remove format in URL if needed
|
// remove format in URL if needed
|
||||||
if ([requestUrl rangeOfString:@".{format}"].location != NSNotFound)
|
if ([resourcePath rangeOfString:@".{format}"].location != NSNotFound) {
|
||||||
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:@".{format}"] withString:@".json"];
|
[resourcePath replaceCharactersInRange: [resourcePath rangeOfString:@".{format}"] withString:@".json"];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
|
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
|
||||||
@ -235,7 +226,7 @@ static NSString * basePath = @"http://petstore.swagger.io/v2";
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
return [self.apiClient requestWithCompletionBlock: requestUrl
|
return [self.apiClient requestWithCompletionBlock: resourcePath
|
||||||
method: @"POST"
|
method: @"POST"
|
||||||
queryParams: queryParams
|
queryParams: queryParams
|
||||||
formParams: formParams
|
formParams: formParams
|
||||||
@ -267,12 +258,13 @@ static NSString * basePath = @"http://petstore.swagger.io/v2";
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
NSMutableString* requestUrl = [NSMutableString stringWithFormat:@"%@/pet/findByStatus", basePath];
|
NSMutableString* resourcePath = [NSMutableString stringWithFormat:@"/pet/findByStatus"];
|
||||||
|
|
||||||
// remove format in URL if needed
|
// remove format in URL if needed
|
||||||
if ([requestUrl rangeOfString:@".{format}"].location != NSNotFound)
|
if ([resourcePath rangeOfString:@".{format}"].location != NSNotFound) {
|
||||||
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:@".{format}"] withString:@".json"];
|
[resourcePath replaceCharactersInRange: [resourcePath rangeOfString:@".{format}"] withString:@".json"];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
|
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
|
||||||
@ -316,7 +308,7 @@ static NSString * basePath = @"http://petstore.swagger.io/v2";
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
return [self.apiClient requestWithCompletionBlock: requestUrl
|
return [self.apiClient requestWithCompletionBlock: resourcePath
|
||||||
method: @"GET"
|
method: @"GET"
|
||||||
queryParams: queryParams
|
queryParams: queryParams
|
||||||
formParams: formParams
|
formParams: formParams
|
||||||
@ -348,12 +340,13 @@ static NSString * basePath = @"http://petstore.swagger.io/v2";
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
NSMutableString* requestUrl = [NSMutableString stringWithFormat:@"%@/pet/findByTags", basePath];
|
NSMutableString* resourcePath = [NSMutableString stringWithFormat:@"/pet/findByTags"];
|
||||||
|
|
||||||
// remove format in URL if needed
|
// remove format in URL if needed
|
||||||
if ([requestUrl rangeOfString:@".{format}"].location != NSNotFound)
|
if ([resourcePath rangeOfString:@".{format}"].location != NSNotFound) {
|
||||||
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:@".{format}"] withString:@".json"];
|
[resourcePath replaceCharactersInRange: [resourcePath rangeOfString:@".{format}"] withString:@".json"];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
|
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
|
||||||
@ -397,7 +390,7 @@ static NSString * basePath = @"http://petstore.swagger.io/v2";
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
return [self.apiClient requestWithCompletionBlock: requestUrl
|
return [self.apiClient requestWithCompletionBlock: resourcePath
|
||||||
method: @"GET"
|
method: @"GET"
|
||||||
queryParams: queryParams
|
queryParams: queryParams
|
||||||
formParams: formParams
|
formParams: formParams
|
||||||
@ -434,13 +427,14 @@ static NSString * basePath = @"http://petstore.swagger.io/v2";
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
NSMutableString* requestUrl = [NSMutableString stringWithFormat:@"%@/pet/{petId}", basePath];
|
NSMutableString* resourcePath = [NSMutableString stringWithFormat:@"/pet/{petId}"];
|
||||||
|
|
||||||
// remove format in URL if needed
|
// remove format in URL if needed
|
||||||
if ([requestUrl rangeOfString:@".{format}"].location != NSNotFound)
|
if ([resourcePath rangeOfString:@".{format}"].location != NSNotFound) {
|
||||||
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:@".{format}"] withString:@".json"];
|
[resourcePath replaceCharactersInRange: [resourcePath rangeOfString:@".{format}"] withString:@".json"];
|
||||||
|
}
|
||||||
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:[NSString stringWithFormat:@"%@%@%@", @"{", @"petId", @"}"]] withString: [SWGApiClient escape:petId]];
|
|
||||||
|
[resourcePath replaceCharactersInRange: [resourcePath rangeOfString:[NSString stringWithFormat:@"%@%@%@", @"{", @"petId", @"}"]] withString: [SWGApiClient escape:petId]];
|
||||||
|
|
||||||
|
|
||||||
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
|
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
|
||||||
@ -478,7 +472,7 @@ static NSString * basePath = @"http://petstore.swagger.io/v2";
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
return [self.apiClient requestWithCompletionBlock: requestUrl
|
return [self.apiClient requestWithCompletionBlock: resourcePath
|
||||||
method: @"GET"
|
method: @"GET"
|
||||||
queryParams: queryParams
|
queryParams: queryParams
|
||||||
formParams: formParams
|
formParams: formParams
|
||||||
@ -521,13 +515,14 @@ static NSString * basePath = @"http://petstore.swagger.io/v2";
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
NSMutableString* requestUrl = [NSMutableString stringWithFormat:@"%@/pet/{petId}", basePath];
|
NSMutableString* resourcePath = [NSMutableString stringWithFormat:@"/pet/{petId}"];
|
||||||
|
|
||||||
// remove format in URL if needed
|
// remove format in URL if needed
|
||||||
if ([requestUrl rangeOfString:@".{format}"].location != NSNotFound)
|
if ([resourcePath rangeOfString:@".{format}"].location != NSNotFound) {
|
||||||
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:@".{format}"] withString:@".json"];
|
[resourcePath replaceCharactersInRange: [resourcePath rangeOfString:@".{format}"] withString:@".json"];
|
||||||
|
}
|
||||||
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:[NSString stringWithFormat:@"%@%@%@", @"{", @"petId", @"}"]] withString: [SWGApiClient escape:petId]];
|
|
||||||
|
[resourcePath replaceCharactersInRange: [resourcePath rangeOfString:[NSString stringWithFormat:@"%@%@%@", @"{", @"petId", @"}"]] withString: [SWGApiClient escape:petId]];
|
||||||
|
|
||||||
|
|
||||||
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
|
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
|
||||||
@ -573,7 +568,7 @@ static NSString * basePath = @"http://petstore.swagger.io/v2";
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
return [self.apiClient requestWithCompletionBlock: requestUrl
|
return [self.apiClient requestWithCompletionBlock: resourcePath
|
||||||
method: @"POST"
|
method: @"POST"
|
||||||
queryParams: queryParams
|
queryParams: queryParams
|
||||||
formParams: formParams
|
formParams: formParams
|
||||||
@ -613,13 +608,14 @@ static NSString * basePath = @"http://petstore.swagger.io/v2";
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
NSMutableString* requestUrl = [NSMutableString stringWithFormat:@"%@/pet/{petId}", basePath];
|
NSMutableString* resourcePath = [NSMutableString stringWithFormat:@"/pet/{petId}"];
|
||||||
|
|
||||||
// remove format in URL if needed
|
// remove format in URL if needed
|
||||||
if ([requestUrl rangeOfString:@".{format}"].location != NSNotFound)
|
if ([resourcePath rangeOfString:@".{format}"].location != NSNotFound) {
|
||||||
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:@".{format}"] withString:@".json"];
|
[resourcePath replaceCharactersInRange: [resourcePath rangeOfString:@".{format}"] withString:@".json"];
|
||||||
|
}
|
||||||
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:[NSString stringWithFormat:@"%@%@%@", @"{", @"petId", @"}"]] withString: [SWGApiClient escape:petId]];
|
|
||||||
|
[resourcePath replaceCharactersInRange: [resourcePath rangeOfString:[NSString stringWithFormat:@"%@%@%@", @"{", @"petId", @"}"]] withString: [SWGApiClient escape:petId]];
|
||||||
|
|
||||||
|
|
||||||
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
|
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
|
||||||
@ -659,7 +655,7 @@ static NSString * basePath = @"http://petstore.swagger.io/v2";
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
return [self.apiClient requestWithCompletionBlock: requestUrl
|
return [self.apiClient requestWithCompletionBlock: resourcePath
|
||||||
method: @"DELETE"
|
method: @"DELETE"
|
||||||
queryParams: queryParams
|
queryParams: queryParams
|
||||||
formParams: formParams
|
formParams: formParams
|
||||||
@ -702,13 +698,14 @@ static NSString * basePath = @"http://petstore.swagger.io/v2";
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
NSMutableString* requestUrl = [NSMutableString stringWithFormat:@"%@/pet/{petId}/uploadImage", basePath];
|
NSMutableString* resourcePath = [NSMutableString stringWithFormat:@"/pet/{petId}/uploadImage"];
|
||||||
|
|
||||||
// remove format in URL if needed
|
// remove format in URL if needed
|
||||||
if ([requestUrl rangeOfString:@".{format}"].location != NSNotFound)
|
if ([resourcePath rangeOfString:@".{format}"].location != NSNotFound) {
|
||||||
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:@".{format}"] withString:@".json"];
|
[resourcePath replaceCharactersInRange: [resourcePath rangeOfString:@".{format}"] withString:@".json"];
|
||||||
|
}
|
||||||
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:[NSString stringWithFormat:@"%@%@%@", @"{", @"petId", @"}"]] withString: [SWGApiClient escape:petId]];
|
|
||||||
|
[resourcePath replaceCharactersInRange: [resourcePath rangeOfString:[NSString stringWithFormat:@"%@%@%@", @"{", @"petId", @"}"]] withString: [SWGApiClient escape:petId]];
|
||||||
|
|
||||||
|
|
||||||
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
|
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
|
||||||
@ -754,7 +751,7 @@ static NSString * basePath = @"http://petstore.swagger.io/v2";
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
return [self.apiClient requestWithCompletionBlock: requestUrl
|
return [self.apiClient requestWithCompletionBlock: resourcePath
|
||||||
method: @"POST"
|
method: @"POST"
|
||||||
queryParams: queryParams
|
queryParams: queryParams
|
||||||
formParams: formParams
|
formParams: formParams
|
||||||
|
@ -18,8 +18,6 @@
|
|||||||
-(void) addHeader:(NSString*)value forKey:(NSString*)key;
|
-(void) addHeader:(NSString*)value forKey:(NSString*)key;
|
||||||
-(unsigned long) requestQueueSize;
|
-(unsigned long) requestQueueSize;
|
||||||
+(SWGStoreApi*) apiWithHeader:(NSString*)headerValue key:(NSString*)key;
|
+(SWGStoreApi*) apiWithHeader:(NSString*)headerValue key:(NSString*)key;
|
||||||
+(void) setBasePath:(NSString*)basePath;
|
|
||||||
+(NSString*) getBasePath;
|
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
/// Returns pet inventories by status
|
/// Returns pet inventories by status
|
||||||
|
@ -9,14 +9,16 @@
|
|||||||
|
|
||||||
@implementation SWGStoreApi
|
@implementation SWGStoreApi
|
||||||
|
|
||||||
static NSString * basePath = @"http://petstore.swagger.io/v2";
|
|
||||||
|
|
||||||
#pragma mark - Initialize methods
|
#pragma mark - Initialize methods
|
||||||
|
|
||||||
- (id) init {
|
- (id) init {
|
||||||
self = [super init];
|
self = [super init];
|
||||||
if (self) {
|
if (self) {
|
||||||
self.apiClient = [SWGApiClient sharedClientFromPool:basePath];
|
SWGConfiguration *config = [SWGConfiguration sharedConfig];
|
||||||
|
if (config.apiClient == nil) {
|
||||||
|
config.apiClient = [[SWGApiClient alloc] init];
|
||||||
|
}
|
||||||
|
self.apiClient = config.apiClient;
|
||||||
self.defaultHeaders = [NSMutableDictionary dictionary];
|
self.defaultHeaders = [NSMutableDictionary dictionary];
|
||||||
}
|
}
|
||||||
return self;
|
return self;
|
||||||
@ -25,12 +27,7 @@ static NSString * basePath = @"http://petstore.swagger.io/v2";
|
|||||||
- (id) initWithApiClient:(SWGApiClient *)apiClient {
|
- (id) initWithApiClient:(SWGApiClient *)apiClient {
|
||||||
self = [super init];
|
self = [super init];
|
||||||
if (self) {
|
if (self) {
|
||||||
if (apiClient) {
|
self.apiClient = apiClient;
|
||||||
self.apiClient = apiClient;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
self.apiClient = [SWGApiClient sharedClientFromPool:basePath];
|
|
||||||
}
|
|
||||||
self.defaultHeaders = [NSMutableDictionary dictionary];
|
self.defaultHeaders = [NSMutableDictionary dictionary];
|
||||||
}
|
}
|
||||||
return self;
|
return self;
|
||||||
@ -48,14 +45,6 @@ static NSString * basePath = @"http://petstore.swagger.io/v2";
|
|||||||
return singletonAPI;
|
return singletonAPI;
|
||||||
}
|
}
|
||||||
|
|
||||||
+(void) setBasePath:(NSString*)path {
|
|
||||||
basePath = path;
|
|
||||||
}
|
|
||||||
|
|
||||||
+(NSString*) getBasePath {
|
|
||||||
return basePath;
|
|
||||||
}
|
|
||||||
|
|
||||||
-(void) addHeader:(NSString*)value forKey:(NSString*)key {
|
-(void) addHeader:(NSString*)value forKey:(NSString*)key {
|
||||||
[self.defaultHeaders setValue:value forKey:key];
|
[self.defaultHeaders setValue:value forKey:key];
|
||||||
}
|
}
|
||||||
@ -82,12 +71,13 @@ static NSString * basePath = @"http://petstore.swagger.io/v2";
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
NSMutableString* requestUrl = [NSMutableString stringWithFormat:@"%@/store/inventory", basePath];
|
NSMutableString* resourcePath = [NSMutableString stringWithFormat:@"/store/inventory"];
|
||||||
|
|
||||||
// remove format in URL if needed
|
// remove format in URL if needed
|
||||||
if ([requestUrl rangeOfString:@".{format}"].location != NSNotFound)
|
if ([resourcePath rangeOfString:@".{format}"].location != NSNotFound) {
|
||||||
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:@".{format}"] withString:@".json"];
|
[resourcePath replaceCharactersInRange: [resourcePath rangeOfString:@".{format}"] withString:@".json"];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
|
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
|
||||||
@ -125,7 +115,7 @@ static NSString * basePath = @"http://petstore.swagger.io/v2";
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
return [self.apiClient requestWithCompletionBlock: requestUrl
|
return [self.apiClient requestWithCompletionBlock: resourcePath
|
||||||
method: @"GET"
|
method: @"GET"
|
||||||
queryParams: queryParams
|
queryParams: queryParams
|
||||||
formParams: formParams
|
formParams: formParams
|
||||||
@ -157,12 +147,13 @@ static NSString * basePath = @"http://petstore.swagger.io/v2";
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
NSMutableString* requestUrl = [NSMutableString stringWithFormat:@"%@/store/order", basePath];
|
NSMutableString* resourcePath = [NSMutableString stringWithFormat:@"/store/order"];
|
||||||
|
|
||||||
// remove format in URL if needed
|
// remove format in URL if needed
|
||||||
if ([requestUrl rangeOfString:@".{format}"].location != NSNotFound)
|
if ([resourcePath rangeOfString:@".{format}"].location != NSNotFound) {
|
||||||
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:@".{format}"] withString:@".json"];
|
[resourcePath replaceCharactersInRange: [resourcePath rangeOfString:@".{format}"] withString:@".json"];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
|
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
|
||||||
@ -216,7 +207,7 @@ static NSString * basePath = @"http://petstore.swagger.io/v2";
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
return [self.apiClient requestWithCompletionBlock: requestUrl
|
return [self.apiClient requestWithCompletionBlock: resourcePath
|
||||||
method: @"POST"
|
method: @"POST"
|
||||||
queryParams: queryParams
|
queryParams: queryParams
|
||||||
formParams: formParams
|
formParams: formParams
|
||||||
@ -253,13 +244,14 @@ static NSString * basePath = @"http://petstore.swagger.io/v2";
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
NSMutableString* requestUrl = [NSMutableString stringWithFormat:@"%@/store/order/{orderId}", basePath];
|
NSMutableString* resourcePath = [NSMutableString stringWithFormat:@"/store/order/{orderId}"];
|
||||||
|
|
||||||
// remove format in URL if needed
|
// remove format in URL if needed
|
||||||
if ([requestUrl rangeOfString:@".{format}"].location != NSNotFound)
|
if ([resourcePath rangeOfString:@".{format}"].location != NSNotFound) {
|
||||||
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:@".{format}"] withString:@".json"];
|
[resourcePath replaceCharactersInRange: [resourcePath rangeOfString:@".{format}"] withString:@".json"];
|
||||||
|
}
|
||||||
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:[NSString stringWithFormat:@"%@%@%@", @"{", @"orderId", @"}"]] withString: [SWGApiClient escape:orderId]];
|
|
||||||
|
[resourcePath replaceCharactersInRange: [resourcePath rangeOfString:[NSString stringWithFormat:@"%@%@%@", @"{", @"orderId", @"}"]] withString: [SWGApiClient escape:orderId]];
|
||||||
|
|
||||||
|
|
||||||
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
|
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
|
||||||
@ -297,7 +289,7 @@ static NSString * basePath = @"http://petstore.swagger.io/v2";
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
return [self.apiClient requestWithCompletionBlock: requestUrl
|
return [self.apiClient requestWithCompletionBlock: resourcePath
|
||||||
method: @"GET"
|
method: @"GET"
|
||||||
queryParams: queryParams
|
queryParams: queryParams
|
||||||
formParams: formParams
|
formParams: formParams
|
||||||
@ -334,13 +326,14 @@ static NSString * basePath = @"http://petstore.swagger.io/v2";
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
NSMutableString* requestUrl = [NSMutableString stringWithFormat:@"%@/store/order/{orderId}", basePath];
|
NSMutableString* resourcePath = [NSMutableString stringWithFormat:@"/store/order/{orderId}"];
|
||||||
|
|
||||||
// remove format in URL if needed
|
// remove format in URL if needed
|
||||||
if ([requestUrl rangeOfString:@".{format}"].location != NSNotFound)
|
if ([resourcePath rangeOfString:@".{format}"].location != NSNotFound) {
|
||||||
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:@".{format}"] withString:@".json"];
|
[resourcePath replaceCharactersInRange: [resourcePath rangeOfString:@".{format}"] withString:@".json"];
|
||||||
|
}
|
||||||
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:[NSString stringWithFormat:@"%@%@%@", @"{", @"orderId", @"}"]] withString: [SWGApiClient escape:orderId]];
|
|
||||||
|
[resourcePath replaceCharactersInRange: [resourcePath rangeOfString:[NSString stringWithFormat:@"%@%@%@", @"{", @"orderId", @"}"]] withString: [SWGApiClient escape:orderId]];
|
||||||
|
|
||||||
|
|
||||||
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
|
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
|
||||||
@ -378,7 +371,7 @@ static NSString * basePath = @"http://petstore.swagger.io/v2";
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
return [self.apiClient requestWithCompletionBlock: requestUrl
|
return [self.apiClient requestWithCompletionBlock: resourcePath
|
||||||
method: @"DELETE"
|
method: @"DELETE"
|
||||||
queryParams: queryParams
|
queryParams: queryParams
|
||||||
formParams: formParams
|
formParams: formParams
|
||||||
|
@ -18,8 +18,6 @@
|
|||||||
-(void) addHeader:(NSString*)value forKey:(NSString*)key;
|
-(void) addHeader:(NSString*)value forKey:(NSString*)key;
|
||||||
-(unsigned long) requestQueueSize;
|
-(unsigned long) requestQueueSize;
|
||||||
+(SWGUserApi*) apiWithHeader:(NSString*)headerValue key:(NSString*)key;
|
+(SWGUserApi*) apiWithHeader:(NSString*)headerValue key:(NSString*)key;
|
||||||
+(void) setBasePath:(NSString*)basePath;
|
|
||||||
+(NSString*) getBasePath;
|
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
/// Create user
|
/// Create user
|
||||||
|
@ -9,14 +9,16 @@
|
|||||||
|
|
||||||
@implementation SWGUserApi
|
@implementation SWGUserApi
|
||||||
|
|
||||||
static NSString * basePath = @"http://petstore.swagger.io/v2";
|
|
||||||
|
|
||||||
#pragma mark - Initialize methods
|
#pragma mark - Initialize methods
|
||||||
|
|
||||||
- (id) init {
|
- (id) init {
|
||||||
self = [super init];
|
self = [super init];
|
||||||
if (self) {
|
if (self) {
|
||||||
self.apiClient = [SWGApiClient sharedClientFromPool:basePath];
|
SWGConfiguration *config = [SWGConfiguration sharedConfig];
|
||||||
|
if (config.apiClient == nil) {
|
||||||
|
config.apiClient = [[SWGApiClient alloc] init];
|
||||||
|
}
|
||||||
|
self.apiClient = config.apiClient;
|
||||||
self.defaultHeaders = [NSMutableDictionary dictionary];
|
self.defaultHeaders = [NSMutableDictionary dictionary];
|
||||||
}
|
}
|
||||||
return self;
|
return self;
|
||||||
@ -25,12 +27,7 @@ static NSString * basePath = @"http://petstore.swagger.io/v2";
|
|||||||
- (id) initWithApiClient:(SWGApiClient *)apiClient {
|
- (id) initWithApiClient:(SWGApiClient *)apiClient {
|
||||||
self = [super init];
|
self = [super init];
|
||||||
if (self) {
|
if (self) {
|
||||||
if (apiClient) {
|
self.apiClient = apiClient;
|
||||||
self.apiClient = apiClient;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
self.apiClient = [SWGApiClient sharedClientFromPool:basePath];
|
|
||||||
}
|
|
||||||
self.defaultHeaders = [NSMutableDictionary dictionary];
|
self.defaultHeaders = [NSMutableDictionary dictionary];
|
||||||
}
|
}
|
||||||
return self;
|
return self;
|
||||||
@ -48,14 +45,6 @@ static NSString * basePath = @"http://petstore.swagger.io/v2";
|
|||||||
return singletonAPI;
|
return singletonAPI;
|
||||||
}
|
}
|
||||||
|
|
||||||
+(void) setBasePath:(NSString*)path {
|
|
||||||
basePath = path;
|
|
||||||
}
|
|
||||||
|
|
||||||
+(NSString*) getBasePath {
|
|
||||||
return basePath;
|
|
||||||
}
|
|
||||||
|
|
||||||
-(void) addHeader:(NSString*)value forKey:(NSString*)key {
|
-(void) addHeader:(NSString*)value forKey:(NSString*)key {
|
||||||
[self.defaultHeaders setValue:value forKey:key];
|
[self.defaultHeaders setValue:value forKey:key];
|
||||||
}
|
}
|
||||||
@ -85,12 +74,13 @@ static NSString * basePath = @"http://petstore.swagger.io/v2";
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
NSMutableString* requestUrl = [NSMutableString stringWithFormat:@"%@/user", basePath];
|
NSMutableString* resourcePath = [NSMutableString stringWithFormat:@"/user"];
|
||||||
|
|
||||||
// remove format in URL if needed
|
// remove format in URL if needed
|
||||||
if ([requestUrl rangeOfString:@".{format}"].location != NSNotFound)
|
if ([resourcePath rangeOfString:@".{format}"].location != NSNotFound) {
|
||||||
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:@".{format}"] withString:@".json"];
|
[resourcePath replaceCharactersInRange: [resourcePath rangeOfString:@".{format}"] withString:@".json"];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
|
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
|
||||||
@ -144,7 +134,7 @@ static NSString * basePath = @"http://petstore.swagger.io/v2";
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
return [self.apiClient requestWithCompletionBlock: requestUrl
|
return [self.apiClient requestWithCompletionBlock: resourcePath
|
||||||
method: @"POST"
|
method: @"POST"
|
||||||
queryParams: queryParams
|
queryParams: queryParams
|
||||||
formParams: formParams
|
formParams: formParams
|
||||||
@ -176,12 +166,13 @@ static NSString * basePath = @"http://petstore.swagger.io/v2";
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
NSMutableString* requestUrl = [NSMutableString stringWithFormat:@"%@/user/createWithArray", basePath];
|
NSMutableString* resourcePath = [NSMutableString stringWithFormat:@"/user/createWithArray"];
|
||||||
|
|
||||||
// remove format in URL if needed
|
// remove format in URL if needed
|
||||||
if ([requestUrl rangeOfString:@".{format}"].location != NSNotFound)
|
if ([resourcePath rangeOfString:@".{format}"].location != NSNotFound) {
|
||||||
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:@".{format}"] withString:@".json"];
|
[resourcePath replaceCharactersInRange: [resourcePath rangeOfString:@".{format}"] withString:@".json"];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
|
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
|
||||||
@ -235,7 +226,7 @@ static NSString * basePath = @"http://petstore.swagger.io/v2";
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
return [self.apiClient requestWithCompletionBlock: requestUrl
|
return [self.apiClient requestWithCompletionBlock: resourcePath
|
||||||
method: @"POST"
|
method: @"POST"
|
||||||
queryParams: queryParams
|
queryParams: queryParams
|
||||||
formParams: formParams
|
formParams: formParams
|
||||||
@ -267,12 +258,13 @@ static NSString * basePath = @"http://petstore.swagger.io/v2";
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
NSMutableString* requestUrl = [NSMutableString stringWithFormat:@"%@/user/createWithList", basePath];
|
NSMutableString* resourcePath = [NSMutableString stringWithFormat:@"/user/createWithList"];
|
||||||
|
|
||||||
// remove format in URL if needed
|
// remove format in URL if needed
|
||||||
if ([requestUrl rangeOfString:@".{format}"].location != NSNotFound)
|
if ([resourcePath rangeOfString:@".{format}"].location != NSNotFound) {
|
||||||
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:@".{format}"] withString:@".json"];
|
[resourcePath replaceCharactersInRange: [resourcePath rangeOfString:@".{format}"] withString:@".json"];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
|
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
|
||||||
@ -326,7 +318,7 @@ static NSString * basePath = @"http://petstore.swagger.io/v2";
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
return [self.apiClient requestWithCompletionBlock: requestUrl
|
return [self.apiClient requestWithCompletionBlock: resourcePath
|
||||||
method: @"POST"
|
method: @"POST"
|
||||||
queryParams: queryParams
|
queryParams: queryParams
|
||||||
formParams: formParams
|
formParams: formParams
|
||||||
@ -361,12 +353,13 @@ static NSString * basePath = @"http://petstore.swagger.io/v2";
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
NSMutableString* requestUrl = [NSMutableString stringWithFormat:@"%@/user/login", basePath];
|
NSMutableString* resourcePath = [NSMutableString stringWithFormat:@"/user/login"];
|
||||||
|
|
||||||
// remove format in URL if needed
|
// remove format in URL if needed
|
||||||
if ([requestUrl rangeOfString:@".{format}"].location != NSNotFound)
|
if ([resourcePath rangeOfString:@".{format}"].location != NSNotFound) {
|
||||||
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:@".{format}"] withString:@".json"];
|
[resourcePath replaceCharactersInRange: [resourcePath rangeOfString:@".{format}"] withString:@".json"];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
|
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
|
||||||
@ -412,7 +405,7 @@ static NSString * basePath = @"http://petstore.swagger.io/v2";
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
return [self.apiClient requestWithCompletionBlock: requestUrl
|
return [self.apiClient requestWithCompletionBlock: resourcePath
|
||||||
method: @"GET"
|
method: @"GET"
|
||||||
queryParams: queryParams
|
queryParams: queryParams
|
||||||
formParams: formParams
|
formParams: formParams
|
||||||
@ -441,12 +434,13 @@ static NSString * basePath = @"http://petstore.swagger.io/v2";
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
NSMutableString* requestUrl = [NSMutableString stringWithFormat:@"%@/user/logout", basePath];
|
NSMutableString* resourcePath = [NSMutableString stringWithFormat:@"/user/logout"];
|
||||||
|
|
||||||
// remove format in URL if needed
|
// remove format in URL if needed
|
||||||
if ([requestUrl rangeOfString:@".{format}"].location != NSNotFound)
|
if ([resourcePath rangeOfString:@".{format}"].location != NSNotFound) {
|
||||||
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:@".{format}"] withString:@".json"];
|
[resourcePath replaceCharactersInRange: [resourcePath rangeOfString:@".{format}"] withString:@".json"];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
|
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
|
||||||
@ -484,7 +478,7 @@ static NSString * basePath = @"http://petstore.swagger.io/v2";
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
return [self.apiClient requestWithCompletionBlock: requestUrl
|
return [self.apiClient requestWithCompletionBlock: resourcePath
|
||||||
method: @"GET"
|
method: @"GET"
|
||||||
queryParams: queryParams
|
queryParams: queryParams
|
||||||
formParams: formParams
|
formParams: formParams
|
||||||
@ -521,13 +515,14 @@ static NSString * basePath = @"http://petstore.swagger.io/v2";
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
NSMutableString* requestUrl = [NSMutableString stringWithFormat:@"%@/user/{username}", basePath];
|
NSMutableString* resourcePath = [NSMutableString stringWithFormat:@"/user/{username}"];
|
||||||
|
|
||||||
// remove format in URL if needed
|
// remove format in URL if needed
|
||||||
if ([requestUrl rangeOfString:@".{format}"].location != NSNotFound)
|
if ([resourcePath rangeOfString:@".{format}"].location != NSNotFound) {
|
||||||
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:@".{format}"] withString:@".json"];
|
[resourcePath replaceCharactersInRange: [resourcePath rangeOfString:@".{format}"] withString:@".json"];
|
||||||
|
}
|
||||||
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:[NSString stringWithFormat:@"%@%@%@", @"{", @"username", @"}"]] withString: [SWGApiClient escape:username]];
|
|
||||||
|
[resourcePath replaceCharactersInRange: [resourcePath rangeOfString:[NSString stringWithFormat:@"%@%@%@", @"{", @"username", @"}"]] withString: [SWGApiClient escape:username]];
|
||||||
|
|
||||||
|
|
||||||
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
|
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
|
||||||
@ -565,7 +560,7 @@ static NSString * basePath = @"http://petstore.swagger.io/v2";
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
return [self.apiClient requestWithCompletionBlock: requestUrl
|
return [self.apiClient requestWithCompletionBlock: resourcePath
|
||||||
method: @"GET"
|
method: @"GET"
|
||||||
queryParams: queryParams
|
queryParams: queryParams
|
||||||
formParams: formParams
|
formParams: formParams
|
||||||
@ -605,13 +600,14 @@ static NSString * basePath = @"http://petstore.swagger.io/v2";
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
NSMutableString* requestUrl = [NSMutableString stringWithFormat:@"%@/user/{username}", basePath];
|
NSMutableString* resourcePath = [NSMutableString stringWithFormat:@"/user/{username}"];
|
||||||
|
|
||||||
// remove format in URL if needed
|
// remove format in URL if needed
|
||||||
if ([requestUrl rangeOfString:@".{format}"].location != NSNotFound)
|
if ([resourcePath rangeOfString:@".{format}"].location != NSNotFound) {
|
||||||
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:@".{format}"] withString:@".json"];
|
[resourcePath replaceCharactersInRange: [resourcePath rangeOfString:@".{format}"] withString:@".json"];
|
||||||
|
}
|
||||||
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:[NSString stringWithFormat:@"%@%@%@", @"{", @"username", @"}"]] withString: [SWGApiClient escape:username]];
|
|
||||||
|
[resourcePath replaceCharactersInRange: [resourcePath rangeOfString:[NSString stringWithFormat:@"%@%@%@", @"{", @"username", @"}"]] withString: [SWGApiClient escape:username]];
|
||||||
|
|
||||||
|
|
||||||
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
|
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
|
||||||
@ -665,7 +661,7 @@ static NSString * basePath = @"http://petstore.swagger.io/v2";
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
return [self.apiClient requestWithCompletionBlock: requestUrl
|
return [self.apiClient requestWithCompletionBlock: resourcePath
|
||||||
method: @"PUT"
|
method: @"PUT"
|
||||||
queryParams: queryParams
|
queryParams: queryParams
|
||||||
formParams: formParams
|
formParams: formParams
|
||||||
@ -702,13 +698,14 @@ static NSString * basePath = @"http://petstore.swagger.io/v2";
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
NSMutableString* requestUrl = [NSMutableString stringWithFormat:@"%@/user/{username}", basePath];
|
NSMutableString* resourcePath = [NSMutableString stringWithFormat:@"/user/{username}"];
|
||||||
|
|
||||||
// remove format in URL if needed
|
// remove format in URL if needed
|
||||||
if ([requestUrl rangeOfString:@".{format}"].location != NSNotFound)
|
if ([resourcePath rangeOfString:@".{format}"].location != NSNotFound) {
|
||||||
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:@".{format}"] withString:@".json"];
|
[resourcePath replaceCharactersInRange: [resourcePath rangeOfString:@".{format}"] withString:@".json"];
|
||||||
|
}
|
||||||
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:[NSString stringWithFormat:@"%@%@%@", @"{", @"username", @"}"]] withString: [SWGApiClient escape:username]];
|
|
||||||
|
[resourcePath replaceCharactersInRange: [resourcePath rangeOfString:[NSString stringWithFormat:@"%@%@%@", @"{", @"username", @"}"]] withString: [SWGApiClient escape:username]];
|
||||||
|
|
||||||
|
|
||||||
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
|
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
|
||||||
@ -746,7 +743,7 @@ static NSString * basePath = @"http://petstore.swagger.io/v2";
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
return [self.apiClient requestWithCompletionBlock: requestUrl
|
return [self.apiClient requestWithCompletionBlock: resourcePath
|
||||||
method: @"DELETE"
|
method: @"DELETE"
|
||||||
queryParams: queryParams
|
queryParams: queryParams
|
||||||
formParams: formParams
|
formParams: formParams
|
||||||
|
@ -7,7 +7,9 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
#import "SWGViewController.h"
|
#import "SWGViewController.h"
|
||||||
|
#import <SwaggerClient/SWGApiClient.h>
|
||||||
#import <SwaggerClient/SWGPet.h>
|
#import <SwaggerClient/SWGPet.h>
|
||||||
|
#import <SwaggerClient/SWGPetApi.h>
|
||||||
#import <SwaggerClient/SWGConfiguration.h>
|
#import <SwaggerClient/SWGConfiguration.h>
|
||||||
|
|
||||||
@interface SWGViewController ()
|
@interface SWGViewController ()
|
||||||
@ -19,11 +21,6 @@
|
|||||||
- (void)viewDidLoad
|
- (void)viewDidLoad
|
||||||
{
|
{
|
||||||
[super viewDidLoad];
|
[super viewDidLoad];
|
||||||
SWGConfiguration *config = [SWGConfiguration sharedConfig];
|
|
||||||
[config setApiKey:@"hello" forApiKeyIdentifier:@"world"];
|
|
||||||
[config setApiKey:@"geekerzp" forApiKeyIdentifier:@"zp"];
|
|
||||||
[config removeApiKey:@"zp"];
|
|
||||||
NSLog(@"%@", config.apiKey);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)didReceiveMemoryWarning
|
- (void)didReceiveMemoryWarning
|
||||||
|
@ -149,4 +149,17 @@
|
|||||||
XCTAssertTrue([result[0][0] isKindOfClass:[NSString class]]);
|
XCTAssertTrue([result[0][0] isKindOfClass:[NSString class]]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)testDeserializeBool {
|
||||||
|
NSString *data;
|
||||||
|
NSNumber *result;
|
||||||
|
|
||||||
|
data = @"true";
|
||||||
|
result = [apiClient deserialize:data class:@"NSNumber*"];
|
||||||
|
XCTAssertTrue([result isEqual:@YES]);
|
||||||
|
|
||||||
|
data = @"false";
|
||||||
|
result = [apiClient deserialize:data class:@"NSNumber*"];
|
||||||
|
XCTAssertTrue([result isEqual:@NO]);
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
@ -89,7 +89,7 @@ class Configuration
|
|||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $host = 'http://localhost';
|
protected $host = 'http://petstore.swagger.io/v2';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Timeout (second) of the HTTP request, by default set to 0, no timeout
|
* Timeout (second) of the HTTP request, by default set to 0, no timeout
|
||||||
@ -103,7 +103,7 @@ class Configuration
|
|||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $userAgent = "PHP-Swagger";
|
protected $userAgent = "PHP-Swagger/1.0.0";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Debug switch (default set to false)
|
* Debug switch (default set to false)
|
||||||
|
@ -247,12 +247,12 @@ class ApiClient(object):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
if type(klass) == str:
|
if type(klass) == str:
|
||||||
if 'list[' in klass:
|
if klass.startswith('list['):
|
||||||
sub_kls = re.match('list\[(.*)\]', klass).group(1)
|
sub_kls = re.match('list\[(.*)\]', klass).group(1)
|
||||||
return [self.__deserialize(sub_data, sub_kls)
|
return [self.__deserialize(sub_data, sub_kls)
|
||||||
for sub_data in data]
|
for sub_data in data]
|
||||||
|
|
||||||
if 'dict(' in klass:
|
if klass.startswith('dict('):
|
||||||
sub_kls = re.match('dict\(([^,]*), (.*)\)', klass).group(2)
|
sub_kls = re.match('dict\(([^,]*), (.*)\)', klass).group(2)
|
||||||
return {k: self.__deserialize(v, sub_kls)
|
return {k: self.__deserialize(v, sub_kls)
|
||||||
for k, v in iteritems(data)}
|
for k, v in iteritems(data)}
|
||||||
|
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