forked from loafle/openapi-generator-original
Merge branch 'develop_2.0' of https://github.com/swagger-api/swagger-codegen into develop_2.0-fork
This commit is contained in:
commit
ea76f34de5
1
.gitignore
vendored
1
.gitignore
vendored
@ -9,6 +9,7 @@ version.properties
|
|||||||
lib/*
|
lib/*
|
||||||
build/*
|
build/*
|
||||||
generated-files/*
|
generated-files/*
|
||||||
|
generated-sources/*
|
||||||
generated-code/*
|
generated-code/*
|
||||||
*.swp
|
*.swp
|
||||||
*.swo
|
*.swo
|
||||||
|
41
modules/swagger-codegen-maven-plugin/README.md
Normal file
41
modules/swagger-codegen-maven-plugin/README.md
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
swagger-codegen-maven-plugin
|
||||||
|
============================
|
||||||
|
|
||||||
|
A Maven plugin to support the [swagger](http://swagger.io) code generation project
|
||||||
|
|
||||||
|
Usage
|
||||||
|
============================
|
||||||
|
|
||||||
|
Add to your `build->plugins` section (default phase is `generate-sources` phase)
|
||||||
|
```xml
|
||||||
|
<plugin>
|
||||||
|
<groupId>io.swagger</groupId>
|
||||||
|
<artifactId>swagger-codegen-maven-plugin</artifactId>
|
||||||
|
<version>${project.version}</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<goals>
|
||||||
|
<goal>generate</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<inputSpec>src/main/resources/api.yaml</inputSpec>
|
||||||
|
<language>java</language>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
```
|
||||||
|
|
||||||
|
Followed by:
|
||||||
|
|
||||||
|
```
|
||||||
|
mvn clean compile
|
||||||
|
```
|
||||||
|
|
||||||
|
### Configuration parameters
|
||||||
|
|
||||||
|
- `inputSpec` - swagger spec file path
|
||||||
|
- `language` - target generation language
|
||||||
|
- `output` - target output path (default is `${project.build.directory}/generated-sources/swagger`)
|
||||||
|
- `templateDirectory` - directory with mustache templates
|
||||||
|
- `addCompileSourceRoot` - add the output directory to the project as a source root (`true` by default)
|
87
modules/swagger-codegen-maven-plugin/pom.xml
Normal file
87
modules/swagger-codegen-maven-plugin/pom.xml
Normal file
@ -0,0 +1,87 @@
|
|||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||||
|
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<parent>
|
||||||
|
<groupId>io.swagger</groupId>
|
||||||
|
<artifactId>swagger-codegen-project</artifactId>
|
||||||
|
<version>2.1.3-SNAPSHOT</version>
|
||||||
|
<relativePath>../..</relativePath>
|
||||||
|
</parent>
|
||||||
|
<artifactId>swagger-codegen-maven-plugin</artifactId>
|
||||||
|
<name>swagger-codegen (maven-plugin)</name>
|
||||||
|
<packaging>maven-plugin</packaging>
|
||||||
|
<description>maven plugin to build modules from swagger codegen</description>
|
||||||
|
<properties>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
</properties>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.maven</groupId>
|
||||||
|
<artifactId>maven-core</artifactId>
|
||||||
|
<version>3.2.5</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.maven</groupId>
|
||||||
|
<artifactId>maven-artifact</artifactId>
|
||||||
|
<version>3.2.5</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.maven</groupId>
|
||||||
|
<artifactId>maven-compat</artifactId>
|
||||||
|
<version>3.2.5</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.maven</groupId>
|
||||||
|
<artifactId>maven-plugin-api</artifactId>
|
||||||
|
<version>3.2.5</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.maven.plugin-tools</groupId>
|
||||||
|
<artifactId>maven-plugin-annotations</artifactId>
|
||||||
|
<version>3.4</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.swagger</groupId>
|
||||||
|
<artifactId>swagger-codegen</artifactId>
|
||||||
|
<version>${project.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>junit</groupId>
|
||||||
|
<artifactId>junit</artifactId>
|
||||||
|
<version>4.12</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
<build>
|
||||||
|
<pluginManagement>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-plugin-plugin</artifactId>
|
||||||
|
<version>3.4</version>
|
||||||
|
<configuration>
|
||||||
|
<skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound>
|
||||||
|
</configuration>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>mojo-descriptor</id>
|
||||||
|
<phase>process-classes</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>descriptor</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
<execution>
|
||||||
|
<id>help-goal</id>
|
||||||
|
<goals>
|
||||||
|
<goal>helpmojo</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</pluginManagement>
|
||||||
|
</build>
|
||||||
|
</project>
|
@ -0,0 +1,16 @@
|
|||||||
|
package io.swagger.codegen.plugin;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* User: lanwen
|
||||||
|
* Date: 24.03.15
|
||||||
|
* Time: 14:47
|
||||||
|
*/
|
||||||
|
public final class AdditionalParams {
|
||||||
|
public static final String TEMPLATE_DIR_PARAM = "templateDir";
|
||||||
|
|
||||||
|
private AdditionalParams() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,118 @@
|
|||||||
|
package io.swagger.codegen.plugin;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright 2001-2005 The Apache Software Foundation.
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import io.swagger.codegen.ClientOptInput;
|
||||||
|
import io.swagger.codegen.ClientOpts;
|
||||||
|
import io.swagger.codegen.CodegenConfig;
|
||||||
|
import io.swagger.codegen.DefaultGenerator;
|
||||||
|
import io.swagger.models.Swagger;
|
||||||
|
import io.swagger.parser.SwaggerParser;
|
||||||
|
import org.apache.maven.plugin.AbstractMojo;
|
||||||
|
import org.apache.maven.plugin.MojoExecutionException;
|
||||||
|
import org.apache.maven.plugins.annotations.LifecyclePhase;
|
||||||
|
import org.apache.maven.plugins.annotations.Mojo;
|
||||||
|
import org.apache.maven.plugins.annotations.Parameter;
|
||||||
|
import org.apache.maven.project.MavenProject;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.ServiceLoader;
|
||||||
|
|
||||||
|
import static io.swagger.codegen.plugin.AdditionalParams.TEMPLATE_DIR_PARAM;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Goal which generates client/server code from a swagger json/yaml definition.
|
||||||
|
*/
|
||||||
|
@Mojo(name = "generate", defaultPhase = LifecyclePhase.GENERATE_SOURCES)
|
||||||
|
public class CodeGenMojo extends AbstractMojo {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Location of the output directory.
|
||||||
|
*/
|
||||||
|
@Parameter(name = "output",
|
||||||
|
property = "swagger.codegen.maven.plugin.output",
|
||||||
|
defaultValue = "${project.build.directory}/generated-sources/swagger")
|
||||||
|
private File output;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Location of the swagger spec, as URL or file.
|
||||||
|
*/
|
||||||
|
@Parameter(name = "inputSpec", required = true)
|
||||||
|
private String inputSpec;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Folder containing the template files.
|
||||||
|
*/
|
||||||
|
@Parameter(name = "templateDirectory")
|
||||||
|
private File templateDirectory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Client language to generate.
|
||||||
|
*/
|
||||||
|
@Parameter(name = "language", required = true)
|
||||||
|
private String language;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add the output directory to the project as a source root, so that the
|
||||||
|
* generated java types are compiled and included in the project artifact.
|
||||||
|
*/
|
||||||
|
@Parameter(defaultValue = "true")
|
||||||
|
private boolean addCompileSourceRoot = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The project being built.
|
||||||
|
*/
|
||||||
|
@Parameter(readonly = true, required = true, defaultValue = "${project}")
|
||||||
|
private MavenProject project;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute() throws MojoExecutionException {
|
||||||
|
Swagger swagger = new SwaggerParser().read(inputSpec);
|
||||||
|
|
||||||
|
CodegenConfig config = forName(language);
|
||||||
|
config.setOutputDir(output.getAbsolutePath());
|
||||||
|
|
||||||
|
if (null != templateDirectory) {
|
||||||
|
config.additionalProperties().put(TEMPLATE_DIR_PARAM, templateDirectory.getAbsolutePath());
|
||||||
|
}
|
||||||
|
|
||||||
|
ClientOptInput input = new ClientOptInput().opts(new ClientOpts()).swagger(swagger);
|
||||||
|
input.setConfig(config);
|
||||||
|
new DefaultGenerator().opts(input).generate();
|
||||||
|
|
||||||
|
if (addCompileSourceRoot) {
|
||||||
|
project.addCompileSourceRoot(output.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private CodegenConfig forName(String name) {
|
||||||
|
ServiceLoader<CodegenConfig> loader = ServiceLoader.load(CodegenConfig.class);
|
||||||
|
for (CodegenConfig config : loader) {
|
||||||
|
if (config.getName().equals(name)) {
|
||||||
|
return config;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// else try to load directly
|
||||||
|
try {
|
||||||
|
return (CodegenConfig) Class.forName(name).newInstance();
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException("Can't load config class with name ".concat(name), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -145,6 +145,10 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
// replace - with _ e.g. created-at => created_at
|
// replace - with _ e.g. created-at => created_at
|
||||||
name = name.replaceAll("-", "_");
|
name = name.replaceAll("-", "_");
|
||||||
|
|
||||||
|
if("_".equals(name)) {
|
||||||
|
name = "_u";
|
||||||
|
}
|
||||||
|
|
||||||
// if it's all uppper case, do nothing
|
// if it's all uppper case, do nothing
|
||||||
if (name.matches("^[A-Z_]*$")) {
|
if (name.matches("^[A-Z_]*$")) {
|
||||||
return name;
|
return name;
|
||||||
|
@ -143,8 +143,10 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
supportingFiles.add(new SupportingFile("SWGObject.m", sourceFolder, "SWGObject.m"));
|
supportingFiles.add(new SupportingFile("SWGObject.m", sourceFolder, "SWGObject.m"));
|
||||||
supportingFiles.add(new SupportingFile("SWGQueryParamCollection.h", sourceFolder, "SWGQueryParamCollection.h"));
|
supportingFiles.add(new SupportingFile("SWGQueryParamCollection.h", sourceFolder, "SWGQueryParamCollection.h"));
|
||||||
supportingFiles.add(new SupportingFile("SWGQueryParamCollection.m", sourceFolder, "SWGQueryParamCollection.m"));
|
supportingFiles.add(new SupportingFile("SWGQueryParamCollection.m", sourceFolder, "SWGQueryParamCollection.m"));
|
||||||
supportingFiles.add(new SupportingFile("SWGApiClient.h", sourceFolder, "SWGApiClient.h"));
|
supportingFiles.add(new SupportingFile("SWGApiClient-header.mustache", sourceFolder, "SWGApiClient.h"));
|
||||||
supportingFiles.add(new SupportingFile("SWGApiClient.m", sourceFolder, "SWGApiClient.m"));
|
supportingFiles.add(new SupportingFile("SWGApiClient-body.mustache", sourceFolder, "SWGApiClient.m"));
|
||||||
|
supportingFiles.add(new SupportingFile("SWGJSONResponseSerializer-header.mustache", sourceFolder, "SWGJSONResponseSerializer.h"));
|
||||||
|
supportingFiles.add(new SupportingFile("SWGJSONResponseSerializer-body.mustache", sourceFolder, "SWGJSONResponseSerializer.m"));
|
||||||
supportingFiles.add(new SupportingFile("SWGFile.h", sourceFolder, "SWGFile.h"));
|
supportingFiles.add(new SupportingFile("SWGFile.h", sourceFolder, "SWGFile.h"));
|
||||||
supportingFiles.add(new SupportingFile("SWGFile.m", sourceFolder, "SWGFile.m"));
|
supportingFiles.add(new SupportingFile("SWGFile.m", sourceFolder, "SWGFile.m"));
|
||||||
supportingFiles.add(new SupportingFile("JSONValueTransformer+ISO8601.m", sourceFolder, "JSONValueTransformer+ISO8601.m"));
|
supportingFiles.add(new SupportingFile("JSONValueTransformer+ISO8601.m", sourceFolder, "JSONValueTransformer+ISO8601.m"));
|
||||||
@ -215,6 +217,16 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return getSwaggerType(p) + "<" + innerTypeDeclaration + ">*";
|
return getSwaggerType(p) + "<" + innerTypeDeclaration + ">*";
|
||||||
|
} else if (p instanceof MapProperty) {
|
||||||
|
MapProperty mp = (MapProperty) p;
|
||||||
|
Property inner = mp.getAdditionalProperties();
|
||||||
|
|
||||||
|
String innerTypeDeclaration = getTypeDeclaration(inner);
|
||||||
|
|
||||||
|
if (innerTypeDeclaration.endsWith("*")) {
|
||||||
|
innerTypeDeclaration = innerTypeDeclaration.substring(0, innerTypeDeclaration.length() - 1);
|
||||||
|
}
|
||||||
|
return getSwaggerType(p) + "* /* NSString, " + innerTypeDeclaration + " */";
|
||||||
} else {
|
} else {
|
||||||
String swaggerType = getSwaggerType(p);
|
String swaggerType = getSwaggerType(p);
|
||||||
|
|
||||||
|
@ -7,16 +7,16 @@ import io.swagger.codegen.SupportingFile;
|
|||||||
import io.swagger.models.properties.ArrayProperty;
|
import io.swagger.models.properties.ArrayProperty;
|
||||||
import io.swagger.models.properties.MapProperty;
|
import io.swagger.models.properties.MapProperty;
|
||||||
import io.swagger.models.properties.Property;
|
import io.swagger.models.properties.Property;
|
||||||
|
import io.swagger.codegen.CliOption;
|
||||||
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
|
||||||
public class PerlClientCodegen extends DefaultCodegen implements CodegenConfig {
|
public class PerlClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||||
protected String invokerPackage = "SwaggerClient";
|
protected String moduleName = "SwaggerClient";
|
||||||
protected String groupId = "io.swagger";
|
protected String moduleVersion = "1.0.0";
|
||||||
protected String artifactId = "swagger-client";
|
|
||||||
protected String artifactVersion = "1.0.0";
|
|
||||||
|
|
||||||
public PerlClientCodegen() {
|
public PerlClientCodegen() {
|
||||||
super();
|
super();
|
||||||
@ -26,8 +26,6 @@ public class PerlClientCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
apiTemplateFiles.put("api.mustache", ".pm");
|
apiTemplateFiles.put("api.mustache", ".pm");
|
||||||
templateDir = "perl";
|
templateDir = "perl";
|
||||||
|
|
||||||
typeMapping.clear();
|
|
||||||
languageSpecificPrimitives.clear();
|
|
||||||
|
|
||||||
reservedWords = new HashSet<String>(
|
reservedWords = new HashSet<String>(
|
||||||
Arrays.asList(
|
Arrays.asList(
|
||||||
@ -44,11 +42,7 @@ public class PerlClientCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
additionalProperties.put("invokerPackage", invokerPackage);
|
languageSpecificPrimitives.clear();
|
||||||
additionalProperties.put("groupId", groupId);
|
|
||||||
additionalProperties.put("artifactId", artifactId);
|
|
||||||
additionalProperties.put("artifactVersion", artifactVersion);
|
|
||||||
|
|
||||||
languageSpecificPrimitives.add("int");
|
languageSpecificPrimitives.add("int");
|
||||||
languageSpecificPrimitives.add("double");
|
languageSpecificPrimitives.add("double");
|
||||||
languageSpecificPrimitives.add("string");
|
languageSpecificPrimitives.add("string");
|
||||||
@ -58,6 +52,7 @@ public class PerlClientCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
languageSpecificPrimitives.add("HASH");
|
languageSpecificPrimitives.add("HASH");
|
||||||
languageSpecificPrimitives.add("object");
|
languageSpecificPrimitives.add("object");
|
||||||
|
|
||||||
|
typeMapping.clear();
|
||||||
typeMapping.put("integer", "int");
|
typeMapping.put("integer", "int");
|
||||||
typeMapping.put("long", "int");
|
typeMapping.put("long", "int");
|
||||||
typeMapping.put("float", "double");
|
typeMapping.put("float", "double");
|
||||||
@ -71,9 +66,31 @@ public class PerlClientCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
typeMapping.put("map", "HASH");
|
typeMapping.put("map", "HASH");
|
||||||
typeMapping.put("object", "object");
|
typeMapping.put("object", "object");
|
||||||
|
|
||||||
supportingFiles.add(new SupportingFile("ApiClient.mustache", ("lib/WWW/" + invokerPackage).replace('/', File.separatorChar), "ApiClient.pm"));
|
cliOptions.clear();
|
||||||
supportingFiles.add(new SupportingFile("Configuration.mustache", ("lib/WWW/" + invokerPackage).replace('/', File.separatorChar), "Configuration.pm"));
|
cliOptions.add(new CliOption("moduleName", "perl module name (convention: CamelCase), default: SwaggerClient"));
|
||||||
supportingFiles.add(new SupportingFile("BaseObject.mustache", ("lib/WWW/" + invokerPackage).replace('/', File.separatorChar), "Object/BaseObject.pm"));
|
cliOptions.add(new CliOption("moduleVersion", "perl module version, default: 1.0.0"));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void processOpts() {
|
||||||
|
super.processOpts();
|
||||||
|
|
||||||
|
if (additionalProperties.containsKey("moduleVersion")) {
|
||||||
|
moduleVersion = (String) additionalProperties.get("moduleVersion");
|
||||||
|
} else {
|
||||||
|
additionalProperties.put("moduleVersion", moduleVersion);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (additionalProperties.containsKey("moduleName")) {
|
||||||
|
moduleName = (String) additionalProperties.get("moduleName");
|
||||||
|
} else {
|
||||||
|
additionalProperties.put("moduleName", moduleName);
|
||||||
|
}
|
||||||
|
|
||||||
|
supportingFiles.add(new SupportingFile("ApiClient.mustache", ("lib/WWW/" + moduleName).replace('/', File.separatorChar), "ApiClient.pm"));
|
||||||
|
supportingFiles.add(new SupportingFile("Configuration.mustache", ("lib/WWW/" + moduleName).replace('/', File.separatorChar), "Configuration.pm"));
|
||||||
|
supportingFiles.add(new SupportingFile("BaseObject.mustache", ("lib/WWW/" + moduleName).replace('/', File.separatorChar), "Object/BaseObject.pm"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public CodegenType getTag() {
|
public CodegenType getTag() {
|
||||||
@ -95,11 +112,11 @@ public class PerlClientCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String apiFileFolder() {
|
public String apiFileFolder() {
|
||||||
return (outputFolder + "/lib/WWW/" + invokerPackage + apiPackage()).replace('/', File.separatorChar);
|
return (outputFolder + "/lib/WWW/" + moduleName + apiPackage()).replace('/', File.separatorChar);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String modelFileFolder() {
|
public String modelFileFolder() {
|
||||||
return (outputFolder + "/lib/WWW/" + invokerPackage + modelPackage()).replace('/', File.separatorChar);
|
return (outputFolder + "/lib/WWW/" + moduleName + modelPackage()).replace('/', File.separatorChar);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -7,6 +7,7 @@ import io.swagger.codegen.SupportingFile;
|
|||||||
import io.swagger.models.properties.ArrayProperty;
|
import io.swagger.models.properties.ArrayProperty;
|
||||||
import io.swagger.models.properties.MapProperty;
|
import io.swagger.models.properties.MapProperty;
|
||||||
import io.swagger.models.properties.Property;
|
import io.swagger.models.properties.Property;
|
||||||
|
import io.swagger.models.properties.RefProperty;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@ -14,24 +15,20 @@ import java.util.HashMap;
|
|||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
|
||||||
public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig {
|
public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||||
protected String invokerPackage = "io.swagger.client";
|
protected String invokerPackage = "Swagger\\Client";
|
||||||
protected String groupId = "io.swagger";
|
protected String groupId = "swagger";
|
||||||
protected String artifactId = "swagger-client";
|
protected String artifactId = "swagger-client";
|
||||||
protected String artifactVersion = "1.0.0";
|
protected String artifactVersion = null;
|
||||||
|
|
||||||
public PhpClientCodegen() {
|
public PhpClientCodegen() {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
invokerPackage = camelize("SwaggerClient");
|
|
||||||
|
|
||||||
String packagePath = invokerPackage + "-php";
|
|
||||||
|
|
||||||
modelPackage = packagePath + "/lib/models";
|
|
||||||
apiPackage = packagePath + "/lib";
|
|
||||||
outputFolder = "generated-code/php";
|
outputFolder = "generated-code/php";
|
||||||
modelTemplateFiles.put("model.mustache", ".php");
|
modelTemplateFiles.put("model.mustache", ".php");
|
||||||
apiTemplateFiles.put("api.mustache", ".php");
|
apiTemplateFiles.put("api.mustache", ".php");
|
||||||
templateDir = "php";
|
templateDir = "php";
|
||||||
|
apiPackage = invokerPackage + "\\Api";
|
||||||
|
modelPackage = invokerPackage + "\\Model";
|
||||||
|
|
||||||
reservedWords = new HashSet<String>(
|
reservedWords = new HashSet<String>(
|
||||||
Arrays.asList(
|
Arrays.asList(
|
||||||
@ -39,6 +36,9 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
);
|
);
|
||||||
|
|
||||||
additionalProperties.put("invokerPackage", invokerPackage);
|
additionalProperties.put("invokerPackage", invokerPackage);
|
||||||
|
additionalProperties.put("modelPackage", modelPackage);
|
||||||
|
additionalProperties.put("apiPackage", apiPackage);
|
||||||
|
additionalProperties.put("escapedInvokerPackage", invokerPackage.replace("\\", "\\\\"));
|
||||||
additionalProperties.put("groupId", groupId);
|
additionalProperties.put("groupId", groupId);
|
||||||
additionalProperties.put("artifactId", artifactId);
|
additionalProperties.put("artifactId", artifactId);
|
||||||
additionalProperties.put("artifactVersion", artifactVersion);
|
additionalProperties.put("artifactVersion", artifactVersion);
|
||||||
@ -46,6 +46,7 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
// ref: http://php.net/manual/en/language.types.intro.php
|
// ref: http://php.net/manual/en/language.types.intro.php
|
||||||
languageSpecificPrimitives = new HashSet<String>(
|
languageSpecificPrimitives = new HashSet<String>(
|
||||||
Arrays.asList(
|
Arrays.asList(
|
||||||
|
"bool",
|
||||||
"boolean",
|
"boolean",
|
||||||
"int",
|
"int",
|
||||||
"integer",
|
"integer",
|
||||||
@ -55,7 +56,9 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
"object",
|
"object",
|
||||||
"DateTime",
|
"DateTime",
|
||||||
"mixed",
|
"mixed",
|
||||||
"number")
|
"number",
|
||||||
|
"void",
|
||||||
|
"byte")
|
||||||
);
|
);
|
||||||
|
|
||||||
instantiationTypes.put("array", "array");
|
instantiationTypes.put("array", "array");
|
||||||
@ -69,20 +72,40 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
typeMapping.put("double", "double");
|
typeMapping.put("double", "double");
|
||||||
typeMapping.put("string", "string");
|
typeMapping.put("string", "string");
|
||||||
typeMapping.put("byte", "int");
|
typeMapping.put("byte", "int");
|
||||||
typeMapping.put("boolean", "boolean");
|
typeMapping.put("boolean", "bool");
|
||||||
typeMapping.put("date", "DateTime");
|
typeMapping.put("date", "\\DateTime");
|
||||||
typeMapping.put("datetime", "DateTime");
|
typeMapping.put("datetime", "\\DateTime");
|
||||||
typeMapping.put("file", "string");
|
typeMapping.put("file", "string");
|
||||||
typeMapping.put("map", "map");
|
typeMapping.put("map", "map");
|
||||||
typeMapping.put("array", "array");
|
typeMapping.put("array", "array");
|
||||||
typeMapping.put("list", "array");
|
typeMapping.put("list", "array");
|
||||||
typeMapping.put("object", "object");
|
typeMapping.put("object", "object");
|
||||||
|
typeMapping.put("DateTime", "\\DateTime");
|
||||||
|
|
||||||
supportingFiles.add(new SupportingFile("composer.mustache", packagePath.replace('/', File.separatorChar), "composer.json"));
|
supportingFiles.add(new SupportingFile("composer.mustache", getPackagePath(), "composer.json"));
|
||||||
supportingFiles.add(new SupportingFile("configuration.mustache", (packagePath + "/lib").replace('/', File.separatorChar), "Configuration.php"));
|
supportingFiles.add(new SupportingFile("configuration.mustache", toPackagePath(invokerPackage, "lib"), "Configuration.php"));
|
||||||
supportingFiles.add(new SupportingFile("ApiClient.mustache", (packagePath + "/lib").replace('/', File.separatorChar), "ApiClient.php"));
|
supportingFiles.add(new SupportingFile("ApiClient.mustache", toPackagePath(invokerPackage, "lib"), "ApiClient.php"));
|
||||||
supportingFiles.add(new SupportingFile("ApiException.mustache", (packagePath + "/lib").replace('/', File.separatorChar), "ApiException.php"));
|
supportingFiles.add(new SupportingFile("ApiException.mustache", toPackagePath(invokerPackage, "lib"), "ApiException.php"));
|
||||||
supportingFiles.add(new SupportingFile("require.mustache", packagePath.replace('/', File.separatorChar), invokerPackage + ".php"));
|
supportingFiles.add(new SupportingFile("autoload.mustache", getPackagePath(), "autoload.php"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPackagePath() {
|
||||||
|
return "SwaggerClient-php";
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toPackagePath(String packageName, String basePath) {
|
||||||
|
packageName = packageName.replace(invokerPackage, "");
|
||||||
|
if (basePath != null && basePath.length() > 0) {
|
||||||
|
basePath = basePath.replaceAll("[\\\\/]?$", "") + File.separatorChar;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (getPackagePath() + File.separatorChar + basePath
|
||||||
|
// Replace period, backslash, forward slash with file separator in package name
|
||||||
|
+ packageName.replaceAll("[\\.\\\\/]", File.separator)
|
||||||
|
// Trim prefix file separators from package path
|
||||||
|
.replaceAll("^" + File.separator, ""))
|
||||||
|
// Trim trailing file separators from the overall path
|
||||||
|
.replaceAll(File.separator + "$", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
public CodegenType getTag() {
|
public CodegenType getTag() {
|
||||||
@ -104,11 +127,11 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String apiFileFolder() {
|
public String apiFileFolder() {
|
||||||
return (outputFolder + "/" + apiPackage()).replace('/', File.separatorChar);
|
return (outputFolder + "/" + toPackagePath(apiPackage(), "lib"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public String modelFileFolder() {
|
public String modelFileFolder() {
|
||||||
return (outputFolder + "/" + modelPackage()).replace('/', File.separatorChar);
|
return (outputFolder + "/" + toPackagePath(modelPackage(), "lib"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -116,15 +139,27 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
if (p instanceof ArrayProperty) {
|
if (p instanceof ArrayProperty) {
|
||||||
ArrayProperty ap = (ArrayProperty) p;
|
ArrayProperty ap = (ArrayProperty) p;
|
||||||
Property inner = ap.getItems();
|
Property inner = ap.getItems();
|
||||||
return getSwaggerType(p) + "[" + getTypeDeclaration(inner) + "]";
|
return getTypeDeclaration(inner) + "[]";
|
||||||
} else if (p instanceof MapProperty) {
|
} else if (p instanceof MapProperty) {
|
||||||
MapProperty mp = (MapProperty) p;
|
MapProperty mp = (MapProperty) p;
|
||||||
Property inner = mp.getAdditionalProperties();
|
Property inner = mp.getAdditionalProperties();
|
||||||
return getSwaggerType(p) + "[string," + getTypeDeclaration(inner) + "]";
|
return getSwaggerType(p) + "[string," + getTypeDeclaration(inner) + "]";
|
||||||
|
} else if (p instanceof RefProperty) {
|
||||||
|
String type = super.getTypeDeclaration(p);
|
||||||
|
return (!languageSpecificPrimitives.contains(type))
|
||||||
|
? "\\" + modelPackage + "\\" + type : type;
|
||||||
}
|
}
|
||||||
return super.getTypeDeclaration(p);
|
return super.getTypeDeclaration(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getTypeDeclaration(String name) {
|
||||||
|
if (!languageSpecificPrimitives.contains(name)) {
|
||||||
|
return "\\" + modelPackage + "\\" + name;
|
||||||
|
}
|
||||||
|
return super.getTypeDeclaration(name);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getSwaggerType(Property p) {
|
public String getSwaggerType(Property p) {
|
||||||
String swaggerType = super.getSwaggerType(p);
|
String swaggerType = super.getSwaggerType(p);
|
||||||
|
@ -46,12 +46,21 @@ public class RubyClientCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
languageSpecificPrimitives.add("string");
|
languageSpecificPrimitives.add("string");
|
||||||
languageSpecificPrimitives.add("DateTime");
|
languageSpecificPrimitives.add("DateTime");
|
||||||
|
|
||||||
typeMapping.put("long", "int");
|
typeMapping.put("string", "String");
|
||||||
typeMapping.put("integer", "int");
|
typeMapping.put("char", "String");
|
||||||
typeMapping.put("Array", "array");
|
typeMapping.put("int", "Integer");
|
||||||
typeMapping.put("String", "string");
|
typeMapping.put("integer", "Integer");
|
||||||
typeMapping.put("List", "array");
|
typeMapping.put("long", "Integer");
|
||||||
typeMapping.put("map", "map");
|
typeMapping.put("short", "Integer");
|
||||||
|
typeMapping.put("float", "Float");
|
||||||
|
typeMapping.put("double", "Float");
|
||||||
|
typeMapping.put("number", "Float");
|
||||||
|
typeMapping.put("DateTime", "DateTime");
|
||||||
|
typeMapping.put("boolean", "BOOLEAN");
|
||||||
|
typeMapping.put("array", "Array");
|
||||||
|
typeMapping.put("List", "Array");
|
||||||
|
typeMapping.put("map", "Hash");
|
||||||
|
typeMapping.put("object", "Object");
|
||||||
|
|
||||||
// remove modelPackage and apiPackage added by default
|
// remove modelPackage and apiPackage added by default
|
||||||
cliOptions.clear();
|
cliOptions.clear();
|
||||||
@ -102,6 +111,7 @@ public class RubyClientCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
String swaggerFolder = baseFolder + File.separator + "swagger";
|
String swaggerFolder = baseFolder + File.separator + "swagger";
|
||||||
supportingFiles.add(new SupportingFile("swagger" + File.separator + "request.mustache", swaggerFolder, "request.rb"));
|
supportingFiles.add(new SupportingFile("swagger" + File.separator + "request.mustache", swaggerFolder, "request.rb"));
|
||||||
supportingFiles.add(new SupportingFile("swagger" + File.separator + "response.mustache", swaggerFolder, "response.rb"));
|
supportingFiles.add(new SupportingFile("swagger" + File.separator + "response.mustache", swaggerFolder, "response.rb"));
|
||||||
|
supportingFiles.add(new SupportingFile("swagger" + File.separator + "api_error.mustache", swaggerFolder, "api_error.rb"));
|
||||||
supportingFiles.add(new SupportingFile("swagger" + File.separator + "version.mustache", swaggerFolder, "version.rb"));
|
supportingFiles.add(new SupportingFile("swagger" + File.separator + "version.mustache", swaggerFolder, "version.rb"));
|
||||||
supportingFiles.add(new SupportingFile("swagger" + File.separator + "configuration.mustache", swaggerFolder, "configuration.rb"));
|
supportingFiles.add(new SupportingFile("swagger" + File.separator + "configuration.mustache", swaggerFolder, "configuration.rb"));
|
||||||
String modelFolder = baseFolder + File.separator + modelPackage.replace("/", File.separator);
|
String modelFolder = baseFolder + File.separator + modelPackage.replace("/", File.separator);
|
||||||
@ -153,11 +163,11 @@ public class RubyClientCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
if (p instanceof ArrayProperty) {
|
if (p instanceof ArrayProperty) {
|
||||||
ArrayProperty ap = (ArrayProperty) p;
|
ArrayProperty ap = (ArrayProperty) p;
|
||||||
Property inner = ap.getItems();
|
Property inner = ap.getItems();
|
||||||
return getSwaggerType(p) + "[" + getTypeDeclaration(inner) + "]";
|
return getSwaggerType(p) + "<" + getTypeDeclaration(inner) + ">";
|
||||||
} else if (p instanceof MapProperty) {
|
} else if (p instanceof MapProperty) {
|
||||||
MapProperty mp = (MapProperty) p;
|
MapProperty mp = (MapProperty) p;
|
||||||
Property inner = mp.getAdditionalProperties();
|
Property inner = mp.getAdditionalProperties();
|
||||||
return getSwaggerType(p) + "[string," + getTypeDeclaration(inner) + "]";
|
return getSwaggerType(p) + "<String, " + getTypeDeclaration(inner) + ">";
|
||||||
}
|
}
|
||||||
return super.getTypeDeclaration(p);
|
return super.getTypeDeclaration(p);
|
||||||
}
|
}
|
||||||
|
@ -351,171 +351,131 @@ static bool loggingEnabled = true;
|
|||||||
*querys = [NSDictionary dictionaryWithDictionary:querysWithAuth];
|
*querys = [NSDictionary dictionaryWithDictionary:querysWithAuth];
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma mark - Perform Request Methods
|
#pragma mark - Deserialize methods
|
||||||
|
|
||||||
-(NSNumber*) dictionary: (NSString*) path
|
- (id) deserialize:(id) data class:(NSString *) class {
|
||||||
method: (NSString*) method
|
NSRegularExpression *regexp = nil;
|
||||||
queryParams: (NSDictionary*) queryParams
|
NSTextCheckingResult *match = nil;
|
||||||
body: (id) body
|
NSMutableArray *resultArray = nil;
|
||||||
headerParams: (NSDictionary*) headerParams
|
NSMutableDictionary *resultDict = nil;
|
||||||
authSettings: (NSArray *) authSettings
|
|
||||||
requestContentType: (NSString*) requestContentType
|
// return nil if data is nil
|
||||||
responseContentType: (NSString*) responseContentType
|
if (!data) {
|
||||||
completionBlock: (void (^)(NSDictionary*, NSError *))completionBlock {
|
return nil;
|
||||||
// setting request serializer
|
|
||||||
if ([requestContentType isEqualToString:@"application/json"]) {
|
|
||||||
self.requestSerializer = [AFJSONRequestSerializer serializer];
|
|
||||||
}
|
|
||||||
else if ([requestContentType isEqualToString:@"application/x-www-form-urlencoded"]) {
|
|
||||||
self.requestSerializer = [AFHTTPRequestSerializer serializer];
|
|
||||||
}
|
|
||||||
else if ([requestContentType isEqualToString:@"multipart/form-data"]) {
|
|
||||||
self.requestSerializer = [AFHTTPRequestSerializer serializer];
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
NSAssert(false, @"unsupport request type %@", requestContentType);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// setting response serializer
|
// remove "*" from class, if ends with "*"
|
||||||
if ([responseContentType isEqualToString:@"application/json"]) {
|
if ([class hasSuffix:@"*"]) {
|
||||||
self.responseSerializer = [AFJSONResponseSerializer serializer];
|
class = [class substringToIndex:[class length] - 1];
|
||||||
}
|
|
||||||
else {
|
|
||||||
self.responseSerializer = [AFHTTPResponseSerializer serializer];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// auth setting
|
// pure object
|
||||||
[self updateHeaderParams:&headerParams queryParams:&queryParams WithAuthSettings:authSettings];
|
if ([class isEqualToString:@"NSObject"]) {
|
||||||
|
return [[NSObject alloc] init];
|
||||||
NSMutableURLRequest * request = nil;
|
|
||||||
if (body != nil && [body isKindOfClass:[NSArray class]]){
|
|
||||||
SWGFile * file;
|
|
||||||
NSMutableDictionary * params = [[NSMutableDictionary alloc] init];
|
|
||||||
for(id obj in body) {
|
|
||||||
if([obj isKindOfClass:[SWGFile class]]) {
|
|
||||||
file = (SWGFile*) obj;
|
|
||||||
requestContentType = @"multipart/form-data";
|
|
||||||
}
|
|
||||||
else if([obj isKindOfClass:[NSDictionary class]]) {
|
|
||||||
for(NSString * key in obj) {
|
|
||||||
params[key] = obj[key];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
NSString * urlString = [[NSURL URLWithString:path relativeToURL:self.baseURL] absoluteString];
|
|
||||||
|
|
||||||
// request with multipart form
|
|
||||||
if([requestContentType isEqualToString:@"multipart/form-data"]) {
|
|
||||||
request = [self.requestSerializer multipartFormRequestWithMethod: @"POST"
|
|
||||||
URLString: urlString
|
|
||||||
parameters: nil
|
|
||||||
constructingBodyWithBlock: ^(id<AFMultipartFormData> formData) {
|
|
||||||
|
|
||||||
for(NSString * key in params) {
|
|
||||||
NSData* data = [params[key] dataUsingEncoding:NSUTF8StringEncoding];
|
|
||||||
[formData appendPartWithFormData: data name: key];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (file) {
|
// list of models
|
||||||
[formData appendPartWithFileData: [file data]
|
NSString *arrayOfModelsPat = @"NSArray<(.+)>";
|
||||||
name: [file paramName]
|
regexp = [NSRegularExpression regularExpressionWithPattern:arrayOfModelsPat
|
||||||
fileName: [file name]
|
options:NSRegularExpressionCaseInsensitive
|
||||||
mimeType: [file mimeType]];
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
error:nil];
|
error:nil];
|
||||||
}
|
|
||||||
// request with form parameters or json
|
|
||||||
else {
|
|
||||||
NSString* pathWithQueryParams = [self pathWithQueryParamsToString:path queryParams:queryParams];
|
|
||||||
NSString* urlString = [[NSURL URLWithString:pathWithQueryParams relativeToURL:self.baseURL] absoluteString];
|
|
||||||
|
|
||||||
request = [self.requestSerializer requestWithMethod:method
|
match = [regexp firstMatchInString:class
|
||||||
URLString:urlString
|
options:0
|
||||||
parameters:params
|
range:NSMakeRange(0, [class length])];
|
||||||
error:nil];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
NSString * pathWithQueryParams = [self pathWithQueryParamsToString:path queryParams:queryParams];
|
|
||||||
NSString * urlString = [[NSURL URLWithString:pathWithQueryParams relativeToURL:self.baseURL] absoluteString];
|
|
||||||
|
|
||||||
request = [self.requestSerializer requestWithMethod:method
|
if (match) {
|
||||||
URLString:urlString
|
NSString *innerType = [class substringWithRange:[match rangeAtIndex:1]];
|
||||||
parameters:body
|
|
||||||
error:nil];
|
|
||||||
}
|
|
||||||
BOOL hasHeaderParams = false;
|
|
||||||
if(headerParams != nil && [headerParams count] > 0)
|
|
||||||
hasHeaderParams = true;
|
|
||||||
if(offlineState) {
|
|
||||||
NSLog(@"%@ cache forced", path);
|
|
||||||
[request setCachePolicy:NSURLRequestReturnCacheDataDontLoad];
|
|
||||||
}
|
|
||||||
else if(!hasHeaderParams && [method isEqualToString:@"GET"] && cacheEnabled) {
|
|
||||||
NSLog(@"%@ cache enabled", path);
|
|
||||||
[request setCachePolicy:NSURLRequestUseProtocolCachePolicy];
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
NSLog(@"%@ cache disabled", path);
|
|
||||||
[request setCachePolicy:NSURLRequestReloadIgnoringLocalCacheData];
|
|
||||||
}
|
|
||||||
|
|
||||||
if(body != nil) {
|
resultArray = [NSMutableArray arrayWithCapacity:[data count]];
|
||||||
if([body isKindOfClass:[NSDictionary class]] || [body isKindOfClass:[NSArray class]]){
|
[data enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
|
||||||
[self.requestSerializer setValue:requestContentType forHTTPHeaderField:@"Content-Type"];
|
[resultArray addObject:[self deserialize:obj class:innerType]];
|
||||||
}
|
|
||||||
else if ([body isKindOfClass:[SWGFile class]]) {}
|
|
||||||
else {
|
|
||||||
NSAssert(false, @"unsupported post type!");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(headerParams != nil){
|
|
||||||
for(NSString * key in [headerParams keyEnumerator]){
|
|
||||||
[request setValue:[headerParams valueForKey:key] forHTTPHeaderField:key];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
[self.requestSerializer setValue:responseContentType forHTTPHeaderField:@"Accept"];
|
|
||||||
|
|
||||||
// Always disable cookies!
|
|
||||||
[request setHTTPShouldHandleCookies:NO];
|
|
||||||
|
|
||||||
|
|
||||||
if (self.logRequests) {
|
|
||||||
[self logRequest:request];
|
|
||||||
}
|
|
||||||
|
|
||||||
NSNumber* requestId = [SWGApiClient queueRequest];
|
|
||||||
AFHTTPRequestOperation *op =
|
|
||||||
[self HTTPRequestOperationWithRequest:request
|
|
||||||
success:^(AFHTTPRequestOperation *operation, id JSON) {
|
|
||||||
if([self executeRequestWithId:requestId]) {
|
|
||||||
if(self.logServerResponses)
|
|
||||||
[self logResponse:JSON forRequest:request error:nil];
|
|
||||||
completionBlock(JSON, nil);
|
|
||||||
}
|
|
||||||
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
|
|
||||||
if([self executeRequestWithId:requestId]) {
|
|
||||||
NSMutableDictionary *userInfo = [error.userInfo mutableCopy];
|
|
||||||
if(operation.responseObject) {
|
|
||||||
// Add in the (parsed) response body.
|
|
||||||
userInfo[SWGResponseObjectErrorKey] = operation.responseObject;
|
|
||||||
}
|
|
||||||
NSError *augmentedError = [error initWithDomain:error.domain code:error.code userInfo:userInfo];
|
|
||||||
|
|
||||||
if(self.logServerResponses)
|
|
||||||
[self logResponse:nil forRequest:request error:augmentedError];
|
|
||||||
completionBlock(nil, augmentedError);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
[self.operationQueue addOperation:op];
|
return resultArray;
|
||||||
return requestId;
|
}
|
||||||
|
|
||||||
|
// list of primitives
|
||||||
|
NSString *arrayOfPrimitivesPet = @"NSArray";
|
||||||
|
regexp = [NSRegularExpression regularExpressionWithPattern:arrayOfPrimitivesPet
|
||||||
|
options:NSRegularExpressionCaseInsensitive
|
||||||
|
error:nil];
|
||||||
|
match = [regexp firstMatchInString:class
|
||||||
|
options:0
|
||||||
|
range:NSMakeRange(0, [class length])];
|
||||||
|
|
||||||
|
if (match) {
|
||||||
|
resultArray = [NSMutableArray arrayWithCapacity:[data count]];
|
||||||
|
[data enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
|
||||||
|
[resultArray addObject:[self deserialize:obj class:NSStringFromClass([obj class])]];
|
||||||
|
}];
|
||||||
|
|
||||||
|
return resultArray;
|
||||||
|
}
|
||||||
|
|
||||||
|
// map
|
||||||
|
NSString *dictPat = @"NSDictionary\\* /\\* (.+), (.+) \\*/";
|
||||||
|
regexp = [NSRegularExpression regularExpressionWithPattern:dictPat
|
||||||
|
options:NSRegularExpressionCaseInsensitive
|
||||||
|
error:nil];
|
||||||
|
match = [regexp firstMatchInString:class
|
||||||
|
options:0
|
||||||
|
range:NSMakeRange(0, [class length])];
|
||||||
|
|
||||||
|
if (match) {
|
||||||
|
NSString *valueType = [class substringWithRange:[match rangeAtIndex:2]];
|
||||||
|
|
||||||
|
resultDict = [NSMutableDictionary dictionaryWithCapacity:[data count]];
|
||||||
|
[data enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
|
||||||
|
[resultDict setValue:[self deserialize:obj class:valueType] forKey:key];
|
||||||
|
}];
|
||||||
|
|
||||||
|
return resultDict;
|
||||||
|
}
|
||||||
|
|
||||||
|
// primitives
|
||||||
|
NSArray *primitiveTypes = @[@"NSString", @"NSDate", @"BOOL", @"NSNumber"];
|
||||||
|
|
||||||
|
if ([primitiveTypes containsObject:class]) {
|
||||||
|
if ([class isEqualToString:@"NSString"]) {
|
||||||
|
return [NSString stringWithString:data];
|
||||||
|
}
|
||||||
|
else if ([class isEqualToString:@"NSDate"]) {
|
||||||
|
return [NSDate dateWithISO8601String:data];
|
||||||
|
}
|
||||||
|
else if ([class isEqualToString:@"BOOL"]) {
|
||||||
|
// Returns YES on encountering one of "Y", "y", "T", "t", or a
|
||||||
|
// digit 1-9—the method ignores any trailing characters
|
||||||
|
// NSString => BOOL => NSNumber
|
||||||
|
return [NSNumber numberWithBool:[data boolValue]];
|
||||||
|
}
|
||||||
|
else if ([class isEqualToString:@"NSNumber"]) {
|
||||||
|
// NSNumber from NSNumber
|
||||||
|
if ([data isKindOfClass:[NSNumber class]]) {
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
// NSNumber from NSString
|
||||||
|
else {
|
||||||
|
NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
|
||||||
|
formatter.numberStyle = NSNumberFormatterDecimalStyle;
|
||||||
|
return [formatter numberFromString:data];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// model
|
||||||
|
Class ModelClass = NSClassFromString(class);
|
||||||
|
if ([ModelClass instancesRespondToSelector:@selector(initWithDictionary:error:)]) {
|
||||||
|
return [[ModelClass alloc] initWithDictionary:data error:nil];
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
-(NSNumber*) stringWithCompletionBlock: (NSString*) path
|
#pragma mark - Perform Request Methods
|
||||||
|
|
||||||
|
-(NSNumber*) requestWithCompletionBlock: (NSString*) path
|
||||||
method: (NSString*) method
|
method: (NSString*) method
|
||||||
queryParams: (NSDictionary*) queryParams
|
queryParams: (NSDictionary*) queryParams
|
||||||
body: (id) body
|
body: (id) body
|
||||||
@ -523,7 +483,7 @@ static bool loggingEnabled = true;
|
|||||||
authSettings: (NSArray *) authSettings
|
authSettings: (NSArray *) authSettings
|
||||||
requestContentType: (NSString*) requestContentType
|
requestContentType: (NSString*) requestContentType
|
||||||
responseContentType: (NSString*) responseContentType
|
responseContentType: (NSString*) responseContentType
|
||||||
completionBlock: (void (^)(NSString*, NSError *))completionBlock {
|
completionBlock: (void (^)(id, NSError *))completionBlock {
|
||||||
// setting request serializer
|
// setting request serializer
|
||||||
if ([requestContentType isEqualToString:@"application/json"]) {
|
if ([requestContentType isEqualToString:@"application/json"]) {
|
||||||
self.requestSerializer = [AFJSONRequestSerializer serializer];
|
self.requestSerializer = [AFJSONRequestSerializer serializer];
|
||||||
@ -540,7 +500,7 @@ static bool loggingEnabled = true;
|
|||||||
|
|
||||||
// setting response serializer
|
// setting response serializer
|
||||||
if ([responseContentType isEqualToString:@"application/json"]) {
|
if ([responseContentType isEqualToString:@"application/json"]) {
|
||||||
self.responseSerializer = [AFJSONResponseSerializer serializer];
|
self.responseSerializer = [SWGJSONResponseSerializer serializer];
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
self.responseSerializer = [AFHTTPResponseSerializer serializer];
|
self.responseSerializer = [AFHTTPResponseSerializer serializer];
|
||||||
@ -648,11 +608,11 @@ static bool loggingEnabled = true;
|
|||||||
|
|
||||||
NSNumber* requestId = [SWGApiClient queueRequest];
|
NSNumber* requestId = [SWGApiClient queueRequest];
|
||||||
AFHTTPRequestOperation *op = [self HTTPRequestOperationWithRequest:request
|
AFHTTPRequestOperation *op = [self HTTPRequestOperationWithRequest:request
|
||||||
success:^(AFHTTPRequestOperation *operation, id responseObject) {
|
success:^(AFHTTPRequestOperation *operation, id response) {
|
||||||
NSString *response = [operation responseString];
|
|
||||||
if([self executeRequestWithId:requestId]) {
|
if([self executeRequestWithId:requestId]) {
|
||||||
if(self.logServerResponses)
|
if(self.logServerResponses) {
|
||||||
[self logResponse:responseObject forRequest:request error:nil];
|
[self logResponse:response forRequest:request error:nil];
|
||||||
|
}
|
||||||
completionBlock(response, nil);
|
completionBlock(response, nil);
|
||||||
}
|
}
|
||||||
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
|
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
|
||||||
@ -683,3 +643,4 @@ static bool loggingEnabled = true;
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1,5 +1,10 @@
|
|||||||
#import <Foundation/Foundation.h>
|
#import <Foundation/Foundation.h>
|
||||||
|
#import <ISO8601/ISO8601.h>
|
||||||
#import "AFHTTPRequestOperationManager.h"
|
#import "AFHTTPRequestOperationManager.h"
|
||||||
|
#import "SWGJSONResponseSerializer.h"
|
||||||
|
|
||||||
|
{{#models}}{{#model}}#import "{{classname}}.h"
|
||||||
|
{{/model}}{{/models}}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A key for `NSError` user info dictionaries.
|
* A key for `NSError` user info dictionaries.
|
||||||
@ -159,37 +164,16 @@ extern NSString *const SWGResponseObjectErrorKey;
|
|||||||
WithAuthSettings:(NSArray *)authSettings;
|
WithAuthSettings:(NSArray *)authSettings;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Perform request
|
* Deserialize the given data to Objective-C object.
|
||||||
*
|
*
|
||||||
* Request with non-empty response
|
* @param data The data will be deserialized.
|
||||||
*
|
* @param class The type of objective-c object.
|
||||||
* @param path Request url.
|
|
||||||
* @param method Request method.
|
|
||||||
* @param queryParams Request query parameters.
|
|
||||||
* @param body Request body.
|
|
||||||
* @param headerParams Request header parameters.
|
|
||||||
* @param authSettings Request authentication names.
|
|
||||||
* @param requestContentType Request content-type.
|
|
||||||
* @param responseContentType Response content-type.
|
|
||||||
* @param completionBlock The block will be executed when the request completed.
|
|
||||||
*
|
|
||||||
* @return The request id.
|
|
||||||
*/
|
*/
|
||||||
-(NSNumber*) dictionary:(NSString*) path
|
- (id) deserialize:(id) data class:(NSString *) class;
|
||||||
method:(NSString*) method
|
|
||||||
queryParams:(NSDictionary*) queryParams
|
|
||||||
body:(id) body
|
|
||||||
headerParams:(NSDictionary*) headerParams
|
|
||||||
authSettings: (NSArray *) authSettings
|
|
||||||
requestContentType:(NSString*) requestContentType
|
|
||||||
responseContentType:(NSString*) responseContentType
|
|
||||||
completionBlock:(void (^)(NSDictionary*, NSError *))completionBlock;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Perform request
|
* Perform request
|
||||||
*
|
*
|
||||||
* Request with empty response
|
|
||||||
*
|
|
||||||
* @param path Request url.
|
* @param path Request url.
|
||||||
* @param method Request method.
|
* @param method Request method.
|
||||||
* @param queryParams Request query parameters.
|
* @param queryParams Request query parameters.
|
||||||
@ -202,7 +186,7 @@ extern NSString *const SWGResponseObjectErrorKey;
|
|||||||
*
|
*
|
||||||
* @return The request id.
|
* @return The request id.
|
||||||
*/
|
*/
|
||||||
-(NSNumber*) stringWithCompletionBlock:(NSString*) path
|
-(NSNumber*) requestWithCompletionBlock:(NSString*) path
|
||||||
method:(NSString*) method
|
method:(NSString*) method
|
||||||
queryParams:(NSDictionary*) queryParams
|
queryParams:(NSDictionary*) queryParams
|
||||||
body:(id) body
|
body:(id) body
|
||||||
@ -210,7 +194,10 @@ extern NSString *const SWGResponseObjectErrorKey;
|
|||||||
authSettings: (NSArray *) authSettings
|
authSettings: (NSArray *) authSettings
|
||||||
requestContentType:(NSString*) requestContentType
|
requestContentType:(NSString*) requestContentType
|
||||||
responseContentType:(NSString*) responseContentType
|
responseContentType:(NSString*) responseContentType
|
||||||
completionBlock:(void (^)(NSString*, NSError *))completionBlock;
|
completionBlock:(void (^)(id, NSError *))completionBlock;
|
||||||
|
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -0,0 +1,39 @@
|
|||||||
|
#import "SWGJSONResponseSerializer.h"
|
||||||
|
|
||||||
|
static BOOL JSONParseError(NSError *error) {
|
||||||
|
if ([error.domain isEqualToString:NSCocoaErrorDomain] && error.code == 3840) {
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NO;
|
||||||
|
}
|
||||||
|
|
||||||
|
@implementation SWGJSONResponseSerializer
|
||||||
|
|
||||||
|
///
|
||||||
|
/// When customize a response serializer,
|
||||||
|
/// the serializer must conform the protocol `AFURLResponseSerialization`
|
||||||
|
/// and implements the protocol method `responseObjectForResponse:error:`
|
||||||
|
///
|
||||||
|
/// @param response The response to be processed.
|
||||||
|
/// @param data The response data to be decoded.
|
||||||
|
/// @param error The error that occurred while attempting to decode the respnse data.
|
||||||
|
///
|
||||||
|
/// @return The object decoded from the specified response data.
|
||||||
|
///
|
||||||
|
- (id) responseObjectForResponse:(NSURLResponse *)response
|
||||||
|
data:(NSData *)data
|
||||||
|
error:(NSError *__autoreleasing *)error {
|
||||||
|
NSDictionary *responseJson = [super responseObjectForResponse:response data:data error:error];
|
||||||
|
|
||||||
|
// if response data is not a valid json, return string of data.
|
||||||
|
if (JSONParseError(*error)) {
|
||||||
|
*error = nil;
|
||||||
|
NSString *responseString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
|
||||||
|
return responseString;
|
||||||
|
}
|
||||||
|
|
||||||
|
return responseJson;
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
@ -0,0 +1,6 @@
|
|||||||
|
#import <Foundation/Foundation.h>
|
||||||
|
#import <AFNetworking/AFURLResponseSerialization.h>
|
||||||
|
|
||||||
|
@interface SWGJSONResponseSerializer : AFJSONResponseSerializer
|
||||||
|
|
||||||
|
@end
|
@ -72,14 +72,16 @@ static NSString * basePath = @"{{basePath}}";
|
|||||||
return [SWGApiClient requestQueueSize];
|
return [SWGApiClient requestQueueSize];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#pragma mark - Api Methods
|
||||||
|
|
||||||
{{#operation}}
|
{{#operation}}
|
||||||
/*!
|
///
|
||||||
* {{{summary}}}
|
/// {{{summary}}}
|
||||||
* {{{notes}}}
|
/// {{{notes}}}
|
||||||
{{#allParams}} * \param {{paramName}} {{{description}}}
|
/// {{#allParams}} @param {{paramName}} {{{description}}}
|
||||||
{{/allParams}} * \returns {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}}
|
///
|
||||||
*/
|
/// {{/allParams}} @returns {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}}
|
||||||
|
///
|
||||||
-(NSNumber*) {{nickname}}WithCompletionBlock{{^allParams}}: {{/allParams}}{{#allParams}}{{#secondaryParam}} {{paramName}}{{/secondaryParam}}: ({{{dataType}}}) {{paramName}}
|
-(NSNumber*) {{nickname}}WithCompletionBlock{{^allParams}}: {{/allParams}}{{#allParams}}{{#secondaryParam}} {{paramName}}{{/secondaryParam}}: ({{{dataType}}}) {{paramName}}
|
||||||
{{/allParams}}
|
{{/allParams}}
|
||||||
{{#returnBaseType}}{{#hasParams}}completionHandler: {{/hasParams}}(void (^)({{{returnType}}} output, NSError* error))completionBlock{{/returnBaseType}}
|
{{#returnBaseType}}{{#hasParams}}completionHandler: {{/hasParams}}(void (^)({{{returnType}}} output, NSError* error))completionBlock{{/returnBaseType}}
|
||||||
@ -195,27 +197,19 @@ static NSString * basePath = @"{{basePath}}";
|
|||||||
}
|
}
|
||||||
{{/requiredParams}}
|
{{/requiredParams}}
|
||||||
{{/requiredParamCount}}
|
{{/requiredParamCount}}
|
||||||
|
return [self.apiClient requestWithCompletionBlock: requestUrl
|
||||||
{{#returnContainer}}
|
method: @"{{httpMethod}}"
|
||||||
// response is in a container
|
queryParams: queryParams
|
||||||
{{>apiBodyResponseWithContainer}}{{/returnContainer}}
|
body: bodyDictionary
|
||||||
|
headerParams: headerParams
|
||||||
{{#returnSimpleType}}
|
authSettings: authSettings
|
||||||
// non container response
|
requestContentType: requestContentType
|
||||||
|
responseContentType: responseContentType
|
||||||
{{#returnTypeIsPrimitive}}
|
completionBlock: ^(id data, NSError *error) {
|
||||||
// primitive response
|
{{^returnType}}completionBlock(error);{{/returnType}}
|
||||||
{{>apiPrimitiveResponse}}{{/returnTypeIsPrimitive}}
|
{{#returnType}}completionBlock([self.apiClient deserialize: data class:@"{{{returnType}}}"], error);{{/returnType}}
|
||||||
|
}
|
||||||
{{#returnBaseType}}
|
];
|
||||||
// complex response
|
|
||||||
{{>apiNonPrimitiveResponse}}{{/returnBaseType}}
|
|
||||||
{{/returnSimpleType}}
|
|
||||||
|
|
||||||
{{^returnSimpleType}}{{^returnContainer}}
|
|
||||||
// it's void
|
|
||||||
{{>voidResponse}}
|
|
||||||
{{/returnContainer}}{{/returnSimpleType}}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
{{/operation}}
|
{{/operation}}
|
||||||
|
@ -17,16 +17,15 @@
|
|||||||
+(void) setBasePath:(NSString*)basePath;
|
+(void) setBasePath:(NSString*)basePath;
|
||||||
+(NSString*) getBasePath;
|
+(NSString*) getBasePath;
|
||||||
{{#operation}}
|
{{#operation}}
|
||||||
/**
|
///
|
||||||
|
///
|
||||||
{{{summary}}}
|
/// {{{summary}}}
|
||||||
{{#notes}}{{{notes}}}{{/notes}}
|
/// {{#notes}}{{{notes}}}{{/notes}}
|
||||||
|
///
|
||||||
{{#allParams}}@param {{paramName}} {{description}}
|
/// {{#allParams}}@param {{paramName}} {{description}}
|
||||||
{{/allParams}}
|
/// {{/allParams}}
|
||||||
|
///
|
||||||
return type: {{{returnType}}}
|
/// @return {{{returnType}}}
|
||||||
*/
|
|
||||||
-(NSNumber*) {{nickname}}WithCompletionBlock {{^allParams}}:{{/allParams}}{{#allParams}}{{#secondaryParam}} {{paramName}}{{/secondaryParam}}:({{{dataType}}}) {{paramName}} {{#hasMore}}
|
-(NSNumber*) {{nickname}}WithCompletionBlock {{^allParams}}:{{/allParams}}{{#allParams}}{{#secondaryParam}} {{paramName}}{{/secondaryParam}}:({{{dataType}}}) {{paramName}} {{#hasMore}}
|
||||||
{{/hasMore}}{{/allParams}}
|
{{/hasMore}}{{/allParams}}
|
||||||
{{#returnBaseType}}{{#hasParams}}
|
{{#returnBaseType}}{{#hasParams}}
|
||||||
|
@ -1,38 +0,0 @@
|
|||||||
// {{returnContainer}} container response type
|
|
||||||
return [self.apiClient dictionary: requestUrl
|
|
||||||
method: @"{{httpMethod}}"
|
|
||||||
queryParams: queryParams
|
|
||||||
body: bodyDictionary
|
|
||||||
headerParams: headerParams
|
|
||||||
authSettings: authSettings
|
|
||||||
requestContentType: requestContentType
|
|
||||||
responseContentType: responseContentType
|
|
||||||
completionBlock: ^(NSDictionary *data, NSError *error) {
|
|
||||||
if (error) {
|
|
||||||
{{#returnBaseType}}completionBlock(nil, error);{{/returnBaseType}}{{^returnBaseType}}completionBlock(error);{{/returnBaseType}}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
{{#isMapContainer}}
|
|
||||||
NSDictionary *result = nil;
|
|
||||||
if (data) {
|
|
||||||
result = [[NSDictionary alloc]initWithDictionary: data];
|
|
||||||
}
|
|
||||||
completionBlock(data, nil);
|
|
||||||
{{/isMapContainer}}{{#isListContainer}}
|
|
||||||
{{#returnBaseType}}if([data isKindOfClass:[NSArray class]]){
|
|
||||||
NSMutableArray * objs = [[NSMutableArray alloc] initWithCapacity:[data count]];
|
|
||||||
for (NSDictionary* dict in (NSArray*)data) {
|
|
||||||
{{#returnTypeIsPrimitive}}
|
|
||||||
{{returnBaseType}}* d = [[{{{returnBaseType}}} alloc]initWithString: dict];
|
|
||||||
{{/returnTypeIsPrimitive}}
|
|
||||||
{{^returnTypeIsPrimitive}}
|
|
||||||
{{{returnBaseType}}}* d = [[{{{returnBaseType}}} alloc] initWithDictionary:dict error:nil];
|
|
||||||
{{/returnTypeIsPrimitive}}
|
|
||||||
[objs addObject:d];
|
|
||||||
}
|
|
||||||
completionBlock(({{{returnType}}})objs, nil);
|
|
||||||
}
|
|
||||||
{{/returnBaseType}}
|
|
||||||
{{/isListContainer}}
|
|
||||||
}];
|
|
||||||
|
|
@ -1,24 +0,0 @@
|
|||||||
{{^returnTypeIsPrimitive}}
|
|
||||||
// comples response type
|
|
||||||
return [self.apiClient dictionary: requestUrl
|
|
||||||
method: @"{{httpMethod}}"
|
|
||||||
queryParams: queryParams
|
|
||||||
body: bodyDictionary
|
|
||||||
headerParams: headerParams
|
|
||||||
authSettings: authSettings
|
|
||||||
requestContentType: requestContentType
|
|
||||||
responseContentType: responseContentType
|
|
||||||
completionBlock: ^(NSDictionary *data, NSError *error) {
|
|
||||||
if (error) {
|
|
||||||
{{#returnBaseType}}completionBlock(nil, error);{{/returnBaseType}}
|
|
||||||
{{^returnBaseType}}completionBlock(error);{{/returnBaseType}}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
{{#returnType}}{{returnType}} result = nil;
|
|
||||||
if (data) {
|
|
||||||
result = [[{{#instantiationType}}NSClassFromString(@"{{{instantiationType}}}") {{/instantiationType}}{{^instantiationType}}{{{returnBaseType}}} {{/instantiationType}} alloc] {{#returnContainer}}{{#isMapContainer}}initWithDictionary{{/isMapContainer}}{{#isListContainer}} initWithDictionary{{/isListContainer}}{{/returnContainer}}{{^returnContainer}} initWithDictionary{{/returnContainer}}:data error:nil];
|
|
||||||
}
|
|
||||||
{{#returnType}}completionBlock(result , nil);{{/returnType}}
|
|
||||||
{{/returnType}}
|
|
||||||
}];
|
|
||||||
{{/returnTypeIsPrimitive}}
|
|
@ -1,36 +0,0 @@
|
|||||||
// primitive response type
|
|
||||||
{{#returnBaseType}}return [self.apiClient stringWithCompletionBlock: requestUrl
|
|
||||||
method: @"{{httpMethod}}"
|
|
||||||
queryParams: queryParams
|
|
||||||
body: bodyDictionary
|
|
||||||
headerParams: headerParams
|
|
||||||
authSettings: authSettings
|
|
||||||
requestContentType: requestContentType
|
|
||||||
responseContentType: responseContentType
|
|
||||||
completionBlock: ^(NSString *data, NSError *error) {
|
|
||||||
if (error) {
|
|
||||||
completionBlock(nil, error);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
{{returnBaseType}} *result = data ? [[{{#instantiationType}}NSClassFromString(@"{{{instantiationType}}}") {{/instantiationType}}{{^instantiationType}}{{{returnBaseType}}} {{/instantiationType}} alloc]initWithString: data] : nil;
|
|
||||||
completionBlock(result, nil);
|
|
||||||
}];
|
|
||||||
{{/returnBaseType}}
|
|
||||||
{{^returnBaseType}}
|
|
||||||
// no return base type
|
|
||||||
return [self.apiClient stringWithCompletionBlock: requestUrl
|
|
||||||
method: @"{{httpMethod}}"
|
|
||||||
queryParams: queryParams
|
|
||||||
body: bodyDictionary
|
|
||||||
headerParams: headerParams
|
|
||||||
requestContentType: requestContentType
|
|
||||||
responseContentType: responseContentType
|
|
||||||
completionBlock: ^(NSString *data, NSError *error) {
|
|
||||||
if (error) {
|
|
||||||
completionBlock(error);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
completionBlock(nil);
|
|
||||||
}];
|
|
||||||
{{/returnBaseType}}
|
|
||||||
|
|
@ -1,15 +0,0 @@
|
|||||||
return [self.apiClient stringWithCompletionBlock: requestUrl
|
|
||||||
method: @"{{httpMethod}}"
|
|
||||||
queryParams: queryParams
|
|
||||||
body: bodyDictionary
|
|
||||||
headerParams: headerParams
|
|
||||||
authSettings: authSettings
|
|
||||||
requestContentType: requestContentType
|
|
||||||
responseContentType: responseContentType
|
|
||||||
completionBlock: ^(NSString *data, NSError *error) {
|
|
||||||
if (error) {
|
|
||||||
completionBlock(error);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
completionBlock(nil);
|
|
||||||
}];
|
|
@ -1,4 +1,4 @@
|
|||||||
package WWW::{{invokerPackage}}::ApiClient;
|
package WWW::{{moduleName}}::ApiClient;
|
||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
@ -18,7 +18,7 @@ use Log::Any qw($log);
|
|||||||
use Carp;
|
use Carp;
|
||||||
use Module::Runtime qw(use_module);
|
use Module::Runtime qw(use_module);
|
||||||
|
|
||||||
use WWW::{{invokerPackage}}::Configuration;
|
use WWW::{{moduleName}}::Configuration;
|
||||||
|
|
||||||
sub new
|
sub new
|
||||||
{
|
{
|
||||||
@ -115,8 +115,8 @@ sub call_api {
|
|||||||
else {
|
else {
|
||||||
}
|
}
|
||||||
|
|
||||||
$self->{ua}->timeout($self->{http_timeout} || $WWW::{{invokerPackage}}::Configuration::http_timeout);
|
$self->{ua}->timeout($self->{http_timeout} || $WWW::{{moduleName}}::Configuration::http_timeout);
|
||||||
$self->{ua}->agent($self->{http_user_agent} || $WWW::{{invokerPackage}}::Configuration::http_user_agent);
|
$self->{ua}->agent($self->{http_user_agent} || $WWW::{{moduleName}}::Configuration::http_user_agent);
|
||||||
|
|
||||||
my $_response = $self->{ua}->request($_request);
|
my $_response = $self->{ua}->request($_request);
|
||||||
|
|
||||||
@ -237,7 +237,7 @@ sub deserialize
|
|||||||
} elsif (grep /^$class$/, ('string', 'int', 'float', 'bool', 'object')) {
|
} elsif (grep /^$class$/, ('string', 'int', 'float', 'bool', 'object')) {
|
||||||
return $data;
|
return $data;
|
||||||
} else { # model
|
} else { # model
|
||||||
my $_instance = use_module("WWW::SwaggerClient::Object::$class")->new;
|
my $_instance = use_module("WWW::{{moduleName}}::Object::$class")->new;
|
||||||
if (ref $data eq "HASH") {
|
if (ref $data eq "HASH") {
|
||||||
return $_instance->from_hash($data);
|
return $_instance->from_hash($data);
|
||||||
} else { # string, need to json decode first
|
} else { # string, need to json decode first
|
||||||
@ -287,10 +287,10 @@ sub select_header_content_type
|
|||||||
sub get_api_key_with_prefix
|
sub get_api_key_with_prefix
|
||||||
{
|
{
|
||||||
my ($self, $api_key) = @_;
|
my ($self, $api_key) = @_;
|
||||||
if ($WWW::{{invokerPackage}}::Configuration::api_key_prefix->{$api_key}) {
|
if ($WWW::{{moduleName}}::Configuration::api_key_prefix->{$api_key}) {
|
||||||
return $WWW::{{invokerPackage}}::Configuration::api_key_prefix->{$api_key}." ".$WWW::{{invokerPackage}}::Configuration::api_key->{$api_key};
|
return $WWW::{{moduleName}}::Configuration::api_key_prefix->{$api_key}." ".$WWW::{{moduleName}}::Configuration::api_key->{$api_key};
|
||||||
} else {
|
} else {
|
||||||
return $WWW::{{invokerPackage}}::Configuration::api_key->{$api_key};
|
return $WWW::{{moduleName}}::Configuration::api_key->{$api_key};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -310,7 +310,7 @@ sub update_params_for_auth {
|
|||||||
if (!defined($auth)) {
|
if (!defined($auth)) {
|
||||||
}
|
}
|
||||||
{{#authMethods}}elsif ($auth eq '{{name}}') {
|
{{#authMethods}}elsif ($auth eq '{{name}}') {
|
||||||
{{#isApiKey}}{{#isKeyInHeader}}$header_params->{'{{keyParamName}}'} = $self->get_api_key_with_prefix('{{keyParamName}}');{{/isKeyInHeader}}{{#isKeyInQuery}}$query_params->{'{{keyParamName}}'} = $self->get_api_key_with_prefix('{{keyParamName}}');{{/isKeyInQuery}}{{/isApiKey}}{{#isBasic}}$header_params->{'Authorization'} = 'Basic '.encode_base64($WWW::{{invokerPackage}}::Configuration::username.":".$WWW::{{invokerPackage}}::Configuration::password);{{/isBasic}}
|
{{#isApiKey}}{{#isKeyInHeader}}$header_params->{'{{keyParamName}}'} = $self->get_api_key_with_prefix('{{keyParamName}}');{{/isKeyInHeader}}{{#isKeyInQuery}}$query_params->{'{{keyParamName}}'} = $self->get_api_key_with_prefix('{{keyParamName}}');{{/isKeyInQuery}}{{/isApiKey}}{{#isBasic}}$header_params->{'Authorization'} = 'Basic '.encode_base64($WWW::{{moduleName}}::Configuration::username.":".$WWW::{{moduleName}}::Configuration::password);{{/isBasic}}
|
||||||
{{#isOAuth}}# TODO support oauth{{/isOAuth}}
|
{{#isOAuth}}# TODO support oauth{{/isOAuth}}
|
||||||
}
|
}
|
||||||
{{/authMethods}}
|
{{/authMethods}}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package WWW::{{invokerPackage}}::Object::BaseObject;
|
package WWW::{{moduleName}}::Object::BaseObject;
|
||||||
|
|
||||||
require 5.6.0;
|
require 5.6.0;
|
||||||
use strict;
|
use strict;
|
||||||
@ -68,7 +68,7 @@ sub _deserialize {
|
|||||||
} elsif ( grep( /^$type$/, ('int', 'double', 'string', 'boolean'))) {
|
} elsif ( grep( /^$type$/, ('int', 'double', 'string', 'boolean'))) {
|
||||||
return $data;
|
return $data;
|
||||||
} else { # hash(model)
|
} else { # hash(model)
|
||||||
my $_instance = eval "WWW::{{invokerPackage}}::Object::$type->new()";
|
my $_instance = eval "WWW::{{moduleName}}::Object::$type->new()";
|
||||||
return $_instance->from_hash($data);
|
return $_instance->from_hash($data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package WWW::{{invokerPackage}}::Configuration;
|
package WWW::{{moduleName}}::Configuration;
|
||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
@ -7,6 +7,8 @@ use utf8;
|
|||||||
use Log::Any qw($log);
|
use Log::Any qw($log);
|
||||||
use Carp;
|
use Carp;
|
||||||
|
|
||||||
|
use constant VERSION => '{{moduleVersion}}';
|
||||||
|
|
||||||
# class/static variables
|
# class/static variables
|
||||||
our $api_client;
|
our $api_client;
|
||||||
our $http_timeout = 180;
|
our $http_timeout = 180;
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
# NOTE: This class is auto generated by the swagger code generator program.
|
# NOTE: This class is auto generated by the swagger code generator program.
|
||||||
# Do not edit the class manually.
|
# Do not edit the class manually.
|
||||||
#
|
#
|
||||||
package WWW::{{invokerPackage}}::{{classname}};
|
package WWW::{{moduleName}}::{{classname}};
|
||||||
|
|
||||||
require 5.6.0;
|
require 5.6.0;
|
||||||
use strict;
|
use strict;
|
||||||
@ -27,18 +27,12 @@ use Exporter;
|
|||||||
use Carp qw( croak );
|
use Carp qw( croak );
|
||||||
use Log::Any qw($log);
|
use Log::Any qw($log);
|
||||||
|
|
||||||
use WWW::{{invokerPackage}}::ApiClient;
|
use WWW::{{moduleName}}::ApiClient;
|
||||||
use WWW::{{invokerPackage}}::Configuration;
|
use WWW::{{moduleName}}::Configuration;
|
||||||
|
|
||||||
{{#operations}}
|
|
||||||
our @EXPORT_OK = qw(
|
|
||||||
{{#operation}}{{{nickname}}}
|
|
||||||
{{/operation}}
|
|
||||||
);
|
|
||||||
|
|
||||||
sub new {
|
sub new {
|
||||||
my $class = shift;
|
my $class = shift;
|
||||||
my $default_api_client = $WWW::{{invokerPackage}}::Configuration::api_client ? $WWW::{{invokerPackage}}::Configuration::api_client : WWW::{{invokerPackage}}::ApiClient->new;
|
my $default_api_client = $WWW::{{moduleName}}::Configuration::api_client ? $WWW::{{moduleName}}::Configuration::api_client : WWW::{{moduleName}}::ApiClient->new;
|
||||||
my (%self) = (
|
my (%self) = (
|
||||||
'api_client' => $default_api_client,
|
'api_client' => $default_api_client,
|
||||||
@_
|
@_
|
||||||
@ -52,17 +46,18 @@ sub new {
|
|||||||
bless \%self, $class;
|
bless \%self, $class;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
{{#operations}}
|
||||||
|
|
||||||
{{#operation}}
|
{{#operation}}
|
||||||
#
|
#
|
||||||
# {{{nickname}}}
|
# {{{nickname}}}
|
||||||
#
|
#
|
||||||
# {{{summary}}}
|
# {{{summary}}}
|
||||||
#
|
#
|
||||||
{{#allParams}} # @param {{dataType}} ${{paramName}} {{description}} {{^optional}}(required){{/optional}}{{#optional}}(optional){{/optional}}
|
{{#allParams}}# @param {{dataType}} ${{paramName}} {{description}} {{^optional}}(required){{/optional}}{{#optional}}(optional){{/optional}}
|
||||||
{{/allParams}} # @return {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}}
|
{{/allParams}}# @return {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}}
|
||||||
#
|
#
|
||||||
sub {{nickname}} {
|
sub {{nickname}} {
|
||||||
my ($self, %args) = @_;
|
my ($self, %args) = @_;
|
||||||
|
|
||||||
{{#allParams}}{{#required}}
|
{{#allParams}}{{#required}}
|
||||||
@ -133,8 +128,8 @@ sub new {
|
|||||||
$header_params, $_body_data, $auth_settings);
|
$header_params, $_body_data, $auth_settings);
|
||||||
return;
|
return;
|
||||||
{{/returnType}}
|
{{/returnType}}
|
||||||
}
|
}
|
||||||
{{/operation}}
|
{{/operation}}
|
||||||
{{newline}}
|
{{newline}}
|
||||||
{{/operations}}
|
{{/operations}}
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{{#models}}
|
{{#models}}
|
||||||
{{#model}}
|
{{#model}}
|
||||||
package WWW::{{invokerPackage}}::Object::{{classname}};
|
package WWW::{{moduleName}}::Object::{{classname}};
|
||||||
|
|
||||||
require 5.6.0;
|
require 5.6.0;
|
||||||
use strict;
|
use strict;
|
||||||
@ -13,7 +13,7 @@ use Log::Any qw($log);
|
|||||||
use Date::Parse;
|
use Date::Parse;
|
||||||
use DateTime;
|
use DateTime;
|
||||||
|
|
||||||
use base "WWW::{{invokerPackage}}::Object::BaseObject";
|
use base "WWW::{{moduleName}}::Object::BaseObject";
|
||||||
|
|
||||||
#
|
#
|
||||||
#{{description}}
|
#{{description}}
|
||||||
|
@ -25,16 +25,13 @@ class ApiClient {
|
|||||||
public static $PUT = "PUT";
|
public static $PUT = "PUT";
|
||||||
public static $DELETE = "DELETE";
|
public static $DELETE = "DELETE";
|
||||||
|
|
||||||
|
/** @var string[] Array of default headers where the key is the header name and the value is the header value */
|
||||||
private $default_header = array();
|
private $default_header = array();
|
||||||
|
|
||||||
/*
|
/** @var string timeout (second) of the HTTP request, by default set to 0, no timeout */
|
||||||
* @var string timeout (second) of the HTTP request, by default set to 0, no timeout
|
|
||||||
*/
|
|
||||||
protected $curl_timeout = 0;
|
protected $curl_timeout = 0;
|
||||||
|
|
||||||
/*
|
/** @var string user agent of the HTTP request, set to "PHP-Swagger" by default */
|
||||||
* @var string user agent of the HTTP request, set to "PHP-Swagger" by default
|
|
||||||
*/
|
|
||||||
protected $user_agent = "PHP-Swagger";
|
protected $user_agent = "PHP-Swagger";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -386,8 +383,8 @@ class ApiClient {
|
|||||||
$deserialized[$key] = $this->deserialize($value, $subClass);
|
$deserialized[$key] = $this->deserialize($value, $subClass);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} elseif (strcasecmp(substr($class, 0, 6),'array[') == 0) {
|
} elseif (strcasecmp(substr($class, -2),'[]') == 0) {
|
||||||
$subClass = substr($class, 6, -1);
|
$subClass = substr($class, 0, -2);
|
||||||
$values = array();
|
$values = array();
|
||||||
foreach ($data as $key => $value) {
|
foreach ($data as $key => $value) {
|
||||||
$values[] = $this->deserialize($value, $subClass);
|
$values[] = $this->deserialize($value, $subClass);
|
||||||
@ -399,7 +396,6 @@ class ApiClient {
|
|||||||
settype($data, $class);
|
settype($data, $class);
|
||||||
$deserialized = $data;
|
$deserialized = $data;
|
||||||
} else {
|
} else {
|
||||||
$class = "{{invokerPackage}}\\models\\".$class;
|
|
||||||
$instance = new $class();
|
$instance = new $class();
|
||||||
foreach ($instance::$swaggerTypes as $property => $type) {
|
foreach ($instance::$swaggerTypes as $property => $type) {
|
||||||
$original_property_name = $instance::$attributeMap[$property];
|
$original_property_name = $instance::$attributeMap[$property];
|
||||||
|
@ -21,14 +21,10 @@ use \Exception;
|
|||||||
|
|
||||||
class ApiException extends Exception {
|
class ApiException extends Exception {
|
||||||
|
|
||||||
/**
|
/** @var string The HTTP body of the server response. */
|
||||||
* The HTTP body of the server response.
|
|
||||||
*/
|
|
||||||
protected $response_body;
|
protected $response_body;
|
||||||
|
|
||||||
/**
|
/** @var string[] The HTTP header of the server response. */
|
||||||
* The HTTP header of the server response.
|
|
||||||
*/
|
|
||||||
protected $response_headers;
|
protected $response_headers;
|
||||||
|
|
||||||
public function __construct($message="", $code=0, $responseHeaders=null, $responseBody=null) {
|
public function __construct($message="", $code=0, $responseHeaders=null, $responseBody=null) {
|
||||||
|
@ -20,11 +20,17 @@
|
|||||||
* 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. Do not edit the class manually.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace {{invokerPackage}};
|
namespace {{apiPackage}};
|
||||||
|
|
||||||
|
use \{{invokerPackage}}\ApiClient;
|
||||||
|
use \{{invokerPackage}}\Configuration;
|
||||||
|
|
||||||
{{#operations}}
|
{{#operations}}
|
||||||
class {{classname}} {
|
class {{classname}} {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param \{{invokerPackage}}\ApiClient|null $apiClient The api client to use. Defaults to getting it from Configuration
|
||||||
|
*/
|
||||||
function __construct($apiClient = null) {
|
function __construct($apiClient = null) {
|
||||||
if (null === $apiClient) {
|
if (null === $apiClient) {
|
||||||
if (Configuration::$apiClient === null) {
|
if (Configuration::$apiClient === null) {
|
||||||
@ -38,17 +44,18 @@ class {{classname}} {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private $apiClient; // instance of the ApiClient
|
/** @var \{{invokerPackage}}\ApiClient instance of the ApiClient */
|
||||||
|
private $apiClient;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get the API client
|
* @return \{{invokerPackage}}\ApiClient get the API client
|
||||||
*/
|
*/
|
||||||
public function getApiClient() {
|
public function getApiClient() {
|
||||||
return $this->apiClient;
|
return $this->apiClient;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* set the API client
|
* @param \{{invokerPackage}} $apiClient set the API client
|
||||||
*/
|
*/
|
||||||
public function setApiClient($apiClient) {
|
public function setApiClient($apiClient) {
|
||||||
$this->apiClient = $apiClient;
|
$this->apiClient = $apiClient;
|
||||||
@ -123,7 +130,6 @@ class {{classname}} {
|
|||||||
$response = $this->apiClient->callAPI($resourcePath, $method,
|
$response = $this->apiClient->callAPI($resourcePath, $method,
|
||||||
$queryParams, $httpBody,
|
$queryParams, $httpBody,
|
||||||
$headerParams, $authSettings);
|
$headerParams, $authSettings);
|
||||||
|
|
||||||
{{#returnType}}if(! $response) {
|
{{#returnType}}if(! $response) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,41 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* An example of a project-specific implementation.
|
||||||
|
*
|
||||||
|
* After registering this autoload function with SPL, the following line
|
||||||
|
* would cause the function to attempt to load the \{{invokerPackage}}\Baz\Qux class
|
||||||
|
* from /path/to/project/lib/Baz/Qux.php:
|
||||||
|
*
|
||||||
|
* new \{{invokerPackage}}\Baz\Qux;
|
||||||
|
*
|
||||||
|
* @param string $class The fully-qualified class name.
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
spl_autoload_register(function ($class) {
|
||||||
|
|
||||||
|
// project-specific namespace prefix
|
||||||
|
$prefix = '{{escapedInvokerPackage}}\\';
|
||||||
|
|
||||||
|
// base directory for the namespace prefix
|
||||||
|
$base_dir = __DIR__ . '/lib/';
|
||||||
|
|
||||||
|
// does the class use the namespace prefix?
|
||||||
|
$len = strlen($prefix);
|
||||||
|
if (strncmp($prefix, $class, $len) !== 0) {
|
||||||
|
// no, move to the next registered autoloader
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// get the relative class name
|
||||||
|
$relative_class = substr($class, $len);
|
||||||
|
|
||||||
|
// replace the namespace prefix with the base directory, replace namespace
|
||||||
|
// separators with directory separators in the relative class name, append
|
||||||
|
// with .php
|
||||||
|
$file = $base_dir . str_replace('\\', '/', $relative_class) . '.php';
|
||||||
|
|
||||||
|
// if the file exists, require it
|
||||||
|
if (file_exists($file)) {
|
||||||
|
require $file;
|
||||||
|
}
|
||||||
|
});
|
@ -1,5 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "{{invokerPackage}}/{{invokerPackage}}-php",
|
"name": "{{groupId}}/{{artifactId}}",{{#artifactVersion}}
|
||||||
|
"version": "{{artifactVersion}}",{{/artifactVersion}}
|
||||||
"description": "{{description}}",
|
"description": "{{description}}",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"swagger",
|
"swagger",
|
||||||
@ -27,6 +28,6 @@
|
|||||||
"squizlabs/php_codesniffer": "~2.0"
|
"squizlabs/php_codesniffer": "~2.0"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": { "{{invokerPackage}}\\" : "lib/" }
|
"psr-4": { "{{escapedInvokerPackage}}\\" : "lib/" }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,41 +17,29 @@
|
|||||||
|
|
||||||
namespace {{invokerPackage}};
|
namespace {{invokerPackage}};
|
||||||
|
|
||||||
|
use \{{invokerPackage}}\ApiClient;
|
||||||
|
|
||||||
class Configuration {
|
class Configuration {
|
||||||
|
|
||||||
/**
|
/** @var string[] Associate array to store API key(s) */
|
||||||
* Associate array to store API key(s)
|
|
||||||
*/
|
|
||||||
public static $apiKey = array();
|
public static $apiKey = array();
|
||||||
|
|
||||||
/**
|
/** string[] Associate array to store API prefix (e.g. Bearer) */
|
||||||
* Associate array to store API prefix (e.g. Bearer)
|
|
||||||
*/
|
|
||||||
public static $apiKeyPrefix = array();
|
public static $apiKeyPrefix = array();
|
||||||
|
|
||||||
/**
|
/** @var string Username for HTTP basic authentication */
|
||||||
* Username for HTTP basic authentication
|
|
||||||
*/
|
|
||||||
public static $username = '';
|
public static $username = '';
|
||||||
|
|
||||||
/**
|
/** @var string Password for HTTP basic authentication */
|
||||||
* Password for HTTP basic authentication
|
|
||||||
*/
|
|
||||||
public static $password = '';
|
public static $password = '';
|
||||||
|
|
||||||
/**
|
/** @var \{{invokerPackage}}\ApiClient The default instance of ApiClient */
|
||||||
* The default instance of ApiClient
|
|
||||||
*/
|
|
||||||
public static $apiClient;
|
public static $apiClient;
|
||||||
|
|
||||||
/**
|
/** @var bool Debug switch (default set to false) */
|
||||||
* Debug switch (default set to false)
|
|
||||||
*/
|
|
||||||
public static $debug = false;
|
public static $debug = false;
|
||||||
|
|
||||||
/**
|
/** @var string Debug file location (log to STDOUT by default) */
|
||||||
* Debug file location (log to STDOUT by default)
|
|
||||||
*/
|
|
||||||
public static $debug_file = 'php://output';
|
public static $debug_file = 'php://output';
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -63,4 +51,3 @@ class Configuration {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,29 +24,31 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace {{invokerPackage}}\models;
|
namespace {{modelPackage}};
|
||||||
|
|
||||||
use \ArrayAccess;
|
use \ArrayAccess;
|
||||||
|
|
||||||
class {{classname}} implements ArrayAccess {
|
class {{classname}} implements ArrayAccess {
|
||||||
|
/** @var string[] Array of property to type mappings. Used for (de)serialization */
|
||||||
static $swaggerTypes = array(
|
static $swaggerTypes = array(
|
||||||
{{#vars}}'{{name}}' => '{{{datatype}}}'{{#hasMore}},
|
{{#vars}}'{{name}}' => '{{{datatype}}}'{{#hasMore}},
|
||||||
{{/hasMore}}{{/vars}}
|
{{/hasMore}}{{/vars}}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/** @var string[] Array of attributes where the key is the local name, and the value is the original name */
|
||||||
static $attributeMap = array(
|
static $attributeMap = array(
|
||||||
{{#vars}}'{{name}}' => '{{baseName}}'{{#hasMore}},
|
{{#vars}}'{{name}}' => '{{baseName}}'{{#hasMore}},
|
||||||
{{/hasMore}}{{/vars}}
|
{{/hasMore}}{{/vars}}
|
||||||
);
|
);
|
||||||
|
{{#vars}}
|
||||||
{{#vars}}{{#description}}
|
/** @var {{datatype}} ${{name}} {{#description}}{{{description}}} {{/description}}*/
|
||||||
|
public ${{name}};
|
||||||
|
{{/vars}}
|
||||||
/**
|
/**
|
||||||
* {{{description}}}
|
* @param mixed[] Array of parameters to initialize the object with
|
||||||
*/{{/description}}
|
*/
|
||||||
public ${{name}}; /* {{{datatype}}} */{{/vars}}
|
|
||||||
|
|
||||||
public function __construct(array $data = null) {
|
public function __construct(array $data = null) {
|
||||||
{{#vars}}$this->{{name}} = $data["{{name}}"];{{#hasMore}}
|
{{#vars}}$this->{{name}} = @$data["{{name}}"];{{#hasMore}}
|
||||||
{{/hasMore}}{{/vars}}
|
{{/hasMore}}{{/vars}}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,13 +0,0 @@
|
|||||||
<?php
|
|
||||||
// load models defined for endpoints
|
|
||||||
foreach (glob(dirname(__FILE__)."/lib/models/*.php") as $filename)
|
|
||||||
{
|
|
||||||
require_once $filename;
|
|
||||||
}
|
|
||||||
|
|
||||||
// load classes for accessing the endpoints
|
|
||||||
foreach (glob(dirname(__FILE__)."/lib/*.php") as $filename)
|
|
||||||
{
|
|
||||||
require_once $filename;
|
|
||||||
}
|
|
||||||
?>
|
|
@ -11,7 +11,7 @@ module {{moduleName}}
|
|||||||
# {{notes}}
|
# {{notes}}
|
||||||
{{#allParams}}{{#required}} # @param {{paramName}} {{description}}
|
{{#allParams}}{{#required}} # @param {{paramName}} {{description}}
|
||||||
{{/required}}{{/allParams}} # @param [Hash] opts the optional parameters
|
{{/required}}{{/allParams}} # @param [Hash] opts the optional parameters
|
||||||
{{#allParams}}{{^required}} # @option opts [{{dataType}}] :{{paramName}} {{description}}
|
{{#allParams}}{{^required}} # @option opts [{{{dataType}}}] :{{paramName}} {{description}}
|
||||||
{{/required}}{{/allParams}} # @return [{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}nil{{/returnType}}]
|
{{/required}}{{/allParams}} # @return [{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}nil{{/returnType}}]
|
||||||
def self.{{nickname}}({{#allParams}}{{#required}}{{paramName}}, {{/required}}{{/allParams}}opts = {})
|
def self.{{nickname}}({{#allParams}}{{#required}}{{paramName}}, {{/required}}{{/allParams}}opts = {})
|
||||||
{{#allParams}}{{#required}}
|
{{#allParams}}{{#required}}
|
||||||
@ -51,8 +51,8 @@ module {{moduleName}}
|
|||||||
{{/bodyParam}}
|
{{/bodyParam}}
|
||||||
|
|
||||||
auth_names = [{{#authMethods}}'{{name}}'{{#hasMore}}, {{/hasMore}}{{/authMethods}}]
|
auth_names = [{{#authMethods}}'{{name}}'{{#hasMore}}, {{/hasMore}}{{/authMethods}}]
|
||||||
{{#returnType}}response = Swagger::Request.new(:{{httpMethod}}, path, {:params => query_params, :headers => header_params, :form_params => form_params, :body => post_body, :auth_names => auth_names}).make.body
|
{{#returnType}}response = Swagger::Request.new(:{{httpMethod}}, path, {:params => query_params, :headers => header_params, :form_params => form_params, :body => post_body, :auth_names => auth_names}).make
|
||||||
{{#returnContainer}}response.map {|response| {{/returnContainer}}obj = {{returnBaseType}}.new() and obj.build_from_hash(response){{#returnContainer}} }{{/returnContainer}}{{/returnType}}{{^returnType}}Swagger::Request.new(:{{httpMethod}}, path, {:params => query_params,:headers => header_params, :form_params => form_params, :body => post_body, :auth_names => auth_names}).make
|
response.deserialize('{{{returnType}}}'){{/returnType}}{{^returnType}}Swagger::Request.new(:{{httpMethod}}, path, {:params => query_params,:headers => header_params, :form_params => form_params, :body => post_body, :auth_names => auth_names}).make
|
||||||
nil{{/returnType}}
|
nil{{/returnType}}
|
||||||
end
|
end
|
||||||
{{/operation}}
|
{{/operation}}
|
||||||
|
@ -2,20 +2,11 @@ module {{moduleName}}
|
|||||||
# base class containing fundamental method such as to_hash, build_from_hash and more
|
# base class containing fundamental method such as to_hash, build_from_hash and more
|
||||||
class BaseObject
|
class BaseObject
|
||||||
|
|
||||||
# return the object in the form of hash
|
|
||||||
def to_body
|
|
||||||
body = {}
|
|
||||||
self.class.attribute_map.each_pair do |key, value|
|
|
||||||
body[value] = self.send(key) unless self.send(key).nil?
|
|
||||||
end
|
|
||||||
body
|
|
||||||
end
|
|
||||||
|
|
||||||
# build the object from hash
|
# build the object from hash
|
||||||
def build_from_hash(attributes)
|
def build_from_hash(attributes)
|
||||||
return nil unless attributes.is_a?(Hash)
|
return nil unless attributes.is_a?(Hash)
|
||||||
self.class.swagger_types.each_pair do |key, type|
|
self.class.swagger_types.each_pair do |key, type|
|
||||||
if type =~ /^array\[(.*)\]/i
|
if type =~ /^Array<(.*)>/i
|
||||||
if attributes[self.class.attribute_map[key]].is_a?(Array)
|
if attributes[self.class.attribute_map[key]].is_a?(Array)
|
||||||
self.send("#{key}=", attributes[self.class.attribute_map[key]].map{ |v| _deserialize($1, v) } )
|
self.send("#{key}=", attributes[self.class.attribute_map[key]].map{ |v| _deserialize($1, v) } )
|
||||||
else
|
else
|
||||||
@ -35,13 +26,13 @@ module {{moduleName}}
|
|||||||
case type.to_sym
|
case type.to_sym
|
||||||
when :DateTime
|
when :DateTime
|
||||||
DateTime.parse(value)
|
DateTime.parse(value)
|
||||||
when :string
|
when :String
|
||||||
value.to_s
|
value.to_s
|
||||||
when :int
|
when :Integer
|
||||||
value.to_i
|
value.to_i
|
||||||
when :double
|
when :Float
|
||||||
value.to_f
|
value.to_f
|
||||||
when :boolean
|
when :BOOLEAN
|
||||||
if value =~ /^(true|t|yes|y|1)$/i
|
if value =~ /^(true|t|yes|y|1)$/i
|
||||||
true
|
true
|
||||||
else
|
else
|
||||||
@ -53,7 +44,16 @@ module {{moduleName}}
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# to_body is an alias to to_body (backward compatibility)
|
def to_s
|
||||||
|
to_hash.to_s
|
||||||
|
end
|
||||||
|
|
||||||
|
# to_body is an alias to to_body (backward compatibility))
|
||||||
|
def to_body
|
||||||
|
to_hash
|
||||||
|
end
|
||||||
|
|
||||||
|
# return the object in the form of hash
|
||||||
def to_hash
|
def to_hash
|
||||||
hash = {}
|
hash = {}
|
||||||
self.class.attribute_map.each_pair do |key, value|
|
self.class.attribute_map.each_pair do |key, value|
|
||||||
|
@ -1,6 +1,4 @@
|
|||||||
# module Swagger
|
class Object
|
||||||
class Object
|
|
||||||
|
|
||||||
unless Object.method_defined? :blank?
|
unless Object.method_defined? :blank?
|
||||||
def blank?
|
def blank?
|
||||||
respond_to?(:empty?) ? empty? : !self
|
respond_to?(:empty?) ? empty? : !self
|
||||||
@ -12,11 +10,9 @@
|
|||||||
!blank?
|
!blank?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
class String
|
||||||
|
|
||||||
class String
|
|
||||||
|
|
||||||
unless String.method_defined? :underscore
|
unless String.method_defined? :underscore
|
||||||
def underscore
|
def underscore
|
||||||
self.gsub(/::/, '/').
|
self.gsub(/::/, '/').
|
||||||
@ -36,11 +32,9 @@
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
class Hash
|
||||||
|
|
||||||
class Hash
|
|
||||||
|
|
||||||
unless Hash.method_defined? :stringify_keys
|
unless Hash.method_defined? :stringify_keys
|
||||||
def stringify_keys
|
def stringify_keys
|
||||||
inject({}) do |options, (key, value)|
|
inject({}) do |options, (key, value)|
|
||||||
@ -85,6 +79,4 @@
|
|||||||
self.replace(self.symbolize_and_underscore_keys)
|
self.replace(self.symbolize_and_underscore_keys)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
end
|
|
||||||
# end
|
|
||||||
|
@ -52,7 +52,7 @@ module {{moduleName}}
|
|||||||
return if Swagger.authenticated?
|
return if Swagger.authenticated?
|
||||||
|
|
||||||
if Swagger.configuration.username.blank? || Swagger.configuration.password.blank?
|
if Swagger.configuration.username.blank? || Swagger.configuration.password.blank?
|
||||||
raise ClientError, "Username and password are required to authenticate."
|
raise ApiError, "Username and password are required to authenticate."
|
||||||
end
|
end
|
||||||
|
|
||||||
request = Swagger::Request.new(
|
request = Swagger::Request.new(
|
||||||
@ -69,10 +69,4 @@ module {{moduleName}}
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class ServerError < StandardError
|
|
||||||
end
|
|
||||||
|
|
||||||
class ClientError < StandardError
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
@ -0,0 +1,26 @@
|
|||||||
|
module {{moduleName}}
|
||||||
|
module Swagger
|
||||||
|
class ApiError < StandardError
|
||||||
|
attr_reader :code, :response_headers, :response_body
|
||||||
|
|
||||||
|
# Usage examples:
|
||||||
|
# ApiError.new
|
||||||
|
# ApiError.new("message")
|
||||||
|
# ApiError.new(:code => 500, :response_headers => {}, :response_body => "")
|
||||||
|
# ApiError.new(:code => 404, :message => "Not Found")
|
||||||
|
def initialize(arg = nil)
|
||||||
|
if arg.is_a? Hash
|
||||||
|
arg.each do |k, v|
|
||||||
|
if k.to_s == 'message'
|
||||||
|
super v
|
||||||
|
else
|
||||||
|
instance_variable_set "@#{k}", v
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
super arg
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -2,15 +2,18 @@ module {{moduleName}}
|
|||||||
module Swagger
|
module Swagger
|
||||||
class Response
|
class Response
|
||||||
require 'json'
|
require 'json'
|
||||||
|
require 'date'
|
||||||
|
|
||||||
attr_accessor :raw
|
attr_accessor :raw
|
||||||
|
|
||||||
def initialize(raw)
|
def initialize(raw)
|
||||||
self.raw = raw
|
self.raw = raw
|
||||||
|
|
||||||
case self.code
|
unless raw.success?
|
||||||
when 500..510 then raise(ServerError, self.error_message)
|
fail ApiError.new(:code => code,
|
||||||
when 299..426 then raise(ClientError, self.error_message)
|
:response_headers => headers,
|
||||||
|
:response_body => body),
|
||||||
|
raw.status_message
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -18,19 +21,65 @@ module {{moduleName}}
|
|||||||
raw.code
|
raw.code
|
||||||
end
|
end
|
||||||
|
|
||||||
# Account for error messages that take different forms...
|
def body
|
||||||
def error_message
|
raw.body
|
||||||
body['message']
|
|
||||||
rescue
|
|
||||||
body
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# If body is JSON, parse it
|
# Deserialize the raw response body to the given return type.
|
||||||
# Otherwise return raw string
|
#
|
||||||
def body
|
# @param [String] return_type some examples: "User", "Array[User]", "Hash[String,Integer]"
|
||||||
JSON.parse(raw.body, :symbolize_names => true)
|
def deserialize(return_type)
|
||||||
rescue
|
return nil if body.blank?
|
||||||
raw.body
|
|
||||||
|
# ensuring a default content type
|
||||||
|
content_type = raw.headers_hash['Content-Type'] || 'application/json'
|
||||||
|
|
||||||
|
unless content_type.start_with?('application/json')
|
||||||
|
fail "Content-Type is not supported: #{content_type}"
|
||||||
|
end
|
||||||
|
|
||||||
|
begin
|
||||||
|
data = JSON.parse(body, :symbolize_names => true)
|
||||||
|
rescue JSON::ParserError => e
|
||||||
|
if return_type == 'String'
|
||||||
|
return body
|
||||||
|
else
|
||||||
|
raise e
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
build_models data, return_type
|
||||||
|
end
|
||||||
|
|
||||||
|
# Walk through the given data and, when necessary, build model(s) from
|
||||||
|
# Hash data for array/hash values of the response.
|
||||||
|
def build_models(data, return_type)
|
||||||
|
case return_type
|
||||||
|
when 'String', 'Integer', 'Float', 'BOOLEAN'
|
||||||
|
# primitives, return directly
|
||||||
|
data
|
||||||
|
when 'DateTime'
|
||||||
|
# parse date time (expecting ISO 8601 format)
|
||||||
|
DateTime.parse data
|
||||||
|
when 'Object'
|
||||||
|
# generic object, return directly
|
||||||
|
data
|
||||||
|
when /\AArray<(.+)>\z/
|
||||||
|
# e.g. Array<Pet>
|
||||||
|
sub_type = $1
|
||||||
|
data.map {|item| build_models(item, sub_type) }
|
||||||
|
when /\AHash\<String, (.+)\>\z/
|
||||||
|
# e.g. Hash<String, Integer>
|
||||||
|
sub_type = $1
|
||||||
|
{}.tap do |hash|
|
||||||
|
data.each {|k, v| hash[k] = build_models(v, sub_type) }
|
||||||
|
end
|
||||||
|
else
|
||||||
|
# models, e.g. Pet
|
||||||
|
{{moduleName}}.const_get(return_type).new.tap do |model|
|
||||||
|
model.build_from_hash data
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# `headers_hash` is a Typhoeus-specific extension of Hash,
|
# `headers_hash` is a Typhoeus-specific extension of Hash,
|
||||||
@ -58,7 +107,7 @@ module {{moduleName}}
|
|||||||
def pretty_body
|
def pretty_body
|
||||||
return unless body.present?
|
return unless body.present?
|
||||||
case format
|
case format
|
||||||
when 'json' then JSON.pretty_generate(body).gsub(/\n/, '<br/>')
|
when 'json' then JSON.pretty_generate(JSON.parse(body)).gsub(/\n/, '<br/>')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
require '{{gemName}}/monkey'
|
require '{{gemName}}/monkey'
|
||||||
require '{{gemName}}/swagger'
|
require '{{gemName}}/swagger'
|
||||||
require '{{gemName}}/swagger/configuration'
|
require '{{gemName}}/swagger/configuration'
|
||||||
|
require '{{gemName}}/swagger/api_error'
|
||||||
require '{{gemName}}/swagger/request'
|
require '{{gemName}}/swagger/request'
|
||||||
require '{{gemName}}/swagger/response'
|
require '{{gemName}}/swagger/response'
|
||||||
require '{{gemName}}/swagger/version'
|
require '{{gemName}}/swagger/version'
|
||||||
|
@ -3,6 +3,7 @@ package Java
|
|||||||
import io.swagger.codegen.languages.JavaClientCodegen
|
import io.swagger.codegen.languages.JavaClientCodegen
|
||||||
import io.swagger.models._
|
import io.swagger.models._
|
||||||
import io.swagger.models.properties._
|
import io.swagger.models.properties._
|
||||||
|
import io.swagger.util.Json
|
||||||
import org.junit.runner.RunWith
|
import org.junit.runner.RunWith
|
||||||
import org.scalatest.{FlatSpec, Matchers}
|
import org.scalatest.{FlatSpec, Matchers}
|
||||||
import org.scalatest.junit.JUnitRunner
|
import org.scalatest.junit.JUnitRunner
|
||||||
@ -344,3 +345,32 @@ class JavaModelTest extends FlatSpec with Matchers {
|
|||||||
cm.classname should be("WithDots")
|
cm.classname should be("WithDots")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@RunWith(classOf[JUnitRunner])
|
||||||
|
class JavaModelTest2 extends FlatSpec with Matchers {
|
||||||
|
it should "translate an invalid param name" in {
|
||||||
|
val model = new ModelImpl()
|
||||||
|
.description("a model with a 2nd char upper-case property names")
|
||||||
|
.property("_", new StringProperty())
|
||||||
|
|
||||||
|
val codegen = new JavaClientCodegen()
|
||||||
|
val cm = codegen.fromModel("sample", model)
|
||||||
|
|
||||||
|
cm.name should be("sample")
|
||||||
|
cm.classname should be("Sample")
|
||||||
|
cm.vars.size should be(1)
|
||||||
|
|
||||||
|
val vars = cm.vars
|
||||||
|
Json.prettyPrint(vars.get(0))
|
||||||
|
vars.get(0).baseName should be("_")
|
||||||
|
vars.get(0).getter should be("getU")
|
||||||
|
vars.get(0).setter should be("setU")
|
||||||
|
vars.get(0).datatype should be("String")
|
||||||
|
vars.get(0).name should be("u")
|
||||||
|
vars.get(0).defaultValue should be("null")
|
||||||
|
vars.get(0).baseType should be("String")
|
||||||
|
vars.get(0).hasMore should equal(null)
|
||||||
|
vars.get(0).isNotContainer should equal(true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -118,7 +118,7 @@ class ObjcModelTest extends FlatSpec with Matchers {
|
|||||||
|
|
||||||
val vars = cm.vars
|
val vars = cm.vars
|
||||||
vars.get(0).baseName should be("translations")
|
vars.get(0).baseName should be("translations")
|
||||||
vars.get(0).datatype should be("NSDictionary*")
|
vars.get(0).datatype should be("NSDictionary* /* NSString, NSString */")
|
||||||
vars.get(0).name should be("translations")
|
vars.get(0).name should be("translations")
|
||||||
vars.get(0).baseType should be("NSDictionary")
|
vars.get(0).baseType should be("NSDictionary")
|
||||||
vars.get(0).containerType should be("map")
|
vars.get(0).containerType should be("map")
|
||||||
@ -192,7 +192,7 @@ class ObjcModelTest extends FlatSpec with Matchers {
|
|||||||
val vars = cm.vars
|
val vars = cm.vars
|
||||||
vars.get(0).baseName should be("children")
|
vars.get(0).baseName should be("children")
|
||||||
vars.get(0).complexType should be("SWGChildren")
|
vars.get(0).complexType should be("SWGChildren")
|
||||||
vars.get(0).datatype should be("NSDictionary*")
|
vars.get(0).datatype should be("NSDictionary* /* NSString, SWGChildren */")
|
||||||
vars.get(0).name should be("children")
|
vars.get(0).name should be("children")
|
||||||
vars.get(0).baseType should be("NSDictionary")
|
vars.get(0).baseType should be("NSDictionary")
|
||||||
vars.get(0).containerType should be("map")
|
vars.get(0).containerType should be("map")
|
||||||
|
@ -51,16 +51,16 @@ class PhpModelTest extends FlatSpec with Matchers {
|
|||||||
vars.get(1).isNotContainer should equal(true)
|
vars.get(1).isNotContainer should equal(true)
|
||||||
|
|
||||||
vars.get(2).baseName should be("createdAt")
|
vars.get(2).baseName should be("createdAt")
|
||||||
vars.get(2).complexType should be(null)
|
vars.get(2).complexType should be("\\DateTime")
|
||||||
vars.get(2).datatype should be("DateTime")
|
vars.get(2).datatype should be("\\DateTime")
|
||||||
vars.get(2).name should be("created_at")
|
vars.get(2).name should be("created_at")
|
||||||
vars.get(2).defaultValue should be("null")
|
vars.get(2).defaultValue should be("null")
|
||||||
vars.get(2).baseType should be("DateTime")
|
vars.get(2).baseType should be("\\DateTime")
|
||||||
vars.get(2).hasMore should equal(null)
|
vars.get(2).hasMore should equal(null)
|
||||||
vars.get(2).required should equal(null)
|
vars.get(2).required should equal(null)
|
||||||
vars.get(2).isNotContainer should equal(true)
|
vars.get(2).isNotContainer should equal(true)
|
||||||
|
|
||||||
cm.imports.size() should be(0)
|
cm.imports.size() should be(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
it should "convert a model with list property" in {
|
it should "convert a model with list property" in {
|
||||||
@ -91,7 +91,7 @@ class PhpModelTest extends FlatSpec with Matchers {
|
|||||||
vars.get(0).isNotContainer should equal(true)
|
vars.get(0).isNotContainer should equal(true)
|
||||||
|
|
||||||
vars.get(1).baseName should be("urls")
|
vars.get(1).baseName should be("urls")
|
||||||
vars.get(1).datatype should be("array[string]")
|
vars.get(1).datatype should be("string[]")
|
||||||
vars.get(1).name should be("urls")
|
vars.get(1).name should be("urls")
|
||||||
vars.get(1).baseType should be("array")
|
vars.get(1).baseType should be("array")
|
||||||
vars.get(1).hasMore should be(null)
|
vars.get(1).hasMore should be(null)
|
||||||
@ -142,7 +142,7 @@ class PhpModelTest extends FlatSpec with Matchers {
|
|||||||
|
|
||||||
val vars = cm.vars
|
val vars = cm.vars
|
||||||
vars.get(0).baseName should be("children")
|
vars.get(0).baseName should be("children")
|
||||||
vars.get(0).datatype should be("Children")
|
vars.get(0).datatype should be("\\Swagger\\Client\\Model\\Children")
|
||||||
vars.get(0).name should be("children")
|
vars.get(0).name should be("children")
|
||||||
vars.get(0).baseType should be("Children")
|
vars.get(0).baseType should be("Children")
|
||||||
vars.get(0).required should equal(null)
|
vars.get(0).required should equal(null)
|
||||||
@ -166,7 +166,7 @@ class PhpModelTest extends FlatSpec with Matchers {
|
|||||||
val vars = cm.vars
|
val vars = cm.vars
|
||||||
vars.get(0).baseName should be("children")
|
vars.get(0).baseName should be("children")
|
||||||
vars.get(0).complexType should be("Children")
|
vars.get(0).complexType should be("Children")
|
||||||
vars.get(0).datatype should be("array[Children]")
|
vars.get(0).datatype should be("\\Swagger\\Client\\Model\\Children[]")
|
||||||
vars.get(0).name should be("children")
|
vars.get(0).name should be("children")
|
||||||
vars.get(0).baseType should be("array")
|
vars.get(0).baseType should be("array")
|
||||||
vars.get(0).containerType should be("array")
|
vars.get(0).containerType should be("array")
|
||||||
@ -192,7 +192,7 @@ class PhpModelTest extends FlatSpec with Matchers {
|
|||||||
val vars = cm.vars
|
val vars = cm.vars
|
||||||
vars.get(0).baseName should be("children")
|
vars.get(0).baseName should be("children")
|
||||||
vars.get(0).complexType should be("Children")
|
vars.get(0).complexType should be("Children")
|
||||||
vars.get(0).datatype should be("map[string,Children]")
|
vars.get(0).datatype should be("map[string,\\Swagger\\Client\\Model\\Children]")
|
||||||
vars.get(0).name should be("children")
|
vars.get(0).name should be("children")
|
||||||
vars.get(0).baseType should be("map")
|
vars.get(0).baseType should be("map")
|
||||||
vars.get(0).containerType should be("map")
|
vars.get(0).containerType should be("map")
|
||||||
|
1
pom.xml
1
pom.xml
@ -397,6 +397,7 @@
|
|||||||
<modules>
|
<modules>
|
||||||
<module>modules/swagger-codegen</module>
|
<module>modules/swagger-codegen</module>
|
||||||
<module>modules/swagger-codegen-cli</module>
|
<module>modules/swagger-codegen-cli</module>
|
||||||
|
<module>modules/swagger-codegen-maven-plugin</module>
|
||||||
<module>modules/swagger-generator</module>
|
<module>modules/swagger-generator</module>
|
||||||
</modules>
|
</modules>
|
||||||
<reporting>
|
<reporting>
|
||||||
|
@ -0,0 +1,41 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||||
|
<plist version="1.0">
|
||||||
|
<dict>
|
||||||
|
<key>IDESourceControlProjectFavoriteDictionaryKey</key>
|
||||||
|
<false/>
|
||||||
|
<key>IDESourceControlProjectIdentifier</key>
|
||||||
|
<string>15AAFA18-9D61-437F-988D-A691BA4C08B1</string>
|
||||||
|
<key>IDESourceControlProjectName</key>
|
||||||
|
<string>SwaggerClient</string>
|
||||||
|
<key>IDESourceControlProjectOriginsDictionary</key>
|
||||||
|
<dict>
|
||||||
|
<key>E5BBF0AA85077C865C95437976D06D819733A208</key>
|
||||||
|
<string>https://github.com/geekerzp/swagger-codegen.git</string>
|
||||||
|
</dict>
|
||||||
|
<key>IDESourceControlProjectPath</key>
|
||||||
|
<string>samples/client/petstore/objc/SwaggerClient.xcworkspace</string>
|
||||||
|
<key>IDESourceControlProjectRelativeInstallPathDictionary</key>
|
||||||
|
<dict>
|
||||||
|
<key>E5BBF0AA85077C865C95437976D06D819733A208</key>
|
||||||
|
<string>../../../../..</string>
|
||||||
|
</dict>
|
||||||
|
<key>IDESourceControlProjectURL</key>
|
||||||
|
<string>https://github.com/geekerzp/swagger-codegen.git</string>
|
||||||
|
<key>IDESourceControlProjectVersion</key>
|
||||||
|
<integer>111</integer>
|
||||||
|
<key>IDESourceControlProjectWCCIdentifier</key>
|
||||||
|
<string>E5BBF0AA85077C865C95437976D06D819733A208</string>
|
||||||
|
<key>IDESourceControlProjectWCConfigurations</key>
|
||||||
|
<array>
|
||||||
|
<dict>
|
||||||
|
<key>IDESourceControlRepositoryExtensionIdentifierKey</key>
|
||||||
|
<string>public.vcs.git</string>
|
||||||
|
<key>IDESourceControlWCCIdentifierKey</key>
|
||||||
|
<string>E5BBF0AA85077C865C95437976D06D819733A208</string>
|
||||||
|
<key>IDESourceControlWCCName</key>
|
||||||
|
<string>swagger-codegen</string>
|
||||||
|
</dict>
|
||||||
|
</array>
|
||||||
|
</dict>
|
||||||
|
</plist>
|
Binary file not shown.
@ -0,0 +1,17 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<Bucket
|
||||||
|
type = "0"
|
||||||
|
version = "2.0">
|
||||||
|
<Breakpoints>
|
||||||
|
<BreakpointProxy
|
||||||
|
BreakpointExtensionID = "Xcode.Breakpoint.ExceptionBreakpoint">
|
||||||
|
<BreakpointContent
|
||||||
|
shouldBeEnabled = "Yes"
|
||||||
|
ignoreCount = "0"
|
||||||
|
continueAfterRunningActions = "No"
|
||||||
|
scope = "0"
|
||||||
|
stopOnStyle = "0">
|
||||||
|
</BreakpointContent>
|
||||||
|
</BreakpointProxy>
|
||||||
|
</Breakpoints>
|
||||||
|
</Bucket>
|
@ -10,6 +10,9 @@
|
|||||||
BA525648922D4C0E9F44D4F1 /* libPods.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 73DA4F1067C343C3962F1542 /* libPods.a */; };
|
BA525648922D4C0E9F44D4F1 /* libPods.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 73DA4F1067C343C3962F1542 /* libPods.a */; };
|
||||||
CF0560EB1B1855CF00C0D4EC /* SWGConfiguration.m in Sources */ = {isa = PBXBuildFile; fileRef = CF0560EA1B1855CF00C0D4EC /* SWGConfiguration.m */; };
|
CF0560EB1B1855CF00C0D4EC /* SWGConfiguration.m in Sources */ = {isa = PBXBuildFile; fileRef = CF0560EA1B1855CF00C0D4EC /* SWGConfiguration.m */; };
|
||||||
CF31D0991B105E4B00509935 /* SWGApiClientTest.m in Sources */ = {isa = PBXBuildFile; fileRef = CF31D0981B105E4B00509935 /* SWGApiClientTest.m */; };
|
CF31D0991B105E4B00509935 /* SWGApiClientTest.m in Sources */ = {isa = PBXBuildFile; fileRef = CF31D0981B105E4B00509935 /* SWGApiClientTest.m */; };
|
||||||
|
CF5B6E2D1B2BD70800862A1C /* UserApiTest.m in Sources */ = {isa = PBXBuildFile; fileRef = CF5B6E2C1B2BD70800862A1C /* UserApiTest.m */; };
|
||||||
|
CFB37D061B2B11DD00D2E5F1 /* StoreApiTest.m in Sources */ = {isa = PBXBuildFile; fileRef = CFB37D051B2B11DC00D2E5F1 /* StoreApiTest.m */; };
|
||||||
|
CFCEFE511B2C1330006313BE /* SWGJSONResponseSerializer.m in Sources */ = {isa = PBXBuildFile; fileRef = CFCEFE501B2C1330006313BE /* SWGJSONResponseSerializer.m */; };
|
||||||
CFD1B6701B05EC7D00DCCD51 /* JSONValueTransformer+ISO8601.m in Sources */ = {isa = PBXBuildFile; fileRef = CFD1B66F1B05EC7D00DCCD51 /* JSONValueTransformer+ISO8601.m */; };
|
CFD1B6701B05EC7D00DCCD51 /* JSONValueTransformer+ISO8601.m in Sources */ = {isa = PBXBuildFile; fileRef = CFD1B66F1B05EC7D00DCCD51 /* JSONValueTransformer+ISO8601.m */; };
|
||||||
CFD1B6711B05EC7D00DCCD51 /* JSONValueTransformer+ISO8601.m in Sources */ = {isa = PBXBuildFile; fileRef = CFD1B66F1B05EC7D00DCCD51 /* JSONValueTransformer+ISO8601.m */; };
|
CFD1B6711B05EC7D00DCCD51 /* JSONValueTransformer+ISO8601.m in Sources */ = {isa = PBXBuildFile; fileRef = CFD1B66F1B05EC7D00DCCD51 /* JSONValueTransformer+ISO8601.m */; };
|
||||||
EA66999A1811D2FA00A70D03 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = EA6699991811D2FA00A70D03 /* Foundation.framework */; };
|
EA66999A1811D2FA00A70D03 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = EA6699991811D2FA00A70D03 /* Foundation.framework */; };
|
||||||
@ -60,6 +63,10 @@
|
|||||||
CF0560E91B1855CF00C0D4EC /* SWGConfiguration.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SWGConfiguration.h; sourceTree = "<group>"; };
|
CF0560E91B1855CF00C0D4EC /* SWGConfiguration.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SWGConfiguration.h; sourceTree = "<group>"; };
|
||||||
CF0560EA1B1855CF00C0D4EC /* SWGConfiguration.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SWGConfiguration.m; sourceTree = "<group>"; };
|
CF0560EA1B1855CF00C0D4EC /* SWGConfiguration.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SWGConfiguration.m; sourceTree = "<group>"; };
|
||||||
CF31D0981B105E4B00509935 /* SWGApiClientTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SWGApiClientTest.m; sourceTree = "<group>"; };
|
CF31D0981B105E4B00509935 /* SWGApiClientTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SWGApiClientTest.m; sourceTree = "<group>"; };
|
||||||
|
CF5B6E2C1B2BD70800862A1C /* UserApiTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UserApiTest.m; sourceTree = "<group>"; };
|
||||||
|
CFB37D051B2B11DC00D2E5F1 /* StoreApiTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = StoreApiTest.m; sourceTree = "<group>"; };
|
||||||
|
CFCEFE4F1B2C1330006313BE /* SWGJSONResponseSerializer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SWGJSONResponseSerializer.h; sourceTree = "<group>"; };
|
||||||
|
CFCEFE501B2C1330006313BE /* SWGJSONResponseSerializer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SWGJSONResponseSerializer.m; sourceTree = "<group>"; };
|
||||||
CFD1B66E1B05EC7D00DCCD51 /* JSONValueTransformer+ISO8601.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "JSONValueTransformer+ISO8601.h"; sourceTree = "<group>"; };
|
CFD1B66E1B05EC7D00DCCD51 /* JSONValueTransformer+ISO8601.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "JSONValueTransformer+ISO8601.h"; sourceTree = "<group>"; };
|
||||||
CFD1B66F1B05EC7D00DCCD51 /* JSONValueTransformer+ISO8601.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "JSONValueTransformer+ISO8601.m"; sourceTree = "<group>"; };
|
CFD1B66F1B05EC7D00DCCD51 /* JSONValueTransformer+ISO8601.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "JSONValueTransformer+ISO8601.m"; sourceTree = "<group>"; };
|
||||||
E2B6DA00BE52336E23783686 /* Pods.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = Pods.debug.xcconfig; path = "../Pods/Target Support Files/Pods/Pods.debug.xcconfig"; sourceTree = "<group>"; };
|
E2B6DA00BE52336E23783686 /* Pods.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = Pods.debug.xcconfig; path = "../Pods/Target Support Files/Pods/Pods.debug.xcconfig"; sourceTree = "<group>"; };
|
||||||
@ -212,6 +219,8 @@
|
|||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
EA8CD3EB1AC274BE00C47D0B /* PetApiTest.h */,
|
EA8CD3EB1AC274BE00C47D0B /* PetApiTest.h */,
|
||||||
|
CF5B6E2C1B2BD70800862A1C /* UserApiTest.m */,
|
||||||
|
CFB37D051B2B11DC00D2E5F1 /* StoreApiTest.m */,
|
||||||
CF31D0981B105E4B00509935 /* SWGApiClientTest.m */,
|
CF31D0981B105E4B00509935 /* SWGApiClientTest.m */,
|
||||||
EA6699C71811D2FB00A70D03 /* PetApiTest.m */,
|
EA6699C71811D2FB00A70D03 /* PetApiTest.m */,
|
||||||
EA6699C21811D2FB00A70D03 /* Supporting Files */,
|
EA6699C21811D2FB00A70D03 /* Supporting Files */,
|
||||||
@ -248,6 +257,8 @@
|
|||||||
EAEA85D61811D3AE00F06E69 /* SWGOrder.h */,
|
EAEA85D61811D3AE00F06E69 /* SWGOrder.h */,
|
||||||
EAEA85D71811D3AE00F06E69 /* SWGOrder.m */,
|
EAEA85D71811D3AE00F06E69 /* SWGOrder.m */,
|
||||||
EAB26B0E1AC8E692002F5C7A /* SWGPet.h */,
|
EAB26B0E1AC8E692002F5C7A /* SWGPet.h */,
|
||||||
|
CFCEFE4F1B2C1330006313BE /* SWGJSONResponseSerializer.h */,
|
||||||
|
CFCEFE501B2C1330006313BE /* SWGJSONResponseSerializer.m */,
|
||||||
EAEA85D91811D3AE00F06E69 /* SWGPet.m */,
|
EAEA85D91811D3AE00F06E69 /* SWGPet.m */,
|
||||||
EAEA85DA1811D3AE00F06E69 /* SWGPetApi.h */,
|
EAEA85DA1811D3AE00F06E69 /* SWGPetApi.h */,
|
||||||
EAEA85DB1811D3AE00F06E69 /* SWGPetApi.m */,
|
EAEA85DB1811D3AE00F06E69 /* SWGPetApi.m */,
|
||||||
@ -415,6 +426,7 @@
|
|||||||
EAEA85E91811D3AE00F06E69 /* SWGOrder.m in Sources */,
|
EAEA85E91811D3AE00F06E69 /* SWGOrder.m in Sources */,
|
||||||
EAEA85E81811D3AE00F06E69 /* SWGObject.m in Sources */,
|
EAEA85E81811D3AE00F06E69 /* SWGObject.m in Sources */,
|
||||||
EA8B8AA41AC6683700638FBB /* SWGQueryParamCollection.m in Sources */,
|
EA8B8AA41AC6683700638FBB /* SWGQueryParamCollection.m in Sources */,
|
||||||
|
CFCEFE511B2C1330006313BE /* SWGJSONResponseSerializer.m in Sources */,
|
||||||
EAEA85E71811D3AE00F06E69 /* SWGFile.m in Sources */,
|
EAEA85E71811D3AE00F06E69 /* SWGFile.m in Sources */,
|
||||||
);
|
);
|
||||||
runOnlyForDeploymentPostprocessing = 0;
|
runOnlyForDeploymentPostprocessing = 0;
|
||||||
@ -426,6 +438,8 @@
|
|||||||
EAB26B0C1AC8DF78002F5C7A /* PetApiTest.h in Sources */,
|
EAB26B0C1AC8DF78002F5C7A /* PetApiTest.h in Sources */,
|
||||||
CFD1B6711B05EC7D00DCCD51 /* JSONValueTransformer+ISO8601.m in Sources */,
|
CFD1B6711B05EC7D00DCCD51 /* JSONValueTransformer+ISO8601.m in Sources */,
|
||||||
EAB26B0D1AC8DF78002F5C7A /* PetApiTest.m in Sources */,
|
EAB26B0D1AC8DF78002F5C7A /* PetApiTest.m in Sources */,
|
||||||
|
CF5B6E2D1B2BD70800862A1C /* UserApiTest.m in Sources */,
|
||||||
|
CFB37D061B2B11DD00D2E5F1 /* StoreApiTest.m in Sources */,
|
||||||
CF31D0991B105E4B00509935 /* SWGApiClientTest.m in Sources */,
|
CF31D0991B105E4B00509935 /* SWGApiClientTest.m in Sources */,
|
||||||
);
|
);
|
||||||
runOnlyForDeploymentPostprocessing = 0;
|
runOnlyForDeploymentPostprocessing = 0;
|
||||||
|
@ -8,6 +8,8 @@
|
|||||||
|
|
||||||
#import "ViewController.h"
|
#import "ViewController.h"
|
||||||
#import "SWGPetApi.h"
|
#import "SWGPetApi.h"
|
||||||
|
#import "SWGStoreApi.h"
|
||||||
|
#import "SWGUserApi.h"
|
||||||
#import "SWGConfiguration.h"
|
#import "SWGConfiguration.h"
|
||||||
|
|
||||||
@interface ViewController ()
|
@interface ViewController ()
|
||||||
@ -54,13 +56,13 @@
|
|||||||
// }
|
// }
|
||||||
];
|
];
|
||||||
*/
|
*/
|
||||||
SWGConfiguration *config = [SWGConfiguration sharedConfig];
|
|
||||||
config.username = @"foo";
|
|
||||||
config.password = @"bar";
|
|
||||||
SWGPetApi *api = [[SWGPetApi alloc] init];
|
SWGPetApi *api = [[SWGPetApi alloc] init];
|
||||||
[api addPetWithCompletionBlock:nil
|
[api deletePetWithCompletionBlock:@"hello"
|
||||||
|
petId:@1434529787992
|
||||||
completionHandler:^(NSError *error) {
|
completionHandler:^(NSError *error) {
|
||||||
|
if (error) {
|
||||||
|
NSLog(@"%@", error);
|
||||||
|
}
|
||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,4 +98,77 @@
|
|||||||
XCTAssertEqualObjects(basicAuthCredentials, [config getBasicAuthToken]);
|
XCTAssertEqualObjects(basicAuthCredentials, [config getBasicAuthToken]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)testDeserialize {
|
||||||
|
id data;
|
||||||
|
id result;
|
||||||
|
|
||||||
|
// list of models
|
||||||
|
data =
|
||||||
|
@[
|
||||||
|
@{
|
||||||
|
@"id": @119,
|
||||||
|
@"category": @{
|
||||||
|
@"id": @0,
|
||||||
|
@"name": @"string"
|
||||||
|
},
|
||||||
|
@"name": @"doggie",
|
||||||
|
@"photoUrls": @[
|
||||||
|
@"string"
|
||||||
|
],
|
||||||
|
@"tags": @[
|
||||||
|
@{
|
||||||
|
@"id": @0,
|
||||||
|
@"name": @"string"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
@"status": @"available"
|
||||||
|
|
||||||
|
}];
|
||||||
|
result = [self.apiClient deserialize:data class:@"NSArray<SWGPet>*"];
|
||||||
|
|
||||||
|
XCTAssertTrue([result isKindOfClass:[NSArray class]]);
|
||||||
|
XCTAssertTrue([[result firstObject] isKindOfClass:[SWGPet class]]);
|
||||||
|
XCTAssertEqualObjects([[result firstObject] _id], @119);
|
||||||
|
|
||||||
|
// map of models
|
||||||
|
data =
|
||||||
|
@{
|
||||||
|
@"pet": @{
|
||||||
|
@"id": @119,
|
||||||
|
@"category": @{
|
||||||
|
@"id": @0,
|
||||||
|
@"name": @"string"
|
||||||
|
},
|
||||||
|
@"name": @"doggie",
|
||||||
|
@"photoUrls": @[
|
||||||
|
@"string"
|
||||||
|
],
|
||||||
|
@"tags": @[
|
||||||
|
@{
|
||||||
|
@"id": @0,
|
||||||
|
@"name": @"string"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
@"status": @"available"
|
||||||
|
|
||||||
|
}
|
||||||
|
};
|
||||||
|
result = [self.apiClient deserialize:data class:@"NSDictionary* /* NSString, SWGPet */"];
|
||||||
|
|
||||||
|
XCTAssertTrue([result isKindOfClass:[NSDictionary class]]);
|
||||||
|
XCTAssertTrue([result[@"pet"] isKindOfClass:[SWGPet class]]);
|
||||||
|
XCTAssertEqualObjects([result[@"pet"] _id], @119);
|
||||||
|
|
||||||
|
// pure object
|
||||||
|
result = [self.apiClient deserialize:@"" class:@"NSObject*"];
|
||||||
|
|
||||||
|
XCTAssertTrue([result isKindOfClass:[NSObject class]]);
|
||||||
|
|
||||||
|
// NSString
|
||||||
|
data = @"test string";
|
||||||
|
result = [self.apiClient deserialize:data class:@"NSString*"];
|
||||||
|
|
||||||
|
XCTAssertTrue([result isKindOfClass:[NSString class]]);
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
@ -0,0 +1,44 @@
|
|||||||
|
#import <UIKit/UIKit.h>
|
||||||
|
#import <XCTest/XCTest.h>
|
||||||
|
#import "SWGStoreApi.h"
|
||||||
|
|
||||||
|
@interface StoreApiTest : XCTestCase
|
||||||
|
|
||||||
|
@property (nonatomic) SWGStoreApi *api;
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
@implementation StoreApiTest
|
||||||
|
|
||||||
|
- (void)setUp {
|
||||||
|
[super setUp];
|
||||||
|
self.api = [[SWGStoreApi alloc] init];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)tearDown {
|
||||||
|
[super tearDown];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)testGetInventory {
|
||||||
|
XCTestExpectation *expectation = [self expectationWithDescription:@"testGetPetByStatus"];
|
||||||
|
|
||||||
|
[self.api getInventoryWithCompletionBlock:^(NSDictionary *output, NSError *error) {
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
XCTFail(@"got error %@", error);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!output) {
|
||||||
|
XCTFail(@"failed to fetch inventory");
|
||||||
|
}
|
||||||
|
|
||||||
|
XCTAssertNotNil(output.allKeys);
|
||||||
|
|
||||||
|
[expectation fulfill];
|
||||||
|
}];
|
||||||
|
|
||||||
|
[self waitForExpectationsWithTimeout:10.0 handler:nil];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@end
|
@ -0,0 +1,47 @@
|
|||||||
|
#import <UIKit/UIKit.h>
|
||||||
|
#import <XCTest/XCTest.h>
|
||||||
|
#import "SWGUserApi.h"
|
||||||
|
|
||||||
|
@interface UserApiTest : XCTestCase
|
||||||
|
|
||||||
|
@property (nonatomic) SWGUserApi *api;
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
@implementation UserApiTest
|
||||||
|
|
||||||
|
- (void)setUp {
|
||||||
|
[super setUp];
|
||||||
|
self.api = [[SWGUserApi alloc] init];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)tearDown {
|
||||||
|
[super tearDown];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)testLoginUser {
|
||||||
|
XCTestExpectation *expectation = [self expectationWithDescription:@"test login user"];
|
||||||
|
|
||||||
|
[self.api loginUserWithCompletionBlock:@"test username" password:@"test password" completionHandler:^(NSString *output, NSError *error) {
|
||||||
|
if (error) {
|
||||||
|
XCTFail(@"got error %@", error);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!output) {
|
||||||
|
XCTFail(@"response can't be nil");
|
||||||
|
}
|
||||||
|
|
||||||
|
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"logged in user"
|
||||||
|
options:0
|
||||||
|
error:nil];
|
||||||
|
NSTextCheckingResult *match = [regex firstMatchInString:output
|
||||||
|
options:0
|
||||||
|
range:NSMakeRange(0, [output length])];
|
||||||
|
XCTAssertNotNil(match);
|
||||||
|
[expectation fulfill];
|
||||||
|
}];
|
||||||
|
|
||||||
|
[self waitForExpectationsWithTimeout:10.0 handler:nil];
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
@ -1,5 +1,14 @@
|
|||||||
#import <Foundation/Foundation.h>
|
#import <Foundation/Foundation.h>
|
||||||
|
#import <ISO8601/ISO8601.h>
|
||||||
#import "AFHTTPRequestOperationManager.h"
|
#import "AFHTTPRequestOperationManager.h"
|
||||||
|
#import "SWGJSONResponseSerializer.h"
|
||||||
|
|
||||||
|
#import "SWGUser.h"
|
||||||
|
#import "SWGCategory.h"
|
||||||
|
#import "SWGPet.h"
|
||||||
|
#import "SWGTag.h"
|
||||||
|
#import "SWGOrder.h"
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A key for `NSError` user info dictionaries.
|
* A key for `NSError` user info dictionaries.
|
||||||
@ -159,37 +168,16 @@ extern NSString *const SWGResponseObjectErrorKey;
|
|||||||
WithAuthSettings:(NSArray *)authSettings;
|
WithAuthSettings:(NSArray *)authSettings;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Perform request
|
* Deserialize the given data to Objective-C object.
|
||||||
*
|
*
|
||||||
* Request with non-empty response
|
* @param data The data will be deserialized.
|
||||||
*
|
* @param class The type of objective-c object.
|
||||||
* @param path Request url.
|
|
||||||
* @param method Request method.
|
|
||||||
* @param queryParams Request query parameters.
|
|
||||||
* @param body Request body.
|
|
||||||
* @param headerParams Request header parameters.
|
|
||||||
* @param authSettings Request authentication names.
|
|
||||||
* @param requestContentType Request content-type.
|
|
||||||
* @param responseContentType Response content-type.
|
|
||||||
* @param completionBlock The block will be executed when the request completed.
|
|
||||||
*
|
|
||||||
* @return The request id.
|
|
||||||
*/
|
*/
|
||||||
-(NSNumber*) dictionary:(NSString*) path
|
- (id) deserialize:(id) data class:(NSString *) class;
|
||||||
method:(NSString*) method
|
|
||||||
queryParams:(NSDictionary*) queryParams
|
|
||||||
body:(id) body
|
|
||||||
headerParams:(NSDictionary*) headerParams
|
|
||||||
authSettings: (NSArray *) authSettings
|
|
||||||
requestContentType:(NSString*) requestContentType
|
|
||||||
responseContentType:(NSString*) responseContentType
|
|
||||||
completionBlock:(void (^)(NSDictionary*, NSError *))completionBlock;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Perform request
|
* Perform request
|
||||||
*
|
*
|
||||||
* Request with empty response
|
|
||||||
*
|
|
||||||
* @param path Request url.
|
* @param path Request url.
|
||||||
* @param method Request method.
|
* @param method Request method.
|
||||||
* @param queryParams Request query parameters.
|
* @param queryParams Request query parameters.
|
||||||
@ -202,7 +190,7 @@ extern NSString *const SWGResponseObjectErrorKey;
|
|||||||
*
|
*
|
||||||
* @return The request id.
|
* @return The request id.
|
||||||
*/
|
*/
|
||||||
-(NSNumber*) stringWithCompletionBlock:(NSString*) path
|
-(NSNumber*) requestWithCompletionBlock:(NSString*) path
|
||||||
method:(NSString*) method
|
method:(NSString*) method
|
||||||
queryParams:(NSDictionary*) queryParams
|
queryParams:(NSDictionary*) queryParams
|
||||||
body:(id) body
|
body:(id) body
|
||||||
@ -210,7 +198,10 @@ extern NSString *const SWGResponseObjectErrorKey;
|
|||||||
authSettings: (NSArray *) authSettings
|
authSettings: (NSArray *) authSettings
|
||||||
requestContentType:(NSString*) requestContentType
|
requestContentType:(NSString*) requestContentType
|
||||||
responseContentType:(NSString*) responseContentType
|
responseContentType:(NSString*) responseContentType
|
||||||
completionBlock:(void (^)(NSString*, NSError *))completionBlock;
|
completionBlock:(void (^)(id, NSError *))completionBlock;
|
||||||
|
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -351,171 +351,131 @@ static bool loggingEnabled = true;
|
|||||||
*querys = [NSDictionary dictionaryWithDictionary:querysWithAuth];
|
*querys = [NSDictionary dictionaryWithDictionary:querysWithAuth];
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma mark - Perform Request Methods
|
#pragma mark - Deserialize methods
|
||||||
|
|
||||||
-(NSNumber*) dictionary: (NSString*) path
|
- (id) deserialize:(id) data class:(NSString *) class {
|
||||||
method: (NSString*) method
|
NSRegularExpression *regexp = nil;
|
||||||
queryParams: (NSDictionary*) queryParams
|
NSTextCheckingResult *match = nil;
|
||||||
body: (id) body
|
NSMutableArray *resultArray = nil;
|
||||||
headerParams: (NSDictionary*) headerParams
|
NSMutableDictionary *resultDict = nil;
|
||||||
authSettings: (NSArray *) authSettings
|
|
||||||
requestContentType: (NSString*) requestContentType
|
// return nil if data is nil
|
||||||
responseContentType: (NSString*) responseContentType
|
if (!data) {
|
||||||
completionBlock: (void (^)(NSDictionary*, NSError *))completionBlock {
|
return nil;
|
||||||
// setting request serializer
|
|
||||||
if ([requestContentType isEqualToString:@"application/json"]) {
|
|
||||||
self.requestSerializer = [AFJSONRequestSerializer serializer];
|
|
||||||
}
|
|
||||||
else if ([requestContentType isEqualToString:@"application/x-www-form-urlencoded"]) {
|
|
||||||
self.requestSerializer = [AFHTTPRequestSerializer serializer];
|
|
||||||
}
|
|
||||||
else if ([requestContentType isEqualToString:@"multipart/form-data"]) {
|
|
||||||
self.requestSerializer = [AFHTTPRequestSerializer serializer];
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
NSAssert(false, @"unsupport request type %@", requestContentType);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// setting response serializer
|
// remove "*" from class, if ends with "*"
|
||||||
if ([responseContentType isEqualToString:@"application/json"]) {
|
if ([class hasSuffix:@"*"]) {
|
||||||
self.responseSerializer = [AFJSONResponseSerializer serializer];
|
class = [class substringToIndex:[class length] - 1];
|
||||||
}
|
|
||||||
else {
|
|
||||||
self.responseSerializer = [AFHTTPResponseSerializer serializer];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// auth setting
|
// pure object
|
||||||
[self updateHeaderParams:&headerParams queryParams:&queryParams WithAuthSettings:authSettings];
|
if ([class isEqualToString:@"NSObject"]) {
|
||||||
|
return [[NSObject alloc] init];
|
||||||
NSMutableURLRequest * request = nil;
|
|
||||||
if (body != nil && [body isKindOfClass:[NSArray class]]){
|
|
||||||
SWGFile * file;
|
|
||||||
NSMutableDictionary * params = [[NSMutableDictionary alloc] init];
|
|
||||||
for(id obj in body) {
|
|
||||||
if([obj isKindOfClass:[SWGFile class]]) {
|
|
||||||
file = (SWGFile*) obj;
|
|
||||||
requestContentType = @"multipart/form-data";
|
|
||||||
}
|
|
||||||
else if([obj isKindOfClass:[NSDictionary class]]) {
|
|
||||||
for(NSString * key in obj) {
|
|
||||||
params[key] = obj[key];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
NSString * urlString = [[NSURL URLWithString:path relativeToURL:self.baseURL] absoluteString];
|
|
||||||
|
|
||||||
// request with multipart form
|
|
||||||
if([requestContentType isEqualToString:@"multipart/form-data"]) {
|
|
||||||
request = [self.requestSerializer multipartFormRequestWithMethod: @"POST"
|
|
||||||
URLString: urlString
|
|
||||||
parameters: nil
|
|
||||||
constructingBodyWithBlock: ^(id<AFMultipartFormData> formData) {
|
|
||||||
|
|
||||||
for(NSString * key in params) {
|
|
||||||
NSData* data = [params[key] dataUsingEncoding:NSUTF8StringEncoding];
|
|
||||||
[formData appendPartWithFormData: data name: key];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (file) {
|
// list of models
|
||||||
[formData appendPartWithFileData: [file data]
|
NSString *arrayOfModelsPat = @"NSArray<(.+)>";
|
||||||
name: [file paramName]
|
regexp = [NSRegularExpression regularExpressionWithPattern:arrayOfModelsPat
|
||||||
fileName: [file name]
|
options:NSRegularExpressionCaseInsensitive
|
||||||
mimeType: [file mimeType]];
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
error:nil];
|
error:nil];
|
||||||
}
|
|
||||||
// request with form parameters or json
|
|
||||||
else {
|
|
||||||
NSString* pathWithQueryParams = [self pathWithQueryParamsToString:path queryParams:queryParams];
|
|
||||||
NSString* urlString = [[NSURL URLWithString:pathWithQueryParams relativeToURL:self.baseURL] absoluteString];
|
|
||||||
|
|
||||||
request = [self.requestSerializer requestWithMethod:method
|
match = [regexp firstMatchInString:class
|
||||||
URLString:urlString
|
options:0
|
||||||
parameters:params
|
range:NSMakeRange(0, [class length])];
|
||||||
error:nil];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
NSString * pathWithQueryParams = [self pathWithQueryParamsToString:path queryParams:queryParams];
|
|
||||||
NSString * urlString = [[NSURL URLWithString:pathWithQueryParams relativeToURL:self.baseURL] absoluteString];
|
|
||||||
|
|
||||||
request = [self.requestSerializer requestWithMethod:method
|
if (match) {
|
||||||
URLString:urlString
|
NSString *innerType = [class substringWithRange:[match rangeAtIndex:1]];
|
||||||
parameters:body
|
|
||||||
error:nil];
|
|
||||||
}
|
|
||||||
BOOL hasHeaderParams = false;
|
|
||||||
if(headerParams != nil && [headerParams count] > 0)
|
|
||||||
hasHeaderParams = true;
|
|
||||||
if(offlineState) {
|
|
||||||
NSLog(@"%@ cache forced", path);
|
|
||||||
[request setCachePolicy:NSURLRequestReturnCacheDataDontLoad];
|
|
||||||
}
|
|
||||||
else if(!hasHeaderParams && [method isEqualToString:@"GET"] && cacheEnabled) {
|
|
||||||
NSLog(@"%@ cache enabled", path);
|
|
||||||
[request setCachePolicy:NSURLRequestUseProtocolCachePolicy];
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
NSLog(@"%@ cache disabled", path);
|
|
||||||
[request setCachePolicy:NSURLRequestReloadIgnoringLocalCacheData];
|
|
||||||
}
|
|
||||||
|
|
||||||
if(body != nil) {
|
resultArray = [NSMutableArray arrayWithCapacity:[data count]];
|
||||||
if([body isKindOfClass:[NSDictionary class]] || [body isKindOfClass:[NSArray class]]){
|
[data enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
|
||||||
[self.requestSerializer setValue:requestContentType forHTTPHeaderField:@"Content-Type"];
|
[resultArray addObject:[self deserialize:obj class:innerType]];
|
||||||
}
|
|
||||||
else if ([body isKindOfClass:[SWGFile class]]) {}
|
|
||||||
else {
|
|
||||||
NSAssert(false, @"unsupported post type!");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(headerParams != nil){
|
|
||||||
for(NSString * key in [headerParams keyEnumerator]){
|
|
||||||
[request setValue:[headerParams valueForKey:key] forHTTPHeaderField:key];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
[self.requestSerializer setValue:responseContentType forHTTPHeaderField:@"Accept"];
|
|
||||||
|
|
||||||
// Always disable cookies!
|
|
||||||
[request setHTTPShouldHandleCookies:NO];
|
|
||||||
|
|
||||||
|
|
||||||
if (self.logRequests) {
|
|
||||||
[self logRequest:request];
|
|
||||||
}
|
|
||||||
|
|
||||||
NSNumber* requestId = [SWGApiClient queueRequest];
|
|
||||||
AFHTTPRequestOperation *op =
|
|
||||||
[self HTTPRequestOperationWithRequest:request
|
|
||||||
success:^(AFHTTPRequestOperation *operation, id JSON) {
|
|
||||||
if([self executeRequestWithId:requestId]) {
|
|
||||||
if(self.logServerResponses)
|
|
||||||
[self logResponse:JSON forRequest:request error:nil];
|
|
||||||
completionBlock(JSON, nil);
|
|
||||||
}
|
|
||||||
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
|
|
||||||
if([self executeRequestWithId:requestId]) {
|
|
||||||
NSMutableDictionary *userInfo = [error.userInfo mutableCopy];
|
|
||||||
if(operation.responseObject) {
|
|
||||||
// Add in the (parsed) response body.
|
|
||||||
userInfo[SWGResponseObjectErrorKey] = operation.responseObject;
|
|
||||||
}
|
|
||||||
NSError *augmentedError = [error initWithDomain:error.domain code:error.code userInfo:userInfo];
|
|
||||||
|
|
||||||
if(self.logServerResponses)
|
|
||||||
[self logResponse:nil forRequest:request error:augmentedError];
|
|
||||||
completionBlock(nil, augmentedError);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
[self.operationQueue addOperation:op];
|
return resultArray;
|
||||||
return requestId;
|
}
|
||||||
|
|
||||||
|
// list of primitives
|
||||||
|
NSString *arrayOfPrimitivesPet = @"NSArray";
|
||||||
|
regexp = [NSRegularExpression regularExpressionWithPattern:arrayOfPrimitivesPet
|
||||||
|
options:NSRegularExpressionCaseInsensitive
|
||||||
|
error:nil];
|
||||||
|
match = [regexp firstMatchInString:class
|
||||||
|
options:0
|
||||||
|
range:NSMakeRange(0, [class length])];
|
||||||
|
|
||||||
|
if (match) {
|
||||||
|
resultArray = [NSMutableArray arrayWithCapacity:[data count]];
|
||||||
|
[data enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
|
||||||
|
[resultArray addObject:[self deserialize:obj class:NSStringFromClass([obj class])]];
|
||||||
|
}];
|
||||||
|
|
||||||
|
return resultArray;
|
||||||
|
}
|
||||||
|
|
||||||
|
// map
|
||||||
|
NSString *dictPat = @"NSDictionary\\* /\\* (.+), (.+) \\*/";
|
||||||
|
regexp = [NSRegularExpression regularExpressionWithPattern:dictPat
|
||||||
|
options:NSRegularExpressionCaseInsensitive
|
||||||
|
error:nil];
|
||||||
|
match = [regexp firstMatchInString:class
|
||||||
|
options:0
|
||||||
|
range:NSMakeRange(0, [class length])];
|
||||||
|
|
||||||
|
if (match) {
|
||||||
|
NSString *valueType = [class substringWithRange:[match rangeAtIndex:2]];
|
||||||
|
|
||||||
|
resultDict = [NSMutableDictionary dictionaryWithCapacity:[data count]];
|
||||||
|
[data enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
|
||||||
|
[resultDict setValue:[self deserialize:obj class:valueType] forKey:key];
|
||||||
|
}];
|
||||||
|
|
||||||
|
return resultDict;
|
||||||
|
}
|
||||||
|
|
||||||
|
// primitives
|
||||||
|
NSArray *primitiveTypes = @[@"NSString", @"NSDate", @"BOOL", @"NSNumber"];
|
||||||
|
|
||||||
|
if ([primitiveTypes containsObject:class]) {
|
||||||
|
if ([class isEqualToString:@"NSString"]) {
|
||||||
|
return [NSString stringWithString:data];
|
||||||
|
}
|
||||||
|
else if ([class isEqualToString:@"NSDate"]) {
|
||||||
|
return [NSDate dateWithISO8601String:data];
|
||||||
|
}
|
||||||
|
else if ([class isEqualToString:@"BOOL"]) {
|
||||||
|
// Returns YES on encountering one of "Y", "y", "T", "t", or a
|
||||||
|
// digit 1-9—the method ignores any trailing characters
|
||||||
|
// NSString => BOOL => NSNumber
|
||||||
|
return [NSNumber numberWithBool:[data boolValue]];
|
||||||
|
}
|
||||||
|
else if ([class isEqualToString:@"NSNumber"]) {
|
||||||
|
// NSNumber from NSNumber
|
||||||
|
if ([data isKindOfClass:[NSNumber class]]) {
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
// NSNumber from NSString
|
||||||
|
else {
|
||||||
|
NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
|
||||||
|
formatter.numberStyle = NSNumberFormatterDecimalStyle;
|
||||||
|
return [formatter numberFromString:data];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// model
|
||||||
|
Class ModelClass = NSClassFromString(class);
|
||||||
|
if ([ModelClass instancesRespondToSelector:@selector(initWithDictionary:error:)]) {
|
||||||
|
return [[ModelClass alloc] initWithDictionary:data error:nil];
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
-(NSNumber*) stringWithCompletionBlock: (NSString*) path
|
#pragma mark - Perform Request Methods
|
||||||
|
|
||||||
|
-(NSNumber*) requestWithCompletionBlock: (NSString*) path
|
||||||
method: (NSString*) method
|
method: (NSString*) method
|
||||||
queryParams: (NSDictionary*) queryParams
|
queryParams: (NSDictionary*) queryParams
|
||||||
body: (id) body
|
body: (id) body
|
||||||
@ -523,7 +483,7 @@ static bool loggingEnabled = true;
|
|||||||
authSettings: (NSArray *) authSettings
|
authSettings: (NSArray *) authSettings
|
||||||
requestContentType: (NSString*) requestContentType
|
requestContentType: (NSString*) requestContentType
|
||||||
responseContentType: (NSString*) responseContentType
|
responseContentType: (NSString*) responseContentType
|
||||||
completionBlock: (void (^)(NSString*, NSError *))completionBlock {
|
completionBlock: (void (^)(id, NSError *))completionBlock {
|
||||||
// setting request serializer
|
// setting request serializer
|
||||||
if ([requestContentType isEqualToString:@"application/json"]) {
|
if ([requestContentType isEqualToString:@"application/json"]) {
|
||||||
self.requestSerializer = [AFJSONRequestSerializer serializer];
|
self.requestSerializer = [AFJSONRequestSerializer serializer];
|
||||||
@ -540,7 +500,7 @@ static bool loggingEnabled = true;
|
|||||||
|
|
||||||
// setting response serializer
|
// setting response serializer
|
||||||
if ([responseContentType isEqualToString:@"application/json"]) {
|
if ([responseContentType isEqualToString:@"application/json"]) {
|
||||||
self.responseSerializer = [AFJSONResponseSerializer serializer];
|
self.responseSerializer = [SWGJSONResponseSerializer serializer];
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
self.responseSerializer = [AFHTTPResponseSerializer serializer];
|
self.responseSerializer = [AFHTTPResponseSerializer serializer];
|
||||||
@ -648,11 +608,11 @@ static bool loggingEnabled = true;
|
|||||||
|
|
||||||
NSNumber* requestId = [SWGApiClient queueRequest];
|
NSNumber* requestId = [SWGApiClient queueRequest];
|
||||||
AFHTTPRequestOperation *op = [self HTTPRequestOperationWithRequest:request
|
AFHTTPRequestOperation *op = [self HTTPRequestOperationWithRequest:request
|
||||||
success:^(AFHTTPRequestOperation *operation, id responseObject) {
|
success:^(AFHTTPRequestOperation *operation, id response) {
|
||||||
NSString *response = [operation responseString];
|
|
||||||
if([self executeRequestWithId:requestId]) {
|
if([self executeRequestWithId:requestId]) {
|
||||||
if(self.logServerResponses)
|
if(self.logServerResponses) {
|
||||||
[self logResponse:responseObject forRequest:request error:nil];
|
[self logResponse:response forRequest:request error:nil];
|
||||||
|
}
|
||||||
completionBlock(response, nil);
|
completionBlock(response, nil);
|
||||||
}
|
}
|
||||||
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
|
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
|
||||||
@ -683,3 +643,4 @@ static bool loggingEnabled = true;
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -0,0 +1,6 @@
|
|||||||
|
#import <Foundation/Foundation.h>
|
||||||
|
#import <AFNetworking/AFURLResponseSerialization.h>
|
||||||
|
|
||||||
|
@interface SWGJSONResponseSerializer : AFJSONResponseSerializer
|
||||||
|
|
||||||
|
@end
|
@ -0,0 +1,39 @@
|
|||||||
|
#import "SWGJSONResponseSerializer.h"
|
||||||
|
|
||||||
|
static BOOL JSONParseError(NSError *error) {
|
||||||
|
if ([error.domain isEqualToString:NSCocoaErrorDomain] && error.code == 3840) {
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NO;
|
||||||
|
}
|
||||||
|
|
||||||
|
@implementation SWGJSONResponseSerializer
|
||||||
|
|
||||||
|
///
|
||||||
|
/// When customize a response serializer,
|
||||||
|
/// the serializer must conform the protocol `AFURLResponseSerialization`
|
||||||
|
/// and implements the protocol method `responseObjectForResponse:error:`
|
||||||
|
///
|
||||||
|
/// @param response The response to be processed.
|
||||||
|
/// @param data The response data to be decoded.
|
||||||
|
/// @param error The error that occurred while attempting to decode the respnse data.
|
||||||
|
///
|
||||||
|
/// @return The object decoded from the specified response data.
|
||||||
|
///
|
||||||
|
- (id) responseObjectForResponse:(NSURLResponse *)response
|
||||||
|
data:(NSData *)data
|
||||||
|
error:(NSError *__autoreleasing *)error {
|
||||||
|
NSDictionary *responseJson = [super responseObjectForResponse:response data:data error:error];
|
||||||
|
|
||||||
|
// if response data is not a valid json, return string of data.
|
||||||
|
if (JSONParseError(*error)) {
|
||||||
|
*error = nil;
|
||||||
|
NSString *responseString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
|
||||||
|
return responseString;
|
||||||
|
}
|
||||||
|
|
||||||
|
return responseJson;
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
@ -15,98 +15,92 @@
|
|||||||
+(SWGPetApi*) apiWithHeader:(NSString*)headerValue key:(NSString*)key;
|
+(SWGPetApi*) apiWithHeader:(NSString*)headerValue key:(NSString*)key;
|
||||||
+(void) setBasePath:(NSString*)basePath;
|
+(void) setBasePath:(NSString*)basePath;
|
||||||
+(NSString*) getBasePath;
|
+(NSString*) getBasePath;
|
||||||
/**
|
///
|
||||||
|
///
|
||||||
Update an existing pet
|
/// Update an existing pet
|
||||||
|
///
|
||||||
|
///
|
||||||
@param body Pet object that needs to be added to the store
|
/// @param body Pet object that needs to be added to the store
|
||||||
|
///
|
||||||
|
///
|
||||||
return type:
|
/// @return
|
||||||
*/
|
|
||||||
-(NSNumber*) updatePetWithCompletionBlock :(SWGPet*) body
|
-(NSNumber*) updatePetWithCompletionBlock :(SWGPet*) body
|
||||||
|
|
||||||
|
|
||||||
completionHandler: (void (^)(NSError* error))completionBlock;
|
completionHandler: (void (^)(NSError* error))completionBlock;
|
||||||
|
|
||||||
|
|
||||||
/**
|
///
|
||||||
|
///
|
||||||
Add a new pet to the store
|
/// Add a new pet to the store
|
||||||
|
///
|
||||||
|
///
|
||||||
@param body Pet object that needs to be added to the store
|
/// @param body Pet object that needs to be added to the store
|
||||||
|
///
|
||||||
|
///
|
||||||
return type:
|
/// @return
|
||||||
*/
|
|
||||||
-(NSNumber*) addPetWithCompletionBlock :(SWGPet*) body
|
-(NSNumber*) addPetWithCompletionBlock :(SWGPet*) body
|
||||||
|
|
||||||
|
|
||||||
completionHandler: (void (^)(NSError* error))completionBlock;
|
completionHandler: (void (^)(NSError* error))completionBlock;
|
||||||
|
|
||||||
|
|
||||||
/**
|
///
|
||||||
|
///
|
||||||
Finds Pets by status
|
/// Finds Pets by status
|
||||||
Multiple status values can be provided with comma seperated strings
|
/// Multiple status values can be provided with comma seperated strings
|
||||||
|
///
|
||||||
@param status Status values that need to be considered for filter
|
/// @param status Status values that need to be considered for filter
|
||||||
|
///
|
||||||
|
///
|
||||||
return type: NSArray<SWGPet>*
|
/// @return NSArray<SWGPet>*
|
||||||
*/
|
|
||||||
-(NSNumber*) findPetsByStatusWithCompletionBlock :(NSArray*) status
|
-(NSNumber*) findPetsByStatusWithCompletionBlock :(NSArray*) status
|
||||||
|
|
||||||
completionHandler: (void (^)(NSArray<SWGPet>* output, NSError* error))completionBlock;
|
completionHandler: (void (^)(NSArray<SWGPet>* output, NSError* error))completionBlock;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
///
|
||||||
|
///
|
||||||
Finds Pets by tags
|
/// Finds Pets by tags
|
||||||
Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing.
|
/// Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing.
|
||||||
|
///
|
||||||
@param tags Tags to filter by
|
/// @param tags Tags to filter by
|
||||||
|
///
|
||||||
|
///
|
||||||
return type: NSArray<SWGPet>*
|
/// @return NSArray<SWGPet>*
|
||||||
*/
|
|
||||||
-(NSNumber*) findPetsByTagsWithCompletionBlock :(NSArray*) tags
|
-(NSNumber*) findPetsByTagsWithCompletionBlock :(NSArray*) tags
|
||||||
|
|
||||||
completionHandler: (void (^)(NSArray<SWGPet>* output, NSError* error))completionBlock;
|
completionHandler: (void (^)(NSArray<SWGPet>* output, NSError* error))completionBlock;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
///
|
||||||
|
///
|
||||||
Find pet by ID
|
/// Find pet by ID
|
||||||
Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions
|
/// Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions
|
||||||
|
///
|
||||||
@param petId ID of pet that needs to be fetched
|
/// @param petId ID of pet that needs to be fetched
|
||||||
|
///
|
||||||
|
///
|
||||||
return type: SWGPet*
|
/// @return SWGPet*
|
||||||
*/
|
|
||||||
-(NSNumber*) getPetByIdWithCompletionBlock :(NSNumber*) petId
|
-(NSNumber*) getPetByIdWithCompletionBlock :(NSNumber*) petId
|
||||||
|
|
||||||
completionHandler: (void (^)(SWGPet* output, NSError* error))completionBlock;
|
completionHandler: (void (^)(SWGPet* output, NSError* error))completionBlock;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
///
|
||||||
|
///
|
||||||
Updates a pet in the store with form data
|
/// Updates a pet in the store with form data
|
||||||
|
///
|
||||||
|
///
|
||||||
@param petId ID of pet that needs to be updated
|
/// @param petId ID of pet that needs to be updated
|
||||||
@param name Updated name of the pet
|
/// @param name Updated name of the pet
|
||||||
@param status Updated status of the pet
|
/// @param status Updated status of the pet
|
||||||
|
///
|
||||||
|
///
|
||||||
return type:
|
/// @return
|
||||||
*/
|
|
||||||
-(NSNumber*) updatePetWithFormWithCompletionBlock :(NSString*) petId
|
-(NSNumber*) updatePetWithFormWithCompletionBlock :(NSString*) petId
|
||||||
name:(NSString*) name
|
name:(NSString*) name
|
||||||
status:(NSString*) status
|
status:(NSString*) status
|
||||||
@ -115,17 +109,16 @@
|
|||||||
completionHandler: (void (^)(NSError* error))completionBlock;
|
completionHandler: (void (^)(NSError* error))completionBlock;
|
||||||
|
|
||||||
|
|
||||||
/**
|
///
|
||||||
|
///
|
||||||
Deletes a pet
|
/// Deletes a pet
|
||||||
|
///
|
||||||
|
///
|
||||||
@param apiKey
|
/// @param apiKey
|
||||||
@param petId Pet id to delete
|
/// @param petId Pet id to delete
|
||||||
|
///
|
||||||
|
///
|
||||||
return type:
|
/// @return
|
||||||
*/
|
|
||||||
-(NSNumber*) deletePetWithCompletionBlock :(NSString*) apiKey
|
-(NSNumber*) deletePetWithCompletionBlock :(NSString*) apiKey
|
||||||
petId:(NSNumber*) petId
|
petId:(NSNumber*) petId
|
||||||
|
|
||||||
@ -133,18 +126,17 @@
|
|||||||
completionHandler: (void (^)(NSError* error))completionBlock;
|
completionHandler: (void (^)(NSError* error))completionBlock;
|
||||||
|
|
||||||
|
|
||||||
/**
|
///
|
||||||
|
///
|
||||||
uploads an image
|
/// uploads an image
|
||||||
|
///
|
||||||
|
///
|
||||||
@param petId ID of pet to update
|
/// @param petId ID of pet to update
|
||||||
@param additionalMetadata Additional data to pass to server
|
/// @param additionalMetadata Additional data to pass to server
|
||||||
@param file file to upload
|
/// @param file file to upload
|
||||||
|
///
|
||||||
|
///
|
||||||
return type:
|
/// @return
|
||||||
*/
|
|
||||||
-(NSNumber*) uploadFileWithCompletionBlock :(NSNumber*) petId
|
-(NSNumber*) uploadFileWithCompletionBlock :(NSNumber*) petId
|
||||||
additionalMetadata:(NSString*) additionalMetadata
|
additionalMetadata:(NSString*) additionalMetadata
|
||||||
file:(SWGFile*) file
|
file:(SWGFile*) file
|
||||||
|
@ -71,13 +71,15 @@ static NSString * basePath = @"http://petstore.swagger.io/v2";
|
|||||||
return [SWGApiClient requestQueueSize];
|
return [SWGApiClient requestQueueSize];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#pragma mark - Api Methods
|
||||||
|
|
||||||
/*!
|
///
|
||||||
* Update an existing pet
|
/// Update an existing pet
|
||||||
*
|
///
|
||||||
* \param body Pet object that needs to be added to the store
|
/// @param body Pet object that needs to be added to the store
|
||||||
* \returns void
|
///
|
||||||
*/
|
/// @returns void
|
||||||
|
///
|
||||||
-(NSNumber*) updatePetWithCompletionBlock: (SWGPet*) body
|
-(NSNumber*) updatePetWithCompletionBlock: (SWGPet*) body
|
||||||
|
|
||||||
|
|
||||||
@ -153,14 +155,7 @@ static NSString * basePath = @"http://petstore.swagger.io/v2";
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return [self.apiClient requestWithCompletionBlock: requestUrl
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// it's void
|
|
||||||
return [self.apiClient stringWithCompletionBlock: requestUrl
|
|
||||||
method: @"PUT"
|
method: @"PUT"
|
||||||
queryParams: queryParams
|
queryParams: queryParams
|
||||||
body: bodyDictionary
|
body: bodyDictionary
|
||||||
@ -168,23 +163,20 @@ static NSString * basePath = @"http://petstore.swagger.io/v2";
|
|||||||
authSettings: authSettings
|
authSettings: authSettings
|
||||||
requestContentType: requestContentType
|
requestContentType: requestContentType
|
||||||
responseContentType: responseContentType
|
responseContentType: responseContentType
|
||||||
completionBlock: ^(NSString *data, NSError *error) {
|
completionBlock: ^(id data, NSError *error) {
|
||||||
if (error) {
|
|
||||||
completionBlock(error);
|
completionBlock(error);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
completionBlock(nil);
|
];
|
||||||
}];
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
///
|
||||||
* Add a new pet to the store
|
/// Add a new pet to the store
|
||||||
*
|
///
|
||||||
* \param body Pet object that needs to be added to the store
|
/// @param body Pet object that needs to be added to the store
|
||||||
* \returns void
|
///
|
||||||
*/
|
/// @returns void
|
||||||
|
///
|
||||||
-(NSNumber*) addPetWithCompletionBlock: (SWGPet*) body
|
-(NSNumber*) addPetWithCompletionBlock: (SWGPet*) body
|
||||||
|
|
||||||
|
|
||||||
@ -260,14 +252,7 @@ static NSString * basePath = @"http://petstore.swagger.io/v2";
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return [self.apiClient requestWithCompletionBlock: requestUrl
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// it's void
|
|
||||||
return [self.apiClient stringWithCompletionBlock: requestUrl
|
|
||||||
method: @"POST"
|
method: @"POST"
|
||||||
queryParams: queryParams
|
queryParams: queryParams
|
||||||
body: bodyDictionary
|
body: bodyDictionary
|
||||||
@ -275,23 +260,20 @@ static NSString * basePath = @"http://petstore.swagger.io/v2";
|
|||||||
authSettings: authSettings
|
authSettings: authSettings
|
||||||
requestContentType: requestContentType
|
requestContentType: requestContentType
|
||||||
responseContentType: responseContentType
|
responseContentType: responseContentType
|
||||||
completionBlock: ^(NSString *data, NSError *error) {
|
completionBlock: ^(id data, NSError *error) {
|
||||||
if (error) {
|
|
||||||
completionBlock(error);
|
completionBlock(error);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
completionBlock(nil);
|
];
|
||||||
}];
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
///
|
||||||
* Finds Pets by status
|
/// Finds Pets by status
|
||||||
* Multiple status values can be provided with comma seperated strings
|
/// Multiple status values can be provided with comma seperated strings
|
||||||
* \param status Status values that need to be considered for filter
|
/// @param status Status values that need to be considered for filter
|
||||||
* \returns NSArray<SWGPet>*
|
///
|
||||||
*/
|
/// @returns NSArray<SWGPet>*
|
||||||
|
///
|
||||||
-(NSNumber*) findPetsByStatusWithCompletionBlock: (NSArray*) status
|
-(NSNumber*) findPetsByStatusWithCompletionBlock: (NSArray*) status
|
||||||
|
|
||||||
completionHandler: (void (^)(NSArray<SWGPet>* output, NSError* error))completionBlock
|
completionHandler: (void (^)(NSArray<SWGPet>* output, NSError* error))completionBlock
|
||||||
@ -350,11 +332,7 @@ static NSString * basePath = @"http://petstore.swagger.io/v2";
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return [self.apiClient requestWithCompletionBlock: requestUrl
|
||||||
|
|
||||||
// response is in a container
|
|
||||||
// array container response type
|
|
||||||
return [self.apiClient dictionary: requestUrl
|
|
||||||
method: @"GET"
|
method: @"GET"
|
||||||
queryParams: queryParams
|
queryParams: queryParams
|
||||||
body: bodyDictionary
|
body: bodyDictionary
|
||||||
@ -362,40 +340,20 @@ static NSString * basePath = @"http://petstore.swagger.io/v2";
|
|||||||
authSettings: authSettings
|
authSettings: authSettings
|
||||||
requestContentType: requestContentType
|
requestContentType: requestContentType
|
||||||
responseContentType: responseContentType
|
responseContentType: responseContentType
|
||||||
completionBlock: ^(NSDictionary *data, NSError *error) {
|
completionBlock: ^(id data, NSError *error) {
|
||||||
if (error) {
|
|
||||||
completionBlock(nil, error);
|
completionBlock([self.apiClient deserialize: data class:@"NSArray<SWGPet>*"], error);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
];
|
||||||
if([data isKindOfClass:[NSArray class]]){
|
|
||||||
NSMutableArray * objs = [[NSMutableArray alloc] initWithCapacity:[data count]];
|
|
||||||
for (NSDictionary* dict in (NSArray*)data) {
|
|
||||||
|
|
||||||
|
|
||||||
SWGPet* d = [[SWGPet alloc] initWithDictionary:dict error:nil];
|
|
||||||
|
|
||||||
[objs addObject:d];
|
|
||||||
}
|
|
||||||
completionBlock((NSArray<SWGPet>*)objs, nil);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}];
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
///
|
||||||
* Finds Pets by tags
|
/// Finds Pets by tags
|
||||||
* Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing.
|
/// Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing.
|
||||||
* \param tags Tags to filter by
|
/// @param tags Tags to filter by
|
||||||
* \returns NSArray<SWGPet>*
|
///
|
||||||
*/
|
/// @returns NSArray<SWGPet>*
|
||||||
|
///
|
||||||
-(NSNumber*) findPetsByTagsWithCompletionBlock: (NSArray*) tags
|
-(NSNumber*) findPetsByTagsWithCompletionBlock: (NSArray*) tags
|
||||||
|
|
||||||
completionHandler: (void (^)(NSArray<SWGPet>* output, NSError* error))completionBlock
|
completionHandler: (void (^)(NSArray<SWGPet>* output, NSError* error))completionBlock
|
||||||
@ -454,11 +412,7 @@ static NSString * basePath = @"http://petstore.swagger.io/v2";
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return [self.apiClient requestWithCompletionBlock: requestUrl
|
||||||
|
|
||||||
// response is in a container
|
|
||||||
// array container response type
|
|
||||||
return [self.apiClient dictionary: requestUrl
|
|
||||||
method: @"GET"
|
method: @"GET"
|
||||||
queryParams: queryParams
|
queryParams: queryParams
|
||||||
body: bodyDictionary
|
body: bodyDictionary
|
||||||
@ -466,40 +420,20 @@ static NSString * basePath = @"http://petstore.swagger.io/v2";
|
|||||||
authSettings: authSettings
|
authSettings: authSettings
|
||||||
requestContentType: requestContentType
|
requestContentType: requestContentType
|
||||||
responseContentType: responseContentType
|
responseContentType: responseContentType
|
||||||
completionBlock: ^(NSDictionary *data, NSError *error) {
|
completionBlock: ^(id data, NSError *error) {
|
||||||
if (error) {
|
|
||||||
completionBlock(nil, error);
|
completionBlock([self.apiClient deserialize: data class:@"NSArray<SWGPet>*"], error);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
];
|
||||||
if([data isKindOfClass:[NSArray class]]){
|
|
||||||
NSMutableArray * objs = [[NSMutableArray alloc] initWithCapacity:[data count]];
|
|
||||||
for (NSDictionary* dict in (NSArray*)data) {
|
|
||||||
|
|
||||||
|
|
||||||
SWGPet* d = [[SWGPet alloc] initWithDictionary:dict error:nil];
|
|
||||||
|
|
||||||
[objs addObject:d];
|
|
||||||
}
|
|
||||||
completionBlock((NSArray<SWGPet>*)objs, nil);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}];
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
///
|
||||||
* Find pet by ID
|
/// Find pet by ID
|
||||||
* Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions
|
/// Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions
|
||||||
* \param petId ID of pet that needs to be fetched
|
/// @param petId ID of pet that needs to be fetched
|
||||||
* \returns SWGPet*
|
///
|
||||||
*/
|
/// @returns SWGPet*
|
||||||
|
///
|
||||||
-(NSNumber*) getPetByIdWithCompletionBlock: (NSNumber*) petId
|
-(NSNumber*) getPetByIdWithCompletionBlock: (NSNumber*) petId
|
||||||
|
|
||||||
completionHandler: (void (^)(SWGPet* output, NSError* error))completionBlock
|
completionHandler: (void (^)(SWGPet* output, NSError* error))completionBlock
|
||||||
@ -556,19 +490,7 @@ static NSString * basePath = @"http://petstore.swagger.io/v2";
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return [self.apiClient requestWithCompletionBlock: requestUrl
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// non container response
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// complex response
|
|
||||||
|
|
||||||
// comples response type
|
|
||||||
return [self.apiClient dictionary: requestUrl
|
|
||||||
method: @"GET"
|
method: @"GET"
|
||||||
queryParams: queryParams
|
queryParams: queryParams
|
||||||
body: bodyDictionary
|
body: bodyDictionary
|
||||||
@ -576,34 +498,24 @@ static NSString * basePath = @"http://petstore.swagger.io/v2";
|
|||||||
authSettings: authSettings
|
authSettings: authSettings
|
||||||
requestContentType: requestContentType
|
requestContentType: requestContentType
|
||||||
responseContentType: responseContentType
|
responseContentType: responseContentType
|
||||||
completionBlock: ^(NSDictionary *data, NSError *error) {
|
completionBlock: ^(id data, NSError *error) {
|
||||||
if (error) {
|
|
||||||
completionBlock(nil, error);
|
|
||||||
|
|
||||||
return;
|
completionBlock([self.apiClient deserialize: data class:@"SWGPet*"], error);
|
||||||
}
|
}
|
||||||
SWGPet* result = nil;
|
];
|
||||||
if (data) {
|
|
||||||
result = [[SWGPet alloc] initWithDictionary:data error:nil];
|
|
||||||
}
|
|
||||||
completionBlock(result , nil);
|
|
||||||
|
|
||||||
}];
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
///
|
||||||
* Updates a pet in the store with form data
|
/// Updates a pet in the store with form data
|
||||||
*
|
///
|
||||||
* \param petId ID of pet that needs to be updated
|
/// @param petId ID of pet that needs to be updated
|
||||||
* \param name Updated name of the pet
|
///
|
||||||
* \param status Updated status of the pet
|
/// @param name Updated name of the pet
|
||||||
* \returns void
|
///
|
||||||
*/
|
/// @param status Updated status of the pet
|
||||||
|
///
|
||||||
|
/// @returns void
|
||||||
|
///
|
||||||
-(NSNumber*) updatePetWithFormWithCompletionBlock: (NSString*) petId
|
-(NSNumber*) updatePetWithFormWithCompletionBlock: (NSString*) petId
|
||||||
name: (NSString*) name
|
name: (NSString*) name
|
||||||
status: (NSString*) status
|
status: (NSString*) status
|
||||||
@ -678,14 +590,7 @@ static NSString * basePath = @"http://petstore.swagger.io/v2";
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return [self.apiClient requestWithCompletionBlock: requestUrl
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// it's void
|
|
||||||
return [self.apiClient stringWithCompletionBlock: requestUrl
|
|
||||||
method: @"POST"
|
method: @"POST"
|
||||||
queryParams: queryParams
|
queryParams: queryParams
|
||||||
body: bodyDictionary
|
body: bodyDictionary
|
||||||
@ -693,24 +598,22 @@ static NSString * basePath = @"http://petstore.swagger.io/v2";
|
|||||||
authSettings: authSettings
|
authSettings: authSettings
|
||||||
requestContentType: requestContentType
|
requestContentType: requestContentType
|
||||||
responseContentType: responseContentType
|
responseContentType: responseContentType
|
||||||
completionBlock: ^(NSString *data, NSError *error) {
|
completionBlock: ^(id data, NSError *error) {
|
||||||
if (error) {
|
|
||||||
completionBlock(error);
|
completionBlock(error);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
completionBlock(nil);
|
];
|
||||||
}];
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
///
|
||||||
* Deletes a pet
|
/// Deletes a pet
|
||||||
*
|
///
|
||||||
* \param apiKey
|
/// @param apiKey
|
||||||
* \param petId Pet id to delete
|
///
|
||||||
* \returns void
|
/// @param petId Pet id to delete
|
||||||
*/
|
///
|
||||||
|
/// @returns void
|
||||||
|
///
|
||||||
-(NSNumber*) deletePetWithCompletionBlock: (NSString*) apiKey
|
-(NSNumber*) deletePetWithCompletionBlock: (NSString*) apiKey
|
||||||
petId: (NSNumber*) petId
|
petId: (NSNumber*) petId
|
||||||
|
|
||||||
@ -770,14 +673,7 @@ static NSString * basePath = @"http://petstore.swagger.io/v2";
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return [self.apiClient requestWithCompletionBlock: requestUrl
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// it's void
|
|
||||||
return [self.apiClient stringWithCompletionBlock: requestUrl
|
|
||||||
method: @"DELETE"
|
method: @"DELETE"
|
||||||
queryParams: queryParams
|
queryParams: queryParams
|
||||||
body: bodyDictionary
|
body: bodyDictionary
|
||||||
@ -785,25 +681,24 @@ static NSString * basePath = @"http://petstore.swagger.io/v2";
|
|||||||
authSettings: authSettings
|
authSettings: authSettings
|
||||||
requestContentType: requestContentType
|
requestContentType: requestContentType
|
||||||
responseContentType: responseContentType
|
responseContentType: responseContentType
|
||||||
completionBlock: ^(NSString *data, NSError *error) {
|
completionBlock: ^(id data, NSError *error) {
|
||||||
if (error) {
|
|
||||||
completionBlock(error);
|
completionBlock(error);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
completionBlock(nil);
|
];
|
||||||
}];
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
///
|
||||||
* uploads an image
|
/// uploads an image
|
||||||
*
|
///
|
||||||
* \param petId ID of pet to update
|
/// @param petId ID of pet to update
|
||||||
* \param additionalMetadata Additional data to pass to server
|
///
|
||||||
* \param file file to upload
|
/// @param additionalMetadata Additional data to pass to server
|
||||||
* \returns void
|
///
|
||||||
*/
|
/// @param file file to upload
|
||||||
|
///
|
||||||
|
/// @returns void
|
||||||
|
///
|
||||||
-(NSNumber*) uploadFileWithCompletionBlock: (NSNumber*) petId
|
-(NSNumber*) uploadFileWithCompletionBlock: (NSNumber*) petId
|
||||||
additionalMetadata: (NSString*) additionalMetadata
|
additionalMetadata: (NSString*) additionalMetadata
|
||||||
file: (SWGFile*) file
|
file: (SWGFile*) file
|
||||||
@ -885,14 +780,7 @@ static NSString * basePath = @"http://petstore.swagger.io/v2";
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return [self.apiClient requestWithCompletionBlock: requestUrl
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// it's void
|
|
||||||
return [self.apiClient stringWithCompletionBlock: requestUrl
|
|
||||||
method: @"POST"
|
method: @"POST"
|
||||||
queryParams: queryParams
|
queryParams: queryParams
|
||||||
body: bodyDictionary
|
body: bodyDictionary
|
||||||
@ -900,15 +788,11 @@ static NSString * basePath = @"http://petstore.swagger.io/v2";
|
|||||||
authSettings: authSettings
|
authSettings: authSettings
|
||||||
requestContentType: requestContentType
|
requestContentType: requestContentType
|
||||||
responseContentType: responseContentType
|
responseContentType: responseContentType
|
||||||
completionBlock: ^(NSString *data, NSError *error) {
|
completionBlock: ^(id data, NSError *error) {
|
||||||
if (error) {
|
|
||||||
completionBlock(error);
|
completionBlock(error);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
completionBlock(nil);
|
];
|
||||||
}];
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -14,62 +14,58 @@
|
|||||||
+(SWGStoreApi*) apiWithHeader:(NSString*)headerValue key:(NSString*)key;
|
+(SWGStoreApi*) apiWithHeader:(NSString*)headerValue key:(NSString*)key;
|
||||||
+(void) setBasePath:(NSString*)basePath;
|
+(void) setBasePath:(NSString*)basePath;
|
||||||
+(NSString*) getBasePath;
|
+(NSString*) getBasePath;
|
||||||
/**
|
///
|
||||||
|
///
|
||||||
Returns pet inventories by status
|
/// Returns pet inventories by status
|
||||||
Returns a map of status codes to quantities
|
/// Returns a map of status codes to quantities
|
||||||
|
///
|
||||||
|
///
|
||||||
|
///
|
||||||
return type: NSDictionary*
|
/// @return NSDictionary* /* NSString, NSNumber */
|
||||||
*/
|
|
||||||
-(NSNumber*) getInventoryWithCompletionBlock :
|
-(NSNumber*) getInventoryWithCompletionBlock :
|
||||||
(void (^)(NSDictionary* output, NSError* error))completionBlock;
|
(void (^)(NSDictionary* /* NSString, NSNumber */ output, NSError* error))completionBlock;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
///
|
||||||
|
///
|
||||||
Place an order for a pet
|
/// Place an order for a pet
|
||||||
|
///
|
||||||
|
///
|
||||||
@param body order placed for purchasing the pet
|
/// @param body order placed for purchasing the pet
|
||||||
|
///
|
||||||
|
///
|
||||||
return type: SWGOrder*
|
/// @return SWGOrder*
|
||||||
*/
|
|
||||||
-(NSNumber*) placeOrderWithCompletionBlock :(SWGOrder*) body
|
-(NSNumber*) placeOrderWithCompletionBlock :(SWGOrder*) body
|
||||||
|
|
||||||
completionHandler: (void (^)(SWGOrder* output, NSError* error))completionBlock;
|
completionHandler: (void (^)(SWGOrder* output, NSError* error))completionBlock;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
///
|
||||||
|
///
|
||||||
Find purchase order by ID
|
/// Find purchase order by ID
|
||||||
For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions
|
/// For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions
|
||||||
|
///
|
||||||
@param orderId ID of pet that needs to be fetched
|
/// @param orderId ID of pet that needs to be fetched
|
||||||
|
///
|
||||||
|
///
|
||||||
return type: SWGOrder*
|
/// @return SWGOrder*
|
||||||
*/
|
|
||||||
-(NSNumber*) getOrderByIdWithCompletionBlock :(NSString*) orderId
|
-(NSNumber*) getOrderByIdWithCompletionBlock :(NSString*) orderId
|
||||||
|
|
||||||
completionHandler: (void (^)(SWGOrder* output, NSError* error))completionBlock;
|
completionHandler: (void (^)(SWGOrder* output, NSError* error))completionBlock;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
///
|
||||||
|
///
|
||||||
Delete purchase order by ID
|
/// Delete purchase order by ID
|
||||||
For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors
|
/// For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors
|
||||||
|
///
|
||||||
@param orderId ID of the order that needs to be deleted
|
/// @param orderId ID of the order that needs to be deleted
|
||||||
|
///
|
||||||
|
///
|
||||||
return type:
|
/// @return
|
||||||
*/
|
|
||||||
-(NSNumber*) deleteOrderWithCompletionBlock :(NSString*) orderId
|
-(NSNumber*) deleteOrderWithCompletionBlock :(NSString*) orderId
|
||||||
|
|
||||||
|
|
||||||
|
@ -70,14 +70,15 @@ static NSString * basePath = @"http://petstore.swagger.io/v2";
|
|||||||
return [SWGApiClient requestQueueSize];
|
return [SWGApiClient requestQueueSize];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#pragma mark - Api Methods
|
||||||
|
|
||||||
/*!
|
///
|
||||||
* Returns pet inventories by status
|
/// Returns pet inventories by status
|
||||||
* Returns a map of status codes to quantities
|
/// Returns a map of status codes to quantities
|
||||||
* \returns NSDictionary*
|
/// @returns NSDictionary* /* NSString, NSNumber */
|
||||||
*/
|
///
|
||||||
-(NSNumber*) getInventoryWithCompletionBlock:
|
-(NSNumber*) getInventoryWithCompletionBlock:
|
||||||
(void (^)(NSDictionary* output, NSError* error))completionBlock
|
(void (^)(NSDictionary* /* NSString, NSNumber */ output, NSError* error))completionBlock
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
@ -127,11 +128,7 @@ static NSString * basePath = @"http://petstore.swagger.io/v2";
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return [self.apiClient requestWithCompletionBlock: requestUrl
|
||||||
|
|
||||||
// response is in a container
|
|
||||||
// map container response type
|
|
||||||
return [self.apiClient dictionary: requestUrl
|
|
||||||
method: @"GET"
|
method: @"GET"
|
||||||
queryParams: queryParams
|
queryParams: queryParams
|
||||||
body: bodyDictionary
|
body: bodyDictionary
|
||||||
@ -139,33 +136,20 @@ static NSString * basePath = @"http://petstore.swagger.io/v2";
|
|||||||
authSettings: authSettings
|
authSettings: authSettings
|
||||||
requestContentType: requestContentType
|
requestContentType: requestContentType
|
||||||
responseContentType: responseContentType
|
responseContentType: responseContentType
|
||||||
completionBlock: ^(NSDictionary *data, NSError *error) {
|
completionBlock: ^(id data, NSError *error) {
|
||||||
if (error) {
|
|
||||||
completionBlock(nil, error);
|
completionBlock([self.apiClient deserialize: data class:@"NSDictionary* /* NSString, NSNumber */"], error);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
];
|
||||||
NSDictionary *result = nil;
|
|
||||||
if (data) {
|
|
||||||
result = [[NSDictionary alloc]initWithDictionary: data];
|
|
||||||
}
|
|
||||||
completionBlock(data, nil);
|
|
||||||
|
|
||||||
}];
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
///
|
||||||
* Place an order for a pet
|
/// Place an order for a pet
|
||||||
*
|
///
|
||||||
* \param body order placed for purchasing the pet
|
/// @param body order placed for purchasing the pet
|
||||||
* \returns SWGOrder*
|
///
|
||||||
*/
|
/// @returns SWGOrder*
|
||||||
|
///
|
||||||
-(NSNumber*) placeOrderWithCompletionBlock: (SWGOrder*) body
|
-(NSNumber*) placeOrderWithCompletionBlock: (SWGOrder*) body
|
||||||
|
|
||||||
completionHandler: (void (^)(SWGOrder* output, NSError* error))completionBlock
|
completionHandler: (void (^)(SWGOrder* output, NSError* error))completionBlock
|
||||||
@ -241,19 +225,7 @@ static NSString * basePath = @"http://petstore.swagger.io/v2";
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return [self.apiClient requestWithCompletionBlock: requestUrl
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// non container response
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// complex response
|
|
||||||
|
|
||||||
// comples response type
|
|
||||||
return [self.apiClient dictionary: requestUrl
|
|
||||||
method: @"POST"
|
method: @"POST"
|
||||||
queryParams: queryParams
|
queryParams: queryParams
|
||||||
body: bodyDictionary
|
body: bodyDictionary
|
||||||
@ -261,32 +233,20 @@ static NSString * basePath = @"http://petstore.swagger.io/v2";
|
|||||||
authSettings: authSettings
|
authSettings: authSettings
|
||||||
requestContentType: requestContentType
|
requestContentType: requestContentType
|
||||||
responseContentType: responseContentType
|
responseContentType: responseContentType
|
||||||
completionBlock: ^(NSDictionary *data, NSError *error) {
|
completionBlock: ^(id data, NSError *error) {
|
||||||
if (error) {
|
|
||||||
completionBlock(nil, error);
|
|
||||||
|
|
||||||
return;
|
completionBlock([self.apiClient deserialize: data class:@"SWGOrder*"], error);
|
||||||
}
|
}
|
||||||
SWGOrder* result = nil;
|
];
|
||||||
if (data) {
|
|
||||||
result = [[SWGOrder alloc] initWithDictionary:data error:nil];
|
|
||||||
}
|
|
||||||
completionBlock(result , nil);
|
|
||||||
|
|
||||||
}];
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
///
|
||||||
* Find purchase order by ID
|
/// Find purchase order by ID
|
||||||
* For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions
|
/// For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions
|
||||||
* \param orderId ID of pet that needs to be fetched
|
/// @param orderId ID of pet that needs to be fetched
|
||||||
* \returns SWGOrder*
|
///
|
||||||
*/
|
/// @returns SWGOrder*
|
||||||
|
///
|
||||||
-(NSNumber*) getOrderByIdWithCompletionBlock: (NSString*) orderId
|
-(NSNumber*) getOrderByIdWithCompletionBlock: (NSString*) orderId
|
||||||
|
|
||||||
completionHandler: (void (^)(SWGOrder* output, NSError* error))completionBlock
|
completionHandler: (void (^)(SWGOrder* output, NSError* error))completionBlock
|
||||||
@ -343,19 +303,7 @@ static NSString * basePath = @"http://petstore.swagger.io/v2";
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return [self.apiClient requestWithCompletionBlock: requestUrl
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// non container response
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// complex response
|
|
||||||
|
|
||||||
// comples response type
|
|
||||||
return [self.apiClient dictionary: requestUrl
|
|
||||||
method: @"GET"
|
method: @"GET"
|
||||||
queryParams: queryParams
|
queryParams: queryParams
|
||||||
body: bodyDictionary
|
body: bodyDictionary
|
||||||
@ -363,32 +311,20 @@ static NSString * basePath = @"http://petstore.swagger.io/v2";
|
|||||||
authSettings: authSettings
|
authSettings: authSettings
|
||||||
requestContentType: requestContentType
|
requestContentType: requestContentType
|
||||||
responseContentType: responseContentType
|
responseContentType: responseContentType
|
||||||
completionBlock: ^(NSDictionary *data, NSError *error) {
|
completionBlock: ^(id data, NSError *error) {
|
||||||
if (error) {
|
|
||||||
completionBlock(nil, error);
|
|
||||||
|
|
||||||
return;
|
completionBlock([self.apiClient deserialize: data class:@"SWGOrder*"], error);
|
||||||
}
|
}
|
||||||
SWGOrder* result = nil;
|
];
|
||||||
if (data) {
|
|
||||||
result = [[SWGOrder alloc] initWithDictionary:data error:nil];
|
|
||||||
}
|
|
||||||
completionBlock(result , nil);
|
|
||||||
|
|
||||||
}];
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
///
|
||||||
* Delete purchase order by ID
|
/// Delete purchase order by ID
|
||||||
* For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors
|
/// For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors
|
||||||
* \param orderId ID of the order that needs to be deleted
|
/// @param orderId ID of the order that needs to be deleted
|
||||||
* \returns void
|
///
|
||||||
*/
|
/// @returns void
|
||||||
|
///
|
||||||
-(NSNumber*) deleteOrderWithCompletionBlock: (NSString*) orderId
|
-(NSNumber*) deleteOrderWithCompletionBlock: (NSString*) orderId
|
||||||
|
|
||||||
|
|
||||||
@ -445,14 +381,7 @@ static NSString * basePath = @"http://petstore.swagger.io/v2";
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return [self.apiClient requestWithCompletionBlock: requestUrl
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// it's void
|
|
||||||
return [self.apiClient stringWithCompletionBlock: requestUrl
|
|
||||||
method: @"DELETE"
|
method: @"DELETE"
|
||||||
queryParams: queryParams
|
queryParams: queryParams
|
||||||
body: bodyDictionary
|
body: bodyDictionary
|
||||||
@ -460,15 +389,11 @@ static NSString * basePath = @"http://petstore.swagger.io/v2";
|
|||||||
authSettings: authSettings
|
authSettings: authSettings
|
||||||
requestContentType: requestContentType
|
requestContentType: requestContentType
|
||||||
responseContentType: responseContentType
|
responseContentType: responseContentType
|
||||||
completionBlock: ^(NSString *data, NSError *error) {
|
completionBlock: ^(id data, NSError *error) {
|
||||||
if (error) {
|
|
||||||
completionBlock(error);
|
completionBlock(error);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
completionBlock(nil);
|
];
|
||||||
}];
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -14,65 +14,61 @@
|
|||||||
+(SWGUserApi*) apiWithHeader:(NSString*)headerValue key:(NSString*)key;
|
+(SWGUserApi*) apiWithHeader:(NSString*)headerValue key:(NSString*)key;
|
||||||
+(void) setBasePath:(NSString*)basePath;
|
+(void) setBasePath:(NSString*)basePath;
|
||||||
+(NSString*) getBasePath;
|
+(NSString*) getBasePath;
|
||||||
/**
|
///
|
||||||
|
///
|
||||||
Create user
|
/// Create user
|
||||||
This can only be done by the logged in user.
|
/// This can only be done by the logged in user.
|
||||||
|
///
|
||||||
@param body Created user object
|
/// @param body Created user object
|
||||||
|
///
|
||||||
|
///
|
||||||
return type:
|
/// @return
|
||||||
*/
|
|
||||||
-(NSNumber*) createUserWithCompletionBlock :(SWGUser*) body
|
-(NSNumber*) createUserWithCompletionBlock :(SWGUser*) body
|
||||||
|
|
||||||
|
|
||||||
completionHandler: (void (^)(NSError* error))completionBlock;
|
completionHandler: (void (^)(NSError* error))completionBlock;
|
||||||
|
|
||||||
|
|
||||||
/**
|
///
|
||||||
|
///
|
||||||
Creates list of users with given input array
|
/// Creates list of users with given input array
|
||||||
|
///
|
||||||
|
///
|
||||||
@param body List of user object
|
/// @param body List of user object
|
||||||
|
///
|
||||||
|
///
|
||||||
return type:
|
/// @return
|
||||||
*/
|
|
||||||
-(NSNumber*) createUsersWithArrayInputWithCompletionBlock :(NSArray<SWGUser>*) body
|
-(NSNumber*) createUsersWithArrayInputWithCompletionBlock :(NSArray<SWGUser>*) body
|
||||||
|
|
||||||
|
|
||||||
completionHandler: (void (^)(NSError* error))completionBlock;
|
completionHandler: (void (^)(NSError* error))completionBlock;
|
||||||
|
|
||||||
|
|
||||||
/**
|
///
|
||||||
|
///
|
||||||
Creates list of users with given input array
|
/// Creates list of users with given input array
|
||||||
|
///
|
||||||
|
///
|
||||||
@param body List of user object
|
/// @param body List of user object
|
||||||
|
///
|
||||||
|
///
|
||||||
return type:
|
/// @return
|
||||||
*/
|
|
||||||
-(NSNumber*) createUsersWithListInputWithCompletionBlock :(NSArray<SWGUser>*) body
|
-(NSNumber*) createUsersWithListInputWithCompletionBlock :(NSArray<SWGUser>*) body
|
||||||
|
|
||||||
|
|
||||||
completionHandler: (void (^)(NSError* error))completionBlock;
|
completionHandler: (void (^)(NSError* error))completionBlock;
|
||||||
|
|
||||||
|
|
||||||
/**
|
///
|
||||||
|
///
|
||||||
Logs user into the system
|
/// Logs user into the system
|
||||||
|
///
|
||||||
|
///
|
||||||
@param username The user name for login
|
/// @param username The user name for login
|
||||||
@param password The password for login in clear text
|
/// @param password The password for login in clear text
|
||||||
|
///
|
||||||
|
///
|
||||||
return type: NSString*
|
/// @return NSString*
|
||||||
*/
|
|
||||||
-(NSNumber*) loginUserWithCompletionBlock :(NSString*) username
|
-(NSNumber*) loginUserWithCompletionBlock :(NSString*) username
|
||||||
password:(NSString*) password
|
password:(NSString*) password
|
||||||
|
|
||||||
@ -80,47 +76,44 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
///
|
||||||
|
///
|
||||||
Logs out current logged in user session
|
/// Logs out current logged in user session
|
||||||
|
///
|
||||||
|
///
|
||||||
|
///
|
||||||
|
///
|
||||||
return type:
|
/// @return
|
||||||
*/
|
|
||||||
-(NSNumber*) logoutUserWithCompletionBlock :
|
-(NSNumber*) logoutUserWithCompletionBlock :
|
||||||
|
|
||||||
(void (^)(NSError* error))completionBlock;
|
(void (^)(NSError* error))completionBlock;
|
||||||
|
|
||||||
|
|
||||||
/**
|
///
|
||||||
|
///
|
||||||
Get user by user name
|
/// Get user by user name
|
||||||
|
///
|
||||||
|
///
|
||||||
@param username The name that needs to be fetched. Use user1 for testing.
|
/// @param username The name that needs to be fetched. Use user1 for testing.
|
||||||
|
///
|
||||||
|
///
|
||||||
return type: SWGUser*
|
/// @return SWGUser*
|
||||||
*/
|
|
||||||
-(NSNumber*) getUserByNameWithCompletionBlock :(NSString*) username
|
-(NSNumber*) getUserByNameWithCompletionBlock :(NSString*) username
|
||||||
|
|
||||||
completionHandler: (void (^)(SWGUser* output, NSError* error))completionBlock;
|
completionHandler: (void (^)(SWGUser* output, NSError* error))completionBlock;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
///
|
||||||
|
///
|
||||||
Updated user
|
/// Updated user
|
||||||
This can only be done by the logged in user.
|
/// This can only be done by the logged in user.
|
||||||
|
///
|
||||||
@param username name that need to be deleted
|
/// @param username name that need to be deleted
|
||||||
@param body Updated user object
|
/// @param body Updated user object
|
||||||
|
///
|
||||||
|
///
|
||||||
return type:
|
/// @return
|
||||||
*/
|
|
||||||
-(NSNumber*) updateUserWithCompletionBlock :(NSString*) username
|
-(NSNumber*) updateUserWithCompletionBlock :(NSString*) username
|
||||||
body:(SWGUser*) body
|
body:(SWGUser*) body
|
||||||
|
|
||||||
@ -128,16 +121,15 @@
|
|||||||
completionHandler: (void (^)(NSError* error))completionBlock;
|
completionHandler: (void (^)(NSError* error))completionBlock;
|
||||||
|
|
||||||
|
|
||||||
/**
|
///
|
||||||
|
///
|
||||||
Delete user
|
/// Delete user
|
||||||
This can only be done by the logged in user.
|
/// This can only be done by the logged in user.
|
||||||
|
///
|
||||||
@param username The name that needs to be deleted
|
/// @param username The name that needs to be deleted
|
||||||
|
///
|
||||||
|
///
|
||||||
return type:
|
/// @return
|
||||||
*/
|
|
||||||
-(NSNumber*) deleteUserWithCompletionBlock :(NSString*) username
|
-(NSNumber*) deleteUserWithCompletionBlock :(NSString*) username
|
||||||
|
|
||||||
|
|
||||||
|
@ -70,13 +70,15 @@ static NSString * basePath = @"http://petstore.swagger.io/v2";
|
|||||||
return [SWGApiClient requestQueueSize];
|
return [SWGApiClient requestQueueSize];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#pragma mark - Api Methods
|
||||||
|
|
||||||
/*!
|
///
|
||||||
* Create user
|
/// Create user
|
||||||
* This can only be done by the logged in user.
|
/// This can only be done by the logged in user.
|
||||||
* \param body Created user object
|
/// @param body Created user object
|
||||||
* \returns void
|
///
|
||||||
*/
|
/// @returns void
|
||||||
|
///
|
||||||
-(NSNumber*) createUserWithCompletionBlock: (SWGUser*) body
|
-(NSNumber*) createUserWithCompletionBlock: (SWGUser*) body
|
||||||
|
|
||||||
|
|
||||||
@ -152,14 +154,7 @@ static NSString * basePath = @"http://petstore.swagger.io/v2";
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return [self.apiClient requestWithCompletionBlock: requestUrl
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// it's void
|
|
||||||
return [self.apiClient stringWithCompletionBlock: requestUrl
|
|
||||||
method: @"POST"
|
method: @"POST"
|
||||||
queryParams: queryParams
|
queryParams: queryParams
|
||||||
body: bodyDictionary
|
body: bodyDictionary
|
||||||
@ -167,23 +162,20 @@ static NSString * basePath = @"http://petstore.swagger.io/v2";
|
|||||||
authSettings: authSettings
|
authSettings: authSettings
|
||||||
requestContentType: requestContentType
|
requestContentType: requestContentType
|
||||||
responseContentType: responseContentType
|
responseContentType: responseContentType
|
||||||
completionBlock: ^(NSString *data, NSError *error) {
|
completionBlock: ^(id data, NSError *error) {
|
||||||
if (error) {
|
|
||||||
completionBlock(error);
|
completionBlock(error);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
completionBlock(nil);
|
];
|
||||||
}];
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
///
|
||||||
* Creates list of users with given input array
|
/// Creates list of users with given input array
|
||||||
*
|
///
|
||||||
* \param body List of user object
|
/// @param body List of user object
|
||||||
* \returns void
|
///
|
||||||
*/
|
/// @returns void
|
||||||
|
///
|
||||||
-(NSNumber*) createUsersWithArrayInputWithCompletionBlock: (NSArray<SWGUser>*) body
|
-(NSNumber*) createUsersWithArrayInputWithCompletionBlock: (NSArray<SWGUser>*) body
|
||||||
|
|
||||||
|
|
||||||
@ -259,14 +251,7 @@ static NSString * basePath = @"http://petstore.swagger.io/v2";
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return [self.apiClient requestWithCompletionBlock: requestUrl
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// it's void
|
|
||||||
return [self.apiClient stringWithCompletionBlock: requestUrl
|
|
||||||
method: @"POST"
|
method: @"POST"
|
||||||
queryParams: queryParams
|
queryParams: queryParams
|
||||||
body: bodyDictionary
|
body: bodyDictionary
|
||||||
@ -274,23 +259,20 @@ static NSString * basePath = @"http://petstore.swagger.io/v2";
|
|||||||
authSettings: authSettings
|
authSettings: authSettings
|
||||||
requestContentType: requestContentType
|
requestContentType: requestContentType
|
||||||
responseContentType: responseContentType
|
responseContentType: responseContentType
|
||||||
completionBlock: ^(NSString *data, NSError *error) {
|
completionBlock: ^(id data, NSError *error) {
|
||||||
if (error) {
|
|
||||||
completionBlock(error);
|
completionBlock(error);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
completionBlock(nil);
|
];
|
||||||
}];
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
///
|
||||||
* Creates list of users with given input array
|
/// Creates list of users with given input array
|
||||||
*
|
///
|
||||||
* \param body List of user object
|
/// @param body List of user object
|
||||||
* \returns void
|
///
|
||||||
*/
|
/// @returns void
|
||||||
|
///
|
||||||
-(NSNumber*) createUsersWithListInputWithCompletionBlock: (NSArray<SWGUser>*) body
|
-(NSNumber*) createUsersWithListInputWithCompletionBlock: (NSArray<SWGUser>*) body
|
||||||
|
|
||||||
|
|
||||||
@ -366,14 +348,7 @@ static NSString * basePath = @"http://petstore.swagger.io/v2";
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return [self.apiClient requestWithCompletionBlock: requestUrl
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// it's void
|
|
||||||
return [self.apiClient stringWithCompletionBlock: requestUrl
|
|
||||||
method: @"POST"
|
method: @"POST"
|
||||||
queryParams: queryParams
|
queryParams: queryParams
|
||||||
body: bodyDictionary
|
body: bodyDictionary
|
||||||
@ -381,24 +356,22 @@ static NSString * basePath = @"http://petstore.swagger.io/v2";
|
|||||||
authSettings: authSettings
|
authSettings: authSettings
|
||||||
requestContentType: requestContentType
|
requestContentType: requestContentType
|
||||||
responseContentType: responseContentType
|
responseContentType: responseContentType
|
||||||
completionBlock: ^(NSString *data, NSError *error) {
|
completionBlock: ^(id data, NSError *error) {
|
||||||
if (error) {
|
|
||||||
completionBlock(error);
|
completionBlock(error);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
completionBlock(nil);
|
];
|
||||||
}];
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
///
|
||||||
* Logs user into the system
|
/// Logs user into the system
|
||||||
*
|
///
|
||||||
* \param username The user name for login
|
/// @param username The user name for login
|
||||||
* \param password The password for login in clear text
|
///
|
||||||
* \returns NSString*
|
/// @param password The password for login in clear text
|
||||||
*/
|
///
|
||||||
|
/// @returns NSString*
|
||||||
|
///
|
||||||
-(NSNumber*) loginUserWithCompletionBlock: (NSString*) username
|
-(NSNumber*) loginUserWithCompletionBlock: (NSString*) username
|
||||||
password: (NSString*) password
|
password: (NSString*) password
|
||||||
|
|
||||||
@ -460,16 +433,7 @@ static NSString * basePath = @"http://petstore.swagger.io/v2";
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return [self.apiClient requestWithCompletionBlock: requestUrl
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// non container response
|
|
||||||
|
|
||||||
|
|
||||||
// primitive response
|
|
||||||
// primitive response type
|
|
||||||
return [self.apiClient stringWithCompletionBlock: requestUrl
|
|
||||||
method: @"GET"
|
method: @"GET"
|
||||||
queryParams: queryParams
|
queryParams: queryParams
|
||||||
body: bodyDictionary
|
body: bodyDictionary
|
||||||
@ -477,33 +441,18 @@ static NSString * basePath = @"http://petstore.swagger.io/v2";
|
|||||||
authSettings: authSettings
|
authSettings: authSettings
|
||||||
requestContentType: requestContentType
|
requestContentType: requestContentType
|
||||||
responseContentType: responseContentType
|
responseContentType: responseContentType
|
||||||
completionBlock: ^(NSString *data, NSError *error) {
|
completionBlock: ^(id data, NSError *error) {
|
||||||
if (error) {
|
|
||||||
completionBlock(nil, error);
|
completionBlock([self.apiClient deserialize: data class:@"NSString*"], error);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
NSString *result = data ? [[NSString alloc]initWithString: data] : nil;
|
];
|
||||||
completionBlock(result, nil);
|
|
||||||
}];
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// complex response
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
///
|
||||||
* Logs out current logged in user session
|
/// Logs out current logged in user session
|
||||||
*
|
///
|
||||||
* \returns void
|
/// @returns void
|
||||||
*/
|
///
|
||||||
-(NSNumber*) logoutUserWithCompletionBlock:
|
-(NSNumber*) logoutUserWithCompletionBlock:
|
||||||
|
|
||||||
(void (^)(NSError* error))completionBlock {
|
(void (^)(NSError* error))completionBlock {
|
||||||
@ -555,14 +504,7 @@ static NSString * basePath = @"http://petstore.swagger.io/v2";
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return [self.apiClient requestWithCompletionBlock: requestUrl
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// it's void
|
|
||||||
return [self.apiClient stringWithCompletionBlock: requestUrl
|
|
||||||
method: @"GET"
|
method: @"GET"
|
||||||
queryParams: queryParams
|
queryParams: queryParams
|
||||||
body: bodyDictionary
|
body: bodyDictionary
|
||||||
@ -570,23 +512,20 @@ static NSString * basePath = @"http://petstore.swagger.io/v2";
|
|||||||
authSettings: authSettings
|
authSettings: authSettings
|
||||||
requestContentType: requestContentType
|
requestContentType: requestContentType
|
||||||
responseContentType: responseContentType
|
responseContentType: responseContentType
|
||||||
completionBlock: ^(NSString *data, NSError *error) {
|
completionBlock: ^(id data, NSError *error) {
|
||||||
if (error) {
|
|
||||||
completionBlock(error);
|
completionBlock(error);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
completionBlock(nil);
|
];
|
||||||
}];
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
///
|
||||||
* Get user by user name
|
/// Get user by user name
|
||||||
*
|
///
|
||||||
* \param username The name that needs to be fetched. Use user1 for testing.
|
/// @param username The name that needs to be fetched. Use user1 for testing.
|
||||||
* \returns SWGUser*
|
///
|
||||||
*/
|
/// @returns SWGUser*
|
||||||
|
///
|
||||||
-(NSNumber*) getUserByNameWithCompletionBlock: (NSString*) username
|
-(NSNumber*) getUserByNameWithCompletionBlock: (NSString*) username
|
||||||
|
|
||||||
completionHandler: (void (^)(SWGUser* output, NSError* error))completionBlock
|
completionHandler: (void (^)(SWGUser* output, NSError* error))completionBlock
|
||||||
@ -643,19 +582,7 @@ static NSString * basePath = @"http://petstore.swagger.io/v2";
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return [self.apiClient requestWithCompletionBlock: requestUrl
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// non container response
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// complex response
|
|
||||||
|
|
||||||
// comples response type
|
|
||||||
return [self.apiClient dictionary: requestUrl
|
|
||||||
method: @"GET"
|
method: @"GET"
|
||||||
queryParams: queryParams
|
queryParams: queryParams
|
||||||
body: bodyDictionary
|
body: bodyDictionary
|
||||||
@ -663,33 +590,22 @@ static NSString * basePath = @"http://petstore.swagger.io/v2";
|
|||||||
authSettings: authSettings
|
authSettings: authSettings
|
||||||
requestContentType: requestContentType
|
requestContentType: requestContentType
|
||||||
responseContentType: responseContentType
|
responseContentType: responseContentType
|
||||||
completionBlock: ^(NSDictionary *data, NSError *error) {
|
completionBlock: ^(id data, NSError *error) {
|
||||||
if (error) {
|
|
||||||
completionBlock(nil, error);
|
|
||||||
|
|
||||||
return;
|
completionBlock([self.apiClient deserialize: data class:@"SWGUser*"], error);
|
||||||
}
|
}
|
||||||
SWGUser* result = nil;
|
];
|
||||||
if (data) {
|
|
||||||
result = [[SWGUser alloc] initWithDictionary:data error:nil];
|
|
||||||
}
|
|
||||||
completionBlock(result , nil);
|
|
||||||
|
|
||||||
}];
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
///
|
||||||
* Updated user
|
/// Updated user
|
||||||
* This can only be done by the logged in user.
|
/// This can only be done by the logged in user.
|
||||||
* \param username name that need to be deleted
|
/// @param username name that need to be deleted
|
||||||
* \param body Updated user object
|
///
|
||||||
* \returns void
|
/// @param body Updated user object
|
||||||
*/
|
///
|
||||||
|
/// @returns void
|
||||||
|
///
|
||||||
-(NSNumber*) updateUserWithCompletionBlock: (NSString*) username
|
-(NSNumber*) updateUserWithCompletionBlock: (NSString*) username
|
||||||
body: (SWGUser*) body
|
body: (SWGUser*) body
|
||||||
|
|
||||||
@ -770,14 +686,7 @@ static NSString * basePath = @"http://petstore.swagger.io/v2";
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return [self.apiClient requestWithCompletionBlock: requestUrl
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// it's void
|
|
||||||
return [self.apiClient stringWithCompletionBlock: requestUrl
|
|
||||||
method: @"PUT"
|
method: @"PUT"
|
||||||
queryParams: queryParams
|
queryParams: queryParams
|
||||||
body: bodyDictionary
|
body: bodyDictionary
|
||||||
@ -785,23 +694,20 @@ static NSString * basePath = @"http://petstore.swagger.io/v2";
|
|||||||
authSettings: authSettings
|
authSettings: authSettings
|
||||||
requestContentType: requestContentType
|
requestContentType: requestContentType
|
||||||
responseContentType: responseContentType
|
responseContentType: responseContentType
|
||||||
completionBlock: ^(NSString *data, NSError *error) {
|
completionBlock: ^(id data, NSError *error) {
|
||||||
if (error) {
|
|
||||||
completionBlock(error);
|
completionBlock(error);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
completionBlock(nil);
|
];
|
||||||
}];
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
///
|
||||||
* Delete user
|
/// Delete user
|
||||||
* This can only be done by the logged in user.
|
/// This can only be done by the logged in user.
|
||||||
* \param username The name that needs to be deleted
|
/// @param username The name that needs to be deleted
|
||||||
* \returns void
|
///
|
||||||
*/
|
/// @returns void
|
||||||
|
///
|
||||||
-(NSNumber*) deleteUserWithCompletionBlock: (NSString*) username
|
-(NSNumber*) deleteUserWithCompletionBlock: (NSString*) username
|
||||||
|
|
||||||
|
|
||||||
@ -858,14 +764,7 @@ static NSString * basePath = @"http://petstore.swagger.io/v2";
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return [self.apiClient requestWithCompletionBlock: requestUrl
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// it's void
|
|
||||||
return [self.apiClient stringWithCompletionBlock: requestUrl
|
|
||||||
method: @"DELETE"
|
method: @"DELETE"
|
||||||
queryParams: queryParams
|
queryParams: queryParams
|
||||||
body: bodyDictionary
|
body: bodyDictionary
|
||||||
@ -873,15 +772,11 @@ static NSString * basePath = @"http://petstore.swagger.io/v2";
|
|||||||
authSettings: authSettings
|
authSettings: authSettings
|
||||||
requestContentType: requestContentType
|
requestContentType: requestContentType
|
||||||
responseContentType: responseContentType
|
responseContentType: responseContentType
|
||||||
completionBlock: ^(NSString *data, NSError *error) {
|
completionBlock: ^(id data, NSError *error) {
|
||||||
if (error) {
|
|
||||||
completionBlock(error);
|
completionBlock(error);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
completionBlock(nil);
|
];
|
||||||
}];
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -7,6 +7,8 @@ use utf8;
|
|||||||
use Log::Any qw($log);
|
use Log::Any qw($log);
|
||||||
use Carp;
|
use Carp;
|
||||||
|
|
||||||
|
use constant VERSION => '1.0.0';
|
||||||
|
|
||||||
# class/static variables
|
# class/static variables
|
||||||
our $api_client;
|
our $api_client;
|
||||||
our $http_timeout = 180;
|
our $http_timeout = 180;
|
||||||
|
@ -30,18 +30,6 @@ use Log::Any qw($log);
|
|||||||
use WWW::SwaggerClient::ApiClient;
|
use WWW::SwaggerClient::ApiClient;
|
||||||
use WWW::SwaggerClient::Configuration;
|
use WWW::SwaggerClient::Configuration;
|
||||||
|
|
||||||
our @EXPORT_OK = qw(
|
|
||||||
update_pet
|
|
||||||
add_pet
|
|
||||||
find_pets_by_status
|
|
||||||
find_pets_by_tags
|
|
||||||
get_pet_by_id
|
|
||||||
update_pet_with_form
|
|
||||||
delete_pet
|
|
||||||
upload_file
|
|
||||||
|
|
||||||
);
|
|
||||||
|
|
||||||
sub new {
|
sub new {
|
||||||
my $class = shift;
|
my $class = shift;
|
||||||
my $default_api_client = $WWW::SwaggerClient::Configuration::api_client ? $WWW::SwaggerClient::Configuration::api_client : WWW::SwaggerClient::ApiClient->new;
|
my $default_api_client = $WWW::SwaggerClient::Configuration::api_client ? $WWW::SwaggerClient::Configuration::api_client : WWW::SwaggerClient::ApiClient->new;
|
||||||
@ -59,16 +47,15 @@ sub new {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#
|
||||||
#
|
# update_pet
|
||||||
# update_pet
|
#
|
||||||
#
|
# Update an existing pet
|
||||||
# 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 (required)
|
# @return void
|
||||||
# @return void
|
#
|
||||||
#
|
sub update_pet {
|
||||||
sub update_pet {
|
|
||||||
my ($self, %args) = @_;
|
my ($self, %args) = @_;
|
||||||
|
|
||||||
|
|
||||||
@ -109,17 +96,16 @@ sub new {
|
|||||||
$header_params, $_body_data, $auth_settings);
|
$header_params, $_body_data, $auth_settings);
|
||||||
return;
|
return;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
#
|
||||||
#
|
# add_pet
|
||||||
# add_pet
|
#
|
||||||
#
|
# Add a new pet to the store
|
||||||
# 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 (required)
|
# @return void
|
||||||
# @return void
|
#
|
||||||
#
|
sub add_pet {
|
||||||
sub add_pet {
|
|
||||||
my ($self, %args) = @_;
|
my ($self, %args) = @_;
|
||||||
|
|
||||||
|
|
||||||
@ -160,17 +146,16 @@ sub new {
|
|||||||
$header_params, $_body_data, $auth_settings);
|
$header_params, $_body_data, $auth_settings);
|
||||||
return;
|
return;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
#
|
||||||
#
|
# find_pets_by_status
|
||||||
# find_pets_by_status
|
#
|
||||||
#
|
# Finds Pets by status
|
||||||
# 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 (required)
|
# @return ARRAY[Pet]
|
||||||
# @return ARRAY[Pet]
|
#
|
||||||
#
|
sub find_pets_by_status {
|
||||||
sub find_pets_by_status {
|
|
||||||
my ($self, %args) = @_;
|
my ($self, %args) = @_;
|
||||||
|
|
||||||
|
|
||||||
@ -214,17 +199,16 @@ sub new {
|
|||||||
my $_response_object = $self->{api_client}->deserialize('ARRAY[Pet]', $response);
|
my $_response_object = $self->{api_client}->deserialize('ARRAY[Pet]', $response);
|
||||||
return $_response_object;
|
return $_response_object;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
#
|
||||||
#
|
# find_pets_by_tags
|
||||||
# find_pets_by_tags
|
#
|
||||||
#
|
# Finds Pets by tags
|
||||||
# Finds Pets by tags
|
#
|
||||||
#
|
# @param ARRAY[string] $tags Tags to filter by (required)
|
||||||
# @param ARRAY[string] $tags Tags to filter by (required)
|
# @return ARRAY[Pet]
|
||||||
# @return ARRAY[Pet]
|
#
|
||||||
#
|
sub find_pets_by_tags {
|
||||||
sub find_pets_by_tags {
|
|
||||||
my ($self, %args) = @_;
|
my ($self, %args) = @_;
|
||||||
|
|
||||||
|
|
||||||
@ -268,17 +252,16 @@ sub new {
|
|||||||
my $_response_object = $self->{api_client}->deserialize('ARRAY[Pet]', $response);
|
my $_response_object = $self->{api_client}->deserialize('ARRAY[Pet]', $response);
|
||||||
return $_response_object;
|
return $_response_object;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
#
|
||||||
#
|
# get_pet_by_id
|
||||||
# get_pet_by_id
|
#
|
||||||
#
|
# Find pet by ID
|
||||||
# Find pet by ID
|
#
|
||||||
#
|
# @param int $pet_id ID of pet that needs to be fetched (required)
|
||||||
# @param int $pet_id ID of pet that needs to be fetched (required)
|
# @return Pet
|
||||||
# @return Pet
|
#
|
||||||
#
|
sub get_pet_by_id {
|
||||||
sub get_pet_by_id {
|
|
||||||
my ($self, %args) = @_;
|
my ($self, %args) = @_;
|
||||||
|
|
||||||
|
|
||||||
@ -329,19 +312,18 @@ sub new {
|
|||||||
my $_response_object = $self->{api_client}->deserialize('Pet', $response);
|
my $_response_object = $self->{api_client}->deserialize('Pet', $response);
|
||||||
return $_response_object;
|
return $_response_object;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
#
|
||||||
#
|
# update_pet_with_form
|
||||||
# update_pet_with_form
|
#
|
||||||
#
|
# Updates a pet in the store with form data
|
||||||
# Updates a pet in the store with form data
|
#
|
||||||
#
|
# @param string $pet_id ID of pet that needs to be updated (required)
|
||||||
# @param string $pet_id ID of pet that needs to be updated (required)
|
# @param string $name Updated name of the pet (required)
|
||||||
# @param string $name Updated name of the pet (required)
|
# @param string $status Updated status of the pet (required)
|
||||||
# @param string $status Updated status of the pet (required)
|
# @return void
|
||||||
# @return void
|
#
|
||||||
#
|
sub update_pet_with_form {
|
||||||
sub update_pet_with_form {
|
|
||||||
my ($self, %args) = @_;
|
my ($self, %args) = @_;
|
||||||
|
|
||||||
|
|
||||||
@ -399,18 +381,17 @@ sub new {
|
|||||||
$header_params, $_body_data, $auth_settings);
|
$header_params, $_body_data, $auth_settings);
|
||||||
return;
|
return;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
#
|
||||||
#
|
# delete_pet
|
||||||
# delete_pet
|
#
|
||||||
#
|
# Deletes a pet
|
||||||
# Deletes a pet
|
#
|
||||||
#
|
# @param string $api_key (required)
|
||||||
# @param string $api_key (required)
|
# @param int $pet_id Pet id to delete (required)
|
||||||
# @param int $pet_id Pet id to delete (required)
|
# @return void
|
||||||
# @return void
|
#
|
||||||
#
|
sub delete_pet {
|
||||||
sub delete_pet {
|
|
||||||
my ($self, %args) = @_;
|
my ($self, %args) = @_;
|
||||||
|
|
||||||
|
|
||||||
@ -461,19 +442,18 @@ sub new {
|
|||||||
$header_params, $_body_data, $auth_settings);
|
$header_params, $_body_data, $auth_settings);
|
||||||
return;
|
return;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
#
|
||||||
#
|
# upload_file
|
||||||
# upload_file
|
#
|
||||||
#
|
# uploads an image
|
||||||
# uploads an image
|
#
|
||||||
#
|
# @param int $pet_id ID of pet to update (required)
|
||||||
# @param int $pet_id ID of pet to update (required)
|
# @param string $additional_metadata Additional data to pass to server (required)
|
||||||
# @param string $additional_metadata Additional data to pass to server (required)
|
# @param file $file file to upload (required)
|
||||||
# @param file $file file to upload (required)
|
# @return void
|
||||||
# @return void
|
#
|
||||||
#
|
sub upload_file {
|
||||||
sub upload_file {
|
|
||||||
my ($self, %args) = @_;
|
my ($self, %args) = @_;
|
||||||
|
|
||||||
|
|
||||||
@ -532,8 +512,7 @@ sub new {
|
|||||||
$header_params, $_body_data, $auth_settings);
|
$header_params, $_body_data, $auth_settings);
|
||||||
return;
|
return;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
@ -30,14 +30,6 @@ use Log::Any qw($log);
|
|||||||
use WWW::SwaggerClient::ApiClient;
|
use WWW::SwaggerClient::ApiClient;
|
||||||
use WWW::SwaggerClient::Configuration;
|
use WWW::SwaggerClient::Configuration;
|
||||||
|
|
||||||
our @EXPORT_OK = qw(
|
|
||||||
get_inventory
|
|
||||||
place_order
|
|
||||||
get_order_by_id
|
|
||||||
delete_order
|
|
||||||
|
|
||||||
);
|
|
||||||
|
|
||||||
sub new {
|
sub new {
|
||||||
my $class = shift;
|
my $class = shift;
|
||||||
my $default_api_client = $WWW::SwaggerClient::Configuration::api_client ? $WWW::SwaggerClient::Configuration::api_client : WWW::SwaggerClient::ApiClient->new;
|
my $default_api_client = $WWW::SwaggerClient::Configuration::api_client ? $WWW::SwaggerClient::Configuration::api_client : WWW::SwaggerClient::ApiClient->new;
|
||||||
@ -55,15 +47,14 @@ sub new {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#
|
||||||
#
|
# get_inventory
|
||||||
# get_inventory
|
#
|
||||||
#
|
# Returns pet inventories by status
|
||||||
# Returns pet inventories by status
|
#
|
||||||
#
|
# @return HASH[string,int]
|
||||||
# @return HASH[string,int]
|
#
|
||||||
#
|
sub get_inventory {
|
||||||
sub get_inventory {
|
|
||||||
my ($self, %args) = @_;
|
my ($self, %args) = @_;
|
||||||
|
|
||||||
|
|
||||||
@ -104,17 +95,16 @@ sub new {
|
|||||||
my $_response_object = $self->{api_client}->deserialize('HASH[string,int]', $response);
|
my $_response_object = $self->{api_client}->deserialize('HASH[string,int]', $response);
|
||||||
return $_response_object;
|
return $_response_object;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
#
|
||||||
#
|
# place_order
|
||||||
# place_order
|
#
|
||||||
#
|
# Place an order for a pet
|
||||||
# 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 (required)
|
# @return Order
|
||||||
# @return Order
|
#
|
||||||
#
|
sub place_order {
|
||||||
sub place_order {
|
|
||||||
my ($self, %args) = @_;
|
my ($self, %args) = @_;
|
||||||
|
|
||||||
|
|
||||||
@ -158,17 +148,16 @@ sub new {
|
|||||||
my $_response_object = $self->{api_client}->deserialize('Order', $response);
|
my $_response_object = $self->{api_client}->deserialize('Order', $response);
|
||||||
return $_response_object;
|
return $_response_object;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
#
|
||||||
#
|
# get_order_by_id
|
||||||
# get_order_by_id
|
#
|
||||||
#
|
# Find purchase order by ID
|
||||||
# Find purchase order by ID
|
#
|
||||||
#
|
# @param string $order_id ID of pet that needs to be fetched (required)
|
||||||
# @param string $order_id ID of pet that needs to be fetched (required)
|
# @return Order
|
||||||
# @return Order
|
#
|
||||||
#
|
sub get_order_by_id {
|
||||||
sub get_order_by_id {
|
|
||||||
my ($self, %args) = @_;
|
my ($self, %args) = @_;
|
||||||
|
|
||||||
|
|
||||||
@ -219,17 +208,16 @@ sub new {
|
|||||||
my $_response_object = $self->{api_client}->deserialize('Order', $response);
|
my $_response_object = $self->{api_client}->deserialize('Order', $response);
|
||||||
return $_response_object;
|
return $_response_object;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
#
|
||||||
#
|
# delete_order
|
||||||
# delete_order
|
#
|
||||||
#
|
# Delete purchase order by ID
|
||||||
# Delete purchase order by ID
|
#
|
||||||
#
|
# @param string $order_id ID of the order that needs to be deleted (required)
|
||||||
# @param string $order_id ID of the order that needs to be deleted (required)
|
# @return void
|
||||||
# @return void
|
#
|
||||||
#
|
sub delete_order {
|
||||||
sub delete_order {
|
|
||||||
my ($self, %args) = @_;
|
my ($self, %args) = @_;
|
||||||
|
|
||||||
|
|
||||||
@ -277,8 +265,7 @@ sub new {
|
|||||||
$header_params, $_body_data, $auth_settings);
|
$header_params, $_body_data, $auth_settings);
|
||||||
return;
|
return;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
@ -30,18 +30,6 @@ use Log::Any qw($log);
|
|||||||
use WWW::SwaggerClient::ApiClient;
|
use WWW::SwaggerClient::ApiClient;
|
||||||
use WWW::SwaggerClient::Configuration;
|
use WWW::SwaggerClient::Configuration;
|
||||||
|
|
||||||
our @EXPORT_OK = qw(
|
|
||||||
create_user
|
|
||||||
create_users_with_array_input
|
|
||||||
create_users_with_list_input
|
|
||||||
login_user
|
|
||||||
logout_user
|
|
||||||
get_user_by_name
|
|
||||||
update_user
|
|
||||||
delete_user
|
|
||||||
|
|
||||||
);
|
|
||||||
|
|
||||||
sub new {
|
sub new {
|
||||||
my $class = shift;
|
my $class = shift;
|
||||||
my $default_api_client = $WWW::SwaggerClient::Configuration::api_client ? $WWW::SwaggerClient::Configuration::api_client : WWW::SwaggerClient::ApiClient->new;
|
my $default_api_client = $WWW::SwaggerClient::Configuration::api_client ? $WWW::SwaggerClient::Configuration::api_client : WWW::SwaggerClient::ApiClient->new;
|
||||||
@ -59,16 +47,15 @@ sub new {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#
|
||||||
#
|
# create_user
|
||||||
# create_user
|
#
|
||||||
#
|
# Create user
|
||||||
# Create user
|
#
|
||||||
#
|
# @param User $body Created user object (required)
|
||||||
# @param User $body Created user object (required)
|
# @return void
|
||||||
# @return void
|
#
|
||||||
#
|
sub create_user {
|
||||||
sub create_user {
|
|
||||||
my ($self, %args) = @_;
|
my ($self, %args) = @_;
|
||||||
|
|
||||||
|
|
||||||
@ -109,17 +96,16 @@ sub new {
|
|||||||
$header_params, $_body_data, $auth_settings);
|
$header_params, $_body_data, $auth_settings);
|
||||||
return;
|
return;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
#
|
||||||
#
|
# create_users_with_array_input
|
||||||
# create_users_with_array_input
|
#
|
||||||
#
|
# Creates list of users with given input array
|
||||||
# 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 (required)
|
# @return void
|
||||||
# @return void
|
#
|
||||||
#
|
sub create_users_with_array_input {
|
||||||
sub create_users_with_array_input {
|
|
||||||
my ($self, %args) = @_;
|
my ($self, %args) = @_;
|
||||||
|
|
||||||
|
|
||||||
@ -160,17 +146,16 @@ sub new {
|
|||||||
$header_params, $_body_data, $auth_settings);
|
$header_params, $_body_data, $auth_settings);
|
||||||
return;
|
return;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
#
|
||||||
#
|
# create_users_with_list_input
|
||||||
# create_users_with_list_input
|
#
|
||||||
#
|
# Creates list of users with given input array
|
||||||
# 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 (required)
|
# @return void
|
||||||
# @return void
|
#
|
||||||
#
|
sub create_users_with_list_input {
|
||||||
sub create_users_with_list_input {
|
|
||||||
my ($self, %args) = @_;
|
my ($self, %args) = @_;
|
||||||
|
|
||||||
|
|
||||||
@ -211,18 +196,17 @@ sub new {
|
|||||||
$header_params, $_body_data, $auth_settings);
|
$header_params, $_body_data, $auth_settings);
|
||||||
return;
|
return;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
#
|
||||||
#
|
# login_user
|
||||||
# login_user
|
#
|
||||||
#
|
# Logs user into the system
|
||||||
# Logs user into the system
|
#
|
||||||
#
|
# @param string $username The user name for login (required)
|
||||||
# @param string $username The user name for login (required)
|
# @param string $password The password for login in clear text (required)
|
||||||
# @param string $password The password for login in clear text (required)
|
# @return string
|
||||||
# @return string
|
#
|
||||||
#
|
sub login_user {
|
||||||
sub login_user {
|
|
||||||
my ($self, %args) = @_;
|
my ($self, %args) = @_;
|
||||||
|
|
||||||
|
|
||||||
@ -269,16 +253,15 @@ sub new {
|
|||||||
my $_response_object = $self->{api_client}->deserialize('string', $response);
|
my $_response_object = $self->{api_client}->deserialize('string', $response);
|
||||||
return $_response_object;
|
return $_response_object;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
#
|
||||||
#
|
# logout_user
|
||||||
# logout_user
|
#
|
||||||
#
|
# Logs out current logged in user session
|
||||||
# Logs out current logged in user session
|
#
|
||||||
#
|
# @return void
|
||||||
# @return void
|
#
|
||||||
#
|
sub logout_user {
|
||||||
sub logout_user {
|
|
||||||
my ($self, %args) = @_;
|
my ($self, %args) = @_;
|
||||||
|
|
||||||
|
|
||||||
@ -316,17 +299,16 @@ sub new {
|
|||||||
$header_params, $_body_data, $auth_settings);
|
$header_params, $_body_data, $auth_settings);
|
||||||
return;
|
return;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
#
|
||||||
#
|
# get_user_by_name
|
||||||
# get_user_by_name
|
#
|
||||||
#
|
# Get user by user name
|
||||||
# Get user by user name
|
#
|
||||||
#
|
# @param string $username The name that needs to be fetched. Use user1 for testing. (required)
|
||||||
# @param string $username The name that needs to be fetched. Use user1 for testing. (required)
|
# @return User
|
||||||
# @return User
|
#
|
||||||
#
|
sub get_user_by_name {
|
||||||
sub get_user_by_name {
|
|
||||||
my ($self, %args) = @_;
|
my ($self, %args) = @_;
|
||||||
|
|
||||||
|
|
||||||
@ -377,18 +359,17 @@ sub new {
|
|||||||
my $_response_object = $self->{api_client}->deserialize('User', $response);
|
my $_response_object = $self->{api_client}->deserialize('User', $response);
|
||||||
return $_response_object;
|
return $_response_object;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
#
|
||||||
#
|
# update_user
|
||||||
# update_user
|
#
|
||||||
#
|
# Updated user
|
||||||
# Updated user
|
#
|
||||||
#
|
# @param string $username name that need to be deleted (required)
|
||||||
# @param string $username name that need to be deleted (required)
|
# @param User $body Updated user object (required)
|
||||||
# @param User $body Updated user object (required)
|
# @return void
|
||||||
# @return void
|
#
|
||||||
#
|
sub update_user {
|
||||||
sub update_user {
|
|
||||||
my ($self, %args) = @_;
|
my ($self, %args) = @_;
|
||||||
|
|
||||||
|
|
||||||
@ -439,17 +420,16 @@ sub new {
|
|||||||
$header_params, $_body_data, $auth_settings);
|
$header_params, $_body_data, $auth_settings);
|
||||||
return;
|
return;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
#
|
||||||
#
|
# delete_user
|
||||||
# delete_user
|
#
|
||||||
#
|
# Delete user
|
||||||
# Delete user
|
#
|
||||||
#
|
# @param string $username The name that needs to be deleted (required)
|
||||||
# @param string $username The name that needs to be deleted (required)
|
# @return void
|
||||||
# @return void
|
#
|
||||||
#
|
sub delete_user {
|
||||||
sub delete_user {
|
|
||||||
my ($self, %args) = @_;
|
my ($self, %args) = @_;
|
||||||
|
|
||||||
|
|
||||||
@ -497,8 +477,7 @@ sub new {
|
|||||||
$header_params, $_body_data, $auth_settings);
|
$header_params, $_body_data, $auth_settings);
|
||||||
return;
|
return;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
@ -1,13 +0,0 @@
|
|||||||
<?php
|
|
||||||
// load models defined for endpoints
|
|
||||||
foreach (glob(dirname(__FILE__)."/lib/models/*.php") as $filename)
|
|
||||||
{
|
|
||||||
require_once $filename;
|
|
||||||
}
|
|
||||||
|
|
||||||
// load classes for accessing the endpoints
|
|
||||||
foreach (glob(dirname(__FILE__)."/lib/*.php") as $filename)
|
|
||||||
{
|
|
||||||
require_once $filename;
|
|
||||||
}
|
|
||||||
?>
|
|
41
samples/client/petstore/php/SwaggerClient-php/autoload.php
Normal file
41
samples/client/petstore/php/SwaggerClient-php/autoload.php
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* An example of a project-specific implementation.
|
||||||
|
*
|
||||||
|
* After registering this autoload function with SPL, the following line
|
||||||
|
* would cause the function to attempt to load the \Swagger\Client\Baz\Qux class
|
||||||
|
* from /path/to/project/lib/Baz/Qux.php:
|
||||||
|
*
|
||||||
|
* new \Swagger\Client\Baz\Qux;
|
||||||
|
*
|
||||||
|
* @param string $class The fully-qualified class name.
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
spl_autoload_register(function ($class) {
|
||||||
|
|
||||||
|
// project-specific namespace prefix
|
||||||
|
$prefix = 'Swagger\\Client\\';
|
||||||
|
|
||||||
|
// base directory for the namespace prefix
|
||||||
|
$base_dir = __DIR__ . '/lib/';
|
||||||
|
|
||||||
|
// does the class use the namespace prefix?
|
||||||
|
$len = strlen($prefix);
|
||||||
|
if (strncmp($prefix, $class, $len) !== 0) {
|
||||||
|
// no, move to the next registered autoloader
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// get the relative class name
|
||||||
|
$relative_class = substr($class, $len);
|
||||||
|
|
||||||
|
// replace the namespace prefix with the base directory, replace namespace
|
||||||
|
// separators with directory separators in the relative class name, append
|
||||||
|
// with .php
|
||||||
|
$file = $base_dir . str_replace('\\', '/', $relative_class) . '.php';
|
||||||
|
|
||||||
|
// if the file exists, require it
|
||||||
|
if (file_exists($file)) {
|
||||||
|
require $file;
|
||||||
|
}
|
||||||
|
});
|
@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"name": "SwaggerClient/SwaggerClient-php",
|
"name": "swagger/swagger-client",
|
||||||
"description": "",
|
"description": "",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"swagger",
|
"swagger",
|
||||||
@ -27,6 +27,6 @@
|
|||||||
"squizlabs/php_codesniffer": "~2.0"
|
"squizlabs/php_codesniffer": "~2.0"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": { "SwaggerClient\\" : "lib/" }
|
"psr-4": { "Swagger\\Client\\" : "lib/" }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
542
samples/client/petstore/php/SwaggerClient-php/lib/Api/PetApi.php
Normal file
542
samples/client/petstore/php/SwaggerClient-php/lib/Api/PetApi.php
Normal file
@ -0,0 +1,542 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* 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. Do not edit the class manually.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Swagger\Client\Api;
|
||||||
|
|
||||||
|
use \Swagger\Client\ApiClient;
|
||||||
|
use \Swagger\Client\Configuration;
|
||||||
|
|
||||||
|
class PetApi {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param \Swagger\Client\ApiClient|null $apiClient The api client to use. Defaults to getting it from Configuration
|
||||||
|
*/
|
||||||
|
function __construct($apiClient = null) {
|
||||||
|
if (null === $apiClient) {
|
||||||
|
if (Configuration::$apiClient === null) {
|
||||||
|
Configuration::$apiClient = new ApiClient(); // create a new API client if not present
|
||||||
|
$this->apiClient = Configuration::$apiClient;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
$this->apiClient = Configuration::$apiClient; // use the default one
|
||||||
|
} else {
|
||||||
|
$this->apiClient = $apiClient; // use the one provided by the user
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @var \Swagger\Client\ApiClient instance of the ApiClient */
|
||||||
|
private $apiClient;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return \Swagger\Client\ApiClient get the API client
|
||||||
|
*/
|
||||||
|
public function getApiClient() {
|
||||||
|
return $this->apiClient;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param \Swagger\Client $apiClient set the API client
|
||||||
|
*/
|
||||||
|
public function setApiClient($apiClient) {
|
||||||
|
$this->apiClient = $apiClient;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* updatePet
|
||||||
|
*
|
||||||
|
* Update an existing pet
|
||||||
|
*
|
||||||
|
* @param \Swagger\Client\Model\Pet $body Pet object that needs to be added to the store (required)
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function updatePet($body) {
|
||||||
|
|
||||||
|
|
||||||
|
// parse inputs
|
||||||
|
$resourcePath = "/pet";
|
||||||
|
$resourcePath = str_replace("{format}", "json", $resourcePath);
|
||||||
|
$method = "PUT";
|
||||||
|
$httpBody = '';
|
||||||
|
$queryParams = array();
|
||||||
|
$headerParams = array();
|
||||||
|
$formParams = array();
|
||||||
|
$_header_accept = $this->apiClient->selectHeaderAccept(array('application/json', 'application/xml'));
|
||||||
|
if (!is_null($_header_accept)) {
|
||||||
|
$headerParams['Accept'] = $_header_accept;
|
||||||
|
}
|
||||||
|
$headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(array('application/json','application/xml'));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
// authentication setting, if any
|
||||||
|
$authSettings = array('petstore_auth');
|
||||||
|
|
||||||
|
// make the API Call
|
||||||
|
$response = $this->apiClient->callAPI($resourcePath, $method,
|
||||||
|
$queryParams, $httpBody,
|
||||||
|
$headerParams, $authSettings);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* addPet
|
||||||
|
*
|
||||||
|
* Add a new pet to the store
|
||||||
|
*
|
||||||
|
* @param \Swagger\Client\Model\Pet $body Pet object that needs to be added to the store (required)
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function addPet($body) {
|
||||||
|
|
||||||
|
|
||||||
|
// parse inputs
|
||||||
|
$resourcePath = "/pet";
|
||||||
|
$resourcePath = str_replace("{format}", "json", $resourcePath);
|
||||||
|
$method = "POST";
|
||||||
|
$httpBody = '';
|
||||||
|
$queryParams = array();
|
||||||
|
$headerParams = array();
|
||||||
|
$formParams = array();
|
||||||
|
$_header_accept = $this->apiClient->selectHeaderAccept(array('application/json', 'application/xml'));
|
||||||
|
if (!is_null($_header_accept)) {
|
||||||
|
$headerParams['Accept'] = $_header_accept;
|
||||||
|
}
|
||||||
|
$headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(array('application/json','application/xml'));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
// authentication setting, if any
|
||||||
|
$authSettings = array('petstore_auth');
|
||||||
|
|
||||||
|
// make the API Call
|
||||||
|
$response = $this->apiClient->callAPI($resourcePath, $method,
|
||||||
|
$queryParams, $httpBody,
|
||||||
|
$headerParams, $authSettings);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* findPetsByStatus
|
||||||
|
*
|
||||||
|
* Finds Pets by status
|
||||||
|
*
|
||||||
|
* @param string[] $status Status values that need to be considered for filter (required)
|
||||||
|
* @return \Swagger\Client\Model\Pet[]
|
||||||
|
*/
|
||||||
|
public function findPetsByStatus($status) {
|
||||||
|
|
||||||
|
|
||||||
|
// parse inputs
|
||||||
|
$resourcePath = "/pet/findByStatus";
|
||||||
|
$resourcePath = str_replace("{format}", "json", $resourcePath);
|
||||||
|
$method = "GET";
|
||||||
|
$httpBody = '';
|
||||||
|
$queryParams = array();
|
||||||
|
$headerParams = array();
|
||||||
|
$formParams = array();
|
||||||
|
$_header_accept = $this->apiClient->selectHeaderAccept(array('application/json', 'application/xml'));
|
||||||
|
if (!is_null($_header_accept)) {
|
||||||
|
$headerParams['Accept'] = $_header_accept;
|
||||||
|
}
|
||||||
|
$headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(array());
|
||||||
|
|
||||||
|
// query params
|
||||||
|
if($status !== null) {
|
||||||
|
$queryParams['status'] = $this->apiClient->toQueryValue($status);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
// authentication setting, if any
|
||||||
|
$authSettings = array('petstore_auth');
|
||||||
|
|
||||||
|
// make the API Call
|
||||||
|
$response = $this->apiClient->callAPI($resourcePath, $method,
|
||||||
|
$queryParams, $httpBody,
|
||||||
|
$headerParams, $authSettings);
|
||||||
|
if(! $response) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$responseObject = $this->apiClient->deserialize($response,'\Swagger\Client\Model\Pet[]');
|
||||||
|
return $responseObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* findPetsByTags
|
||||||
|
*
|
||||||
|
* Finds Pets by tags
|
||||||
|
*
|
||||||
|
* @param string[] $tags Tags to filter by (required)
|
||||||
|
* @return \Swagger\Client\Model\Pet[]
|
||||||
|
*/
|
||||||
|
public function findPetsByTags($tags) {
|
||||||
|
|
||||||
|
|
||||||
|
// parse inputs
|
||||||
|
$resourcePath = "/pet/findByTags";
|
||||||
|
$resourcePath = str_replace("{format}", "json", $resourcePath);
|
||||||
|
$method = "GET";
|
||||||
|
$httpBody = '';
|
||||||
|
$queryParams = array();
|
||||||
|
$headerParams = array();
|
||||||
|
$formParams = array();
|
||||||
|
$_header_accept = $this->apiClient->selectHeaderAccept(array('application/json', 'application/xml'));
|
||||||
|
if (!is_null($_header_accept)) {
|
||||||
|
$headerParams['Accept'] = $_header_accept;
|
||||||
|
}
|
||||||
|
$headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(array());
|
||||||
|
|
||||||
|
// query params
|
||||||
|
if($tags !== null) {
|
||||||
|
$queryParams['tags'] = $this->apiClient->toQueryValue($tags);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
// authentication setting, if any
|
||||||
|
$authSettings = array('petstore_auth');
|
||||||
|
|
||||||
|
// make the API Call
|
||||||
|
$response = $this->apiClient->callAPI($resourcePath, $method,
|
||||||
|
$queryParams, $httpBody,
|
||||||
|
$headerParams, $authSettings);
|
||||||
|
if(! $response) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$responseObject = $this->apiClient->deserialize($response,'\Swagger\Client\Model\Pet[]');
|
||||||
|
return $responseObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* getPetById
|
||||||
|
*
|
||||||
|
* Find pet by ID
|
||||||
|
*
|
||||||
|
* @param int $pet_id ID of pet that needs to be fetched (required)
|
||||||
|
* @return \Swagger\Client\Model\Pet
|
||||||
|
*/
|
||||||
|
public function getPetById($pet_id) {
|
||||||
|
|
||||||
|
// verify the required parameter 'pet_id' is set
|
||||||
|
if ($pet_id === null) {
|
||||||
|
throw new \InvalidArgumentException('Missing the required parameter $pet_id when calling getPetById');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// parse inputs
|
||||||
|
$resourcePath = "/pet/{petId}";
|
||||||
|
$resourcePath = str_replace("{format}", "json", $resourcePath);
|
||||||
|
$method = "GET";
|
||||||
|
$httpBody = '';
|
||||||
|
$queryParams = array();
|
||||||
|
$headerParams = array();
|
||||||
|
$formParams = array();
|
||||||
|
$_header_accept = $this->apiClient->selectHeaderAccept(array('application/json', 'application/xml'));
|
||||||
|
if (!is_null($_header_accept)) {
|
||||||
|
$headerParams['Accept'] = $_header_accept;
|
||||||
|
}
|
||||||
|
$headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(array());
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// path params
|
||||||
|
if($pet_id !== null) {
|
||||||
|
$resourcePath = str_replace("{" . "petId" . "}",
|
||||||
|
$this->apiClient->toPathValue($pet_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;
|
||||||
|
}
|
||||||
|
|
||||||
|
// authentication setting, if any
|
||||||
|
$authSettings = array('api_key', 'petstore_auth');
|
||||||
|
|
||||||
|
// make the API Call
|
||||||
|
$response = $this->apiClient->callAPI($resourcePath, $method,
|
||||||
|
$queryParams, $httpBody,
|
||||||
|
$headerParams, $authSettings);
|
||||||
|
if(! $response) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$responseObject = $this->apiClient->deserialize($response,'\Swagger\Client\Model\Pet');
|
||||||
|
return $responseObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* updatePetWithForm
|
||||||
|
*
|
||||||
|
* 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)
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function updatePetWithForm($pet_id, $name, $status) {
|
||||||
|
|
||||||
|
// verify the required parameter 'pet_id' is set
|
||||||
|
if ($pet_id === null) {
|
||||||
|
throw new \InvalidArgumentException('Missing the required parameter $pet_id when calling updatePetWithForm');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// parse inputs
|
||||||
|
$resourcePath = "/pet/{petId}";
|
||||||
|
$resourcePath = str_replace("{format}", "json", $resourcePath);
|
||||||
|
$method = "POST";
|
||||||
|
$httpBody = '';
|
||||||
|
$queryParams = array();
|
||||||
|
$headerParams = array();
|
||||||
|
$formParams = array();
|
||||||
|
$_header_accept = $this->apiClient->selectHeaderAccept(array('application/json', 'application/xml'));
|
||||||
|
if (!is_null($_header_accept)) {
|
||||||
|
$headerParams['Accept'] = $_header_accept;
|
||||||
|
}
|
||||||
|
$headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(array('application/x-www-form-urlencoded'));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// path params
|
||||||
|
if($pet_id !== null) {
|
||||||
|
$resourcePath = str_replace("{" . "petId" . "}",
|
||||||
|
$this->apiClient->toPathValue($pet_id), $resourcePath);
|
||||||
|
}
|
||||||
|
// form params
|
||||||
|
if ($name !== null) {
|
||||||
|
$formParams['name'] = $this->apiClient->toFormValue($name);
|
||||||
|
}// form params
|
||||||
|
if ($status !== null) {
|
||||||
|
$formParams['status'] = $this->apiClient->toFormValue($status);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
// authentication setting, if any
|
||||||
|
$authSettings = array('petstore_auth');
|
||||||
|
|
||||||
|
// make the API Call
|
||||||
|
$response = $this->apiClient->callAPI($resourcePath, $method,
|
||||||
|
$queryParams, $httpBody,
|
||||||
|
$headerParams, $authSettings);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* deletePet
|
||||||
|
*
|
||||||
|
* Deletes a pet
|
||||||
|
*
|
||||||
|
* @param string $api_key (required)
|
||||||
|
* @param int $pet_id Pet id to delete (required)
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function deletePet($api_key, $pet_id) {
|
||||||
|
|
||||||
|
// verify the required parameter 'pet_id' is set
|
||||||
|
if ($pet_id === null) {
|
||||||
|
throw new \InvalidArgumentException('Missing the required parameter $pet_id when calling deletePet');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// parse inputs
|
||||||
|
$resourcePath = "/pet/{petId}";
|
||||||
|
$resourcePath = str_replace("{format}", "json", $resourcePath);
|
||||||
|
$method = "DELETE";
|
||||||
|
$httpBody = '';
|
||||||
|
$queryParams = array();
|
||||||
|
$headerParams = array();
|
||||||
|
$formParams = array();
|
||||||
|
$_header_accept = $this->apiClient->selectHeaderAccept(array('application/json', 'application/xml'));
|
||||||
|
if (!is_null($_header_accept)) {
|
||||||
|
$headerParams['Accept'] = $_header_accept;
|
||||||
|
}
|
||||||
|
$headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(array());
|
||||||
|
|
||||||
|
|
||||||
|
// header params
|
||||||
|
if($api_key !== null) {
|
||||||
|
$headerParams['api_key'] = $this->apiClient->toHeaderValue($api_key);
|
||||||
|
}
|
||||||
|
// path params
|
||||||
|
if($pet_id !== null) {
|
||||||
|
$resourcePath = str_replace("{" . "petId" . "}",
|
||||||
|
$this->apiClient->toPathValue($pet_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;
|
||||||
|
}
|
||||||
|
|
||||||
|
// authentication setting, if any
|
||||||
|
$authSettings = array('petstore_auth');
|
||||||
|
|
||||||
|
// make the API Call
|
||||||
|
$response = $this->apiClient->callAPI($resourcePath, $method,
|
||||||
|
$queryParams, $httpBody,
|
||||||
|
$headerParams, $authSettings);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* uploadFile
|
||||||
|
*
|
||||||
|
* 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 string $file file to upload (required)
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function uploadFile($pet_id, $additional_metadata, $file) {
|
||||||
|
|
||||||
|
// verify the required parameter 'pet_id' is set
|
||||||
|
if ($pet_id === null) {
|
||||||
|
throw new \InvalidArgumentException('Missing the required parameter $pet_id when calling uploadFile');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// parse inputs
|
||||||
|
$resourcePath = "/pet/{petId}/uploadImage";
|
||||||
|
$resourcePath = str_replace("{format}", "json", $resourcePath);
|
||||||
|
$method = "POST";
|
||||||
|
$httpBody = '';
|
||||||
|
$queryParams = array();
|
||||||
|
$headerParams = array();
|
||||||
|
$formParams = array();
|
||||||
|
$_header_accept = $this->apiClient->selectHeaderAccept(array('application/json', 'application/xml'));
|
||||||
|
if (!is_null($_header_accept)) {
|
||||||
|
$headerParams['Accept'] = $_header_accept;
|
||||||
|
}
|
||||||
|
$headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(array('multipart/form-data'));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// path params
|
||||||
|
if($pet_id !== null) {
|
||||||
|
$resourcePath = str_replace("{" . "petId" . "}",
|
||||||
|
$this->apiClient->toPathValue($pet_id), $resourcePath);
|
||||||
|
}
|
||||||
|
// form params
|
||||||
|
if ($additional_metadata !== null) {
|
||||||
|
$formParams['additionalMetadata'] = $this->apiClient->toFormValue($additional_metadata);
|
||||||
|
}// form params
|
||||||
|
if ($file !== null) {
|
||||||
|
$formParams['file'] = '@' . $this->apiClient->toFormValue($file);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
// authentication setting, if any
|
||||||
|
$authSettings = array('petstore_auth');
|
||||||
|
|
||||||
|
// make the API Call
|
||||||
|
$response = $this->apiClient->callAPI($resourcePath, $method,
|
||||||
|
$queryParams, $httpBody,
|
||||||
|
$headerParams, $authSettings);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,297 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* 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. Do not edit the class manually.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Swagger\Client\Api;
|
||||||
|
|
||||||
|
use \Swagger\Client\ApiClient;
|
||||||
|
use \Swagger\Client\Configuration;
|
||||||
|
|
||||||
|
class StoreApi {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param \Swagger\Client\ApiClient|null $apiClient The api client to use. Defaults to getting it from Configuration
|
||||||
|
*/
|
||||||
|
function __construct($apiClient = null) {
|
||||||
|
if (null === $apiClient) {
|
||||||
|
if (Configuration::$apiClient === null) {
|
||||||
|
Configuration::$apiClient = new ApiClient(); // create a new API client if not present
|
||||||
|
$this->apiClient = Configuration::$apiClient;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
$this->apiClient = Configuration::$apiClient; // use the default one
|
||||||
|
} else {
|
||||||
|
$this->apiClient = $apiClient; // use the one provided by the user
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @var \Swagger\Client\ApiClient instance of the ApiClient */
|
||||||
|
private $apiClient;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return \Swagger\Client\ApiClient get the API client
|
||||||
|
*/
|
||||||
|
public function getApiClient() {
|
||||||
|
return $this->apiClient;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param \Swagger\Client $apiClient set the API client
|
||||||
|
*/
|
||||||
|
public function setApiClient($apiClient) {
|
||||||
|
$this->apiClient = $apiClient;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* getInventory
|
||||||
|
*
|
||||||
|
* Returns pet inventories by status
|
||||||
|
*
|
||||||
|
* @return map[string,int]
|
||||||
|
*/
|
||||||
|
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 = $this->apiClient->selectHeaderAccept(array('application/json', 'application/xml'));
|
||||||
|
if (!is_null($_header_accept)) {
|
||||||
|
$headerParams['Accept'] = $_header_accept;
|
||||||
|
}
|
||||||
|
$headerParams['Content-Type'] = $this->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;
|
||||||
|
}
|
||||||
|
|
||||||
|
// authentication setting, if any
|
||||||
|
$authSettings = array('api_key');
|
||||||
|
|
||||||
|
// make the API Call
|
||||||
|
$response = $this->apiClient->callAPI($resourcePath, $method,
|
||||||
|
$queryParams, $httpBody,
|
||||||
|
$headerParams, $authSettings);
|
||||||
|
if(! $response) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$responseObject = $this->apiClient->deserialize($response,'map[string,int]');
|
||||||
|
return $responseObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
||||||
|
*/
|
||||||
|
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 = $this->apiClient->selectHeaderAccept(array('application/json', 'application/xml'));
|
||||||
|
if (!is_null($_header_accept)) {
|
||||||
|
$headerParams['Accept'] = $_header_accept;
|
||||||
|
}
|
||||||
|
$headerParams['Content-Type'] = $this->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;
|
||||||
|
}
|
||||||
|
|
||||||
|
// authentication setting, if any
|
||||||
|
$authSettings = array();
|
||||||
|
|
||||||
|
// make the API Call
|
||||||
|
$response = $this->apiClient->callAPI($resourcePath, $method,
|
||||||
|
$queryParams, $httpBody,
|
||||||
|
$headerParams, $authSettings);
|
||||||
|
if(! $response) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$responseObject = $this->apiClient->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
|
||||||
|
*/
|
||||||
|
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 = $this->apiClient->selectHeaderAccept(array('application/json', 'application/xml'));
|
||||||
|
if (!is_null($_header_accept)) {
|
||||||
|
$headerParams['Accept'] = $_header_accept;
|
||||||
|
}
|
||||||
|
$headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(array());
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// path params
|
||||||
|
if($order_id !== null) {
|
||||||
|
$resourcePath = str_replace("{" . "orderId" . "}",
|
||||||
|
$this->apiClient->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;
|
||||||
|
}
|
||||||
|
|
||||||
|
// authentication setting, if any
|
||||||
|
$authSettings = array();
|
||||||
|
|
||||||
|
// make the API Call
|
||||||
|
$response = $this->apiClient->callAPI($resourcePath, $method,
|
||||||
|
$queryParams, $httpBody,
|
||||||
|
$headerParams, $authSettings);
|
||||||
|
if(! $response) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$responseObject = $this->apiClient->deserialize($response,'\Swagger\Client\Model\Order');
|
||||||
|
return $responseObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* deleteOrder
|
||||||
|
*
|
||||||
|
* Delete purchase order by ID
|
||||||
|
*
|
||||||
|
* @param string $order_id ID of the order that needs to be deleted (required)
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
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 = $this->apiClient->selectHeaderAccept(array('application/json', 'application/xml'));
|
||||||
|
if (!is_null($_header_accept)) {
|
||||||
|
$headerParams['Accept'] = $_header_accept;
|
||||||
|
}
|
||||||
|
$headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(array());
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// path params
|
||||||
|
if($order_id !== null) {
|
||||||
|
$resourcePath = str_replace("{" . "orderId" . "}",
|
||||||
|
$this->apiClient->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;
|
||||||
|
}
|
||||||
|
|
||||||
|
// authentication setting, if any
|
||||||
|
$authSettings = array();
|
||||||
|
|
||||||
|
// make the API Call
|
||||||
|
$response = $this->apiClient->callAPI($resourcePath, $method,
|
||||||
|
$queryParams, $httpBody,
|
||||||
|
$headerParams, $authSettings);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,517 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* 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. Do not edit the class manually.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Swagger\Client\Api;
|
||||||
|
|
||||||
|
use \Swagger\Client\ApiClient;
|
||||||
|
use \Swagger\Client\Configuration;
|
||||||
|
|
||||||
|
class UserApi {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param \Swagger\Client\ApiClient|null $apiClient The api client to use. Defaults to getting it from Configuration
|
||||||
|
*/
|
||||||
|
function __construct($apiClient = null) {
|
||||||
|
if (null === $apiClient) {
|
||||||
|
if (Configuration::$apiClient === null) {
|
||||||
|
Configuration::$apiClient = new ApiClient(); // create a new API client if not present
|
||||||
|
$this->apiClient = Configuration::$apiClient;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
$this->apiClient = Configuration::$apiClient; // use the default one
|
||||||
|
} else {
|
||||||
|
$this->apiClient = $apiClient; // use the one provided by the user
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @var \Swagger\Client\ApiClient instance of the ApiClient */
|
||||||
|
private $apiClient;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return \Swagger\Client\ApiClient get the API client
|
||||||
|
*/
|
||||||
|
public function getApiClient() {
|
||||||
|
return $this->apiClient;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param \Swagger\Client $apiClient set the API client
|
||||||
|
*/
|
||||||
|
public function setApiClient($apiClient) {
|
||||||
|
$this->apiClient = $apiClient;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* createUser
|
||||||
|
*
|
||||||
|
* Create user
|
||||||
|
*
|
||||||
|
* @param \Swagger\Client\Model\User $body Created user object (required)
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function createUser($body) {
|
||||||
|
|
||||||
|
|
||||||
|
// parse inputs
|
||||||
|
$resourcePath = "/user";
|
||||||
|
$resourcePath = str_replace("{format}", "json", $resourcePath);
|
||||||
|
$method = "POST";
|
||||||
|
$httpBody = '';
|
||||||
|
$queryParams = array();
|
||||||
|
$headerParams = array();
|
||||||
|
$formParams = array();
|
||||||
|
$_header_accept = $this->apiClient->selectHeaderAccept(array('application/json', 'application/xml'));
|
||||||
|
if (!is_null($_header_accept)) {
|
||||||
|
$headerParams['Accept'] = $_header_accept;
|
||||||
|
}
|
||||||
|
$headerParams['Content-Type'] = $this->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;
|
||||||
|
}
|
||||||
|
|
||||||
|
// authentication setting, if any
|
||||||
|
$authSettings = array();
|
||||||
|
|
||||||
|
// make the API Call
|
||||||
|
$response = $this->apiClient->callAPI($resourcePath, $method,
|
||||||
|
$queryParams, $httpBody,
|
||||||
|
$headerParams, $authSettings);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* createUsersWithArrayInput
|
||||||
|
*
|
||||||
|
* Creates list of users with given input array
|
||||||
|
*
|
||||||
|
* @param \Swagger\Client\Model\User[] $body List of user object (required)
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function createUsersWithArrayInput($body) {
|
||||||
|
|
||||||
|
|
||||||
|
// parse inputs
|
||||||
|
$resourcePath = "/user/createWithArray";
|
||||||
|
$resourcePath = str_replace("{format}", "json", $resourcePath);
|
||||||
|
$method = "POST";
|
||||||
|
$httpBody = '';
|
||||||
|
$queryParams = array();
|
||||||
|
$headerParams = array();
|
||||||
|
$formParams = array();
|
||||||
|
$_header_accept = $this->apiClient->selectHeaderAccept(array('application/json', 'application/xml'));
|
||||||
|
if (!is_null($_header_accept)) {
|
||||||
|
$headerParams['Accept'] = $_header_accept;
|
||||||
|
}
|
||||||
|
$headerParams['Content-Type'] = $this->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;
|
||||||
|
}
|
||||||
|
|
||||||
|
// authentication setting, if any
|
||||||
|
$authSettings = array();
|
||||||
|
|
||||||
|
// make the API Call
|
||||||
|
$response = $this->apiClient->callAPI($resourcePath, $method,
|
||||||
|
$queryParams, $httpBody,
|
||||||
|
$headerParams, $authSettings);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* createUsersWithListInput
|
||||||
|
*
|
||||||
|
* Creates list of users with given input array
|
||||||
|
*
|
||||||
|
* @param \Swagger\Client\Model\User[] $body List of user object (required)
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function createUsersWithListInput($body) {
|
||||||
|
|
||||||
|
|
||||||
|
// parse inputs
|
||||||
|
$resourcePath = "/user/createWithList";
|
||||||
|
$resourcePath = str_replace("{format}", "json", $resourcePath);
|
||||||
|
$method = "POST";
|
||||||
|
$httpBody = '';
|
||||||
|
$queryParams = array();
|
||||||
|
$headerParams = array();
|
||||||
|
$formParams = array();
|
||||||
|
$_header_accept = $this->apiClient->selectHeaderAccept(array('application/json', 'application/xml'));
|
||||||
|
if (!is_null($_header_accept)) {
|
||||||
|
$headerParams['Accept'] = $_header_accept;
|
||||||
|
}
|
||||||
|
$headerParams['Content-Type'] = $this->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;
|
||||||
|
}
|
||||||
|
|
||||||
|
// authentication setting, if any
|
||||||
|
$authSettings = array();
|
||||||
|
|
||||||
|
// make the API Call
|
||||||
|
$response = $this->apiClient->callAPI($resourcePath, $method,
|
||||||
|
$queryParams, $httpBody,
|
||||||
|
$headerParams, $authSettings);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* loginUser
|
||||||
|
*
|
||||||
|
* 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)
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function loginUser($username, $password) {
|
||||||
|
|
||||||
|
|
||||||
|
// parse inputs
|
||||||
|
$resourcePath = "/user/login";
|
||||||
|
$resourcePath = str_replace("{format}", "json", $resourcePath);
|
||||||
|
$method = "GET";
|
||||||
|
$httpBody = '';
|
||||||
|
$queryParams = array();
|
||||||
|
$headerParams = array();
|
||||||
|
$formParams = array();
|
||||||
|
$_header_accept = $this->apiClient->selectHeaderAccept(array('application/json', 'application/xml'));
|
||||||
|
if (!is_null($_header_accept)) {
|
||||||
|
$headerParams['Accept'] = $_header_accept;
|
||||||
|
}
|
||||||
|
$headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(array());
|
||||||
|
|
||||||
|
// query params
|
||||||
|
if($username !== null) {
|
||||||
|
$queryParams['username'] = $this->apiClient->toQueryValue($username);
|
||||||
|
}// query params
|
||||||
|
if($password !== null) {
|
||||||
|
$queryParams['password'] = $this->apiClient->toQueryValue($password);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
// authentication setting, if any
|
||||||
|
$authSettings = array();
|
||||||
|
|
||||||
|
// make the API Call
|
||||||
|
$response = $this->apiClient->callAPI($resourcePath, $method,
|
||||||
|
$queryParams, $httpBody,
|
||||||
|
$headerParams, $authSettings);
|
||||||
|
if(! $response) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$responseObject = $this->apiClient->deserialize($response,'string');
|
||||||
|
return $responseObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* logoutUser
|
||||||
|
*
|
||||||
|
* Logs out current logged in user session
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function logoutUser() {
|
||||||
|
|
||||||
|
|
||||||
|
// parse inputs
|
||||||
|
$resourcePath = "/user/logout";
|
||||||
|
$resourcePath = str_replace("{format}", "json", $resourcePath);
|
||||||
|
$method = "GET";
|
||||||
|
$httpBody = '';
|
||||||
|
$queryParams = array();
|
||||||
|
$headerParams = array();
|
||||||
|
$formParams = array();
|
||||||
|
$_header_accept = $this->apiClient->selectHeaderAccept(array('application/json', 'application/xml'));
|
||||||
|
if (!is_null($_header_accept)) {
|
||||||
|
$headerParams['Accept'] = $_header_accept;
|
||||||
|
}
|
||||||
|
$headerParams['Content-Type'] = $this->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;
|
||||||
|
}
|
||||||
|
|
||||||
|
// authentication setting, if any
|
||||||
|
$authSettings = array();
|
||||||
|
|
||||||
|
// make the API Call
|
||||||
|
$response = $this->apiClient->callAPI($resourcePath, $method,
|
||||||
|
$queryParams, $httpBody,
|
||||||
|
$headerParams, $authSettings);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* getUserByName
|
||||||
|
*
|
||||||
|
* Get user by user name
|
||||||
|
*
|
||||||
|
* @param string $username The name that needs to be fetched. Use user1 for testing. (required)
|
||||||
|
* @return \Swagger\Client\Model\User
|
||||||
|
*/
|
||||||
|
public function getUserByName($username) {
|
||||||
|
|
||||||
|
// verify the required parameter 'username' is set
|
||||||
|
if ($username === null) {
|
||||||
|
throw new \InvalidArgumentException('Missing the required parameter $username when calling getUserByName');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// parse inputs
|
||||||
|
$resourcePath = "/user/{username}";
|
||||||
|
$resourcePath = str_replace("{format}", "json", $resourcePath);
|
||||||
|
$method = "GET";
|
||||||
|
$httpBody = '';
|
||||||
|
$queryParams = array();
|
||||||
|
$headerParams = array();
|
||||||
|
$formParams = array();
|
||||||
|
$_header_accept = $this->apiClient->selectHeaderAccept(array('application/json', 'application/xml'));
|
||||||
|
if (!is_null($_header_accept)) {
|
||||||
|
$headerParams['Accept'] = $_header_accept;
|
||||||
|
}
|
||||||
|
$headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(array());
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// path params
|
||||||
|
if($username !== null) {
|
||||||
|
$resourcePath = str_replace("{" . "username" . "}",
|
||||||
|
$this->apiClient->toPathValue($username), $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;
|
||||||
|
}
|
||||||
|
|
||||||
|
// authentication setting, if any
|
||||||
|
$authSettings = array();
|
||||||
|
|
||||||
|
// make the API Call
|
||||||
|
$response = $this->apiClient->callAPI($resourcePath, $method,
|
||||||
|
$queryParams, $httpBody,
|
||||||
|
$headerParams, $authSettings);
|
||||||
|
if(! $response) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$responseObject = $this->apiClient->deserialize($response,'\Swagger\Client\Model\User');
|
||||||
|
return $responseObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* updateUser
|
||||||
|
*
|
||||||
|
* Updated user
|
||||||
|
*
|
||||||
|
* @param string $username name that need to be deleted (required)
|
||||||
|
* @param \Swagger\Client\Model\User $body Updated user object (required)
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function updateUser($username, $body) {
|
||||||
|
|
||||||
|
// verify the required parameter 'username' is set
|
||||||
|
if ($username === null) {
|
||||||
|
throw new \InvalidArgumentException('Missing the required parameter $username when calling updateUser');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// parse inputs
|
||||||
|
$resourcePath = "/user/{username}";
|
||||||
|
$resourcePath = str_replace("{format}", "json", $resourcePath);
|
||||||
|
$method = "PUT";
|
||||||
|
$httpBody = '';
|
||||||
|
$queryParams = array();
|
||||||
|
$headerParams = array();
|
||||||
|
$formParams = array();
|
||||||
|
$_header_accept = $this->apiClient->selectHeaderAccept(array('application/json', 'application/xml'));
|
||||||
|
if (!is_null($_header_accept)) {
|
||||||
|
$headerParams['Accept'] = $_header_accept;
|
||||||
|
}
|
||||||
|
$headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(array());
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// path params
|
||||||
|
if($username !== null) {
|
||||||
|
$resourcePath = str_replace("{" . "username" . "}",
|
||||||
|
$this->apiClient->toPathValue($username), $resourcePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
// authentication setting, if any
|
||||||
|
$authSettings = array();
|
||||||
|
|
||||||
|
// make the API Call
|
||||||
|
$response = $this->apiClient->callAPI($resourcePath, $method,
|
||||||
|
$queryParams, $httpBody,
|
||||||
|
$headerParams, $authSettings);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* deleteUser
|
||||||
|
*
|
||||||
|
* Delete user
|
||||||
|
*
|
||||||
|
* @param string $username The name that needs to be deleted (required)
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function deleteUser($username) {
|
||||||
|
|
||||||
|
// verify the required parameter 'username' is set
|
||||||
|
if ($username === null) {
|
||||||
|
throw new \InvalidArgumentException('Missing the required parameter $username when calling deleteUser');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// parse inputs
|
||||||
|
$resourcePath = "/user/{username}";
|
||||||
|
$resourcePath = str_replace("{format}", "json", $resourcePath);
|
||||||
|
$method = "DELETE";
|
||||||
|
$httpBody = '';
|
||||||
|
$queryParams = array();
|
||||||
|
$headerParams = array();
|
||||||
|
$formParams = array();
|
||||||
|
$_header_accept = $this->apiClient->selectHeaderAccept(array('application/json', 'application/xml'));
|
||||||
|
if (!is_null($_header_accept)) {
|
||||||
|
$headerParams['Accept'] = $_header_accept;
|
||||||
|
}
|
||||||
|
$headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(array());
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// path params
|
||||||
|
if($username !== null) {
|
||||||
|
$resourcePath = str_replace("{" . "username" . "}",
|
||||||
|
$this->apiClient->toPathValue($username), $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;
|
||||||
|
}
|
||||||
|
|
||||||
|
// authentication setting, if any
|
||||||
|
$authSettings = array();
|
||||||
|
|
||||||
|
// make the API Call
|
||||||
|
$response = $this->apiClient->callAPI($resourcePath, $method,
|
||||||
|
$queryParams, $httpBody,
|
||||||
|
$headerParams, $authSettings);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -15,7 +15,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace SwaggerClient;
|
namespace Swagger\Client;
|
||||||
|
|
||||||
class ApiClient {
|
class ApiClient {
|
||||||
|
|
||||||
@ -25,16 +25,13 @@ class ApiClient {
|
|||||||
public static $PUT = "PUT";
|
public static $PUT = "PUT";
|
||||||
public static $DELETE = "DELETE";
|
public static $DELETE = "DELETE";
|
||||||
|
|
||||||
|
/** @var string[] Array of default headers where the key is the header name and the value is the header value */
|
||||||
private $default_header = array();
|
private $default_header = array();
|
||||||
|
|
||||||
/*
|
/** @var string timeout (second) of the HTTP request, by default set to 0, no timeout */
|
||||||
* @var string timeout (second) of the HTTP request, by default set to 0, no timeout
|
|
||||||
*/
|
|
||||||
protected $curl_timeout = 0;
|
protected $curl_timeout = 0;
|
||||||
|
|
||||||
/*
|
/** @var string user agent of the HTTP request, set to "PHP-Swagger" by default */
|
||||||
* @var string user agent of the HTTP request, set to "PHP-Swagger" by default
|
|
||||||
*/
|
|
||||||
protected $user_agent = "PHP-Swagger";
|
protected $user_agent = "PHP-Swagger";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -391,8 +388,8 @@ class ApiClient {
|
|||||||
$deserialized[$key] = $this->deserialize($value, $subClass);
|
$deserialized[$key] = $this->deserialize($value, $subClass);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} elseif (strcasecmp(substr($class, 0, 6),'array[') == 0) {
|
} elseif (strcasecmp(substr($class, -2),'[]') == 0) {
|
||||||
$subClass = substr($class, 6, -1);
|
$subClass = substr($class, 0, -2);
|
||||||
$values = array();
|
$values = array();
|
||||||
foreach ($data as $key => $value) {
|
foreach ($data as $key => $value) {
|
||||||
$values[] = $this->deserialize($value, $subClass);
|
$values[] = $this->deserialize($value, $subClass);
|
||||||
@ -404,7 +401,6 @@ class ApiClient {
|
|||||||
settype($data, $class);
|
settype($data, $class);
|
||||||
$deserialized = $data;
|
$deserialized = $data;
|
||||||
} else {
|
} else {
|
||||||
$class = "SwaggerClient\\models\\".$class;
|
|
||||||
$instance = new $class();
|
$instance = new $class();
|
||||||
foreach ($instance::$swaggerTypes as $property => $type) {
|
foreach ($instance::$swaggerTypes as $property => $type) {
|
||||||
$original_property_name = $instance::$attributeMap[$property];
|
$original_property_name = $instance::$attributeMap[$property];
|
||||||
|
@ -15,20 +15,16 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace SwaggerClient;
|
namespace Swagger\Client;
|
||||||
|
|
||||||
use \Exception;
|
use \Exception;
|
||||||
|
|
||||||
class ApiException extends Exception {
|
class ApiException extends Exception {
|
||||||
|
|
||||||
/**
|
/** @var string The HTTP body of the server response. */
|
||||||
* The HTTP body of the server response.
|
|
||||||
*/
|
|
||||||
protected $response_body;
|
protected $response_body;
|
||||||
|
|
||||||
/**
|
/** @var string[] The HTTP header of the server response. */
|
||||||
* The HTTP header of the server response.
|
|
||||||
*/
|
|
||||||
protected $response_headers;
|
protected $response_headers;
|
||||||
|
|
||||||
public function __construct($message="", $code=0, $responseHeaders=null, $responseBody=null) {
|
public function __construct($message="", $code=0, $responseHeaders=null, $responseBody=null) {
|
||||||
|
@ -15,43 +15,31 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace SwaggerClient;
|
namespace Swagger\Client;
|
||||||
|
|
||||||
|
use \Swagger\Client\ApiClient;
|
||||||
|
|
||||||
class Configuration {
|
class Configuration {
|
||||||
|
|
||||||
/**
|
/** @var string[] Associate array to store API key(s) */
|
||||||
* Associate array to store API key(s)
|
|
||||||
*/
|
|
||||||
public static $apiKey = array();
|
public static $apiKey = array();
|
||||||
|
|
||||||
/**
|
/** string[] Associate array to store API prefix (e.g. Bearer) */
|
||||||
* Associate array to store API prefix (e.g. Bearer)
|
|
||||||
*/
|
|
||||||
public static $apiKeyPrefix = array();
|
public static $apiKeyPrefix = array();
|
||||||
|
|
||||||
/**
|
/** @var string Username for HTTP basic authentication */
|
||||||
* Username for HTTP basic authentication
|
|
||||||
*/
|
|
||||||
public static $username = '';
|
public static $username = '';
|
||||||
|
|
||||||
/**
|
/** @var string Password for HTTP basic authentication */
|
||||||
* Password for HTTP basic authentication
|
|
||||||
*/
|
|
||||||
public static $password = '';
|
public static $password = '';
|
||||||
|
|
||||||
/**
|
/** @var \Swagger\Client\ApiClient The default instance of ApiClient */
|
||||||
* The default instance of ApiClient
|
|
||||||
*/
|
|
||||||
public static $apiClient;
|
public static $apiClient;
|
||||||
|
|
||||||
/**
|
/** @var bool Debug switch (default set to false) */
|
||||||
* Debug switch (default set to false)
|
|
||||||
*/
|
|
||||||
public static $debug = false;
|
public static $debug = false;
|
||||||
|
|
||||||
/**
|
/** @var string Debug file location (log to STDOUT by default) */
|
||||||
* Debug file location (log to STDOUT by default)
|
|
||||||
*/
|
|
||||||
public static $debug_file = 'php://output';
|
public static $debug_file = 'php://output';
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -63,4 +51,3 @@ class Configuration {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,28 +22,35 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace SwaggerClient\models;
|
namespace Swagger\Client\Model;
|
||||||
|
|
||||||
use \ArrayAccess;
|
use \ArrayAccess;
|
||||||
|
|
||||||
class Category implements ArrayAccess {
|
class Category implements ArrayAccess {
|
||||||
|
/** @var string[] Array of property to type mappings. Used for (de)serialization */
|
||||||
static $swaggerTypes = array(
|
static $swaggerTypes = array(
|
||||||
'id' => 'int',
|
'id' => 'int',
|
||||||
'name' => 'string'
|
'name' => 'string'
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/** @var string[] Array of attributes where the key is the local name, and the value is the original name */
|
||||||
static $attributeMap = array(
|
static $attributeMap = array(
|
||||||
'id' => 'id',
|
'id' => 'id',
|
||||||
'name' => 'name'
|
'name' => 'name'
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/** @var int $id */
|
||||||
|
public $id;
|
||||||
|
|
||||||
public $id; /* int */
|
/** @var string $name */
|
||||||
public $name; /* string */
|
public $name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param mixed[] Array of parameters to initialize the object with
|
||||||
|
*/
|
||||||
public function __construct(array $data = null) {
|
public function __construct(array $data = null) {
|
||||||
$this->id = $data["id"];
|
$this->id = @$data["id"];
|
||||||
$this->name = $data["name"];
|
$this->name = @$data["name"];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function offsetExists($offset) {
|
public function offsetExists($offset) {
|
@ -22,20 +22,22 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace SwaggerClient\models;
|
namespace Swagger\Client\Model;
|
||||||
|
|
||||||
use \ArrayAccess;
|
use \ArrayAccess;
|
||||||
|
|
||||||
class Order implements ArrayAccess {
|
class Order implements ArrayAccess {
|
||||||
|
/** @var string[] Array of property to type mappings. Used for (de)serialization */
|
||||||
static $swaggerTypes = array(
|
static $swaggerTypes = array(
|
||||||
'id' => 'int',
|
'id' => 'int',
|
||||||
'pet_id' => 'int',
|
'pet_id' => 'int',
|
||||||
'quantity' => 'int',
|
'quantity' => 'int',
|
||||||
'ship_date' => 'DateTime',
|
'ship_date' => '\DateTime',
|
||||||
'status' => 'string',
|
'status' => 'string',
|
||||||
'complete' => 'boolean'
|
'complete' => 'bool'
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/** @var string[] Array of attributes where the key is the local name, and the value is the original name */
|
||||||
static $attributeMap = array(
|
static $attributeMap = array(
|
||||||
'id' => 'id',
|
'id' => 'id',
|
||||||
'pet_id' => 'petId',
|
'pet_id' => 'petId',
|
||||||
@ -45,24 +47,34 @@ class Order implements ArrayAccess {
|
|||||||
'complete' => 'complete'
|
'complete' => 'complete'
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/** @var int $id */
|
||||||
|
public $id;
|
||||||
|
|
||||||
|
/** @var int $pet_id */
|
||||||
|
public $pet_id;
|
||||||
|
|
||||||
|
/** @var int $quantity */
|
||||||
|
public $quantity;
|
||||||
|
|
||||||
|
/** @var \DateTime $ship_date */
|
||||||
|
public $ship_date;
|
||||||
|
|
||||||
|
/** @var string $status Order Status */
|
||||||
|
public $status;
|
||||||
|
|
||||||
|
/** @var bool $complete */
|
||||||
|
public $complete;
|
||||||
|
|
||||||
public $id; /* int */
|
|
||||||
public $pet_id; /* int */
|
|
||||||
public $quantity; /* int */
|
|
||||||
public $ship_date; /* DateTime */
|
|
||||||
/**
|
/**
|
||||||
* Order Status
|
* @param mixed[] Array of parameters to initialize the object with
|
||||||
*/
|
*/
|
||||||
public $status; /* string */
|
|
||||||
public $complete; /* boolean */
|
|
||||||
|
|
||||||
public function __construct(array $data = null) {
|
public function __construct(array $data = null) {
|
||||||
$this->id = $data["id"];
|
$this->id = @$data["id"];
|
||||||
$this->pet_id = $data["pet_id"];
|
$this->pet_id = @$data["pet_id"];
|
||||||
$this->quantity = $data["quantity"];
|
$this->quantity = @$data["quantity"];
|
||||||
$this->ship_date = $data["ship_date"];
|
$this->ship_date = @$data["ship_date"];
|
||||||
$this->status = $data["status"];
|
$this->status = @$data["status"];
|
||||||
$this->complete = $data["complete"];
|
$this->complete = @$data["complete"];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function offsetExists($offset) {
|
public function offsetExists($offset) {
|
@ -22,20 +22,22 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace SwaggerClient\models;
|
namespace Swagger\Client\Model;
|
||||||
|
|
||||||
use \ArrayAccess;
|
use \ArrayAccess;
|
||||||
|
|
||||||
class Pet implements ArrayAccess {
|
class Pet implements ArrayAccess {
|
||||||
|
/** @var string[] Array of property to type mappings. Used for (de)serialization */
|
||||||
static $swaggerTypes = array(
|
static $swaggerTypes = array(
|
||||||
'id' => 'int',
|
'id' => 'int',
|
||||||
'category' => 'Category',
|
'category' => '\Swagger\Client\Model\Category',
|
||||||
'name' => 'string',
|
'name' => 'string',
|
||||||
'photo_urls' => 'array[string]',
|
'photo_urls' => 'string[]',
|
||||||
'tags' => 'array[Tag]',
|
'tags' => '\Swagger\Client\Model\Tag[]',
|
||||||
'status' => 'string'
|
'status' => 'string'
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/** @var string[] Array of attributes where the key is the local name, and the value is the original name */
|
||||||
static $attributeMap = array(
|
static $attributeMap = array(
|
||||||
'id' => 'id',
|
'id' => 'id',
|
||||||
'category' => 'category',
|
'category' => 'category',
|
||||||
@ -45,24 +47,34 @@ class Pet implements ArrayAccess {
|
|||||||
'status' => 'status'
|
'status' => 'status'
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/** @var int $id */
|
||||||
|
public $id;
|
||||||
|
|
||||||
|
/** @var \Swagger\Client\Model\Category $category */
|
||||||
|
public $category;
|
||||||
|
|
||||||
|
/** @var string $name */
|
||||||
|
public $name;
|
||||||
|
|
||||||
|
/** @var string[] $photo_urls */
|
||||||
|
public $photo_urls;
|
||||||
|
|
||||||
|
/** @var \Swagger\Client\Model\Tag[] $tags */
|
||||||
|
public $tags;
|
||||||
|
|
||||||
|
/** @var string $status pet status in the store */
|
||||||
|
public $status;
|
||||||
|
|
||||||
public $id; /* int */
|
|
||||||
public $category; /* Category */
|
|
||||||
public $name; /* string */
|
|
||||||
public $photo_urls; /* array[string] */
|
|
||||||
public $tags; /* array[Tag] */
|
|
||||||
/**
|
/**
|
||||||
* pet status in the store
|
* @param mixed[] Array of parameters to initialize the object with
|
||||||
*/
|
*/
|
||||||
public $status; /* string */
|
|
||||||
|
|
||||||
public function __construct(array $data = null) {
|
public function __construct(array $data = null) {
|
||||||
$this->id = $data["id"];
|
$this->id = @$data["id"];
|
||||||
$this->category = $data["category"];
|
$this->category = @$data["category"];
|
||||||
$this->name = $data["name"];
|
$this->name = @$data["name"];
|
||||||
$this->photo_urls = $data["photo_urls"];
|
$this->photo_urls = @$data["photo_urls"];
|
||||||
$this->tags = $data["tags"];
|
$this->tags = @$data["tags"];
|
||||||
$this->status = $data["status"];
|
$this->status = @$data["status"];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function offsetExists($offset) {
|
public function offsetExists($offset) {
|
@ -22,28 +22,35 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace SwaggerClient\models;
|
namespace Swagger\Client\Model;
|
||||||
|
|
||||||
use \ArrayAccess;
|
use \ArrayAccess;
|
||||||
|
|
||||||
class Tag implements ArrayAccess {
|
class Tag implements ArrayAccess {
|
||||||
|
/** @var string[] Array of property to type mappings. Used for (de)serialization */
|
||||||
static $swaggerTypes = array(
|
static $swaggerTypes = array(
|
||||||
'id' => 'int',
|
'id' => 'int',
|
||||||
'name' => 'string'
|
'name' => 'string'
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/** @var string[] Array of attributes where the key is the local name, and the value is the original name */
|
||||||
static $attributeMap = array(
|
static $attributeMap = array(
|
||||||
'id' => 'id',
|
'id' => 'id',
|
||||||
'name' => 'name'
|
'name' => 'name'
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/** @var int $id */
|
||||||
|
public $id;
|
||||||
|
|
||||||
public $id; /* int */
|
/** @var string $name */
|
||||||
public $name; /* string */
|
public $name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param mixed[] Array of parameters to initialize the object with
|
||||||
|
*/
|
||||||
public function __construct(array $data = null) {
|
public function __construct(array $data = null) {
|
||||||
$this->id = $data["id"];
|
$this->id = @$data["id"];
|
||||||
$this->name = $data["name"];
|
$this->name = @$data["name"];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function offsetExists($offset) {
|
public function offsetExists($offset) {
|
@ -22,11 +22,12 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace SwaggerClient\models;
|
namespace Swagger\Client\Model;
|
||||||
|
|
||||||
use \ArrayAccess;
|
use \ArrayAccess;
|
||||||
|
|
||||||
class User implements ArrayAccess {
|
class User implements ArrayAccess {
|
||||||
|
/** @var string[] Array of property to type mappings. Used for (de)serialization */
|
||||||
static $swaggerTypes = array(
|
static $swaggerTypes = array(
|
||||||
'id' => 'int',
|
'id' => 'int',
|
||||||
'username' => 'string',
|
'username' => 'string',
|
||||||
@ -38,6 +39,7 @@ class User implements ArrayAccess {
|
|||||||
'user_status' => 'int'
|
'user_status' => 'int'
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/** @var string[] Array of attributes where the key is the local name, and the value is the original name */
|
||||||
static $attributeMap = array(
|
static $attributeMap = array(
|
||||||
'id' => 'id',
|
'id' => 'id',
|
||||||
'username' => 'username',
|
'username' => 'username',
|
||||||
@ -49,28 +51,42 @@ class User implements ArrayAccess {
|
|||||||
'user_status' => 'userStatus'
|
'user_status' => 'userStatus'
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/** @var int $id */
|
||||||
|
public $id;
|
||||||
|
|
||||||
|
/** @var string $username */
|
||||||
|
public $username;
|
||||||
|
|
||||||
|
/** @var string $first_name */
|
||||||
|
public $first_name;
|
||||||
|
|
||||||
|
/** @var string $last_name */
|
||||||
|
public $last_name;
|
||||||
|
|
||||||
|
/** @var string $email */
|
||||||
|
public $email;
|
||||||
|
|
||||||
|
/** @var string $password */
|
||||||
|
public $password;
|
||||||
|
|
||||||
|
/** @var string $phone */
|
||||||
|
public $phone;
|
||||||
|
|
||||||
|
/** @var int $user_status User Status */
|
||||||
|
public $user_status;
|
||||||
|
|
||||||
public $id; /* int */
|
|
||||||
public $username; /* string */
|
|
||||||
public $first_name; /* string */
|
|
||||||
public $last_name; /* string */
|
|
||||||
public $email; /* string */
|
|
||||||
public $password; /* string */
|
|
||||||
public $phone; /* string */
|
|
||||||
/**
|
/**
|
||||||
* User Status
|
* @param mixed[] Array of parameters to initialize the object with
|
||||||
*/
|
*/
|
||||||
public $user_status; /* int */
|
|
||||||
|
|
||||||
public function __construct(array $data = null) {
|
public function __construct(array $data = null) {
|
||||||
$this->id = $data["id"];
|
$this->id = @$data["id"];
|
||||||
$this->username = $data["username"];
|
$this->username = @$data["username"];
|
||||||
$this->first_name = $data["first_name"];
|
$this->first_name = @$data["first_name"];
|
||||||
$this->last_name = $data["last_name"];
|
$this->last_name = @$data["last_name"];
|
||||||
$this->email = $data["email"];
|
$this->email = @$data["email"];
|
||||||
$this->password = $data["password"];
|
$this->password = @$data["password"];
|
||||||
$this->phone = $data["phone"];
|
$this->phone = @$data["phone"];
|
||||||
$this->user_status = $data["user_status"];
|
$this->user_status = @$data["user_status"];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function offsetExists($offset) {
|
public function offsetExists($offset) {
|
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
require_once('SwaggerClient.php');
|
require_once('autoload.php');
|
||||||
|
|
||||||
class PetApiTest extends \PHPUnit_Framework_TestCase
|
class PetApiTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
@ -15,28 +15,28 @@ class PetApiTest extends \PHPUnit_Framework_TestCase
|
|||||||
error_reporting(-1);
|
error_reporting(-1);
|
||||||
|
|
||||||
// enable debugging
|
// enable debugging
|
||||||
//SwaggerClient\Configuration::$debug = true;
|
//Swagger\Client\Configuration::$debug = true;
|
||||||
|
|
||||||
// skip initializing the API client as it should be automatic
|
// skip initializing the API client as it should be automatic
|
||||||
//$api_client = new SwaggerClient\ApiClient('http://petstore.swagger.io/v2');
|
//$api_client = new Swagger\Client\ApiClient('http://petstore.swagger.io/v2');
|
||||||
// new pet
|
// new pet
|
||||||
$new_pet_id = 10005;
|
$new_pet_id = 10005;
|
||||||
$new_pet = new SwaggerClient\models\Pet;
|
$new_pet = new Swagger\Client\Model\Pet;
|
||||||
$new_pet->id = $new_pet_id;
|
$new_pet->id = $new_pet_id;
|
||||||
$new_pet->name = "PHP Unit Test";
|
$new_pet->name = "PHP Unit Test";
|
||||||
// new tag
|
// new tag
|
||||||
$tag= new SwaggerClient\models\Tag;
|
$tag= new Swagger\Client\Model\Tag;
|
||||||
$tag->id = $new_pet_id; // use the same id as pet
|
$tag->id = $new_pet_id; // use the same id as pet
|
||||||
$tag->name = "test php tag";
|
$tag->name = "test php tag";
|
||||||
// new category
|
// new category
|
||||||
$category = new SwaggerClient\models\Category;
|
$category = new Swagger\Client\Model\Category;
|
||||||
$category->id = $new_pet_id; // use the same id as pet
|
$category->id = $new_pet_id; // use the same id as pet
|
||||||
$category->name = "test php category";
|
$category->name = "test php category";
|
||||||
|
|
||||||
$new_pet->tags = array($tag);
|
$new_pet->tags = array($tag);
|
||||||
$new_pet->category = $category;
|
$new_pet->category = $category;
|
||||||
|
|
||||||
$pet_api = new SwaggerClient\PetAPI();
|
$pet_api = new Swagger\Client\Api\PetAPI();
|
||||||
// add a new pet (model)
|
// add a new pet (model)
|
||||||
$add_response = $pet_api->addPet($new_pet);
|
$add_response = $pet_api->addPet($new_pet);
|
||||||
}
|
}
|
||||||
@ -45,7 +45,7 @@ class PetApiTest extends \PHPUnit_Framework_TestCase
|
|||||||
public function testApiClient()
|
public function testApiClient()
|
||||||
{
|
{
|
||||||
// test selectHeaderAccept
|
// test selectHeaderAccept
|
||||||
$api_client = new SwaggerClient\ApiClient();
|
$api_client = new Swagger\Client\ApiClient();
|
||||||
$this->assertSame('application/json', $api_client->selectHeaderAccept(array('application/xml','application/json')));
|
$this->assertSame('application/json', $api_client->selectHeaderAccept(array('application/xml','application/json')));
|
||||||
$this->assertSame(NULL, $api_client->selectHeaderAccept(array()));
|
$this->assertSame(NULL, $api_client->selectHeaderAccept(array()));
|
||||||
$this->assertSame('application/yaml,application/xml', $api_client->selectHeaderAccept(array('application/yaml','application/xml')));
|
$this->assertSame('application/yaml,application/xml', $api_client->selectHeaderAccept(array('application/yaml','application/xml')));
|
||||||
@ -67,22 +67,22 @@ class PetApiTest extends \PHPUnit_Framework_TestCase
|
|||||||
$defaultHeader = $api_client->getDefaultHeader();
|
$defaultHeader = $api_client->getDefaultHeader();
|
||||||
$this->assertFalse(isset($defaultHeader['test2']));
|
$this->assertFalse(isset($defaultHeader['test2']));
|
||||||
|
|
||||||
$pet_api = new SwaggerClient\PetAPI();
|
$pet_api = new Swagger\Client\Api\PetAPI();
|
||||||
$pet_api2 = new SwaggerClient\PetAPI();
|
$pet_api2 = new Swagger\Client\Api\PetAPI();
|
||||||
$apiClient3 = new SwaggerClient\ApiClient();
|
$apiClient3 = new Swagger\Client\ApiClient();
|
||||||
$apiClient3->setUserAgent = 'api client 3';
|
$apiClient3->setUserAgent = 'api client 3';
|
||||||
$apiClient4 = new SwaggerClient\ApiClient();
|
$apiClient4 = new Swagger\Client\ApiClient();
|
||||||
$apiClient4->setUserAgent = 'api client 4';
|
$apiClient4->setUserAgent = 'api client 4';
|
||||||
$pet_api3 = new SwaggerClient\PetAPI($apiClient3);
|
$pet_api3 = new Swagger\Client\Api\PetAPI($apiClient3);
|
||||||
|
|
||||||
// same default api client
|
// same default api client
|
||||||
$this->assertSame($pet_api->getApiClient(), $pet_api2->getApiClient());
|
$this->assertSame($pet_api->getApiClient(), $pet_api2->getApiClient());
|
||||||
// confirm using the default api client in the Configuration
|
// confirm using the default api client in the Configuration
|
||||||
$this->assertSame($pet_api->getApiClient(), SwaggerClient\Configuration::$apiClient);
|
$this->assertSame($pet_api->getApiClient(), Swagger\Client\Configuration::$apiClient);
|
||||||
// 2 different api clients are not the same
|
// 2 different api clients are not the same
|
||||||
$this->assertNotEquals($apiClient3, $apiClient4);
|
$this->assertNotEquals($apiClient3, $apiClient4);
|
||||||
// customized pet api not using the default (configuration) api client
|
// customized pet api not using the default (configuration) api client
|
||||||
$this->assertNotEquals($pet_api3->getApiClient(), SwaggerClient\Configuration::$apiClient);
|
$this->assertNotEquals($pet_api3->getApiClient(), Swagger\Client\Configuration::$apiClient);
|
||||||
// customied pet api not using the old pet api's api client
|
// customied pet api not using the old pet api's api client
|
||||||
$this->assertNotEquals($pet_api2->getApiClient(), $pet_api3->getApiClient());
|
$this->assertNotEquals($pet_api2->getApiClient(), $pet_api3->getApiClient());
|
||||||
|
|
||||||
@ -96,10 +96,10 @@ class PetApiTest extends \PHPUnit_Framework_TestCase
|
|||||||
public function testGetPetById()
|
public function testGetPetById()
|
||||||
{
|
{
|
||||||
// initialize the API client without host
|
// initialize the API client without host
|
||||||
$api_client = new SwaggerClient\ApiClient();
|
$api_client = new Swagger\Client\ApiClient();
|
||||||
SwaggerClient\Configuration::$apiKey['api_key'] = '111222333444555';
|
Swagger\Client\Configuration::$apiKey['api_key'] = '111222333444555';
|
||||||
$pet_id = 10005; // ID of pet that needs to be fetched
|
$pet_id = 10005; // ID of pet that needs to be fetched
|
||||||
$pet_api = new SwaggerClient\PetAPI($api_client);
|
$pet_api = new Swagger\Client\Api\PetAPI($api_client);
|
||||||
// return Pet (model)
|
// return Pet (model)
|
||||||
$response = $pet_api->getPetById($pet_id);
|
$response = $pet_api->getPetById($pet_id);
|
||||||
$this->assertSame($response->id, $pet_id);
|
$this->assertSame($response->id, $pet_id);
|
||||||
@ -114,12 +114,12 @@ class PetApiTest extends \PHPUnit_Framework_TestCase
|
|||||||
public function testFindPetByStatus()
|
public function testFindPetByStatus()
|
||||||
{
|
{
|
||||||
// initialize the API client
|
// initialize the API client
|
||||||
$api_client = new SwaggerClient\ApiClient('http://petstore.swagger.io/v2');
|
$api_client = new Swagger\Client\ApiClient('http://petstore.swagger.io/v2');
|
||||||
$pet_api = new SwaggerClient\PetAPI($api_client);
|
$pet_api = new Swagger\Client\Api\PetAPI($api_client);
|
||||||
// return Pet (model)
|
// return Pet (model)
|
||||||
$response = $pet_api->findPetsByStatus("available");
|
$response = $pet_api->findPetsByStatus("available");
|
||||||
$this->assertGreaterThan(0, count($response)); // at least one object returned
|
$this->assertGreaterThan(0, count($response)); // at least one object returned
|
||||||
$this->assertSame(get_class($response[0]), "SwaggerClient\models\Pet"); // verify the object is Pet
|
$this->assertSame(get_class($response[0]), "Swagger\\Client\\Model\\Pet"); // verify the object is Pet
|
||||||
// loop through result to ensure status is "available"
|
// loop through result to ensure status is "available"
|
||||||
foreach ($response as $_pet) {
|
foreach ($response as $_pet) {
|
||||||
$this->assertSame($_pet['status'], "available");
|
$this->assertSame($_pet['status'], "available");
|
||||||
@ -133,11 +133,11 @@ class PetApiTest extends \PHPUnit_Framework_TestCase
|
|||||||
public function testUpdatePet()
|
public function testUpdatePet()
|
||||||
{
|
{
|
||||||
// initialize the API client
|
// initialize the API client
|
||||||
$api_client = new SwaggerClient\ApiClient('http://petstore.swagger.io/v2');
|
$api_client = new Swagger\Client\ApiClient('http://petstore.swagger.io/v2');
|
||||||
$pet_id = 10001; // ID of pet that needs to be fetched
|
$pet_id = 10001; // ID of pet that needs to be fetched
|
||||||
$pet_api = new SwaggerClient\PetAPI($api_client);
|
$pet_api = new Swagger\Client\Api\PetAPI($api_client);
|
||||||
// create updated pet object
|
// create updated pet object
|
||||||
$updated_pet = new SwaggerClient\models\Pet;
|
$updated_pet = new Swagger\Client\Model\Pet;
|
||||||
$updated_pet->id = $pet_id;
|
$updated_pet->id = $pet_id;
|
||||||
$updated_pet->name = 'updatePet'; // new name
|
$updated_pet->name = 'updatePet'; // new name
|
||||||
$updated_pet->status = 'pending'; // new status
|
$updated_pet->status = 'pending'; // new status
|
||||||
@ -156,9 +156,9 @@ class PetApiTest extends \PHPUnit_Framework_TestCase
|
|||||||
public function testUpdatePetWithForm()
|
public function testUpdatePetWithForm()
|
||||||
{
|
{
|
||||||
// initialize the API client
|
// initialize the API client
|
||||||
$api_client = new SwaggerClient\ApiClient('http://petstore.swagger.io/v2');
|
$api_client = new Swagger\Client\ApiClient('http://petstore.swagger.io/v2');
|
||||||
$pet_id = 10001; // ID of pet that needs to be fetched
|
$pet_id = 10001; // ID of pet that needs to be fetched
|
||||||
$pet_api = new SwaggerClient\PetAPI($api_client);
|
$pet_api = new Swagger\Client\Api\PetAPI($api_client);
|
||||||
// update Pet (form)
|
// update Pet (form)
|
||||||
$update_response = $pet_api->updatePetWithForm($pet_id, 'update pet with form', 'sold');
|
$update_response = $pet_api->updatePetWithForm($pet_id, 'update pet with form', 'sold');
|
||||||
// return nothing (void)
|
// return nothing (void)
|
||||||
@ -173,12 +173,12 @@ class PetApiTest extends \PHPUnit_Framework_TestCase
|
|||||||
public function testAddPet()
|
public function testAddPet()
|
||||||
{
|
{
|
||||||
// initialize the API client
|
// initialize the API client
|
||||||
$api_client = new SwaggerClient\ApiClient('http://petstore.swagger.io/v2');
|
$api_client = new Swagger\Client\ApiClient('http://petstore.swagger.io/v2');
|
||||||
$new_pet_id = 10001;
|
$new_pet_id = 10001;
|
||||||
$new_pet = new SwaggerClient\models\Pet;
|
$new_pet = new Swagger\Client\Model\Pet;
|
||||||
$new_pet->id = $new_pet_id;
|
$new_pet->id = $new_pet_id;
|
||||||
$new_pet->name = "PHP Unit Test";
|
$new_pet->name = "PHP Unit Test";
|
||||||
$pet_api = new SwaggerClient\PetAPI($api_client);
|
$pet_api = new Swagger\Client\Api\PetAPI($api_client);
|
||||||
// add a new pet (model)
|
// add a new pet (model)
|
||||||
$add_response = $pet_api->addPet($new_pet);
|
$add_response = $pet_api->addPet($new_pet);
|
||||||
// return nothing (void)
|
// return nothing (void)
|
||||||
@ -193,8 +193,8 @@ class PetApiTest extends \PHPUnit_Framework_TestCase
|
|||||||
public function testUploadFile()
|
public function testUploadFile()
|
||||||
{
|
{
|
||||||
// initialize the API client
|
// initialize the API client
|
||||||
$api_client = new SwaggerClient\ApiClient('http://petstore.swagger.io/v2');
|
$api_client = new Swagger\Client\ApiClient('http://petstore.swagger.io/v2');
|
||||||
$pet_api = new SwaggerClient\PetAPI($api_client);
|
$pet_api = new Swagger\Client\Api\PetAPI($api_client);
|
||||||
// upload file
|
// upload file
|
||||||
$pet_id = 10001;
|
$pet_id = 10001;
|
||||||
$add_response = $pet_api->uploadFile($pet_id, "test meta", "./composer.json");
|
$add_response = $pet_api->uploadFile($pet_id, "test meta", "./composer.json");
|
||||||
@ -206,8 +206,8 @@ class PetApiTest extends \PHPUnit_Framework_TestCase
|
|||||||
public function testGetInventory()
|
public function testGetInventory()
|
||||||
{
|
{
|
||||||
// initialize the API client
|
// initialize the API client
|
||||||
$api_client = new SwaggerClient\APIClient('http://petstore.swagger.io/v2');
|
$api_client = new Swagger\Client\APIClient('http://petstore.swagger.io/v2');
|
||||||
$store_api = new SwaggerClient\StoreAPI($api_client);
|
$store_api = new Swagger\Client\Api\StoreAPI($api_client);
|
||||||
// get inventory
|
// get inventory
|
||||||
$get_response = $store_api->getInventory();
|
$get_response = $store_api->getInventory();
|
||||||
|
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
//require_once('vendor/autoload.php');
|
require_once(__DIR__ . '/SwaggerClient-php/autoload.php');
|
||||||
require_once('SwaggerClient-php/SwaggerClient.php');
|
|
||||||
|
|
||||||
// show error reporting
|
// show error reporting
|
||||||
//ini_set('display_errors', 1);
|
//ini_set('display_errors', 1);
|
||||||
@ -18,7 +17,7 @@ $petId = 10005; // ID of pet that needs to be fetched
|
|||||||
try {
|
try {
|
||||||
// get pet by id
|
// get pet by id
|
||||||
//$pet_api = new SwaggerClient\PetAPI($api_client);
|
//$pet_api = new SwaggerClient\PetAPI($api_client);
|
||||||
$pet_api = new SwaggerClient\PetAPI();
|
$pet_api = new Swagger\Client\Api\PetAPI();
|
||||||
// test default header
|
// test default header
|
||||||
$pet_api->getApiClient()->addDefaultHeader("TEST_API_KEY", "09182sdkanafndsl903");
|
$pet_api->getApiClient()->addDefaultHeader("TEST_API_KEY", "09182sdkanafndsl903");
|
||||||
// return Pet (model)
|
// return Pet (model)
|
||||||
@ -28,34 +27,31 @@ try {
|
|||||||
|
|
||||||
// add pet (post json)
|
// add pet (post json)
|
||||||
$new_pet_id = 10005;
|
$new_pet_id = 10005;
|
||||||
$new_pet = new SwaggerClient\models\Pet;
|
$new_pet = new Swagger\Client\Model\Pet;
|
||||||
$new_pet->id = $new_pet_id;
|
$new_pet->id = $new_pet_id;
|
||||||
$new_pet->name = "PHP Unit Test";
|
$new_pet->name = "PHP Unit Test";
|
||||||
// new tag
|
// new tag
|
||||||
$tag= new SwaggerClient\models\Tag;
|
$tag= new Swagger\Client\Model\Tag;
|
||||||
$tag->id = $new_pet_id; // use the same id as pet
|
$tag->id = $new_pet_id; // use the same id as pet
|
||||||
//$tag->name = "test php tag";
|
//$tag->name = "test php tag";
|
||||||
// new category
|
// new category
|
||||||
$category = new SwaggerClient\models\Category;
|
$category = new Swagger\Client\Model\Category;
|
||||||
$category->id = 0; // use the same id as pet
|
$category->id = 0; // use the same id as pet
|
||||||
//$category->name = "test php category";
|
//$category->name = "test php category";
|
||||||
|
|
||||||
$new_pet->tags = array($tag);
|
$new_pet->tags = array($tag);
|
||||||
$new_pet->category = $category;
|
$new_pet->category = $category;
|
||||||
|
|
||||||
$pet_api = new SwaggerClient\PetAPI();
|
$pet_api = new Swagger\Client\Api\PetAPI();
|
||||||
// add a new pet (model)
|
// add a new pet (model)
|
||||||
$add_response = $pet_api->addPet($new_pet);
|
$add_response = $pet_api->addPet($new_pet);
|
||||||
|
|
||||||
// test upload file (exception)
|
// test upload file (exception)
|
||||||
$upload_response = $pet_api->uploadFile($petId, "test meta", NULL);
|
$upload_response = $pet_api->uploadFile($petId, "test meta", NULL);
|
||||||
|
|
||||||
} catch (Exception $e) {
|
} catch (Swagger\Client\Exception $e) {
|
||||||
echo 'Caught exception: ', $e->getMessage(), "\n";
|
echo 'Caught exception: ', $e->getMessage(), "\n";
|
||||||
echo 'HTTP response headers: ', $e->getResponseHeaders(), "\n";
|
echo 'HTTP response headers: ', $e->getResponseHeaders(), "\n";
|
||||||
echo 'HTTP response body: ', $e->getResponseBody(), "\n";
|
echo 'HTTP response body: ', $e->getResponseBody(), "\n";
|
||||||
echo 'HTTP status code: ', $e->getCode(), "\n";
|
echo 'HTTP status code: ', $e->getCode(), "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
?>
|
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
require 'swagger_client/monkey'
|
require 'swagger_client/monkey'
|
||||||
require 'swagger_client/swagger'
|
require 'swagger_client/swagger'
|
||||||
require 'swagger_client/swagger/configuration'
|
require 'swagger_client/swagger/configuration'
|
||||||
|
require 'swagger_client/swagger/api_error'
|
||||||
require 'swagger_client/swagger/request'
|
require 'swagger_client/swagger/request'
|
||||||
require 'swagger_client/swagger/response'
|
require 'swagger_client/swagger/response'
|
||||||
require 'swagger_client/swagger/version'
|
require 'swagger_client/swagger/version'
|
||||||
@ -16,8 +17,8 @@ require 'swagger_client/models/order'
|
|||||||
|
|
||||||
# APIs
|
# APIs
|
||||||
require 'swagger_client/api/user_api'
|
require 'swagger_client/api/user_api'
|
||||||
require 'swagger_client/api/store_api'
|
|
||||||
require 'swagger_client/api/pet_api'
|
require 'swagger_client/api/pet_api'
|
||||||
|
require 'swagger_client/api/store_api'
|
||||||
|
|
||||||
module SwaggerClient
|
module SwaggerClient
|
||||||
# Initialize the default configuration
|
# Initialize the default configuration
|
||||||
|
@ -82,8 +82,8 @@ module SwaggerClient
|
|||||||
# Finds Pets by status
|
# Finds Pets by status
|
||||||
# Multiple status values can be provided with comma seperated strings
|
# Multiple status values can be provided with comma seperated strings
|
||||||
# @param [Hash] opts the optional parameters
|
# @param [Hash] opts the optional parameters
|
||||||
# @option opts [array[string]] :status Status values that need to be considered for filter
|
# @option opts [Array<String>] :status Status values that need to be considered for filter
|
||||||
# @return [array[Pet]]
|
# @return [Array<Pet>]
|
||||||
def self.find_pets_by_status(opts = {})
|
def self.find_pets_by_status(opts = {})
|
||||||
|
|
||||||
|
|
||||||
@ -113,15 +113,15 @@ module SwaggerClient
|
|||||||
|
|
||||||
|
|
||||||
auth_names = ['petstore_auth']
|
auth_names = ['petstore_auth']
|
||||||
response = Swagger::Request.new(:GET, path, {:params => query_params, :headers => header_params, :form_params => form_params, :body => post_body, :auth_names => auth_names}).make.body
|
response = Swagger::Request.new(:GET, path, {:params => query_params, :headers => header_params, :form_params => form_params, :body => post_body, :auth_names => auth_names}).make
|
||||||
response.map {|response| obj = Pet.new() and obj.build_from_hash(response) }
|
response.deserialize('Array<Pet>')
|
||||||
end
|
end
|
||||||
|
|
||||||
# Finds Pets by tags
|
# Finds Pets by tags
|
||||||
# Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing.
|
# Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing.
|
||||||
# @param [Hash] opts the optional parameters
|
# @param [Hash] opts the optional parameters
|
||||||
# @option opts [array[string]] :tags Tags to filter by
|
# @option opts [Array<String>] :tags Tags to filter by
|
||||||
# @return [array[Pet]]
|
# @return [Array<Pet>]
|
||||||
def self.find_pets_by_tags(opts = {})
|
def self.find_pets_by_tags(opts = {})
|
||||||
|
|
||||||
|
|
||||||
@ -151,8 +151,8 @@ module SwaggerClient
|
|||||||
|
|
||||||
|
|
||||||
auth_names = ['petstore_auth']
|
auth_names = ['petstore_auth']
|
||||||
response = Swagger::Request.new(:GET, path, {:params => query_params, :headers => header_params, :form_params => form_params, :body => post_body, :auth_names => auth_names}).make.body
|
response = Swagger::Request.new(:GET, path, {:params => query_params, :headers => header_params, :form_params => form_params, :body => post_body, :auth_names => auth_names}).make
|
||||||
response.map {|response| obj = Pet.new() and obj.build_from_hash(response) }
|
response.deserialize('Array<Pet>')
|
||||||
end
|
end
|
||||||
|
|
||||||
# Find pet by ID
|
# Find pet by ID
|
||||||
@ -190,17 +190,17 @@ module SwaggerClient
|
|||||||
post_body = nil
|
post_body = nil
|
||||||
|
|
||||||
|
|
||||||
auth_names = ['petstore_auth', 'api_key']
|
auth_names = ['api_key', 'petstore_auth']
|
||||||
response = Swagger::Request.new(:GET, path, {:params => query_params, :headers => header_params, :form_params => form_params, :body => post_body, :auth_names => auth_names}).make.body
|
response = Swagger::Request.new(:GET, path, {:params => query_params, :headers => header_params, :form_params => form_params, :body => post_body, :auth_names => auth_names}).make
|
||||||
obj = Pet.new() and obj.build_from_hash(response)
|
response.deserialize('Pet')
|
||||||
end
|
end
|
||||||
|
|
||||||
# Updates a pet in the store with form data
|
# Updates a pet in the store with form data
|
||||||
#
|
#
|
||||||
# @param pet_id ID of pet that needs to be updated
|
# @param pet_id ID of pet that needs to be updated
|
||||||
# @param [Hash] opts the optional parameters
|
# @param [Hash] opts the optional parameters
|
||||||
# @option opts [string] :name Updated name of the pet
|
# @option opts [String] :name Updated name of the pet
|
||||||
# @option opts [string] :status Updated status of the pet
|
# @option opts [String] :status Updated status of the pet
|
||||||
# @return [nil]
|
# @return [nil]
|
||||||
def self.update_pet_with_form(pet_id, opts = {})
|
def self.update_pet_with_form(pet_id, opts = {})
|
||||||
|
|
||||||
@ -243,7 +243,7 @@ module SwaggerClient
|
|||||||
#
|
#
|
||||||
# @param pet_id Pet id to delete
|
# @param pet_id Pet id to delete
|
||||||
# @param [Hash] opts the optional parameters
|
# @param [Hash] opts the optional parameters
|
||||||
# @option opts [string] :api_key
|
# @option opts [String] :api_key
|
||||||
# @return [nil]
|
# @return [nil]
|
||||||
def self.delete_pet(pet_id, opts = {})
|
def self.delete_pet(pet_id, opts = {})
|
||||||
|
|
||||||
@ -285,7 +285,7 @@ module SwaggerClient
|
|||||||
#
|
#
|
||||||
# @param pet_id ID of pet to update
|
# @param pet_id ID of pet to update
|
||||||
# @param [Hash] opts the optional parameters
|
# @param [Hash] opts the optional parameters
|
||||||
# @option opts [string] :additional_metadata Additional data to pass to server
|
# @option opts [String] :additional_metadata Additional data to pass to server
|
||||||
# @option opts [file] :file file to upload
|
# @option opts [file] :file file to upload
|
||||||
# @return [nil]
|
# @return [nil]
|
||||||
def self.upload_file(pet_id, opts = {})
|
def self.upload_file(pet_id, opts = {})
|
||||||
|
@ -8,7 +8,7 @@ module SwaggerClient
|
|||||||
# Returns pet inventories by status
|
# Returns pet inventories by status
|
||||||
# Returns a map of status codes to quantities
|
# Returns a map of status codes to quantities
|
||||||
# @param [Hash] opts the optional parameters
|
# @param [Hash] opts the optional parameters
|
||||||
# @return [map[string,int]]
|
# @return [Hash<String, Integer>]
|
||||||
def self.get_inventory(opts = {})
|
def self.get_inventory(opts = {})
|
||||||
|
|
||||||
|
|
||||||
@ -37,8 +37,8 @@ module SwaggerClient
|
|||||||
|
|
||||||
|
|
||||||
auth_names = ['api_key']
|
auth_names = ['api_key']
|
||||||
response = Swagger::Request.new(:GET, path, {:params => query_params, :headers => header_params, :form_params => form_params, :body => post_body, :auth_names => auth_names}).make.body
|
response = Swagger::Request.new(:GET, path, {:params => query_params, :headers => header_params, :form_params => form_params, :body => post_body, :auth_names => auth_names}).make
|
||||||
response.map {|response| obj = map.new() and obj.build_from_hash(response) }
|
response.deserialize('Hash<String, Integer>')
|
||||||
end
|
end
|
||||||
|
|
||||||
# Place an order for a pet
|
# Place an order for a pet
|
||||||
@ -74,8 +74,8 @@ module SwaggerClient
|
|||||||
|
|
||||||
|
|
||||||
auth_names = []
|
auth_names = []
|
||||||
response = Swagger::Request.new(:POST, path, {:params => query_params, :headers => header_params, :form_params => form_params, :body => post_body, :auth_names => auth_names}).make.body
|
response = Swagger::Request.new(:POST, path, {:params => query_params, :headers => header_params, :form_params => form_params, :body => post_body, :auth_names => auth_names}).make
|
||||||
obj = Order.new() and obj.build_from_hash(response)
|
response.deserialize('Order')
|
||||||
end
|
end
|
||||||
|
|
||||||
# Find purchase order by ID
|
# Find purchase order by ID
|
||||||
@ -114,8 +114,8 @@ module SwaggerClient
|
|||||||
|
|
||||||
|
|
||||||
auth_names = []
|
auth_names = []
|
||||||
response = Swagger::Request.new(:GET, path, {:params => query_params, :headers => header_params, :form_params => form_params, :body => post_body, :auth_names => auth_names}).make.body
|
response = Swagger::Request.new(:GET, path, {:params => query_params, :headers => header_params, :form_params => form_params, :body => post_body, :auth_names => auth_names}).make
|
||||||
obj = Order.new() and obj.build_from_hash(response)
|
response.deserialize('Order')
|
||||||
end
|
end
|
||||||
|
|
||||||
# Delete purchase order by ID
|
# Delete purchase order by ID
|
||||||
|
@ -45,7 +45,7 @@ module SwaggerClient
|
|||||||
# Creates list of users with given input array
|
# Creates list of users with given input array
|
||||||
#
|
#
|
||||||
# @param [Hash] opts the optional parameters
|
# @param [Hash] opts the optional parameters
|
||||||
# @option opts [array[User]] :body List of user object
|
# @option opts [Array<User>] :body List of user object
|
||||||
# @return [nil]
|
# @return [nil]
|
||||||
def self.create_users_with_array_input(opts = {})
|
def self.create_users_with_array_input(opts = {})
|
||||||
|
|
||||||
@ -82,7 +82,7 @@ module SwaggerClient
|
|||||||
# Creates list of users with given input array
|
# Creates list of users with given input array
|
||||||
#
|
#
|
||||||
# @param [Hash] opts the optional parameters
|
# @param [Hash] opts the optional parameters
|
||||||
# @option opts [array[User]] :body List of user object
|
# @option opts [Array<User>] :body List of user object
|
||||||
# @return [nil]
|
# @return [nil]
|
||||||
def self.create_users_with_list_input(opts = {})
|
def self.create_users_with_list_input(opts = {})
|
||||||
|
|
||||||
@ -119,9 +119,9 @@ module SwaggerClient
|
|||||||
# Logs user into the system
|
# Logs user into the system
|
||||||
#
|
#
|
||||||
# @param [Hash] opts the optional parameters
|
# @param [Hash] opts the optional parameters
|
||||||
# @option opts [string] :username The user name for login
|
# @option opts [String] :username The user name for login
|
||||||
# @option opts [string] :password The password for login in clear text
|
# @option opts [String] :password The password for login in clear text
|
||||||
# @return [string]
|
# @return [String]
|
||||||
def self.login_user(opts = {})
|
def self.login_user(opts = {})
|
||||||
|
|
||||||
|
|
||||||
@ -152,8 +152,8 @@ module SwaggerClient
|
|||||||
|
|
||||||
|
|
||||||
auth_names = []
|
auth_names = []
|
||||||
response = Swagger::Request.new(:GET, path, {:params => query_params, :headers => header_params, :form_params => form_params, :body => post_body, :auth_names => auth_names}).make.body
|
response = Swagger::Request.new(:GET, path, {:params => query_params, :headers => header_params, :form_params => form_params, :body => post_body, :auth_names => auth_names}).make
|
||||||
obj = string.new() and obj.build_from_hash(response)
|
response.deserialize('String')
|
||||||
end
|
end
|
||||||
|
|
||||||
# Logs out current logged in user session
|
# Logs out current logged in user session
|
||||||
@ -228,8 +228,8 @@ module SwaggerClient
|
|||||||
|
|
||||||
|
|
||||||
auth_names = []
|
auth_names = []
|
||||||
response = Swagger::Request.new(:GET, path, {:params => query_params, :headers => header_params, :form_params => form_params, :body => post_body, :auth_names => auth_names}).make.body
|
response = Swagger::Request.new(:GET, path, {:params => query_params, :headers => header_params, :form_params => form_params, :body => post_body, :auth_names => auth_names}).make
|
||||||
obj = User.new() and obj.build_from_hash(response)
|
response.deserialize('User')
|
||||||
end
|
end
|
||||||
|
|
||||||
# Updated user
|
# Updated user
|
||||||
|
@ -2,20 +2,11 @@ module SwaggerClient
|
|||||||
# base class containing fundamental method such as to_hash, build_from_hash and more
|
# base class containing fundamental method such as to_hash, build_from_hash and more
|
||||||
class BaseObject
|
class BaseObject
|
||||||
|
|
||||||
# return the object in the form of hash
|
|
||||||
def to_body
|
|
||||||
body = {}
|
|
||||||
self.class.attribute_map.each_pair do |key, value|
|
|
||||||
body[value] = self.send(key) unless self.send(key).nil?
|
|
||||||
end
|
|
||||||
body
|
|
||||||
end
|
|
||||||
|
|
||||||
# build the object from hash
|
# build the object from hash
|
||||||
def build_from_hash(attributes)
|
def build_from_hash(attributes)
|
||||||
return nil unless attributes.is_a?(Hash)
|
return nil unless attributes.is_a?(Hash)
|
||||||
self.class.swagger_types.each_pair do |key, type|
|
self.class.swagger_types.each_pair do |key, type|
|
||||||
if type =~ /^array\[(.*)\]/i
|
if type =~ /^Array<(.*)>/i
|
||||||
if attributes[self.class.attribute_map[key]].is_a?(Array)
|
if attributes[self.class.attribute_map[key]].is_a?(Array)
|
||||||
self.send("#{key}=", attributes[self.class.attribute_map[key]].map{ |v| _deserialize($1, v) } )
|
self.send("#{key}=", attributes[self.class.attribute_map[key]].map{ |v| _deserialize($1, v) } )
|
||||||
else
|
else
|
||||||
@ -35,13 +26,13 @@ module SwaggerClient
|
|||||||
case type.to_sym
|
case type.to_sym
|
||||||
when :DateTime
|
when :DateTime
|
||||||
DateTime.parse(value)
|
DateTime.parse(value)
|
||||||
when :string
|
when :String
|
||||||
value.to_s
|
value.to_s
|
||||||
when :int
|
when :Integer
|
||||||
value.to_i
|
value.to_i
|
||||||
when :double
|
when :Float
|
||||||
value.to_f
|
value.to_f
|
||||||
when :boolean
|
when :BOOLEAN
|
||||||
if value =~ /^(true|t|yes|y|1)$/i
|
if value =~ /^(true|t|yes|y|1)$/i
|
||||||
true
|
true
|
||||||
else
|
else
|
||||||
@ -53,7 +44,16 @@ module SwaggerClient
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# to_body is an alias to to_body (backward compatibility)
|
def to_s
|
||||||
|
to_hash.to_s
|
||||||
|
end
|
||||||
|
|
||||||
|
# to_body is an alias to to_body (backward compatibility))
|
||||||
|
def to_body
|
||||||
|
to_hash
|
||||||
|
end
|
||||||
|
|
||||||
|
# return the object in the form of hash
|
||||||
def to_hash
|
def to_hash
|
||||||
hash = {}
|
hash = {}
|
||||||
self.class.attribute_map.each_pair do |key, value|
|
self.class.attribute_map.each_pair do |key, value|
|
||||||
|
@ -18,8 +18,8 @@ module SwaggerClient
|
|||||||
# attribute type
|
# attribute type
|
||||||
def self.swagger_types
|
def self.swagger_types
|
||||||
{
|
{
|
||||||
:'id' => :'int',
|
:'id' => :'Integer',
|
||||||
:'name' => :'string'
|
:'name' => :'String'
|
||||||
|
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
@ -30,12 +30,12 @@ module SwaggerClient
|
|||||||
# attribute type
|
# attribute type
|
||||||
def self.swagger_types
|
def self.swagger_types
|
||||||
{
|
{
|
||||||
:'id' => :'int',
|
:'id' => :'Integer',
|
||||||
:'pet_id' => :'int',
|
:'pet_id' => :'Integer',
|
||||||
:'quantity' => :'int',
|
:'quantity' => :'Integer',
|
||||||
:'ship_date' => :'DateTime',
|
:'ship_date' => :'DateTime',
|
||||||
:'status' => :'string',
|
:'status' => :'String',
|
||||||
:'complete' => :'boolean'
|
:'complete' => :'BOOLEAN'
|
||||||
|
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
@ -30,12 +30,12 @@ module SwaggerClient
|
|||||||
# attribute type
|
# attribute type
|
||||||
def self.swagger_types
|
def self.swagger_types
|
||||||
{
|
{
|
||||||
:'id' => :'int',
|
:'id' => :'Integer',
|
||||||
:'category' => :'Category',
|
:'category' => :'Category',
|
||||||
:'name' => :'string',
|
:'name' => :'String',
|
||||||
:'photo_urls' => :'array[string]',
|
:'photo_urls' => :'Array<String>',
|
||||||
:'tags' => :'array[Tag]',
|
:'tags' => :'Array<Tag>',
|
||||||
:'status' => :'string'
|
:'status' => :'String'
|
||||||
|
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
@ -18,8 +18,8 @@ module SwaggerClient
|
|||||||
# attribute type
|
# attribute type
|
||||||
def self.swagger_types
|
def self.swagger_types
|
||||||
{
|
{
|
||||||
:'id' => :'int',
|
:'id' => :'Integer',
|
||||||
:'name' => :'string'
|
:'name' => :'String'
|
||||||
|
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
@ -36,14 +36,14 @@ module SwaggerClient
|
|||||||
# attribute type
|
# attribute type
|
||||||
def self.swagger_types
|
def self.swagger_types
|
||||||
{
|
{
|
||||||
:'id' => :'int',
|
:'id' => :'Integer',
|
||||||
:'username' => :'string',
|
:'username' => :'String',
|
||||||
:'first_name' => :'string',
|
:'first_name' => :'String',
|
||||||
:'last_name' => :'string',
|
:'last_name' => :'String',
|
||||||
:'email' => :'string',
|
:'email' => :'String',
|
||||||
:'password' => :'string',
|
:'password' => :'String',
|
||||||
:'phone' => :'string',
|
:'phone' => :'String',
|
||||||
:'user_status' => :'int'
|
:'user_status' => :'Integer'
|
||||||
|
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
@ -1,6 +1,4 @@
|
|||||||
# module Swagger
|
class Object
|
||||||
class Object
|
|
||||||
|
|
||||||
unless Object.method_defined? :blank?
|
unless Object.method_defined? :blank?
|
||||||
def blank?
|
def blank?
|
||||||
respond_to?(:empty?) ? empty? : !self
|
respond_to?(:empty?) ? empty? : !self
|
||||||
@ -12,11 +10,9 @@
|
|||||||
!blank?
|
!blank?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
class String
|
||||||
|
|
||||||
class String
|
|
||||||
|
|
||||||
unless String.method_defined? :underscore
|
unless String.method_defined? :underscore
|
||||||
def underscore
|
def underscore
|
||||||
self.gsub(/::/, '/').
|
self.gsub(/::/, '/').
|
||||||
@ -36,11 +32,9 @@
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
class Hash
|
||||||
|
|
||||||
class Hash
|
|
||||||
|
|
||||||
unless Hash.method_defined? :stringify_keys
|
unless Hash.method_defined? :stringify_keys
|
||||||
def stringify_keys
|
def stringify_keys
|
||||||
inject({}) do |options, (key, value)|
|
inject({}) do |options, (key, value)|
|
||||||
@ -85,6 +79,4 @@
|
|||||||
self.replace(self.symbolize_and_underscore_keys)
|
self.replace(self.symbolize_and_underscore_keys)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
end
|
|
||||||
# end
|
|
||||||
|
@ -52,7 +52,7 @@ module SwaggerClient
|
|||||||
return if Swagger.authenticated?
|
return if Swagger.authenticated?
|
||||||
|
|
||||||
if Swagger.configuration.username.blank? || Swagger.configuration.password.blank?
|
if Swagger.configuration.username.blank? || Swagger.configuration.password.blank?
|
||||||
raise ClientError, "Username and password are required to authenticate."
|
raise ApiError, "Username and password are required to authenticate."
|
||||||
end
|
end
|
||||||
|
|
||||||
request = Swagger::Request.new(
|
request = Swagger::Request.new(
|
||||||
@ -69,10 +69,4 @@ module SwaggerClient
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class ServerError < StandardError
|
|
||||||
end
|
|
||||||
|
|
||||||
class ClientError < StandardError
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
@ -0,0 +1,26 @@
|
|||||||
|
module SwaggerClient
|
||||||
|
module Swagger
|
||||||
|
class ApiError < StandardError
|
||||||
|
attr_reader :code, :response_headers, :response_body
|
||||||
|
|
||||||
|
# Usage examples:
|
||||||
|
# ApiError.new
|
||||||
|
# ApiError.new("message")
|
||||||
|
# ApiError.new(:code => 500, :response_headers => {}, :response_body => "")
|
||||||
|
# ApiError.new(:code => 404, :message => "Not Found")
|
||||||
|
def initialize(arg = nil)
|
||||||
|
if arg.is_a? Hash
|
||||||
|
arg.each do |k, v|
|
||||||
|
if k.to_s == 'message'
|
||||||
|
super v
|
||||||
|
else
|
||||||
|
instance_variable_set "@#{k}", v
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
super arg
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -2,15 +2,18 @@ module SwaggerClient
|
|||||||
module Swagger
|
module Swagger
|
||||||
class Response
|
class Response
|
||||||
require 'json'
|
require 'json'
|
||||||
|
require 'date'
|
||||||
|
|
||||||
attr_accessor :raw
|
attr_accessor :raw
|
||||||
|
|
||||||
def initialize(raw)
|
def initialize(raw)
|
||||||
self.raw = raw
|
self.raw = raw
|
||||||
|
|
||||||
case self.code
|
unless raw.success?
|
||||||
when 500..510 then raise(ServerError, self.error_message)
|
fail ApiError.new(:code => code,
|
||||||
when 299..426 then raise(ClientError, self.error_message)
|
:response_headers => headers,
|
||||||
|
:response_body => body),
|
||||||
|
raw.status_message
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -18,19 +21,65 @@ module SwaggerClient
|
|||||||
raw.code
|
raw.code
|
||||||
end
|
end
|
||||||
|
|
||||||
# Account for error messages that take different forms...
|
def body
|
||||||
def error_message
|
raw.body
|
||||||
body['message']
|
|
||||||
rescue
|
|
||||||
body
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# If body is JSON, parse it
|
# Deserialize the raw response body to the given return type.
|
||||||
# Otherwise return raw string
|
#
|
||||||
def body
|
# @param [String] return_type some examples: "User", "Array[User]", "Hash[String,Integer]"
|
||||||
JSON.parse(raw.body, :symbolize_names => true)
|
def deserialize(return_type)
|
||||||
rescue
|
return nil if body.blank?
|
||||||
raw.body
|
|
||||||
|
# ensuring a default content type
|
||||||
|
content_type = raw.headers_hash['Content-Type'] || 'application/json'
|
||||||
|
|
||||||
|
unless content_type.start_with?('application/json')
|
||||||
|
fail "Content-Type is not supported: #{content_type}"
|
||||||
|
end
|
||||||
|
|
||||||
|
begin
|
||||||
|
data = JSON.parse(body, :symbolize_names => true)
|
||||||
|
rescue JSON::ParserError => e
|
||||||
|
if return_type == 'String'
|
||||||
|
return body
|
||||||
|
else
|
||||||
|
raise e
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
build_models data, return_type
|
||||||
|
end
|
||||||
|
|
||||||
|
# Walk through the given data and, when necessary, build model(s) from
|
||||||
|
# Hash data for array/hash values of the response.
|
||||||
|
def build_models(data, return_type)
|
||||||
|
case return_type
|
||||||
|
when 'String', 'Integer', 'Float', 'BOOLEAN'
|
||||||
|
# primitives, return directly
|
||||||
|
data
|
||||||
|
when 'DateTime'
|
||||||
|
# parse date time (expecting ISO 8601 format)
|
||||||
|
DateTime.parse data
|
||||||
|
when 'Object'
|
||||||
|
# generic object, return directly
|
||||||
|
data
|
||||||
|
when /\AArray<(.+)>\z/
|
||||||
|
# e.g. Array<Pet>
|
||||||
|
sub_type = $1
|
||||||
|
data.map {|item| build_models(item, sub_type) }
|
||||||
|
when /\AHash\<String, (.+)\>\z/
|
||||||
|
# e.g. Hash<String, Integer>
|
||||||
|
sub_type = $1
|
||||||
|
{}.tap do |hash|
|
||||||
|
data.each {|k, v| hash[k] = build_models(v, sub_type) }
|
||||||
|
end
|
||||||
|
else
|
||||||
|
# models, e.g. Pet
|
||||||
|
SwaggerClient.const_get(return_type).new.tap do |model|
|
||||||
|
model.build_from_hash data
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# `headers_hash` is a Typhoeus-specific extension of Hash,
|
# `headers_hash` is a Typhoeus-specific extension of Hash,
|
||||||
@ -58,7 +107,7 @@ module SwaggerClient
|
|||||||
def pretty_body
|
def pretty_body
|
||||||
return unless body.present?
|
return unless body.present?
|
||||||
case format
|
case format
|
||||||
when 'json' then JSON.pretty_generate(body).gsub(/\n/, '<br/>')
|
when 'json' then JSON.pretty_generate(JSON.parse(body)).gsub(/\n/, '<br/>')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -13,9 +13,14 @@ describe "Pet" do
|
|||||||
tag2 = SwaggerClient::Tag.new({'id' => 2, 'name'=> 'tag2'})
|
tag2 = SwaggerClient::Tag.new({'id' => 2, 'name'=> 'tag2'})
|
||||||
category1 = SwaggerClient::Category.new({:id => 1, :name => 'category unknown'})
|
category1 = SwaggerClient::Category.new({:id => 1, :name => 'category unknown'})
|
||||||
# initalize using both string and symbol key
|
# initalize using both string and symbol key
|
||||||
pet_hash = {:'id' => 10002, :'name' => "RUBY UNIT TESTING", :'status' => "pending",
|
pet_hash = {
|
||||||
:'photo_urls' => ["url1", "url2"], :'category' => category1,
|
:id => 10002,
|
||||||
:'tags' => [tag1, tag2]}
|
:name => "RUBY UNIT TESTING",
|
||||||
|
:status => "pending",
|
||||||
|
:photo_urls => ["url1", "url2"],
|
||||||
|
:category => category1,
|
||||||
|
:tags => [tag1, tag2]
|
||||||
|
}
|
||||||
pet = SwaggerClient::Pet.new(pet_hash)
|
pet = SwaggerClient::Pet.new(pet_hash)
|
||||||
# test new
|
# test new
|
||||||
pet.name.should == "RUBY UNIT TESTING"
|
pet.name.should == "RUBY UNIT TESTING"
|
||||||
@ -45,9 +50,26 @@ describe "Pet" do
|
|||||||
pet.category.name.should == "category test"
|
pet.category.name.should == "category test"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "should not find a pet that does not exist" do
|
||||||
|
begin
|
||||||
|
SwaggerClient::PetApi.get_pet_by_id(-1)
|
||||||
|
fail 'it should raise error'
|
||||||
|
rescue SwaggerClient::Swagger::ApiError => e
|
||||||
|
e.code.should == 404
|
||||||
|
e.message.should == 'Not Found'
|
||||||
|
e.response_body.should == '{"code":1,"type":"error","message":"Pet not found"}'
|
||||||
|
e.response_headers.should be_a(Hash)
|
||||||
|
e.response_headers['Content-Type'].should == 'application/json'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
it "should find pets by status" do
|
it "should find pets by status" do
|
||||||
pets = SwaggerClient::PetApi.find_pets_by_status(:status => 'available')
|
pets = SwaggerClient::PetApi.find_pets_by_status(:status => 'available')
|
||||||
pets.length.should >= 3
|
pets.length.should >= 3
|
||||||
|
pets.each do |pet|
|
||||||
|
pet.should be_a(SwaggerClient::Pet)
|
||||||
|
pet.status.should == 'available'
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should not find a pet with invalid status" do
|
it "should not find a pet with invalid status" do
|
||||||
@ -57,11 +79,11 @@ describe "Pet" do
|
|||||||
|
|
||||||
it "should find a pet by status" do
|
it "should find a pet by status" do
|
||||||
pets = SwaggerClient::PetApi.find_pets_by_status(:status => "available,sold")
|
pets = SwaggerClient::PetApi.find_pets_by_status(:status => "available,sold")
|
||||||
pets.map {|pet|
|
pets.each do |pet|
|
||||||
if(pet.status != 'available' && pet.status != 'sold')
|
if pet.status != 'available' && pet.status != 'sold'
|
||||||
raise "pet status wasn't right"
|
raise "pet status wasn't right"
|
||||||
end
|
end
|
||||||
}
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should update a pet" do
|
it "should update a pet" do
|
||||||
|
@ -8,7 +8,6 @@ describe SwaggerClient::Swagger::Response do
|
|||||||
end
|
end
|
||||||
|
|
||||||
before(:each) do
|
before(:each) do
|
||||||
|
|
||||||
VCR.use_cassette('pet_resource', :record => :new_episodes) do
|
VCR.use_cassette('pet_resource', :record => :new_episodes) do
|
||||||
@raw = Typhoeus::Request.get("http://petstore.swagger.io/v2/pet/10002")
|
@raw = Typhoeus::Request.get("http://petstore.swagger.io/v2/pet/10002")
|
||||||
end
|
end
|
||||||
@ -18,8 +17,10 @@ describe SwaggerClient::Swagger::Response do
|
|||||||
|
|
||||||
describe "initialization" do
|
describe "initialization" do
|
||||||
it "sets body" do
|
it "sets body" do
|
||||||
@response.body.class.should == Hash
|
@response.body.should be_a(String)
|
||||||
@response.body.has_key?(:'name').should == true
|
data = JSON.parse(@response.body)
|
||||||
|
data.should be_a(Hash)
|
||||||
|
data['id'].should == 10002
|
||||||
end
|
end
|
||||||
|
|
||||||
it "sets code" do
|
it "sets code" do
|
||||||
@ -32,7 +33,6 @@ describe SwaggerClient::Swagger::Response do
|
|||||||
end
|
end
|
||||||
|
|
||||||
describe "format" do
|
describe "format" do
|
||||||
|
|
||||||
it "recognizes json" do
|
it "recognizes json" do
|
||||||
@response.format.should == 'json'
|
@response.format.should == 'json'
|
||||||
@response.json?.should == true
|
@response.json?.should == true
|
||||||
@ -47,11 +47,9 @@ describe SwaggerClient::Swagger::Response do
|
|||||||
@response.format.should == 'xml'
|
@response.format.should == 'xml'
|
||||||
@response.xml?.should == true
|
@response.xml?.should == true
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "prettiness" do
|
describe "prettiness" do
|
||||||
|
|
||||||
it "has a pretty json body" do
|
it "has a pretty json body" do
|
||||||
@response.pretty_body.should =~ /\{.*\}/
|
@response.pretty_body.should =~ /\{.*\}/
|
||||||
end
|
end
|
||||||
@ -59,7 +57,26 @@ describe SwaggerClient::Swagger::Response do
|
|||||||
it "has pretty headers" do
|
it "has pretty headers" do
|
||||||
@response.pretty_headers.should =~ /\{.*\}/
|
@response.pretty_headers.should =~ /\{.*\}/
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "deserialize" do
|
||||||
|
it "handles Hash<String, String>" do
|
||||||
|
@response.stub(:body) { '{"message": "Hello"}' }
|
||||||
|
data = @response.deserialize('Hash<String, String>')
|
||||||
|
data.should be_a(Hash)
|
||||||
|
data.should == {:message => 'Hello'}
|
||||||
|
end
|
||||||
|
|
||||||
|
it "handles Hash<String, Pet>" do
|
||||||
|
json = @response.body
|
||||||
|
@response.stub(:body) { "{\"pet\": #{json}}" }
|
||||||
|
data = @response.deserialize('Hash<String, Pet>')
|
||||||
|
data.should be_a(Hash)
|
||||||
|
data.keys.should == [:pet]
|
||||||
|
pet = data[:pet]
|
||||||
|
pet.should be_a(SwaggerClient::Pet)
|
||||||
|
pet.id.should == 10002
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -10,4 +10,14 @@ describe "Store" do
|
|||||||
item = SwaggerClient::StoreApi.get_order_by_id(10002)
|
item = SwaggerClient::StoreApi.get_order_by_id(10002)
|
||||||
item.id.should == 10002
|
item.id.should == 10002
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "should featch the inventory" do
|
||||||
|
result = SwaggerClient::StoreApi.get_inventory
|
||||||
|
result.should be_a(Hash)
|
||||||
|
result.should_not be_empty
|
||||||
|
result.each do |k, v|
|
||||||
|
k.should be_a(Symbol)
|
||||||
|
v.should be_a(Integer)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user