Fixes enums c#

This commit is contained in:
Justus Thorvaldsson 2015-12-08 09:43:28 +01:00
parent 3aff6e8328
commit b434fb517f
57 changed files with 1423 additions and 789 deletions

View File

@ -36,6 +36,7 @@ Check out [Swagger-Spec](https://github.com/swagger-api/swagger-spec) for additi
- [To build a server stub](#to-build-a-server-stub)
- [Node.js](#nodejs)
- [PHP Silex](#php-silex)
- [Python Flask (Connexion)](#python-flask-connexion)
- [Ruby Sinatra](#ruby-sinatra)
- [Scala Scalatra](#scala-scalatra)
- [Java JAX-RS](#java-jax-rs)
@ -268,9 +269,11 @@ AkkaScalaClientCodegen.java
AndroidClientCodegen.java
AsyncScalaClientCodegen.java
CSharpClientCodegen.java
ClojureClientCodegen.java
CsharpDotNet2ClientCodegen.java
DartClientCodegen.java
FlashClientCodegen.java
FlaskConnexionCodegen.java
JavaClientCodegen.java
JavaInflectorServerCodegen.java
JaxRSServerCodegen.java
@ -441,6 +444,15 @@ java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate \
-o samples/server/petstore/silex
```
### Python Flask (Connexion)
```
java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate \
-i http://petstore.swagger.io/v2/swagger.json \
-l flaskConnexion \
-o samples/server/petstore/flaskConnexion
```
### Ruby Sinatra
```

View File

@ -1,6 +1,7 @@
package io.swagger.codegen.cmd;
import ch.lambdaj.function.convert.Converter;
import com.google.common.base.CaseFormat;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.samskivert.mustache.Mustache;
@ -9,7 +10,6 @@ import io.airlift.airline.Option;
import io.swagger.codegen.DefaultGenerator;
import io.swagger.codegen.SupportingFile;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -55,7 +55,7 @@ public class Meta implements Runnable {
final File targetDir = new File(outputFolder);
LOG.info("writing to folder [{}]", targetDir.getAbsolutePath());
String mainClass = StringUtils.capitalize(name) + "Generator";
String mainClass = CaseFormat.LOWER_HYPHEN.to(CaseFormat.UPPER_CAMEL, name) + "Generator";
List<SupportingFile> supportingFiles = ImmutableList.of(
new SupportingFile("pom.mustache", "", "pom.xml"),
@ -68,11 +68,18 @@ public class Meta implements Runnable {
"src/main/resources/META-INF/services", "io.swagger.codegen.CodegenConfig")
);
String swaggerVersion = this.getClass().getPackage().getImplementationVersion();
// if the code is running outside of the jar (i.e. from the IDE), it will not have the version available.
// let's default it with something.
if (swaggerVersion==null) {
swaggerVersion = "2.1.3";
}
Map<String, Object> data = new ImmutableMap.Builder<String, Object>()
.put("generatorPackage", targetPackage)
.put("generatorClass", mainClass)
.put("name", name)
.put("fullyQualifiedGeneratorClass", targetPackage + "." + mainClass).build();
.put("fullyQualifiedGeneratorClass", targetPackage + "." + mainClass)
.put("swaggerCodegenVersion", swaggerVersion).build();
with(supportingFiles).convert(processFiles(targetDir, data));

View File

@ -1,5 +1,6 @@
package io.swagger.codegen.languages;
import io.swagger.codegen.CliOption;
import io.swagger.codegen.CodegenConfig;
import io.swagger.codegen.CodegenConstants;
import io.swagger.codegen.CodegenOperation;
@ -13,8 +14,6 @@ import io.swagger.models.Swagger;
import org.apache.commons.lang.StringUtils;
import java.io.File;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Map;
import java.util.List;
@ -23,13 +22,15 @@ public class ClojureClientCodegen extends DefaultCodegen implements CodegenConfi
private static final String PROJECT_DESCRIPTION = "projectDescription";
private static final String PROJECT_VERSION = "projectVersion";
private static final String PROJECT_URL = "projectUrl";
private static final String LICENSE_NAME = "licenseName";
private static final String LICENSE_URL = "licenseUrl";
private static final String PROJECT_LICENSE_NAME = "projectLicenseName";
private static final String PROJECT_LICENSE_URL = "projectLicenseUrl";
private static final String BASE_NAMESPACE = "baseNamespace";
protected String projectName = null;
protected String projectDescription = null;
protected String projectVersion = null;
protected String baseNamespace = null;
protected String sourceFolder = "src";
public ClojureClientCodegen() {
@ -37,6 +38,21 @@ public class ClojureClientCodegen extends DefaultCodegen implements CodegenConfi
outputFolder = "generated-code" + File.separator + "clojure";
apiTemplateFiles.put("api.mustache", ".clj");
embeddedTemplateDir = templateDir = "clojure";
cliOptions.add(new CliOption(PROJECT_NAME,
"name of the project (Default: generated from info.title or \"swagger-clj-client\")"));
cliOptions.add(new CliOption(PROJECT_DESCRIPTION,
"description of the project (Default: using info.description or \"Client library of <projectNname>\")"));
cliOptions.add(new CliOption(PROJECT_VERSION,
"version of the project (Default: using info.version or \"1.0.0\")"));
cliOptions.add(new CliOption(PROJECT_URL,
"URL of the project (Default: using info.contact.url or not included in project.clj)"));
cliOptions.add(new CliOption(PROJECT_LICENSE_NAME,
"name of the license the project uses (Default: using info.license.name or not included in project.clj)"));
cliOptions.add(new CliOption(PROJECT_LICENSE_URL,
"URL of the license the project uses (Default: using info.license.url or not included in project.clj)"));
cliOptions.add(new CliOption(BASE_NAMESPACE,
"the base/top namespace (Default: generated from projectName)"));
}
@Override
@ -67,6 +83,9 @@ public class ClojureClientCodegen extends DefaultCodegen implements CodegenConfi
if (additionalProperties.containsKey(PROJECT_VERSION)) {
projectVersion = ((String) additionalProperties.get(PROJECT_VERSION));
}
if (additionalProperties.containsKey(BASE_NAMESPACE)) {
baseNamespace = ((String) additionalProperties.get(BASE_NAMESPACE));
}
if (swagger.getInfo() != null) {
Info info = swagger.getInfo();
@ -91,11 +110,11 @@ public class ClojureClientCodegen extends DefaultCodegen implements CodegenConfi
}
if (info.getLicense() != null) {
License license = info.getLicense();
if (additionalProperties.get(LICENSE_NAME) == null) {
additionalProperties.put(LICENSE_NAME, license.getName());
if (additionalProperties.get(PROJECT_LICENSE_NAME) == null) {
additionalProperties.put(PROJECT_LICENSE_NAME, license.getName());
}
if (additionalProperties.get(LICENSE_URL) == null) {
additionalProperties.put(LICENSE_URL, license.getUrl());
if (additionalProperties.get(PROJECT_LICENSE_URL) == null) {
additionalProperties.put(PROJECT_LICENSE_URL, license.getUrl());
}
}
}
@ -110,8 +129,9 @@ public class ClojureClientCodegen extends DefaultCodegen implements CodegenConfi
if (projectDescription == null) {
projectDescription = "Client library of " + projectName;
}
final String baseNamespace = dashize(projectName);
if (baseNamespace == null) {
baseNamespace = dashize(projectName);
}
apiPackage = baseNamespace + ".api";
additionalProperties.put(PROJECT_NAME, projectName);

View File

@ -44,6 +44,9 @@ public class ApiKeyAuth implements Authentication {
@Override
public void applyToParams(List<Pair> queryParams, Map<String, String> headerParams) {
if (apiKey == null) {
return;
}
String value;
if (apiKeyPrefix != null) {
value = apiKeyPrefix + " " + apiKey;

View File

@ -2,11 +2,12 @@ package {{invokerPackage}}.auth;
import {{invokerPackage}}.Pair;
import com.migcomponents.migbase64.Base64;
import java.util.Map;
import java.util.List;
import java.io.UnsupportedEncodingException;
import javax.xml.bind.DatatypeConverter;
{{>generatedAnnotation}}
public class HttpBasicAuth implements Authentication {
@ -31,9 +32,12 @@ public class HttpBasicAuth implements Authentication {
@Override
public void applyToParams(List<Pair> queryParams, Map<String, String> headerParams) {
if (username == null && password == null) {
return;
}
String str = (username == null ? "" : username) + ":" + (password == null ? "" : password);
try {
headerParams.put("Authorization", "Basic " + DatatypeConverter.printBase64Binary(str.getBytes("UTF-8")));
headerParams.put("Authorization", "Basic " + Base64.encodeToString(str.getBytes("UTF-8"), false));
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}

View File

@ -152,6 +152,13 @@
<version>${jodatime-version}</version>
</dependency>
<!-- Base64 encoding that works in both JVM and Android -->
<dependency>
<groupId>com.brsanthu</groupId>
<artifactId>migbase64</artifactId>
<version>2.2</version>
</dependency>
<!-- test dependencies -->
<dependency>
<groupId>junit</groupId>

View File

@ -64,6 +64,38 @@ import {{invokerPackage}}.auth.ApiKeyAuth;
import {{invokerPackage}}.auth.OAuth;
public class ApiClient {
public static final double JAVA_VERSION;
public static final boolean IS_ANDROID;
public static final int ANDROID_SDK_VERSION;
static {
JAVA_VERSION = Double.parseDouble(System.getProperty("java.specification.version"));
boolean isAndroid;
try {
Class.forName("android.app.Activity");
isAndroid = true;
} catch (ClassNotFoundException e) {
isAndroid = false;
}
IS_ANDROID = isAndroid;
int sdkVersion = 0;
if (IS_ANDROID) {
try {
sdkVersion = Class.forName("android.os.Build$VERSION").getField("SDK_INT").getInt(null);
} catch (Exception e) {
try {
sdkVersion = Integer.parseInt((String) Class.forName("android.os.Build$VERSION").getField("SDK").get(null));
} catch (Exception e2) { }
}
}
ANDROID_SDK_VERSION = sdkVersion;
}
/**
* The datetime format to be used when <code>lenientDatetimeFormat</code> is enabled.
*/
public static final String LENIENT_DATETIME_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSSZ";
private String basePath = "{{basePath}}";
private boolean lenientOnJson = false;
private boolean debugging = false;
@ -100,8 +132,7 @@ public class ApiClient {
this.dateFormat = new SimpleDateFormat("yyyy-MM-dd");
// Always use UTC as the default time zone when dealing with date (without time).
this.dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
// Use the system's default time zone when dealing with datetime (mainly formatting).
this.datetimeFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX");
initDatetimeFormat();
// Be lenient on datetime formats when parsing datetime from string.
// See <code>parseDatetime</code>.
@ -263,25 +294,30 @@ public class ApiClient {
if (str == null)
return null;
DateFormat format;
if (lenientDatetimeFormat) {
/*
* When lenientDatetimeFormat is enabled, process the given string
* to support various formats defined by ISO 8601.
* When lenientDatetimeFormat is enabled, normalize the date string
* into <code>LENIENT_DATETIME_FORMAT</code> to support various formats
* defined by ISO 8601.
*/
// normalize time zone
// trailing "Z": 2015-08-16T08:20:05Z => 2015-08-16T08:20:05+00:00
str = str.replaceAll("[zZ]\\z", "+00:00");
// add colon: 2015-08-16T08:20:05+0000 => 2015-08-16T08:20:05+00:00
str = str.replaceAll("([+-]\\d{2})(\\d{2})\\z", "$1:$2");
// expand time zone: 2015-08-16T08:20:05+00 => 2015-08-16T08:20:05+00:00
str = str.replaceAll("([+-]\\d{2})\\z", "$1:00");
// trailing "Z": 2015-08-16T08:20:05Z => 2015-08-16T08:20:05+0000
str = str.replaceAll("[zZ]\\z", "+0000");
// remove colon in time zone: 2015-08-16T08:20:05+00:00 => 2015-08-16T08:20:05+0000
str = str.replaceAll("([+-]\\d{2}):(\\d{2})\\z", "$1$2");
// expand time zone: 2015-08-16T08:20:05+00 => 2015-08-16T08:20:05+0000
str = str.replaceAll("([+-]\\d{2})\\z", "$100");
// add milliseconds when missing
// 2015-08-16T08:20:05+00:00 => 2015-08-16T08:20:05.000+00:00
str = str.replaceAll("(:\\d{1,2})([+-]\\d{2}:\\d{2})\\z", "$1.000$2");
// 2015-08-16T08:20:05+0000 => 2015-08-16T08:20:05.000+0000
str = str.replaceAll("(:\\d{1,2})([+-]\\d{4})\\z", "$1.000$2");
format = new SimpleDateFormat(LENIENT_DATETIME_FORMAT);
} else {
format = this.datetimeFormat;
}
try {
return datetimeFormat.parse(str);
return format.parse(str);
} catch (ParseException e) {
throw new RuntimeException(e);
}
@ -916,6 +952,31 @@ public class ApiClient {
}
}
/**
* Initialize datetime format according to the current environment, e.g. Java 1.7 and Android.
*/
private void initDatetimeFormat() {
String formatWithTimeZone = null;
if (IS_ANDROID) {
if (ANDROID_SDK_VERSION >= 18) {
// The time zone format "ZZZZZ" is available since Android 4.3 (SDK version 18)
formatWithTimeZone = "yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ";
}
} else if (JAVA_VERSION >= 1.7) {
// The time zone format "XXX" is available since Java 1.7
formatWithTimeZone = "yyyy-MM-dd'T'HH:mm:ss.SSSXXX";
}
if (formatWithTimeZone != null) {
this.datetimeFormat = new SimpleDateFormat(formatWithTimeZone);
// NOTE: Use the system's default time zone (mainly for datetime formatting).
} else {
// Use a common format that works across all systems.
this.datetimeFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
// Always use the UTC time zone as we are using a constant trailing "Z" here.
this.datetimeFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
}
}
/**
* Apply SSL related settings to httpClient according to the current values of
* verifyingSsl and sslCaCert.

View File

@ -2,7 +2,7 @@ package {{invokerPackage}}.auth;
import {{invokerPackage}}.Pair;
import com.migcomponents.migbase64.Base64;
import com.squareup.okhttp.Credentials;
import java.util.Map;
import java.util.List;
@ -31,11 +31,11 @@ public class HttpBasicAuth implements Authentication {
@Override
public void applyToParams(List<Pair> queryParams, Map<String, String> headerParams) {
String str = (username == null ? "" : username) + ":" + (password == null ? "" : password);
try {
headerParams.put("Authorization", "Basic " + Base64.encodeToString(str.getBytes("UTF-8"), false));
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
if (username == null && password == null) {
return;
}
headerParams.put("Authorization", Credentials.basic(
username == null ? "" : username,
password == null ? "" : password));
}
}

View File

@ -122,11 +122,6 @@
<artifactId>gson</artifactId>
<version>${gson-version}</version>
</dependency>
<dependency>
<groupId>com.brsanthu</groupId>
<artifactId>migbase64</artifactId>
<version>2.2</version>
</dependency>
<!-- test dependencies -->
<dependency>

View File

@ -148,6 +148,13 @@
<version>${jodatime-version}</version>
</dependency>
<!-- Base64 encoding that works in both JVM and Android -->
<dependency>
<groupId>com.brsanthu</groupId>
<artifactId>migbase64</artifactId>
<version>2.2</version>
</dependency>
<!-- test dependencies -->
<dependency>
<groupId>junit</groupId>

View File

@ -1,5 +1,5 @@
{{=< >=}}(ns <package>.<classname>
(:require [<projectName>.core :refer [call-api check-required-params]])
(:require [<baseNamespace>.core :refer [call-api check-required-params]])
(:import (java.io File)))
<#operations><#operation>
(defn <nickname>

View File

@ -1,8 +1,8 @@
{{=< >=}}(defproject <&projectName> "<&projectVersion>"
:description "<&projectDescription>"<#projectUrl>
:url "<&projectUrl>"</projectUrl><#licenseName>
:license {:name "<&licenseName>"<#licenseUrl>
:url "<&licenseUrl>"</licenseUrl>}</licenseName>
:url "<&projectUrl>"</projectUrl><#projectLicenseName>
:license {:name "<&projectLicenseName>"<#projectLicenseUrl>
:url "<&projectLicenseUrl>"</projectLicenseUrl>}</projectLicenseName>
:dependencies [[org.clojure/clojure "1.7.0"]
[clj-http "2.0.0"]
[cheshire "5.5.0"]])

View File

@ -95,7 +95,7 @@
</dependency>
</dependencies>
<properties>
<swagger-codegen-version>2.1.3</swagger-codegen-version>
<swagger-codegen-version>{{swaggerCodegenVersion}}</swagger-codegen-version>
<maven-plugin-version>1.0.0</maven-plugin-version>
<junit-version>4.8.1</junit-version>
</properties>

View File

@ -1,6 +1,6 @@
public enum {{name}} {
public enum {{datatypeWithEnum}} {
{{#allowableValues}}{{#enumVars}}
[EnumMember("{{jsonname}}")]
[EnumMember(Value = "{{jsonname}}")]
{{name}}{{^-last}},
{{/-last}}{{#-last}}{{/-last}}{{/enumVars}}{{/allowableValues}}
}

View File

@ -1,69 +1,119 @@
using System;
using System.Linq;
using System.IO;
using System.Text;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.Serialization;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
{{#models}}
{{#model}}
namespace {{packageName}}.Model {
namespace {{packageName}}.Model
{
/// <summary>
/// {{description}}
/// </summary>
[DataContract]
public class {{classname}}{{#parent}} : {{{parent}}}{{/parent}} {
{{#vars}}{{#isEnum}}
public class {{classname}} : IEquatable<{{classname}}>{{#parent}}, {{{parent}}}{{/parent}}
{ {{#vars}}{{#isEnum}}
[JsonConverter(typeof(StringEnumConverter))]
{{>enumClass}}{{/isEnum}}{{#items.isEnum}}{{#items}}
{{>enumClass}}{{/items}}{{/items.isEnum}}
private {{{name}}} {{name}};
{{>enumClass}}{{/items}}{{/items.isEnum}}{{/vars}}
{{#vars}}{{#isEnum}}
/// <summary>
/// {{^description}}Gets or Sets {{{name}}}{{/description}}{{#description}}{{{description}}}{{/description}}
/// </summary>{{#description}}
/// <value>{{{description}}}</value>{{/description}}
[DataMember(Name="{{baseName}}", EmitDefaultValue=false)]
public {{{name}}} {{name}} { get; set; }
{{/vars}}
{{#vars}}{{^isEnum}}
public {{{datatypeWithEnum}}} {{name}} { get; set; }
{{/isEnum}}{{/vars}}{{#vars}}{{^isEnum}}
/// <summary>
/// {{^description}}Gets or Sets {{{name}}}{{/description}}{{#description}}{{{description}}}{{/description}}
/// </summary>{{#description}}
/// <value>{{{description}}}</value>{{/description}}
[DataMember(Name="{{baseName}}", EmitDefaultValue=false)]
public {{{datatype}}} {{name}} { get; set; }
{{/isEnum}}{{/vars}}
/// <summary>
/// Get the string presentation of the object
/// Returns the string presentation of the object
/// </summary>
/// <returns>String presentation of the object</returns>
public override string ToString() {
public override string ToString()
{
var sb = new StringBuilder();
sb.Append("class {{classname}} {\n");
{{#vars}}
sb.Append(" {{name}}: ").Append({{name}}).Append("\n");
{{#vars}}sb.Append(" {{name}}: ").Append({{name}}).Append("\n");
{{/vars}}
sb.Append("}\n");
return sb.ToString();
}
/// <summary>
/// Get the JSON string presentation of the object
/// Returns the JSON string presentation of the object
/// </summary>
/// <returns>JSON string presentation of the object</returns>
public {{#parent}} new {{/parent}}string ToJson() {
public {{#parent}} new {{/parent}}string ToJson()
{
return JsonConvert.SerializeObject(this, Formatting.Indented);
}
}
/// <summary>
/// Returns true if objects are equal
/// </summary>
/// <param name="obj">Object to be compared</param>
/// <returns>Boolean</returns>
public override bool Equals(object obj)
{
// credit: http://stackoverflow.com/a/10454552/677735
return this.Equals(obj as {{classname}});
}
/// <summary>
/// Returns true if {{classname}} instances are equal
/// </summary>
/// <param name="obj">Instance of {{classname}} to be compared</param>
/// <returns>Boolean</returns>
public bool Equals({{classname}} other)
{
// credit: http://stackoverflow.com/a/10454552/677735
if (other == null)
return false;
return {{#vars}}{{#isNotContainer}}
(
this.{{name}} == other.{{name}} ||
this.{{name}} != null &&
this.{{name}}.Equals(other.{{name}})
){{#hasMore}} && {{/hasMore}}{{/isNotContainer}}{{^isNotContainer}}
(
this.{{name}} == other.{{name}} ||
this.{{name}} != null &&
this.{{name}}.SequenceEqual(other.{{name}})
){{#hasMore}} && {{/hasMore}}{{/isNotContainer}}{{/vars}};
}
/// <summary>
/// Gets the hash code
/// </summary>
/// <returns>Hash code</returns>
public override int GetHashCode()
{
// credit: http://stackoverflow.com/a/263416/677735
unchecked // Overflow is fine, just wrap
{
int hash = 41;
// Suitable nullity checks etc, of course :)
{{#vars}}
if (this.{{name}} != null)
hash = hash * 57 + this.{{name}}.GetHashCode();
{{/vars}}
return hash;
}
}
}
{{/model}}
{{/models}}
}

View File

@ -317,10 +317,24 @@ sub update_params_for_auth {
foreach my $auth (@$auth_settings) {
# determine which one to use
if (!defined($auth)) {
# TODO show warning about auth setting not defined
}
{{#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::{{moduleName}}::Configuration::username.":".$WWW::{{moduleName}}::Configuration::password);{{/isBasic}}
{{#isOAuth}}$header_params->{'Authorization'} = 'Bearer ' . $WWW::{{moduleName}}::Configuration::access_token;{{/isOAuth}}
{{#isApiKey}}{{#isKeyInHeader}}
my $api_key = $self->get_api_key_with_prefix('{{keyParamName}}');
if ($api_key) {
$header_params->{'{{keyParamName}}'} = $api_key;
}{{/isKeyInHeader}}{{#isKeyInQuery}}
my $api_key = $self->get_api_key_with_prefix('{{keyParamName}}');
if ($api_key) {
$query_params->{'{{keyParamName}}'} = $api_key;
}{{/isKeyInQuery}}{{/isApiKey}}{{#isBasic}}
if ($WWW::{{moduleName}}::Configuration::username || $WWW::{{moduleName}}::Configuration::password) {
$header_params->{'Authorization'} = 'Basic ' . encode_base64($WWW::{{moduleName}}::Configuration::username . ":" . $WWW::{{moduleName}}::Configuration::password);
}{{/isBasic}}{{#isOAuth}}
if ($WWW::{{moduleName}}::Configuration::access_token) {
$header_params->{'Authorization'} = 'Bearer ' . $WWW::{{moduleName}}::Configuration::access_token;
}{{/isOAuth}}
}
{{/authMethods}}
else {

View File

@ -166,12 +166,18 @@ use \{{invokerPackage}}\ObjectSerializer;
$httpBody = $formParams; // for HTTP post (form)
}
{{#authMethods}}{{#isApiKey}}
// this endpoint requires API key authentication
$apiKey = $this->apiClient->getApiKeyWithPrefix('{{keyParamName}}');
if (isset($apiKey)) {
if ($apiKey !== null) {
{{#isKeyInHeader}}$headerParams['{{keyParamName}}'] = $apiKey;{{/isKeyInHeader}}{{#isKeyInQuery}}$queryParams['{{keyParamName}}'] = $apiKey;{{/isKeyInQuery}}
}{{/isApiKey}}
{{#isBasic}}$headerParams['Authorization'] = 'Basic ' . base64_encode($this->apiClient->getConfig()->getUsername() . ":" . $this->apiClient->getConfig()->getPassword());{{/isBasic}}
{{#isOAuth}}$headerParams['Authorization'] = 'Bearer ' . $this->apiClient->getConfig()->getAccessToken();{{/isOAuth}}
{{#isBasic}}// this endpoint requires HTTP basic authentication
if ($this->apiClient->getConfig()->getUsername() !== null or $this->apiClient->getConfig()->getPassword() !== null) {
$headerParams['Authorization'] = 'Basic ' . base64_encode($this->apiClient->getConfig()->getUsername() . ":" . $this->apiClient->getConfig()->getPassword());
}{{/isBasic}}{{#isOAuth}}// this endpoint requires OAuth (access token)
if ($this->apiClient->getConfig()->getAccessToken() !== null) {
$headerParams['Authorization'] = 'Bearer ' . $this->apiClient->getConfig()->getAccessToken();
}{{/isOAuth}}
{{/authMethods}}
// make the API Call
try

View File

@ -453,7 +453,9 @@ class ApiClient(object):
for auth in auth_settings:
auth_setting = config.auth_settings().get(auth)
if auth_setting:
if auth_setting['in'] == 'header':
if not auth_setting['value']:
continue
elif auth_setting['in'] == 'header':
headers[auth_setting['key']] = auth_setting['value']
elif auth_setting['in'] == 'query':
querys[auth_setting['key']] = auth_setting['value']

13
pom.xml
View File

@ -305,6 +305,18 @@
<module>samples/client/petstore/android-java</module>
</modules>
</profile>
<profile>
<id>clojure-client</id>
<activation>
<property>
<name>env</name>
<value>clojure</value>
</property>
</activation>
<modules>
<module>samples/client/petstore/clojure</module>
</modules>
</profile>
<profile>
<id>java-client</id>
<activation>
@ -435,6 +447,7 @@
</activation>
<modules>
<module>samples/client/petstore/android-java</module>
<module>samples/client/petstore/clojure</module>
<module>samples/client/petstore/java/default</module>
<module>samples/client/petstore/java/jersey2</module>
<module>samples/client/petstore/java/okhttp-gson</module>

View File

@ -1,7 +1,6 @@
/target
/classes
/checkouts
pom.xml
pom.xml.asc
*.jar
*.class

View File

@ -0,0 +1,32 @@
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>io.swagger</groupId>
<artifactId>swagger-petstore-clojure</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<name>Swagger Petstore - Clojure Client</name>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<id>lein-test</id>
<phase>integration-test</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>lein</executable>
<arguments>
<argument>test</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -1,38 +1,21 @@
using System;
using System.Linq;
using System.IO;
using System.Text;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.Serialization;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
namespace IO.Swagger.Model {
namespace IO.Swagger.Model
{
/// <summary>
///
/// </summary>
[DataContract]
public class Category {
private Id Id;
/// <summary>
/// Gets or Sets Id
/// </summary>
[DataMember(Name="id", EmitDefaultValue=false)]
public Id Id { get; set; }
private Name Name;
/// <summary>
/// Gets or Sets Name
/// </summary>
[DataMember(Name="name", EmitDefaultValue=false)]
public Name Name { get; set; }
public class Category : IEquatable<Category>
{
/// <summary>
/// Gets or Sets Id
@ -40,25 +23,21 @@ namespace IO.Swagger.Model {
[DataMember(Name="id", EmitDefaultValue=false)]
public long? Id { get; set; }
/// <summary>
/// Gets or Sets Name
/// </summary>
[DataMember(Name="name", EmitDefaultValue=false)]
public string Name { get; set; }
/// <summary>
/// Get the string presentation of the object
/// Returns the string presentation of the object
/// </summary>
/// <returns>String presentation of the object</returns>
public override string ToString() {
public override string ToString()
{
var sb = new StringBuilder();
sb.Append("class Category {\n");
sb.Append(" Id: ").Append(Id).Append("\n");
sb.Append(" Name: ").Append(Name).Append("\n");
sb.Append("}\n");
@ -66,12 +45,70 @@ namespace IO.Swagger.Model {
}
/// <summary>
/// Get the JSON string presentation of the object
/// Returns the JSON string presentation of the object
/// </summary>
/// <returns>JSON string presentation of the object</returns>
public string ToJson() {
public string ToJson()
{
return JsonConvert.SerializeObject(this, Formatting.Indented);
}
}
/// <summary>
/// Returns true if objects are equal
/// </summary>
/// <param name="obj">Object to be compared</param>
/// <returns>Boolean</returns>
public override bool Equals(object obj)
{
// credit: http://stackoverflow.com/a/10454552/677735
return this.Equals(obj as Category);
}
/// <summary>
/// Returns true if Category instances are equal
/// </summary>
/// <param name="obj">Instance of Category to be compared</param>
/// <returns>Boolean</returns>
public bool Equals(Category other)
{
// credit: http://stackoverflow.com/a/10454552/677735
if (other == null)
return false;
return
(
this.Id == other.Id ||
this.Id != null &&
this.Id.Equals(other.Id)
) &&
(
this.Name == other.Name ||
this.Name != null &&
this.Name.Equals(other.Name)
);
}
/// <summary>
/// Gets the hash code
/// </summary>
/// <returns>Hash code</returns>
public override int GetHashCode()
{
// credit: http://stackoverflow.com/a/263416/677735
unchecked // Overflow is fine, just wrap
{
int hash = 41;
// Suitable nullity checks etc, of course :)
if (this.Id != null)
hash = hash * 57 + this.Id.GetHashCode();
if (this.Name != null)
hash = hash * 57 + this.Name.GetHashCode();
return hash;
}
}
}
}

View File

@ -1,87 +1,40 @@
using System;
using System.Linq;
using System.IO;
using System.Text;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.Serialization;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
namespace IO.Swagger.Model {
namespace IO.Swagger.Model
{
/// <summary>
///
/// </summary>
[DataContract]
public class Order {
private Id Id;
/// <summary>
/// Gets or Sets Id
/// </summary>
[DataMember(Name="id", EmitDefaultValue=false)]
public Id Id { get; set; }
private PetId PetId;
/// <summary>
/// Gets or Sets PetId
/// </summary>
[DataMember(Name="petId", EmitDefaultValue=false)]
public PetId PetId { get; set; }
private Quantity Quantity;
/// <summary>
/// Gets or Sets Quantity
/// </summary>
[DataMember(Name="quantity", EmitDefaultValue=false)]
public Quantity Quantity { get; set; }
private ShipDate ShipDate;
/// <summary>
/// Gets or Sets ShipDate
/// </summary>
[DataMember(Name="shipDate", EmitDefaultValue=false)]
public ShipDate ShipDate { get; set; }
public class Order : IEquatable<Order>
{
[JsonConverter(typeof(StringEnumConverter))]
public enum Status {
public enum StatusEnum {
[EnumMember("placed")]
[EnumMember(Value = "placed")]
Placed,
[EnumMember("approved")]
[EnumMember(Value = "approved")]
Approved,
[EnumMember("delivered")]
[EnumMember(Value = "delivered")]
Delivered
}
private Status Status;
/// <summary>
/// Order Status
/// </summary>
/// <value>Order Status</value>
[DataMember(Name="status", EmitDefaultValue=false)]
public Status Status { get; set; }
private Complete Complete;
/// <summary>
/// Gets or Sets Complete
/// </summary>
[DataMember(Name="complete", EmitDefaultValue=false)]
public Complete Complete { get; set; }
public StatusEnum Status { get; set; }
/// <summary>
/// Gets or Sets Id
@ -89,62 +42,43 @@ namespace IO.Swagger.Model {
[DataMember(Name="id", EmitDefaultValue=false)]
public long? Id { get; set; }
/// <summary>
/// Gets or Sets PetId
/// </summary>
[DataMember(Name="petId", EmitDefaultValue=false)]
public long? PetId { get; set; }
/// <summary>
/// Gets or Sets Quantity
/// </summary>
[DataMember(Name="quantity", EmitDefaultValue=false)]
public int? Quantity { get; set; }
/// <summary>
/// Gets or Sets ShipDate
/// </summary>
[DataMember(Name="shipDate", EmitDefaultValue=false)]
public DateTime? ShipDate { get; set; }
/// <summary>
/// Order Status
/// </summary>
/// <value>Order Status</value>
[DataMember(Name="status", EmitDefaultValue=false)]
public string Status { get; set; }
/// <summary>
/// Gets or Sets Complete
/// </summary>
[DataMember(Name="complete", EmitDefaultValue=false)]
public bool? Complete { get; set; }
/// <summary>
/// Get the string presentation of the object
/// Returns the string presentation of the object
/// </summary>
/// <returns>String presentation of the object</returns>
public override string ToString() {
public override string ToString()
{
var sb = new StringBuilder();
sb.Append("class Order {\n");
sb.Append(" Id: ").Append(Id).Append("\n");
sb.Append(" PetId: ").Append(PetId).Append("\n");
sb.Append(" Quantity: ").Append(Quantity).Append("\n");
sb.Append(" ShipDate: ").Append(ShipDate).Append("\n");
sb.Append(" Status: ").Append(Status).Append("\n");
sb.Append(" Complete: ").Append(Complete).Append("\n");
sb.Append("}\n");
@ -152,12 +86,102 @@ namespace IO.Swagger.Model {
}
/// <summary>
/// Get the JSON string presentation of the object
/// Returns the JSON string presentation of the object
/// </summary>
/// <returns>JSON string presentation of the object</returns>
public string ToJson() {
public string ToJson()
{
return JsonConvert.SerializeObject(this, Formatting.Indented);
}
}
/// <summary>
/// Returns true if objects are equal
/// </summary>
/// <param name="obj">Object to be compared</param>
/// <returns>Boolean</returns>
public override bool Equals(object obj)
{
// credit: http://stackoverflow.com/a/10454552/677735
return this.Equals(obj as Order);
}
/// <summary>
/// Returns true if Order instances are equal
/// </summary>
/// <param name="obj">Instance of Order to be compared</param>
/// <returns>Boolean</returns>
public bool Equals(Order other)
{
// credit: http://stackoverflow.com/a/10454552/677735
if (other == null)
return false;
return
(
this.Id == other.Id ||
this.Id != null &&
this.Id.Equals(other.Id)
) &&
(
this.PetId == other.PetId ||
this.PetId != null &&
this.PetId.Equals(other.PetId)
) &&
(
this.Quantity == other.Quantity ||
this.Quantity != null &&
this.Quantity.Equals(other.Quantity)
) &&
(
this.ShipDate == other.ShipDate ||
this.ShipDate != null &&
this.ShipDate.Equals(other.ShipDate)
) &&
(
this.Status == other.Status ||
this.Status != null &&
this.Status.Equals(other.Status)
) &&
(
this.Complete == other.Complete ||
this.Complete != null &&
this.Complete.Equals(other.Complete)
);
}
/// <summary>
/// Gets the hash code
/// </summary>
/// <returns>Hash code</returns>
public override int GetHashCode()
{
// credit: http://stackoverflow.com/a/263416/677735
unchecked // Overflow is fine, just wrap
{
int hash = 41;
// Suitable nullity checks etc, of course :)
if (this.Id != null)
hash = hash * 57 + this.Id.GetHashCode();
if (this.PetId != null)
hash = hash * 57 + this.PetId.GetHashCode();
if (this.Quantity != null)
hash = hash * 57 + this.Quantity.GetHashCode();
if (this.ShipDate != null)
hash = hash * 57 + this.ShipDate.GetHashCode();
if (this.Status != null)
hash = hash * 57 + this.Status.GetHashCode();
if (this.Complete != null)
hash = hash * 57 + this.Complete.GetHashCode();
return hash;
}
}
}
}

View File

@ -1,87 +1,40 @@
using System;
using System.Linq;
using System.IO;
using System.Text;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.Serialization;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
namespace IO.Swagger.Model {
namespace IO.Swagger.Model
{
/// <summary>
///
/// </summary>
[DataContract]
public class Pet {
private Id Id;
/// <summary>
/// Gets or Sets Id
/// </summary>
[DataMember(Name="id", EmitDefaultValue=false)]
public Id Id { get; set; }
private Category Category;
/// <summary>
/// Gets or Sets Category
/// </summary>
[DataMember(Name="category", EmitDefaultValue=false)]
public Category Category { get; set; }
private Name Name;
/// <summary>
/// Gets or Sets Name
/// </summary>
[DataMember(Name="name", EmitDefaultValue=false)]
public Name Name { get; set; }
private PhotoUrls PhotoUrls;
/// <summary>
/// Gets or Sets PhotoUrls
/// </summary>
[DataMember(Name="photoUrls", EmitDefaultValue=false)]
public PhotoUrls PhotoUrls { get; set; }
private Tags Tags;
/// <summary>
/// Gets or Sets Tags
/// </summary>
[DataMember(Name="tags", EmitDefaultValue=false)]
public Tags Tags { get; set; }
public class Pet : IEquatable<Pet>
{
[JsonConverter(typeof(StringEnumConverter))]
public enum Status {
public enum StatusEnum {
[EnumMember("available")]
[EnumMember(Value = "available")]
Available,
[EnumMember("pending")]
[EnumMember(Value = "pending")]
Pending,
[EnumMember("sold")]
[EnumMember(Value = "sold")]
Sold
}
private Status Status;
/// <summary>
/// pet status in the store
/// </summary>
/// <value>pet status in the store</value>
[DataMember(Name="status", EmitDefaultValue=false)]
public Status Status { get; set; }
public StatusEnum Status { get; set; }
/// <summary>
/// Gets or Sets Id
@ -89,62 +42,43 @@ namespace IO.Swagger.Model {
[DataMember(Name="id", EmitDefaultValue=false)]
public long? Id { get; set; }
/// <summary>
/// Gets or Sets Category
/// </summary>
[DataMember(Name="category", EmitDefaultValue=false)]
public Category Category { get; set; }
/// <summary>
/// Gets or Sets Name
/// </summary>
[DataMember(Name="name", EmitDefaultValue=false)]
public string Name { get; set; }
/// <summary>
/// Gets or Sets PhotoUrls
/// </summary>
[DataMember(Name="photoUrls", EmitDefaultValue=false)]
public List<string> PhotoUrls { get; set; }
/// <summary>
/// Gets or Sets Tags
/// </summary>
[DataMember(Name="tags", EmitDefaultValue=false)]
public List<Tag> Tags { get; set; }
/// <summary>
/// pet status in the store
/// </summary>
/// <value>pet status in the store</value>
[DataMember(Name="status", EmitDefaultValue=false)]
public string Status { get; set; }
/// <summary>
/// Get the string presentation of the object
/// Returns the string presentation of the object
/// </summary>
/// <returns>String presentation of the object</returns>
public override string ToString() {
public override string ToString()
{
var sb = new StringBuilder();
sb.Append("class Pet {\n");
sb.Append(" Id: ").Append(Id).Append("\n");
sb.Append(" Category: ").Append(Category).Append("\n");
sb.Append(" Name: ").Append(Name).Append("\n");
sb.Append(" PhotoUrls: ").Append(PhotoUrls).Append("\n");
sb.Append(" Tags: ").Append(Tags).Append("\n");
sb.Append(" Status: ").Append(Status).Append("\n");
sb.Append("}\n");
@ -152,12 +86,102 @@ namespace IO.Swagger.Model {
}
/// <summary>
/// Get the JSON string presentation of the object
/// Returns the JSON string presentation of the object
/// </summary>
/// <returns>JSON string presentation of the object</returns>
public string ToJson() {
public string ToJson()
{
return JsonConvert.SerializeObject(this, Formatting.Indented);
}
}
/// <summary>
/// Returns true if objects are equal
/// </summary>
/// <param name="obj">Object to be compared</param>
/// <returns>Boolean</returns>
public override bool Equals(object obj)
{
// credit: http://stackoverflow.com/a/10454552/677735
return this.Equals(obj as Pet);
}
/// <summary>
/// Returns true if Pet instances are equal
/// </summary>
/// <param name="obj">Instance of Pet to be compared</param>
/// <returns>Boolean</returns>
public bool Equals(Pet other)
{
// credit: http://stackoverflow.com/a/10454552/677735
if (other == null)
return false;
return
(
this.Id == other.Id ||
this.Id != null &&
this.Id.Equals(other.Id)
) &&
(
this.Category == other.Category ||
this.Category != null &&
this.Category.Equals(other.Category)
) &&
(
this.Name == other.Name ||
this.Name != null &&
this.Name.Equals(other.Name)
) &&
(
this.PhotoUrls == other.PhotoUrls ||
this.PhotoUrls != null &&
this.PhotoUrls.SequenceEqual(other.PhotoUrls)
) &&
(
this.Tags == other.Tags ||
this.Tags != null &&
this.Tags.SequenceEqual(other.Tags)
) &&
(
this.Status == other.Status ||
this.Status != null &&
this.Status.Equals(other.Status)
);
}
/// <summary>
/// Gets the hash code
/// </summary>
/// <returns>Hash code</returns>
public override int GetHashCode()
{
// credit: http://stackoverflow.com/a/263416/677735
unchecked // Overflow is fine, just wrap
{
int hash = 41;
// Suitable nullity checks etc, of course :)
if (this.Id != null)
hash = hash * 57 + this.Id.GetHashCode();
if (this.Category != null)
hash = hash * 57 + this.Category.GetHashCode();
if (this.Name != null)
hash = hash * 57 + this.Name.GetHashCode();
if (this.PhotoUrls != null)
hash = hash * 57 + this.PhotoUrls.GetHashCode();
if (this.Tags != null)
hash = hash * 57 + this.Tags.GetHashCode();
if (this.Status != null)
hash = hash * 57 + this.Status.GetHashCode();
return hash;
}
}
}
}

View File

@ -1,38 +1,21 @@
using System;
using System.Linq;
using System.IO;
using System.Text;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.Serialization;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
namespace IO.Swagger.Model {
namespace IO.Swagger.Model
{
/// <summary>
///
/// </summary>
[DataContract]
public class Tag {
private Id Id;
/// <summary>
/// Gets or Sets Id
/// </summary>
[DataMember(Name="id", EmitDefaultValue=false)]
public Id Id { get; set; }
private Name Name;
/// <summary>
/// Gets or Sets Name
/// </summary>
[DataMember(Name="name", EmitDefaultValue=false)]
public Name Name { get; set; }
public class Tag : IEquatable<Tag>
{
/// <summary>
/// Gets or Sets Id
@ -40,25 +23,21 @@ namespace IO.Swagger.Model {
[DataMember(Name="id", EmitDefaultValue=false)]
public long? Id { get; set; }
/// <summary>
/// Gets or Sets Name
/// </summary>
[DataMember(Name="name", EmitDefaultValue=false)]
public string Name { get; set; }
/// <summary>
/// Get the string presentation of the object
/// Returns the string presentation of the object
/// </summary>
/// <returns>String presentation of the object</returns>
public override string ToString() {
public override string ToString()
{
var sb = new StringBuilder();
sb.Append("class Tag {\n");
sb.Append(" Id: ").Append(Id).Append("\n");
sb.Append(" Name: ").Append(Name).Append("\n");
sb.Append("}\n");
@ -66,12 +45,70 @@ namespace IO.Swagger.Model {
}
/// <summary>
/// Get the JSON string presentation of the object
/// Returns the JSON string presentation of the object
/// </summary>
/// <returns>JSON string presentation of the object</returns>
public string ToJson() {
public string ToJson()
{
return JsonConvert.SerializeObject(this, Formatting.Indented);
}
}
/// <summary>
/// Returns true if objects are equal
/// </summary>
/// <param name="obj">Object to be compared</param>
/// <returns>Boolean</returns>
public override bool Equals(object obj)
{
// credit: http://stackoverflow.com/a/10454552/677735
return this.Equals(obj as Tag);
}
/// <summary>
/// Returns true if Tag instances are equal
/// </summary>
/// <param name="obj">Instance of Tag to be compared</param>
/// <returns>Boolean</returns>
public bool Equals(Tag other)
{
// credit: http://stackoverflow.com/a/10454552/677735
if (other == null)
return false;
return
(
this.Id == other.Id ||
this.Id != null &&
this.Id.Equals(other.Id)
) &&
(
this.Name == other.Name ||
this.Name != null &&
this.Name.Equals(other.Name)
);
}
/// <summary>
/// Gets the hash code
/// </summary>
/// <returns>Hash code</returns>
public override int GetHashCode()
{
// credit: http://stackoverflow.com/a/263416/677735
unchecked // Overflow is fine, just wrap
{
int hash = 41;
// Suitable nullity checks etc, of course :)
if (this.Id != null)
hash = hash * 57 + this.Id.GetHashCode();
if (this.Name != null)
hash = hash * 57 + this.Name.GetHashCode();
return hash;
}
}
}
}

View File

@ -1,93 +1,21 @@
using System;
using System.Linq;
using System.IO;
using System.Text;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.Serialization;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
namespace IO.Swagger.Model {
namespace IO.Swagger.Model
{
/// <summary>
///
/// </summary>
[DataContract]
public class User {
private Id Id;
/// <summary>
/// Gets or Sets Id
/// </summary>
[DataMember(Name="id", EmitDefaultValue=false)]
public Id Id { get; set; }
private Username Username;
/// <summary>
/// Gets or Sets Username
/// </summary>
[DataMember(Name="username", EmitDefaultValue=false)]
public Username Username { get; set; }
private FirstName FirstName;
/// <summary>
/// Gets or Sets FirstName
/// </summary>
[DataMember(Name="firstName", EmitDefaultValue=false)]
public FirstName FirstName { get; set; }
private LastName LastName;
/// <summary>
/// Gets or Sets LastName
/// </summary>
[DataMember(Name="lastName", EmitDefaultValue=false)]
public LastName LastName { get; set; }
private Email Email;
/// <summary>
/// Gets or Sets Email
/// </summary>
[DataMember(Name="email", EmitDefaultValue=false)]
public Email Email { get; set; }
private Password Password;
/// <summary>
/// Gets or Sets Password
/// </summary>
[DataMember(Name="password", EmitDefaultValue=false)]
public Password Password { get; set; }
private Phone Phone;
/// <summary>
/// Gets or Sets Phone
/// </summary>
[DataMember(Name="phone", EmitDefaultValue=false)]
public Phone Phone { get; set; }
private UserStatus UserStatus;
/// <summary>
/// User Status
/// </summary>
/// <value>User Status</value>
[DataMember(Name="userStatus", EmitDefaultValue=false)]
public UserStatus UserStatus { get; set; }
public class User : IEquatable<User>
{
/// <summary>
/// Gets or Sets Id
@ -95,49 +23,42 @@ namespace IO.Swagger.Model {
[DataMember(Name="id", EmitDefaultValue=false)]
public long? Id { get; set; }
/// <summary>
/// Gets or Sets Username
/// </summary>
[DataMember(Name="username", EmitDefaultValue=false)]
public string Username { get; set; }
/// <summary>
/// Gets or Sets FirstName
/// </summary>
[DataMember(Name="firstName", EmitDefaultValue=false)]
public string FirstName { get; set; }
/// <summary>
/// Gets or Sets LastName
/// </summary>
[DataMember(Name="lastName", EmitDefaultValue=false)]
public string LastName { get; set; }
/// <summary>
/// Gets or Sets Email
/// </summary>
[DataMember(Name="email", EmitDefaultValue=false)]
public string Email { get; set; }
/// <summary>
/// Gets or Sets Password
/// </summary>
[DataMember(Name="password", EmitDefaultValue=false)]
public string Password { get; set; }
/// <summary>
/// Gets or Sets Phone
/// </summary>
[DataMember(Name="phone", EmitDefaultValue=false)]
public string Phone { get; set; }
/// <summary>
/// User Status
/// </summary>
@ -145,30 +66,21 @@ namespace IO.Swagger.Model {
[DataMember(Name="userStatus", EmitDefaultValue=false)]
public int? UserStatus { get; set; }
/// <summary>
/// Get the string presentation of the object
/// Returns the string presentation of the object
/// </summary>
/// <returns>String presentation of the object</returns>
public override string ToString() {
public override string ToString()
{
var sb = new StringBuilder();
sb.Append("class User {\n");
sb.Append(" Id: ").Append(Id).Append("\n");
sb.Append(" Username: ").Append(Username).Append("\n");
sb.Append(" FirstName: ").Append(FirstName).Append("\n");
sb.Append(" LastName: ").Append(LastName).Append("\n");
sb.Append(" Email: ").Append(Email).Append("\n");
sb.Append(" Password: ").Append(Password).Append("\n");
sb.Append(" Phone: ").Append(Phone).Append("\n");
sb.Append(" UserStatus: ").Append(UserStatus).Append("\n");
sb.Append("}\n");
@ -176,12 +88,118 @@ namespace IO.Swagger.Model {
}
/// <summary>
/// Get the JSON string presentation of the object
/// Returns the JSON string presentation of the object
/// </summary>
/// <returns>JSON string presentation of the object</returns>
public string ToJson() {
public string ToJson()
{
return JsonConvert.SerializeObject(this, Formatting.Indented);
}
}
/// <summary>
/// Returns true if objects are equal
/// </summary>
/// <param name="obj">Object to be compared</param>
/// <returns>Boolean</returns>
public override bool Equals(object obj)
{
// credit: http://stackoverflow.com/a/10454552/677735
return this.Equals(obj as User);
}
/// <summary>
/// Returns true if User instances are equal
/// </summary>
/// <param name="obj">Instance of User to be compared</param>
/// <returns>Boolean</returns>
public bool Equals(User other)
{
// credit: http://stackoverflow.com/a/10454552/677735
if (other == null)
return false;
return
(
this.Id == other.Id ||
this.Id != null &&
this.Id.Equals(other.Id)
) &&
(
this.Username == other.Username ||
this.Username != null &&
this.Username.Equals(other.Username)
) &&
(
this.FirstName == other.FirstName ||
this.FirstName != null &&
this.FirstName.Equals(other.FirstName)
) &&
(
this.LastName == other.LastName ||
this.LastName != null &&
this.LastName.Equals(other.LastName)
) &&
(
this.Email == other.Email ||
this.Email != null &&
this.Email.Equals(other.Email)
) &&
(
this.Password == other.Password ||
this.Password != null &&
this.Password.Equals(other.Password)
) &&
(
this.Phone == other.Phone ||
this.Phone != null &&
this.Phone.Equals(other.Phone)
) &&
(
this.UserStatus == other.UserStatus ||
this.UserStatus != null &&
this.UserStatus.Equals(other.UserStatus)
);
}
/// <summary>
/// Gets the hash code
/// </summary>
/// <returns>Hash code</returns>
public override int GetHashCode()
{
// credit: http://stackoverflow.com/a/263416/677735
unchecked // Overflow is fine, just wrap
{
int hash = 41;
// Suitable nullity checks etc, of course :)
if (this.Id != null)
hash = hash * 57 + this.Id.GetHashCode();
if (this.Username != null)
hash = hash * 57 + this.Username.GetHashCode();
if (this.FirstName != null)
hash = hash * 57 + this.FirstName.GetHashCode();
if (this.LastName != null)
hash = hash * 57 + this.LastName.GetHashCode();
if (this.Email != null)
hash = hash * 57 + this.Email.GetHashCode();
if (this.Password != null)
hash = hash * 57 + this.Password.GetHashCode();
if (this.Phone != null)
hash = hash * 57 + this.Phone.GetHashCode();
if (this.UserStatus != null)
hash = hash * 57 + this.UserStatus.GetHashCode();
return hash;
}
}
}
}

View File

@ -2,8 +2,25 @@
<MonoDevelop.Ide.Workspace ActiveConfiguration="Debug" />
<MonoDevelop.Ide.Workbench ActiveDocument="TestPet.cs">
<Files>
<File FileName="TestPet.cs" Line="11" Column="2" />
<File FileName="TestPet.cs" Line="8" Column="25" />
</Files>
<Pads>
<Pad Id="MonoDevelop.NUnit.TestPad">
<State name="__root__">
<Node name="SwaggerClientTest" expanded="True">
<Node name="SwaggerClientTest" expanded="True">
<Node name="SwaggerClient" expanded="True">
<Node name="TestPet" expanded="True">
<Node name="TestPet" expanded="True">
<Node name="TestEqual" selected="True" />
</Node>
</Node>
</Node>
</Node>
</Node>
</State>
</Pad>
</Pads>
</MonoDevelop.Ide.Workbench>
<MonoDevelop.Ide.DebuggingService.Breakpoints>
<BreakpointStore />

View File

@ -1,5 +1,6 @@
using NUnit.Framework;
using System;
using System.Linq;
using System.IO;
using System.Collections.Generic;
using IO.Swagger.Api;
@ -144,6 +145,68 @@ namespace SwaggerClient.TestPet
}
[Test ()]
public void TestEqual()
{
// create pet
Pet p1 = new Pet();
p1.Id = petId;
p1.Name = "Csharp test";
p1.Status = "available";
// create Category object
Category category1 = new Category();
category1.Id = 56;
category1.Name = "sample category name2";
List<String> photoUrls1 = new List<String>(new String[] {"sample photoUrls"});
// create Tag object
Tag tag1 = new Tag();
tag1.Id = petId;
tag1.Name = "sample tag name1";
List<Tag> tags1 = new List<Tag>(new Tag[] {tag1});
p1.Tags = tags1;
p1.Category = category1;
p1.PhotoUrls = photoUrls1;
// create pet 2
Pet p2 = new Pet();
p2.Id = petId;
p2.Name = "Csharp test";
p2.Status = "available";
// create Category object
Category category2 = new Category();
category2.Id = 56;
category2.Name = "sample category name2";
List<String> photoUrls2 = new List<String>(new String[] {"sample photoUrls"});
// create Tag object
Tag tag2 = new Tag();
tag2.Id = petId;
tag2.Name = "sample tag name1";
List<Tag> tags2 = new List<Tag>(new Tag[] {tag2});
p2.Tags = tags2;
p2.Category = category2;
p2.PhotoUrls = photoUrls2;
// p1 and p2 should be equal (both object and attribute level)
Assert.IsTrue (category1.Equals (category2));
Assert.IsTrue (tags1.SequenceEqual (tags2));
Assert.IsTrue (p1.PhotoUrls.SequenceEqual(p2.PhotoUrls));
Assert.IsTrue (p1.Equals (p2));
// update attribute to that p1 and p2 are not equal
category2.Name = "new category name";
Assert.IsFalse(category1.Equals (category2));
tags2 = new List<Tag> ();
Assert.IsFalse (tags1.SequenceEqual (tags2));
// photoUrls has not changed so it should be equal
Assert.IsTrue (p1.PhotoUrls.SequenceEqual(p2.PhotoUrls));
Assert.IsFalse (p1.Equals (p2));
}
}
}

View File

@ -1,8 +1,8 @@
/Users/williamcheng/Code/csharp/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/.NETFramework,Version=v4.5.AssemblyAttribute.cs
/Users/williamcheng/Code/csharp/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/SwaggerClientTest.dll.mdb
/Users/williamcheng/Code/csharp/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/SwaggerClientTest.dll
/Users/williamcheng/Code/csharp/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.dll
/Users/williamcheng/Code/csharp/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.dll.mdb
/Users/williamcheng/Code/csharp/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/Newtonsoft.Json.dll
/Users/williamcheng/Code/csharp/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/nunit.framework.dll
/Users/williamcheng/Code/csharp/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/RestSharp.dll
/Users/williamcheng/Code/wing328/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/.NETFramework,Version=v4.5.AssemblyAttribute.cs
/Users/williamcheng/Code/wing328/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/SwaggerClientTest.dll.mdb
/Users/williamcheng/Code/wing328/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/SwaggerClientTest.dll
/Users/williamcheng/Code/wing328/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.dll
/Users/williamcheng/Code/wing328/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.dll.mdb
/Users/williamcheng/Code/wing328/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/Newtonsoft.Json.dll
/Users/williamcheng/Code/wing328/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/nunit.framework.dll
/Users/williamcheng/Code/wing328/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/RestSharp.dll

View File

@ -148,6 +148,13 @@
<version>${jodatime-version}</version>
</dependency>
<!-- Base64 encoding that works in both JVM and Android -->
<dependency>
<groupId>com.brsanthu</groupId>
<artifactId>migbase64</artifactId>
<version>2.2</version>
</dependency>
<!-- test dependencies -->
<dependency>
<groupId>junit</groupId>

View File

@ -5,7 +5,7 @@ import io.swagger.client.Pair;
import java.util.Map;
import java.util.List;
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-11-19T13:52:16.052+01:00")
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-11-20T17:28:23.285+08:00")
public class ApiKeyAuth implements Authentication {
private final String location;
private final String paramName;
@ -44,6 +44,9 @@ public class ApiKeyAuth implements Authentication {
@Override
public void applyToParams(List<Pair> queryParams, Map<String, String> headerParams) {
if (apiKey == null) {
return;
}
String value;
if (apiKeyPrefix != null) {
value = apiKeyPrefix + " " + apiKey;

View File

@ -2,13 +2,14 @@ package io.swagger.client.auth;
import io.swagger.client.Pair;
import com.migcomponents.migbase64.Base64;
import java.util.Map;
import java.util.List;
import java.io.UnsupportedEncodingException;
import javax.xml.bind.DatatypeConverter;
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-11-19T13:52:16.052+01:00")
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-11-22T13:15:32.345+08:00")
public class HttpBasicAuth implements Authentication {
private String username;
private String password;
@ -31,9 +32,12 @@ public class HttpBasicAuth implements Authentication {
@Override
public void applyToParams(List<Pair> queryParams, Map<String, String> headerParams) {
if (username == null && password == null) {
return;
}
String str = (username == null ? "" : username) + ":" + (password == null ? "" : password);
try {
headerParams.put("Authorization", "Basic " + DatatypeConverter.printBase64Binary(str.getBytes("UTF-8")));
headerParams.put("Authorization", "Basic " + Base64.encodeToString(str.getBytes("UTF-8"), false));
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}

View File

@ -152,6 +152,13 @@
<version>${jodatime-version}</version>
</dependency>
<!-- Base64 encoding that works in both JVM and Android -->
<dependency>
<groupId>com.brsanthu</groupId>
<artifactId>migbase64</artifactId>
<version>2.2</version>
</dependency>
<!-- test dependencies -->
<dependency>
<groupId>junit</groupId>

View File

@ -5,7 +5,7 @@ import io.swagger.client.Pair;
import java.util.Map;
import java.util.List;
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-11-17T11:17:50.535-05:00")
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-11-20T17:28:47.318+08:00")
public class ApiKeyAuth implements Authentication {
private final String location;
private final String paramName;
@ -44,6 +44,9 @@ public class ApiKeyAuth implements Authentication {
@Override
public void applyToParams(List<Pair> queryParams, Map<String, String> headerParams) {
if (apiKey == null) {
return;
}
String value;
if (apiKeyPrefix != null) {
value = apiKeyPrefix + " " + apiKey;

View File

@ -2,13 +2,14 @@ package io.swagger.client.auth;
import io.swagger.client.Pair;
import com.migcomponents.migbase64.Base64;
import java.util.Map;
import java.util.List;
import java.io.UnsupportedEncodingException;
import javax.xml.bind.DatatypeConverter;
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-11-17T11:17:50.535-05:00")
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-11-22T13:15:27.225+08:00")
public class HttpBasicAuth implements Authentication {
private String username;
private String password;
@ -31,9 +32,12 @@ public class HttpBasicAuth implements Authentication {
@Override
public void applyToParams(List<Pair> queryParams, Map<String, String> headerParams) {
if (username == null && password == null) {
return;
}
String str = (username == null ? "" : username) + ":" + (password == null ? "" : password);
try {
headerParams.put("Authorization", "Basic " + DatatypeConverter.printBase64Binary(str.getBytes("UTF-8")));
headerParams.put("Authorization", "Basic " + Base64.encodeToString(str.getBytes("UTF-8"), false));
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}

View File

@ -122,11 +122,6 @@
<artifactId>gson</artifactId>
<version>${gson-version}</version>
</dependency>
<dependency>
<groupId>com.brsanthu</groupId>
<artifactId>migbase64</artifactId>
<version>2.2</version>
</dependency>
<!-- test dependencies -->
<dependency>

View File

@ -64,6 +64,38 @@ import io.swagger.client.auth.ApiKeyAuth;
import io.swagger.client.auth.OAuth;
public class ApiClient {
public static final double JAVA_VERSION;
public static final boolean IS_ANDROID;
public static final int ANDROID_SDK_VERSION;
static {
JAVA_VERSION = Double.parseDouble(System.getProperty("java.specification.version"));
boolean isAndroid;
try {
Class.forName("android.app.Activity");
isAndroid = true;
} catch (ClassNotFoundException e) {
isAndroid = false;
}
IS_ANDROID = isAndroid;
int sdkVersion = 0;
if (IS_ANDROID) {
try {
sdkVersion = Class.forName("android.os.Build$VERSION").getField("SDK_INT").getInt(null);
} catch (Exception e) {
try {
sdkVersion = Integer.parseInt((String) Class.forName("android.os.Build$VERSION").getField("SDK").get(null));
} catch (Exception e2) { }
}
}
ANDROID_SDK_VERSION = sdkVersion;
}
/**
* The datetime format to be used when <code>lenientDatetimeFormat</code> is enabled.
*/
public static final String LENIENT_DATETIME_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSSZ";
private String basePath = "http://petstore.swagger.io/v2";
private boolean lenientOnJson = false;
private boolean debugging = false;
@ -100,8 +132,7 @@ public class ApiClient {
this.dateFormat = new SimpleDateFormat("yyyy-MM-dd");
// Always use UTC as the default time zone when dealing with date (without time).
this.dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
// Use the system's default time zone when dealing with datetime (mainly formatting).
this.datetimeFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX");
initDatetimeFormat();
// Be lenient on datetime formats when parsing datetime from string.
// See <code>parseDatetime</code>.
@ -262,25 +293,30 @@ public class ApiClient {
if (str == null)
return null;
DateFormat format;
if (lenientDatetimeFormat) {
/*
* When lenientDatetimeFormat is enabled, process the given string
* to support various formats defined by ISO 8601.
* When lenientDatetimeFormat is enabled, normalize the date string
* into <code>LENIENT_DATETIME_FORMAT</code> to support various formats
* defined by ISO 8601.
*/
// normalize time zone
// trailing "Z": 2015-08-16T08:20:05Z => 2015-08-16T08:20:05+00:00
str = str.replaceAll("[zZ]\\z", "+00:00");
// add colon: 2015-08-16T08:20:05+0000 => 2015-08-16T08:20:05+00:00
str = str.replaceAll("([+-]\\d{2})(\\d{2})\\z", "$1:$2");
// expand time zone: 2015-08-16T08:20:05+00 => 2015-08-16T08:20:05+00:00
str = str.replaceAll("([+-]\\d{2})\\z", "$1:00");
// trailing "Z": 2015-08-16T08:20:05Z => 2015-08-16T08:20:05+0000
str = str.replaceAll("[zZ]\\z", "+0000");
// remove colon in time zone: 2015-08-16T08:20:05+00:00 => 2015-08-16T08:20:05+0000
str = str.replaceAll("([+-]\\d{2}):(\\d{2})\\z", "$1$2");
// expand time zone: 2015-08-16T08:20:05+00 => 2015-08-16T08:20:05+0000
str = str.replaceAll("([+-]\\d{2})\\z", "$100");
// add milliseconds when missing
// 2015-08-16T08:20:05+00:00 => 2015-08-16T08:20:05.000+00:00
str = str.replaceAll("(:\\d{1,2})([+-]\\d{2}:\\d{2})\\z", "$1.000$2");
// 2015-08-16T08:20:05+0000 => 2015-08-16T08:20:05.000+0000
str = str.replaceAll("(:\\d{1,2})([+-]\\d{4})\\z", "$1.000$2");
format = new SimpleDateFormat(LENIENT_DATETIME_FORMAT);
} else {
format = this.datetimeFormat;
}
try {
return datetimeFormat.parse(str);
return format.parse(str);
} catch (ParseException e) {
throw new RuntimeException(e);
}
@ -915,6 +951,31 @@ public class ApiClient {
}
}
/**
* Initialize datetime format according to the current environment, e.g. Java 1.7 and Android.
*/
private void initDatetimeFormat() {
String formatWithTimeZone = null;
if (IS_ANDROID) {
if (ANDROID_SDK_VERSION >= 18) {
// The time zone format "ZZZZZ" is available since Android 4.3 (SDK version 18)
formatWithTimeZone = "yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ";
}
} else if (JAVA_VERSION >= 1.7) {
// The time zone format "XXX" is available since Java 1.7
formatWithTimeZone = "yyyy-MM-dd'T'HH:mm:ss.SSSXXX";
}
if (formatWithTimeZone != null) {
this.datetimeFormat = new SimpleDateFormat(formatWithTimeZone);
// NOTE: Use the system's default time zone (mainly for datetime formatting).
} else {
// Use a common format that works across all systems.
this.datetimeFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
// Always use the UTC time zone as we are using a constant trailing "Z" here.
this.datetimeFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
}
}
/**
* Apply SSL related settings to httpClient according to the current values of
* verifyingSsl and sslCaCert.

View File

@ -5,7 +5,7 @@ import io.swagger.client.Pair;
import java.util.Map;
import java.util.List;
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-10-20T11:42:25.339-07:00")
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-11-20T17:28:54.086+08:00")
public class ApiKeyAuth implements Authentication {
private final String location;
private final String paramName;
@ -44,6 +44,9 @@ public class ApiKeyAuth implements Authentication {
@Override
public void applyToParams(List<Pair> queryParams, Map<String, String> headerParams) {
if (apiKey == null) {
return;
}
String value;
if (apiKeyPrefix != null) {
value = apiKeyPrefix + " " + apiKey;

View File

@ -2,7 +2,7 @@ package io.swagger.client.auth;
import io.swagger.client.Pair;
import com.migcomponents.migbase64.Base64;
import com.squareup.okhttp.Credentials;
import java.util.Map;
import java.util.List;
@ -31,11 +31,11 @@ public class HttpBasicAuth implements Authentication {
@Override
public void applyToParams(List<Pair> queryParams, Map<String, String> headerParams) {
String str = (username == null ? "" : username) + ":" + (password == null ? "" : password);
try {
headerParams.put("Authorization", "Basic " + Base64.encodeToString(str.getBytes("UTF-8"), false));
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
if (username == null && password == null) {
return;
}
headerParams.put("Authorization", Credentials.basic(
username == null ? "" : username,
password == null ? "" : password));
}
}

View File

@ -29,6 +29,20 @@ public class ApiKeyAuthTest {
assertEquals(0, headerParams.size());
}
@Test
public void testApplyToParamsInQueryWithNullValue() {
List<Pair> queryParams = new ArrayList<Pair>();
Map<String, String> headerParams = new HashMap<String, String>();
ApiKeyAuth auth = new ApiKeyAuth("query", "api_key");
auth.setApiKey(null);
auth.applyToParams(queryParams, headerParams);
// no changes to parameters
assertEquals(0, queryParams.size());
assertEquals(0, headerParams.size());
}
@Test
public void testApplyToParamsInHeaderWithPrefix() {
List<Pair> queryParams = new ArrayList<Pair>();
@ -44,4 +58,19 @@ public class ApiKeyAuthTest {
assertEquals(1, headerParams.size());
assertEquals("Token my-api-token", headerParams.get("X-API-TOKEN"));
}
@Test
public void testApplyToParamsInHeaderWithNullValue() {
List<Pair> queryParams = new ArrayList<Pair>();
Map<String, String> headerParams = new HashMap<String, String>();
ApiKeyAuth auth = new ApiKeyAuth("header", "X-API-TOKEN");
auth.setApiKey(null);
auth.setApiKeyPrefix("Token");
auth.applyToParams(queryParams, headerParams);
// no changes to parameters
assertEquals(0, queryParams.size());
assertEquals(0, headerParams.size());
}
}

View File

@ -48,5 +48,15 @@ public class HttpBasicAuthTest {
// the string below is base64-encoded result of "my-username:" with the "Basic " prefix
expected = "Basic bXktdXNlcm5hbWU6";
assertEquals(expected, headerParams.get("Authorization"));
// null username and password should be ignored
queryParams = new ArrayList<Pair>();
headerParams = new HashMap<String, String>();
auth.setUsername(null);
auth.setPassword(null);
auth.applyToParams(queryParams, headerParams);
// no changes to parameters
assertEquals(0, queryParams.size());
assertEquals(0, headerParams.size());
}
}

View File

@ -317,15 +317,21 @@ sub update_params_for_auth {
foreach my $auth (@$auth_settings) {
# determine which one to use
if (!defined($auth)) {
# TODO show warning about auth setting not defined
}
elsif ($auth eq 'api_key') {
$header_params->{'api_key'} = $self->get_api_key_with_prefix('api_key');
my $api_key = $self->get_api_key_with_prefix('api_key');
if ($api_key) {
$header_params->{'api_key'} = $api_key;
}
}
elsif ($auth eq 'petstore_auth') {
if ($WWW::SwaggerClient::Configuration::access_token) {
$header_params->{'Authorization'} = 'Bearer ' . $WWW::SwaggerClient::Configuration::access_token;
}
}
else {
# TODO show warning about security definition not found

View File

@ -37,7 +37,7 @@ has version_info => ( is => 'ro',
default => sub { {
app_name => 'Swagger Petstore',
app_version => '1.0.0',
generated_date => '2015-11-13T20:46:43.271Z',
generated_date => '2015-11-20T17:35:18.902+08:00',
generator_class => 'class io.swagger.codegen.languages.PerlClientCodegen',
} },
documentation => 'Information about the application version and the codegen codebase version'
@ -103,7 +103,7 @@ Automatically generated by the Perl Swagger Codegen project:
=over 4
=item Build date: 2015-11-13T20:46:43.271Z
=item Build date: 2015-11-20T17:35:18.902+08:00
=item Build package: class io.swagger.codegen.languages.PerlClientCodegen

View File

@ -135,8 +135,10 @@ class PetApi
$httpBody = $formParams; // for HTTP post (form)
}
// this endpoint requires OAuth (access token)
if ($this->apiClient->getConfig()->getAccessToken() !== null) {
$headerParams['Authorization'] = 'Bearer ' . $this->apiClient->getConfig()->getAccessToken();
}
// make the API Call
try
@ -200,8 +202,10 @@ class PetApi
$httpBody = $formParams; // for HTTP post (form)
}
// this endpoint requires OAuth (access token)
if ($this->apiClient->getConfig()->getAccessToken() !== null) {
$headerParams['Authorization'] = 'Bearer ' . $this->apiClient->getConfig()->getAccessToken();
}
// make the API Call
try
@ -264,8 +268,10 @@ class PetApi
$httpBody = $formParams; // for HTTP post (form)
}
// this endpoint requires OAuth (access token)
if ($this->apiClient->getConfig()->getAccessToken() !== null) {
$headerParams['Authorization'] = 'Bearer ' . $this->apiClient->getConfig()->getAccessToken();
}
// make the API Call
try
@ -340,8 +346,10 @@ class PetApi
$httpBody = $formParams; // for HTTP post (form)
}
// this endpoint requires OAuth (access token)
if ($this->apiClient->getConfig()->getAccessToken() !== null) {
$headerParams['Authorization'] = 'Bearer ' . $this->apiClient->getConfig()->getAccessToken();
}
// make the API Call
try
@ -424,13 +432,13 @@ class PetApi
$httpBody = $formParams; // for HTTP post (form)
}
// this endpoint requires API key authentication
$apiKey = $this->apiClient->getApiKeyWithPrefix('api_key');
if (isset($apiKey)) {
if ($apiKey !== null) {
$headerParams['api_key'] = $apiKey;
}
// make the API Call
try
{
@ -526,8 +534,10 @@ class PetApi
$httpBody = $formParams; // for HTTP post (form)
}
// this endpoint requires OAuth (access token)
if ($this->apiClient->getConfig()->getAccessToken() !== null) {
$headerParams['Authorization'] = 'Bearer ' . $this->apiClient->getConfig()->getAccessToken();
}
// make the API Call
try
@ -602,8 +612,10 @@ class PetApi
$httpBody = $formParams; // for HTTP post (form)
}
// this endpoint requires OAuth (access token)
if ($this->apiClient->getConfig()->getAccessToken() !== null) {
$headerParams['Authorization'] = 'Bearer ' . $this->apiClient->getConfig()->getAccessToken();
}
// make the API Call
try
@ -694,8 +706,10 @@ class PetApi
$httpBody = $formParams; // for HTTP post (form)
}
// this endpoint requires OAuth (access token)
if ($this->apiClient->getConfig()->getAccessToken() !== null) {
$headerParams['Authorization'] = 'Bearer ' . $this->apiClient->getConfig()->getAccessToken();
}
// make the API Call
try

View File

@ -130,13 +130,13 @@ class StoreApi
$httpBody = $formParams; // for HTTP post (form)
}
// this endpoint requires API key authentication
$apiKey = $this->apiClient->getApiKeyWithPrefix('api_key');
if (isset($apiKey)) {
if ($apiKey !== null) {
$headerParams['api_key'] = $apiKey;
}
// make the API Call
try
{

View File

@ -69,7 +69,7 @@ class ApiClient
* Constructor of the class
* @param Configuration $config config for this ApiClient
*/
function __construct(Configuration $config = null)
public function __construct(Configuration $config = null)
{
if ($config == null) {
$config = Configuration::getDefaultConfiguration();

View File

@ -193,7 +193,7 @@ class ObjectSerializer
$deserialized = $values;
} elseif ($class === '\DateTime') {
$deserialized = new \DateTime($data);
} elseif (in_array($class, array('void', 'bool', 'string', 'double', 'byte', 'mixed', 'integer', 'float', 'int', 'DateTime', 'number', 'boolean', 'object'))) {
} elseif (in_array($class, array('integer', 'int', 'void', 'number', 'object', 'double', 'float', 'byte', 'DateTime', 'string', 'mixed', 'boolean', 'bool'))) {
settype($data, $class);
$deserialized = $data;
} elseif ($class === '\SplFileObject') {

File diff suppressed because one or more lines are too long

View File

@ -20,3 +20,17 @@ Requirement already satisfied (use --upgrade to upgrade): randomize in ./.venv/l
Requirement already satisfied (use --upgrade to upgrade): virtualenv>=1.11.2 in ./.venv/lib/python2.7/site-packages (from tox->-r dev-requirements.txt (line 2))
Requirement already satisfied (use --upgrade to upgrade): py>=1.4.17 in ./.venv/lib/python2.7/site-packages (from tox->-r dev-requirements.txt (line 2))
Requirement already satisfied (use --upgrade to upgrade): pluggy<0.4.0,>=0.3.0 in ./.venv/lib/python2.7/site-packages (from tox->-r dev-requirements.txt (line 2))
Requirement already satisfied (use --upgrade to upgrade): nose in ./venv/lib/python2.7/site-packages (from -r dev-requirements.txt (line 1))
Requirement already satisfied (use --upgrade to upgrade): tox in ./venv/lib/python2.7/site-packages (from -r dev-requirements.txt (line 2))
Requirement already satisfied (use --upgrade to upgrade): coverage in ./venv/lib/python2.7/site-packages (from -r dev-requirements.txt (line 3))
Requirement already satisfied (use --upgrade to upgrade): randomize in ./venv/lib/python2.7/site-packages (from -r dev-requirements.txt (line 4))
Requirement already satisfied (use --upgrade to upgrade): virtualenv>=1.11.2 in ./venv/lib/python2.7/site-packages (from tox->-r dev-requirements.txt (line 2))
Requirement already satisfied (use --upgrade to upgrade): py>=1.4.17 in ./venv/lib/python2.7/site-packages (from tox->-r dev-requirements.txt (line 2))
Requirement already satisfied (use --upgrade to upgrade): pluggy<0.4.0,>=0.3.0 in ./venv/lib/python2.7/site-packages (from tox->-r dev-requirements.txt (line 2))
Requirement already satisfied (use --upgrade to upgrade): nose in ./venv/lib/python2.7/site-packages (from -r dev-requirements.txt (line 1))
Requirement already satisfied (use --upgrade to upgrade): tox in ./venv/lib/python2.7/site-packages (from -r dev-requirements.txt (line 2))
Requirement already satisfied (use --upgrade to upgrade): coverage in ./venv/lib/python2.7/site-packages (from -r dev-requirements.txt (line 3))
Requirement already satisfied (use --upgrade to upgrade): randomize in ./venv/lib/python2.7/site-packages (from -r dev-requirements.txt (line 4))
Requirement already satisfied (use --upgrade to upgrade): virtualenv>=1.11.2 in ./venv/lib/python2.7/site-packages (from tox->-r dev-requirements.txt (line 2))
Requirement already satisfied (use --upgrade to upgrade): py>=1.4.17 in ./venv/lib/python2.7/site-packages (from tox->-r dev-requirements.txt (line 2))
Requirement already satisfied (use --upgrade to upgrade): pluggy<0.4.0,>=0.3.0 in ./venv/lib/python2.7/site-packages (from tox->-r dev-requirements.txt (line 2))

View File

@ -453,7 +453,9 @@ class ApiClient(object):
for auth in auth_settings:
auth_setting = config.auth_settings().get(auth)
if auth_setting:
if auth_setting['in'] == 'header':
if not auth_setting['value']:
continue
elif auth_setting['in'] == 'header':
headers[auth_setting['key']] = auth_setting['value']
elif auth_setting['in'] == 'query':
querys[auth_setting['key']] = auth_setting['value']

View File

@ -79,6 +79,7 @@ class PetApi(object):
params[key] = val
del params['kwargs']
resource_path = '/pet'.replace('{format}', 'json')
method = 'PUT'
@ -154,6 +155,7 @@ class PetApi(object):
params[key] = val
del params['kwargs']
resource_path = '/pet'.replace('{format}', 'json')
method = 'POST'
@ -229,6 +231,7 @@ class PetApi(object):
params[key] = val
del params['kwargs']
resource_path = '/pet/findByStatus'.replace('{format}', 'json')
method = 'GET'
@ -304,6 +307,7 @@ class PetApi(object):
params[key] = val
del params['kwargs']
resource_path = '/pet/findByTags'.replace('{format}', 'json')
method = 'GET'
@ -365,9 +369,6 @@ class PetApi(object):
If the method is called asynchronously,
returns the request thread.
"""
# verify the required parameter 'pet_id' is set
if pet_id is None:
raise ValueError("Missing the required parameter `pet_id` when calling `get_pet_by_id`")
all_params = ['pet_id']
all_params.append('callback')
@ -382,6 +383,10 @@ class PetApi(object):
params[key] = val
del params['kwargs']
# verify the required parameter 'pet_id' is set
if ('pet_id' not in params) or (params['pet_id'] is None):
raise ValueError("Missing the required parameter `pet_id` when calling `get_pet_by_id`")
resource_path = '/pet/{petId}'.replace('{format}', 'json')
method = 'GET'
@ -445,9 +450,6 @@ class PetApi(object):
If the method is called asynchronously,
returns the request thread.
"""
# verify the required parameter 'pet_id' is set
if pet_id is None:
raise ValueError("Missing the required parameter `pet_id` when calling `update_pet_with_form`")
all_params = ['pet_id', 'name', 'status']
all_params.append('callback')
@ -462,6 +464,10 @@ class PetApi(object):
params[key] = val
del params['kwargs']
# verify the required parameter 'pet_id' is set
if ('pet_id' not in params) or (params['pet_id'] is None):
raise ValueError("Missing the required parameter `pet_id` when calling `update_pet_with_form`")
resource_path = '/pet/{petId}'.replace('{format}', 'json')
method = 'POST'
@ -528,9 +534,6 @@ class PetApi(object):
If the method is called asynchronously,
returns the request thread.
"""
# verify the required parameter 'pet_id' is set
if pet_id is None:
raise ValueError("Missing the required parameter `pet_id` when calling `delete_pet`")
all_params = ['pet_id', 'api_key']
all_params.append('callback')
@ -545,6 +548,10 @@ class PetApi(object):
params[key] = val
del params['kwargs']
# verify the required parameter 'pet_id' is set
if ('pet_id' not in params) or (params['pet_id'] is None):
raise ValueError("Missing the required parameter `pet_id` when calling `delete_pet`")
resource_path = '/pet/{petId}'.replace('{format}', 'json')
method = 'DELETE'
@ -610,9 +617,6 @@ class PetApi(object):
If the method is called asynchronously,
returns the request thread.
"""
# verify the required parameter 'pet_id' is set
if pet_id is None:
raise ValueError("Missing the required parameter `pet_id` when calling `upload_file`")
all_params = ['pet_id', 'additional_metadata', 'file']
all_params.append('callback')
@ -627,6 +631,10 @@ class PetApi(object):
params[key] = val
del params['kwargs']
# verify the required parameter 'pet_id' is set
if ('pet_id' not in params) or (params['pet_id'] is None):
raise ValueError("Missing the required parameter `pet_id` when calling `upload_file`")
resource_path = '/pet/{petId}/uploadImage'.replace('{format}', 'json')
method = 'POST'

View File

@ -78,6 +78,7 @@ class StoreApi(object):
params[key] = val
del params['kwargs']
resource_path = '/store/inventory'.replace('{format}', 'json')
method = 'GET'
@ -151,6 +152,7 @@ class StoreApi(object):
params[key] = val
del params['kwargs']
resource_path = '/store/order'.replace('{format}', 'json')
method = 'POST'
@ -212,9 +214,6 @@ class StoreApi(object):
If the method is called asynchronously,
returns the request thread.
"""
# verify the required parameter 'order_id' is set
if order_id is None:
raise ValueError("Missing the required parameter `order_id` when calling `get_order_by_id`")
all_params = ['order_id']
all_params.append('callback')
@ -229,6 +228,10 @@ class StoreApi(object):
params[key] = val
del params['kwargs']
# verify the required parameter 'order_id' is set
if ('order_id' not in params) or (params['order_id'] is None):
raise ValueError("Missing the required parameter `order_id` when calling `get_order_by_id`")
resource_path = '/store/order/{orderId}'.replace('{format}', 'json')
method = 'GET'
@ -290,9 +293,6 @@ class StoreApi(object):
If the method is called asynchronously,
returns the request thread.
"""
# verify the required parameter 'order_id' is set
if order_id is None:
raise ValueError("Missing the required parameter `order_id` when calling `delete_order`")
all_params = ['order_id']
all_params.append('callback')
@ -307,6 +307,10 @@ class StoreApi(object):
params[key] = val
del params['kwargs']
# verify the required parameter 'order_id' is set
if ('order_id' not in params) or (params['order_id'] is None):
raise ValueError("Missing the required parameter `order_id` when calling `delete_order`")
resource_path = '/store/order/{orderId}'.replace('{format}', 'json')
method = 'DELETE'

View File

@ -79,6 +79,7 @@ class UserApi(object):
params[key] = val
del params['kwargs']
resource_path = '/user'.replace('{format}', 'json')
method = 'POST'
@ -154,6 +155,7 @@ class UserApi(object):
params[key] = val
del params['kwargs']
resource_path = '/user/createWithArray'.replace('{format}', 'json')
method = 'POST'
@ -229,6 +231,7 @@ class UserApi(object):
params[key] = val
del params['kwargs']
resource_path = '/user/createWithList'.replace('{format}', 'json')
method = 'POST'
@ -305,6 +308,7 @@ class UserApi(object):
params[key] = val
del params['kwargs']
resource_path = '/user/login'.replace('{format}', 'json')
method = 'GET'
@ -381,6 +385,7 @@ class UserApi(object):
params[key] = val
del params['kwargs']
resource_path = '/user/logout'.replace('{format}', 'json')
method = 'GET'
@ -440,9 +445,6 @@ class UserApi(object):
If the method is called asynchronously,
returns the request thread.
"""
# verify the required parameter 'username' is set
if username is None:
raise ValueError("Missing the required parameter `username` when calling `get_user_by_name`")
all_params = ['username']
all_params.append('callback')
@ -457,6 +459,10 @@ class UserApi(object):
params[key] = val
del params['kwargs']
# verify the required parameter 'username' is set
if ('username' not in params) or (params['username'] is None):
raise ValueError("Missing the required parameter `username` when calling `get_user_by_name`")
resource_path = '/user/{username}'.replace('{format}', 'json')
method = 'GET'
@ -519,9 +525,6 @@ class UserApi(object):
If the method is called asynchronously,
returns the request thread.
"""
# verify the required parameter 'username' is set
if username is None:
raise ValueError("Missing the required parameter `username` when calling `update_user`")
all_params = ['username', 'body']
all_params.append('callback')
@ -536,6 +539,10 @@ class UserApi(object):
params[key] = val
del params['kwargs']
# verify the required parameter 'username' is set
if ('username' not in params) or (params['username'] is None):
raise ValueError("Missing the required parameter `username` when calling `update_user`")
resource_path = '/user/{username}'.replace('{format}', 'json')
method = 'PUT'
@ -599,9 +606,6 @@ class UserApi(object):
If the method is called asynchronously,
returns the request thread.
"""
# verify the required parameter 'username' is set
if username is None:
raise ValueError("Missing the required parameter `username` when calling `delete_user`")
all_params = ['username']
all_params.append('callback')
@ -616,6 +620,10 @@ class UserApi(object):
params[key] = val
del params['kwargs']
# verify the required parameter 'username' is set
if ('username' not in params) or (params['username'] is None):
raise ValueError("Missing the required parameter `username` when calling `delete_user`")
resource_path = '/user/{username}'.replace('{format}', 'json')
method = 'DELETE'