forked from loafle/openapi-generator-original
Merge branch 'develop_2.0' into ruby-debug
Conflicts: modules/swagger-codegen/src/main/resources/ruby/swagger/configuration.mustache modules/swagger-codegen/src/main/resources/ruby/swagger/request.mustache samples/client/petstore/ruby/lib/petstore/swagger/request.rb samples/client/petstore/ruby/lib/swagger_client.rb samples/client/petstore/ruby/lib/swagger_client/swagger/configuration.rb
This commit is contained in:
@@ -183,7 +183,7 @@ StaticDocCodegen.java
|
||||
StaticHtmlGenerator.java
|
||||
SwaggerGenerator.java
|
||||
SwaggerYamlGenerator.java
|
||||
SwiftGenerator.java
|
||||
SwiftCodegen.java
|
||||
TizenClientCodegen.java
|
||||
```
|
||||
|
||||
|
||||
@@ -18,22 +18,28 @@ if [ ! -d "${APP_DIR}" ]; then
|
||||
fi
|
||||
|
||||
cd $APP_DIR
|
||||
./bin/akka-scala-petstore.sh
|
||||
./bin/android-java-petstore.sh
|
||||
./bin/csharp-petstore.sh
|
||||
./bin/dynamic-html.sh
|
||||
./bin/html-petstore.sh
|
||||
./bin/jaxrs-petstore-server.sh
|
||||
./bin/java-petstore.sh
|
||||
./bin/qt5-petstore.sh
|
||||
./bin/jaxrs-petstore-server.sh
|
||||
./bin/nodejs-petstore-server.sh
|
||||
./bin/objc-petstore.sh
|
||||
./bin/perl-petstore.sh
|
||||
./bin/php-petstore.sh
|
||||
./bin/python-petstore.sh
|
||||
./bin/python3-petstore.sh
|
||||
./bin/qt5-petstore.sh
|
||||
./bin/retrofit-petstore.sh
|
||||
./bin/ruby-petstore.sh
|
||||
./bin/objc-petstore.sh
|
||||
./bin/scala-async-petstore.sh
|
||||
./bin/scala-petstore.sh
|
||||
./bin/scalatra-petstore-server.sh
|
||||
./bin/silex-petstore-server.sh
|
||||
./bin/spring-mvc-petstore-server.sh
|
||||
./bin/swift-petstore.sh
|
||||
./bin/tizen-petstore.sh
|
||||
./bin/typescript-angular-petstore.sh
|
||||
./bin/typescript-node-petstore.sh
|
||||
|
||||
4
bin/swift-petstore.json
Normal file
4
bin/swift-petstore.json
Normal file
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"projectName": "PetstoreClient",
|
||||
"responseAs": "PromiseKit"
|
||||
}
|
||||
@@ -26,6 +26,6 @@ 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/swift -i modules/swagger-codegen/src/test/resources/2_0/petstore.json -l swift -o samples/client/petstore/swift"
|
||||
ags="$@ generate -t modules/swagger-codegen/src/main/resources/swift -i modules/swagger-codegen/src/test/resources/2_0/petstore.json -l swift -c ./bin/swift-petstore.json -o samples/client/petstore/swift"
|
||||
|
||||
java -DappName=PetstoreClient $JAVA_OPTS -jar $executable $ags
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package io.swagger.codegen;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public class CodegenSecurity {
|
||||
public String name;
|
||||
public String type;
|
||||
@@ -7,4 +9,7 @@ public class CodegenSecurity {
|
||||
// ApiKey specific
|
||||
public String keyParamName;
|
||||
public Boolean isKeyInQuery, isKeyInHeader;
|
||||
// Oauth specific
|
||||
public String flow, authorizationUrl, tokenUrl;
|
||||
public Set<String> scopes;
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ import io.swagger.models.Swagger;
|
||||
import io.swagger.models.auth.ApiKeyAuthDefinition;
|
||||
import io.swagger.models.auth.BasicAuthDefinition;
|
||||
import io.swagger.models.auth.In;
|
||||
import io.swagger.models.auth.OAuth2Definition;
|
||||
import io.swagger.models.auth.SecuritySchemeDefinition;
|
||||
import io.swagger.models.parameters.BodyParameter;
|
||||
import io.swagger.models.parameters.CookieParameter;
|
||||
@@ -50,6 +51,7 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
@@ -851,6 +853,17 @@ public class DefaultCodegen {
|
||||
}
|
||||
op.bodyParam = bodyParam;
|
||||
op.httpMethod = httpMethod.toUpperCase();
|
||||
// move "required" parameters in front of "optional" parameters
|
||||
Collections.sort(allParams, new Comparator<CodegenParameter>() {
|
||||
@Override
|
||||
public int compare(CodegenParameter one, CodegenParameter another) {
|
||||
boolean oneRequired = one.required == null ? false : one.required;
|
||||
boolean anotherRequired = another.required == null ? false : another.required;
|
||||
if (oneRequired == anotherRequired) return 0;
|
||||
else if (oneRequired) return -1;
|
||||
else return 1;
|
||||
}
|
||||
});
|
||||
op.allParams = addHasMore(allParams);
|
||||
op.bodyParams = addHasMore(bodyParams);
|
||||
op.pathParams = addHasMore(pathParams);
|
||||
@@ -1062,10 +1075,17 @@ public class DefaultCodegen {
|
||||
sec.keyParamName = apiKeyDefinition.getName();
|
||||
sec.isKeyInHeader = apiKeyDefinition.getIn() == In.HEADER;
|
||||
sec.isKeyInQuery = !sec.isKeyInHeader;
|
||||
} else if(schemeDefinition instanceof BasicAuthDefinition) {
|
||||
sec.isKeyInHeader = sec.isKeyInQuery = sec.isApiKey = sec.isOAuth = false;
|
||||
sec.isBasic = true;
|
||||
} else {
|
||||
sec.isKeyInHeader = sec.isKeyInQuery = sec.isApiKey = false;
|
||||
sec.isBasic = schemeDefinition instanceof BasicAuthDefinition;
|
||||
sec.isOAuth = !sec.isBasic;
|
||||
final OAuth2Definition oauth2Definition = (OAuth2Definition) schemeDefinition;
|
||||
sec.isKeyInHeader = sec.isKeyInQuery = sec.isApiKey = sec.isBasic = false;
|
||||
sec.isOAuth = true;
|
||||
sec.flow = oauth2Definition.getFlow();
|
||||
sec.authorizationUrl = oauth2Definition.getAuthorizationUrl();
|
||||
sec.tokenUrl = oauth2Definition.getTokenUrl();
|
||||
sec.scopes = oauth2Definition.getScopes().keySet();
|
||||
}
|
||||
|
||||
sec.hasMore = it.hasNext();
|
||||
|
||||
@@ -9,6 +9,7 @@ import io.swagger.models.Model;
|
||||
import io.swagger.models.Operation;
|
||||
import io.swagger.models.Path;
|
||||
import io.swagger.models.Swagger;
|
||||
import io.swagger.models.auth.OAuth2Definition;
|
||||
import io.swagger.models.auth.SecuritySchemeDefinition;
|
||||
import io.swagger.util.Json;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
@@ -371,7 +372,22 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
|
||||
String securityName = security.keySet().iterator().next();
|
||||
SecuritySchemeDefinition securityDefinition = fromSecurity(securityName);
|
||||
if (securityDefinition != null) {
|
||||
authMethods.put(securityName, securityDefinition);
|
||||
if(securityDefinition instanceof OAuth2Definition) {
|
||||
OAuth2Definition oauth2Definition = (OAuth2Definition) securityDefinition;
|
||||
OAuth2Definition oauth2Operation = new OAuth2Definition();
|
||||
oauth2Operation.setType(oauth2Definition.getType());
|
||||
oauth2Operation.setAuthorizationUrl(oauth2Definition.getAuthorizationUrl());
|
||||
oauth2Operation.setFlow(oauth2Definition.getFlow());
|
||||
oauth2Operation.setTokenUrl(oauth2Definition.getTokenUrl());
|
||||
for (String scope : security.values().iterator().next()) {
|
||||
if (oauth2Definition.getScopes().containsKey(scope)) {
|
||||
oauth2Operation.addScope(scope, oauth2Definition.getScopes().get(scope));
|
||||
}
|
||||
}
|
||||
authMethods.put(securityName, oauth2Operation);
|
||||
} else {
|
||||
authMethods.put(securityName, securityDefinition);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!authMethods.isEmpty()) {
|
||||
|
||||
@@ -232,6 +232,8 @@ public class AndroidClientCodegen extends DefaultCodegen implements CodegenConfi
|
||||
(sourceFolder + File.separator + invokerPackage).replace(".", java.io.File.separator), "JsonUtil.java"));
|
||||
supportingFiles.add(new SupportingFile("apiException.mustache",
|
||||
(sourceFolder + File.separator + invokerPackage).replace(".", java.io.File.separator), "ApiException.java"));
|
||||
supportingFiles.add(new SupportingFile("Pair.mustache",
|
||||
(sourceFolder + File.separator + invokerPackage).replace(".", java.io.File.separator), "Pair.java"));
|
||||
}
|
||||
|
||||
public Boolean getUseAndroidMavenGradlePlugin() {
|
||||
|
||||
@@ -116,6 +116,7 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
supportingFiles.add(new SupportingFile("Configuration.mustache", invokerFolder, "Configuration.java"));
|
||||
supportingFiles.add(new SupportingFile("JsonUtil.mustache", invokerFolder, "JsonUtil.java"));
|
||||
supportingFiles.add(new SupportingFile("StringUtil.mustache", invokerFolder, "StringUtil.java"));
|
||||
supportingFiles.add(new SupportingFile("Pair.mustache", invokerFolder, "Pair.java"));
|
||||
|
||||
final String authFolder = (sourceFolder + File.separator + invokerPackage + ".auth").replace(".", File.separator);
|
||||
supportingFiles.add(new SupportingFile("auth/Authentication.mustache", authFolder, "Authentication.java"));
|
||||
|
||||
@@ -20,7 +20,7 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
protected String groupId = "swagger";
|
||||
protected String artifactId = "swagger-client";
|
||||
protected String packagePath = "SwaggerClient-php";
|
||||
protected String artifactVersion = null;
|
||||
protected String artifactVersion = "1.0.0";
|
||||
protected String srcBasePath = "lib";
|
||||
|
||||
public PhpClientCodegen() {
|
||||
@@ -79,7 +79,7 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
typeMapping.put("boolean", "bool");
|
||||
typeMapping.put("date", "\\DateTime");
|
||||
typeMapping.put("datetime", "\\DateTime");
|
||||
typeMapping.put("file", "string");
|
||||
typeMapping.put("file", "\\SplFileObject");
|
||||
typeMapping.put("map", "map");
|
||||
typeMapping.put("array", "array");
|
||||
typeMapping.put("list", "array");
|
||||
|
||||
@@ -33,6 +33,7 @@ public class Python3ClientCodegen extends DefaultCodegen implements CodegenConfi
|
||||
languageSpecificPrimitives.add("bool");
|
||||
languageSpecificPrimitives.add("str");
|
||||
languageSpecificPrimitives.add("datetime");
|
||||
languageSpecificPrimitives.add("date");
|
||||
|
||||
typeMapping.clear();
|
||||
typeMapping.put("integer", "int");
|
||||
@@ -43,7 +44,8 @@ public class Python3ClientCodegen extends DefaultCodegen implements CodegenConfi
|
||||
typeMapping.put("map", "map");
|
||||
typeMapping.put("boolean", "bool");
|
||||
typeMapping.put("string", "str");
|
||||
typeMapping.put("date", "datetime");
|
||||
typeMapping.put("date", "date");
|
||||
typeMapping.put("DateTime", "datetime");
|
||||
|
||||
// from https://docs.python.org/release/2.5.4/ref/keywords.html
|
||||
reservedWords = new HashSet<String>(
|
||||
|
||||
@@ -34,6 +34,7 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
languageSpecificPrimitives.add("bool");
|
||||
languageSpecificPrimitives.add("str");
|
||||
languageSpecificPrimitives.add("datetime");
|
||||
languageSpecificPrimitives.add("date");
|
||||
|
||||
typeMapping.clear();
|
||||
typeMapping.put("integer", "int");
|
||||
@@ -44,7 +45,8 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
typeMapping.put("map", "dict");
|
||||
typeMapping.put("boolean", "bool");
|
||||
typeMapping.put("string", "str");
|
||||
typeMapping.put("date", "datetime");
|
||||
typeMapping.put("date", "date");
|
||||
typeMapping.put("DateTime", "datetime");
|
||||
typeMapping.put("object", "object");
|
||||
|
||||
// from https://docs.python.org/release/2.5.4/ref/keywords.html
|
||||
|
||||
@@ -62,6 +62,7 @@ public class RubyClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
typeMapping.put("List", "Array");
|
||||
typeMapping.put("map", "Hash");
|
||||
typeMapping.put("object", "Object");
|
||||
typeMapping.put("file", "File");
|
||||
|
||||
// remove modelPackage and apiPackage added by default
|
||||
cliOptions.clear();
|
||||
|
||||
@@ -2,6 +2,7 @@ package io.swagger.codegen.languages;
|
||||
|
||||
import io.swagger.codegen.CodegenConfig;
|
||||
import io.swagger.codegen.CodegenOperation;
|
||||
import io.swagger.codegen.CodegenResponse;
|
||||
import io.swagger.codegen.CodegenType;
|
||||
import io.swagger.codegen.SupportingFile;
|
||||
import io.swagger.models.Operation;
|
||||
@@ -146,6 +147,14 @@ public class SpringMVCServerCodegen extends JavaClientCodegen implements Codegen
|
||||
if (operations != null) {
|
||||
List<CodegenOperation> ops = (List<CodegenOperation>) operations.get("operation");
|
||||
for (CodegenOperation operation : ops) {
|
||||
List<CodegenResponse> responses = operation.responses;
|
||||
if (responses != null) {
|
||||
for (CodegenResponse resp : responses) {
|
||||
if ("0".equals(resp.code)) {
|
||||
resp.code = "200";
|
||||
}
|
||||
}
|
||||
}
|
||||
if (operation.returnType == null) {
|
||||
operation.returnType = "Void";
|
||||
} else if (operation.returnType.startsWith("List")) {
|
||||
|
||||
@@ -0,0 +1,286 @@
|
||||
package io.swagger.codegen.languages;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.Iterators;
|
||||
import com.google.common.collect.Lists;
|
||||
import io.swagger.codegen.*;
|
||||
import io.swagger.models.Model;
|
||||
import io.swagger.models.Operation;
|
||||
import io.swagger.models.parameters.HeaderParameter;
|
||||
import io.swagger.models.parameters.Parameter;
|
||||
import io.swagger.models.properties.ArrayProperty;
|
||||
import io.swagger.models.properties.MapProperty;
|
||||
import io.swagger.models.properties.Property;
|
||||
import org.apache.commons.lang.ArrayUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.*;
|
||||
import java.io.File;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class SwiftCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
private static final Pattern PATH_PARAM_PATTERN = Pattern.compile("\\{[a-zA-Z_]+\\}");
|
||||
protected static final String LIBRARY_PROMISE_KIT = "PromiseKit";
|
||||
protected static final String[] RESPONSE_LIBRARIES = { LIBRARY_PROMISE_KIT };
|
||||
protected String projectName = "SwaggerClient";
|
||||
protected boolean unwrapRequired = false;
|
||||
protected String[] responseAs = new String[0];
|
||||
protected String sourceFolder = "Classes" + File.separator + "Swaggers";
|
||||
|
||||
public CodegenType getTag() {
|
||||
return CodegenType.CLIENT;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return "swift";
|
||||
}
|
||||
|
||||
public String getHelp() {
|
||||
return "Generates a swift client library.";
|
||||
}
|
||||
|
||||
public SwiftCodegen() {
|
||||
super();
|
||||
outputFolder = "generated-code" + File.separator + "swift";
|
||||
modelTemplateFiles.put("model.mustache", ".swift");
|
||||
apiTemplateFiles.put("api.mustache", ".swift");
|
||||
templateDir = "swift";
|
||||
apiPackage = File.separator + "APIs";
|
||||
modelPackage = File.separator + "Models";
|
||||
|
||||
languageSpecificPrimitives = new HashSet<String>(
|
||||
Arrays.asList(
|
||||
"Int",
|
||||
"Float",
|
||||
"Double",
|
||||
"Bool",
|
||||
"Void",
|
||||
"String",
|
||||
"Character")
|
||||
);
|
||||
defaultIncludes = new HashSet<String>(
|
||||
Arrays.asList(
|
||||
"NSDate",
|
||||
"Array",
|
||||
"Dictionary",
|
||||
"Set",
|
||||
"Any",
|
||||
"Empty",
|
||||
"AnyObject")
|
||||
);
|
||||
reservedWords = new HashSet<String>(
|
||||
Arrays.asList(
|
||||
"class", "break", "as", "associativity", "deinit", "case", "dynamicType", "convenience", "enum", "continue",
|
||||
"false", "dynamic", "extension", "default", "is", "didSet", "func", "do", "nil", "final", "import", "else",
|
||||
"self", "get", "init", "fallthrough", "Self", "infix", "internal", "for", "super", "inout", "let", "if",
|
||||
"true", "lazy", "operator", "in", "COLUMN", "left", "private", "return", "FILE", "mutating", "protocol",
|
||||
"switch", "FUNCTION", "none", "public", "where", "LINE", "nonmutating", "static", "while", "optional",
|
||||
"struct", "override", "subscript", "postfix", "typealias", "precedence", "var", "prefix", "Protocol",
|
||||
"required", "right", "set", "Type", "unowned", "weak")
|
||||
);
|
||||
|
||||
typeMapping = new HashMap<String, String>();
|
||||
typeMapping.put("array", "Array");
|
||||
typeMapping.put("List", "Array");
|
||||
typeMapping.put("map", "Dictionary");
|
||||
typeMapping.put("date", "NSDate");
|
||||
typeMapping.put("Date", "NSDate");
|
||||
typeMapping.put("DateTime", "NSDate");
|
||||
typeMapping.put("boolean", "Bool");
|
||||
typeMapping.put("string", "String");
|
||||
typeMapping.put("char", "Character");
|
||||
typeMapping.put("short", "Int");
|
||||
typeMapping.put("int", "Int");
|
||||
typeMapping.put("long", "Int");
|
||||
typeMapping.put("integer", "Int");
|
||||
typeMapping.put("Integer", "Int");
|
||||
typeMapping.put("float", "Float");
|
||||
typeMapping.put("number", "Double");
|
||||
typeMapping.put("double", "Double");
|
||||
typeMapping.put("object", "String");
|
||||
typeMapping.put("file", "NSData");
|
||||
|
||||
importMapping = new HashMap<String, String>();
|
||||
|
||||
cliOptions.add(new CliOption("projectName", "Project name in Xcode"));
|
||||
cliOptions.add(new CliOption("responseAs", "Optionally use libraries to manage response. Currently " +
|
||||
StringUtils.join(RESPONSE_LIBRARIES, ", ") + " are available."));
|
||||
cliOptions.add(new CliOption("unwrapRequired", "Treat 'required' properties in response as non-optional " +
|
||||
"(which would crash the app if api returns null as opposed to required option specified in json schema"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processOpts() {
|
||||
super.processOpts();
|
||||
|
||||
// Setup project name
|
||||
if (additionalProperties.containsKey("projectName")) {
|
||||
projectName = (String) additionalProperties.get("projectName");
|
||||
} else {
|
||||
additionalProperties.put("projectName", projectName);
|
||||
}
|
||||
sourceFolder = projectName + File.separator + sourceFolder;
|
||||
|
||||
// Setup unwrapRequired option, which makes all the properties with "required" non-optional
|
||||
if (additionalProperties.containsKey("unwrapRequired")) {
|
||||
unwrapRequired = Boolean.parseBoolean(String.valueOf(additionalProperties.get("unwrapRequired")));
|
||||
}
|
||||
additionalProperties.put("unwrapRequired", unwrapRequired);
|
||||
|
||||
// Setup unwrapRequired option, which makes all the properties with "required" non-optional
|
||||
if (additionalProperties.containsKey("responseAs")) {
|
||||
Object responseAsObject = additionalProperties.get("responseAs");
|
||||
if (responseAsObject instanceof String) {
|
||||
responseAs = ((String)responseAsObject).split(",");
|
||||
} else {
|
||||
responseAs = (String[]) responseAsObject;
|
||||
}
|
||||
}
|
||||
additionalProperties.put("responseAs", responseAs);
|
||||
if (ArrayUtils.contains(responseAs, LIBRARY_PROMISE_KIT)) {
|
||||
additionalProperties.put("usePromiseKit", true);
|
||||
}
|
||||
|
||||
supportingFiles.add(new SupportingFile("Cartfile.mustache", "", "Cartfile"));
|
||||
supportingFiles.add(new SupportingFile("APIHelper.mustache", sourceFolder, "APIHelper.swift"));
|
||||
supportingFiles.add(new SupportingFile("AlamofireImplementations.mustache", sourceFolder,
|
||||
"AlamofireImplementations.swift"));
|
||||
supportingFiles.add(new SupportingFile("Extensions.mustache", sourceFolder, "Extensions.swift"));
|
||||
supportingFiles.add(new SupportingFile("Models.mustache", sourceFolder, "Models.swift"));
|
||||
supportingFiles.add(new SupportingFile("APIs.mustache", sourceFolder, "APIs.swift"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String escapeReservedWord(String name) {
|
||||
return "Swagger" + name; // add an underscore to the name
|
||||
}
|
||||
|
||||
@Override
|
||||
public String modelFileFolder() {
|
||||
return outputFolder + File.separator + sourceFolder + modelPackage().replace('.', File.separatorChar);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String apiFileFolder() {
|
||||
return outputFolder + File.separator + sourceFolder + apiPackage().replace('.', File.separatorChar);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTypeDeclaration(Property p) {
|
||||
if (p instanceof ArrayProperty) {
|
||||
ArrayProperty ap = (ArrayProperty) p;
|
||||
Property inner = ap.getItems();
|
||||
return "[" + getTypeDeclaration(inner) + "]";
|
||||
} else if (p instanceof MapProperty) {
|
||||
MapProperty mp = (MapProperty) p;
|
||||
Property inner = mp.getAdditionalProperties();
|
||||
return "[String:" + getTypeDeclaration(inner) + "]";
|
||||
}
|
||||
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 toModelName(type);
|
||||
} else
|
||||
type = swaggerType;
|
||||
return toModelName(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toDefaultValue(Property p) {
|
||||
// nil
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toInstantiationType(Property p) {
|
||||
if (p instanceof MapProperty) {
|
||||
MapProperty ap = (MapProperty) p;
|
||||
String inner = getSwaggerType(ap.getAdditionalProperties());
|
||||
return "[String:" + inner + "]";
|
||||
} else if (p instanceof ArrayProperty) {
|
||||
ArrayProperty ap = (ArrayProperty) p;
|
||||
String inner = getSwaggerType(ap.getItems());
|
||||
return "[" + inner + "]";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CodegenProperty fromProperty(String name, Property p) {
|
||||
CodegenProperty codegenProperty = super.fromProperty(name, p);
|
||||
if (codegenProperty.isEnum) {
|
||||
List<Map<String, String>> swiftEnums = new ArrayList<Map<String, String>>();
|
||||
List<String> values = (List<String>) codegenProperty.allowableValues.get("values");
|
||||
for (String value : values) {
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
map.put("enum", StringUtils.capitalize(value));
|
||||
map.put("raw", value);
|
||||
swiftEnums.add(map);
|
||||
}
|
||||
codegenProperty.allowableValues.put("values", swiftEnums);
|
||||
codegenProperty.datatypeWithEnum =
|
||||
StringUtils.left(codegenProperty.datatypeWithEnum, codegenProperty.datatypeWithEnum.length() - "Enum".length());
|
||||
if (reservedWords.contains(codegenProperty.datatypeWithEnum)) {
|
||||
codegenProperty.datatypeWithEnum = escapeReservedWord(codegenProperty.datatypeWithEnum);
|
||||
}
|
||||
}
|
||||
return codegenProperty;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toApiName(String name) {
|
||||
if(name.length() == 0)
|
||||
return "DefaultAPI";
|
||||
return initialCaps(name) + "API";
|
||||
}
|
||||
|
||||
@Override
|
||||
public CodegenOperation fromOperation(String path, String httpMethod, Operation operation, Map<String, Model> definitions) {
|
||||
path = normalizePath(path);
|
||||
List<Parameter> parameters = operation.getParameters();
|
||||
parameters = Lists.newArrayList(Iterators.filter(parameters.iterator(), new Predicate<Parameter>() {
|
||||
@Override
|
||||
public boolean apply(@Nullable Parameter parameter) {
|
||||
return !(parameter instanceof HeaderParameter);
|
||||
}
|
||||
}));
|
||||
operation.setParameters(parameters);
|
||||
return super.fromOperation(path, httpMethod, operation, definitions);
|
||||
}
|
||||
|
||||
private static String normalizePath(String path) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
||||
int cursor = 0;
|
||||
Matcher matcher = PATH_PARAM_PATTERN.matcher(path);
|
||||
boolean found = matcher.find();
|
||||
while (found) {
|
||||
String stringBeforeMatch = path.substring(cursor, matcher.start());
|
||||
builder.append(stringBeforeMatch);
|
||||
|
||||
String group = matcher.group().substring(1, matcher.group().length() - 1);
|
||||
group = camelize(group, true);
|
||||
builder
|
||||
.append("{")
|
||||
.append(group)
|
||||
.append("}");
|
||||
|
||||
cursor = matcher.end();
|
||||
found = matcher.find();
|
||||
}
|
||||
|
||||
String stringAfterMatch = path.substring(cursor);
|
||||
builder.append(stringAfterMatch);
|
||||
|
||||
return builder.toString();
|
||||
}
|
||||
}
|
||||
@@ -1,265 +0,0 @@
|
||||
package io.swagger.codegen.languages;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.Iterators;
|
||||
import com.google.common.collect.Lists;
|
||||
import io.swagger.codegen.CodegenConfig;
|
||||
import io.swagger.codegen.CodegenOperation;
|
||||
import io.swagger.codegen.CodegenProperty;
|
||||
import io.swagger.codegen.CodegenType;
|
||||
import io.swagger.codegen.DefaultCodegen;
|
||||
import io.swagger.codegen.SupportingFile;
|
||||
import io.swagger.models.Model;
|
||||
import io.swagger.models.Operation;
|
||||
import io.swagger.models.parameters.HeaderParameter;
|
||||
import io.swagger.models.parameters.Parameter;
|
||||
import io.swagger.models.properties.ArrayProperty;
|
||||
import io.swagger.models.properties.MapProperty;
|
||||
import io.swagger.models.properties.Property;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class SwiftGenerator extends DefaultCodegen implements CodegenConfig {
|
||||
private static final Pattern PATH_PARAM_PATTERN = Pattern.compile("\\{[a-zA-Z_]+\\}");
|
||||
protected String sourceFolder = "Classes/Swaggers";
|
||||
|
||||
public SwiftGenerator() {
|
||||
super();
|
||||
outputFolder = "generated-code/swift";
|
||||
modelTemplateFiles.put("model.mustache", ".swift");
|
||||
apiTemplateFiles.put("api.mustache", ".swift");
|
||||
templateDir = "swift";
|
||||
apiPackage = "/APIs";
|
||||
modelPackage = "/Models";
|
||||
|
||||
// Inject application name
|
||||
String appName = System.getProperty("appName");
|
||||
if (appName == null) {
|
||||
appName = "SwaggerClient";
|
||||
}
|
||||
additionalProperties.put("projectName", appName);
|
||||
|
||||
// Inject base url override
|
||||
String basePathOverride = System.getProperty("basePathOverride");
|
||||
if (basePathOverride != null) {
|
||||
additionalProperties.put("basePathOverride", basePathOverride);
|
||||
}
|
||||
|
||||
sourceFolder = appName + "/" + sourceFolder;
|
||||
|
||||
supportingFiles.add(new SupportingFile("Cartfile.mustache", "", "Cartfile"));
|
||||
supportingFiles.add(new SupportingFile("APIHelper.mustache", sourceFolder, "APIHelper.swift"));
|
||||
supportingFiles.add(new SupportingFile("AlamofireImplementations.mustache", sourceFolder, "AlamofireImplementations.swift"));
|
||||
supportingFiles.add(new SupportingFile("Extensions.mustache", sourceFolder, "Extensions.swift"));
|
||||
supportingFiles.add(new SupportingFile("Models.mustache", sourceFolder, "Models.swift"));
|
||||
supportingFiles.add(new SupportingFile("APIs.mustache", sourceFolder, "APIs.swift"));
|
||||
|
||||
languageSpecificPrimitives = new HashSet<String>(
|
||||
Arrays.asList(
|
||||
"Int",
|
||||
"Float",
|
||||
"Double",
|
||||
"Bool",
|
||||
"Void",
|
||||
"String",
|
||||
"Character")
|
||||
);
|
||||
defaultIncludes = new HashSet<String>(
|
||||
Arrays.asList(
|
||||
"NSDate",
|
||||
"Array",
|
||||
"Dictionary",
|
||||
"Set",
|
||||
"Any",
|
||||
"Empty",
|
||||
"AnyObject")
|
||||
);
|
||||
reservedWords = new HashSet<String>(
|
||||
Arrays.asList(
|
||||
"class", "break", "as", "associativity", "deinit", "case", "dynamicType", "convenience", "enum", "continue",
|
||||
"false", "dynamic", "extension", "default", "is", "didSet", "func", "do", "nil", "final", "import", "else",
|
||||
"self", "get", "init", "fallthrough", "Self", "infix", "internal", "for", "super", "inout", "let", "if",
|
||||
"true", "lazy", "operator", "in", "COLUMN", "left", "private", "return", "FILE", "mutating", "protocol",
|
||||
"switch", "FUNCTION", "none", "public", "where", "LINE", "nonmutating", "static", "while", "optional",
|
||||
"struct", "override", "subscript", "postfix", "typealias", "precedence", "var", "prefix", "Protocol",
|
||||
"required", "right", "set", "Type", "unowned", "weak")
|
||||
);
|
||||
|
||||
typeMapping = new HashMap<String, String>();
|
||||
typeMapping.put("array", "Array");
|
||||
typeMapping.put("List", "Array");
|
||||
typeMapping.put("map", "Dictionary");
|
||||
typeMapping.put("date", "NSDate");
|
||||
typeMapping.put("Date", "NSDate");
|
||||
typeMapping.put("DateTime", "NSDate");
|
||||
typeMapping.put("boolean", "Bool");
|
||||
typeMapping.put("string", "String");
|
||||
typeMapping.put("char", "Character");
|
||||
typeMapping.put("short", "Int");
|
||||
typeMapping.put("int", "Int");
|
||||
typeMapping.put("long", "Int");
|
||||
typeMapping.put("integer", "Int");
|
||||
typeMapping.put("Integer", "Int");
|
||||
typeMapping.put("float", "Float");
|
||||
typeMapping.put("number", "Double");
|
||||
typeMapping.put("double", "Double");
|
||||
typeMapping.put("object", "AnyObject");
|
||||
typeMapping.put("file", "NSData");
|
||||
|
||||
importMapping = new HashMap<String, String>();
|
||||
}
|
||||
|
||||
private static String normalizePath(String path) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
||||
int cursor = 0;
|
||||
Matcher matcher = PATH_PARAM_PATTERN.matcher(path);
|
||||
boolean found = matcher.find();
|
||||
while (found) {
|
||||
String stringBeforeMatch = path.substring(cursor, matcher.start());
|
||||
builder.append(stringBeforeMatch);
|
||||
|
||||
String group = matcher.group().substring(1, matcher.group().length() - 1);
|
||||
group = camelize(group, true);
|
||||
builder
|
||||
.append("{")
|
||||
.append(group)
|
||||
.append("}");
|
||||
|
||||
cursor = matcher.end();
|
||||
found = matcher.find();
|
||||
}
|
||||
|
||||
String stringAfterMatch = path.substring(cursor);
|
||||
builder.append(stringAfterMatch);
|
||||
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
public CodegenType getTag() {
|
||||
return CodegenType.CLIENT;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return "swift";
|
||||
}
|
||||
|
||||
public String getHelp() {
|
||||
return "Generates a swift client library.";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String escapeReservedWord(String name) {
|
||||
return "_" + name; // add an underscore to the name
|
||||
}
|
||||
|
||||
@Override
|
||||
public String modelFileFolder() {
|
||||
return outputFolder + "/" + sourceFolder + modelPackage().replace('.', File.separatorChar);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String apiFileFolder() {
|
||||
return outputFolder + "/" + sourceFolder + apiPackage().replace('.', File.separatorChar);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTypeDeclaration(Property p) {
|
||||
if (p instanceof ArrayProperty) {
|
||||
ArrayProperty ap = (ArrayProperty) p;
|
||||
Property inner = ap.getItems();
|
||||
return "[" + getTypeDeclaration(inner) + "]";
|
||||
} else if (p instanceof MapProperty) {
|
||||
MapProperty mp = (MapProperty) p;
|
||||
Property inner = mp.getAdditionalProperties();
|
||||
return "[String:" + getTypeDeclaration(inner) + "]";
|
||||
}
|
||||
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 toModelName(type);
|
||||
}
|
||||
} else {
|
||||
type = swaggerType;
|
||||
}
|
||||
return toModelName(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toDefaultValue(Property p) {
|
||||
// nil
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toInstantiationType(Property p) {
|
||||
if (p instanceof MapProperty) {
|
||||
MapProperty ap = (MapProperty) p;
|
||||
String inner = getSwaggerType(ap.getAdditionalProperties());
|
||||
return "[String:" + inner + "]";
|
||||
} else if (p instanceof ArrayProperty) {
|
||||
ArrayProperty ap = (ArrayProperty) p;
|
||||
String inner = getSwaggerType(ap.getItems());
|
||||
return "[" + inner + "]";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CodegenProperty fromProperty(String name, Property p) {
|
||||
CodegenProperty codegenProperty = super.fromProperty(name, p);
|
||||
if (codegenProperty.isEnum) {
|
||||
List<Map<String, String>> swiftEnums = new ArrayList<Map<String, String>>();
|
||||
List<String> values = (List<String>) codegenProperty.allowableValues.get("values");
|
||||
for (String value : values) {
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
map.put("enum", StringUtils.capitalize(value));
|
||||
map.put("raw", value);
|
||||
swiftEnums.add(map);
|
||||
}
|
||||
codegenProperty.allowableValues.put("values", swiftEnums);
|
||||
codegenProperty.datatypeWithEnum =
|
||||
StringUtils.left(codegenProperty.datatypeWithEnum, codegenProperty.datatypeWithEnum.length() - "Enum".length());
|
||||
}
|
||||
return codegenProperty;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toApiName(String name) {
|
||||
if (name.length() == 0) {
|
||||
return "DefaultAPI";
|
||||
}
|
||||
return initialCaps(name) + "API";
|
||||
}
|
||||
|
||||
@Override
|
||||
public CodegenOperation fromOperation(String path, String httpMethod, Operation operation, Map<String, Model> definitions) {
|
||||
path = normalizePath(path);
|
||||
List<Parameter> parameters = operation.getParameters();
|
||||
parameters = Lists.newArrayList(Iterators.filter(parameters.iterator(), new Predicate<Parameter>() {
|
||||
@Override
|
||||
public boolean apply(@Nullable Parameter parameter) {
|
||||
return !(parameter instanceof HeaderParameter);
|
||||
}
|
||||
}));
|
||||
operation.setParameters(parameters);
|
||||
return super.fromOperation(path, httpMethod, operation, definitions);
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,7 @@ public class TypeScriptAngularClientCodegen extends TypeScriptNodeClientCodegen
|
||||
apiTemplateFiles.put("api.mustache", ".ts");
|
||||
templateDir = "TypeScript-Angular";
|
||||
apiPackage = "api";
|
||||
modelPackage = "api";
|
||||
modelPackage = "model";
|
||||
|
||||
supportingFiles.add(new SupportingFile("api.d.mustache", apiPackage + File.separator, "api.d.ts"));
|
||||
}
|
||||
|
||||
@@ -77,6 +77,8 @@ public class TypeScriptNodeClientCodegen extends DefaultCodegen implements Codeg
|
||||
typeMapping.put("double", "number");
|
||||
typeMapping.put("object", "any");
|
||||
typeMapping.put("integer", "number");
|
||||
typeMapping.put("Map", "any");
|
||||
typeMapping.put("DateTime", "Date");
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.TimeZone;
|
||||
|
||||
@@ -238,6 +239,62 @@ public class ApiClient {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Format to {@code Pair} objects.
|
||||
*/
|
||||
public List<Pair> parameterToPairs(String collectionFormat, String name, Object value){
|
||||
List<Pair> params = new ArrayList<Pair>();
|
||||
|
||||
// preconditions
|
||||
if (name == null || name.isEmpty() || value == null) return params;
|
||||
|
||||
Collection valueCollection = null;
|
||||
if (value instanceof Collection) {
|
||||
valueCollection = (Collection) value;
|
||||
} else {
|
||||
params.add(new Pair(name, parameterToString(value)));
|
||||
return params;
|
||||
}
|
||||
|
||||
if (valueCollection.isEmpty()){
|
||||
return params;
|
||||
}
|
||||
|
||||
// get the collection format
|
||||
collectionFormat = (collectionFormat == null || collectionFormat.isEmpty() ? "csv" : collectionFormat); // default: csv
|
||||
|
||||
// create the params based on the collection format
|
||||
if (collectionFormat.equals("multi")) {
|
||||
for (Object item : valueCollection) {
|
||||
params.add(new Pair(name, parameterToString(item)));
|
||||
}
|
||||
|
||||
return params;
|
||||
}
|
||||
|
||||
String delimiter = ",";
|
||||
|
||||
if (collectionFormat.equals("csv")) {
|
||||
delimiter = ",";
|
||||
} else if (collectionFormat.equals("ssv")) {
|
||||
delimiter = " ";
|
||||
} else if (collectionFormat.equals("tsv")) {
|
||||
delimiter = "\t";
|
||||
} else if (collectionFormat.equals("pipes")) {
|
||||
delimiter = "|";
|
||||
}
|
||||
|
||||
StringBuilder sb = new StringBuilder() ;
|
||||
for (Object item : valueCollection) {
|
||||
sb.append(delimiter);
|
||||
sb.append(parameterToString(item));
|
||||
}
|
||||
|
||||
params.add(new Pair(name, sb.substring(1)));
|
||||
|
||||
return params;
|
||||
}
|
||||
|
||||
/**
|
||||
* Select the Accept header's value from the given accepts array:
|
||||
* if JSON exists in the given array, use it;
|
||||
@@ -341,23 +398,25 @@ public class ApiClient {
|
||||
* @param authNames The authentications to apply
|
||||
* @return The response body in type of string
|
||||
*/
|
||||
public String invokeAPI(String path, String method, Map<String, String> queryParams, Object body, Map<String, String> headerParams, Map<String, String> formParams, String accept, String contentType, String[] authNames) throws ApiException {
|
||||
public String invokeAPI(String path, String method, List<Pair> queryParams, Object body, Map<String, String> headerParams, Map<String, String> formParams, String accept, String contentType, String[] authNames) throws ApiException {
|
||||
updateParamsForAuth(authNames, queryParams, headerParams);
|
||||
|
||||
Client client = getClient();
|
||||
|
||||
StringBuilder b = new StringBuilder();
|
||||
for(String key : queryParams.keySet()) {
|
||||
String value = queryParams.get(key);
|
||||
if (value != null){
|
||||
if(b.toString().length() == 0)
|
||||
b.append("?");
|
||||
else
|
||||
b.append("?");
|
||||
if (queryParams != null){
|
||||
for (Pair queryParam : queryParams){
|
||||
if (!queryParam.getName().isEmpty()) {
|
||||
b.append(escapeString(queryParam.getName()));
|
||||
b.append("=");
|
||||
b.append(escapeString(queryParam.getValue()));
|
||||
b.append("&");
|
||||
b.append(escapeString(key)).append("=").append(escapeString(value));
|
||||
}
|
||||
}
|
||||
}
|
||||
String querystring = b.toString();
|
||||
|
||||
String querystring = b.substring(0, b.length() - 1);
|
||||
|
||||
Builder builder;
|
||||
if (accept == null)
|
||||
@@ -457,7 +516,7 @@ public class ApiClient {
|
||||
*
|
||||
* @param authNames The authentications to apply
|
||||
*/
|
||||
private void updateParamsForAuth(String[] authNames, Map<String, String> queryParams, Map<String, String> headerParams) {
|
||||
private void updateParamsForAuth(String[] authNames, List<Pair> queryParams, Map<String, String> headerParams) {
|
||||
for (String authName : authNames) {
|
||||
Authentication auth = authentications.get(authName);
|
||||
if (auth == null) throw new RuntimeException("Authentication undefined: " + authName);
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
package {{invokerPackage}};
|
||||
|
||||
public class Pair {
|
||||
private String name = "";
|
||||
private String value = "";
|
||||
|
||||
public Pair (String name, String value) {
|
||||
setName(name);
|
||||
setValue(value);
|
||||
}
|
||||
|
||||
private void setName(String name) {
|
||||
if (!isValidString(name)) return;
|
||||
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
private void setValue(String value) {
|
||||
if (!isValidString(value)) return;
|
||||
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
private boolean isValidString(String arg) {
|
||||
if (arg == null) return false;
|
||||
if (arg.trim().isEmpty()) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package {{package}};
|
||||
import {{invokerPackage}}.ApiException;
|
||||
import {{invokerPackage}}.ApiClient;
|
||||
import {{invokerPackage}}.Configuration;
|
||||
import {{invokerPackage}}.Pair;
|
||||
|
||||
import {{modelPackage}}.*;
|
||||
|
||||
@@ -58,19 +59,19 @@ public class {{classname}} {
|
||||
|
||||
// create path and map variables
|
||||
String path = "{{path}}".replaceAll("\\{format\\}","json"){{#pathParams}}
|
||||
.replaceAll("\\{" + "{{paramName}}" + "\\}", apiClient.escapeString({{{paramName}}}.toString())){{/pathParams}};
|
||||
.replaceAll("\\{" + "{{baseName}}" + "\\}", apiClient.escapeString({{{paramName}}}.toString())){{/pathParams}};
|
||||
|
||||
// query params
|
||||
Map<String, String> queryParams = new HashMap<String, String>();
|
||||
List<Pair> queryParams = new ArrayList<Pair>();
|
||||
Map<String, String> headerParams = new HashMap<String, String>();
|
||||
Map<String, String> formParams = new HashMap<String, String>();
|
||||
|
||||
{{#queryParams}}if ({{paramName}} != null)
|
||||
queryParams.put("{{baseName}}", apiClient.parameterToString({{paramName}}));
|
||||
{{#queryParams}}
|
||||
queryParams.addAll(apiClient.parameterToPairs("{{#collectionFormat}}{{{collectionFormat}}}{{/collectionFormat}}", "{{baseName}}", {{paramName}}));
|
||||
{{/queryParams}}
|
||||
|
||||
{{#headerParams}}if ({{paramName}} != null)
|
||||
headerParams.put("{{baseName}}", apiClient.parameterToString({{paramName}}));
|
||||
headerParams.put("{{baseName}}", apiClient.parameterToString({{paramName}}));
|
||||
{{/headerParams}}
|
||||
|
||||
final String[] accepts = {
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package {{invokerPackage}}.auth;
|
||||
|
||||
import {{invokerPackage}}.Pair;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.List;
|
||||
|
||||
public class ApiKeyAuth implements Authentication {
|
||||
private final String location;
|
||||
@@ -39,7 +42,7 @@ public class ApiKeyAuth implements Authentication {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyToParams(Map<String, String> queryParams, Map<String, String> headerParams) {
|
||||
public void applyToParams(List<Pair> queryParams, Map<String, String> headerParams) {
|
||||
String value;
|
||||
if (apiKeyPrefix != null) {
|
||||
value = apiKeyPrefix + " " + apiKey;
|
||||
@@ -47,7 +50,7 @@ public class ApiKeyAuth implements Authentication {
|
||||
value = apiKey;
|
||||
}
|
||||
if (location == "query") {
|
||||
queryParams.put(paramName, value);
|
||||
queryParams.add(new Pair(paramName, value));
|
||||
} else if (location == "header") {
|
||||
headerParams.put(paramName, value);
|
||||
}
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
package {{invokerPackage}}.auth;
|
||||
|
||||
import {{invokerPackage}}.Pair;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.List;
|
||||
|
||||
public interface Authentication {
|
||||
/** Apply authentication settings to header and query params. */
|
||||
void applyToParams(Map<String, String> queryParams, Map<String, String> headerParams);
|
||||
void applyToParams(List<Pair> queryParams, Map<String, String> headerParams);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package {{invokerPackage}}.auth;
|
||||
|
||||
import {{invokerPackage}}.Pair;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.List;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import javax.xml.bind.DatatypeConverter;
|
||||
@@ -26,7 +29,7 @@ public class HttpBasicAuth implements Authentication {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyToParams(Map<String, String> queryParams, Map<String, String> headerParams) {
|
||||
public void applyToParams(List<Pair> queryParams, Map<String, String> headerParams) {
|
||||
String str = (username == null ? "" : username) + ":" + (password == null ? "" : password);
|
||||
try {
|
||||
headerParams.put("Authorization", "Basic " + DatatypeConverter.printBase64Binary(str.getBytes("UTF-8")));
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
package {{invokerPackage}}.auth;
|
||||
|
||||
import {{invokerPackage}}.Pair;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.List;
|
||||
|
||||
public class OAuth implements Authentication {
|
||||
@Override
|
||||
public void applyToParams(Map<String, String> queryParams, Map<String, String> headerParams) {
|
||||
public void applyToParams(List<Pair> queryParams, Map<String, String> headerParams) {
|
||||
// TODO: support oauth
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,4 +8,5 @@ This server was generated by the [swagger-codegen](https://github.com/swagger-ap
|
||||
|
||||
The underlying library integrating swagger to Spring-MVC is [springfox](https://github.com/springfox/springfox)
|
||||
|
||||
You can view the server in swagger-ui by pointing to http://localhost:8002{{^contextPath}}/{{/contextPath}}{{#contextPath}}{{contextPath}}{{/contextPath}}/sdoc.jsp
|
||||
You can view the server in swagger-ui by pointing to
|
||||
http://localhost:8002{{^contextPath}}/{{/contextPath}}{{#contextPath}}{{contextPath}}{{/contextPath}}/swagger-ui.html
|
||||
@@ -33,8 +33,7 @@
|
||||
<webAppConfig>
|
||||
<contextPath>{{^contextPath}}/{{/contextPath}}{{#contextPath}}{{contextPath}}{{/contextPath}}</contextPath>
|
||||
</webAppConfig>
|
||||
<webAppSourceDirectory>target/${project.artifactId}-${project-version}</webAppSourceDirectory>
|
||||
<webDefaultXml>${project.basedir}/conf/jetty/webdefault.xml</webDefaultXml>
|
||||
<webAppSourceDirectory>target/${project.artifactId}-${project.version}</webAppSourceDirectory>
|
||||
<stopPort>8079</stopPort>
|
||||
<stopKey>stopit</stopKey>
|
||||
<httpConnector>
|
||||
@@ -63,49 +62,6 @@
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>com.googlecode.maven-download-plugin</groupId>
|
||||
<artifactId>download-maven-plugin</artifactId>
|
||||
<version>1.2.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>swagger-ui</id>
|
||||
<goals>
|
||||
<goal>wget</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<url>https://github.com/swagger-api/swagger-ui/archive/v${swagger-ui-version}.tar.gz</url>
|
||||
<unpack>true</unpack>
|
||||
<outputDirectory>${project.build.directory}</outputDirectory>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-resources-plugin</artifactId>
|
||||
<version>2.6</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>copy-resources</id>
|
||||
<phase>validate</phase>
|
||||
<goals>
|
||||
<goal>copy-resources</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<outputDirectory>target/${project.artifactId}-${project.version}</outputDirectory>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>${project.build.directory}/swagger-ui-${swagger-ui-version}/dist</directory>
|
||||
<filtering>true</filtering>
|
||||
<excludes>
|
||||
<exclude>index.html</exclude>
|
||||
</excludes>
|
||||
</resource>
|
||||
</resources>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<dependencies>
|
||||
@@ -163,21 +119,6 @@
|
||||
</dependency>
|
||||
|
||||
<!--SpringFox dependencies-->
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-core</artifactId>
|
||||
<version>${springfox-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-spi</artifactId>
|
||||
<version>${springfox-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-spring-web</artifactId>
|
||||
<version>${springfox-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-swagger2</artifactId>
|
||||
@@ -189,12 +130,6 @@
|
||||
<version>${springfox-version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.scalatest</groupId>
|
||||
<artifactId>scalatest_2.9.1</artifactId>
|
||||
<version>${scala-test-version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
@@ -217,13 +152,12 @@
|
||||
<properties>
|
||||
<swagger-core-version>1.5.0</swagger-core-version>
|
||||
<jetty-version>9.2.9.v20150224</jetty-version>
|
||||
<swagger-ui-version>2.1.0-M2</swagger-ui-version>
|
||||
<jersey-version>1.13</jersey-version>
|
||||
<slf4j-version>1.6.3</slf4j-version>
|
||||
<scala-test-version>1.6.1</scala-test-version>
|
||||
<junit-version>4.8.1</junit-version>
|
||||
<servlet-api-version>2.5</servlet-api-version>
|
||||
<springfox-version>2.0.0-SNAPSHOT</springfox-version>
|
||||
<springfox-version>2.0.4-SNAPSHOT</springfox-version>
|
||||
<spring-version>4.0.9.RELEASE</spring-version>
|
||||
</properties>
|
||||
</project>
|
||||
@@ -21,7 +21,7 @@ io.swagger.codegen.languages.StaticDocCodegen
|
||||
io.swagger.codegen.languages.StaticHtmlGenerator
|
||||
io.swagger.codegen.languages.SwaggerGenerator
|
||||
io.swagger.codegen.languages.SwaggerYamlGenerator
|
||||
io.swagger.codegen.languages.SwiftGenerator
|
||||
io.swagger.codegen.languages.SwiftCodegen
|
||||
io.swagger.codegen.languages.TizenClientCodegen
|
||||
io.swagger.codegen.languages.TypeScriptAngularClientCodegen
|
||||
io.swagger.codegen.languages.TypeScriptNodeClientCodegen
|
||||
|
||||
@@ -12,7 +12,7 @@ module {{package}} {
|
||||
*/
|
||||
{{/description}}
|
||||
export class {{classname}} {
|
||||
private basePath = '{{basePath}}';
|
||||
private basePath = '{{contextPath}}';
|
||||
|
||||
static $inject: string[] = ['$http'];
|
||||
|
||||
@@ -22,7 +22,7 @@ module {{package}} {
|
||||
}
|
||||
}
|
||||
{{#operation}}
|
||||
public {{nickname}} ({{#allParams}}{{paramName}}: {{{dataType}}}, {{/allParams}} extraHttpRequestParams?: any ) : ng.IHttpPromise<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}{}{{/returnType}}> {
|
||||
public {{nickname}} ({{#allParams}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}, {{/allParams}}extraHttpRequestParams?: any ) : ng.IHttpPromise<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}{}{{/returnType}}> {
|
||||
var path = this.basePath + '{{path}}';
|
||||
{{#pathParams}}
|
||||
path = path.replace('{' + '{{paramName}}' + '}', String({{paramName}}));
|
||||
@@ -50,7 +50,7 @@ module {{package}} {
|
||||
};
|
||||
|
||||
if (extraHttpRequestParams) {
|
||||
for (var k in extraHttpRequestParams){
|
||||
for (var k in extraHttpRequestParams) {
|
||||
if (extraHttpRequestParams.hasOwnProperty(k)) {
|
||||
httpRequestParams[k] = extraHttpRequestParams[k];
|
||||
}
|
||||
@@ -61,8 +61,5 @@ module {{package}} {
|
||||
}
|
||||
{{/operation}}
|
||||
}
|
||||
|
||||
angular.module('{{package}}_{{classname}}', ['$http'])
|
||||
.service('{{classname}}', {{classname}});
|
||||
}
|
||||
{{/operations}}
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
*/
|
||||
{{/description}}
|
||||
export class {{classname}} {
|
||||
private basePath = '{{basePath}}';
|
||||
private basePath = '{{contextPath}}';
|
||||
|
||||
constructor(private url: string, private username: string, private password: string, basePath?: string) {
|
||||
if (basePath) {
|
||||
@@ -16,7 +16,7 @@ export class {{classname}} {
|
||||
}
|
||||
|
||||
{{#operation}}
|
||||
public {{nickname}} ({{#allParams}}{{paramName}}: {{{dataType}}}{{#hasMore}}, {{/hasMore}}{{/allParams}} ) : Promise<{ response: http.ClientResponse; {{#returnType}}body: {{{returnType}}}; {{/returnType}} }> {
|
||||
public {{nickname}} ({{#allParams}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) : Promise<{ response: http.ClientResponse; {{#returnType}}body: {{{returnType}}}; {{/returnType}} }> {
|
||||
var path = this.url + this.basePath + '{{path}}';
|
||||
|
||||
{{#pathParams}}
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
package {{invokerPackage}};
|
||||
|
||||
public class Pair {
|
||||
private String name = "";
|
||||
private String value = "";
|
||||
|
||||
public Pair(String name, String value) {
|
||||
setName(name);
|
||||
setValue(value);
|
||||
}
|
||||
|
||||
private void setName(String name) {
|
||||
if (!isValidString(name)) return;
|
||||
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
private void setValue(String value) {
|
||||
if (!isValidString(value)) return;
|
||||
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
private boolean isValidString(String arg) {
|
||||
if (arg == null) return false;
|
||||
if (arg.trim().isEmpty()) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package {{package}};
|
||||
|
||||
import {{invokerPackage}}.ApiException;
|
||||
import {{invokerPackage}}.ApiInvoker;
|
||||
import {{invokerPackage}}.Pair;
|
||||
|
||||
import {{modelPackage}}.*;
|
||||
|
||||
@@ -55,20 +56,21 @@ public class {{classname}} {
|
||||
{{/required}}{{/allParams}}
|
||||
|
||||
// create path and map variables
|
||||
String path = "{{path}}".replaceAll("\\{format\\}","json"){{#pathParams}}.replaceAll("\\{" + "{{paramName}}" + "\\}", apiInvoker.escapeString({{{paramName}}}.toString())){{/pathParams}};
|
||||
String path = "{{path}}".replaceAll("\\{format\\}","json"){{#pathParams}}.replaceAll("\\{" + "{{baseName}}" + "\\}", apiInvoker.escapeString({{{paramName}}}.toString())){{/pathParams}};
|
||||
|
||||
// query params
|
||||
Map<String, String> queryParams = new HashMap<String, String>();
|
||||
List<Pair> queryParams = new ArrayList<Pair>();
|
||||
// header params
|
||||
Map<String, String> headerParams = new HashMap<String, String>();
|
||||
// form params
|
||||
Map<String, String> formParams = new HashMap<String, String>();
|
||||
|
||||
{{#queryParams}}if ({{paramName}} != null)
|
||||
queryParams.put("{{baseName}}", ApiInvoker.parameterToString({{paramName}}));
|
||||
{{#queryParams}}
|
||||
queryParams.addAll(ApiInvoker.parameterToPairs("{{#collectionFormat}}{{{collectionFormat}}}{{/collectionFormat}}", "{{baseName}}", {{paramName}}));
|
||||
{{/queryParams}}
|
||||
|
||||
{{#headerParams}}headerParams.put("{{baseName}}", ApiInvoker.parameterToString({{paramName}}));
|
||||
{{#headerParams}}
|
||||
headerParams.put("{{baseName}}", ApiInvoker.parameterToString({{paramName}}));
|
||||
{{/headerParams}}
|
||||
|
||||
String[] contentTypes = {
|
||||
|
||||
@@ -23,6 +23,7 @@ import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
@@ -132,6 +133,62 @@ public class ApiInvoker {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Format to {@code Pair} objects.
|
||||
*/
|
||||
public static List<Pair> parameterToPairs(String collectionFormat, String name, Object value){
|
||||
List<Pair> params = new ArrayList<Pair>();
|
||||
|
||||
// preconditions
|
||||
if (name == null || name.isEmpty() || value == null) return params;
|
||||
|
||||
Collection valueCollection = null;
|
||||
if (value instanceof Collection) {
|
||||
valueCollection = (Collection) value;
|
||||
} else {
|
||||
params.add(new Pair(name, parameterToString(value)));
|
||||
return params;
|
||||
}
|
||||
|
||||
if (valueCollection.isEmpty()){
|
||||
return params;
|
||||
}
|
||||
|
||||
// get the collection format
|
||||
collectionFormat = (collectionFormat == null || collectionFormat.isEmpty() ? "csv" : collectionFormat); // default: csv
|
||||
|
||||
// create the params based on the collection format
|
||||
if (collectionFormat.equals("multi")) {
|
||||
for (Object item : valueCollection) {
|
||||
params.add(new Pair(name, parameterToString(item)));
|
||||
}
|
||||
|
||||
return params;
|
||||
}
|
||||
|
||||
String delimiter = ",";
|
||||
|
||||
if (collectionFormat.equals("csv")) {
|
||||
delimiter = ",";
|
||||
} else if (collectionFormat.equals("ssv")) {
|
||||
delimiter = " ";
|
||||
} else if (collectionFormat.equals("tsv")) {
|
||||
delimiter = "\t";
|
||||
} else if (collectionFormat.equals("pipes")) {
|
||||
delimiter = "|";
|
||||
}
|
||||
|
||||
StringBuilder sb = new StringBuilder() ;
|
||||
for (Object item : valueCollection) {
|
||||
sb.append(delimiter);
|
||||
sb.append(parameterToString(item));
|
||||
}
|
||||
|
||||
params.add(new Pair(name, sb.substring(1)));
|
||||
|
||||
return params;
|
||||
}
|
||||
|
||||
public ApiInvoker() {
|
||||
initConnectionManager();
|
||||
}
|
||||
@@ -184,21 +241,24 @@ public class ApiInvoker {
|
||||
}
|
||||
}
|
||||
|
||||
public String invokeAPI(String host, String path, String method, Map<String, String> queryParams, Object body, Map<String, String> headerParams, Map<String, String> formParams, String contentType) throws ApiException {
|
||||
public String invokeAPI(String host, String path, String method, List<Pair> queryParams, Object body, Map<String, String> headerParams, Map<String, String> formParams, String contentType) throws ApiException {
|
||||
HttpClient client = getClient(host);
|
||||
|
||||
StringBuilder b = new StringBuilder();
|
||||
for(String key : queryParams.keySet()) {
|
||||
String value = queryParams.get(key);
|
||||
if (value != null){
|
||||
if(b.toString().length() == 0)
|
||||
b.append("?");
|
||||
else
|
||||
b.append("?");
|
||||
if (queryParams != null){
|
||||
for (Pair queryParam : queryParams){
|
||||
if (!queryParam.getName().isEmpty()) {
|
||||
b.append(escapeString(queryParam.getName()));
|
||||
b.append("=");
|
||||
b.append(escapeString(queryParam.getValue()));
|
||||
b.append("&");
|
||||
b.append(escapeString(key)).append("=").append(escapeString(value));
|
||||
}
|
||||
}
|
||||
}
|
||||
String url = host + path + b.toString();
|
||||
|
||||
String querystring = b.substring(0, b.length() - 1);
|
||||
String url = host + path + querystring;
|
||||
|
||||
HashMap<String, String> headers = new HashMap<String, String>();
|
||||
|
||||
|
||||
@@ -11,10 +11,9 @@ import collection.mutable
|
||||
class {{classname}}(client: TransportClient, config: SwaggerConfig) extends ApiClient(client, config) {
|
||||
|
||||
{{#operation}}
|
||||
def {{nickname}}({{#allParams}}{{#optional}}{{paramName}}: Option[{{dataType}}] = {{#defaultValue}}Some({{defaultValue}}){{/defaultValue}}{{^defaultValue}}None{{/defaultValue}}{{#hasMore}},
|
||||
{{/hasMore}}
|
||||
{{/optional}}{{^optional}}{{paramName}}: {{dataType}}{{#defaultValue}} = {{{defaultValue}}}{{/defaultValue}}{{#hasMore}},
|
||||
{{/hasMore}}{{/optional}}{{/allParams}})(implicit reader: ClientResponseReader[{{#returnType}}{{returnType}}{{/returnType}}{{^returnType}}Unit{{/returnType}}]{{#bodyParams}}, writer: RequestWriter[{{dataType}}]{{/bodyParams}}){{#returnType}}: Future[{{returnType}}]{{/returnType}}{{^returnType}}: Future[Unit]{{/returnType}} = {
|
||||
def {{nickname}}({{#allParams}}{{^required}}{{paramName}}: Option[{{dataType}}] = {{#defaultValue}}Some({{defaultValue}}){{/defaultValue}}{{^defaultValue}}None{{/defaultValue}}{{#hasMore}},{{/hasMore}}
|
||||
{{/required}}{{#required}}{{paramName}}: {{dataType}}{{#defaultValue}} = {{{defaultValue}}}{{/defaultValue}}{{#hasMore}},
|
||||
{{/hasMore}}{{/required}}{{/allParams}})(implicit reader: ClientResponseReader[{{#returnType}}{{returnType}}{{/returnType}}{{^returnType}}Unit{{/returnType}}]{{#bodyParams}}, writer: RequestWriter[{{dataType}}]{{/bodyParams}}){{#returnType}}: Future[{{returnType}}]{{/returnType}}{{^returnType}}: Future[Unit]{{/returnType}} = {
|
||||
// create path and map variables
|
||||
val path = (addFmt("{{path}}"){{#pathParams}}
|
||||
replaceAll ("\\{" + "{{baseName}}" + "\\}",{{paramName}}.toString){{/pathParams}})
|
||||
@@ -27,8 +26,8 @@ class {{classname}}(client: TransportClient, config: SwaggerConfig) extends ApiC
|
||||
val paramCount = (Set[Any]({{/requiredParamCount}}{{#requiredParams}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/requiredParams}}{{#requiredParamCount}}) - null).size
|
||||
if (paramCount != {{requiredParamCount}}) sys.error("missing required params"){{/requiredParamCount}}
|
||||
|
||||
{{#queryParams}}{{#optional}}if({{paramName}} != null) {{paramName}}.foreach { v => queryParams += "{{baseName}}" -> v.toString }{{/optional}}{{^optional}}
|
||||
if({{paramName}} != null) queryParams += "{{baseName}}" -> {{paramName}}.toString{{/optional}}{{/queryParams}}
|
||||
{{#queryParams}}{{^required}}if({{paramName}} != null) {{paramName}}.foreach { v => queryParams += "{{baseName}}" -> v.toString }{{/required}}{{#required}}
|
||||
if({{paramName}} != null) queryParams += "{{baseName}}" -> {{paramName}}.toString{{/required}}{{/queryParams}}
|
||||
|
||||
{{#headerParams}}headerParams += "{{baseName}}" -> {{paramName}}.toString{{/headerParams}}
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ sub new {
|
||||
#
|
||||
# {{{summary}}}
|
||||
#
|
||||
{{#allParams}}# @param {{dataType}} ${{paramName}} {{description}} {{^optional}}(required){{/optional}}{{#optional}}(optional){{/optional}}
|
||||
{{#allParams}}# @param {{dataType}} ${{paramName}} {{description}} {{#required}}(required){{/required}}{{^required}}(optional){{/required}}
|
||||
{{/allParams}}# @return {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}}
|
||||
#
|
||||
sub {{nickname}} {
|
||||
|
||||
@@ -1,4 +1,15 @@
|
||||
<?php
|
||||
/**
|
||||
* ApiClient
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* @category Class
|
||||
* @package {{invokerPackage}}
|
||||
* @author http://github.com/swagger-api/swagger-codegen
|
||||
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache Licene v2
|
||||
* @link https://github.com/swagger-api/swagger-codegen
|
||||
*/
|
||||
/**
|
||||
* Copyright 2015 SmartBear Software
|
||||
*
|
||||
@@ -14,206 +25,248 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* NOTE: This class is auto generated by the swagger code generator program.
|
||||
* https://github.com/swagger-api/swagger-codegen
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
namespace {{invokerPackage}};
|
||||
|
||||
class ApiClient {
|
||||
/**
|
||||
* ApiClient Class Doc Comment
|
||||
*
|
||||
* @category Class
|
||||
* @package {{invokerPackage}}
|
||||
* @author http://github.com/swagger-api/swagger-codegen
|
||||
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache Licene v2
|
||||
* @link https://github.com/swagger-api/swagger-codegen
|
||||
*/
|
||||
class ApiClient
|
||||
{
|
||||
|
||||
public static $PATCH = "PATCH";
|
||||
public static $POST = "POST";
|
||||
public static $GET = "GET";
|
||||
public static $PUT = "PUT";
|
||||
public static $DELETE = "DELETE";
|
||||
|
||||
/** @var Configuration */
|
||||
protected $config;
|
||||
|
||||
/** @var ObjectSerializer */
|
||||
protected $serializer;
|
||||
|
||||
/**
|
||||
* @param Configuration $config config for this ApiClient
|
||||
*/
|
||||
function __construct(Configuration $config = null) {
|
||||
if ($config == null) {
|
||||
$config = Configuration::getDefaultConfiguration();
|
||||
public static $PATCH = "PATCH";
|
||||
public static $POST = "POST";
|
||||
public static $GET = "GET";
|
||||
public static $PUT = "PUT";
|
||||
public static $DELETE = "DELETE";
|
||||
|
||||
/**
|
||||
* Configuration
|
||||
* @var Configuration
|
||||
*/
|
||||
protected $config;
|
||||
|
||||
/**
|
||||
* Object Serializer
|
||||
* @var ObjectSerializer
|
||||
*/
|
||||
protected $serializer;
|
||||
|
||||
/**
|
||||
* Constructor of the class
|
||||
* @param Configuration $config config for this ApiClient
|
||||
*/
|
||||
function __construct(Configuration $config = null)
|
||||
{
|
||||
if ($config == null) {
|
||||
$config = Configuration::getDefaultConfiguration();
|
||||
}
|
||||
|
||||
$this->config = $config;
|
||||
$this->serializer = new ObjectSerializer();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the config
|
||||
* @return Configuration
|
||||
*/
|
||||
public function getConfig()
|
||||
{
|
||||
return $this->config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the serializer
|
||||
* @return ObjectSerializer
|
||||
*/
|
||||
public function getSerializer()
|
||||
{
|
||||
return $this->serializer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get API key (with prefix if set)
|
||||
* @param string $apiKeyIdentifier name of apikey
|
||||
* @return string API key with the prefix
|
||||
*/
|
||||
public function getApiKeyWithPrefix($apiKeyIdentifier)
|
||||
{
|
||||
$prefix = $this->config->getApiKeyPrefix($apiKeyIdentifier);
|
||||
$apiKey = $this->config->getApiKey($apiKeyIdentifier);
|
||||
|
||||
if (!isset($apiKey)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (isset($prefix)) {
|
||||
$keyWithPrefix = $prefix." ".$apiKey;
|
||||
} else {
|
||||
$keyWithPrefix = $apiKey;
|
||||
}
|
||||
|
||||
return $keyWithPrefix;
|
||||
}
|
||||
|
||||
$this->config = $config;
|
||||
$this->serializer = new ObjectSerializer();
|
||||
}
|
||||
|
||||
/**
|
||||
* get the config
|
||||
* @return Configuration
|
||||
*/
|
||||
public function getConfig() {
|
||||
return $this->config;
|
||||
}
|
||||
|
||||
/**
|
||||
* get the serializer
|
||||
* @return ObjectSerializer
|
||||
*/
|
||||
public function getSerializer() {
|
||||
return $this->serializer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get API key (with prefix if set)
|
||||
* @param string $apiKey name of apikey
|
||||
* @return string API key with the prefix
|
||||
*/
|
||||
public function getApiKeyWithPrefix($apiKey) {
|
||||
$prefix = $this->config->getApiKeyPrefix($apiKey);
|
||||
$apiKey = $this->config->getApiKey($apiKey);
|
||||
|
||||
if (!isset($apiKey)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (isset($prefix)) {
|
||||
$keyWithPrefix = $prefix." ".$apiKey;
|
||||
} else {
|
||||
$keyWithPrefix = $apiKey;
|
||||
}
|
||||
|
||||
return $keyWithPrefix;
|
||||
}
|
||||
/**
|
||||
* Make the HTTP call (Sync)
|
||||
* @param string $resourcePath path to method endpoint
|
||||
* @param string $method method to call
|
||||
* @param array $queryParams parameters to be place in query URL
|
||||
* @param array $postData parameters to be placed in POST body
|
||||
* @param array $headerParams parameters to be place in request header
|
||||
* @param string $responseType expected response type of the endpoint
|
||||
* @throws \{{invokerPackage}}\ApiException on a non 2xx response
|
||||
* @return mixed
|
||||
*/
|
||||
public function callApi($resourcePath, $method, $queryParams, $postData, $headerParams, $responseType=null)
|
||||
{
|
||||
|
||||
/**
|
||||
* @param string $resourcePath path to method endpoint
|
||||
* @param string $method method to call
|
||||
* @param array $queryParams parameters to be place in query URL
|
||||
* @param array $postData parameters to be placed in POST body
|
||||
* @param array $headerParams parameters to be place in request header
|
||||
* @throws \{{invokerPackage}}\ApiException on a non 2xx response
|
||||
* @return mixed
|
||||
*/
|
||||
public function callApi($resourcePath, $method, $queryParams, $postData, $headerParams) {
|
||||
|
||||
$headers = array();
|
||||
|
||||
# construct the http header
|
||||
$headerParams = array_merge((array)$this->config->getDefaultHeaders(), (array)$headerParams);
|
||||
|
||||
foreach ($headerParams as $key => $val) {
|
||||
$headers[] = "$key: $val";
|
||||
$headers = array();
|
||||
|
||||
// construct the http header
|
||||
$headerParams = array_merge(
|
||||
(array)$this->config->getDefaultHeaders(),
|
||||
(array)$headerParams
|
||||
);
|
||||
|
||||
foreach ($headerParams as $key => $val) {
|
||||
$headers[] = "$key: $val";
|
||||
}
|
||||
|
||||
// form data
|
||||
if ($postData and in_array('Content-Type: application/x-www-form-urlencoded', $headers)) {
|
||||
$postData = http_build_query($postData);
|
||||
} else if ((is_object($postData) or is_array($postData)) and !in_array('Content-Type: multipart/form-data', $headers)) { // json model
|
||||
$postData = json_encode($this->serializer->sanitizeForSerialization($postData));
|
||||
}
|
||||
|
||||
$url = $this->config->getHost() . $resourcePath;
|
||||
|
||||
$curl = curl_init();
|
||||
// set timeout, if needed
|
||||
if ($this->config->getCurlTimeout() != 0) {
|
||||
curl_setopt($curl, CURLOPT_TIMEOUT, $this->config->getCurlTimeout());
|
||||
}
|
||||
// return the result on success, rather than just TRUE
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
|
||||
|
||||
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
|
||||
|
||||
if (! empty($queryParams)) {
|
||||
$url = ($url . '?' . http_build_query($queryParams));
|
||||
}
|
||||
|
||||
if ($method == self::$POST) {
|
||||
curl_setopt($curl, CURLOPT_POST, true);
|
||||
curl_setopt($curl, CURLOPT_POSTFIELDS, $postData);
|
||||
} else if ($method == self::$PATCH) {
|
||||
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PATCH");
|
||||
curl_setopt($curl, CURLOPT_POSTFIELDS, $postData);
|
||||
} else if ($method == self::$PUT) {
|
||||
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT");
|
||||
curl_setopt($curl, CURLOPT_POSTFIELDS, $postData);
|
||||
} else if ($method == self::$DELETE) {
|
||||
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "DELETE");
|
||||
curl_setopt($curl, CURLOPT_POSTFIELDS, $postData);
|
||||
} else if ($method != self::$GET) {
|
||||
throw new ApiException('Method ' . $method . ' is not recognized.');
|
||||
}
|
||||
curl_setopt($curl, CURLOPT_URL, $url);
|
||||
|
||||
// Set user agent
|
||||
curl_setopt($curl, CURLOPT_USERAGENT, $this->config->getUserAgent());
|
||||
|
||||
// debugging for curl
|
||||
if ($this->config->getDebug()) {
|
||||
error_log("[DEBUG] HTTP Request body ~BEGIN~\n".print_r($postData, true)."\n~END~\n", 3, $this->config->getDebugFile());
|
||||
|
||||
curl_setopt($curl, CURLOPT_VERBOSE, 1);
|
||||
curl_setopt($curl, CURLOPT_STDERR, fopen($this->config->getDebugFile(), 'a'));
|
||||
} else {
|
||||
curl_setopt($curl, CURLOPT_VERBOSE, 0);
|
||||
}
|
||||
|
||||
// obtain the HTTP response headers
|
||||
curl_setopt($curl, CURLOPT_HEADER, 1);
|
||||
|
||||
// Make the request
|
||||
$response = curl_exec($curl);
|
||||
$http_header_size = curl_getinfo($curl, CURLINFO_HEADER_SIZE);
|
||||
$http_header = substr($response, 0, $http_header_size);
|
||||
$http_body = substr($response, $http_header_size);
|
||||
$response_info = curl_getinfo($curl);
|
||||
|
||||
// debug HTTP response body
|
||||
if ($this->config->getDebug()) {
|
||||
error_log("[DEBUG] HTTP Response body ~BEGIN~\n".print_r($http_body, true)."\n~END~\n", 3, $this->config->getDebugFile());
|
||||
}
|
||||
|
||||
// Handle the response
|
||||
if ($response_info['http_code'] == 0) {
|
||||
throw new ApiException("API call to $url timed out: ".serialize($response_info), 0, null, null);
|
||||
} else if ($response_info['http_code'] >= 200 && $response_info['http_code'] <= 299 ) {
|
||||
// return raw body if response is a file
|
||||
if ($responseType == '\SplFileObject') {
|
||||
return array($http_body, $http_header);
|
||||
}
|
||||
|
||||
$data = json_decode($http_body);
|
||||
if (json_last_error() > 0) { // if response is a string
|
||||
$data = $http_body;
|
||||
}
|
||||
} else {
|
||||
throw new ApiException(
|
||||
"[".$response_info['http_code']."] Error connecting to the API ($url)",
|
||||
$response_info['http_code'], $http_header, $http_body
|
||||
);
|
||||
}
|
||||
return array($data, $http_header);
|
||||
}
|
||||
|
||||
// form data
|
||||
if ($postData and in_array('Content-Type: application/x-www-form-urlencoded', $headers)) {
|
||||
$postData = http_build_query($postData);
|
||||
|
||||
/**
|
||||
* Return the header 'Accept' based on an array of Accept provided
|
||||
*
|
||||
* @param string[] $accept Array of header
|
||||
*
|
||||
* @return string Accept (e.g. application/json)
|
||||
*/
|
||||
public static function selectHeaderAccept($accept)
|
||||
{
|
||||
if (count($accept) === 0 or (count($accept) === 1 and $accept[0] === '')) {
|
||||
return null;
|
||||
} elseif (preg_grep("/application\/json/i", $accept)) {
|
||||
return 'application/json';
|
||||
} else {
|
||||
return implode(',', $accept);
|
||||
}
|
||||
}
|
||||
else if ((is_object($postData) or is_array($postData)) and !in_array('Content-Type: multipart/form-data', $headers)) { // json model
|
||||
$postData = json_encode($this->serializer->sanitizeForSerialization($postData));
|
||||
|
||||
/**
|
||||
* Return the content type based on an array of content-type provided
|
||||
*
|
||||
* @param string[] $content_type Array fo content-type
|
||||
*
|
||||
* @return string Content-Type (e.g. application/json)
|
||||
*/
|
||||
public static function selectHeaderContentType($content_type)
|
||||
{
|
||||
if (count($content_type) === 0 or (count($content_type) === 1 and $content_type[0] === '')) {
|
||||
return 'application/json';
|
||||
} elseif (preg_grep("/application\/json/i", $content_type)) {
|
||||
return 'application/json';
|
||||
} else {
|
||||
return implode(',', $content_type);
|
||||
}
|
||||
}
|
||||
|
||||
$url = $this->config->getHost() . $resourcePath;
|
||||
|
||||
$curl = curl_init();
|
||||
// set timeout, if needed
|
||||
if ($this->config->getCurlTimeout() != 0) {
|
||||
curl_setopt($curl, CURLOPT_TIMEOUT, $this->config->getCurlTimeout());
|
||||
}
|
||||
// return the result on success, rather than just TRUE
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
|
||||
|
||||
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
|
||||
|
||||
if (! empty($queryParams)) {
|
||||
$url = ($url . '?' . http_build_query($queryParams));
|
||||
}
|
||||
|
||||
if ($method == self::$POST) {
|
||||
curl_setopt($curl, CURLOPT_POST, true);
|
||||
curl_setopt($curl, CURLOPT_POSTFIELDS, $postData);
|
||||
} else if ($method == self::$PATCH) {
|
||||
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PATCH");
|
||||
curl_setopt($curl, CURLOPT_POSTFIELDS, $postData);
|
||||
} else if ($method == self::$PUT) {
|
||||
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT");
|
||||
curl_setopt($curl, CURLOPT_POSTFIELDS, $postData);
|
||||
} else if ($method == self::$DELETE) {
|
||||
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "DELETE");
|
||||
curl_setopt($curl, CURLOPT_POSTFIELDS, $postData);
|
||||
} else if ($method != self::$GET) {
|
||||
throw new ApiException('Method ' . $method . ' is not recognized.');
|
||||
}
|
||||
curl_setopt($curl, CURLOPT_URL, $url);
|
||||
|
||||
// Set user agent
|
||||
curl_setopt($curl, CURLOPT_USERAGENT, $this->config->getUserAgent());
|
||||
|
||||
// debugging for curl
|
||||
if ($this->config->getDebug()) {
|
||||
error_log("[DEBUG] HTTP Request body ~BEGIN~\n".print_r($postData, true)."\n~END~\n", 3, $this->config->getDebugFile());
|
||||
|
||||
curl_setopt($curl, CURLOPT_VERBOSE, 1);
|
||||
curl_setopt($curl, CURLOPT_STDERR, fopen($this->config->getDebugFile(), 'a'));
|
||||
} else {
|
||||
curl_setopt($curl, CURLOPT_VERBOSE, 0);
|
||||
}
|
||||
|
||||
// obtain the HTTP response headers
|
||||
curl_setopt($curl, CURLOPT_HEADER, 1);
|
||||
|
||||
// Make the request
|
||||
$response = curl_exec($curl);
|
||||
$http_header_size = curl_getinfo($curl, CURLINFO_HEADER_SIZE);
|
||||
$http_header = substr($response, 0, $http_header_size);
|
||||
$http_body = substr($response, $http_header_size);
|
||||
$response_info = curl_getinfo($curl);
|
||||
|
||||
// debug HTTP response body
|
||||
if ($this->config->getDebug()) {
|
||||
error_log("[DEBUG] HTTP Response body ~BEGIN~\n".print_r($http_body, true)."\n~END~\n", 3, $this->config->getDebugFile());
|
||||
}
|
||||
|
||||
// Handle the response
|
||||
if ($response_info['http_code'] == 0) {
|
||||
throw new ApiException("API call to $url timed out: ".serialize($response_info), 0, null, null);
|
||||
} else if ($response_info['http_code'] >= 200 && $response_info['http_code'] <= 299 ) {
|
||||
$data = json_decode($http_body);
|
||||
if (json_last_error() > 0) { // if response is a string
|
||||
$data = $http_body;
|
||||
}
|
||||
} else {
|
||||
throw new ApiException("[".$response_info['http_code']."] Error connecting to the API ($url)",
|
||||
$response_info['http_code'], $http_header, $http_body);
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
/*
|
||||
* return the header 'Accept' based on an array of Accept provided
|
||||
*
|
||||
* @param string[] $accept Array of header
|
||||
* @return string Accept (e.g. application/json)
|
||||
*/
|
||||
public static function selectHeaderAccept($accept) {
|
||||
if (count($accept) === 0 or (count($accept) === 1 and $accept[0] === '')) {
|
||||
return NULL;
|
||||
} elseif (preg_grep("/application\/json/i", $accept)) {
|
||||
return 'application/json';
|
||||
} else {
|
||||
return implode(',', $accept);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* return the content type based on an array of content-type provided
|
||||
*
|
||||
* @param string[] content_type_array Array fo content-type
|
||||
* @return string Content-Type (e.g. application/json)
|
||||
*/
|
||||
public static function selectHeaderContentType($content_type) {
|
||||
if (count($content_type) === 0 or (count($content_type) === 1 and $content_type[0] === '')) {
|
||||
return 'application/json';
|
||||
} elseif (preg_grep("/application\/json/i", $content_type)) {
|
||||
return 'application/json';
|
||||
} else {
|
||||
return implode(',', $content_type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,14 @@
|
||||
<?php
|
||||
/**
|
||||
* ApiException
|
||||
* PHP version 5
|
||||
*
|
||||
* @category Class
|
||||
* @package {{invokerPackage}}
|
||||
* @author http://github.com/swagger-api/swagger-codegen
|
||||
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache Licene v2
|
||||
* @link https://github.com/swagger-api/swagger-codegen
|
||||
*/
|
||||
/**
|
||||
* Copyright 2015 SmartBear Software
|
||||
*
|
||||
@@ -14,57 +24,97 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* NOTE: This class is auto generated by the swagger code generator program.
|
||||
* https://github.com/swagger-api/swagger-codegen
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
namespace {{invokerPackage}};
|
||||
|
||||
use \Exception;
|
||||
|
||||
class ApiException extends Exception {
|
||||
/**
|
||||
* ApiException Class Doc Comment
|
||||
*
|
||||
* @category Class
|
||||
* @package {{invokerPackage}}
|
||||
* @author http://github.com/swagger-api/swagger-codegen
|
||||
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache Licene v2
|
||||
* @link https://github.com/swagger-api/swagger-codegen
|
||||
*/
|
||||
class ApiException extends Exception
|
||||
{
|
||||
|
||||
/** @var string The HTTP body of the server response. */
|
||||
protected $responseBody;
|
||||
/**
|
||||
* The HTTP body of the server response.
|
||||
* @var string
|
||||
*/
|
||||
protected $responseBody;
|
||||
|
||||
/**
|
||||
* The HTTP header of the server response.
|
||||
* @var string[]
|
||||
*/
|
||||
protected $responseHeaders;
|
||||
|
||||
/**
|
||||
* The deserialized response object
|
||||
* @var $responseObject;
|
||||
*/
|
||||
protected $responseObject;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param string $message Error message
|
||||
* @param string $code HTTP status code
|
||||
* @param string $responseHeaders HTTP response header
|
||||
* @param string $responseBody Deseralized response object
|
||||
*/
|
||||
public function __construct($message="", $code=0, $responseHeaders=null, $responseBody=null)
|
||||
{
|
||||
parent::__construct($message, $code);
|
||||
$this->responseHeaders = $responseHeaders;
|
||||
$this->responseBody = $responseBody;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the HTTP response header
|
||||
*
|
||||
* @return string HTTP response header
|
||||
*/
|
||||
public function getResponseHeaders()
|
||||
{
|
||||
return $this->responseHeaders;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the HTTP response body
|
||||
*
|
||||
* @return string HTTP response body
|
||||
*/
|
||||
public function getResponseBody()
|
||||
{
|
||||
return $this->responseBody;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the deseralized response object (during deserialization)
|
||||
* @param mixed $obj Deserialized response object
|
||||
* @return void
|
||||
*/
|
||||
public function setResponseObject($obj)
|
||||
{
|
||||
$this->responseObject = $obj;
|
||||
}
|
||||
|
||||
/** @var string[] The HTTP header of the server response. */
|
||||
protected $responseHeaders;
|
||||
|
||||
/**
|
||||
* The deserialized response object
|
||||
*/
|
||||
protected $responseObject;
|
||||
|
||||
public function __construct($message="", $code=0, $responseHeaders=null, $responseBody=null) {
|
||||
parent::__construct($message, $code);
|
||||
$this->responseHeaders = $responseHeaders;
|
||||
$this->responseBody = $responseBody;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the HTTP response header
|
||||
*
|
||||
* @return string HTTP response header
|
||||
*/
|
||||
public function getResponseHeaders() {
|
||||
return $this->responseHeaders;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the HTTP response body
|
||||
*
|
||||
* @return string HTTP response body
|
||||
*/
|
||||
public function getResponseBody() {
|
||||
return $this->responseBody;
|
||||
}
|
||||
|
||||
/**
|
||||
* sets the deseralized response object (during deserialization)
|
||||
* @param mixed $obj
|
||||
*/
|
||||
public function setResponseObject($obj) {
|
||||
$this->responseObject = $obj;
|
||||
}
|
||||
|
||||
public function getResponseObject() {
|
||||
return $this->responseObject;
|
||||
}
|
||||
/**
|
||||
* Gets the deseralized response object (during deserialization)
|
||||
*
|
||||
* @return mixed the deserialized response object
|
||||
*/
|
||||
public function getResponseObject()
|
||||
{
|
||||
return $this->responseObject;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,47 +1,95 @@
|
||||
<?php
|
||||
/**
|
||||
* ObjectSerializer
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* @category Class
|
||||
* @package {{invokerPackage}}
|
||||
* @author http://github.com/swagger-api/swagger-codegen
|
||||
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache Licene v2
|
||||
* @link https://github.com/swagger-api/swagger-codegen
|
||||
*/
|
||||
/**
|
||||
* Copyright 2015 SmartBear Software
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
/**
|
||||
* NOTE: This class is auto generated by the swagger code generator program.
|
||||
* https://github.com/swagger-api/swagger-codegen
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
namespace {{invokerPackage}};
|
||||
|
||||
class ObjectSerializer {
|
||||
/**
|
||||
* ObjectSerializer Class Doc Comment
|
||||
*
|
||||
* @category Class
|
||||
* @package {{invokerPackage}}
|
||||
* @author http://github.com/swagger-api/swagger-codegen
|
||||
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache Licene v2
|
||||
* @link https://github.com/swagger-api/swagger-codegen
|
||||
*/
|
||||
class ObjectSerializer
|
||||
{
|
||||
|
||||
/**
|
||||
* Build a JSON POST object
|
||||
*
|
||||
* @param mixed $data the data to serialize
|
||||
*
|
||||
* @return string serialized form of $data
|
||||
*/
|
||||
public function sanitizeForSerialization($data) {
|
||||
if (is_scalar($data) || null === $data) {
|
||||
$sanitized = $data;
|
||||
} else if ($data instanceof \DateTime) {
|
||||
$sanitized = $data->format(\DateTime::ISO8601);
|
||||
} else if (is_array($data)) {
|
||||
foreach ($data as $property => $value) {
|
||||
$data[$property] = $this->sanitizeForSerialization($value);
|
||||
public function sanitizeForSerialization($data)
|
||||
{
|
||||
if (is_scalar($data) || null === $data) {
|
||||
$sanitized = $data;
|
||||
} else if ($data instanceof \DateTime) {
|
||||
$sanitized = $data->format(\DateTime::ISO8601);
|
||||
} else if (is_array($data)) {
|
||||
foreach ($data as $property => $value) {
|
||||
$data[$property] = $this->sanitizeForSerialization($value);
|
||||
}
|
||||
$sanitized = $data;
|
||||
} else if (is_object($data)) {
|
||||
$values = array();
|
||||
foreach (array_keys($data::$swaggerTypes) as $property) {
|
||||
$getter = $data::$getters[$property];
|
||||
if ($data->$getter() !== null) {
|
||||
$values[$data::$attributeMap[$property]] = $this->sanitizeForSerialization($data->$getter());
|
||||
}
|
||||
}
|
||||
$sanitized = $values;
|
||||
} else {
|
||||
$sanitized = (string)$data;
|
||||
}
|
||||
$sanitized = $data;
|
||||
} else if (is_object($data)) {
|
||||
$values = array();
|
||||
foreach (array_keys($data::$swaggerTypes) as $property) {
|
||||
$getter = $data::$getters[$property];
|
||||
if ($data->$getter() !== null) {
|
||||
$values[$data::$attributeMap[$property]] = $this->sanitizeForSerialization($data->$getter());
|
||||
}
|
||||
}
|
||||
$sanitized = $values;
|
||||
} else {
|
||||
$sanitized = (string)$data;
|
||||
}
|
||||
|
||||
return $sanitized;
|
||||
return $sanitized;
|
||||
}
|
||||
|
||||
/**
|
||||
* Take value and turn it into a string suitable for inclusion in
|
||||
* the path, by url-encoding.
|
||||
*
|
||||
* @param string $value a string which will be part of the path
|
||||
*
|
||||
* @return string the serialized object
|
||||
*/
|
||||
public function toPathValue($value) {
|
||||
return rawurlencode($this->toString($value));
|
||||
public function toPathValue($value)
|
||||
{
|
||||
return rawurlencode($this->toString($value));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -49,103 +97,133 @@ class ObjectSerializer {
|
||||
* the query, by imploding comma-separated if it's an object.
|
||||
* If it's a string, pass through unchanged. It will be url-encoded
|
||||
* later.
|
||||
*
|
||||
* @param object $object an object to be serialized to a string
|
||||
*
|
||||
* @return string the serialized object
|
||||
*/
|
||||
public function toQueryValue($object) {
|
||||
if (is_array($object)) {
|
||||
return implode(',', $object);
|
||||
} else {
|
||||
return $this->toString($object);
|
||||
}
|
||||
public function toQueryValue($object)
|
||||
{
|
||||
if (is_array($object)) {
|
||||
return implode(',', $object);
|
||||
} else {
|
||||
return $this->toString($object);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Take value and turn it into a string suitable for inclusion in
|
||||
* the header. If it's a string, pass through unchanged
|
||||
* If it's a datetime object, format it in ISO8601
|
||||
*
|
||||
* @param string $value a string which will be part of the header
|
||||
*
|
||||
* @return string the header string
|
||||
*/
|
||||
public function toHeaderValue($value) {
|
||||
return $this->toString($value);
|
||||
public function toHeaderValue($value)
|
||||
{
|
||||
return $this->toString($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Take value and turn it into a string suitable for inclusion in
|
||||
* the http body (form parameter). If it's a string, pass through unchanged
|
||||
* If it's a datetime object, format it in ISO8601
|
||||
*
|
||||
* @param string $value the value of the form parameter
|
||||
*
|
||||
* @return string the form string
|
||||
*/
|
||||
public function toFormValue($value) {
|
||||
return $this->toString($value);
|
||||
public function toFormValue($value)
|
||||
{
|
||||
if ($value instanceof SplFileObject) {
|
||||
return $value->getRealPath();
|
||||
} else {
|
||||
return $this->toString($value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Take value and turn it into a string suitable for inclusion in
|
||||
* the parameter. If it's a string, pass through unchanged
|
||||
* If it's a datetime object, format it in ISO8601
|
||||
*
|
||||
* @param string $value the value of the parameter
|
||||
*
|
||||
* @return string the header string
|
||||
*/
|
||||
public function toString($value) {
|
||||
if ($value instanceof \DateTime) { // datetime in ISO8601 format
|
||||
return $value->format(\DateTime::ISO8601);
|
||||
} else {
|
||||
return $value;
|
||||
}
|
||||
public function toString($value)
|
||||
{
|
||||
if ($value instanceof \DateTime) { // datetime in ISO8601 format
|
||||
return $value->format(\DateTime::ISO8601);
|
||||
} else {
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserialize a JSON string into an object
|
||||
*
|
||||
* @param mixed $data object or primitive to be deserialized
|
||||
* @param string $class class name is passed as a string
|
||||
* @param mixed $data object or primitive to be deserialized
|
||||
* @param string $class class name is passed as a string
|
||||
* @param string $httpHeader HTTP headers
|
||||
*
|
||||
* @return object an instance of $class
|
||||
*/
|
||||
public function deserialize($data, $class) {
|
||||
if (null === $data) {
|
||||
$deserialized = null;
|
||||
} elseif (substr($class, 0, 4) == 'map[') { # for associative array e.g. map[string,int]
|
||||
$inner = substr($class, 4, -1);
|
||||
$deserialized = array();
|
||||
if(strrpos($inner, ",") !== false) {
|
||||
$subClass_array = explode(',', $inner, 2);
|
||||
$subClass = $subClass_array[1];
|
||||
foreach ($data as $key => $value) {
|
||||
$deserialized[$key] = $this->deserialize($value, $subClass);
|
||||
}
|
||||
public function deserialize($data, $class, $httpHeader=null)
|
||||
{
|
||||
if (null === $data) {
|
||||
$deserialized = null;
|
||||
} elseif (substr($class, 0, 4) === 'map[') { // for associative array e.g. map[string,int]
|
||||
$inner = substr($class, 4, -1);
|
||||
$deserialized = array();
|
||||
if (strrpos($inner, ",") !== false) {
|
||||
$subClass_array = explode(',', $inner, 2);
|
||||
$subClass = $subClass_array[1];
|
||||
foreach ($data as $key => $value) {
|
||||
$deserialized[$key] = $this->deserialize($value, $subClass);
|
||||
}
|
||||
}
|
||||
} elseif (strcasecmp(substr($class, -2), '[]') == 0) {
|
||||
$subClass = substr($class, 0, -2);
|
||||
$values = array();
|
||||
foreach ($data as $key => $value) {
|
||||
$values[] = $this->deserialize($value, $subClass);
|
||||
}
|
||||
$deserialized = $values;
|
||||
} elseif ($class === 'DateTime') {
|
||||
$deserialized = new \DateTime($data);
|
||||
} elseif (in_array($class, array('string', 'int', 'float', 'double', 'bool', 'object'))) {
|
||||
settype($data, $class);
|
||||
$deserialized = $data;
|
||||
} elseif ($class === '\SplFileObject') {
|
||||
// determine file name
|
||||
if (preg_match('/Content-Disposition: inline; filename=[\'"]?([^\'"\s]+)[\'"]?$/i', $httpHeader, $match)) {
|
||||
$filename = Configuration::getDefaultConfiguration()->getTempFolderPath().$match[1];
|
||||
} else {
|
||||
$filename = tempnam(Configuration::getDefaultConfiguration()->getTempFolderPath(), '');
|
||||
}
|
||||
$deserialized = new \SplFileObject($filename, "w");
|
||||
$byte_written = $deserialized->fwrite($data);
|
||||
error_log("[INFO] Written $byte_written byte to $filename. Please move the file to a proper folder or delete the temp file after processing.\n", 3, Configuration::getDefaultConfiguration()->getDebugFile());
|
||||
|
||||
} else {
|
||||
$instance = new $class();
|
||||
foreach ($instance::$swaggerTypes as $property => $type) {
|
||||
$propertySetter = $instance::$setters[$property];
|
||||
|
||||
if (!isset($propertySetter) || !isset($data->{$instance::$attributeMap[$property]})) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$propertyValue = $data->{$instance::$attributeMap[$property]};
|
||||
if (isset($propertyValue)) {
|
||||
$instance->$propertySetter($this->deserialize($propertyValue, $type));
|
||||
}
|
||||
}
|
||||
$deserialized = $instance;
|
||||
}
|
||||
} elseif (strcasecmp(substr($class, -2),'[]') == 0) {
|
||||
$subClass = substr($class, 0, -2);
|
||||
$values = array();
|
||||
foreach ($data as $key => $value) {
|
||||
$values[] = $this->deserialize($value, $subClass);
|
||||
}
|
||||
$deserialized = $values;
|
||||
} elseif ($class == 'DateTime') {
|
||||
$deserialized = new \DateTime($data);
|
||||
} elseif (in_array($class, array('string', 'int', 'float', 'double', 'bool', 'object'))) {
|
||||
settype($data, $class);
|
||||
$deserialized = $data;
|
||||
} else {
|
||||
$instance = new $class();
|
||||
foreach ($instance::$swaggerTypes as $property => $type) {
|
||||
$propertySetter = $instance::$setters[$property];
|
||||
|
||||
if (!isset($propertySetter) || !isset($data->{$instance::$attributeMap[$property]})) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$propertyValue = $data->{$instance::$attributeMap[$property]};
|
||||
if (isset($propertyValue)) {
|
||||
$instance->$propertySetter($this->deserialize($propertyValue, $type));
|
||||
}
|
||||
}
|
||||
$deserialized = $instance;
|
||||
}
|
||||
|
||||
return $deserialized;
|
||||
|
||||
return $deserialized;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,14 @@
|
||||
<?php
|
||||
/**
|
||||
* {{classname}}
|
||||
* PHP version 5
|
||||
*
|
||||
* @category Class
|
||||
* @package {{invokerPackage}}
|
||||
* @author http://github.com/swagger-api/swagger-codegen
|
||||
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache Licene v2
|
||||
* @link https://github.com/swagger-api/swagger-codegen
|
||||
*/
|
||||
/**
|
||||
* Copyright 2015 SmartBear Software
|
||||
*
|
||||
@@ -16,8 +26,9 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* NOTE: This class is auto generated by the swagger code generator program. Do not edit the class manually.
|
||||
* NOTE: This class is auto generated by the swagger code generator program.
|
||||
* https://github.com/swagger-api/swagger-codegen
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
namespace {{apiPackage}};
|
||||
@@ -27,135 +38,156 @@ use \{{invokerPackage}}\ApiClient;
|
||||
use \{{invokerPackage}}\ApiException;
|
||||
use \{{invokerPackage}}\ObjectSerializer;
|
||||
|
||||
{{#operations}}
|
||||
class {{classname}} {
|
||||
/**
|
||||
* {{classname}} Class Doc Comment
|
||||
*
|
||||
* @category Class
|
||||
* @package {{invokerPackage}}
|
||||
* @author http://github.com/swagger-api/swagger-codegen
|
||||
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache Licene v2
|
||||
* @link https://github.com/swagger-api/swagger-codegen
|
||||
*/
|
||||
{{#operations}}class {{classname}}
|
||||
{
|
||||
|
||||
/** @var \{{invokerPackage}}\ApiClient instance of the ApiClient */
|
||||
private $apiClient;
|
||||
|
||||
/**
|
||||
* @param \{{invokerPackage}}\ApiClient|null $apiClient The api client to use
|
||||
*/
|
||||
function __construct($apiClient = null) {
|
||||
if ($apiClient == null) {
|
||||
$apiClient = new ApiClient();
|
||||
$apiClient->getConfig()->setHost('{{basePath}}');
|
||||
}
|
||||
|
||||
$this->apiClient = $apiClient;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \{{invokerPackage}}\ApiClient get the API client
|
||||
*/
|
||||
public function getApiClient() {
|
||||
return $this->apiClient;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \{{invokerPackage}}\ApiClient $apiClient set the API client
|
||||
* @return {{classname}}
|
||||
*/
|
||||
public function setApiClient(ApiClient $apiClient) {
|
||||
$this->apiClient = $apiClient;
|
||||
return $this;
|
||||
}
|
||||
|
||||
{{#operation}}
|
||||
/**
|
||||
* {{{nickname}}}
|
||||
*
|
||||
* {{{summary}}}
|
||||
*
|
||||
{{#allParams}} * @param {{dataType}} ${{paramName}} {{description}} {{^optional}}(required){{/optional}}{{#optional}}(optional){{/optional}}
|
||||
{{/allParams}} * @return {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}}
|
||||
* @throws \{{invokerPackage}}\ApiException on non-2xx response
|
||||
*/
|
||||
public function {{nickname}}({{#allParams}}${{paramName}}{{#optional}}=null{{/optional}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) {
|
||||
{{#allParams}}{{#required}}
|
||||
// verify the required parameter '{{paramName}}' is set
|
||||
if (${{paramName}} === null) {
|
||||
throw new \InvalidArgumentException('Missing the required parameter ${{paramName}} when calling {{nickname}}');
|
||||
}
|
||||
{{/required}}{{/allParams}}
|
||||
|
||||
// parse inputs
|
||||
$resourcePath = "{{path}}";
|
||||
$resourcePath = str_replace("{format}", "json", $resourcePath);
|
||||
$method = "{{httpMethod}}";
|
||||
$httpBody = '';
|
||||
$queryParams = array();
|
||||
$headerParams = array();
|
||||
$formParams = array();
|
||||
$_header_accept = ApiClient::selectHeaderAccept(array({{#produces}}'{{mediaType}}'{{#hasMore}}, {{/hasMore}}{{/produces}}));
|
||||
if (!is_null($_header_accept)) {
|
||||
$headerParams['Accept'] = $_header_accept;
|
||||
}
|
||||
$headerParams['Content-Type'] = ApiClient::selectHeaderContentType(array({{#consumes}}'{{mediaType}}'{{#hasMore}},{{/hasMore}}{{/consumes}}));
|
||||
|
||||
{{#queryParams}}// query params
|
||||
if(${{paramName}} !== null) {
|
||||
$queryParams['{{baseName}}'] = $this->apiClient->getSerializer()->toQueryValue(${{paramName}});
|
||||
}{{/queryParams}}
|
||||
{{#headerParams}}// header params
|
||||
if(${{paramName}} !== null) {
|
||||
$headerParams['{{baseName}}'] = $this->apiClient->getSerializer()->toHeaderValue(${{paramName}});
|
||||
}{{/headerParams}}
|
||||
{{#pathParams}}// path params
|
||||
if(${{paramName}} !== null) {
|
||||
$resourcePath = str_replace("{" . "{{baseName}}" . "}",
|
||||
$this->apiClient->getSerializer()->toPathValue(${{paramName}}),
|
||||
$resourcePath);
|
||||
}{{/pathParams}}
|
||||
{{#formParams}}// form params
|
||||
if (${{paramName}} !== null) {
|
||||
$formParams['{{baseName}}'] = {{#isFile}}'@' . {{/isFile}}$this->apiClient->getSerializer()->toFormValue(${{paramName}});
|
||||
}{{/formParams}}
|
||||
{{#bodyParams}}// body params
|
||||
$_tempBody = null;
|
||||
if (isset(${{paramName}})) {
|
||||
$_tempBody = ${{paramName}};
|
||||
}{{/bodyParams}}
|
||||
|
||||
// for model (json/xml)
|
||||
if (isset($_tempBody)) {
|
||||
$httpBody = $_tempBody; // $_tempBody is the method argument, if present
|
||||
} else if (count($formParams) > 0) {
|
||||
// for HTTP post (form)
|
||||
$httpBody = $formParams;
|
||||
}
|
||||
{{#authMethods}}{{#isApiKey}}
|
||||
$apiKey = $this->apiClient->getApiKeyWithPrefix('{{keyParamName}}');
|
||||
if (isset($apiKey)) {
|
||||
{{#isKeyInHeader}}$headerParams['{{keyParamName}}'] = $apiKey;{{/isKeyInHeader}}{{#isKeyInQuery}}$queryParams['{{keyParamName}}'] = $apiKey;{{/isKeyInQuery}}
|
||||
}{{/isApiKey}}
|
||||
{{#isBasic}}$headerParams['Authorization'] = 'Basic '.base64_encode($this->apiClient->getConfig()->getUsername().":".$this->apiClient->getConfig()->getPassword());{{/isBasic}}
|
||||
{{#isOAuth}}//TODO support oauth{{/isOAuth}}
|
||||
{{/authMethods}}
|
||||
// make the API Call
|
||||
try {
|
||||
$response = $this->apiClient->callAPI($resourcePath, $method,
|
||||
$queryParams, $httpBody,
|
||||
$headerParams);
|
||||
} catch (ApiException $e) {
|
||||
switch ($e->getCode()) { {{#responses}}{{#dataType}}
|
||||
case {{code}}:
|
||||
$data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '{{dataType}}');
|
||||
$e->setResponseObject($data);
|
||||
break;{{/dataType}}{{/responses}}
|
||||
/**
|
||||
* API Client
|
||||
* @var \{{invokerPackage}}\ApiClient instance of the ApiClient
|
||||
*/
|
||||
protected $apiClient;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param \{{invokerPackage}}\ApiClient|null $apiClient The api client to use
|
||||
*/
|
||||
function __construct($apiClient = null)
|
||||
{
|
||||
if ($apiClient == null) {
|
||||
$apiClient = new ApiClient();
|
||||
$apiClient->getConfig()->setHost('{{basePath}}');
|
||||
}
|
||||
|
||||
throw $e;
|
||||
}
|
||||
{{#returnType}}
|
||||
if (!$response) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$responseObject = $this->apiClient->getSerializer()->deserialize($response,'{{returnType}}');
|
||||
return $responseObject;
|
||||
{{/returnType}}
|
||||
}
|
||||
{{/operation}}
|
||||
|
||||
$this->apiClient = $apiClient;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get API client
|
||||
* @return \{{invokerPackage}}\ApiClient get the API client
|
||||
*/
|
||||
public function getApiClient()
|
||||
{
|
||||
return $this->apiClient;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the API client
|
||||
* @param \{{invokerPackage}}\ApiClient $apiClient set the API client
|
||||
* @return {{classname}}
|
||||
*/
|
||||
public function setApiClient(ApiClient $apiClient)
|
||||
{
|
||||
$this->apiClient = $apiClient;
|
||||
return $this;
|
||||
}
|
||||
|
||||
{{#operation}}
|
||||
/**
|
||||
* {{{nickname}}}
|
||||
*
|
||||
* {{{summary}}}
|
||||
*
|
||||
{{#allParams}} * @param {{dataType}} ${{paramName}} {{description}} {{#required}}(required){{/required}}{{^required}}(optional){{/required}}
|
||||
{{/allParams}} * @return {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}}
|
||||
* @throws \{{invokerPackage}}\ApiException on non-2xx response
|
||||
*/
|
||||
public function {{nickname}}({{#allParams}}${{paramName}}{{^required}}=null{{/required}}{{#hasMore}}, {{/hasMore}}{{/allParams}})
|
||||
{
|
||||
{{#allParams}}{{#required}}
|
||||
// verify the required parameter '{{paramName}}' is set
|
||||
if (${{paramName}} === null) {
|
||||
throw new \InvalidArgumentException('Missing the required parameter ${{paramName}} when calling {{nickname}}');
|
||||
}{{/required}}{{/allParams}}
|
||||
|
||||
// parse inputs
|
||||
$resourcePath = "{{path}}";
|
||||
$resourcePath = str_replace("{format}", "json", $resourcePath);
|
||||
$method = "{{httpMethod}}";
|
||||
$httpBody = '';
|
||||
$queryParams = array();
|
||||
$headerParams = array();
|
||||
$formParams = array();
|
||||
$_header_accept = ApiClient::selectHeaderAccept(array({{#produces}}'{{mediaType}}'{{#hasMore}}, {{/hasMore}}{{/produces}}));
|
||||
if (!is_null($_header_accept)) {
|
||||
$headerParams['Accept'] = $_header_accept;
|
||||
}
|
||||
$headerParams['Content-Type'] = ApiClient::selectHeaderContentType(array({{#consumes}}'{{mediaType}}'{{#hasMore}},{{/hasMore}}{{/consumes}}));
|
||||
|
||||
{{#queryParams}}// query params
|
||||
if (${{paramName}} !== null) {
|
||||
$queryParams['{{baseName}}'] = $this->apiClient->getSerializer()->toQueryValue(${{paramName}});
|
||||
}{{/queryParams}}
|
||||
{{#headerParams}}// header params
|
||||
if (${{paramName}} !== null) {
|
||||
$headerParams['{{baseName}}'] = $this->apiClient->getSerializer()->toHeaderValue(${{paramName}});
|
||||
}{{/headerParams}}
|
||||
{{#pathParams}}// path params
|
||||
if (${{paramName}} !== null) {
|
||||
$resourcePath = str_replace(
|
||||
"{" . "{{baseName}}" . "}",
|
||||
$this->apiClient->getSerializer()->toPathValue(${{paramName}}),
|
||||
$resourcePath
|
||||
);
|
||||
}{{/pathParams}}
|
||||
{{#formParams}}// form params
|
||||
if (${{paramName}} !== null) {
|
||||
$formParams['{{baseName}}'] = {{#isFile}}'@' . {{/isFile}}$this->apiClient->getSerializer()->toFormValue(${{paramName}});
|
||||
}{{/formParams}}
|
||||
{{#bodyParams}}// body params
|
||||
$_tempBody = null;
|
||||
if (isset(${{paramName}})) {
|
||||
$_tempBody = ${{paramName}};
|
||||
}{{/bodyParams}}
|
||||
|
||||
// for model (json/xml)
|
||||
if (isset($_tempBody)) {
|
||||
$httpBody = $_tempBody; // $_tempBody is the method argument, if present
|
||||
} else if (count($formParams) > 0) {
|
||||
$httpBody = $formParams; // for HTTP post (form)
|
||||
}
|
||||
{{#authMethods}}{{#isApiKey}}
|
||||
$apiKey = $this->apiClient->getApiKeyWithPrefix('{{keyParamName}}');
|
||||
if (isset($apiKey)) {
|
||||
{{#isKeyInHeader}}$headerParams['{{keyParamName}}'] = $apiKey;{{/isKeyInHeader}}{{#isKeyInQuery}}$queryParams['{{keyParamName}}'] = $apiKey;{{/isKeyInQuery}}
|
||||
}{{/isApiKey}}
|
||||
{{#isBasic}}$headerParams['Authorization'] = 'Basic '.base64_encode($this->apiClient->getConfig()->getUsername().":".$this->apiClient->getConfig()->getPassword());{{/isBasic}}
|
||||
{{#isOAuth}}//TODO support oauth{{/isOAuth}}
|
||||
{{/authMethods}}
|
||||
// make the API Call
|
||||
try
|
||||
{
|
||||
list($response, $httpHeader) = $this->apiClient->callApi(
|
||||
$resourcePath, $method,
|
||||
$queryParams, $httpBody,
|
||||
$headerParams{{#returnType}}, '{{returnType}}'{{/returnType}}
|
||||
);
|
||||
} catch (ApiException $e) {
|
||||
switch ($e->getCode()) { {{#responses}}{{#dataType}}
|
||||
case {{code}}:
|
||||
$data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '{{dataType}}', $httpHeader);
|
||||
$e->setResponseObject($data);
|
||||
break;{{/dataType}}{{/responses}}
|
||||
}
|
||||
|
||||
throw $e;
|
||||
}
|
||||
{{#returnType}}
|
||||
if (!$response) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->apiClient->getSerializer()->deserialize($response, '{{returnType}}');
|
||||
{{/returnType}}
|
||||
}
|
||||
{{/operation}}
|
||||
}
|
||||
{{/operations}}
|
||||
|
||||
@@ -1,33 +1,33 @@
|
||||
{
|
||||
"name": "{{groupId}}/{{artifactId}}",{{#artifactVersion}}
|
||||
"version": "{{artifactVersion}}",{{/artifactVersion}}
|
||||
"description": "{{description}}",
|
||||
"keywords": [
|
||||
"swagger",
|
||||
"php",
|
||||
"sdk",
|
||||
"api"
|
||||
],
|
||||
"homepage": "http://swagger.io",
|
||||
"license": "Apache v2",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Swagger and contributors",
|
||||
"homepage": "https://github.com/swagger-api/swagger-codegen"
|
||||
"name": "{{groupId}}/{{artifactId}}",{{#artifactVersion}}
|
||||
"version": "{{artifactVersion}}",{{/artifactVersion}}
|
||||
"description": "{{description}}",
|
||||
"keywords": [
|
||||
"swagger",
|
||||
"php",
|
||||
"sdk",
|
||||
"api"
|
||||
],
|
||||
"homepage": "http://swagger.io",
|
||||
"license": "Apache v2",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Swagger and contributors",
|
||||
"homepage": "https://github.com/swagger-api/swagger-codegen"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=5.3.3",
|
||||
"ext-curl": "*",
|
||||
"ext-json": "*",
|
||||
"ext-mbstring": "*"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "~4.0",
|
||||
"satooshi/php-coveralls": "~0.6.1",
|
||||
"squizlabs/php_codesniffer": "~2.0"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": { "{{escapedInvokerPackage}}\\" : "{{srcBasePath}}/" }
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=5.3.3",
|
||||
"ext-curl": "*",
|
||||
"ext-json": "*",
|
||||
"ext-mbstring": "*"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "~4.0",
|
||||
"satooshi/php-coveralls": "~0.6.1",
|
||||
"squizlabs/php_codesniffer": "~2.0"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": { "{{escapedInvokerPackage}}\\" : "{{srcBasePath}}/" }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,15 @@
|
||||
<?php
|
||||
/**
|
||||
* Configuration
|
||||
* PHP version 5
|
||||
*
|
||||
* @category Class
|
||||
* @package {{invokerPackage}}
|
||||
* @author http://github.com/swagger-api/swagger-codegen
|
||||
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache Licene v2
|
||||
* @link https://github.com/swagger-api/swagger-codegen
|
||||
*/
|
||||
|
||||
/**
|
||||
* Copyright 2015 SmartBear Software
|
||||
*
|
||||
@@ -15,252 +26,439 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* NOTE: This class is auto generated by the swagger code generator program.
|
||||
* https://github.com/swagger-api/swagger-codegen
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
namespace {{invokerPackage}};
|
||||
|
||||
class Configuration {
|
||||
/**
|
||||
* Configuration Class Doc Comment
|
||||
* PHP version 5
|
||||
*
|
||||
* @category Class
|
||||
* @package {{invokerPackage}}
|
||||
* @author http://github.com/swagger-api/swagger-codegen
|
||||
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache Licene v2
|
||||
* @link https://github.com/swagger-api/swagger-codegen
|
||||
*/
|
||||
class Configuration
|
||||
{
|
||||
|
||||
private static $defaultConfiguration = null;
|
||||
private static $_defaultConfiguration = null;
|
||||
|
||||
/**
|
||||
* Associate array to store API key(s)
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $apiKeys = array();
|
||||
|
||||
/**
|
||||
* Associate array to store API prefix (e.g. Bearer)
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $apiKeyPrefixes = array();
|
||||
|
||||
/**
|
||||
* Username for HTTP basic authentication
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $username = '';
|
||||
|
||||
/**
|
||||
* Password for HTTP basic authentication
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $password = '';
|
||||
|
||||
/**
|
||||
* The default instance of ApiClient
|
||||
*
|
||||
* @var \{{invokerPackage}}\ApiClient
|
||||
*/
|
||||
protected $defaultHeaders = array();
|
||||
|
||||
/**
|
||||
* The host
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $host = 'http://localhost';
|
||||
|
||||
/**
|
||||
* Timeout (second) of the HTTP request, by default set to 0, no timeout
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $curlTimeout = 0;
|
||||
|
||||
/**
|
||||
* User agent of the HTTP request, set to "PHP-Swagger" by default
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $userAgent = "PHP-Swagger";
|
||||
|
||||
/**
|
||||
* Debug switch (default set to false)
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $debug = false;
|
||||
|
||||
/**
|
||||
* Debug file location (log to STDOUT by default)
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $debugFile = 'php://output';
|
||||
|
||||
/** @var string[] Associate array to store API key(s) */
|
||||
protected $apiKeys = array();
|
||||
/**
|
||||
* Debug file location (log to STDOUT by default)
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $tempFolderPath;
|
||||
|
||||
/** string[] Associate array to store API prefix (e.g. Bearer) */
|
||||
protected $apiKeyPrefixes = array();
|
||||
|
||||
/** @var string Username for HTTP basic authentication */
|
||||
protected $username = '';
|
||||
|
||||
/** @var string Password for HTTP basic authentication */
|
||||
protected $password = '';
|
||||
|
||||
/** @var \{{invokerPackage}}\ApiClient The default instance of ApiClient */
|
||||
protected $defaultHeaders = array();
|
||||
|
||||
/** @var string The host */
|
||||
protected $host = 'http://localhost';
|
||||
|
||||
/** @var string timeout (second) of the HTTP request, by default set to 0, no timeout */
|
||||
protected $curlTimeout = 0;
|
||||
|
||||
/** @var string user agent of the HTTP request, set to "PHP-Swagger" by default */
|
||||
protected $userAgent = "PHP-Swagger";
|
||||
|
||||
/** @var bool Debug switch (default set to false) */
|
||||
protected $debug = false;
|
||||
|
||||
/** @var string Debug file location (log to STDOUT by default) */
|
||||
protected $debugFile = 'php://output';
|
||||
|
||||
/**
|
||||
* @param string $key
|
||||
* @param string $value
|
||||
* @return Configuration
|
||||
*/
|
||||
public function setApiKey($key, $value) {
|
||||
$this->apiKeys[$key] = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $key
|
||||
* @return string
|
||||
*/
|
||||
public function getApiKey($key) {
|
||||
return isset($this->apiKeys[$key]) ? $this->apiKeys[$key] : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $key
|
||||
* @param string $value
|
||||
* @return Configuration
|
||||
*/
|
||||
public function setApiKeyPrefix($key, $value) {
|
||||
$this->apiKeyPrefixes[$key] = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $key
|
||||
* @return string
|
||||
*/
|
||||
public function getApiKeyPrefix($key) {
|
||||
return isset($this->apiKeyPrefixes[$key]) ? $this->apiKeyPrefixes[$key] : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $username
|
||||
* @return Configuration
|
||||
*/
|
||||
public function setUsername($username) {
|
||||
$this->username = $username;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getUsername() {
|
||||
return $this->username;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $password
|
||||
* @return Configuration
|
||||
*/
|
||||
public function setPassword($password) {
|
||||
$this->password = $password;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getPassword() {
|
||||
return $this->password;
|
||||
}
|
||||
|
||||
/**
|
||||
* add default header
|
||||
*
|
||||
* @param string $headerName header name (e.g. Token)
|
||||
* @param string $headerValue header value (e.g. 1z8wp3)
|
||||
* @return ApiClient
|
||||
*/
|
||||
public function addDefaultHeader($headerName, $headerValue) {
|
||||
if (!is_string($headerName)) {
|
||||
throw new \InvalidArgumentException('Header name must be a string.');
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->tempFolderPath = sys_get_temp_dir();
|
||||
}
|
||||
|
||||
$this->defaultHeaders[$headerName] = $headerValue;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* get the default header
|
||||
*
|
||||
* @return array default header
|
||||
*/
|
||||
public function getDefaultHeaders() {
|
||||
return $this->defaultHeaders;
|
||||
}
|
||||
|
||||
/**
|
||||
* delete a default header
|
||||
* @param string $headerName the header to delete
|
||||
* @return Configuration
|
||||
*/
|
||||
public function deleteDefaultHeader($headerName) {
|
||||
unset($this->defaultHeaders[$headerName]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $host
|
||||
* @return Configuration
|
||||
*/
|
||||
public function setHost($host) {
|
||||
$this->host = $host;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getHost() {
|
||||
return $this->host;
|
||||
}
|
||||
|
||||
/**
|
||||
* set the user agent of the api client
|
||||
*
|
||||
* @param string $userAgent the user agent of the api client
|
||||
* @return ApiClient
|
||||
*/
|
||||
public function setUserAgent($userAgent) {
|
||||
if (!is_string($userAgent)) {
|
||||
throw new \InvalidArgumentException('User-agent must be a string.');
|
||||
|
||||
/**
|
||||
* Sets API key
|
||||
*
|
||||
* @param string $apiKeyIdentifier API key identifier (authentication scheme)
|
||||
* @param string $key API key or token
|
||||
*
|
||||
* @return Configuration
|
||||
*/
|
||||
public function setApiKey($apiKeyIdentifier, $key)
|
||||
{
|
||||
$this->apiKeys[$apiKeyIdentifier] = $key;
|
||||
return $this;
|
||||
}
|
||||
|
||||
$this->userAgent = $userAgent;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* get the user agent of the api client
|
||||
*
|
||||
* @return string user agent
|
||||
*/
|
||||
public function getUserAgent() {
|
||||
return $this->userAgent;
|
||||
}
|
||||
|
||||
/**
|
||||
* set the HTTP timeout value
|
||||
*
|
||||
* @param integer $seconds Number of seconds before timing out [set to 0 for no timeout]
|
||||
* @return ApiClient
|
||||
*/
|
||||
public function setCurlTimeout($seconds) {
|
||||
if (!is_numeric($seconds) || $seconds < 0) {
|
||||
throw new \InvalidArgumentException('Timeout value must be numeric and a non-negative number.');
|
||||
|
||||
/**
|
||||
* Gets API key
|
||||
*
|
||||
* @param string $apiKeyIdentifier API key identifier (authentication scheme)
|
||||
*
|
||||
* @return string API key or token
|
||||
*/
|
||||
public function getApiKey($apiKeyIdentifier)
|
||||
{
|
||||
return isset($this->apiKeys[$apiKeyIdentifier]) ? $this->apiKeys[$apiKeyIdentifier] : null;
|
||||
}
|
||||
|
||||
$this->curlTimeout = $seconds;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* get the HTTP timeout value
|
||||
*
|
||||
* @return string HTTP timeout value
|
||||
*/
|
||||
public function getCurlTimeout() {
|
||||
return $this->curlTimeout;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $debug
|
||||
* @return Configuration
|
||||
*/
|
||||
public function setDebug($debug) {
|
||||
$this->debug = $debug;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function getDebug() {
|
||||
return $this->debug;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $debugFile
|
||||
* @return Configuration
|
||||
*/
|
||||
public function setDebugFile($debugFile) {
|
||||
$this->debugFile = $debugFile;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getDebugFile() {
|
||||
return $this->debugFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Configuration
|
||||
*/
|
||||
public static function getDefaultConfiguration() {
|
||||
if (self::$defaultConfiguration == null) {
|
||||
return new Configuration();
|
||||
|
||||
/**
|
||||
* Sets the prefix for API key (e.g. Bearer)
|
||||
*
|
||||
* @param string $apiKeyIdentifier API key identifier (authentication scheme)
|
||||
* @param string $prefix API key prefix, e.g. Bearer
|
||||
*
|
||||
* @return Configuration
|
||||
*/
|
||||
public function setApiKeyPrefix($apiKeyIdentifier, $prefix)
|
||||
{
|
||||
$this->apiKeyPrefixes[$apiKeyIdentifier] = $prefix;
|
||||
return $this;
|
||||
}
|
||||
|
||||
return self::$defaultConfiguration;
|
||||
}
|
||||
|
||||
public static function setDefaultConfiguration(Configuration $config) {
|
||||
self::$defaultConfiguration = $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets API key prefix
|
||||
*
|
||||
* @param string $apiKeyIdentifier API key identifier (authentication scheme)
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getApiKeyPrefix($apiKeyIdentifier)
|
||||
{
|
||||
return isset($this->apiKeyPrefixes[$apiKeyIdentifier]) ? $this->apiKeyPrefixes[$apiKeyIdentifier] : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the username for HTTP basic authentication
|
||||
*
|
||||
* @param string $username Username for HTTP basic authentication
|
||||
*
|
||||
* @return Configuration
|
||||
*/
|
||||
public function setUsername($username)
|
||||
{
|
||||
$this->username = $username;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the username for HTTP basic authentication
|
||||
*
|
||||
* @return string Username for HTTP basic authentication
|
||||
*/
|
||||
public function getUsername()
|
||||
{
|
||||
return $this->username;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the password for HTTP basic authentication
|
||||
*
|
||||
* @param string $password Password for HTTP basic authentication
|
||||
*
|
||||
* @return Configuration
|
||||
*/
|
||||
public function setPassword($password)
|
||||
{
|
||||
$this->password = $password;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the password for HTTP basic authentication
|
||||
*
|
||||
* @return string Password for HTTP basic authentication
|
||||
*/
|
||||
public function getPassword()
|
||||
{
|
||||
return $this->password;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a default header
|
||||
*
|
||||
* @param string $headerName header name (e.g. Token)
|
||||
* @param string $headerValue header value (e.g. 1z8wp3)
|
||||
*
|
||||
* @return ApiClient
|
||||
*/
|
||||
public function addDefaultHeader($headerName, $headerValue)
|
||||
{
|
||||
if (!is_string($headerName)) {
|
||||
throw new \InvalidArgumentException('Header name must be a string.');
|
||||
}
|
||||
|
||||
$this->defaultHeaders[$headerName] = $headerValue;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the default header
|
||||
*
|
||||
* @return array An array of default header(s)
|
||||
*/
|
||||
public function getDefaultHeaders()
|
||||
{
|
||||
return $this->defaultHeaders;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a default header
|
||||
*
|
||||
* @param string $headerName the header to delete
|
||||
*
|
||||
* @return Configuration
|
||||
*/
|
||||
public function deleteDefaultHeader($headerName)
|
||||
{
|
||||
unset($this->defaultHeaders[$headerName]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the host
|
||||
*
|
||||
* @param string $host Host
|
||||
*
|
||||
* @return Configuration
|
||||
*/
|
||||
public function setHost($host)
|
||||
{
|
||||
$this->host = $host;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the host
|
||||
*
|
||||
* @return string Host
|
||||
*/
|
||||
public function getHost()
|
||||
{
|
||||
return $this->host;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the user agent of the api client
|
||||
*
|
||||
* @param string $userAgent the user agent of the api client
|
||||
*
|
||||
* @return ApiClient
|
||||
*/
|
||||
public function setUserAgent($userAgent)
|
||||
{
|
||||
if (!is_string($userAgent)) {
|
||||
throw new \InvalidArgumentException('User-agent must be a string.');
|
||||
}
|
||||
|
||||
$this->userAgent = $userAgent;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the user agent of the api client
|
||||
*
|
||||
* @return string user agent
|
||||
*/
|
||||
public function getUserAgent()
|
||||
{
|
||||
return $this->userAgent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the HTTP timeout value
|
||||
*
|
||||
* @param integer $seconds Number of seconds before timing out [set to 0 for no timeout]
|
||||
*
|
||||
* @return ApiClient
|
||||
*/
|
||||
public function setCurlTimeout($seconds)
|
||||
{
|
||||
if (!is_numeric($seconds) || $seconds < 0) {
|
||||
throw new \InvalidArgumentException('Timeout value must be numeric and a non-negative number.');
|
||||
}
|
||||
|
||||
$this->curlTimeout = $seconds;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the HTTP timeout value
|
||||
*
|
||||
* @return string HTTP timeout value
|
||||
*/
|
||||
public function getCurlTimeout()
|
||||
{
|
||||
return $this->curlTimeout;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets debug flag
|
||||
*
|
||||
* @param bool $debug Debug flag
|
||||
*
|
||||
* @return Configuration
|
||||
*/
|
||||
public function setDebug($debug)
|
||||
{
|
||||
$this->debug = $debug;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the debug flag
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function getDebug()
|
||||
{
|
||||
return $this->debug;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the debug file
|
||||
*
|
||||
* @param string $debugFile Debug file
|
||||
*
|
||||
* @return Configuration
|
||||
*/
|
||||
public function setDebugFile($debugFile)
|
||||
{
|
||||
$this->debugFile = $debugFile;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the debug file
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDebugFile()
|
||||
{
|
||||
return $this->debugFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the temp folder path
|
||||
*
|
||||
* @param string $tempFolderPath Temp folder path
|
||||
*
|
||||
* @return Configuration
|
||||
*/
|
||||
public function setTempFolderPath($tempFolderPath)
|
||||
{
|
||||
$this->tempFolderPath = $tempFolderPath;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the temp folder path
|
||||
*
|
||||
* @return string Temp folder path
|
||||
*/
|
||||
public function getTempFolderPath()
|
||||
{
|
||||
return $this->tempFolderPath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the default configuration instance
|
||||
*
|
||||
* @return Configuration
|
||||
*/
|
||||
public static function getDefaultConfiguration()
|
||||
{
|
||||
if (self::$_defaultConfiguration == null) {
|
||||
self::$_defaultConfiguration = new Configuration();
|
||||
}
|
||||
|
||||
return self::$_defaultConfiguration;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the detault configuration instance
|
||||
*
|
||||
* @param Configuration $config An instance of the Configuration Object
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function setDefaultConfiguration(Configuration $config)
|
||||
{
|
||||
self::$_defaultConfiguration = $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the essential information for debugging
|
||||
*
|
||||
* @return string The report for debugging
|
||||
*/
|
||||
public static function toDebugReport()
|
||||
{
|
||||
$report = "PHP SDK ({{invokerPackage}}) Debug Report:\n";
|
||||
$report .= " OS: ".php_uname()."\n";
|
||||
$report .= " PHP Version: ".phpversion()."\n";
|
||||
$report .= " Swagger Spec Version: {{version}}\n";
|
||||
$report .= " SDK Package Version: {{artifactVersion}}\n";
|
||||
$report .= " Temp Folder Path: ".self::getDefaultConfiguration()->getTempFolderPath()."\n";
|
||||
|
||||
return $report;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,4 +1,17 @@
|
||||
<?php
|
||||
{{#models}}
|
||||
{{#model}}
|
||||
/**
|
||||
* {{classname}}
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* @category Class
|
||||
* @package {{invokerPackage}}
|
||||
* @author http://github.com/swagger-api/swagger-codegen
|
||||
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache Licene v2
|
||||
* @link https://github.com/swagger-api/swagger-codegen
|
||||
*/
|
||||
/**
|
||||
* Copyright 2015 SmartBear Software
|
||||
*
|
||||
@@ -14,97 +27,160 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
{{#models}}
|
||||
{{#model}}
|
||||
/**
|
||||
* {{description}}
|
||||
*
|
||||
* NOTE: This class is auto generated by the swagger code generator program. Do not edit the class manually.
|
||||
*
|
||||
* NOTE: This class is auto generated by the swagger code generator program.
|
||||
* https://github.com/swagger-api/swagger-codegen
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
namespace {{modelPackage}};
|
||||
|
||||
use \ArrayAccess;
|
||||
/**
|
||||
* {{classname}} Class Doc Comment
|
||||
*
|
||||
* @category Class
|
||||
* @description {{description}}
|
||||
* @package {{invokerPackage}}
|
||||
* @author http://github.com/swagger-api/swagger-codegen
|
||||
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache Licene v2
|
||||
* @link https://github.com/swagger-api/swagger-codegen
|
||||
*/
|
||||
class {{classname}} implements ArrayAccess
|
||||
{
|
||||
/**
|
||||
* Array of property to type mappings. Used for (de)serialization
|
||||
* @var string[]
|
||||
*/
|
||||
static $swaggerTypes = array(
|
||||
{{#vars}}'{{name}}' => '{{{datatype}}}'{{#hasMore}},
|
||||
{{/hasMore}}{{/vars}}
|
||||
);
|
||||
|
||||
/**
|
||||
* Array of attributes where the key is the local name, and the value is the original name
|
||||
* @var string[]
|
||||
*/
|
||||
static $attributeMap = array(
|
||||
{{#vars}}'{{name}}' => '{{baseName}}'{{#hasMore}},
|
||||
{{/hasMore}}{{/vars}}
|
||||
);
|
||||
|
||||
/**
|
||||
* Array of attributes to setter functions (for deserialization of responses)
|
||||
* @var string[]
|
||||
*/
|
||||
static $setters = array(
|
||||
{{#vars}}'{{name}}' => '{{setter}}'{{#hasMore}},
|
||||
{{/hasMore}}{{/vars}}
|
||||
);
|
||||
|
||||
/**
|
||||
* Array of attributes to getter functions (for serialization of requests)
|
||||
* @var string[]
|
||||
*/
|
||||
static $getters = array(
|
||||
{{#vars}}'{{name}}' => '{{getter}}'{{#hasMore}},
|
||||
{{/hasMore}}{{/vars}}
|
||||
);
|
||||
|
||||
{{#vars}}
|
||||
/**
|
||||
* ${{name}} {{#description}}{{{description}}}{{/description}}
|
||||
* @var {{datatype}}
|
||||
*/
|
||||
protected ${{name}};
|
||||
{{/vars}}
|
||||
|
||||
class {{classname}} implements ArrayAccess {
|
||||
/** @var string[] Array of property to type mappings. Used for (de)serialization */
|
||||
static $swaggerTypes = array(
|
||||
{{#vars}}'{{name}}' => '{{{datatype}}}'{{#hasMore}},
|
||||
{{/hasMore}}{{/vars}}
|
||||
);
|
||||
|
||||
/** @var string[] Array of attributes where the key is the local name, and the value is the original name */
|
||||
static $attributeMap = array(
|
||||
{{#vars}}'{{name}}' => '{{baseName}}'{{#hasMore}},
|
||||
{{/hasMore}}{{/vars}}
|
||||
);
|
||||
|
||||
/** @var string[] Array of attributes to setter functions (for deserialization of responses) */
|
||||
static $setters = array(
|
||||
{{#vars}}'{{name}}' => '{{setter}}'{{#hasMore}},
|
||||
{{/hasMore}}{{/vars}}
|
||||
);
|
||||
|
||||
/** @var string[] Array of attributes to getter functions (for serialization of requests) */
|
||||
static $getters = array(
|
||||
{{#vars}}'{{name}}' => '{{getter}}'{{#hasMore}},
|
||||
{{/hasMore}}{{/vars}}
|
||||
);
|
||||
|
||||
{{#vars}}
|
||||
/** @var {{datatype}} ${{name}} {{#description}}{{{description}}} {{/description}}*/
|
||||
protected ${{name}};
|
||||
{{/vars}}
|
||||
public function __construct(array $data = null) {
|
||||
if ($data != null) {
|
||||
{{#vars}}$this->{{name}} = $data["{{name}}"];{{#hasMore}}
|
||||
{{/hasMore}}{{/vars}}
|
||||
/**
|
||||
* Constructor
|
||||
* @param mixed[] $data Associated array of property value initalizing the model
|
||||
*/
|
||||
public function __construct(array $data = null)
|
||||
{
|
||||
if ($data != null) {
|
||||
{{#vars}}$this->{{name}} = $data["{{name}}"];{{#hasMore}}
|
||||
{{/hasMore}}{{/vars}}
|
||||
}
|
||||
}
|
||||
}
|
||||
{{#vars}}
|
||||
/**
|
||||
* get {{name}}
|
||||
* @return {{datatype}}
|
||||
*/
|
||||
public function {{getter}}() {
|
||||
return $this->{{name}};
|
||||
}
|
||||
|
||||
/**
|
||||
* set {{name}}
|
||||
* @param {{datatype}} ${{name}}
|
||||
* @return $this
|
||||
*/
|
||||
public function {{setter}}(${{name}}) {
|
||||
$this->{{name}} = ${{name}};
|
||||
return $this;
|
||||
}
|
||||
{{/vars}}
|
||||
public function offsetExists($offset) {
|
||||
return isset($this->$offset);
|
||||
}
|
||||
|
||||
public function offsetGet($offset) {
|
||||
return $this->$offset;
|
||||
}
|
||||
|
||||
public function offsetSet($offset, $value) {
|
||||
$this->$offset = $value;
|
||||
}
|
||||
|
||||
public function offsetUnset($offset) {
|
||||
unset($this->$offset);
|
||||
}
|
||||
|
||||
public function __toString() {
|
||||
if (defined('JSON_PRETTY_PRINT')) {
|
||||
return json_encode($this, JSON_PRETTY_PRINT);
|
||||
} else {
|
||||
return json_encode($this);
|
||||
{{#vars}}
|
||||
/**
|
||||
* Gets {{name}}
|
||||
* @return {{datatype}}
|
||||
*/
|
||||
public function {{getter}}()
|
||||
{
|
||||
return $this->{{name}};
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets {{name}}
|
||||
* @param {{datatype}} ${{name}} {{#description}}{{{description}}}{{/description}}
|
||||
* @return $this
|
||||
*/
|
||||
public function {{setter}}(${{name}})
|
||||
{
|
||||
{{#isEnum}}$allowed_values = array({{#allowableValues}}{{#values}}"{{{this}}}"{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}});
|
||||
if (!in_array(${{{name}}}, $allowed_values)) {
|
||||
throw new \InvalidArgumentException("Invalid value for '{{name}}', must be one of {{#allowableValues}}{{#values}}'{{{this}}}'{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}}");
|
||||
}{{/isEnum}}
|
||||
$this->{{name}} = ${{name}};
|
||||
return $this;
|
||||
}
|
||||
{{/vars}}
|
||||
/**
|
||||
* Returns true if offset exists. False otherwise.
|
||||
* @param integer $offset Offset
|
||||
* @return boolean
|
||||
*/
|
||||
public function offsetExists($offset)
|
||||
{
|
||||
return isset($this->$offset);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets offset.
|
||||
* @param integer $offset Offset
|
||||
* @return mixed
|
||||
*/
|
||||
public function offsetGet($offset)
|
||||
{
|
||||
return $this->$offset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets value based on offset.
|
||||
* @param integer $offset Offset
|
||||
* @param mixed $value Value to be set
|
||||
* @return void
|
||||
*/
|
||||
public function offsetSet($offset, $value)
|
||||
{
|
||||
$this->$offset = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Unsets offset.
|
||||
* @param integer $offset Offset
|
||||
* @return void
|
||||
*/
|
||||
public function offsetUnset($offset)
|
||||
{
|
||||
unset($this->$offset);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the string presentation of the object
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
if (defined('JSON_PRETTY_PRINT')) {
|
||||
return json_encode(get_object_vars($this), JSON_PRETTY_PRINT);
|
||||
} else {
|
||||
return json_encode(get_object_vars($this));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
{{/model}}
|
||||
{{/models}}
|
||||
|
||||
@@ -47,7 +47,7 @@ class {{classname}}(object):
|
||||
{{{summary}}}
|
||||
{{{notes}}}
|
||||
|
||||
{{#allParams}}:param {{dataType}} {{paramName}}: {{{description}}} {{#required}}(required){{/required}}{{#optional}}(optional){{/optional}}
|
||||
{{#allParams}}:param {{dataType}} {{paramName}}: {{{description}}} {{#required}}(required){{/required}}{{^required}}(optional){{/required}}
|
||||
{{/allParams}}
|
||||
:return: {{#returnType}}{{returnType}}{{/returnType}}{{^returnType}}None{{/returnType}}
|
||||
"""
|
||||
|
||||
@@ -36,7 +36,7 @@ class {{classname}}(object):
|
||||
{{{notes}}}
|
||||
|
||||
Args:
|
||||
{{#allParams}}{{paramName}}, {{dataType}}: {{{description}}} {{^optional}}(required){{/optional}}{{#optional}}(optional){{/optional}}
|
||||
{{#allParams}}{{paramName}}, {{dataType}}: {{{description}}} {{#required}}(required){{/required}}{{^required}}(optional){{/required}}
|
||||
{{/allParams}}
|
||||
|
||||
Returns: {{returnType}}
|
||||
|
||||
@@ -60,6 +60,18 @@ module {{moduleName}}
|
||||
# @return [#debug]
|
||||
attr_accessor :logger
|
||||
|
||||
# Defines the temporary folder to store downloaded files
|
||||
# (for API endpoints that have file response).
|
||||
# Default to use `Tempfile`.
|
||||
#
|
||||
# @return [String]
|
||||
attr_accessor :temp_folder_path
|
||||
|
||||
# Defines the headers to be used in HTTP requests of all API calls by default.
|
||||
#
|
||||
# @return [Hash]
|
||||
attr_accessor :default_headers
|
||||
|
||||
# Defaults go in here..
|
||||
def initialize
|
||||
@format = 'json'
|
||||
@@ -70,6 +82,12 @@ module {{moduleName}}
|
||||
@inject_format = false
|
||||
@force_ending_format = false
|
||||
|
||||
@default_headers = {
|
||||
'Content-Type' => "application/#{@format.downcase}",
|
||||
'User-Agent' => @user_agent
|
||||
}
|
||||
|
||||
# keys for API key authentication (param-name => api-key)
|
||||
@api_key = {}
|
||||
@api_key_prefix = {}
|
||||
|
||||
|
||||
@@ -9,27 +9,21 @@ module {{moduleName}}
|
||||
# All requests must have an HTTP method and a path
|
||||
# Optionals parameters are :params, :headers, :body, :format, :host
|
||||
def initialize(http_method, path, attributes = {})
|
||||
attributes[:format] ||= Swagger.configuration.format
|
||||
attributes[:params] ||= {}
|
||||
@http_method = http_method.to_sym.downcase
|
||||
@path = path
|
||||
|
||||
# Set default headers
|
||||
default_headers = {
|
||||
'Content-Type' => "application/#{attributes[:format].downcase}",
|
||||
'User-Agent' => Swagger.configuration.user_agent
|
||||
}
|
||||
attributes.each { |name, value| send "#{name}=", value }
|
||||
|
||||
# Merge argument headers into defaults
|
||||
attributes[:headers] = default_headers.merge(attributes[:headers] || {})
|
||||
@format ||= Swagger.configuration.format
|
||||
@params ||= {}
|
||||
|
||||
# Apply default headers
|
||||
@headers = Swagger.configuration.default_headers.merge(@headers || {})
|
||||
|
||||
# Stick in the auth token if there is one
|
||||
if Swagger.authenticated?
|
||||
attributes[:headers].merge!({:auth_token => Swagger.configuration.auth_token})
|
||||
@headers.merge!({:auth_token => Swagger.configuration.auth_token})
|
||||
end
|
||||
|
||||
self.http_method = http_method.to_sym.downcase
|
||||
self.path = path
|
||||
|
||||
attributes.each { |name, value| send "#{name}=", value }
|
||||
{{#hasAuthMethods}}
|
||||
update_params_for_auth!
|
||||
{{/hasAuthMethods}}
|
||||
|
||||
@@ -3,6 +3,7 @@ module {{moduleName}}
|
||||
class Response
|
||||
require 'json'
|
||||
require 'date'
|
||||
require 'tempfile'
|
||||
|
||||
attr_accessor :raw
|
||||
|
||||
@@ -32,8 +33,11 @@ module {{moduleName}}
|
||||
def deserialize(return_type)
|
||||
return nil if body.nil? || body.empty?
|
||||
|
||||
# handle file downloading - save response body into a tmp file and return the File instance
|
||||
return download_file if return_type == 'File'
|
||||
|
||||
# ensuring a default content type
|
||||
content_type = raw.headers_hash['Content-Type'] || 'application/json'
|
||||
content_type = raw.headers['Content-Type'] || 'application/json'
|
||||
|
||||
unless content_type.start_with?('application/json')
|
||||
fail "Content-Type is not supported: #{content_type}"
|
||||
@@ -91,6 +95,28 @@ module {{moduleName}}
|
||||
end
|
||||
end
|
||||
|
||||
# Save response body into a file in (the defined) temporary folder, using the filename
|
||||
# from the "Content-Disposition" header if provided, otherwise a random filename.
|
||||
#
|
||||
# @see Configuration#temp_folder_path
|
||||
# @return [File] the file downloaded
|
||||
def download_file
|
||||
tmp_file = Tempfile.new '', Swagger.configuration.temp_folder_path
|
||||
content_disposition = raw.headers['Content-Disposition']
|
||||
if content_disposition
|
||||
filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1]
|
||||
path = File.join File.dirname(tmp_file), filename
|
||||
else
|
||||
path = tmp_file.path
|
||||
end
|
||||
# close and delete temp file
|
||||
tmp_file.close!
|
||||
|
||||
File.open(path, 'w') { |file| file.write(raw.body) }
|
||||
Swagger.logger.info "File written to #{path}. Please move the file to a proper folder for further processing and delete the temp afterwards"
|
||||
return File.new(path)
|
||||
end
|
||||
|
||||
# `headers_hash` is a Typhoeus-specific extension of Hash,
|
||||
# so simplify it back into a regular old Hash.
|
||||
def headers
|
||||
|
||||
@@ -21,5 +21,6 @@ require '{{importPath}}'
|
||||
|
||||
module {{moduleName}}
|
||||
# Initialize the default configuration
|
||||
Swagger.configuration ||= Swagger::Configuration.new
|
||||
Swagger.configuration = Swagger::Configuration.new
|
||||
Swagger.configure { |config| }
|
||||
end
|
||||
|
||||
@@ -5,17 +5,16 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import PromiseKit
|
||||
|
||||
class {{projectName}}API {
|
||||
static let basePath = "{{^basePathOverride}}{{basePath}}{{/basePathOverride}}{{basePathOverride}}"
|
||||
class OneteamAPI {
|
||||
static let basePath = "http://ec2-52-68-31-200.ap-northeast-1.compute.amazonaws.com/"
|
||||
static var credential: NSURLCredential?
|
||||
static var requestBuilderFactory: RequestBuilderFactory = AlamofireRequestBuilderFactory()
|
||||
}
|
||||
|
||||
class APIBase {
|
||||
func toParameters(encodable: JSONEncodable?) -> [String: AnyObject]? {
|
||||
let encoded: AnyObject? = encodable?.encode()
|
||||
let encoded: AnyObject? = encodable?.encodeToJSON()
|
||||
|
||||
if encoded! is [AnyObject] {
|
||||
var dictionary = [String:AnyObject]()
|
||||
@@ -44,7 +43,7 @@ class RequestBuilder<T> {
|
||||
self.isBody = isBody
|
||||
}
|
||||
|
||||
func execute() -> Promise<Response<T>> { fatalError("Not implemented") }
|
||||
func execute(completion: (response: Response<T>?, erorr: NSError?) -> Void) { }
|
||||
|
||||
func addHeader(#name: String, value: String) -> Self {
|
||||
if !value.isEmpty {
|
||||
@@ -54,7 +53,7 @@ class RequestBuilder<T> {
|
||||
}
|
||||
|
||||
func addCredential() -> Self {
|
||||
self.credential = {{projectName}}API.credential
|
||||
self.credential = OneteamAPI.credential
|
||||
return self
|
||||
}
|
||||
}
|
||||
@@ -63,4 +62,3 @@ protocol RequestBuilderFactory {
|
||||
func getBuilder<T>() -> RequestBuilder<T>.Type
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
//
|
||||
|
||||
import Alamofire
|
||||
import PromiseKit
|
||||
|
||||
class AlamofireRequestBuilderFactory: RequestBuilderFactory {
|
||||
func getBuilder<T>() -> RequestBuilder<T>.Type {
|
||||
@@ -21,7 +20,7 @@ class AlamofireRequestBuilder<T>: RequestBuilder<T> {
|
||||
super.init(method: method, URLString: URLString, parameters: parameters, isBody: isBody)
|
||||
}
|
||||
|
||||
override func execute() -> Promise<Response<T>> {
|
||||
override func execute(completion: (response: Response<T>?, erorr: NSError?) -> Void) {
|
||||
let managerId = NSUUID().UUIDString
|
||||
// Create a new manager for each request to customize its request header
|
||||
let configuration = NSURLSessionConfiguration.defaultSessionConfiguration()
|
||||
@@ -35,36 +34,41 @@ class AlamofireRequestBuilder<T>: RequestBuilder<T> {
|
||||
request.authenticate(usingCredential: credential)
|
||||
}
|
||||
|
||||
let defer = Promise<Response<T>>.defer()
|
||||
request.responseJSON(options: .AllowFragments) { (req, res, json, error) in
|
||||
managerStore.removeValueForKey(managerId)
|
||||
|
||||
if let error = error {
|
||||
defer.reject(error)
|
||||
completion(response: nil, erorr: error)
|
||||
return
|
||||
}
|
||||
if res!.statusCode >= 400 {
|
||||
//TODO: Add error entity
|
||||
let error = NSError(domain: res!.URL!.URLString, code: res!.statusCode, userInfo: [:])
|
||||
defer.reject(error)
|
||||
let userInfo: [NSObject : AnyObject] = (json != nil) ? ["data": json!] : [:]
|
||||
let error = NSError(domain: res!.URL!.URLString, code: res!.statusCode, userInfo: userInfo)
|
||||
completion(response: nil, erorr: error)
|
||||
return
|
||||
}
|
||||
|
||||
if () is T {
|
||||
let response = Response(response: res!, body: () as! T)
|
||||
defer.fulfill(response)
|
||||
completion(response: response, erorr: nil)
|
||||
return
|
||||
}
|
||||
if let json: AnyObject = json {
|
||||
let body = Decoders.decode(clazz: T.self, source: json)
|
||||
let response = Response(response: res!, body: body)
|
||||
defer.fulfill(response)
|
||||
completion(response: response, erorr: nil)
|
||||
return
|
||||
} else if "" is T {
|
||||
// swagger-parser currently doesn't support void, which will be fixed in future swagger-parser release
|
||||
// https://github.com/swagger-api/swagger-parser/pull/34
|
||||
let response = Response(response: res!, body: "" as! T)
|
||||
completion(response: response, erorr: nil)
|
||||
return
|
||||
}
|
||||
|
||||
defer.reject(NSError(domain: "localhost", code: 500, userInfo: ["reason": "unreacheable code"]))
|
||||
completion(response: nil, erorr: NSError(domain: "localhost", code: 500, userInfo: ["reason": "unreacheable code"]))
|
||||
}
|
||||
return defer.promise
|
||||
}
|
||||
|
||||
private func buildHeaders() -> [String: AnyObject] {
|
||||
@@ -76,4 +80,3 @@ class AlamofireRequestBuilder<T>: RequestBuilder<T> {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -4,45 +4,45 @@
|
||||
// https://github.com/swagger-api/swagger-codegen
|
||||
//
|
||||
|
||||
import Alamofire
|
||||
import PromiseKit
|
||||
import Alamofire{{#usePromiseKit}}
|
||||
import PromiseKit{{/usePromiseKit}}
|
||||
|
||||
extension Bool: JSONEncodable {
|
||||
func encode() -> AnyObject { return self }
|
||||
func encodeToJSON() -> AnyObject { return self }
|
||||
}
|
||||
|
||||
extension Float: JSONEncodable {
|
||||
func encode() -> AnyObject { return self }
|
||||
func encodeToJSON() -> AnyObject { return self }
|
||||
}
|
||||
|
||||
extension Int: JSONEncodable {
|
||||
func encode() -> AnyObject { return self }
|
||||
func encodeToJSON() -> AnyObject { return self }
|
||||
}
|
||||
|
||||
extension Double: JSONEncodable {
|
||||
func encode() -> AnyObject { return self }
|
||||
func encodeToJSON() -> AnyObject { return self }
|
||||
}
|
||||
|
||||
extension String: JSONEncodable {
|
||||
func encode() -> AnyObject { return self }
|
||||
func encodeToJSON() -> AnyObject { return self }
|
||||
}
|
||||
|
||||
private func encodeIfPossible<T>(object: T) -> AnyObject {
|
||||
if object is JSONEncodable {
|
||||
return (object as! JSONEncodable).encode()
|
||||
return (object as! JSONEncodable).encodeToJSON()
|
||||
} else {
|
||||
return object as! AnyObject
|
||||
}
|
||||
}
|
||||
|
||||
extension Array: JSONEncodable {
|
||||
func encode() -> AnyObject {
|
||||
func encodeToJSON() -> AnyObject {
|
||||
return self.map(encodeIfPossible)
|
||||
}
|
||||
}
|
||||
|
||||
extension Dictionary: JSONEncodable {
|
||||
func encode() -> AnyObject {
|
||||
func encodeToJSON() -> AnyObject {
|
||||
var dictionary = [NSObject:AnyObject]()
|
||||
for (key, value) in self {
|
||||
dictionary[key as! NSObject] = encodeIfPossible(value)
|
||||
@@ -50,3 +50,30 @@ extension Dictionary: JSONEncodable {
|
||||
return dictionary
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private let dateFormatter: NSDateFormatter = {
|
||||
let dateFormatter = NSDateFormatter()
|
||||
dateFormatter.dateFormat = "yyyy-MM-dd"
|
||||
return dateFormatter
|
||||
}()
|
||||
|
||||
extension NSDate: JSONEncodable {
|
||||
func encodeToJSON() -> AnyObject {
|
||||
return dateFormatter.stringFromDate(self)
|
||||
}
|
||||
}
|
||||
|
||||
{{#usePromiseKit}}extension RequestBuilder {
|
||||
func execute() -> Promise<Response<T>> {
|
||||
let deferred = Promise<Response<T>>.defer()
|
||||
self.execute { (response: Response<T>?, error: NSError?) in
|
||||
if let response = response {
|
||||
deferred.fulfill(response)
|
||||
} else {
|
||||
deferred.reject(error!)
|
||||
}
|
||||
}
|
||||
return deferred.promise
|
||||
}
|
||||
}{{/usePromiseKit}}
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
import Foundation
|
||||
|
||||
protocol JSONEncodable {
|
||||
func encode() -> AnyObject
|
||||
func encodeToJSON() -> AnyObject
|
||||
}
|
||||
|
||||
class Response<T> {
|
||||
@@ -97,25 +97,32 @@ class Decoders {
|
||||
|
||||
static private func initialize() {
|
||||
dispatch_once(&once) {
|
||||
let dateTimeFormatter = NSDateFormatter()
|
||||
dateTimeFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss'Z'"
|
||||
let dateFormatter = NSDateFormatter()
|
||||
dateFormatter.dateFormat = "yyyy-MM-dd"
|
||||
let formatters = [
|
||||
"yyyy-MM-dd",
|
||||
"yyyy-MM-dd'T'HH:mm:ssZZZZZ",
|
||||
"yyyy-MM-dd'T'HH:mm:ss'Z'"
|
||||
].map { (format: String) -> NSDateFormatter in
|
||||
let formatter = NSDateFormatter()
|
||||
formatter.dateFormat = format
|
||||
return formatter
|
||||
}
|
||||
// Decoder for NSDate
|
||||
Decoders.addDecoder(clazz: NSDate.self) { (source: AnyObject) -> NSDate in
|
||||
let sourceString = source as! String
|
||||
if count(sourceString) == 10 {
|
||||
return dateFormatter.dateFromString(sourceString)!
|
||||
for formatter in formatters {
|
||||
if let date = formatter.dateFromString(sourceString) {
|
||||
return date
|
||||
}
|
||||
}
|
||||
return dateTimeFormatter.dateFromString(sourceString)!
|
||||
fatalError("formatter failed to parse \(sourceString)")
|
||||
} {{#models}}{{#model}}
|
||||
|
||||
// Decoder for {{{classname}}}
|
||||
Decoders.addDecoder(clazz: {{{classname}}}.self) { (source: AnyObject) -> {{{classname}}} in
|
||||
let sourceDictionary = source as! [NSObject:AnyObject]
|
||||
var instance = {{classname}}(){{#vars}}{{#isEnum}}
|
||||
instance.{{name}} = (sourceDictionary["{{name}}"] as? String).map { {{classname}}.{{datatypeWithEnum}}(rawValue: $0)! }{{#required}}!{{/required}} {{/isEnum}}{{^isEnum}}
|
||||
instance.{{name}} = Decoders.decode{{^required}}Optional{{/required}}(clazz: {{{baseType}}}.self, source: sourceDictionary["{{name}}"]{{#required}}!{{/required}}){{/isEnum}}{{/vars}}
|
||||
instance.{{name}} = (sourceDictionary["{{name}}"] as? String).map { {{classname}}.{{datatypeWithEnum}}(rawValue: $0)! }{{#unwrapRequired}}{{#required}}!{{/required}}{{/unwrapRequired}} {{/isEnum}}{{^isEnum}}
|
||||
instance.{{name}} = Decoders.decode{{^unwrapRequired}}Optional{{/unwrapRequired}}{{#unwrapRequired}}{{^required}}Optional{{/required}}{{/unwrapRequired}}(clazz: {{{baseType}}}.self, source: sourceDictionary["{{name}}"]{{#unwrapRequired}}{{#required}}!{{/required}}{{/unwrapRequired}}){{/isEnum}}{{/vars}}
|
||||
return instance
|
||||
}{{/model}}
|
||||
{{/models}}
|
||||
|
||||
@@ -21,7 +21,9 @@ extension {{projectName}}API {
|
||||
- {{{notes}}}{{/notes}}{{#subresourceOperation}}
|
||||
- subresourceOperation: {{subresourceOperation}}{{/subresourceOperation}}{{#defaultResponse}}
|
||||
- defaultResponse: {{defaultResponse}}{{/defaultResponse}}{{#authMethods}}
|
||||
- authMethods: {{authMethods}}{{/authMethods}}{{#responseHeaders}}
|
||||
- {{#isBasic}}BASIC{{/isBasic}}{{#isOAuth}}OAuth{{/isOAuth}}{{#isApiKey}}API Key{{/isApiKey}}:
|
||||
- type: {{type}}{{#keyParamName}} {{keyParamName}} {{#isKeyInQuery}}(QUERY){{/isKeyInQuery}}{{#isKeyInHeaer}}(HEADER){{/isKeyInHeaer}}{{/keyParamName}}
|
||||
- name: {{name}}{{/authMethods}}{{#responseHeaders}}
|
||||
- responseHeaders: {{responseHeaders}}{{/responseHeaders}}{{#examples}}
|
||||
- examples: {{{examples}}}{{/examples}}{{#externalDocs}}
|
||||
- externalDocs: {{externalDocs}}{{/externalDocs}}{{#hasParams}}
|
||||
@@ -35,7 +37,7 @@ extension {{projectName}}API {
|
||||
path = path.stringByReplacingOccurrencesOfString("{{=<% %>=}}{<%paramName%>}<%={{ }}=%>", withString: "\({{paramName}})", options: .LiteralSearch, range: nil){{/pathParams}}
|
||||
let url = {{projectName}}API.basePath + path
|
||||
{{#bodyParam}}
|
||||
let parameters = {{paramName}}{{^required}}?{{/required}}.encode() as? [String:AnyObject]{{/bodyParam}}{{^bodyParam}}
|
||||
let parameters = {{paramName}}{{^required}}?{{/required}}.encodeToJSON() as? [String:AnyObject]{{/bodyParam}}{{^bodyParam}}
|
||||
let nillableParameters: [String:AnyObject?] = {{^queryParams}}[:]{{/queryParams}}{{#queryParams}}{{^secondaryParam}}[{{/secondaryParam}}
|
||||
"{{paramName}}": {{paramName}}{{#hasMore}},{{/hasMore}}{{^hasMore}}
|
||||
]{{/hasMore}}{{/queryParams}}
|
||||
|
||||
@@ -17,17 +17,17 @@ class {{classname}}: JSONEncodable {
|
||||
}
|
||||
{{/isEnum}}{{/vars}}
|
||||
{{#vars}}{{#isEnum}}{{#description}}/** {{description}} */
|
||||
{{/description}}var {{name}}: {{{datatypeWithEnum}}}{{^required}}?{{/required}}{{#required}}!{{/required}}{{#defaultValue}} = {{{defaultValue}}}{{/defaultValue}}{{/isEnum}}{{^isEnum}}{{#description}}/** {{description}} */
|
||||
{{/description}}var {{name}}: {{{datatype}}}{{^required}}?{{/required}}{{#required}}!{{/required}}{{#defaultValue}} = {{{defaultValue}}}{{/defaultValue}}{{/isEnum}}
|
||||
{{/description}}var {{name}}: {{{datatypeWithEnum}}}{{^unwrapRequired}}?{{/unwrapRequired}}{{#unwrapRequired}}{{^required}}?{{/required}}{{#required}}!{{/required}}{{/unwrapRequired}}{{#defaultValue}} = {{{defaultValue}}}{{/defaultValue}}{{/isEnum}}{{^isEnum}}{{#description}}/** {{description}} */
|
||||
{{/description}}var {{name}}: {{{datatype}}}{{^unwrapRequired}}?{{/unwrapRequired}}{{#unwrapRequired}}{{^required}}?{{/required}}{{#required}}!{{/required}}{{/unwrapRequired}}{{#defaultValue}} = {{{defaultValue}}}{{/defaultValue}}{{/isEnum}}
|
||||
{{/vars}}
|
||||
|
||||
// MARK: JSONEncodable
|
||||
func encode() -> AnyObject {
|
||||
func encodeToJSON() -> AnyObject {
|
||||
var nillableDictionary = [String:AnyObject?](){{#vars}}{{#isNotContainer}}{{#isPrimitiveType}}{{^isEnum}}
|
||||
nillableDictionary["{{name}}"] = self.{{name}}{{/isEnum}}{{/isPrimitiveType}}{{#isEnum}}
|
||||
nillableDictionary["{{name}}"] = self.{{name}}{{^required}}?{{/required}}.rawValue{{/isEnum}}{{^isPrimitiveType}}
|
||||
nillableDictionary["{{name}}"] = self.{{name}}{{^required}}?{{/required}}.encode(){{/isPrimitiveType}}{{/isNotContainer}}{{#isContainer}}
|
||||
nillableDictionary["{{name}}"] = self.{{name}}{{^required}}?{{/required}}.encode(){{/isContainer}}{{/vars}}
|
||||
nillableDictionary["{{name}}"] = self.{{name}}{{^unwrapRequired}}?{{/unwrapRequired}}{{#unwrapRequired}}{{^required}}?{{/required}}{{/unwrapRequired}}.rawValue{{/isEnum}}{{^isPrimitiveType}}
|
||||
nillableDictionary["{{name}}"] = self.{{name}}{{^unwrapRequired}}?{{/unwrapRequired}}{{#unwrapRequired}}{{^required}}?{{/required}}{{/unwrapRequired}}.encodeToJSON(){{/isPrimitiveType}}{{/isNotContainer}}{{#isContainer}}
|
||||
nillableDictionary["{{name}}"] = self.{{name}}{{^unwrapRequired}}?{{/unwrapRequired}}{{#unwrapRequired}}{{^required}}?{{/required}}{{/unwrapRequired}}.encodeToJSON(){{/isContainer}}{{/vars}}
|
||||
let dictionary: [String:AnyObject] = APIHelper.rejectNil(nillableDictionary) ?? [:]
|
||||
return dictionary
|
||||
}
|
||||
|
||||
@@ -49,8 +49,8 @@ class TypeScriptAngularModelTest extends FlatSpec with Matchers {
|
||||
vars.get(1).isNotContainer should equal(true)
|
||||
|
||||
vars.get(2).baseName should be("createdAt")
|
||||
vars.get(2).complexType should be("DateTime")
|
||||
vars.get(2).datatype should be("DateTime")
|
||||
vars.get(2).complexType should be("Date")
|
||||
vars.get(2).datatype should be("Date")
|
||||
vars.get(2).name should be("createdAt")
|
||||
vars.get(2).defaultValue should be("null")
|
||||
vars.get(2).hasMore should equal(null)
|
||||
|
||||
@@ -49,8 +49,8 @@ class TypeScriptNodeModelTest extends FlatSpec with Matchers {
|
||||
vars.get(1).isNotContainer should equal(true)
|
||||
|
||||
vars.get(2).baseName should be("createdAt")
|
||||
vars.get(2).complexType should be("DateTime")
|
||||
vars.get(2).datatype should be("DateTime")
|
||||
vars.get(2).complexType should be("Date")
|
||||
vars.get(2).datatype should be("Date")
|
||||
vars.get(2).name should be("createdAt")
|
||||
vars.get(2).defaultValue should be("null")
|
||||
vars.get(2).hasMore should equal(null)
|
||||
|
||||
@@ -108,10 +108,10 @@ object PetApi {
|
||||
* Expected answers:
|
||||
* code 400 : (Invalid pet value)
|
||||
*
|
||||
* @param apiKey
|
||||
* @param petId Pet id to delete
|
||||
* @param apiKey
|
||||
*/
|
||||
def deletePet(apiKey: Option[String] = None, petId: Long): ApiRequest[Unit] =
|
||||
def deletePet(petId: Long, apiKey: Option[String] = None): ApiRequest[Unit] =
|
||||
ApiRequest[Unit](ApiMethods.DELETE, "http://petstore.swagger.io/v2", "/pet/{petId}", "application/json")
|
||||
.withPathParam("petId", petId)
|
||||
.withHeaderParam("api_key", apiKey)
|
||||
|
||||
@@ -23,6 +23,7 @@ import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
@@ -132,6 +133,62 @@ public class ApiInvoker {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Format to {@code Pair} objects.
|
||||
*/
|
||||
public static List<Pair> parameterToPairs(String collectionFormat, String name, Object value){
|
||||
List<Pair> params = new ArrayList<Pair>();
|
||||
|
||||
// preconditions
|
||||
if (name == null || name.isEmpty() || value == null) return params;
|
||||
|
||||
Collection valueCollection = null;
|
||||
if (value instanceof Collection) {
|
||||
valueCollection = (Collection) value;
|
||||
} else {
|
||||
params.add(new Pair(name, parameterToString(value)));
|
||||
return params;
|
||||
}
|
||||
|
||||
if (valueCollection.isEmpty()){
|
||||
return params;
|
||||
}
|
||||
|
||||
// get the collection format
|
||||
collectionFormat = (collectionFormat == null || collectionFormat.isEmpty() ? "csv" : collectionFormat); // default: csv
|
||||
|
||||
// create the params based on the collection format
|
||||
if (collectionFormat.equals("multi")) {
|
||||
for (Object item : valueCollection) {
|
||||
params.add(new Pair(name, parameterToString(item)));
|
||||
}
|
||||
|
||||
return params;
|
||||
}
|
||||
|
||||
String delimiter = ",";
|
||||
|
||||
if (collectionFormat.equals("csv")) {
|
||||
delimiter = ",";
|
||||
} else if (collectionFormat.equals("ssv")) {
|
||||
delimiter = " ";
|
||||
} else if (collectionFormat.equals("tsv")) {
|
||||
delimiter = "\t";
|
||||
} else if (collectionFormat.equals("pipes")) {
|
||||
delimiter = "|";
|
||||
}
|
||||
|
||||
StringBuilder sb = new StringBuilder() ;
|
||||
for (Object item : valueCollection) {
|
||||
sb.append(delimiter);
|
||||
sb.append(parameterToString(item));
|
||||
}
|
||||
|
||||
params.add(new Pair(name, sb.substring(1)));
|
||||
|
||||
return params;
|
||||
}
|
||||
|
||||
public ApiInvoker() {
|
||||
initConnectionManager();
|
||||
}
|
||||
@@ -184,21 +241,24 @@ public class ApiInvoker {
|
||||
}
|
||||
}
|
||||
|
||||
public String invokeAPI(String host, String path, String method, Map<String, String> queryParams, Object body, Map<String, String> headerParams, Map<String, String> formParams, String contentType) throws ApiException {
|
||||
public String invokeAPI(String host, String path, String method, List<Pair> queryParams, Object body, Map<String, String> headerParams, Map<String, String> formParams, String contentType) throws ApiException {
|
||||
HttpClient client = getClient(host);
|
||||
|
||||
StringBuilder b = new StringBuilder();
|
||||
for(String key : queryParams.keySet()) {
|
||||
String value = queryParams.get(key);
|
||||
if (value != null){
|
||||
if(b.toString().length() == 0)
|
||||
b.append("?");
|
||||
else
|
||||
b.append("?");
|
||||
if (queryParams != null){
|
||||
for (Pair queryParam : queryParams){
|
||||
if (!queryParam.getName().isEmpty()) {
|
||||
b.append(escapeString(queryParam.getName()));
|
||||
b.append("=");
|
||||
b.append(escapeString(queryParam.getValue()));
|
||||
b.append("&");
|
||||
b.append(escapeString(key)).append("=").append(escapeString(value));
|
||||
}
|
||||
}
|
||||
}
|
||||
String url = host + path + b.toString();
|
||||
|
||||
String querystring = b.substring(0, b.length() - 1);
|
||||
String url = host + path + querystring;
|
||||
|
||||
HashMap<String, String> headers = new HashMap<String, String>();
|
||||
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
package io.swagger.client;
|
||||
|
||||
public class Pair {
|
||||
private String name = "";
|
||||
private String value = "";
|
||||
|
||||
public Pair(String name, String value) {
|
||||
setName(name);
|
||||
setValue(value);
|
||||
}
|
||||
|
||||
private void setName(String name) {
|
||||
if (!isValidString(name)) return;
|
||||
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
private void setValue(String value) {
|
||||
if (!isValidString(value)) return;
|
||||
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
private boolean isValidString(String arg) {
|
||||
if (arg == null) return false;
|
||||
if (arg.trim().isEmpty()) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package io.swagger.client.api;
|
||||
|
||||
import io.swagger.client.ApiException;
|
||||
import io.swagger.client.ApiInvoker;
|
||||
import io.swagger.client.Pair;
|
||||
|
||||
import io.swagger.client.model.*;
|
||||
|
||||
@@ -52,7 +53,7 @@ public class PetApi {
|
||||
String path = "/pet".replaceAll("\\{format\\}","json");
|
||||
|
||||
// query params
|
||||
Map<String, String> queryParams = new HashMap<String, String>();
|
||||
List<Pair> queryParams = new ArrayList<Pair>();
|
||||
// header params
|
||||
Map<String, String> headerParams = new HashMap<String, String>();
|
||||
// form params
|
||||
@@ -106,7 +107,7 @@ public class PetApi {
|
||||
String path = "/pet".replaceAll("\\{format\\}","json");
|
||||
|
||||
// query params
|
||||
Map<String, String> queryParams = new HashMap<String, String>();
|
||||
List<Pair> queryParams = new ArrayList<Pair>();
|
||||
// header params
|
||||
Map<String, String> headerParams = new HashMap<String, String>();
|
||||
// form params
|
||||
@@ -160,14 +161,14 @@ public class PetApi {
|
||||
String path = "/pet/findByStatus".replaceAll("\\{format\\}","json");
|
||||
|
||||
// query params
|
||||
Map<String, String> queryParams = new HashMap<String, String>();
|
||||
List<Pair> queryParams = new ArrayList<Pair>();
|
||||
// header params
|
||||
Map<String, String> headerParams = new HashMap<String, String>();
|
||||
// form params
|
||||
Map<String, String> formParams = new HashMap<String, String>();
|
||||
|
||||
if (status != null)
|
||||
queryParams.put("status", ApiInvoker.parameterToString(status));
|
||||
|
||||
queryParams.addAll(ApiInvoker.parameterToPairs("multi", "status", status));
|
||||
|
||||
|
||||
|
||||
@@ -216,14 +217,14 @@ public class PetApi {
|
||||
String path = "/pet/findByTags".replaceAll("\\{format\\}","json");
|
||||
|
||||
// query params
|
||||
Map<String, String> queryParams = new HashMap<String, String>();
|
||||
List<Pair> queryParams = new ArrayList<Pair>();
|
||||
// header params
|
||||
Map<String, String> headerParams = new HashMap<String, String>();
|
||||
// form params
|
||||
Map<String, String> formParams = new HashMap<String, String>();
|
||||
|
||||
if (tags != null)
|
||||
queryParams.put("tags", ApiInvoker.parameterToString(tags));
|
||||
|
||||
queryParams.addAll(ApiInvoker.parameterToPairs("multi", "tags", tags));
|
||||
|
||||
|
||||
|
||||
@@ -277,7 +278,7 @@ public class PetApi {
|
||||
String path = "/pet/{petId}".replaceAll("\\{format\\}","json").replaceAll("\\{" + "petId" + "\\}", apiInvoker.escapeString(petId.toString()));
|
||||
|
||||
// query params
|
||||
Map<String, String> queryParams = new HashMap<String, String>();
|
||||
List<Pair> queryParams = new ArrayList<Pair>();
|
||||
// header params
|
||||
Map<String, String> headerParams = new HashMap<String, String>();
|
||||
// form params
|
||||
@@ -338,7 +339,7 @@ public class PetApi {
|
||||
String path = "/pet/{petId}".replaceAll("\\{format\\}","json").replaceAll("\\{" + "petId" + "\\}", apiInvoker.escapeString(petId.toString()));
|
||||
|
||||
// query params
|
||||
Map<String, String> queryParams = new HashMap<String, String>();
|
||||
List<Pair> queryParams = new ArrayList<Pair>();
|
||||
// header params
|
||||
Map<String, String> headerParams = new HashMap<String, String>();
|
||||
// form params
|
||||
@@ -391,11 +392,11 @@ public class PetApi {
|
||||
/**
|
||||
* Deletes a pet
|
||||
*
|
||||
* @param apiKey
|
||||
* @param petId Pet id to delete
|
||||
* @param apiKey
|
||||
* @return void
|
||||
*/
|
||||
public void deletePet (String apiKey, Long petId) throws ApiException {
|
||||
public void deletePet (Long petId, String apiKey) throws ApiException {
|
||||
Object postBody = null;
|
||||
|
||||
// verify the required parameter 'petId' is set
|
||||
@@ -408,7 +409,7 @@ public class PetApi {
|
||||
String path = "/pet/{petId}".replaceAll("\\{format\\}","json").replaceAll("\\{" + "petId" + "\\}", apiInvoker.escapeString(petId.toString()));
|
||||
|
||||
// query params
|
||||
Map<String, String> queryParams = new HashMap<String, String>();
|
||||
List<Pair> queryParams = new ArrayList<Pair>();
|
||||
// header params
|
||||
Map<String, String> headerParams = new HashMap<String, String>();
|
||||
// form params
|
||||
@@ -416,6 +417,7 @@ public class PetApi {
|
||||
|
||||
|
||||
|
||||
|
||||
headerParams.put("api_key", ApiInvoker.parameterToString(apiKey));
|
||||
|
||||
|
||||
@@ -470,7 +472,7 @@ public class PetApi {
|
||||
String path = "/pet/{petId}/uploadImage".replaceAll("\\{format\\}","json").replaceAll("\\{" + "petId" + "\\}", apiInvoker.escapeString(petId.toString()));
|
||||
|
||||
// query params
|
||||
Map<String, String> queryParams = new HashMap<String, String>();
|
||||
List<Pair> queryParams = new ArrayList<Pair>();
|
||||
// header params
|
||||
Map<String, String> headerParams = new HashMap<String, String>();
|
||||
// form params
|
||||
|
||||
@@ -2,6 +2,7 @@ package io.swagger.client.api;
|
||||
|
||||
import io.swagger.client.ApiException;
|
||||
import io.swagger.client.ApiInvoker;
|
||||
import io.swagger.client.Pair;
|
||||
|
||||
import io.swagger.client.model.*;
|
||||
|
||||
@@ -51,7 +52,7 @@ public class StoreApi {
|
||||
String path = "/store/inventory".replaceAll("\\{format\\}","json");
|
||||
|
||||
// query params
|
||||
Map<String, String> queryParams = new HashMap<String, String>();
|
||||
List<Pair> queryParams = new ArrayList<Pair>();
|
||||
// header params
|
||||
Map<String, String> headerParams = new HashMap<String, String>();
|
||||
// form params
|
||||
@@ -105,7 +106,7 @@ public class StoreApi {
|
||||
String path = "/store/order".replaceAll("\\{format\\}","json");
|
||||
|
||||
// query params
|
||||
Map<String, String> queryParams = new HashMap<String, String>();
|
||||
List<Pair> queryParams = new ArrayList<Pair>();
|
||||
// header params
|
||||
Map<String, String> headerParams = new HashMap<String, String>();
|
||||
// form params
|
||||
@@ -164,7 +165,7 @@ public class StoreApi {
|
||||
String path = "/store/order/{orderId}".replaceAll("\\{format\\}","json").replaceAll("\\{" + "orderId" + "\\}", apiInvoker.escapeString(orderId.toString()));
|
||||
|
||||
// query params
|
||||
Map<String, String> queryParams = new HashMap<String, String>();
|
||||
List<Pair> queryParams = new ArrayList<Pair>();
|
||||
// header params
|
||||
Map<String, String> headerParams = new HashMap<String, String>();
|
||||
// form params
|
||||
@@ -223,7 +224,7 @@ public class StoreApi {
|
||||
String path = "/store/order/{orderId}".replaceAll("\\{format\\}","json").replaceAll("\\{" + "orderId" + "\\}", apiInvoker.escapeString(orderId.toString()));
|
||||
|
||||
// query params
|
||||
Map<String, String> queryParams = new HashMap<String, String>();
|
||||
List<Pair> queryParams = new ArrayList<Pair>();
|
||||
// header params
|
||||
Map<String, String> headerParams = new HashMap<String, String>();
|
||||
// form params
|
||||
|
||||
@@ -2,6 +2,7 @@ package io.swagger.client.api;
|
||||
|
||||
import io.swagger.client.ApiException;
|
||||
import io.swagger.client.ApiInvoker;
|
||||
import io.swagger.client.Pair;
|
||||
|
||||
import io.swagger.client.model.*;
|
||||
|
||||
@@ -52,7 +53,7 @@ public class UserApi {
|
||||
String path = "/user".replaceAll("\\{format\\}","json");
|
||||
|
||||
// query params
|
||||
Map<String, String> queryParams = new HashMap<String, String>();
|
||||
List<Pair> queryParams = new ArrayList<Pair>();
|
||||
// header params
|
||||
Map<String, String> headerParams = new HashMap<String, String>();
|
||||
// form params
|
||||
@@ -106,7 +107,7 @@ public class UserApi {
|
||||
String path = "/user/createWithArray".replaceAll("\\{format\\}","json");
|
||||
|
||||
// query params
|
||||
Map<String, String> queryParams = new HashMap<String, String>();
|
||||
List<Pair> queryParams = new ArrayList<Pair>();
|
||||
// header params
|
||||
Map<String, String> headerParams = new HashMap<String, String>();
|
||||
// form params
|
||||
@@ -160,7 +161,7 @@ public class UserApi {
|
||||
String path = "/user/createWithList".replaceAll("\\{format\\}","json");
|
||||
|
||||
// query params
|
||||
Map<String, String> queryParams = new HashMap<String, String>();
|
||||
List<Pair> queryParams = new ArrayList<Pair>();
|
||||
// header params
|
||||
Map<String, String> headerParams = new HashMap<String, String>();
|
||||
// form params
|
||||
@@ -215,16 +216,16 @@ public class UserApi {
|
||||
String path = "/user/login".replaceAll("\\{format\\}","json");
|
||||
|
||||
// query params
|
||||
Map<String, String> queryParams = new HashMap<String, String>();
|
||||
List<Pair> queryParams = new ArrayList<Pair>();
|
||||
// header params
|
||||
Map<String, String> headerParams = new HashMap<String, String>();
|
||||
// form params
|
||||
Map<String, String> formParams = new HashMap<String, String>();
|
||||
|
||||
if (username != null)
|
||||
queryParams.put("username", ApiInvoker.parameterToString(username));
|
||||
if (password != null)
|
||||
queryParams.put("password", ApiInvoker.parameterToString(password));
|
||||
|
||||
queryParams.addAll(ApiInvoker.parameterToPairs("", "username", username));
|
||||
|
||||
queryParams.addAll(ApiInvoker.parameterToPairs("", "password", password));
|
||||
|
||||
|
||||
|
||||
@@ -272,7 +273,7 @@ public class UserApi {
|
||||
String path = "/user/logout".replaceAll("\\{format\\}","json");
|
||||
|
||||
// query params
|
||||
Map<String, String> queryParams = new HashMap<String, String>();
|
||||
List<Pair> queryParams = new ArrayList<Pair>();
|
||||
// header params
|
||||
Map<String, String> headerParams = new HashMap<String, String>();
|
||||
// form params
|
||||
@@ -331,7 +332,7 @@ public class UserApi {
|
||||
String path = "/user/{username}".replaceAll("\\{format\\}","json").replaceAll("\\{" + "username" + "\\}", apiInvoker.escapeString(username.toString()));
|
||||
|
||||
// query params
|
||||
Map<String, String> queryParams = new HashMap<String, String>();
|
||||
List<Pair> queryParams = new ArrayList<Pair>();
|
||||
// header params
|
||||
Map<String, String> headerParams = new HashMap<String, String>();
|
||||
// form params
|
||||
@@ -391,7 +392,7 @@ public class UserApi {
|
||||
String path = "/user/{username}".replaceAll("\\{format\\}","json").replaceAll("\\{" + "username" + "\\}", apiInvoker.escapeString(username.toString()));
|
||||
|
||||
// query params
|
||||
Map<String, String> queryParams = new HashMap<String, String>();
|
||||
List<Pair> queryParams = new ArrayList<Pair>();
|
||||
// header params
|
||||
Map<String, String> headerParams = new HashMap<String, String>();
|
||||
// form params
|
||||
@@ -450,7 +451,7 @@ public class UserApi {
|
||||
String path = "/user/{username}".replaceAll("\\{format\\}","json").replaceAll("\\{" + "username" + "\\}", apiInvoker.escapeString(username.toString()));
|
||||
|
||||
// query params
|
||||
Map<String, String> queryParams = new HashMap<String, String>();
|
||||
List<Pair> queryParams = new ArrayList<Pair>();
|
||||
// header params
|
||||
Map<String, String> headerParams = new HashMap<String, String>();
|
||||
// form params
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package io.swagger.client.model;
|
||||
|
||||
import io.swagger.client.model.Category;
|
||||
import java.util.*;
|
||||
import io.swagger.client.model.Tag;
|
||||
import java.util.*;
|
||||
|
||||
import io.swagger.annotations.*;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
package io.swagger.client;
|
||||
|
||||
import org.junit.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
||||
public class ApiInvokerTest {
|
||||
|
||||
@Test
|
||||
public void testParameterToPairsWhenNameIsInvalid() throws Exception {
|
||||
List<Pair> pairs_a = ApiInvoker.parameterToPairs("csv", null, new Integer(1));
|
||||
List<Pair> pairs_b = ApiInvoker.parameterToPairs("csv", "", new Integer(1));
|
||||
|
||||
assertTrue(pairs_a.isEmpty());
|
||||
assertTrue(pairs_b.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParameterToPairsWhenValueIsNull() throws Exception {
|
||||
List<Pair> pairs = ApiInvoker.parameterToPairs("csv", "param-a", null);
|
||||
|
||||
assertTrue(pairs.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParameterToPairsWhenValueIsEmptyStrings() throws Exception {
|
||||
|
||||
// single empty string
|
||||
List<Pair> pairs = ApiInvoker.parameterToPairs("csv", "param-a", " ");
|
||||
assertEquals(1, pairs.size());
|
||||
|
||||
// list of empty strings
|
||||
List<String> strs = new ArrayList<String>();
|
||||
strs.add(" ");
|
||||
strs.add(" ");
|
||||
strs.add(" ");
|
||||
|
||||
List<Pair> concatStrings = ApiInvoker.parameterToPairs("csv", "param-a", strs);
|
||||
|
||||
assertEquals(1, concatStrings.size());
|
||||
assertFalse(concatStrings.get(0).getValue().isEmpty()); // should contain some delimiters
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParameterToPairsWhenValueIsNotCollection() throws Exception {
|
||||
String name = "param-a";
|
||||
Integer value = 1;
|
||||
|
||||
List<Pair> pairs = ApiInvoker.parameterToPairs("csv", name, value);
|
||||
|
||||
assertEquals(1, pairs.size());
|
||||
assertEquals(value, Integer.valueOf(pairs.get(0).getValue()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParameterToPairsWhenValueIsCollection() throws Exception {
|
||||
Map<String, String> collectionFormatMap = new HashMap<String, String>();
|
||||
collectionFormatMap.put("csv", ",");
|
||||
collectionFormatMap.put("tsv", "\t");
|
||||
collectionFormatMap.put("ssv", " ");
|
||||
collectionFormatMap.put("pipes", "\\|");
|
||||
collectionFormatMap.put("", ","); // no format, must default to csv
|
||||
collectionFormatMap.put("unknown", ","); // all other formats, must default to csv
|
||||
|
||||
String name = "param-a";
|
||||
|
||||
List<Object> values = new ArrayList<Object>();
|
||||
values.add("value-a");
|
||||
values.add(123);
|
||||
values.add(new Date());
|
||||
|
||||
// check for multi separately
|
||||
List<Pair> multiPairs = ApiInvoker.parameterToPairs("multi", name, values);
|
||||
assertEquals(values.size(), multiPairs.size());
|
||||
|
||||
// all other formats
|
||||
for (String collectionFormat : collectionFormatMap.keySet()) {
|
||||
List<Pair> pairs = ApiInvoker.parameterToPairs(collectionFormat, name, values);
|
||||
|
||||
assertEquals(1, pairs.size());
|
||||
|
||||
String delimiter = collectionFormatMap.get(collectionFormat);
|
||||
String[] pairValueSplit = pairs.get(0).getValue().split(delimiter);
|
||||
|
||||
// must equal input values
|
||||
assertEquals(values.size(), pairValueSplit.length);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -118,7 +118,7 @@ public class PetApiTest {
|
||||
api.addPet(pet);
|
||||
|
||||
Pet fetched = api.getPetById(pet.getId());
|
||||
api.deletePet(null, fetched.getId());
|
||||
api.deletePet(fetched.getId(), null);
|
||||
|
||||
try {
|
||||
fetched = api.getPetById(fetched.getId());
|
||||
|
||||
@@ -3,10 +3,10 @@ organization := ""
|
||||
name := "-client"
|
||||
|
||||
libraryDependencies ++= Seq(
|
||||
"com.wordnik" %% "swagger-async-httpclient" % "0.3.5",
|
||||
"joda-time" % "joda-time" % "2.3",
|
||||
"org.joda" % "joda-convert" % "1.3.1",
|
||||
"ch.qos.logback" % "logback-classic" % "1.0.13" % "provided",
|
||||
"org.scalatest" %% "scalatest" % "2.2.1" % "test",
|
||||
"junit" % "junit" % "4.11" % "test"
|
||||
"io.swagger" %% "swagger-async-httpclient" % "0.3.5",
|
||||
"joda-time" % "joda-time" % "2.3",
|
||||
"org.joda" % "joda-convert" % "1.3.1",
|
||||
"ch.qos.logback" % "logback-classic" % "1.0.13" % "provided",
|
||||
"org.scalatest" %% "scalatest" % "2.2.1" % "test",
|
||||
"junit" % "junit" % "4.11" % "test"
|
||||
)
|
||||
|
||||
@@ -7,21 +7,21 @@ import io.swagger.client._
|
||||
import java.io.Closeable
|
||||
|
||||
class SwaggerClient(config: SwaggerConfig) extends Closeable {
|
||||
val locator = config.locator
|
||||
val name = config.name
|
||||
val locator = config.locator
|
||||
val name = config.name
|
||||
|
||||
private[this] val client = transportClient
|
||||
private[this] val client = transportClient
|
||||
|
||||
protected def transportClient: TransportClient = new RestClient(config)
|
||||
protected def transportClient: TransportClient = new RestClient(config)
|
||||
|
||||
val user = new UserApi(client, config)
|
||||
|
||||
val pet = new PetApi(client, config)
|
||||
|
||||
val store = new StoreApi(client, config)
|
||||
|
||||
|
||||
val user = new UserApi(client, config)
|
||||
|
||||
val pet = new PetApi(client, config)
|
||||
|
||||
val store = new StoreApi(client, config)
|
||||
|
||||
|
||||
def close() {
|
||||
client.close()
|
||||
}
|
||||
def close() {
|
||||
client.close()
|
||||
}
|
||||
}
|
||||
@@ -7,187 +7,191 @@ import scala.concurrent.{ Future, Await }
|
||||
import scala.concurrent.duration._
|
||||
import collection.mutable
|
||||
|
||||
class PetApi(client: TransportClient, config: SwaggerConfig) extends ApiClient(client, config) {
|
||||
class PetApi(client: TransportClient, config: SwaggerConfig) extends ApiClient(client, config) {
|
||||
|
||||
|
||||
def updatePet(body: Pet)(implicit reader: ClientResponseReader[Unit], writer: RequestWriter[Pet]): Future[Unit] = {
|
||||
// create path and map variables
|
||||
val path = (addFmt("/pet"))
|
||||
|
||||
def updatePet(body: Option[Pet] = None
|
||||
)(implicit reader: ClientResponseReader[Unit], writer: RequestWriter[Pet]): Future[Unit] = {
|
||||
// create path and map variables
|
||||
val path = (addFmt("/pet"))
|
||||
|
||||
// query params
|
||||
val queryParams = new mutable.HashMap[String, String]
|
||||
val headerParams = new mutable.HashMap[String, String]
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
val resFuture = client.submit("PUT", path, queryParams.toMap, headerParams.toMap, writer.write(body))
|
||||
resFuture flatMap { resp =>
|
||||
process(reader.read(resp))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
def addPet(body: Pet)(implicit reader: ClientResponseReader[Unit], writer: RequestWriter[Pet]): Future[Unit] = {
|
||||
// create path and map variables
|
||||
val path = (addFmt("/pet"))
|
||||
|
||||
// query params
|
||||
val queryParams = new mutable.HashMap[String, String]
|
||||
val headerParams = new mutable.HashMap[String, String]
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
val resFuture = client.submit("POST", path, queryParams.toMap, headerParams.toMap, writer.write(body))
|
||||
resFuture flatMap { resp =>
|
||||
process(reader.read(resp))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
def findPetsByStatus(status: List[String] = available)(implicit reader: ClientResponseReader[List[Pet]]): Future[List[Pet]] = {
|
||||
// create path and map variables
|
||||
val path = (addFmt("/pet/findByStatus"))
|
||||
|
||||
// query params
|
||||
val queryParams = new mutable.HashMap[String, String]
|
||||
val headerParams = new mutable.HashMap[String, String]
|
||||
|
||||
|
||||
|
||||
|
||||
if(status != null) queryParams += "status" -> status.toString
|
||||
|
||||
|
||||
|
||||
val resFuture = client.submit("GET", path, queryParams.toMap, headerParams.toMap, "")
|
||||
resFuture flatMap { resp =>
|
||||
process(reader.read(resp))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
def findPetsByTags(tags: List[String])(implicit reader: ClientResponseReader[List[Pet]]): Future[List[Pet]] = {
|
||||
// create path and map variables
|
||||
val path = (addFmt("/pet/findByTags"))
|
||||
|
||||
// query params
|
||||
val queryParams = new mutable.HashMap[String, String]
|
||||
val headerParams = new mutable.HashMap[String, String]
|
||||
|
||||
|
||||
|
||||
|
||||
if(tags != null) queryParams += "tags" -> tags.toString
|
||||
|
||||
|
||||
|
||||
val resFuture = client.submit("GET", path, queryParams.toMap, headerParams.toMap, "")
|
||||
resFuture flatMap { resp =>
|
||||
process(reader.read(resp))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
def getPetById(petId: Long)(implicit reader: ClientResponseReader[Pet]): Future[Pet] = {
|
||||
// create path and map variables
|
||||
val path = (addFmt("/pet/{petId}")
|
||||
replaceAll ("\\{" + "petId" + "\\}",petId.toString))
|
||||
|
||||
// query params
|
||||
val queryParams = new mutable.HashMap[String, String]
|
||||
val headerParams = new mutable.HashMap[String, String]
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
val resFuture = client.submit("GET", path, queryParams.toMap, headerParams.toMap, "")
|
||||
resFuture flatMap { resp =>
|
||||
process(reader.read(resp))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
def updatePetWithForm(petId: String,
|
||||
name: String,
|
||||
status: String)(implicit reader: ClientResponseReader[Unit]): Future[Unit] = {
|
||||
// create path and map variables
|
||||
val path = (addFmt("/pet/{petId}")
|
||||
replaceAll ("\\{" + "petId" + "\\}",petId.toString))
|
||||
|
||||
// query params
|
||||
val queryParams = new mutable.HashMap[String, String]
|
||||
val headerParams = new mutable.HashMap[String, String]
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
val resFuture = client.submit("POST", path, queryParams.toMap, headerParams.toMap, "")
|
||||
resFuture flatMap { resp =>
|
||||
process(reader.read(resp))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
def deletePet(apiKey: String,
|
||||
petId: Long)(implicit reader: ClientResponseReader[Unit]): Future[Unit] = {
|
||||
// create path and map variables
|
||||
val path = (addFmt("/pet/{petId}")
|
||||
replaceAll ("\\{" + "petId" + "\\}",petId.toString))
|
||||
|
||||
// query params
|
||||
val queryParams = new mutable.HashMap[String, String]
|
||||
val headerParams = new mutable.HashMap[String, String]
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
headerParams += "api_key" -> apiKey.toString
|
||||
|
||||
val resFuture = client.submit("DELETE", path, queryParams.toMap, headerParams.toMap, "")
|
||||
resFuture flatMap { resp =>
|
||||
process(reader.read(resp))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
def uploadFile(petId: Long,
|
||||
additionalMetadata: String,
|
||||
file: File)(implicit reader: ClientResponseReader[Unit]): Future[Unit] = {
|
||||
// create path and map variables
|
||||
val path = (addFmt("/pet/{petId}/uploadImage")
|
||||
replaceAll ("\\{" + "petId" + "\\}",petId.toString))
|
||||
|
||||
// query params
|
||||
val queryParams = new mutable.HashMap[String, String]
|
||||
val headerParams = new mutable.HashMap[String, String]
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
val resFuture = client.submit("POST", path, queryParams.toMap, headerParams.toMap, "")
|
||||
resFuture flatMap { resp =>
|
||||
process(reader.read(resp))
|
||||
}
|
||||
}
|
||||
// query params
|
||||
val queryParams = new mutable.HashMap[String, String]
|
||||
val headerParams = new mutable.HashMap[String, String]
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
val resFuture = client.submit("PUT", path, queryParams.toMap, headerParams.toMap, writer.write(body))
|
||||
resFuture flatMap { resp =>
|
||||
process(reader.read(resp))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
def addPet(body: Option[Pet] = None
|
||||
)(implicit reader: ClientResponseReader[Unit], writer: RequestWriter[Pet]): Future[Unit] = {
|
||||
// create path and map variables
|
||||
val path = (addFmt("/pet"))
|
||||
|
||||
// query params
|
||||
val queryParams = new mutable.HashMap[String, String]
|
||||
val headerParams = new mutable.HashMap[String, String]
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
val resFuture = client.submit("POST", path, queryParams.toMap, headerParams.toMap, writer.write(body))
|
||||
resFuture flatMap { resp =>
|
||||
process(reader.read(resp))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
def findPetsByStatus(status: Option[List[String]] = Some(available)
|
||||
)(implicit reader: ClientResponseReader[List[Pet]]): Future[List[Pet]] = {
|
||||
// create path and map variables
|
||||
val path = (addFmt("/pet/findByStatus"))
|
||||
|
||||
// query params
|
||||
val queryParams = new mutable.HashMap[String, String]
|
||||
val headerParams = new mutable.HashMap[String, String]
|
||||
|
||||
|
||||
|
||||
if(status != null) status.foreach { v => queryParams += "status" -> v.toString }
|
||||
|
||||
|
||||
|
||||
val resFuture = client.submit("GET", path, queryParams.toMap, headerParams.toMap, "")
|
||||
resFuture flatMap { resp =>
|
||||
process(reader.read(resp))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
def findPetsByTags(tags: Option[List[String]] = None
|
||||
)(implicit reader: ClientResponseReader[List[Pet]]): Future[List[Pet]] = {
|
||||
// create path and map variables
|
||||
val path = (addFmt("/pet/findByTags"))
|
||||
|
||||
// query params
|
||||
val queryParams = new mutable.HashMap[String, String]
|
||||
val headerParams = new mutable.HashMap[String, String]
|
||||
|
||||
|
||||
|
||||
if(tags != null) tags.foreach { v => queryParams += "tags" -> v.toString }
|
||||
|
||||
|
||||
|
||||
val resFuture = client.submit("GET", path, queryParams.toMap, headerParams.toMap, "")
|
||||
resFuture flatMap { resp =>
|
||||
process(reader.read(resp))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
def getPetById(petId: Long)(implicit reader: ClientResponseReader[Pet]): Future[Pet] = {
|
||||
// create path and map variables
|
||||
val path = (addFmt("/pet/{petId}")
|
||||
replaceAll ("\\{" + "petId" + "\\}",petId.toString))
|
||||
|
||||
// query params
|
||||
val queryParams = new mutable.HashMap[String, String]
|
||||
val headerParams = new mutable.HashMap[String, String]
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
val resFuture = client.submit("GET", path, queryParams.toMap, headerParams.toMap, "")
|
||||
resFuture flatMap { resp =>
|
||||
process(reader.read(resp))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
def updatePetWithForm(petId: String,
|
||||
name: Option[String] = None,
|
||||
status: Option[String] = None
|
||||
)(implicit reader: ClientResponseReader[Unit]): Future[Unit] = {
|
||||
// create path and map variables
|
||||
val path = (addFmt("/pet/{petId}")
|
||||
replaceAll ("\\{" + "petId" + "\\}",petId.toString))
|
||||
|
||||
// query params
|
||||
val queryParams = new mutable.HashMap[String, String]
|
||||
val headerParams = new mutable.HashMap[String, String]
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
val resFuture = client.submit("POST", path, queryParams.toMap, headerParams.toMap, "")
|
||||
resFuture flatMap { resp =>
|
||||
process(reader.read(resp))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
def deletePet(apiKey: Option[String] = None,
|
||||
petId: Long)(implicit reader: ClientResponseReader[Unit]): Future[Unit] = {
|
||||
// create path and map variables
|
||||
val path = (addFmt("/pet/{petId}")
|
||||
replaceAll ("\\{" + "petId" + "\\}",petId.toString))
|
||||
|
||||
// query params
|
||||
val queryParams = new mutable.HashMap[String, String]
|
||||
val headerParams = new mutable.HashMap[String, String]
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
headerParams += "api_key" -> apiKey.toString
|
||||
|
||||
val resFuture = client.submit("DELETE", path, queryParams.toMap, headerParams.toMap, "")
|
||||
resFuture flatMap { resp =>
|
||||
process(reader.read(resp))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
def uploadFile(petId: Long,
|
||||
additionalMetadata: Option[String] = None,
|
||||
file: Option[File] = None
|
||||
)(implicit reader: ClientResponseReader[Unit]): Future[Unit] = {
|
||||
// create path and map variables
|
||||
val path = (addFmt("/pet/{petId}/uploadImage")
|
||||
replaceAll ("\\{" + "petId" + "\\}",petId.toString))
|
||||
|
||||
// query params
|
||||
val queryParams = new mutable.HashMap[String, String]
|
||||
val headerParams = new mutable.HashMap[String, String]
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
val resFuture = client.submit("POST", path, queryParams.toMap, headerParams.toMap, "")
|
||||
resFuture flatMap { resp =>
|
||||
process(reader.read(resp))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -6,94 +6,95 @@ import scala.concurrent.{ Future, Await }
|
||||
import scala.concurrent.duration._
|
||||
import collection.mutable
|
||||
|
||||
class StoreApi(client: TransportClient, config: SwaggerConfig) extends ApiClient(client, config) {
|
||||
class StoreApi(client: TransportClient, config: SwaggerConfig) extends ApiClient(client, config) {
|
||||
|
||||
|
||||
def getInventory()(implicit reader: ClientResponseReader[Map[String, Integer]]): Future[Map[String, Integer]] = {
|
||||
// create path and map variables
|
||||
val path = (addFmt("/store/inventory"))
|
||||
|
||||
def getInventory()(implicit reader: ClientResponseReader[Map[String, Integer]]): Future[Map[String, Integer]] = {
|
||||
// create path and map variables
|
||||
val path = (addFmt("/store/inventory"))
|
||||
|
||||
// query params
|
||||
val queryParams = new mutable.HashMap[String, String]
|
||||
val headerParams = new mutable.HashMap[String, String]
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
val resFuture = client.submit("GET", path, queryParams.toMap, headerParams.toMap, "")
|
||||
resFuture flatMap { resp =>
|
||||
process(reader.read(resp))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
def placeOrder(body: Order)(implicit reader: ClientResponseReader[Order], writer: RequestWriter[Order]): Future[Order] = {
|
||||
// create path and map variables
|
||||
val path = (addFmt("/store/order"))
|
||||
|
||||
// query params
|
||||
val queryParams = new mutable.HashMap[String, String]
|
||||
val headerParams = new mutable.HashMap[String, String]
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
val resFuture = client.submit("POST", path, queryParams.toMap, headerParams.toMap, writer.write(body))
|
||||
resFuture flatMap { resp =>
|
||||
process(reader.read(resp))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
def getOrderById(orderId: String)(implicit reader: ClientResponseReader[Order]): Future[Order] = {
|
||||
// create path and map variables
|
||||
val path = (addFmt("/store/order/{orderId}")
|
||||
replaceAll ("\\{" + "orderId" + "\\}",orderId.toString))
|
||||
|
||||
// query params
|
||||
val queryParams = new mutable.HashMap[String, String]
|
||||
val headerParams = new mutable.HashMap[String, String]
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
val resFuture = client.submit("GET", path, queryParams.toMap, headerParams.toMap, "")
|
||||
resFuture flatMap { resp =>
|
||||
process(reader.read(resp))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
def deleteOrder(orderId: String)(implicit reader: ClientResponseReader[Unit]): Future[Unit] = {
|
||||
// create path and map variables
|
||||
val path = (addFmt("/store/order/{orderId}")
|
||||
replaceAll ("\\{" + "orderId" + "\\}",orderId.toString))
|
||||
|
||||
// query params
|
||||
val queryParams = new mutable.HashMap[String, String]
|
||||
val headerParams = new mutable.HashMap[String, String]
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
val resFuture = client.submit("DELETE", path, queryParams.toMap, headerParams.toMap, "")
|
||||
resFuture flatMap { resp =>
|
||||
process(reader.read(resp))
|
||||
}
|
||||
}
|
||||
// query params
|
||||
val queryParams = new mutable.HashMap[String, String]
|
||||
val headerParams = new mutable.HashMap[String, String]
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
val resFuture = client.submit("GET", path, queryParams.toMap, headerParams.toMap, "")
|
||||
resFuture flatMap { resp =>
|
||||
process(reader.read(resp))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
def placeOrder(body: Option[Order] = None
|
||||
)(implicit reader: ClientResponseReader[Order], writer: RequestWriter[Order]): Future[Order] = {
|
||||
// create path and map variables
|
||||
val path = (addFmt("/store/order"))
|
||||
|
||||
// query params
|
||||
val queryParams = new mutable.HashMap[String, String]
|
||||
val headerParams = new mutable.HashMap[String, String]
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
val resFuture = client.submit("POST", path, queryParams.toMap, headerParams.toMap, writer.write(body))
|
||||
resFuture flatMap { resp =>
|
||||
process(reader.read(resp))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
def getOrderById(orderId: String)(implicit reader: ClientResponseReader[Order]): Future[Order] = {
|
||||
// create path and map variables
|
||||
val path = (addFmt("/store/order/{orderId}")
|
||||
replaceAll ("\\{" + "orderId" + "\\}",orderId.toString))
|
||||
|
||||
// query params
|
||||
val queryParams = new mutable.HashMap[String, String]
|
||||
val headerParams = new mutable.HashMap[String, String]
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
val resFuture = client.submit("GET", path, queryParams.toMap, headerParams.toMap, "")
|
||||
resFuture flatMap { resp =>
|
||||
process(reader.read(resp))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
def deleteOrder(orderId: String)(implicit reader: ClientResponseReader[Unit]): Future[Unit] = {
|
||||
// create path and map variables
|
||||
val path = (addFmt("/store/order/{orderId}")
|
||||
replaceAll ("\\{" + "orderId" + "\\}",orderId.toString))
|
||||
|
||||
// query params
|
||||
val queryParams = new mutable.HashMap[String, String]
|
||||
val headerParams = new mutable.HashMap[String, String]
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
val resFuture = client.submit("DELETE", path, queryParams.toMap, headerParams.toMap, "")
|
||||
resFuture flatMap { resp =>
|
||||
process(reader.read(resp))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -6,183 +6,186 @@ import scala.concurrent.{ Future, Await }
|
||||
import scala.concurrent.duration._
|
||||
import collection.mutable
|
||||
|
||||
class UserApi(client: TransportClient, config: SwaggerConfig) extends ApiClient(client, config) {
|
||||
class UserApi(client: TransportClient, config: SwaggerConfig) extends ApiClient(client, config) {
|
||||
|
||||
|
||||
def createUser(body: User)(implicit reader: ClientResponseReader[Unit], writer: RequestWriter[User]): Future[Unit] = {
|
||||
// create path and map variables
|
||||
val path = (addFmt("/user"))
|
||||
|
||||
def createUser(body: Option[User] = None
|
||||
)(implicit reader: ClientResponseReader[Unit], writer: RequestWriter[User]): Future[Unit] = {
|
||||
// create path and map variables
|
||||
val path = (addFmt("/user"))
|
||||
|
||||
// query params
|
||||
val queryParams = new mutable.HashMap[String, String]
|
||||
val headerParams = new mutable.HashMap[String, String]
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
val resFuture = client.submit("POST", path, queryParams.toMap, headerParams.toMap, writer.write(body))
|
||||
resFuture flatMap { resp =>
|
||||
process(reader.read(resp))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
def createUsersWithArrayInput(body: List[User])(implicit reader: ClientResponseReader[Unit], writer: RequestWriter[List[User]]): Future[Unit] = {
|
||||
// create path and map variables
|
||||
val path = (addFmt("/user/createWithArray"))
|
||||
|
||||
// query params
|
||||
val queryParams = new mutable.HashMap[String, String]
|
||||
val headerParams = new mutable.HashMap[String, String]
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
val resFuture = client.submit("POST", path, queryParams.toMap, headerParams.toMap, writer.write(body))
|
||||
resFuture flatMap { resp =>
|
||||
process(reader.read(resp))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
def createUsersWithListInput(body: List[User])(implicit reader: ClientResponseReader[Unit], writer: RequestWriter[List[User]]): Future[Unit] = {
|
||||
// create path and map variables
|
||||
val path = (addFmt("/user/createWithList"))
|
||||
|
||||
// query params
|
||||
val queryParams = new mutable.HashMap[String, String]
|
||||
val headerParams = new mutable.HashMap[String, String]
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
val resFuture = client.submit("POST", path, queryParams.toMap, headerParams.toMap, writer.write(body))
|
||||
resFuture flatMap { resp =>
|
||||
process(reader.read(resp))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
def loginUser(username: String,
|
||||
password: String)(implicit reader: ClientResponseReader[String]): Future[String] = {
|
||||
// create path and map variables
|
||||
val path = (addFmt("/user/login"))
|
||||
|
||||
// query params
|
||||
val queryParams = new mutable.HashMap[String, String]
|
||||
val headerParams = new mutable.HashMap[String, String]
|
||||
|
||||
|
||||
|
||||
|
||||
if(username != null) queryParams += "username" -> username.toString
|
||||
if(password != null) queryParams += "password" -> password.toString
|
||||
|
||||
|
||||
|
||||
val resFuture = client.submit("GET", path, queryParams.toMap, headerParams.toMap, "")
|
||||
resFuture flatMap { resp =>
|
||||
process(reader.read(resp))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
def logoutUser()(implicit reader: ClientResponseReader[Unit]): Future[Unit] = {
|
||||
// create path and map variables
|
||||
val path = (addFmt("/user/logout"))
|
||||
|
||||
// query params
|
||||
val queryParams = new mutable.HashMap[String, String]
|
||||
val headerParams = new mutable.HashMap[String, String]
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
val resFuture = client.submit("GET", path, queryParams.toMap, headerParams.toMap, "")
|
||||
resFuture flatMap { resp =>
|
||||
process(reader.read(resp))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
def getUserByName(username: String)(implicit reader: ClientResponseReader[User]): Future[User] = {
|
||||
// create path and map variables
|
||||
val path = (addFmt("/user/{username}")
|
||||
replaceAll ("\\{" + "username" + "\\}",username.toString))
|
||||
|
||||
// query params
|
||||
val queryParams = new mutable.HashMap[String, String]
|
||||
val headerParams = new mutable.HashMap[String, String]
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
val resFuture = client.submit("GET", path, queryParams.toMap, headerParams.toMap, "")
|
||||
resFuture flatMap { resp =>
|
||||
process(reader.read(resp))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
def updateUser(username: String,
|
||||
body: User)(implicit reader: ClientResponseReader[Unit], writer: RequestWriter[User]): Future[Unit] = {
|
||||
// create path and map variables
|
||||
val path = (addFmt("/user/{username}")
|
||||
replaceAll ("\\{" + "username" + "\\}",username.toString))
|
||||
|
||||
// query params
|
||||
val queryParams = new mutable.HashMap[String, String]
|
||||
val headerParams = new mutable.HashMap[String, String]
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
val resFuture = client.submit("PUT", path, queryParams.toMap, headerParams.toMap, writer.write(body))
|
||||
resFuture flatMap { resp =>
|
||||
process(reader.read(resp))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
def deleteUser(username: String)(implicit reader: ClientResponseReader[Unit]): Future[Unit] = {
|
||||
// create path and map variables
|
||||
val path = (addFmt("/user/{username}")
|
||||
replaceAll ("\\{" + "username" + "\\}",username.toString))
|
||||
|
||||
// query params
|
||||
val queryParams = new mutable.HashMap[String, String]
|
||||
val headerParams = new mutable.HashMap[String, String]
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
val resFuture = client.submit("DELETE", path, queryParams.toMap, headerParams.toMap, "")
|
||||
resFuture flatMap { resp =>
|
||||
process(reader.read(resp))
|
||||
}
|
||||
}
|
||||
// query params
|
||||
val queryParams = new mutable.HashMap[String, String]
|
||||
val headerParams = new mutable.HashMap[String, String]
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
val resFuture = client.submit("POST", path, queryParams.toMap, headerParams.toMap, writer.write(body))
|
||||
resFuture flatMap { resp =>
|
||||
process(reader.read(resp))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
def createUsersWithArrayInput(body: Option[List[User]] = None
|
||||
)(implicit reader: ClientResponseReader[Unit], writer: RequestWriter[List[User]]): Future[Unit] = {
|
||||
// create path and map variables
|
||||
val path = (addFmt("/user/createWithArray"))
|
||||
|
||||
// query params
|
||||
val queryParams = new mutable.HashMap[String, String]
|
||||
val headerParams = new mutable.HashMap[String, String]
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
val resFuture = client.submit("POST", path, queryParams.toMap, headerParams.toMap, writer.write(body))
|
||||
resFuture flatMap { resp =>
|
||||
process(reader.read(resp))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
def createUsersWithListInput(body: Option[List[User]] = None
|
||||
)(implicit reader: ClientResponseReader[Unit], writer: RequestWriter[List[User]]): Future[Unit] = {
|
||||
// create path and map variables
|
||||
val path = (addFmt("/user/createWithList"))
|
||||
|
||||
// query params
|
||||
val queryParams = new mutable.HashMap[String, String]
|
||||
val headerParams = new mutable.HashMap[String, String]
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
val resFuture = client.submit("POST", path, queryParams.toMap, headerParams.toMap, writer.write(body))
|
||||
resFuture flatMap { resp =>
|
||||
process(reader.read(resp))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
def loginUser(username: Option[String] = None,
|
||||
password: Option[String] = None
|
||||
)(implicit reader: ClientResponseReader[String]): Future[String] = {
|
||||
// create path and map variables
|
||||
val path = (addFmt("/user/login"))
|
||||
|
||||
// query params
|
||||
val queryParams = new mutable.HashMap[String, String]
|
||||
val headerParams = new mutable.HashMap[String, String]
|
||||
|
||||
|
||||
|
||||
if(username != null) username.foreach { v => queryParams += "username" -> v.toString }if(password != null) password.foreach { v => queryParams += "password" -> v.toString }
|
||||
|
||||
|
||||
|
||||
val resFuture = client.submit("GET", path, queryParams.toMap, headerParams.toMap, "")
|
||||
resFuture flatMap { resp =>
|
||||
process(reader.read(resp))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
def logoutUser()(implicit reader: ClientResponseReader[Unit]): Future[Unit] = {
|
||||
// create path and map variables
|
||||
val path = (addFmt("/user/logout"))
|
||||
|
||||
// query params
|
||||
val queryParams = new mutable.HashMap[String, String]
|
||||
val headerParams = new mutable.HashMap[String, String]
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
val resFuture = client.submit("GET", path, queryParams.toMap, headerParams.toMap, "")
|
||||
resFuture flatMap { resp =>
|
||||
process(reader.read(resp))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
def getUserByName(username: String)(implicit reader: ClientResponseReader[User]): Future[User] = {
|
||||
// create path and map variables
|
||||
val path = (addFmt("/user/{username}")
|
||||
replaceAll ("\\{" + "username" + "\\}",username.toString))
|
||||
|
||||
// query params
|
||||
val queryParams = new mutable.HashMap[String, String]
|
||||
val headerParams = new mutable.HashMap[String, String]
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
val resFuture = client.submit("GET", path, queryParams.toMap, headerParams.toMap, "")
|
||||
resFuture flatMap { resp =>
|
||||
process(reader.read(resp))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
def updateUser(username: String,
|
||||
body: Option[User] = None
|
||||
)(implicit reader: ClientResponseReader[Unit], writer: RequestWriter[User]): Future[Unit] = {
|
||||
// create path and map variables
|
||||
val path = (addFmt("/user/{username}")
|
||||
replaceAll ("\\{" + "username" + "\\}",username.toString))
|
||||
|
||||
// query params
|
||||
val queryParams = new mutable.HashMap[String, String]
|
||||
val headerParams = new mutable.HashMap[String, String]
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
val resFuture = client.submit("PUT", path, queryParams.toMap, headerParams.toMap, writer.write(body))
|
||||
resFuture flatMap { resp =>
|
||||
process(reader.read(resp))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
def deleteUser(username: String)(implicit reader: ClientResponseReader[Unit]): Future[Unit] = {
|
||||
// create path and map variables
|
||||
val path = (addFmt("/user/{username}")
|
||||
replaceAll ("\\{" + "username" + "\\}",username.toString))
|
||||
|
||||
// query params
|
||||
val queryParams = new mutable.HashMap[String, String]
|
||||
val headerParams = new mutable.HashMap[String, String]
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
val resFuture = client.submit("DELETE", path, queryParams.toMap, headerParams.toMap, "")
|
||||
resFuture flatMap { resp =>
|
||||
process(reader.read(resp))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -3,10 +3,8 @@ package io.swagger.client.model
|
||||
import org.joda.time.DateTime
|
||||
|
||||
|
||||
|
||||
case class Category (
|
||||
id: Long,
|
||||
name: String
|
||||
|
||||
)
|
||||
|
||||
case class Category (
|
||||
id: Long,
|
||||
name: String
|
||||
|
||||
)
|
||||
|
||||
@@ -3,14 +3,12 @@ package io.swagger.client.model
|
||||
import org.joda.time.DateTime
|
||||
|
||||
|
||||
|
||||
case class Order (
|
||||
id: Long,
|
||||
petId: Long,
|
||||
quantity: Integer,
|
||||
shipDate: DateTime,
|
||||
status: String, // Order Status
|
||||
complete: Boolean
|
||||
|
||||
)
|
||||
|
||||
case class Order (
|
||||
id: Long,
|
||||
petId: Long,
|
||||
quantity: Integer,
|
||||
shipDate: DateTime,
|
||||
status: String, // Order Status
|
||||
complete: Boolean
|
||||
|
||||
)
|
||||
|
||||
@@ -3,14 +3,12 @@ package io.swagger.client.model
|
||||
import org.joda.time.DateTime
|
||||
|
||||
|
||||
|
||||
case class Pet (
|
||||
id: Long,
|
||||
category: Category,
|
||||
name: String,
|
||||
photoUrls: List[String],
|
||||
tags: List[Tag],
|
||||
status: String // pet status in the store
|
||||
|
||||
)
|
||||
|
||||
case class Pet (
|
||||
id: Long,
|
||||
category: Category,
|
||||
name: String,
|
||||
photoUrls: List[String],
|
||||
tags: List[Tag],
|
||||
status: String // pet status in the store
|
||||
|
||||
)
|
||||
|
||||
@@ -3,10 +3,8 @@ package io.swagger.client.model
|
||||
import org.joda.time.DateTime
|
||||
|
||||
|
||||
|
||||
case class Tag (
|
||||
id: Long,
|
||||
name: String
|
||||
|
||||
)
|
||||
|
||||
case class Tag (
|
||||
id: Long,
|
||||
name: String
|
||||
|
||||
)
|
||||
|
||||
@@ -3,16 +3,14 @@ package io.swagger.client.model
|
||||
import org.joda.time.DateTime
|
||||
|
||||
|
||||
|
||||
case class User (
|
||||
id: Long,
|
||||
username: String,
|
||||
firstName: String,
|
||||
lastName: String,
|
||||
email: String,
|
||||
password: String,
|
||||
phone: String,
|
||||
userStatus: Integer // User Status
|
||||
|
||||
)
|
||||
|
||||
case class User (
|
||||
id: Long,
|
||||
username: String,
|
||||
firstName: String,
|
||||
lastName: String,
|
||||
email: String,
|
||||
password: String,
|
||||
phone: String,
|
||||
userStatus: Integer // User Status
|
||||
|
||||
)
|
||||
|
||||
@@ -22,6 +22,7 @@ import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.TimeZone;
|
||||
|
||||
@@ -237,6 +238,62 @@ public class ApiClient {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Format to {@code Pair} objects.
|
||||
*/
|
||||
public List<Pair> parameterToPairs(String collectionFormat, String name, Object value){
|
||||
List<Pair> params = new ArrayList<Pair>();
|
||||
|
||||
// preconditions
|
||||
if (name == null || name.isEmpty() || value == null) return params;
|
||||
|
||||
Collection valueCollection = null;
|
||||
if (value instanceof Collection) {
|
||||
valueCollection = (Collection) value;
|
||||
} else {
|
||||
params.add(new Pair(name, parameterToString(value)));
|
||||
return params;
|
||||
}
|
||||
|
||||
if (valueCollection.isEmpty()){
|
||||
return params;
|
||||
}
|
||||
|
||||
// get the collection format
|
||||
collectionFormat = (collectionFormat == null || collectionFormat.isEmpty() ? "csv" : collectionFormat); // default: csv
|
||||
|
||||
// create the params based on the collection format
|
||||
if (collectionFormat.equals("multi")) {
|
||||
for (Object item : valueCollection) {
|
||||
params.add(new Pair(name, parameterToString(item)));
|
||||
}
|
||||
|
||||
return params;
|
||||
}
|
||||
|
||||
String delimiter = ",";
|
||||
|
||||
if (collectionFormat.equals("csv")) {
|
||||
delimiter = ",";
|
||||
} else if (collectionFormat.equals("ssv")) {
|
||||
delimiter = " ";
|
||||
} else if (collectionFormat.equals("tsv")) {
|
||||
delimiter = "\t";
|
||||
} else if (collectionFormat.equals("pipes")) {
|
||||
delimiter = "|";
|
||||
}
|
||||
|
||||
StringBuilder sb = new StringBuilder() ;
|
||||
for (Object item : valueCollection) {
|
||||
sb.append(delimiter);
|
||||
sb.append(parameterToString(item));
|
||||
}
|
||||
|
||||
params.add(new Pair(name, sb.substring(1)));
|
||||
|
||||
return params;
|
||||
}
|
||||
|
||||
/**
|
||||
* Select the Accept header's value from the given accepts array:
|
||||
* if JSON exists in the given array, use it;
|
||||
@@ -340,23 +397,25 @@ public class ApiClient {
|
||||
* @param authNames The authentications to apply
|
||||
* @return The response body in type of string
|
||||
*/
|
||||
public String invokeAPI(String path, String method, Map<String, String> queryParams, Object body, Map<String, String> headerParams, Map<String, String> formParams, String accept, String contentType, String[] authNames) throws ApiException {
|
||||
public String invokeAPI(String path, String method, List<Pair> queryParams, Object body, Map<String, String> headerParams, Map<String, String> formParams, String accept, String contentType, String[] authNames) throws ApiException {
|
||||
updateParamsForAuth(authNames, queryParams, headerParams);
|
||||
|
||||
Client client = getClient();
|
||||
|
||||
StringBuilder b = new StringBuilder();
|
||||
for(String key : queryParams.keySet()) {
|
||||
String value = queryParams.get(key);
|
||||
if (value != null){
|
||||
if(b.toString().length() == 0)
|
||||
b.append("?");
|
||||
else
|
||||
b.append("?");
|
||||
if (queryParams != null){
|
||||
for (Pair queryParam : queryParams){
|
||||
if (!queryParam.getName().isEmpty()) {
|
||||
b.append(escapeString(queryParam.getName()));
|
||||
b.append("=");
|
||||
b.append(escapeString(queryParam.getValue()));
|
||||
b.append("&");
|
||||
b.append(escapeString(key)).append("=").append(escapeString(value));
|
||||
}
|
||||
}
|
||||
}
|
||||
String querystring = b.toString();
|
||||
|
||||
String querystring = b.substring(0, b.length() - 1);
|
||||
|
||||
Builder builder;
|
||||
if (accept == null)
|
||||
@@ -456,7 +515,7 @@ public class ApiClient {
|
||||
*
|
||||
* @param authNames The authentications to apply
|
||||
*/
|
||||
private void updateParamsForAuth(String[] authNames, Map<String, String> queryParams, Map<String, String> headerParams) {
|
||||
private void updateParamsForAuth(String[] authNames, List<Pair> queryParams, Map<String, String> headerParams) {
|
||||
for (String authName : authNames) {
|
||||
Authentication auth = authentications.get(authName);
|
||||
if (auth == null) throw new RuntimeException("Authentication undefined: " + authName);
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
package io.swagger.client;
|
||||
|
||||
public class Pair {
|
||||
private String name = "";
|
||||
private String value = "";
|
||||
|
||||
public Pair (String name, String value) {
|
||||
setName(name);
|
||||
setValue(value);
|
||||
}
|
||||
|
||||
private void setName(String name) {
|
||||
if (!isValidString(name)) return;
|
||||
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
private void setValue(String value) {
|
||||
if (!isValidString(value)) return;
|
||||
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
private boolean isValidString(String arg) {
|
||||
if (arg == null) return false;
|
||||
if (arg.trim().isEmpty()) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package io.swagger.client.api;
|
||||
import io.swagger.client.ApiException;
|
||||
import io.swagger.client.ApiClient;
|
||||
import io.swagger.client.Configuration;
|
||||
import io.swagger.client.Pair;
|
||||
|
||||
import io.swagger.client.model.*;
|
||||
|
||||
@@ -54,7 +55,7 @@ public class PetApi {
|
||||
String path = "/pet".replaceAll("\\{format\\}","json");
|
||||
|
||||
// query params
|
||||
Map<String, String> queryParams = new HashMap<String, String>();
|
||||
List<Pair> queryParams = new ArrayList<Pair>();
|
||||
Map<String, String> headerParams = new HashMap<String, String>();
|
||||
Map<String, String> formParams = new HashMap<String, String>();
|
||||
|
||||
@@ -111,7 +112,7 @@ public class PetApi {
|
||||
String path = "/pet".replaceAll("\\{format\\}","json");
|
||||
|
||||
// query params
|
||||
Map<String, String> queryParams = new HashMap<String, String>();
|
||||
List<Pair> queryParams = new ArrayList<Pair>();
|
||||
Map<String, String> headerParams = new HashMap<String, String>();
|
||||
Map<String, String> formParams = new HashMap<String, String>();
|
||||
|
||||
@@ -168,12 +169,12 @@ public class PetApi {
|
||||
String path = "/pet/findByStatus".replaceAll("\\{format\\}","json");
|
||||
|
||||
// query params
|
||||
Map<String, String> queryParams = new HashMap<String, String>();
|
||||
List<Pair> queryParams = new ArrayList<Pair>();
|
||||
Map<String, String> headerParams = new HashMap<String, String>();
|
||||
Map<String, String> formParams = new HashMap<String, String>();
|
||||
|
||||
if (status != null)
|
||||
queryParams.put("status", apiClient.parameterToString(status));
|
||||
|
||||
queryParams.addAll(apiClient.parameterToPairs("multi", "status", status));
|
||||
|
||||
|
||||
|
||||
@@ -227,12 +228,12 @@ public class PetApi {
|
||||
String path = "/pet/findByTags".replaceAll("\\{format\\}","json");
|
||||
|
||||
// query params
|
||||
Map<String, String> queryParams = new HashMap<String, String>();
|
||||
List<Pair> queryParams = new ArrayList<Pair>();
|
||||
Map<String, String> headerParams = new HashMap<String, String>();
|
||||
Map<String, String> formParams = new HashMap<String, String>();
|
||||
|
||||
if (tags != null)
|
||||
queryParams.put("tags", apiClient.parameterToString(tags));
|
||||
|
||||
queryParams.addAll(apiClient.parameterToPairs("multi", "tags", tags));
|
||||
|
||||
|
||||
|
||||
@@ -292,7 +293,7 @@ public class PetApi {
|
||||
.replaceAll("\\{" + "petId" + "\\}", apiClient.escapeString(petId.toString()));
|
||||
|
||||
// query params
|
||||
Map<String, String> queryParams = new HashMap<String, String>();
|
||||
List<Pair> queryParams = new ArrayList<Pair>();
|
||||
Map<String, String> headerParams = new HashMap<String, String>();
|
||||
Map<String, String> formParams = new HashMap<String, String>();
|
||||
|
||||
@@ -357,7 +358,7 @@ public class PetApi {
|
||||
.replaceAll("\\{" + "petId" + "\\}", apiClient.escapeString(petId.toString()));
|
||||
|
||||
// query params
|
||||
Map<String, String> queryParams = new HashMap<String, String>();
|
||||
List<Pair> queryParams = new ArrayList<Pair>();
|
||||
Map<String, String> headerParams = new HashMap<String, String>();
|
||||
Map<String, String> formParams = new HashMap<String, String>();
|
||||
|
||||
@@ -417,11 +418,11 @@ public class PetApi {
|
||||
/**
|
||||
* Deletes a pet
|
||||
*
|
||||
* @param apiKey
|
||||
* @param petId Pet id to delete
|
||||
* @param apiKey
|
||||
* @return void
|
||||
*/
|
||||
public void deletePet (String apiKey, Long petId) throws ApiException {
|
||||
public void deletePet (Long petId, String apiKey) throws ApiException {
|
||||
Object postBody = null;
|
||||
|
||||
// verify the required parameter 'petId' is set
|
||||
@@ -435,14 +436,14 @@ public class PetApi {
|
||||
.replaceAll("\\{" + "petId" + "\\}", apiClient.escapeString(petId.toString()));
|
||||
|
||||
// query params
|
||||
Map<String, String> queryParams = new HashMap<String, String>();
|
||||
List<Pair> queryParams = new ArrayList<Pair>();
|
||||
Map<String, String> headerParams = new HashMap<String, String>();
|
||||
Map<String, String> formParams = new HashMap<String, String>();
|
||||
|
||||
|
||||
|
||||
if (apiKey != null)
|
||||
headerParams.put("api_key", apiClient.parameterToString(apiKey));
|
||||
headerParams.put("api_key", apiClient.parameterToString(apiKey));
|
||||
|
||||
|
||||
final String[] accepts = {
|
||||
@@ -502,7 +503,7 @@ public class PetApi {
|
||||
.replaceAll("\\{" + "petId" + "\\}", apiClient.escapeString(petId.toString()));
|
||||
|
||||
// query params
|
||||
Map<String, String> queryParams = new HashMap<String, String>();
|
||||
List<Pair> queryParams = new ArrayList<Pair>();
|
||||
Map<String, String> headerParams = new HashMap<String, String>();
|
||||
Map<String, String> formParams = new HashMap<String, String>();
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package io.swagger.client.api;
|
||||
import io.swagger.client.ApiException;
|
||||
import io.swagger.client.ApiClient;
|
||||
import io.swagger.client.Configuration;
|
||||
import io.swagger.client.Pair;
|
||||
|
||||
import io.swagger.client.model.*;
|
||||
|
||||
@@ -53,7 +54,7 @@ public class StoreApi {
|
||||
String path = "/store/inventory".replaceAll("\\{format\\}","json");
|
||||
|
||||
// query params
|
||||
Map<String, String> queryParams = new HashMap<String, String>();
|
||||
List<Pair> queryParams = new ArrayList<Pair>();
|
||||
Map<String, String> headerParams = new HashMap<String, String>();
|
||||
Map<String, String> formParams = new HashMap<String, String>();
|
||||
|
||||
@@ -110,7 +111,7 @@ public class StoreApi {
|
||||
String path = "/store/order".replaceAll("\\{format\\}","json");
|
||||
|
||||
// query params
|
||||
Map<String, String> queryParams = new HashMap<String, String>();
|
||||
List<Pair> queryParams = new ArrayList<Pair>();
|
||||
Map<String, String> headerParams = new HashMap<String, String>();
|
||||
Map<String, String> formParams = new HashMap<String, String>();
|
||||
|
||||
@@ -173,7 +174,7 @@ public class StoreApi {
|
||||
.replaceAll("\\{" + "orderId" + "\\}", apiClient.escapeString(orderId.toString()));
|
||||
|
||||
// query params
|
||||
Map<String, String> queryParams = new HashMap<String, String>();
|
||||
List<Pair> queryParams = new ArrayList<Pair>();
|
||||
Map<String, String> headerParams = new HashMap<String, String>();
|
||||
Map<String, String> formParams = new HashMap<String, String>();
|
||||
|
||||
@@ -236,7 +237,7 @@ public class StoreApi {
|
||||
.replaceAll("\\{" + "orderId" + "\\}", apiClient.escapeString(orderId.toString()));
|
||||
|
||||
// query params
|
||||
Map<String, String> queryParams = new HashMap<String, String>();
|
||||
List<Pair> queryParams = new ArrayList<Pair>();
|
||||
Map<String, String> headerParams = new HashMap<String, String>();
|
||||
Map<String, String> formParams = new HashMap<String, String>();
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package io.swagger.client.api;
|
||||
import io.swagger.client.ApiException;
|
||||
import io.swagger.client.ApiClient;
|
||||
import io.swagger.client.Configuration;
|
||||
import io.swagger.client.Pair;
|
||||
|
||||
import io.swagger.client.model.*;
|
||||
|
||||
@@ -54,7 +55,7 @@ public class UserApi {
|
||||
String path = "/user".replaceAll("\\{format\\}","json");
|
||||
|
||||
// query params
|
||||
Map<String, String> queryParams = new HashMap<String, String>();
|
||||
List<Pair> queryParams = new ArrayList<Pair>();
|
||||
Map<String, String> headerParams = new HashMap<String, String>();
|
||||
Map<String, String> formParams = new HashMap<String, String>();
|
||||
|
||||
@@ -111,7 +112,7 @@ public class UserApi {
|
||||
String path = "/user/createWithArray".replaceAll("\\{format\\}","json");
|
||||
|
||||
// query params
|
||||
Map<String, String> queryParams = new HashMap<String, String>();
|
||||
List<Pair> queryParams = new ArrayList<Pair>();
|
||||
Map<String, String> headerParams = new HashMap<String, String>();
|
||||
Map<String, String> formParams = new HashMap<String, String>();
|
||||
|
||||
@@ -168,7 +169,7 @@ public class UserApi {
|
||||
String path = "/user/createWithList".replaceAll("\\{format\\}","json");
|
||||
|
||||
// query params
|
||||
Map<String, String> queryParams = new HashMap<String, String>();
|
||||
List<Pair> queryParams = new ArrayList<Pair>();
|
||||
Map<String, String> headerParams = new HashMap<String, String>();
|
||||
Map<String, String> formParams = new HashMap<String, String>();
|
||||
|
||||
@@ -226,14 +227,14 @@ public class UserApi {
|
||||
String path = "/user/login".replaceAll("\\{format\\}","json");
|
||||
|
||||
// query params
|
||||
Map<String, String> queryParams = new HashMap<String, String>();
|
||||
List<Pair> queryParams = new ArrayList<Pair>();
|
||||
Map<String, String> headerParams = new HashMap<String, String>();
|
||||
Map<String, String> formParams = new HashMap<String, String>();
|
||||
|
||||
if (username != null)
|
||||
queryParams.put("username", apiClient.parameterToString(username));
|
||||
if (password != null)
|
||||
queryParams.put("password", apiClient.parameterToString(password));
|
||||
|
||||
queryParams.addAll(apiClient.parameterToPairs("", "username", username));
|
||||
|
||||
queryParams.addAll(apiClient.parameterToPairs("", "password", password));
|
||||
|
||||
|
||||
|
||||
@@ -286,7 +287,7 @@ public class UserApi {
|
||||
String path = "/user/logout".replaceAll("\\{format\\}","json");
|
||||
|
||||
// query params
|
||||
Map<String, String> queryParams = new HashMap<String, String>();
|
||||
List<Pair> queryParams = new ArrayList<Pair>();
|
||||
Map<String, String> headerParams = new HashMap<String, String>();
|
||||
Map<String, String> formParams = new HashMap<String, String>();
|
||||
|
||||
@@ -349,7 +350,7 @@ public class UserApi {
|
||||
.replaceAll("\\{" + "username" + "\\}", apiClient.escapeString(username.toString()));
|
||||
|
||||
// query params
|
||||
Map<String, String> queryParams = new HashMap<String, String>();
|
||||
List<Pair> queryParams = new ArrayList<Pair>();
|
||||
Map<String, String> headerParams = new HashMap<String, String>();
|
||||
Map<String, String> formParams = new HashMap<String, String>();
|
||||
|
||||
@@ -413,7 +414,7 @@ public class UserApi {
|
||||
.replaceAll("\\{" + "username" + "\\}", apiClient.escapeString(username.toString()));
|
||||
|
||||
// query params
|
||||
Map<String, String> queryParams = new HashMap<String, String>();
|
||||
List<Pair> queryParams = new ArrayList<Pair>();
|
||||
Map<String, String> headerParams = new HashMap<String, String>();
|
||||
Map<String, String> formParams = new HashMap<String, String>();
|
||||
|
||||
@@ -476,7 +477,7 @@ public class UserApi {
|
||||
.replaceAll("\\{" + "username" + "\\}", apiClient.escapeString(username.toString()));
|
||||
|
||||
// query params
|
||||
Map<String, String> queryParams = new HashMap<String, String>();
|
||||
List<Pair> queryParams = new ArrayList<Pair>();
|
||||
Map<String, String> headerParams = new HashMap<String, String>();
|
||||
Map<String, String> formParams = new HashMap<String, String>();
|
||||
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package io.swagger.client.auth;
|
||||
|
||||
import io.swagger.client.Pair;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.List;
|
||||
|
||||
public class ApiKeyAuth implements Authentication {
|
||||
private final String location;
|
||||
@@ -39,7 +42,7 @@ public class ApiKeyAuth implements Authentication {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyToParams(Map<String, String> queryParams, Map<String, String> headerParams) {
|
||||
public void applyToParams(List<Pair> queryParams, Map<String, String> headerParams) {
|
||||
String value;
|
||||
if (apiKeyPrefix != null) {
|
||||
value = apiKeyPrefix + " " + apiKey;
|
||||
@@ -47,7 +50,7 @@ public class ApiKeyAuth implements Authentication {
|
||||
value = apiKey;
|
||||
}
|
||||
if (location == "query") {
|
||||
queryParams.put(paramName, value);
|
||||
queryParams.add(new Pair(paramName, value));
|
||||
} else if (location == "header") {
|
||||
headerParams.put(paramName, value);
|
||||
}
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
package io.swagger.client.auth;
|
||||
|
||||
import io.swagger.client.Pair;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.List;
|
||||
|
||||
public interface Authentication {
|
||||
/** Apply authentication settings to header and query params. */
|
||||
void applyToParams(Map<String, String> queryParams, Map<String, String> headerParams);
|
||||
void applyToParams(List<Pair> queryParams, Map<String, String> headerParams);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package io.swagger.client.auth;
|
||||
|
||||
import io.swagger.client.Pair;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.List;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import javax.xml.bind.DatatypeConverter;
|
||||
@@ -26,7 +29,7 @@ public class HttpBasicAuth implements Authentication {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyToParams(Map<String, String> queryParams, Map<String, String> headerParams) {
|
||||
public void applyToParams(List<Pair> queryParams, Map<String, String> headerParams) {
|
||||
String str = (username == null ? "" : username) + ":" + (password == null ? "" : password);
|
||||
try {
|
||||
headerParams.put("Authorization", "Basic " + DatatypeConverter.printBase64Binary(str.getBytes("UTF-8")));
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
package io.swagger.client.auth;
|
||||
|
||||
import io.swagger.client.Pair;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.List;
|
||||
|
||||
public class OAuth implements Authentication {
|
||||
@Override
|
||||
public void applyToParams(Map<String, String> queryParams, Map<String, String> headerParams) {
|
||||
public void applyToParams(List<Pair> queryParams, Map<String, String> headerParams) {
|
||||
// TODO: support oauth
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ package io.swagger.client;
|
||||
|
||||
import io.swagger.client.auth.*;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
import org.junit.*;
|
||||
import static org.junit.Assert.*;
|
||||
@@ -109,4 +109,85 @@ public class ApiClientTest {
|
||||
auth.setApiKey(null);
|
||||
auth.setApiKeyPrefix(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParameterToPairsWhenNameIsInvalid() throws Exception {
|
||||
List<Pair> pairs_a = apiClient.parameterToPairs("csv", null, new Integer(1));
|
||||
List<Pair> pairs_b = apiClient.parameterToPairs("csv", "", new Integer(1));
|
||||
|
||||
assertTrue(pairs_a.isEmpty());
|
||||
assertTrue(pairs_b.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParameterToPairsWhenValueIsNull() throws Exception {
|
||||
List<Pair> pairs = apiClient.parameterToPairs("csv", "param-a", null);
|
||||
|
||||
assertTrue(pairs.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParameterToPairsWhenValueIsEmptyStrings() throws Exception {
|
||||
|
||||
// single empty string
|
||||
List<Pair> pairs = apiClient.parameterToPairs("csv", "param-a", " ");
|
||||
assertEquals(1, pairs.size());
|
||||
|
||||
// list of empty strings
|
||||
List<String> strs = new ArrayList<String>();
|
||||
strs.add(" ");
|
||||
strs.add(" ");
|
||||
strs.add(" ");
|
||||
|
||||
List<Pair> concatStrings = apiClient.parameterToPairs("csv", "param-a", strs);
|
||||
|
||||
assertEquals(1, concatStrings.size());
|
||||
assertFalse(concatStrings.get(0).getValue().isEmpty()); // should contain some delimiters
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParameterToPairsWhenValueIsNotCollection() throws Exception {
|
||||
String name = "param-a";
|
||||
Integer value = 1;
|
||||
|
||||
List<Pair> pairs = apiClient.parameterToPairs("csv", name, value);
|
||||
|
||||
assertEquals(1, pairs.size());
|
||||
assertEquals(value, Integer.valueOf(pairs.get(0).getValue()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParameterToPairsWhenValueIsCollection() throws Exception {
|
||||
Map<String, String> collectionFormatMap = new HashMap<String, String>();
|
||||
collectionFormatMap.put("csv", ",");
|
||||
collectionFormatMap.put("tsv", "\t");
|
||||
collectionFormatMap.put("ssv", " ");
|
||||
collectionFormatMap.put("pipes", "\\|");
|
||||
collectionFormatMap.put("", ","); // no format, must default to csv
|
||||
collectionFormatMap.put("unknown", ","); // all other formats, must default to csv
|
||||
|
||||
String name = "param-a";
|
||||
|
||||
List<Object> values = new ArrayList<Object>();
|
||||
values.add("value-a");
|
||||
values.add(123);
|
||||
values.add(new Date());
|
||||
|
||||
// check for multi separately
|
||||
List<Pair> multiPairs = apiClient.parameterToPairs("multi", name, values);
|
||||
assertEquals(values.size(), multiPairs.size());
|
||||
|
||||
// all other formats
|
||||
for (String collectionFormat : collectionFormatMap.keySet()) {
|
||||
List<Pair> pairs = apiClient.parameterToPairs(collectionFormat, name, values);
|
||||
|
||||
assertEquals(1, pairs.size());
|
||||
|
||||
String delimiter = collectionFormatMap.get(collectionFormat);
|
||||
String[] pairValueSplit = pairs.get(0).getValue().split(delimiter);
|
||||
|
||||
// must equal input values
|
||||
assertEquals(values.size(), pairValueSplit.length);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
package io.swagger.client.auth;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Map;
|
||||
import java.util.List;
|
||||
|
||||
import io.swagger.client.Pair;
|
||||
import org.junit.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
@@ -10,7 +13,7 @@ import static org.junit.Assert.*;
|
||||
public class ApiKeyAuthTest {
|
||||
@Test
|
||||
public void testApplyToParamsInQuery() {
|
||||
Map<String, String> queryParams = new HashMap<String, String>();
|
||||
List<Pair> queryParams = new ArrayList<Pair>();
|
||||
Map<String, String> headerParams = new HashMap<String, String>();
|
||||
|
||||
ApiKeyAuth auth = new ApiKeyAuth("query", "api_key");
|
||||
@@ -18,14 +21,17 @@ public class ApiKeyAuthTest {
|
||||
auth.applyToParams(queryParams, headerParams);
|
||||
|
||||
assertEquals(1, queryParams.size());
|
||||
assertEquals("my-api-key", queryParams.get("api_key"));
|
||||
for (Pair queryParam : queryParams) {
|
||||
assertEquals("my-api-key", queryParam.getValue());
|
||||
}
|
||||
|
||||
// no changes to header parameters
|
||||
assertEquals(0, headerParams.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testApplyToParamsInHeaderWithPrefix() {
|
||||
Map<String, String> queryParams = new HashMap<String, String>();
|
||||
List<Pair> queryParams = new ArrayList<Pair>();
|
||||
Map<String, String> headerParams = new HashMap<String, String>();
|
||||
|
||||
ApiKeyAuth auth = new ApiKeyAuth("header", "X-API-TOKEN");
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
package io.swagger.client.auth;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Map;
|
||||
import java.util.List;
|
||||
|
||||
import io.swagger.client.Pair;
|
||||
import org.junit.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
@@ -17,7 +20,7 @@ public class HttpBasicAuthTest {
|
||||
|
||||
@Test
|
||||
public void testApplyToParams() {
|
||||
Map<String, String> queryParams = new HashMap<String, String>();
|
||||
List<Pair> queryParams = new ArrayList<Pair>();
|
||||
Map<String, String> headerParams = new HashMap<String, String>();
|
||||
|
||||
auth.setUsername("my-username");
|
||||
|
||||
@@ -151,7 +151,7 @@ public class PetApiTest {
|
||||
api.addPet(pet);
|
||||
|
||||
Pet fetched = api.getPetById(pet.getId());
|
||||
api.deletePet(null, fetched.getId());
|
||||
api.deletePet(fetched.getId(), null);
|
||||
|
||||
try {
|
||||
fetched = api.getPetById(fetched.getId());
|
||||
|
||||
@@ -52,7 +52,7 @@ sub new {
|
||||
#
|
||||
# Update an existing pet
|
||||
#
|
||||
# @param Pet $body Pet object that needs to be added to the store (required)
|
||||
# @param Pet $body Pet object that needs to be added to the store (optional)
|
||||
# @return void
|
||||
#
|
||||
sub update_pet {
|
||||
@@ -102,7 +102,7 @@ sub update_pet {
|
||||
#
|
||||
# Add a new pet to the store
|
||||
#
|
||||
# @param Pet $body Pet object that needs to be added to the store (required)
|
||||
# @param Pet $body Pet object that needs to be added to the store (optional)
|
||||
# @return void
|
||||
#
|
||||
sub add_pet {
|
||||
@@ -152,7 +152,7 @@ sub add_pet {
|
||||
#
|
||||
# Finds Pets by status
|
||||
#
|
||||
# @param ARRAY[string] $status Status values that need to be considered for filter (required)
|
||||
# @param ARRAY[string] $status Status values that need to be considered for filter (optional)
|
||||
# @return ARRAY[Pet]
|
||||
#
|
||||
sub find_pets_by_status {
|
||||
@@ -205,7 +205,7 @@ sub find_pets_by_status {
|
||||
#
|
||||
# Finds Pets by tags
|
||||
#
|
||||
# @param ARRAY[string] $tags Tags to filter by (required)
|
||||
# @param ARRAY[string] $tags Tags to filter by (optional)
|
||||
# @return ARRAY[Pet]
|
||||
#
|
||||
sub find_pets_by_tags {
|
||||
@@ -319,8 +319,8 @@ sub get_pet_by_id {
|
||||
# Updates a pet in the store with form data
|
||||
#
|
||||
# @param string $pet_id ID of pet that needs to be updated (required)
|
||||
# @param string $name Updated name of the pet (required)
|
||||
# @param string $status Updated status of the pet (required)
|
||||
# @param string $name Updated name of the pet (optional)
|
||||
# @param string $status Updated status of the pet (optional)
|
||||
# @return void
|
||||
#
|
||||
sub update_pet_with_form {
|
||||
@@ -387,7 +387,7 @@ sub update_pet_with_form {
|
||||
#
|
||||
# Deletes a pet
|
||||
#
|
||||
# @param string $api_key (required)
|
||||
# @param string $api_key (optional)
|
||||
# @param int $pet_id Pet id to delete (required)
|
||||
# @return void
|
||||
#
|
||||
@@ -449,8 +449,8 @@ sub delete_pet {
|
||||
# uploads an image
|
||||
#
|
||||
# @param int $pet_id ID of pet to update (required)
|
||||
# @param string $additional_metadata Additional data to pass to server (required)
|
||||
# @param file $file file to upload (required)
|
||||
# @param string $additional_metadata Additional data to pass to server (optional)
|
||||
# @param file $file file to upload (optional)
|
||||
# @return void
|
||||
#
|
||||
sub upload_file {
|
||||
|
||||
@@ -101,7 +101,7 @@ sub get_inventory {
|
||||
#
|
||||
# Place an order for a pet
|
||||
#
|
||||
# @param Order $body order placed for purchasing the pet (required)
|
||||
# @param Order $body order placed for purchasing the pet (optional)
|
||||
# @return Order
|
||||
#
|
||||
sub place_order {
|
||||
|
||||
@@ -52,7 +52,7 @@ sub new {
|
||||
#
|
||||
# Create user
|
||||
#
|
||||
# @param User $body Created user object (required)
|
||||
# @param User $body Created user object (optional)
|
||||
# @return void
|
||||
#
|
||||
sub create_user {
|
||||
@@ -102,7 +102,7 @@ sub create_user {
|
||||
#
|
||||
# Creates list of users with given input array
|
||||
#
|
||||
# @param ARRAY[User] $body List of user object (required)
|
||||
# @param ARRAY[User] $body List of user object (optional)
|
||||
# @return void
|
||||
#
|
||||
sub create_users_with_array_input {
|
||||
@@ -152,7 +152,7 @@ sub create_users_with_array_input {
|
||||
#
|
||||
# Creates list of users with given input array
|
||||
#
|
||||
# @param ARRAY[User] $body List of user object (required)
|
||||
# @param ARRAY[User] $body List of user object (optional)
|
||||
# @return void
|
||||
#
|
||||
sub create_users_with_list_input {
|
||||
@@ -202,8 +202,8 @@ sub create_users_with_list_input {
|
||||
#
|
||||
# Logs user into the system
|
||||
#
|
||||
# @param string $username The user name for login (required)
|
||||
# @param string $password The password for login in clear text (required)
|
||||
# @param string $username The user name for login (optional)
|
||||
# @param string $password The password for login in clear text (optional)
|
||||
# @return string
|
||||
#
|
||||
sub login_user {
|
||||
@@ -366,7 +366,7 @@ sub get_user_by_name {
|
||||
# Updated user
|
||||
#
|
||||
# @param string $username name that need to be deleted (required)
|
||||
# @param User $body Updated user object (required)
|
||||
# @param User $body Updated user object (optional)
|
||||
# @return void
|
||||
#
|
||||
sub update_user {
|
||||
|
||||
@@ -1,32 +1,33 @@
|
||||
{
|
||||
"name": "swagger/swagger-client",
|
||||
"description": "",
|
||||
"keywords": [
|
||||
"swagger",
|
||||
"php",
|
||||
"sdk",
|
||||
"api"
|
||||
],
|
||||
"homepage": "http://swagger.io",
|
||||
"license": "Apache v2",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Swagger and contributors",
|
||||
"homepage": "https://github.com/swagger-api/swagger-codegen"
|
||||
"name": "swagger/swagger-client",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"keywords": [
|
||||
"swagger",
|
||||
"php",
|
||||
"sdk",
|
||||
"api"
|
||||
],
|
||||
"homepage": "http://swagger.io",
|
||||
"license": "Apache v2",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Swagger and contributors",
|
||||
"homepage": "https://github.com/swagger-api/swagger-codegen"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=5.3.3",
|
||||
"ext-curl": "*",
|
||||
"ext-json": "*",
|
||||
"ext-mbstring": "*"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "~4.0",
|
||||
"satooshi/php-coveralls": "~0.6.1",
|
||||
"squizlabs/php_codesniffer": "~2.0"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": { "Swagger\\Client\\" : "lib/" }
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=5.3.3",
|
||||
"ext-curl": "*",
|
||||
"ext-json": "*",
|
||||
"ext-mbstring": "*"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "~4.0",
|
||||
"satooshi/php-coveralls": "~0.6.1",
|
||||
"squizlabs/php_codesniffer": "~2.0"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": { "Swagger\\Client\\" : "lib/" }
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,4 +1,14 @@
|
||||
<?php
|
||||
/**
|
||||
* StoreApi
|
||||
* PHP version 5
|
||||
*
|
||||
* @category Class
|
||||
* @package Swagger\Client
|
||||
* @author http://github.com/swagger-api/swagger-codegen
|
||||
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache Licene v2
|
||||
* @link https://github.com/swagger-api/swagger-codegen
|
||||
*/
|
||||
/**
|
||||
* Copyright 2015 SmartBear Software
|
||||
*
|
||||
@@ -16,8 +26,9 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* NOTE: This class is auto generated by the swagger code generator program. Do not edit the class manually.
|
||||
* NOTE: This class is auto generated by the swagger code generator program.
|
||||
* https://github.com/swagger-api/swagger-codegen
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
namespace Swagger\Client\Api;
|
||||
@@ -27,317 +38,347 @@ use \Swagger\Client\ApiClient;
|
||||
use \Swagger\Client\ApiException;
|
||||
use \Swagger\Client\ObjectSerializer;
|
||||
|
||||
class StoreApi {
|
||||
/**
|
||||
* StoreApi Class Doc Comment
|
||||
*
|
||||
* @category Class
|
||||
* @package Swagger\Client
|
||||
* @author http://github.com/swagger-api/swagger-codegen
|
||||
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache Licene v2
|
||||
* @link https://github.com/swagger-api/swagger-codegen
|
||||
*/
|
||||
class StoreApi
|
||||
{
|
||||
|
||||
/** @var \Swagger\Client\ApiClient instance of the ApiClient */
|
||||
private $apiClient;
|
||||
|
||||
/**
|
||||
* @param \Swagger\Client\ApiClient|null $apiClient The api client to use
|
||||
*/
|
||||
function __construct($apiClient = null) {
|
||||
if ($apiClient == null) {
|
||||
$apiClient = new ApiClient();
|
||||
$apiClient->getConfig()->setHost('http://petstore.swagger.io/v2');
|
||||
/**
|
||||
* API Client
|
||||
* @var \Swagger\Client\ApiClient instance of the ApiClient
|
||||
*/
|
||||
protected $apiClient;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param \Swagger\Client\ApiClient|null $apiClient The api client to use
|
||||
*/
|
||||
function __construct($apiClient = null)
|
||||
{
|
||||
if ($apiClient == null) {
|
||||
$apiClient = new ApiClient();
|
||||
$apiClient->getConfig()->setHost('http://petstore.swagger.io/v2');
|
||||
}
|
||||
|
||||
$this->apiClient = $apiClient;
|
||||
}
|
||||
|
||||
$this->apiClient = $apiClient;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Swagger\Client\ApiClient get the API client
|
||||
*/
|
||||
public function getApiClient() {
|
||||
return $this->apiClient;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Swagger\Client\ApiClient $apiClient set the API client
|
||||
* @return StoreApi
|
||||
*/
|
||||
public function setApiClient(ApiClient $apiClient) {
|
||||
$this->apiClient = $apiClient;
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* getInventory
|
||||
*
|
||||
* Returns pet inventories by status
|
||||
*
|
||||
* @return map[string,int]
|
||||
* @throws \Swagger\Client\ApiException on non-2xx response
|
||||
*/
|
||||
public function getInventory() {
|
||||
|
||||
|
||||
// parse inputs
|
||||
$resourcePath = "/store/inventory";
|
||||
$resourcePath = str_replace("{format}", "json", $resourcePath);
|
||||
$method = "GET";
|
||||
$httpBody = '';
|
||||
$queryParams = array();
|
||||
$headerParams = array();
|
||||
$formParams = array();
|
||||
$_header_accept = ApiClient::selectHeaderAccept(array('application/json', 'application/xml'));
|
||||
if (!is_null($_header_accept)) {
|
||||
$headerParams['Accept'] = $_header_accept;
|
||||
}
|
||||
$headerParams['Content-Type'] = ApiClient::selectHeaderContentType(array());
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// for model (json/xml)
|
||||
if (isset($_tempBody)) {
|
||||
$httpBody = $_tempBody; // $_tempBody is the method argument, if present
|
||||
} else if (count($formParams) > 0) {
|
||||
// for HTTP post (form)
|
||||
$httpBody = $formParams;
|
||||
}
|
||||
|
||||
$apiKey = $this->apiClient->getApiKeyWithPrefix('api_key');
|
||||
if (isset($apiKey)) {
|
||||
$headerParams['api_key'] = $apiKey;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// make the API Call
|
||||
try {
|
||||
$response = $this->apiClient->callAPI($resourcePath, $method,
|
||||
$queryParams, $httpBody,
|
||||
$headerParams);
|
||||
} catch (ApiException $e) {
|
||||
switch ($e->getCode()) {
|
||||
case 200:
|
||||
$data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), 'map[string,int]');
|
||||
$e->setResponseObject($data);
|
||||
break;
|
||||
/**
|
||||
* Get API client
|
||||
* @return \Swagger\Client\ApiClient get the API client
|
||||
*/
|
||||
public function getApiClient()
|
||||
{
|
||||
return $this->apiClient;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the API client
|
||||
* @param \Swagger\Client\ApiClient $apiClient set the API client
|
||||
* @return StoreApi
|
||||
*/
|
||||
public function setApiClient(ApiClient $apiClient)
|
||||
{
|
||||
$this->apiClient = $apiClient;
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* getInventory
|
||||
*
|
||||
* Returns pet inventories by status
|
||||
*
|
||||
* @return map[string,int]
|
||||
* @throws \Swagger\Client\ApiException on non-2xx response
|
||||
*/
|
||||
public function getInventory()
|
||||
{
|
||||
|
||||
|
||||
// parse inputs
|
||||
$resourcePath = "/store/inventory";
|
||||
$resourcePath = str_replace("{format}", "json", $resourcePath);
|
||||
$method = "GET";
|
||||
$httpBody = '';
|
||||
$queryParams = array();
|
||||
$headerParams = array();
|
||||
$formParams = array();
|
||||
$_header_accept = ApiClient::selectHeaderAccept(array('application/json', 'application/xml'));
|
||||
if (!is_null($_header_accept)) {
|
||||
$headerParams['Accept'] = $_header_accept;
|
||||
}
|
||||
|
||||
throw $e;
|
||||
}
|
||||
|
||||
if (!$response) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$responseObject = $this->apiClient->getSerializer()->deserialize($response,'map[string,int]');
|
||||
return $responseObject;
|
||||
|
||||
}
|
||||
$headerParams['Content-Type'] = ApiClient::selectHeaderContentType(array());
|
||||
|
||||
/**
|
||||
* placeOrder
|
||||
*
|
||||
* Place an order for a pet
|
||||
*
|
||||
* @param \Swagger\Client\Model\Order $body order placed for purchasing the pet (required)
|
||||
* @return \Swagger\Client\Model\Order
|
||||
* @throws \Swagger\Client\ApiException on non-2xx response
|
||||
*/
|
||||
public function placeOrder($body) {
|
||||
|
||||
|
||||
// parse inputs
|
||||
$resourcePath = "/store/order";
|
||||
$resourcePath = str_replace("{format}", "json", $resourcePath);
|
||||
$method = "POST";
|
||||
$httpBody = '';
|
||||
$queryParams = array();
|
||||
$headerParams = array();
|
||||
$formParams = array();
|
||||
$_header_accept = ApiClient::selectHeaderAccept(array('application/json', 'application/xml'));
|
||||
if (!is_null($_header_accept)) {
|
||||
$headerParams['Accept'] = $_header_accept;
|
||||
}
|
||||
$headerParams['Content-Type'] = ApiClient::selectHeaderContentType(array());
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// body params
|
||||
$_tempBody = null;
|
||||
if (isset($body)) {
|
||||
$_tempBody = $body;
|
||||
}
|
||||
|
||||
// for model (json/xml)
|
||||
if (isset($_tempBody)) {
|
||||
$httpBody = $_tempBody; // $_tempBody is the method argument, if present
|
||||
} else if (count($formParams) > 0) {
|
||||
// for HTTP post (form)
|
||||
$httpBody = $formParams;
|
||||
}
|
||||
|
||||
// make the API Call
|
||||
try {
|
||||
$response = $this->apiClient->callAPI($resourcePath, $method,
|
||||
$queryParams, $httpBody,
|
||||
$headerParams);
|
||||
} catch (ApiException $e) {
|
||||
switch ($e->getCode()) {
|
||||
case 200:
|
||||
$data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\Swagger\Client\Model\Order');
|
||||
$e->setResponseObject($data);
|
||||
break;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// for model (json/xml)
|
||||
if (isset($_tempBody)) {
|
||||
$httpBody = $_tempBody; // $_tempBody is the method argument, if present
|
||||
} else if (count($formParams) > 0) {
|
||||
$httpBody = $formParams; // for HTTP post (form)
|
||||
}
|
||||
|
||||
throw $e;
|
||||
}
|
||||
|
||||
if (!$response) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$responseObject = $this->apiClient->getSerializer()->deserialize($response,'\Swagger\Client\Model\Order');
|
||||
return $responseObject;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* getOrderById
|
||||
*
|
||||
* Find purchase order by ID
|
||||
*
|
||||
* @param string $order_id ID of pet that needs to be fetched (required)
|
||||
* @return \Swagger\Client\Model\Order
|
||||
* @throws \Swagger\Client\ApiException on non-2xx response
|
||||
*/
|
||||
public function getOrderById($order_id) {
|
||||
|
||||
// verify the required parameter 'order_id' is set
|
||||
if ($order_id === null) {
|
||||
throw new \InvalidArgumentException('Missing the required parameter $order_id when calling getOrderById');
|
||||
}
|
||||
|
||||
|
||||
// parse inputs
|
||||
$resourcePath = "/store/order/{orderId}";
|
||||
$resourcePath = str_replace("{format}", "json", $resourcePath);
|
||||
$method = "GET";
|
||||
$httpBody = '';
|
||||
$queryParams = array();
|
||||
$headerParams = array();
|
||||
$formParams = array();
|
||||
$_header_accept = ApiClient::selectHeaderAccept(array('application/json', 'application/xml'));
|
||||
if (!is_null($_header_accept)) {
|
||||
$headerParams['Accept'] = $_header_accept;
|
||||
}
|
||||
$headerParams['Content-Type'] = ApiClient::selectHeaderContentType(array());
|
||||
|
||||
|
||||
|
||||
// path params
|
||||
if($order_id !== null) {
|
||||
$resourcePath = str_replace("{" . "orderId" . "}",
|
||||
$this->apiClient->getSerializer()->toPathValue($order_id),
|
||||
$resourcePath);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// for model (json/xml)
|
||||
if (isset($_tempBody)) {
|
||||
$httpBody = $_tempBody; // $_tempBody is the method argument, if present
|
||||
} else if (count($formParams) > 0) {
|
||||
// for HTTP post (form)
|
||||
$httpBody = $formParams;
|
||||
}
|
||||
|
||||
// make the API Call
|
||||
try {
|
||||
$response = $this->apiClient->callAPI($resourcePath, $method,
|
||||
$queryParams, $httpBody,
|
||||
$headerParams);
|
||||
} catch (ApiException $e) {
|
||||
switch ($e->getCode()) {
|
||||
case 200:
|
||||
$data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\Swagger\Client\Model\Order');
|
||||
$e->setResponseObject($data);
|
||||
break;
|
||||
|
||||
$apiKey = $this->apiClient->getApiKeyWithPrefix('api_key');
|
||||
if (isset($apiKey)) {
|
||||
$headerParams['api_key'] = $apiKey;
|
||||
}
|
||||
|
||||
throw $e;
|
||||
}
|
||||
|
||||
if (!$response) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$responseObject = $this->apiClient->getSerializer()->deserialize($response,'\Swagger\Client\Model\Order');
|
||||
return $responseObject;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
// make the API Call
|
||||
try
|
||||
{
|
||||
list($response, $httpHeader) = $this->apiClient->callApi(
|
||||
$resourcePath, $method,
|
||||
$queryParams, $httpBody,
|
||||
$headerParams, 'map[string,int]'
|
||||
);
|
||||
} catch (ApiException $e) {
|
||||
switch ($e->getCode()) {
|
||||
case 200:
|
||||
$data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), 'map[string,int]', $httpHeader);
|
||||
$e->setResponseObject($data);
|
||||
break;
|
||||
}
|
||||
|
||||
/**
|
||||
* deleteOrder
|
||||
*
|
||||
* Delete purchase order by ID
|
||||
*
|
||||
* @param string $order_id ID of the order that needs to be deleted (required)
|
||||
* @return void
|
||||
* @throws \Swagger\Client\ApiException on non-2xx response
|
||||
*/
|
||||
public function deleteOrder($order_id) {
|
||||
|
||||
// verify the required parameter 'order_id' is set
|
||||
if ($order_id === null) {
|
||||
throw new \InvalidArgumentException('Missing the required parameter $order_id when calling deleteOrder');
|
||||
}
|
||||
|
||||
|
||||
// parse inputs
|
||||
$resourcePath = "/store/order/{orderId}";
|
||||
$resourcePath = str_replace("{format}", "json", $resourcePath);
|
||||
$method = "DELETE";
|
||||
$httpBody = '';
|
||||
$queryParams = array();
|
||||
$headerParams = array();
|
||||
$formParams = array();
|
||||
$_header_accept = ApiClient::selectHeaderAccept(array('application/json', 'application/xml'));
|
||||
if (!is_null($_header_accept)) {
|
||||
$headerParams['Accept'] = $_header_accept;
|
||||
}
|
||||
$headerParams['Content-Type'] = ApiClient::selectHeaderContentType(array());
|
||||
|
||||
|
||||
|
||||
// path params
|
||||
if($order_id !== null) {
|
||||
$resourcePath = str_replace("{" . "orderId" . "}",
|
||||
$this->apiClient->getSerializer()->toPathValue($order_id),
|
||||
$resourcePath);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// for model (json/xml)
|
||||
if (isset($_tempBody)) {
|
||||
$httpBody = $_tempBody; // $_tempBody is the method argument, if present
|
||||
} else if (count($formParams) > 0) {
|
||||
// for HTTP post (form)
|
||||
$httpBody = $formParams;
|
||||
}
|
||||
|
||||
// make the API Call
|
||||
try {
|
||||
$response = $this->apiClient->callAPI($resourcePath, $method,
|
||||
$queryParams, $httpBody,
|
||||
$headerParams);
|
||||
} catch (ApiException $e) {
|
||||
switch ($e->getCode()) {
|
||||
throw $e;
|
||||
}
|
||||
|
||||
if (!$response) {
|
||||
return null;
|
||||
}
|
||||
|
||||
throw $e;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $this->apiClient->getSerializer()->deserialize($response, 'map[string,int]');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* placeOrder
|
||||
*
|
||||
* Place an order for a pet
|
||||
*
|
||||
* @param \Swagger\Client\Model\Order $body order placed for purchasing the pet (optional)
|
||||
* @return \Swagger\Client\Model\Order
|
||||
* @throws \Swagger\Client\ApiException on non-2xx response
|
||||
*/
|
||||
public function placeOrder($body=null)
|
||||
{
|
||||
|
||||
|
||||
// parse inputs
|
||||
$resourcePath = "/store/order";
|
||||
$resourcePath = str_replace("{format}", "json", $resourcePath);
|
||||
$method = "POST";
|
||||
$httpBody = '';
|
||||
$queryParams = array();
|
||||
$headerParams = array();
|
||||
$formParams = array();
|
||||
$_header_accept = ApiClient::selectHeaderAccept(array('application/json', 'application/xml'));
|
||||
if (!is_null($_header_accept)) {
|
||||
$headerParams['Accept'] = $_header_accept;
|
||||
}
|
||||
$headerParams['Content-Type'] = ApiClient::selectHeaderContentType(array());
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// body params
|
||||
$_tempBody = null;
|
||||
if (isset($body)) {
|
||||
$_tempBody = $body;
|
||||
}
|
||||
|
||||
// for model (json/xml)
|
||||
if (isset($_tempBody)) {
|
||||
$httpBody = $_tempBody; // $_tempBody is the method argument, if present
|
||||
} else if (count($formParams) > 0) {
|
||||
$httpBody = $formParams; // for HTTP post (form)
|
||||
}
|
||||
|
||||
// make the API Call
|
||||
try
|
||||
{
|
||||
list($response, $httpHeader) = $this->apiClient->callApi(
|
||||
$resourcePath, $method,
|
||||
$queryParams, $httpBody,
|
||||
$headerParams, '\Swagger\Client\Model\Order'
|
||||
);
|
||||
} catch (ApiException $e) {
|
||||
switch ($e->getCode()) {
|
||||
case 200:
|
||||
$data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\Swagger\Client\Model\Order', $httpHeader);
|
||||
$e->setResponseObject($data);
|
||||
break;
|
||||
}
|
||||
|
||||
throw $e;
|
||||
}
|
||||
|
||||
if (!$response) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->apiClient->getSerializer()->deserialize($response, '\Swagger\Client\Model\Order');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* getOrderById
|
||||
*
|
||||
* Find purchase order by ID
|
||||
*
|
||||
* @param string $order_id ID of pet that needs to be fetched (required)
|
||||
* @return \Swagger\Client\Model\Order
|
||||
* @throws \Swagger\Client\ApiException on non-2xx response
|
||||
*/
|
||||
public function getOrderById($order_id)
|
||||
{
|
||||
|
||||
// verify the required parameter 'order_id' is set
|
||||
if ($order_id === null) {
|
||||
throw new \InvalidArgumentException('Missing the required parameter $order_id when calling getOrderById');
|
||||
}
|
||||
|
||||
// parse inputs
|
||||
$resourcePath = "/store/order/{orderId}";
|
||||
$resourcePath = str_replace("{format}", "json", $resourcePath);
|
||||
$method = "GET";
|
||||
$httpBody = '';
|
||||
$queryParams = array();
|
||||
$headerParams = array();
|
||||
$formParams = array();
|
||||
$_header_accept = ApiClient::selectHeaderAccept(array('application/json', 'application/xml'));
|
||||
if (!is_null($_header_accept)) {
|
||||
$headerParams['Accept'] = $_header_accept;
|
||||
}
|
||||
$headerParams['Content-Type'] = ApiClient::selectHeaderContentType(array());
|
||||
|
||||
|
||||
|
||||
// path params
|
||||
if ($order_id !== null) {
|
||||
$resourcePath = str_replace(
|
||||
"{" . "orderId" . "}",
|
||||
$this->apiClient->getSerializer()->toPathValue($order_id),
|
||||
$resourcePath
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// for model (json/xml)
|
||||
if (isset($_tempBody)) {
|
||||
$httpBody = $_tempBody; // $_tempBody is the method argument, if present
|
||||
} else if (count($formParams) > 0) {
|
||||
$httpBody = $formParams; // for HTTP post (form)
|
||||
}
|
||||
|
||||
// make the API Call
|
||||
try
|
||||
{
|
||||
list($response, $httpHeader) = $this->apiClient->callApi(
|
||||
$resourcePath, $method,
|
||||
$queryParams, $httpBody,
|
||||
$headerParams, '\Swagger\Client\Model\Order'
|
||||
);
|
||||
} catch (ApiException $e) {
|
||||
switch ($e->getCode()) {
|
||||
case 200:
|
||||
$data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\Swagger\Client\Model\Order', $httpHeader);
|
||||
$e->setResponseObject($data);
|
||||
break;
|
||||
}
|
||||
|
||||
throw $e;
|
||||
}
|
||||
|
||||
if (!$response) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->apiClient->getSerializer()->deserialize($response, '\Swagger\Client\Model\Order');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* deleteOrder
|
||||
*
|
||||
* Delete purchase order by ID
|
||||
*
|
||||
* @param string $order_id ID of the order that needs to be deleted (required)
|
||||
* @return void
|
||||
* @throws \Swagger\Client\ApiException on non-2xx response
|
||||
*/
|
||||
public function deleteOrder($order_id)
|
||||
{
|
||||
|
||||
// verify the required parameter 'order_id' is set
|
||||
if ($order_id === null) {
|
||||
throw new \InvalidArgumentException('Missing the required parameter $order_id when calling deleteOrder');
|
||||
}
|
||||
|
||||
// parse inputs
|
||||
$resourcePath = "/store/order/{orderId}";
|
||||
$resourcePath = str_replace("{format}", "json", $resourcePath);
|
||||
$method = "DELETE";
|
||||
$httpBody = '';
|
||||
$queryParams = array();
|
||||
$headerParams = array();
|
||||
$formParams = array();
|
||||
$_header_accept = ApiClient::selectHeaderAccept(array('application/json', 'application/xml'));
|
||||
if (!is_null($_header_accept)) {
|
||||
$headerParams['Accept'] = $_header_accept;
|
||||
}
|
||||
$headerParams['Content-Type'] = ApiClient::selectHeaderContentType(array());
|
||||
|
||||
|
||||
|
||||
// path params
|
||||
if ($order_id !== null) {
|
||||
$resourcePath = str_replace(
|
||||
"{" . "orderId" . "}",
|
||||
$this->apiClient->getSerializer()->toPathValue($order_id),
|
||||
$resourcePath
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// for model (json/xml)
|
||||
if (isset($_tempBody)) {
|
||||
$httpBody = $_tempBody; // $_tempBody is the method argument, if present
|
||||
} else if (count($formParams) > 0) {
|
||||
$httpBody = $formParams; // for HTTP post (form)
|
||||
}
|
||||
|
||||
// make the API Call
|
||||
try
|
||||
{
|
||||
list($response, $httpHeader) = $this->apiClient->callApi(
|
||||
$resourcePath, $method,
|
||||
$queryParams, $httpBody,
|
||||
$headerParams
|
||||
);
|
||||
} catch (ApiException $e) {
|
||||
switch ($e->getCode()) {
|
||||
}
|
||||
|
||||
throw $e;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,4 +1,15 @@
|
||||
<?php
|
||||
/**
|
||||
* ApiClient
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* @category Class
|
||||
* @package Swagger\Client
|
||||
* @author http://github.com/swagger-api/swagger-codegen
|
||||
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache Licene v2
|
||||
* @link https://github.com/swagger-api/swagger-codegen
|
||||
*/
|
||||
/**
|
||||
* Copyright 2015 SmartBear Software
|
||||
*
|
||||
@@ -14,206 +25,248 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* NOTE: This class is auto generated by the swagger code generator program.
|
||||
* https://github.com/swagger-api/swagger-codegen
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
namespace Swagger\Client;
|
||||
|
||||
class ApiClient {
|
||||
/**
|
||||
* ApiClient Class Doc Comment
|
||||
*
|
||||
* @category Class
|
||||
* @package Swagger\Client
|
||||
* @author http://github.com/swagger-api/swagger-codegen
|
||||
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache Licene v2
|
||||
* @link https://github.com/swagger-api/swagger-codegen
|
||||
*/
|
||||
class ApiClient
|
||||
{
|
||||
|
||||
public static $PATCH = "PATCH";
|
||||
public static $POST = "POST";
|
||||
public static $GET = "GET";
|
||||
public static $PUT = "PUT";
|
||||
public static $DELETE = "DELETE";
|
||||
|
||||
/** @var Configuration */
|
||||
protected $config;
|
||||
|
||||
/** @var ObjectSerializer */
|
||||
protected $serializer;
|
||||
|
||||
/**
|
||||
* @param Configuration $config config for this ApiClient
|
||||
*/
|
||||
function __construct(Configuration $config = null) {
|
||||
if ($config == null) {
|
||||
$config = Configuration::getDefaultConfiguration();
|
||||
public static $PATCH = "PATCH";
|
||||
public static $POST = "POST";
|
||||
public static $GET = "GET";
|
||||
public static $PUT = "PUT";
|
||||
public static $DELETE = "DELETE";
|
||||
|
||||
/**
|
||||
* Configuration
|
||||
* @var Configuration
|
||||
*/
|
||||
protected $config;
|
||||
|
||||
/**
|
||||
* Object Serializer
|
||||
* @var ObjectSerializer
|
||||
*/
|
||||
protected $serializer;
|
||||
|
||||
/**
|
||||
* Constructor of the class
|
||||
* @param Configuration $config config for this ApiClient
|
||||
*/
|
||||
function __construct(Configuration $config = null)
|
||||
{
|
||||
if ($config == null) {
|
||||
$config = Configuration::getDefaultConfiguration();
|
||||
}
|
||||
|
||||
$this->config = $config;
|
||||
$this->serializer = new ObjectSerializer();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the config
|
||||
* @return Configuration
|
||||
*/
|
||||
public function getConfig()
|
||||
{
|
||||
return $this->config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the serializer
|
||||
* @return ObjectSerializer
|
||||
*/
|
||||
public function getSerializer()
|
||||
{
|
||||
return $this->serializer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get API key (with prefix if set)
|
||||
* @param string $apiKeyIdentifier name of apikey
|
||||
* @return string API key with the prefix
|
||||
*/
|
||||
public function getApiKeyWithPrefix($apiKeyIdentifier)
|
||||
{
|
||||
$prefix = $this->config->getApiKeyPrefix($apiKeyIdentifier);
|
||||
$apiKey = $this->config->getApiKey($apiKeyIdentifier);
|
||||
|
||||
if (!isset($apiKey)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (isset($prefix)) {
|
||||
$keyWithPrefix = $prefix." ".$apiKey;
|
||||
} else {
|
||||
$keyWithPrefix = $apiKey;
|
||||
}
|
||||
|
||||
return $keyWithPrefix;
|
||||
}
|
||||
|
||||
$this->config = $config;
|
||||
$this->serializer = new ObjectSerializer();
|
||||
}
|
||||
|
||||
/**
|
||||
* get the config
|
||||
* @return Configuration
|
||||
*/
|
||||
public function getConfig() {
|
||||
return $this->config;
|
||||
}
|
||||
|
||||
/**
|
||||
* get the serializer
|
||||
* @return ObjectSerializer
|
||||
*/
|
||||
public function getSerializer() {
|
||||
return $this->serializer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get API key (with prefix if set)
|
||||
* @param string $apiKey name of apikey
|
||||
* @return string API key with the prefix
|
||||
*/
|
||||
public function getApiKeyWithPrefix($apiKey) {
|
||||
$prefix = $this->config->getApiKeyPrefix($apiKey);
|
||||
$apiKey = $this->config->getApiKey($apiKey);
|
||||
|
||||
if (!isset($apiKey)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (isset($prefix)) {
|
||||
$keyWithPrefix = $prefix." ".$apiKey;
|
||||
} else {
|
||||
$keyWithPrefix = $apiKey;
|
||||
}
|
||||
|
||||
return $keyWithPrefix;
|
||||
}
|
||||
/**
|
||||
* Make the HTTP call (Sync)
|
||||
* @param string $resourcePath path to method endpoint
|
||||
* @param string $method method to call
|
||||
* @param array $queryParams parameters to be place in query URL
|
||||
* @param array $postData parameters to be placed in POST body
|
||||
* @param array $headerParams parameters to be place in request header
|
||||
* @param string $responseType expected response type of the endpoint
|
||||
* @throws \Swagger\Client\ApiException on a non 2xx response
|
||||
* @return mixed
|
||||
*/
|
||||
public function callApi($resourcePath, $method, $queryParams, $postData, $headerParams, $responseType=null)
|
||||
{
|
||||
|
||||
/**
|
||||
* @param string $resourcePath path to method endpoint
|
||||
* @param string $method method to call
|
||||
* @param array $queryParams parameters to be place in query URL
|
||||
* @param array $postData parameters to be placed in POST body
|
||||
* @param array $headerParams parameters to be place in request header
|
||||
* @throws \Swagger\Client\ApiException on a non 2xx response
|
||||
* @return mixed
|
||||
*/
|
||||
public function callApi($resourcePath, $method, $queryParams, $postData, $headerParams) {
|
||||
|
||||
$headers = array();
|
||||
|
||||
# construct the http header
|
||||
$headerParams = array_merge((array)$this->config->getDefaultHeaders(), (array)$headerParams);
|
||||
|
||||
foreach ($headerParams as $key => $val) {
|
||||
$headers[] = "$key: $val";
|
||||
$headers = array();
|
||||
|
||||
// construct the http header
|
||||
$headerParams = array_merge(
|
||||
(array)$this->config->getDefaultHeaders(),
|
||||
(array)$headerParams
|
||||
);
|
||||
|
||||
foreach ($headerParams as $key => $val) {
|
||||
$headers[] = "$key: $val";
|
||||
}
|
||||
|
||||
// form data
|
||||
if ($postData and in_array('Content-Type: application/x-www-form-urlencoded', $headers)) {
|
||||
$postData = http_build_query($postData);
|
||||
} else if ((is_object($postData) or is_array($postData)) and !in_array('Content-Type: multipart/form-data', $headers)) { // json model
|
||||
$postData = json_encode($this->serializer->sanitizeForSerialization($postData));
|
||||
}
|
||||
|
||||
$url = $this->config->getHost() . $resourcePath;
|
||||
|
||||
$curl = curl_init();
|
||||
// set timeout, if needed
|
||||
if ($this->config->getCurlTimeout() != 0) {
|
||||
curl_setopt($curl, CURLOPT_TIMEOUT, $this->config->getCurlTimeout());
|
||||
}
|
||||
// return the result on success, rather than just TRUE
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
|
||||
|
||||
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
|
||||
|
||||
if (! empty($queryParams)) {
|
||||
$url = ($url . '?' . http_build_query($queryParams));
|
||||
}
|
||||
|
||||
if ($method == self::$POST) {
|
||||
curl_setopt($curl, CURLOPT_POST, true);
|
||||
curl_setopt($curl, CURLOPT_POSTFIELDS, $postData);
|
||||
} else if ($method == self::$PATCH) {
|
||||
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PATCH");
|
||||
curl_setopt($curl, CURLOPT_POSTFIELDS, $postData);
|
||||
} else if ($method == self::$PUT) {
|
||||
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT");
|
||||
curl_setopt($curl, CURLOPT_POSTFIELDS, $postData);
|
||||
} else if ($method == self::$DELETE) {
|
||||
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "DELETE");
|
||||
curl_setopt($curl, CURLOPT_POSTFIELDS, $postData);
|
||||
} else if ($method != self::$GET) {
|
||||
throw new ApiException('Method ' . $method . ' is not recognized.');
|
||||
}
|
||||
curl_setopt($curl, CURLOPT_URL, $url);
|
||||
|
||||
// Set user agent
|
||||
curl_setopt($curl, CURLOPT_USERAGENT, $this->config->getUserAgent());
|
||||
|
||||
// debugging for curl
|
||||
if ($this->config->getDebug()) {
|
||||
error_log("[DEBUG] HTTP Request body ~BEGIN~\n".print_r($postData, true)."\n~END~\n", 3, $this->config->getDebugFile());
|
||||
|
||||
curl_setopt($curl, CURLOPT_VERBOSE, 1);
|
||||
curl_setopt($curl, CURLOPT_STDERR, fopen($this->config->getDebugFile(), 'a'));
|
||||
} else {
|
||||
curl_setopt($curl, CURLOPT_VERBOSE, 0);
|
||||
}
|
||||
|
||||
// obtain the HTTP response headers
|
||||
curl_setopt($curl, CURLOPT_HEADER, 1);
|
||||
|
||||
// Make the request
|
||||
$response = curl_exec($curl);
|
||||
$http_header_size = curl_getinfo($curl, CURLINFO_HEADER_SIZE);
|
||||
$http_header = substr($response, 0, $http_header_size);
|
||||
$http_body = substr($response, $http_header_size);
|
||||
$response_info = curl_getinfo($curl);
|
||||
|
||||
// debug HTTP response body
|
||||
if ($this->config->getDebug()) {
|
||||
error_log("[DEBUG] HTTP Response body ~BEGIN~\n".print_r($http_body, true)."\n~END~\n", 3, $this->config->getDebugFile());
|
||||
}
|
||||
|
||||
// Handle the response
|
||||
if ($response_info['http_code'] == 0) {
|
||||
throw new ApiException("API call to $url timed out: ".serialize($response_info), 0, null, null);
|
||||
} else if ($response_info['http_code'] >= 200 && $response_info['http_code'] <= 299 ) {
|
||||
// return raw body if response is a file
|
||||
if ($responseType == '\SplFileObject') {
|
||||
return array($http_body, $http_header);
|
||||
}
|
||||
|
||||
$data = json_decode($http_body);
|
||||
if (json_last_error() > 0) { // if response is a string
|
||||
$data = $http_body;
|
||||
}
|
||||
} else {
|
||||
throw new ApiException(
|
||||
"[".$response_info['http_code']."] Error connecting to the API ($url)",
|
||||
$response_info['http_code'], $http_header, $http_body
|
||||
);
|
||||
}
|
||||
return array($data, $http_header);
|
||||
}
|
||||
|
||||
// form data
|
||||
if ($postData and in_array('Content-Type: application/x-www-form-urlencoded', $headers)) {
|
||||
$postData = http_build_query($postData);
|
||||
|
||||
/**
|
||||
* Return the header 'Accept' based on an array of Accept provided
|
||||
*
|
||||
* @param string[] $accept Array of header
|
||||
*
|
||||
* @return string Accept (e.g. application/json)
|
||||
*/
|
||||
public static function selectHeaderAccept($accept)
|
||||
{
|
||||
if (count($accept) === 0 or (count($accept) === 1 and $accept[0] === '')) {
|
||||
return null;
|
||||
} elseif (preg_grep("/application\/json/i", $accept)) {
|
||||
return 'application/json';
|
||||
} else {
|
||||
return implode(',', $accept);
|
||||
}
|
||||
}
|
||||
else if ((is_object($postData) or is_array($postData)) and !in_array('Content-Type: multipart/form-data', $headers)) { // json model
|
||||
$postData = json_encode($this->serializer->sanitizeForSerialization($postData));
|
||||
|
||||
/**
|
||||
* Return the content type based on an array of content-type provided
|
||||
*
|
||||
* @param string[] $content_type Array fo content-type
|
||||
*
|
||||
* @return string Content-Type (e.g. application/json)
|
||||
*/
|
||||
public static function selectHeaderContentType($content_type)
|
||||
{
|
||||
if (count($content_type) === 0 or (count($content_type) === 1 and $content_type[0] === '')) {
|
||||
return 'application/json';
|
||||
} elseif (preg_grep("/application\/json/i", $content_type)) {
|
||||
return 'application/json';
|
||||
} else {
|
||||
return implode(',', $content_type);
|
||||
}
|
||||
}
|
||||
|
||||
$url = $this->config->getHost() . $resourcePath;
|
||||
|
||||
$curl = curl_init();
|
||||
// set timeout, if needed
|
||||
if ($this->config->getCurlTimeout() != 0) {
|
||||
curl_setopt($curl, CURLOPT_TIMEOUT, $this->config->getCurlTimeout());
|
||||
}
|
||||
// return the result on success, rather than just TRUE
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
|
||||
|
||||
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
|
||||
|
||||
if (! empty($queryParams)) {
|
||||
$url = ($url . '?' . http_build_query($queryParams));
|
||||
}
|
||||
|
||||
if ($method == self::$POST) {
|
||||
curl_setopt($curl, CURLOPT_POST, true);
|
||||
curl_setopt($curl, CURLOPT_POSTFIELDS, $postData);
|
||||
} else if ($method == self::$PATCH) {
|
||||
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PATCH");
|
||||
curl_setopt($curl, CURLOPT_POSTFIELDS, $postData);
|
||||
} else if ($method == self::$PUT) {
|
||||
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT");
|
||||
curl_setopt($curl, CURLOPT_POSTFIELDS, $postData);
|
||||
} else if ($method == self::$DELETE) {
|
||||
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "DELETE");
|
||||
curl_setopt($curl, CURLOPT_POSTFIELDS, $postData);
|
||||
} else if ($method != self::$GET) {
|
||||
throw new ApiException('Method ' . $method . ' is not recognized.');
|
||||
}
|
||||
curl_setopt($curl, CURLOPT_URL, $url);
|
||||
|
||||
// Set user agent
|
||||
curl_setopt($curl, CURLOPT_USERAGENT, $this->config->getUserAgent());
|
||||
|
||||
// debugging for curl
|
||||
if ($this->config->getDebug()) {
|
||||
error_log("[DEBUG] HTTP Request body ~BEGIN~\n".print_r($postData, true)."\n~END~\n", 3, $this->config->getDebugFile());
|
||||
|
||||
curl_setopt($curl, CURLOPT_VERBOSE, 1);
|
||||
curl_setopt($curl, CURLOPT_STDERR, fopen($this->config->getDebugFile(), 'a'));
|
||||
} else {
|
||||
curl_setopt($curl, CURLOPT_VERBOSE, 0);
|
||||
}
|
||||
|
||||
// obtain the HTTP response headers
|
||||
curl_setopt($curl, CURLOPT_HEADER, 1);
|
||||
|
||||
// Make the request
|
||||
$response = curl_exec($curl);
|
||||
$http_header_size = curl_getinfo($curl, CURLINFO_HEADER_SIZE);
|
||||
$http_header = substr($response, 0, $http_header_size);
|
||||
$http_body = substr($response, $http_header_size);
|
||||
$response_info = curl_getinfo($curl);
|
||||
|
||||
// debug HTTP response body
|
||||
if ($this->config->getDebug()) {
|
||||
error_log("[DEBUG] HTTP Response body ~BEGIN~\n".print_r($http_body, true)."\n~END~\n", 3, $this->config->getDebugFile());
|
||||
}
|
||||
|
||||
// Handle the response
|
||||
if ($response_info['http_code'] == 0) {
|
||||
throw new ApiException("API call to $url timed out: ".serialize($response_info), 0, null, null);
|
||||
} else if ($response_info['http_code'] >= 200 && $response_info['http_code'] <= 299 ) {
|
||||
$data = json_decode($http_body);
|
||||
if (json_last_error() > 0) { // if response is a string
|
||||
$data = $http_body;
|
||||
}
|
||||
} else {
|
||||
throw new ApiException("[".$response_info['http_code']."] Error connecting to the API ($url)",
|
||||
$response_info['http_code'], $http_header, $http_body);
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
/*
|
||||
* return the header 'Accept' based on an array of Accept provided
|
||||
*
|
||||
* @param string[] $accept Array of header
|
||||
* @return string Accept (e.g. application/json)
|
||||
*/
|
||||
public static function selectHeaderAccept($accept) {
|
||||
if (count($accept) === 0 or (count($accept) === 1 and $accept[0] === '')) {
|
||||
return NULL;
|
||||
} elseif (preg_grep("/application\/json/i", $accept)) {
|
||||
return 'application/json';
|
||||
} else {
|
||||
return implode(',', $accept);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* return the content type based on an array of content-type provided
|
||||
*
|
||||
* @param string[] content_type_array Array fo content-type
|
||||
* @return string Content-Type (e.g. application/json)
|
||||
*/
|
||||
public static function selectHeaderContentType($content_type) {
|
||||
if (count($content_type) === 0 or (count($content_type) === 1 and $content_type[0] === '')) {
|
||||
return 'application/json';
|
||||
} elseif (preg_grep("/application\/json/i", $content_type)) {
|
||||
return 'application/json';
|
||||
} else {
|
||||
return implode(',', $content_type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,14 @@
|
||||
<?php
|
||||
/**
|
||||
* ApiException
|
||||
* PHP version 5
|
||||
*
|
||||
* @category Class
|
||||
* @package Swagger\Client
|
||||
* @author http://github.com/swagger-api/swagger-codegen
|
||||
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache Licene v2
|
||||
* @link https://github.com/swagger-api/swagger-codegen
|
||||
*/
|
||||
/**
|
||||
* Copyright 2015 SmartBear Software
|
||||
*
|
||||
@@ -14,57 +24,97 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* NOTE: This class is auto generated by the swagger code generator program.
|
||||
* https://github.com/swagger-api/swagger-codegen
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
namespace Swagger\Client;
|
||||
|
||||
use \Exception;
|
||||
|
||||
class ApiException extends Exception {
|
||||
/**
|
||||
* ApiException Class Doc Comment
|
||||
*
|
||||
* @category Class
|
||||
* @package Swagger\Client
|
||||
* @author http://github.com/swagger-api/swagger-codegen
|
||||
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache Licene v2
|
||||
* @link https://github.com/swagger-api/swagger-codegen
|
||||
*/
|
||||
class ApiException extends Exception
|
||||
{
|
||||
|
||||
/** @var string The HTTP body of the server response. */
|
||||
protected $responseBody;
|
||||
/**
|
||||
* The HTTP body of the server response.
|
||||
* @var string
|
||||
*/
|
||||
protected $responseBody;
|
||||
|
||||
/**
|
||||
* The HTTP header of the server response.
|
||||
* @var string[]
|
||||
*/
|
||||
protected $responseHeaders;
|
||||
|
||||
/**
|
||||
* The deserialized response object
|
||||
* @var $responseObject;
|
||||
*/
|
||||
protected $responseObject;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param string $message Error message
|
||||
* @param string $code HTTP status code
|
||||
* @param string $responseHeaders HTTP response header
|
||||
* @param string $responseBody Deseralized response object
|
||||
*/
|
||||
public function __construct($message="", $code=0, $responseHeaders=null, $responseBody=null)
|
||||
{
|
||||
parent::__construct($message, $code);
|
||||
$this->responseHeaders = $responseHeaders;
|
||||
$this->responseBody = $responseBody;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the HTTP response header
|
||||
*
|
||||
* @return string HTTP response header
|
||||
*/
|
||||
public function getResponseHeaders()
|
||||
{
|
||||
return $this->responseHeaders;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the HTTP response body
|
||||
*
|
||||
* @return string HTTP response body
|
||||
*/
|
||||
public function getResponseBody()
|
||||
{
|
||||
return $this->responseBody;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the deseralized response object (during deserialization)
|
||||
* @param mixed $obj Deserialized response object
|
||||
* @return void
|
||||
*/
|
||||
public function setResponseObject($obj)
|
||||
{
|
||||
$this->responseObject = $obj;
|
||||
}
|
||||
|
||||
/** @var string[] The HTTP header of the server response. */
|
||||
protected $responseHeaders;
|
||||
|
||||
/**
|
||||
* The deserialized response object
|
||||
*/
|
||||
protected $responseObject;
|
||||
|
||||
public function __construct($message="", $code=0, $responseHeaders=null, $responseBody=null) {
|
||||
parent::__construct($message, $code);
|
||||
$this->responseHeaders = $responseHeaders;
|
||||
$this->responseBody = $responseBody;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the HTTP response header
|
||||
*
|
||||
* @return string HTTP response header
|
||||
*/
|
||||
public function getResponseHeaders() {
|
||||
return $this->responseHeaders;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the HTTP response body
|
||||
*
|
||||
* @return string HTTP response body
|
||||
*/
|
||||
public function getResponseBody() {
|
||||
return $this->responseBody;
|
||||
}
|
||||
|
||||
/**
|
||||
* sets the deseralized response object (during deserialization)
|
||||
* @param mixed $obj
|
||||
*/
|
||||
public function setResponseObject($obj) {
|
||||
$this->responseObject = $obj;
|
||||
}
|
||||
|
||||
public function getResponseObject() {
|
||||
return $this->responseObject;
|
||||
}
|
||||
/**
|
||||
* Gets the deseralized response object (during deserialization)
|
||||
*
|
||||
* @return mixed the deserialized response object
|
||||
*/
|
||||
public function getResponseObject()
|
||||
{
|
||||
return $this->responseObject;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,15 @@
|
||||
<?php
|
||||
/**
|
||||
* Configuration
|
||||
* PHP version 5
|
||||
*
|
||||
* @category Class
|
||||
* @package Swagger\Client
|
||||
* @author http://github.com/swagger-api/swagger-codegen
|
||||
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache Licene v2
|
||||
* @link https://github.com/swagger-api/swagger-codegen
|
||||
*/
|
||||
|
||||
/**
|
||||
* Copyright 2015 SmartBear Software
|
||||
*
|
||||
@@ -15,252 +26,439 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* NOTE: This class is auto generated by the swagger code generator program.
|
||||
* https://github.com/swagger-api/swagger-codegen
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
namespace Swagger\Client;
|
||||
|
||||
class Configuration {
|
||||
/**
|
||||
* Configuration Class Doc Comment
|
||||
* PHP version 5
|
||||
*
|
||||
* @category Class
|
||||
* @package Swagger\Client
|
||||
* @author http://github.com/swagger-api/swagger-codegen
|
||||
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache Licene v2
|
||||
* @link https://github.com/swagger-api/swagger-codegen
|
||||
*/
|
||||
class Configuration
|
||||
{
|
||||
|
||||
private static $defaultConfiguration = null;
|
||||
private static $_defaultConfiguration = null;
|
||||
|
||||
/**
|
||||
* Associate array to store API key(s)
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $apiKeys = array();
|
||||
|
||||
/**
|
||||
* Associate array to store API prefix (e.g. Bearer)
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $apiKeyPrefixes = array();
|
||||
|
||||
/**
|
||||
* Username for HTTP basic authentication
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $username = '';
|
||||
|
||||
/**
|
||||
* Password for HTTP basic authentication
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $password = '';
|
||||
|
||||
/**
|
||||
* The default instance of ApiClient
|
||||
*
|
||||
* @var \Swagger\Client\ApiClient
|
||||
*/
|
||||
protected $defaultHeaders = array();
|
||||
|
||||
/**
|
||||
* The host
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $host = 'http://localhost';
|
||||
|
||||
/**
|
||||
* Timeout (second) of the HTTP request, by default set to 0, no timeout
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $curlTimeout = 0;
|
||||
|
||||
/**
|
||||
* User agent of the HTTP request, set to "PHP-Swagger" by default
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $userAgent = "PHP-Swagger";
|
||||
|
||||
/**
|
||||
* Debug switch (default set to false)
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $debug = false;
|
||||
|
||||
/**
|
||||
* Debug file location (log to STDOUT by default)
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $debugFile = 'php://output';
|
||||
|
||||
/** @var string[] Associate array to store API key(s) */
|
||||
protected $apiKeys = array();
|
||||
/**
|
||||
* Debug file location (log to STDOUT by default)
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $tempFolderPath;
|
||||
|
||||
/** string[] Associate array to store API prefix (e.g. Bearer) */
|
||||
protected $apiKeyPrefixes = array();
|
||||
|
||||
/** @var string Username for HTTP basic authentication */
|
||||
protected $username = '';
|
||||
|
||||
/** @var string Password for HTTP basic authentication */
|
||||
protected $password = '';
|
||||
|
||||
/** @var \Swagger\Client\ApiClient The default instance of ApiClient */
|
||||
protected $defaultHeaders = array();
|
||||
|
||||
/** @var string The host */
|
||||
protected $host = 'http://localhost';
|
||||
|
||||
/** @var string timeout (second) of the HTTP request, by default set to 0, no timeout */
|
||||
protected $curlTimeout = 0;
|
||||
|
||||
/** @var string user agent of the HTTP request, set to "PHP-Swagger" by default */
|
||||
protected $userAgent = "PHP-Swagger";
|
||||
|
||||
/** @var bool Debug switch (default set to false) */
|
||||
protected $debug = false;
|
||||
|
||||
/** @var string Debug file location (log to STDOUT by default) */
|
||||
protected $debugFile = 'php://output';
|
||||
|
||||
/**
|
||||
* @param string $key
|
||||
* @param string $value
|
||||
* @return Configuration
|
||||
*/
|
||||
public function setApiKey($key, $value) {
|
||||
$this->apiKeys[$key] = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $key
|
||||
* @return string
|
||||
*/
|
||||
public function getApiKey($key) {
|
||||
return isset($this->apiKeys[$key]) ? $this->apiKeys[$key] : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $key
|
||||
* @param string $value
|
||||
* @return Configuration
|
||||
*/
|
||||
public function setApiKeyPrefix($key, $value) {
|
||||
$this->apiKeyPrefixes[$key] = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $key
|
||||
* @return string
|
||||
*/
|
||||
public function getApiKeyPrefix($key) {
|
||||
return isset($this->apiKeyPrefixes[$key]) ? $this->apiKeyPrefixes[$key] : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $username
|
||||
* @return Configuration
|
||||
*/
|
||||
public function setUsername($username) {
|
||||
$this->username = $username;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getUsername() {
|
||||
return $this->username;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $password
|
||||
* @return Configuration
|
||||
*/
|
||||
public function setPassword($password) {
|
||||
$this->password = $password;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getPassword() {
|
||||
return $this->password;
|
||||
}
|
||||
|
||||
/**
|
||||
* add default header
|
||||
*
|
||||
* @param string $headerName header name (e.g. Token)
|
||||
* @param string $headerValue header value (e.g. 1z8wp3)
|
||||
* @return ApiClient
|
||||
*/
|
||||
public function addDefaultHeader($headerName, $headerValue) {
|
||||
if (!is_string($headerName)) {
|
||||
throw new \InvalidArgumentException('Header name must be a string.');
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->tempFolderPath = sys_get_temp_dir();
|
||||
}
|
||||
|
||||
$this->defaultHeaders[$headerName] = $headerValue;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* get the default header
|
||||
*
|
||||
* @return array default header
|
||||
*/
|
||||
public function getDefaultHeaders() {
|
||||
return $this->defaultHeaders;
|
||||
}
|
||||
|
||||
/**
|
||||
* delete a default header
|
||||
* @param string $headerName the header to delete
|
||||
* @return Configuration
|
||||
*/
|
||||
public function deleteDefaultHeader($headerName) {
|
||||
unset($this->defaultHeaders[$headerName]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $host
|
||||
* @return Configuration
|
||||
*/
|
||||
public function setHost($host) {
|
||||
$this->host = $host;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getHost() {
|
||||
return $this->host;
|
||||
}
|
||||
|
||||
/**
|
||||
* set the user agent of the api client
|
||||
*
|
||||
* @param string $userAgent the user agent of the api client
|
||||
* @return ApiClient
|
||||
*/
|
||||
public function setUserAgent($userAgent) {
|
||||
if (!is_string($userAgent)) {
|
||||
throw new \InvalidArgumentException('User-agent must be a string.');
|
||||
|
||||
/**
|
||||
* Sets API key
|
||||
*
|
||||
* @param string $apiKeyIdentifier API key identifier (authentication scheme)
|
||||
* @param string $key API key or token
|
||||
*
|
||||
* @return Configuration
|
||||
*/
|
||||
public function setApiKey($apiKeyIdentifier, $key)
|
||||
{
|
||||
$this->apiKeys[$apiKeyIdentifier] = $key;
|
||||
return $this;
|
||||
}
|
||||
|
||||
$this->userAgent = $userAgent;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* get the user agent of the api client
|
||||
*
|
||||
* @return string user agent
|
||||
*/
|
||||
public function getUserAgent() {
|
||||
return $this->userAgent;
|
||||
}
|
||||
|
||||
/**
|
||||
* set the HTTP timeout value
|
||||
*
|
||||
* @param integer $seconds Number of seconds before timing out [set to 0 for no timeout]
|
||||
* @return ApiClient
|
||||
*/
|
||||
public function setCurlTimeout($seconds) {
|
||||
if (!is_numeric($seconds) || $seconds < 0) {
|
||||
throw new \InvalidArgumentException('Timeout value must be numeric and a non-negative number.');
|
||||
|
||||
/**
|
||||
* Gets API key
|
||||
*
|
||||
* @param string $apiKeyIdentifier API key identifier (authentication scheme)
|
||||
*
|
||||
* @return string API key or token
|
||||
*/
|
||||
public function getApiKey($apiKeyIdentifier)
|
||||
{
|
||||
return isset($this->apiKeys[$apiKeyIdentifier]) ? $this->apiKeys[$apiKeyIdentifier] : null;
|
||||
}
|
||||
|
||||
$this->curlTimeout = $seconds;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* get the HTTP timeout value
|
||||
*
|
||||
* @return string HTTP timeout value
|
||||
*/
|
||||
public function getCurlTimeout() {
|
||||
return $this->curlTimeout;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $debug
|
||||
* @return Configuration
|
||||
*/
|
||||
public function setDebug($debug) {
|
||||
$this->debug = $debug;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function getDebug() {
|
||||
return $this->debug;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $debugFile
|
||||
* @return Configuration
|
||||
*/
|
||||
public function setDebugFile($debugFile) {
|
||||
$this->debugFile = $debugFile;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getDebugFile() {
|
||||
return $this->debugFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Configuration
|
||||
*/
|
||||
public static function getDefaultConfiguration() {
|
||||
if (self::$defaultConfiguration == null) {
|
||||
return new Configuration();
|
||||
|
||||
/**
|
||||
* Sets the prefix for API key (e.g. Bearer)
|
||||
*
|
||||
* @param string $apiKeyIdentifier API key identifier (authentication scheme)
|
||||
* @param string $prefix API key prefix, e.g. Bearer
|
||||
*
|
||||
* @return Configuration
|
||||
*/
|
||||
public function setApiKeyPrefix($apiKeyIdentifier, $prefix)
|
||||
{
|
||||
$this->apiKeyPrefixes[$apiKeyIdentifier] = $prefix;
|
||||
return $this;
|
||||
}
|
||||
|
||||
return self::$defaultConfiguration;
|
||||
}
|
||||
|
||||
public static function setDefaultConfiguration(Configuration $config) {
|
||||
self::$defaultConfiguration = $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets API key prefix
|
||||
*
|
||||
* @param string $apiKeyIdentifier API key identifier (authentication scheme)
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getApiKeyPrefix($apiKeyIdentifier)
|
||||
{
|
||||
return isset($this->apiKeyPrefixes[$apiKeyIdentifier]) ? $this->apiKeyPrefixes[$apiKeyIdentifier] : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the username for HTTP basic authentication
|
||||
*
|
||||
* @param string $username Username for HTTP basic authentication
|
||||
*
|
||||
* @return Configuration
|
||||
*/
|
||||
public function setUsername($username)
|
||||
{
|
||||
$this->username = $username;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the username for HTTP basic authentication
|
||||
*
|
||||
* @return string Username for HTTP basic authentication
|
||||
*/
|
||||
public function getUsername()
|
||||
{
|
||||
return $this->username;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the password for HTTP basic authentication
|
||||
*
|
||||
* @param string $password Password for HTTP basic authentication
|
||||
*
|
||||
* @return Configuration
|
||||
*/
|
||||
public function setPassword($password)
|
||||
{
|
||||
$this->password = $password;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the password for HTTP basic authentication
|
||||
*
|
||||
* @return string Password for HTTP basic authentication
|
||||
*/
|
||||
public function getPassword()
|
||||
{
|
||||
return $this->password;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a default header
|
||||
*
|
||||
* @param string $headerName header name (e.g. Token)
|
||||
* @param string $headerValue header value (e.g. 1z8wp3)
|
||||
*
|
||||
* @return ApiClient
|
||||
*/
|
||||
public function addDefaultHeader($headerName, $headerValue)
|
||||
{
|
||||
if (!is_string($headerName)) {
|
||||
throw new \InvalidArgumentException('Header name must be a string.');
|
||||
}
|
||||
|
||||
$this->defaultHeaders[$headerName] = $headerValue;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the default header
|
||||
*
|
||||
* @return array An array of default header(s)
|
||||
*/
|
||||
public function getDefaultHeaders()
|
||||
{
|
||||
return $this->defaultHeaders;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a default header
|
||||
*
|
||||
* @param string $headerName the header to delete
|
||||
*
|
||||
* @return Configuration
|
||||
*/
|
||||
public function deleteDefaultHeader($headerName)
|
||||
{
|
||||
unset($this->defaultHeaders[$headerName]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the host
|
||||
*
|
||||
* @param string $host Host
|
||||
*
|
||||
* @return Configuration
|
||||
*/
|
||||
public function setHost($host)
|
||||
{
|
||||
$this->host = $host;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the host
|
||||
*
|
||||
* @return string Host
|
||||
*/
|
||||
public function getHost()
|
||||
{
|
||||
return $this->host;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the user agent of the api client
|
||||
*
|
||||
* @param string $userAgent the user agent of the api client
|
||||
*
|
||||
* @return ApiClient
|
||||
*/
|
||||
public function setUserAgent($userAgent)
|
||||
{
|
||||
if (!is_string($userAgent)) {
|
||||
throw new \InvalidArgumentException('User-agent must be a string.');
|
||||
}
|
||||
|
||||
$this->userAgent = $userAgent;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the user agent of the api client
|
||||
*
|
||||
* @return string user agent
|
||||
*/
|
||||
public function getUserAgent()
|
||||
{
|
||||
return $this->userAgent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the HTTP timeout value
|
||||
*
|
||||
* @param integer $seconds Number of seconds before timing out [set to 0 for no timeout]
|
||||
*
|
||||
* @return ApiClient
|
||||
*/
|
||||
public function setCurlTimeout($seconds)
|
||||
{
|
||||
if (!is_numeric($seconds) || $seconds < 0) {
|
||||
throw new \InvalidArgumentException('Timeout value must be numeric and a non-negative number.');
|
||||
}
|
||||
|
||||
$this->curlTimeout = $seconds;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the HTTP timeout value
|
||||
*
|
||||
* @return string HTTP timeout value
|
||||
*/
|
||||
public function getCurlTimeout()
|
||||
{
|
||||
return $this->curlTimeout;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets debug flag
|
||||
*
|
||||
* @param bool $debug Debug flag
|
||||
*
|
||||
* @return Configuration
|
||||
*/
|
||||
public function setDebug($debug)
|
||||
{
|
||||
$this->debug = $debug;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the debug flag
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function getDebug()
|
||||
{
|
||||
return $this->debug;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the debug file
|
||||
*
|
||||
* @param string $debugFile Debug file
|
||||
*
|
||||
* @return Configuration
|
||||
*/
|
||||
public function setDebugFile($debugFile)
|
||||
{
|
||||
$this->debugFile = $debugFile;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the debug file
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDebugFile()
|
||||
{
|
||||
return $this->debugFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the temp folder path
|
||||
*
|
||||
* @param string $tempFolderPath Temp folder path
|
||||
*
|
||||
* @return Configuration
|
||||
*/
|
||||
public function setTempFolderPath($tempFolderPath)
|
||||
{
|
||||
$this->tempFolderPath = $tempFolderPath;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the temp folder path
|
||||
*
|
||||
* @return string Temp folder path
|
||||
*/
|
||||
public function getTempFolderPath()
|
||||
{
|
||||
return $this->tempFolderPath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the default configuration instance
|
||||
*
|
||||
* @return Configuration
|
||||
*/
|
||||
public static function getDefaultConfiguration()
|
||||
{
|
||||
if (self::$_defaultConfiguration == null) {
|
||||
self::$_defaultConfiguration = new Configuration();
|
||||
}
|
||||
|
||||
return self::$_defaultConfiguration;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the detault configuration instance
|
||||
*
|
||||
* @param Configuration $config An instance of the Configuration Object
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function setDefaultConfiguration(Configuration $config)
|
||||
{
|
||||
self::$_defaultConfiguration = $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the essential information for debugging
|
||||
*
|
||||
* @return string The report for debugging
|
||||
*/
|
||||
public static function toDebugReport()
|
||||
{
|
||||
$report = "PHP SDK (Swagger\Client) Debug Report:\n";
|
||||
$report .= " OS: ".php_uname()."\n";
|
||||
$report .= " PHP Version: ".phpversion()."\n";
|
||||
$report .= " Swagger Spec Version: 1.0.0\n";
|
||||
$report .= " SDK Package Version: 1.0.0\n";
|
||||
$report .= " Temp Folder Path: ".self::getDefaultConfiguration()->getTempFolderPath()."\n";
|
||||
|
||||
return $report;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,4 +1,15 @@
|
||||
<?php
|
||||
/**
|
||||
* Category
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* @category Class
|
||||
* @package Swagger\Client
|
||||
* @author http://github.com/swagger-api/swagger-codegen
|
||||
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache Licene v2
|
||||
* @link https://github.com/swagger-api/swagger-codegen
|
||||
*/
|
||||
/**
|
||||
* Copyright 2015 SmartBear Software
|
||||
*
|
||||
@@ -14,114 +25,182 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by the swagger code generator program. Do not edit the class manually.
|
||||
*
|
||||
* NOTE: This class is auto generated by the swagger code generator program.
|
||||
* https://github.com/swagger-api/swagger-codegen
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
namespace Swagger\Client\Model;
|
||||
|
||||
use \ArrayAccess;
|
||||
|
||||
class Category implements ArrayAccess {
|
||||
/** @var string[] Array of property to type mappings. Used for (de)serialization */
|
||||
static $swaggerTypes = array(
|
||||
'id' => 'int',
|
||||
'name' => 'string'
|
||||
);
|
||||
|
||||
/** @var string[] Array of attributes where the key is the local name, and the value is the original name */
|
||||
static $attributeMap = array(
|
||||
'id' => 'id',
|
||||
'name' => 'name'
|
||||
);
|
||||
|
||||
/** @var string[] Array of attributes to setter functions (for deserialization of responses) */
|
||||
static $setters = array(
|
||||
'id' => 'setId',
|
||||
'name' => 'setName'
|
||||
);
|
||||
|
||||
/** @var string[] Array of attributes to getter functions (for serialization of requests) */
|
||||
static $getters = array(
|
||||
'id' => 'getId',
|
||||
'name' => 'getName'
|
||||
);
|
||||
|
||||
/**
|
||||
* Category Class Doc Comment
|
||||
*
|
||||
* @category Class
|
||||
* @description
|
||||
* @package Swagger\Client
|
||||
* @author http://github.com/swagger-api/swagger-codegen
|
||||
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache Licene v2
|
||||
* @link https://github.com/swagger-api/swagger-codegen
|
||||
*/
|
||||
class Category implements ArrayAccess
|
||||
{
|
||||
/**
|
||||
* Array of property to type mappings. Used for (de)serialization
|
||||
* @var string[]
|
||||
*/
|
||||
static $swaggerTypes = array(
|
||||
'id' => 'int',
|
||||
'name' => 'string'
|
||||
);
|
||||
|
||||
/** @var int $id */
|
||||
protected $id;
|
||||
/**
|
||||
* Array of attributes where the key is the local name, and the value is the original name
|
||||
* @var string[]
|
||||
*/
|
||||
static $attributeMap = array(
|
||||
'id' => 'id',
|
||||
'name' => 'name'
|
||||
);
|
||||
|
||||
/** @var string $name */
|
||||
protected $name;
|
||||
/**
|
||||
* Array of attributes to setter functions (for deserialization of responses)
|
||||
* @var string[]
|
||||
*/
|
||||
static $setters = array(
|
||||
'id' => 'setId',
|
||||
'name' => 'setName'
|
||||
);
|
||||
|
||||
public function __construct(array $data = null) {
|
||||
if ($data != null) {
|
||||
$this->id = $data["id"];
|
||||
$this->name = $data["name"];
|
||||
/**
|
||||
* Array of attributes to getter functions (for serialization of requests)
|
||||
* @var string[]
|
||||
*/
|
||||
static $getters = array(
|
||||
'id' => 'getId',
|
||||
'name' => 'getName'
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
* $id
|
||||
* @var int
|
||||
*/
|
||||
protected $id;
|
||||
|
||||
/**
|
||||
* $name
|
||||
* @var string
|
||||
*/
|
||||
protected $name;
|
||||
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param mixed[] $data Associated array of property value initalizing the model
|
||||
*/
|
||||
public function __construct(array $data = null)
|
||||
{
|
||||
if ($data != null) {
|
||||
$this->id = $data["id"];
|
||||
$this->name = $data["name"];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* get id
|
||||
* @return int
|
||||
*/
|
||||
public function getId() {
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* set id
|
||||
* @param int $id
|
||||
* @return $this
|
||||
*/
|
||||
public function setId($id) {
|
||||
$this->id = $id;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* get name
|
||||
* @return string
|
||||
*/
|
||||
public function getName() {
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* set name
|
||||
* @param string $name
|
||||
* @return $this
|
||||
*/
|
||||
public function setName($name) {
|
||||
$this->name = $name;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function offsetExists($offset) {
|
||||
return isset($this->$offset);
|
||||
}
|
||||
|
||||
public function offsetGet($offset) {
|
||||
return $this->$offset;
|
||||
}
|
||||
|
||||
public function offsetSet($offset, $value) {
|
||||
$this->$offset = $value;
|
||||
}
|
||||
|
||||
public function offsetUnset($offset) {
|
||||
unset($this->$offset);
|
||||
}
|
||||
|
||||
public function __toString() {
|
||||
if (defined('JSON_PRETTY_PRINT')) {
|
||||
return json_encode($this, JSON_PRETTY_PRINT);
|
||||
} else {
|
||||
return json_encode($this);
|
||||
|
||||
/**
|
||||
* Gets id
|
||||
* @return int
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets id
|
||||
* @param int $id
|
||||
* @return $this
|
||||
*/
|
||||
public function setId($id)
|
||||
{
|
||||
|
||||
$this->id = $id;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets name
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets name
|
||||
* @param string $name
|
||||
* @return $this
|
||||
*/
|
||||
public function setName($name)
|
||||
{
|
||||
|
||||
$this->name = $name;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if offset exists. False otherwise.
|
||||
* @param integer $offset Offset
|
||||
* @return boolean
|
||||
*/
|
||||
public function offsetExists($offset)
|
||||
{
|
||||
return isset($this->$offset);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets offset.
|
||||
* @param integer $offset Offset
|
||||
* @return mixed
|
||||
*/
|
||||
public function offsetGet($offset)
|
||||
{
|
||||
return $this->$offset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets value based on offset.
|
||||
* @param integer $offset Offset
|
||||
* @param mixed $value Value to be set
|
||||
* @return void
|
||||
*/
|
||||
public function offsetSet($offset, $value)
|
||||
{
|
||||
$this->$offset = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Unsets offset.
|
||||
* @param integer $offset Offset
|
||||
* @return void
|
||||
*/
|
||||
public function offsetUnset($offset)
|
||||
{
|
||||
unset($this->$offset);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the string presentation of the object
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
if (defined('JSON_PRETTY_PRINT')) {
|
||||
return json_encode(get_object_vars($this), JSON_PRETTY_PRINT);
|
||||
} else {
|
||||
return json_encode(get_object_vars($this));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,15 @@
|
||||
<?php
|
||||
/**
|
||||
* Order
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* @category Class
|
||||
* @package Swagger\Client
|
||||
* @author http://github.com/swagger-api/swagger-codegen
|
||||
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache Licene v2
|
||||
* @link https://github.com/swagger-api/swagger-codegen
|
||||
*/
|
||||
/**
|
||||
* Copyright 2015 SmartBear Software
|
||||
*
|
||||
@@ -14,218 +25,313 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by the swagger code generator program. Do not edit the class manually.
|
||||
*
|
||||
* NOTE: This class is auto generated by the swagger code generator program.
|
||||
* https://github.com/swagger-api/swagger-codegen
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
namespace Swagger\Client\Model;
|
||||
|
||||
use \ArrayAccess;
|
||||
/**
|
||||
* Order Class Doc Comment
|
||||
*
|
||||
* @category Class
|
||||
* @description
|
||||
* @package Swagger\Client
|
||||
* @author http://github.com/swagger-api/swagger-codegen
|
||||
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache Licene v2
|
||||
* @link https://github.com/swagger-api/swagger-codegen
|
||||
*/
|
||||
class Order implements ArrayAccess
|
||||
{
|
||||
/**
|
||||
* Array of property to type mappings. Used for (de)serialization
|
||||
* @var string[]
|
||||
*/
|
||||
static $swaggerTypes = array(
|
||||
'id' => 'int',
|
||||
'pet_id' => 'int',
|
||||
'quantity' => 'int',
|
||||
'ship_date' => '\DateTime',
|
||||
'status' => 'string',
|
||||
'complete' => 'bool'
|
||||
);
|
||||
|
||||
/**
|
||||
* Array of attributes where the key is the local name, and the value is the original name
|
||||
* @var string[]
|
||||
*/
|
||||
static $attributeMap = array(
|
||||
'id' => 'id',
|
||||
'pet_id' => 'petId',
|
||||
'quantity' => 'quantity',
|
||||
'ship_date' => 'shipDate',
|
||||
'status' => 'status',
|
||||
'complete' => 'complete'
|
||||
);
|
||||
|
||||
/**
|
||||
* Array of attributes to setter functions (for deserialization of responses)
|
||||
* @var string[]
|
||||
*/
|
||||
static $setters = array(
|
||||
'id' => 'setId',
|
||||
'pet_id' => 'setPetId',
|
||||
'quantity' => 'setQuantity',
|
||||
'ship_date' => 'setShipDate',
|
||||
'status' => 'setStatus',
|
||||
'complete' => 'setComplete'
|
||||
);
|
||||
|
||||
/**
|
||||
* Array of attributes to getter functions (for serialization of requests)
|
||||
* @var string[]
|
||||
*/
|
||||
static $getters = array(
|
||||
'id' => 'getId',
|
||||
'pet_id' => 'getPetId',
|
||||
'quantity' => 'getQuantity',
|
||||
'ship_date' => 'getShipDate',
|
||||
'status' => 'getStatus',
|
||||
'complete' => 'getComplete'
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
* $id
|
||||
* @var int
|
||||
*/
|
||||
protected $id;
|
||||
|
||||
/**
|
||||
* $pet_id
|
||||
* @var int
|
||||
*/
|
||||
protected $pet_id;
|
||||
|
||||
/**
|
||||
* $quantity
|
||||
* @var int
|
||||
*/
|
||||
protected $quantity;
|
||||
|
||||
/**
|
||||
* $ship_date
|
||||
* @var \DateTime
|
||||
*/
|
||||
protected $ship_date;
|
||||
|
||||
/**
|
||||
* $status Order Status
|
||||
* @var string
|
||||
*/
|
||||
protected $status;
|
||||
|
||||
/**
|
||||
* $complete
|
||||
* @var bool
|
||||
*/
|
||||
protected $complete;
|
||||
|
||||
|
||||
class Order implements ArrayAccess {
|
||||
/** @var string[] Array of property to type mappings. Used for (de)serialization */
|
||||
static $swaggerTypes = array(
|
||||
'id' => 'int',
|
||||
'pet_id' => 'int',
|
||||
'quantity' => 'int',
|
||||
'ship_date' => '\DateTime',
|
||||
'status' => 'string',
|
||||
'complete' => 'bool'
|
||||
);
|
||||
|
||||
/** @var string[] Array of attributes where the key is the local name, and the value is the original name */
|
||||
static $attributeMap = array(
|
||||
'id' => 'id',
|
||||
'pet_id' => 'petId',
|
||||
'quantity' => 'quantity',
|
||||
'ship_date' => 'shipDate',
|
||||
'status' => 'status',
|
||||
'complete' => 'complete'
|
||||
);
|
||||
|
||||
/** @var string[] Array of attributes to setter functions (for deserialization of responses) */
|
||||
static $setters = array(
|
||||
'id' => 'setId',
|
||||
'pet_id' => 'setPetId',
|
||||
'quantity' => 'setQuantity',
|
||||
'ship_date' => 'setShipDate',
|
||||
'status' => 'setStatus',
|
||||
'complete' => 'setComplete'
|
||||
);
|
||||
|
||||
/** @var string[] Array of attributes to getter functions (for serialization of requests) */
|
||||
static $getters = array(
|
||||
'id' => 'getId',
|
||||
'pet_id' => 'getPetId',
|
||||
'quantity' => 'getQuantity',
|
||||
'ship_date' => 'getShipDate',
|
||||
'status' => 'getStatus',
|
||||
'complete' => 'getComplete'
|
||||
);
|
||||
|
||||
|
||||
/** @var int $id */
|
||||
protected $id;
|
||||
|
||||
/** @var int $pet_id */
|
||||
protected $pet_id;
|
||||
|
||||
/** @var int $quantity */
|
||||
protected $quantity;
|
||||
|
||||
/** @var \DateTime $ship_date */
|
||||
protected $ship_date;
|
||||
|
||||
/** @var string $status Order Status */
|
||||
protected $status;
|
||||
|
||||
/** @var bool $complete */
|
||||
protected $complete;
|
||||
|
||||
public function __construct(array $data = null) {
|
||||
if ($data != null) {
|
||||
$this->id = $data["id"];
|
||||
$this->pet_id = $data["pet_id"];
|
||||
$this->quantity = $data["quantity"];
|
||||
$this->ship_date = $data["ship_date"];
|
||||
$this->status = $data["status"];
|
||||
$this->complete = $data["complete"];
|
||||
/**
|
||||
* Constructor
|
||||
* @param mixed[] $data Associated array of property value initalizing the model
|
||||
*/
|
||||
public function __construct(array $data = null)
|
||||
{
|
||||
if ($data != null) {
|
||||
$this->id = $data["id"];
|
||||
$this->pet_id = $data["pet_id"];
|
||||
$this->quantity = $data["quantity"];
|
||||
$this->ship_date = $data["ship_date"];
|
||||
$this->status = $data["status"];
|
||||
$this->complete = $data["complete"];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* get id
|
||||
* @return int
|
||||
*/
|
||||
public function getId() {
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* set id
|
||||
* @param int $id
|
||||
* @return $this
|
||||
*/
|
||||
public function setId($id) {
|
||||
$this->id = $id;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* get pet_id
|
||||
* @return int
|
||||
*/
|
||||
public function getPetId() {
|
||||
return $this->pet_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* set pet_id
|
||||
* @param int $pet_id
|
||||
* @return $this
|
||||
*/
|
||||
public function setPetId($pet_id) {
|
||||
$this->pet_id = $pet_id;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* get quantity
|
||||
* @return int
|
||||
*/
|
||||
public function getQuantity() {
|
||||
return $this->quantity;
|
||||
}
|
||||
|
||||
/**
|
||||
* set quantity
|
||||
* @param int $quantity
|
||||
* @return $this
|
||||
*/
|
||||
public function setQuantity($quantity) {
|
||||
$this->quantity = $quantity;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* get ship_date
|
||||
* @return \DateTime
|
||||
*/
|
||||
public function getShipDate() {
|
||||
return $this->ship_date;
|
||||
}
|
||||
|
||||
/**
|
||||
* set ship_date
|
||||
* @param \DateTime $ship_date
|
||||
* @return $this
|
||||
*/
|
||||
public function setShipDate($ship_date) {
|
||||
$this->ship_date = $ship_date;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* get status
|
||||
* @return string
|
||||
*/
|
||||
public function getStatus() {
|
||||
return $this->status;
|
||||
}
|
||||
|
||||
/**
|
||||
* set status
|
||||
* @param string $status
|
||||
* @return $this
|
||||
*/
|
||||
public function setStatus($status) {
|
||||
$this->status = $status;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* get complete
|
||||
* @return bool
|
||||
*/
|
||||
public function getComplete() {
|
||||
return $this->complete;
|
||||
}
|
||||
|
||||
/**
|
||||
* set complete
|
||||
* @param bool $complete
|
||||
* @return $this
|
||||
*/
|
||||
public function setComplete($complete) {
|
||||
$this->complete = $complete;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function offsetExists($offset) {
|
||||
return isset($this->$offset);
|
||||
}
|
||||
|
||||
public function offsetGet($offset) {
|
||||
return $this->$offset;
|
||||
}
|
||||
|
||||
public function offsetSet($offset, $value) {
|
||||
$this->$offset = $value;
|
||||
}
|
||||
|
||||
public function offsetUnset($offset) {
|
||||
unset($this->$offset);
|
||||
}
|
||||
|
||||
public function __toString() {
|
||||
if (defined('JSON_PRETTY_PRINT')) {
|
||||
return json_encode($this, JSON_PRETTY_PRINT);
|
||||
} else {
|
||||
return json_encode($this);
|
||||
|
||||
/**
|
||||
* Gets id
|
||||
* @return int
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets id
|
||||
* @param int $id
|
||||
* @return $this
|
||||
*/
|
||||
public function setId($id)
|
||||
{
|
||||
|
||||
$this->id = $id;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets pet_id
|
||||
* @return int
|
||||
*/
|
||||
public function getPetId()
|
||||
{
|
||||
return $this->pet_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets pet_id
|
||||
* @param int $pet_id
|
||||
* @return $this
|
||||
*/
|
||||
public function setPetId($pet_id)
|
||||
{
|
||||
|
||||
$this->pet_id = $pet_id;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets quantity
|
||||
* @return int
|
||||
*/
|
||||
public function getQuantity()
|
||||
{
|
||||
return $this->quantity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets quantity
|
||||
* @param int $quantity
|
||||
* @return $this
|
||||
*/
|
||||
public function setQuantity($quantity)
|
||||
{
|
||||
|
||||
$this->quantity = $quantity;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets ship_date
|
||||
* @return \DateTime
|
||||
*/
|
||||
public function getShipDate()
|
||||
{
|
||||
return $this->ship_date;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets ship_date
|
||||
* @param \DateTime $ship_date
|
||||
* @return $this
|
||||
*/
|
||||
public function setShipDate($ship_date)
|
||||
{
|
||||
|
||||
$this->ship_date = $ship_date;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets status
|
||||
* @return string
|
||||
*/
|
||||
public function getStatus()
|
||||
{
|
||||
return $this->status;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets status
|
||||
* @param string $status Order Status
|
||||
* @return $this
|
||||
*/
|
||||
public function setStatus($status)
|
||||
{
|
||||
$allowed_values = array("placed", "approved", "delivered");
|
||||
if (!in_array($status, $allowed_values)) {
|
||||
throw new \InvalidArgumentException("Invalid value for 'status', must be one of 'placed', 'approved', 'delivered'");
|
||||
}
|
||||
$this->status = $status;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets complete
|
||||
* @return bool
|
||||
*/
|
||||
public function getComplete()
|
||||
{
|
||||
return $this->complete;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets complete
|
||||
* @param bool $complete
|
||||
* @return $this
|
||||
*/
|
||||
public function setComplete($complete)
|
||||
{
|
||||
|
||||
$this->complete = $complete;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if offset exists. False otherwise.
|
||||
* @param integer $offset Offset
|
||||
* @return boolean
|
||||
*/
|
||||
public function offsetExists($offset)
|
||||
{
|
||||
return isset($this->$offset);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets offset.
|
||||
* @param integer $offset Offset
|
||||
* @return mixed
|
||||
*/
|
||||
public function offsetGet($offset)
|
||||
{
|
||||
return $this->$offset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets value based on offset.
|
||||
* @param integer $offset Offset
|
||||
* @param mixed $value Value to be set
|
||||
* @return void
|
||||
*/
|
||||
public function offsetSet($offset, $value)
|
||||
{
|
||||
$this->$offset = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Unsets offset.
|
||||
* @param integer $offset Offset
|
||||
* @return void
|
||||
*/
|
||||
public function offsetUnset($offset)
|
||||
{
|
||||
unset($this->$offset);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the string presentation of the object
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
if (defined('JSON_PRETTY_PRINT')) {
|
||||
return json_encode(get_object_vars($this), JSON_PRETTY_PRINT);
|
||||
} else {
|
||||
return json_encode(get_object_vars($this));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user