Merge branch 'master' into java-local-var

This commit is contained in:
xhh 2016-03-01 12:06:44 +08:00
commit 8e937bd0a8
34 changed files with 863 additions and 565 deletions

View File

@ -705,6 +705,7 @@ Here are some companies/projects using Swagger Codegen in production. To add you
- [StyleRecipe](http://stylerecipe.co.jp)
- [ThoughtWorks](https://www.thoughtworks.com)
- [uShip](https://www.uship.com/)
- [Zalando](https://tech.zalando.com)
- [ZEEF.com](https://zeef.com/)
License

View File

@ -5,18 +5,11 @@ import io.airlift.airline.Option;
import io.swagger.codegen.ClientOptInput;
import io.swagger.codegen.CodegenConstants;
import io.swagger.codegen.DefaultGenerator;
import io.swagger.codegen.utils.OptionUtils;
import io.swagger.codegen.config.CodegenConfigurator;
import org.apache.commons.lang3.tuple.Pair;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import static io.swagger.codegen.config.CodegenConfiguratorUtils.*;
import static org.apache.commons.lang3.StringUtils.isNotEmpty;
/**
@ -190,74 +183,15 @@ public class Generate implements Runnable {
configurator.setLibrary(library);
}
setSystemProperties(configurator);
setInstantiationTypes(configurator);
setImportMappings(configurator);
setTypeMappings(configurator);
setAdditionalProperties(configurator);
setLanguageSpecificPrimitives(configurator);
applySystemPropertiesKvp(systemProperties, configurator);
applyInstantiationTypesKvp(instantiationTypes, configurator);
applyImportMappingsKvp(importMappings, configurator);
applyTypeMappingsKvp(typeMappings, configurator);
applyAdditionalPropertiesKvp(additionalProperties, configurator);
applyLanguageSpecificPrimitivesCsv(languageSpecificPrimitives, configurator);
final ClientOptInput clientOptInput = configurator.toClientOptInput();
new DefaultGenerator().opts(clientOptInput).generate();
}
private void setSystemProperties(CodegenConfigurator configurator) {
final Map<String, String> map = createMapFromKeyValuePairs(systemProperties);
for (Map.Entry<String, String> entry : map.entrySet()) {
configurator.addSystemProperty(entry.getKey(), entry.getValue());
}
}
private void setInstantiationTypes(CodegenConfigurator configurator) {
final Map<String, String> map = createMapFromKeyValuePairs(instantiationTypes);
for (Map.Entry<String, String> entry : map.entrySet()) {
configurator.addInstantiationType(entry.getKey(), entry.getValue());
}
}
private void setImportMappings(CodegenConfigurator configurator) {
final Map<String, String> map = createMapFromKeyValuePairs(importMappings);
for (Map.Entry<String, String> entry : map.entrySet()) {
configurator.addImportMapping(entry.getKey(), entry.getValue());
}
}
private void setTypeMappings(CodegenConfigurator configurator) {
final Map<String, String> map = createMapFromKeyValuePairs(typeMappings);
for (Map.Entry<String, String> entry : map.entrySet()) {
configurator.addTypeMapping(entry.getKey(), entry.getValue());
}
}
private void setAdditionalProperties(CodegenConfigurator configurator) {
final Map<String, String> map = createMapFromKeyValuePairs(additionalProperties);
for (Map.Entry<String, String> entry : map.entrySet()) {
configurator.addAdditionalProperty(entry.getKey(), entry.getValue());
}
}
private void setLanguageSpecificPrimitives(CodegenConfigurator configurator) {
final Set<String> set = createSetFromCsvList(languageSpecificPrimitives);
for (String item : set) {
configurator.addLanguageSpecificPrimitive(item);
}
}
private static Set<String> createSetFromCsvList(String csvProperty) {
final List<String> values = OptionUtils.splitCommaSeparatedList(csvProperty);
return new HashSet<String>(values);
}
private static Map<String, String> createMapFromKeyValuePairs(String commaSeparatedKVPairs) {
final List<Pair<String, String>> pairs = OptionUtils.parseCommaSeparatedTuples(commaSeparatedKVPairs);
Map<String, String> result = new HashMap<String, String>();
for (Pair<String, String> pair : pairs) {
result.put(pair.getLeft(), pair.getRight());
}
return result;
}
}

View File

@ -1,16 +0,0 @@
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";
public static final String MODEL_PACKAGE_PARAM = "modelPackage";
public static final String API_PACKAGE_PARAM = "apiPackage";
public static final String INVOKER_PACKAGE_PARAM = "invokerPackage";
public static final String LIBRARY_PARAM = "library";
private AdditionalParams() {}
}

View File

@ -16,13 +16,13 @@ package io.swagger.codegen.plugin;
* limitations under the License.
*/
import config.Config;
import config.ConfigParser;
import io.swagger.codegen.*;
import io.swagger.codegen.utils.OptionUtils;
import io.swagger.codegen.CliOption;
import io.swagger.codegen.ClientOptInput;
import io.swagger.codegen.CodegenConfig;
import io.swagger.codegen.DefaultGenerator;
import io.swagger.codegen.config.CodegenConfigurator;
import io.swagger.models.Swagger;
import io.swagger.parser.SwaggerParser;
import org.apache.commons.lang3.tuple.Pair;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.LifecyclePhase;
@ -33,17 +33,27 @@ import org.apache.maven.project.MavenProject;
import java.io.File;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import static io.swagger.codegen.plugin.AdditionalParams.*;
import static io.swagger.codegen.config.CodegenConfiguratorUtils.*;
import static org.apache.commons.lang3.StringUtils.isNotEmpty;
/**
* Goal which generates client/server code from a swagger json/yaml definition.
*/
@Mojo(name = "generate", defaultPhase = LifecyclePhase.GENERATE_SOURCES)
public class CodeGenMojo extends AbstractMojo {
@Parameter(name="verbose", required = false, defaultValue = "false")
private boolean verbose;
/**
* Client language to generate.
*/
@Parameter(name = "language", required = true)
private String language;
/**
* Location of the output directory.
*/
@ -65,10 +75,23 @@ public class CodeGenMojo extends AbstractMojo {
private File templateDirectory;
/**
* The package to use for generated model objects/classes
* Adds authorization headers when fetching the swagger definitions remotely.
" Pass in a URL-encoded string of name:header with a comma separating multiple values
*/
@Parameter(name = "modelPackage")
private String modelPackage;
@Parameter(name="auth")
private String auth;
/**
* Path to separate json configuration file.
*/
@Parameter(name = "configurationFile", required = false)
private String configurationFile;
/**
* Specifies if the existing files should be overwritten during the generation.
*/
@Parameter(name="skipOverwrite", required=false)
private Boolean skipOverwrite;
/**
* The package to use for generated api objects/classes
@ -76,6 +99,12 @@ public class CodeGenMojo extends AbstractMojo {
@Parameter(name = "apiPackage")
private String apiPackage;
/**
* The package to use for generated model objects/classes
*/
@Parameter(name = "modelPackage")
private String modelPackage;
/**
* The package to use for the generated invoker objects
*/
@ -83,16 +112,22 @@ public class CodeGenMojo extends AbstractMojo {
private String invokerPackage;
/**
* Client language to generate.
* groupId in generated pom.xml
*/
@Parameter(name = "language", required = true)
private String language;
@Parameter(name = "groupId")
private String groupId;
/**
* Path to separate json configuration file.
* artifactId in generated pom.xml
*/
@Parameter(name = "configurationFile", required = false)
private String configurationFile;
@Parameter(name = "artifactId")
private String artifactId;
/**
* artifact version in generated pom.xml
*/
@Parameter(name = "artifactVersion")
private String artifactVersion;
/**
* Sets the library
@ -127,12 +162,92 @@ public class CodeGenMojo extends AbstractMojo {
@Override
public void execute() throws MojoExecutionException {
Swagger swagger = new SwaggerParser().read(inputSpec);
CodegenConfig config = CodegenConfigLoader.forName(language);
config.setOutputDir(output.getAbsolutePath());
//attempt to read from config file
CodegenConfigurator configurator = CodegenConfigurator.fromFile(configurationFile);
//if a config file wasn't specified or we were unable to read it
if(configurator == null) {
configurator = new CodegenConfigurator();
}
configurator.setVerbose(verbose);
if(skipOverwrite != null) {
configurator.setSkipOverwrite(skipOverwrite);
}
if(isNotEmpty(inputSpec)) {
configurator.setInputSpec(inputSpec);
}
configurator.setLang(language);
configurator.setOutputDir(output.getAbsolutePath());
if(isNotEmpty(auth)) {
configurator.setAuth(auth);
}
if(isNotEmpty(apiPackage)) {
configurator.setApiPackage(apiPackage);
}
if(isNotEmpty(modelPackage)) {
configurator.setModelPackage(modelPackage);
}
if(isNotEmpty(invokerPackage)) {
configurator.setInvokerPackage(invokerPackage);
}
if(isNotEmpty(groupId)) {
configurator.setGroupId(groupId);
}
if(isNotEmpty(artifactId)) {
configurator.setArtifactId(artifactId);
}
if(isNotEmpty(artifactVersion)) {
configurator.setArtifactVersion(artifactVersion);
}
if(isNotEmpty(library)) {
configurator.setLibrary(library);
}
if (null != templateDirectory) {
configurator.setTemplateDir(templateDirectory.getAbsolutePath());
}
if (configOptions != null) {
if(configOptions.containsKey("instantiation-types")) {
applyInstantiationTypesKvp(configOptions.get("instantiation-types").toString(), configurator);
}
if(configOptions.containsKey("import-mappings")) {
applyImportMappingsKvp(configOptions.get("import-mappings").toString(), configurator);
}
if(configOptions.containsKey("type-mappings")) {
applyTypeMappingsKvp(configOptions.get("type-mappings").toString(), configurator);
}
if(configOptions.containsKey("language-specific-primitives")) {
applyLanguageSpecificPrimitivesCsv(configOptions.get("language-specific-primitives").toString(), configurator);
}
if(configOptions.containsKey("additional-properties")) {
applyAdditionalPropertiesKvp(configOptions.get("additional-properties").toString(), configurator);
}
}
if (environmentVariables != null) {
for(String key : environmentVariables.keySet()) {
String value = environmentVariables.get(key);
if(value == null) {
@ -140,58 +255,21 @@ public class CodeGenMojo extends AbstractMojo {
value = "";
}
System.setProperty(key, value);
}
}
if (null != library) {
config.setLibrary(library);
}
if (null != templateDirectory) {
config.additionalProperties().put(TEMPLATE_DIR_PARAM, templateDirectory.getAbsolutePath());
}
if (null != modelPackage) {
config.additionalProperties().put(MODEL_PACKAGE_PARAM, modelPackage);
}
if (null != apiPackage) {
config.additionalProperties().put(API_PACKAGE_PARAM, apiPackage);
}
if (null != invokerPackage) {
config.additionalProperties().put(INVOKER_PACKAGE_PARAM, invokerPackage);
}
Set<String> definedOptions = new HashSet<String>();
for (CliOption langCliOption : config.cliOptions()) {
definedOptions.add(langCliOption.getOpt());
}
if (configOptions != null) {
if(configOptions.containsKey("import-mappings")) {
Map<String, String> mappings = createMapFromKeyValuePairs(configOptions.remove("import-mappings").toString());
config.importMapping().putAll(mappings);
}
if(configOptions.containsKey("type-mappings")) {
Map<String, String> mappings = createMapFromKeyValuePairs(configOptions.remove("type-mappings").toString());
config.typeMapping().putAll(mappings);
}
if(configOptions.containsKey("instantiation-types")) {
Map<String, String> mappings = createMapFromKeyValuePairs(configOptions.remove("instantiation-types").toString());
config.instantiationTypes().putAll(mappings);
}
addAdditionalProperties(config, definedOptions, configOptions);
}
if (null != configurationFile) {
Config genConfig = ConfigParser.read(configurationFile);
if (null != genConfig) {
addAdditionalProperties(config, definedOptions, genConfig.getOptions());
} else {
throw new RuntimeException("Unable to read configuration file");
configurator.addSystemProperty(key, value);
}
}
ClientOptInput input = new ClientOptInput().opts(new ClientOpts()).swagger(swagger);
input.setConfig(config);
final ClientOptInput input = configurator.toClientOptInput();
final CodegenConfig config = input.getConfig();
if(configOptions != null) {
for (CliOption langCliOption : config.cliOptions()) {
if (configOptions.containsKey(langCliOption.getOpt())) {
input.getConfig().additionalProperties().put(langCliOption.getOpt(),
configOptions.get(langCliOption.getOpt()));
}
}
}
if(configHelp) {
for (CliOption langCliOption : config.cliOptions()) {
@ -215,25 +293,4 @@ public class CodeGenMojo extends AbstractMojo {
project.addCompileSourceRoot(output.toString());
}
}
private void addAdditionalProperties(CodegenConfig config, Set<String> definedOptions, Map<?,?> configOptions) {
for(Map.Entry<?, ?> configEntry : configOptions.entrySet()) {
config.additionalProperties().put(configEntry.getKey().toString(), configEntry.getValue());
if(!definedOptions.contains(configEntry.getKey())) {
getLog().warn("Additional property: " + configEntry.getKey() + " is not defined for this language.");
}
}
}
private static Map<String, String> createMapFromKeyValuePairs(String commaSeparatedKVPairs) {
final List<Pair<String, String>> pairs = OptionUtils.parseCommaSeparatedTuples(commaSeparatedKVPairs);
Map<String, String> result = new HashMap<String, String>();
for (Pair<String, String> pair : pairs) {
result.put(pair.getLeft(), pair.getRight());
}
return result;
}
}

View File

@ -0,0 +1,77 @@
package io.swagger.codegen.config;
import io.swagger.codegen.utils.OptionUtils;
import org.apache.commons.lang3.tuple.Pair;
import java.util.*;
/**
* Contains shared logic for applying key-value pairs and CSV strings
* to specific settings in CodegenConfigurator.
*
* <p>
* This class exists to facilitate testing. These methods could be applied
* to CodegenConfigurator, but this complicates things when mocking CodegenConfigurator.
* </p>
*/
public final class CodegenConfiguratorUtils {
public static void applySystemPropertiesKvp(String systemProperties, CodegenConfigurator configurator) {
final Map<String, String> map = createMapFromKeyValuePairs(systemProperties);
for (Map.Entry<String, String> entry : map.entrySet()) {
configurator.addSystemProperty(entry.getKey(), entry.getValue());
}
}
public static void applyInstantiationTypesKvp(String instantiationTypes, CodegenConfigurator configurator) {
final Map<String, String> map = createMapFromKeyValuePairs(instantiationTypes);
for (Map.Entry<String, String> entry : map.entrySet()) {
configurator.addInstantiationType(entry.getKey(), entry.getValue());
}
}
public static void applyImportMappingsKvp(String importMappings, CodegenConfigurator configurator) {
final Map<String, String> map = createMapFromKeyValuePairs(importMappings);
for (Map.Entry<String, String> entry : map.entrySet()) {
configurator.addImportMapping(entry.getKey(), entry.getValue());
}
}
public static void applyTypeMappingsKvp(String typeMappings, CodegenConfigurator configurator) {
final Map<String, String> map = createMapFromKeyValuePairs(typeMappings);
for (Map.Entry<String, String> entry : map.entrySet()) {
configurator.addTypeMapping(entry.getKey(), entry.getValue());
}
}
public static void applyAdditionalPropertiesKvp(String additionalProperties, CodegenConfigurator configurator) {
final Map<String, String> map = createMapFromKeyValuePairs(additionalProperties);
for (Map.Entry<String, String> entry : map.entrySet()) {
configurator.addAdditionalProperty(entry.getKey(), entry.getValue());
}
}
public static void applyLanguageSpecificPrimitivesCsv(String languageSpecificPrimitives, CodegenConfigurator configurator) {
final Set<String> set = createSetFromCsvList(languageSpecificPrimitives);
for (String item : set) {
configurator.addLanguageSpecificPrimitive(item);
}
}
private static Set<String> createSetFromCsvList(String csvProperty) {
final List<String> values = OptionUtils.splitCommaSeparatedList(csvProperty);
return new HashSet<String>(values);
}
private static Map<String, String> createMapFromKeyValuePairs(String commaSeparatedKVPairs) {
final List<Pair<String, String>> pairs = OptionUtils.parseCommaSeparatedTuples(commaSeparatedKVPairs);
Map<String, String> result = new HashMap<String, String>();
for (Pair<String, String> pair : pairs) {
result.put(pair.getLeft(), pair.getRight());
}
return result;
}
}

View File

@ -17,12 +17,13 @@ public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen imp
supportsInheritance = true;
setReservedWordsLowerCase(Arrays.asList(
// local variable names used in API methods (endpoints)
"path", "queryParameters", "headerParams", "formParams", "useFormData", "deferred",
"varLocalPath", "queryParameters", "headerParams", "formParams", "useFormData", "varLocalDeferred",
"requestOptions",
// Typescript reserved words
"abstract", "await", "boolean", "break", "byte", "case", "catch", "char", "class", "const", "continue", "debugger", "default", "delete", "do", "double", "else", "enum", "export", "extends", "false", "final", "finally", "float", "for", "function", "goto", "if", "implements", "import", "in", "instanceof", "int", "interface", "let", "long", "native", "new", "null", "package", "private", "protected", "public", "return", "short", "static", "super", "switch", "synchronized", "this", "throw", "transient", "true", "try", "typeof", "var", "void", "volatile", "while", "with", "yield"));
languageSpecificPrimitives = new HashSet<String>(Arrays.asList(
"string",
"String",
"boolean",
"Boolean",
@ -30,7 +31,12 @@ public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen imp
"Integer",
"Long",
"Float",
"Object"));
"Object",
"Array",
"Date",
"number",
"any"
));
instantiationTypes.put("array", "Array");
typeMapping = new HashMap<String, String>();
@ -116,10 +122,22 @@ public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen imp
@Override
public String toModelName(String name) {
// model name cannot use reserved keyword, e.g. return
if (isReservedWord(name))
throw new RuntimeException(name
+ " (reserved word) cannot be used as a model name");
name = sanitizeName(name); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
if (!StringUtils.isEmpty(modelNamePrefix)) {
name = modelNamePrefix + "_" + name;
}
if (!StringUtils.isEmpty(modelNameSuffix)) {
name = name + "_" + modelNameSuffix;
}
// model name cannot use reserved keyword, e.g. return
if (isReservedWord(name)) {
String modelName = camelize("object_" + name);
LOGGER.warn(name + " (reserved word) cannot be used as model name. Renamed to " + modelName);
return modelName;
}
// camelize the model name
// phone_number => PhoneNumber
@ -158,7 +176,7 @@ public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen imp
return type;
} else
type = swaggerType;
return type;
return toModelName(type);
}
@Override

View File

@ -103,7 +103,7 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
supportedLibraries.put("jersey2", "HTTP client: Jersey client 2.6");
supportedLibraries.put("okhttp-gson", "HTTP client: OkHttp 2.4.0. JSON processing: Gson 2.3.1");
supportedLibraries.put(RETROFIT_1, "HTTP client: OkHttp 2.4.0. JSON processing: Gson 2.3.1 (Retrofit 1.9.0)");
supportedLibraries.put(RETROFIT_2, "HTTP client: OkHttp 2.5.0. JSON processing: Gson 2.4 (Retrofit 2.0.0-beta2). Enable the RxJava adapter using '-DuseRxJava=true'.");
supportedLibraries.put(RETROFIT_2, "HTTP client: OkHttp 2.5.0. JSON processing: Gson 2.4 (Retrofit 2.0.0-beta4). Enable the RxJava adapter using '-DuseRxJava=true'.");
CliOption library = new CliOption(CodegenConstants.LIBRARY, "library template (sub-template) to use");
library.setDefault(DEFAULT_LIBRARY);

View File

@ -55,9 +55,6 @@ public class RubyClientCodegen extends DefaultCodegen implements CodegenConfig {
modelTestTemplateFiles.put("model_test.mustache", ".rb");
apiTestTemplateFiles.put("api_test.mustache", ".rb");
typeMapping.clear();
languageSpecificPrimitives.clear();
setReservedWordsLowerCase(
Arrays.asList(
// local variable names used in API methods (endpoints)
@ -71,11 +68,24 @@ public class RubyClientCodegen extends DefaultCodegen implements CodegenConfig {
"if", "not", "return", "undef", "yield")
);
typeMapping.clear();
languageSpecificPrimitives.clear();
// primitives in ruby lang
languageSpecificPrimitives.add("int");
languageSpecificPrimitives.add("array");
languageSpecificPrimitives.add("map");
languageSpecificPrimitives.add("string");
// primitives in the typeMapping
languageSpecificPrimitives.add("String");
languageSpecificPrimitives.add("Integer");
languageSpecificPrimitives.add("Float");
languageSpecificPrimitives.add("Date");
languageSpecificPrimitives.add("DateTime");
languageSpecificPrimitives.add("BOOLEAN");
languageSpecificPrimitives.add("Array");
languageSpecificPrimitives.add("Hash");
languageSpecificPrimitives.add("File");
typeMapping.put("string", "String");
typeMapping.put("char", "String");
@ -317,7 +327,7 @@ public class RubyClientCodegen extends DefaultCodegen implements CodegenConfig {
String type = null;
if (typeMapping.containsKey(swaggerType)) {
type = typeMapping.get(swaggerType);
if (languageSpecificPrimitives.contains(type)) {
if (languageSpecificPrimitives.contains(type)) {
return type;
}
} else {
@ -333,7 +343,6 @@ public class RubyClientCodegen extends DefaultCodegen implements CodegenConfig {
public String toVarName(String name) {
// sanitize name
name = sanitizeName(name); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
// if it's all uppper case, convert to lower case
if (name.matches("^[A-Z_]*$")) {
name = name.toLowerCase();
@ -361,6 +370,14 @@ public class RubyClientCodegen extends DefaultCodegen implements CodegenConfig {
public String toModelName(String name) {
name = sanitizeName(name); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
if (!StringUtils.isEmpty(modelNamePrefix)) {
name = modelNamePrefix + "_" + name;
}
if (!StringUtils.isEmpty(modelNameSuffix)) {
name = name + "_" + modelNameSuffix;
}
// model name cannot use reserved keyword, e.g. return
if (isReservedWord(name)) {
String modelName = camelize("object_" + name);
@ -375,6 +392,15 @@ public class RubyClientCodegen extends DefaultCodegen implements CodegenConfig {
@Override
public String toModelFilename(String name) {
name = sanitizeName(name); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
if (!StringUtils.isEmpty(modelNamePrefix)) {
name = modelNamePrefix + "_" + name;
}
if (!StringUtils.isEmpty(modelNameSuffix)) {
name = name + "_" + modelNameSuffix;
}
// model name cannot use reserved keyword, e.g. return
if (isReservedWord(name)) {
String filename = underscore("object_" + name);
@ -398,12 +424,12 @@ public class RubyClientCodegen extends DefaultCodegen implements CodegenConfig {
@Override
public String toApiTestFilename(String name) {
return toApiName(name) + "_spec";
return toApiFilename(name) + "_spec";
}
@Override
public String toModelTestFilename(String name) {
return toModelName(name) + "_spec";
return toModelFilename(name) + "_spec";
}
@Override

View File

@ -12,8 +12,8 @@ import org.apache.oltu.oauth2.client.request.OAuthClientRequest.TokenRequestBuil
import retrofit2.Converter;
import retrofit2.Retrofit;
import retrofit2.GsonConverterFactory;
{{#useRxJava}}import retrofit2.RxJavaCallAdapterFactory;{{/useRxJava}}
import retrofit2.converter.gson.GsonConverterFactory;
{{#useRxJava}}import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory;{{/useRxJava}}
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
@ -103,14 +103,14 @@ public class ApiClient {
.setUsername(username)
.setPassword(password);
}
public void createDefaultAdapter() {
Gson gson = new GsonBuilder()
.setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ")
.create();
okClient = new OkHttpClient();
String baseUrl = "{{basePath}}";
if(!baseUrl.endsWith("/"))
baseUrl = baseUrl + "/";
@ -125,7 +125,7 @@ public class ApiClient {
public <S> S createService(Class<S> serviceClass) {
return adapterBuilder.build().create(serviceClass);
}
/**
@ -203,7 +203,7 @@ public class ApiClient {
}
}
}
/**
* Helper method to configure the oauth accessCode/implicit flow parameters
* @param clientId
@ -225,7 +225,7 @@ public class ApiClient {
}
}
}
/**
* Configures a listener which is notified when a new access token is received.
* @param accessTokenListener
@ -272,7 +272,7 @@ public class ApiClient {
public OkHttpClient getOkClient() {
return okClient;
}
public void addAuthsToOkClient(OkHttpClient okClient) {
for(Interceptor apiAuthorization : apiAuthorizations.values()) {
okClient.interceptors().add(apiAuthorization);
@ -308,14 +308,14 @@ class GsonResponseBodyConverterToString<T> implements Converter<ResponseBody, T>
String returned = value.string();
try {
return gson.fromJson(returned, type);
}
}
catch (JsonParseException e) {
return (T) returned;
}
}
}
}
class GsonCustomConverterFactory extends Converter.Factory
class GsonCustomConverterFactory extends Converter.Factory
{
public static GsonCustomConverterFactory create(Gson gson) {
return new GsonCustomConverterFactory(gson);
@ -339,8 +339,8 @@ class GsonCustomConverterFactory extends Converter.Factory
}
@Override
public Converter<?, RequestBody> requestBodyConverter(Type type, Annotation[] annotations, Retrofit retrofit) {
return gsonConverterFactory.requestBodyConverter(type, annotations, retrofit);
public Converter<?, RequestBody> requestBodyConverter(Type type, Annotation[] parameterAnnotations, Annotation[] methodAnnotations, Retrofit retrofit) {
return gsonConverterFactory.requestBodyConverter(type, parameterAnnotations, methodAnnotations, retrofit);
}
}

View File

@ -4,18 +4,18 @@ import java.util.Arrays;
import java.util.List;
public class CollectionFormats {
public static class CSVParams {
protected List<String> params;
public CSVParams() {
}
public CSVParams(List<String> params) {
this.params = params;
}
public CSVParams(String... params) {
this.params = Arrays.asList(params);
}
@ -27,19 +27,19 @@ public class CollectionFormats {
public void setParams(List<String> params) {
this.params = params;
}
@Override
public String toString() {
return StringUtil.join(params.toArray(new String[0]), ",");
}
}
public static class SSVParams extends CSVParams {
public SSVParams() {
}
public SSVParams(List<String> params) {
super(params);
}
@ -53,16 +53,16 @@ public class CollectionFormats {
return StringUtil.join(params.toArray(new String[0]), " ");
}
}
public static class TSVParams extends CSVParams {
public TSVParams() {
}
public TSVParams(List<String> params) {
super(params);
}
public TSVParams(String... params) {
super(params);
}
@ -72,16 +72,16 @@ public class CollectionFormats {
return StringUtil.join( params.toArray(new String[0]), "\t");
}
}
public static class PIPESParams extends CSVParams {
public PIPESParams() {
}
public PIPESParams(List<String> params) {
super(params);
}
public PIPESParams(String... params) {
super(params);
}
@ -91,5 +91,5 @@ public class CollectionFormats {
return StringUtil.join(params.toArray(new String[0]), "|");
}
}
}

View File

@ -90,9 +90,8 @@ if(hasProperty('target') && target == 'android') {
}
ext {
okhttp_version = "3.0.1"
oltu_version = "1.0.0"
retrofit_version = "2.0.0-beta3"
retrofit_version = "2.0.0-beta4"
gson_version = "2.4"
swagger_annotations_version = "1.5.0"
junit_version = "4.12"
@ -103,8 +102,6 @@ ext {
}
dependencies {
compile "com.squareup.okhttp3:okhttp:$okhttp_version"
compile "com.squareup.retrofit2:retrofit:$retrofit_version"
compile "com.squareup.retrofit2:converter-gson:$retrofit_version"
{{#useRxJava}}
@ -113,7 +110,6 @@ dependencies {
{{/useRxJava}}
{{^useRxJava}}{{/useRxJava}}
compile "com.google.code.gson:gson:$gson_version"
compile "io.swagger:swagger-annotations:$swagger_annotations_version"
compile "org.apache.oltu.oauth2:org.apache.oltu.oauth2.client:$oltu_version"

View File

@ -161,7 +161,7 @@
</dependencies>
<properties>
<swagger-annotations-version>1.5.0</swagger-annotations-version>
<retrofit-version>2.0.0-beta3</retrofit-version>
<retrofit-version>2.0.0-beta4</retrofit-version>
{{#useRxJava}}<rxjava-version>1.0.16</rxjava-version>{{/useRxJava}}
<okhttp-version>3.0.1</okhttp-version>
<gson-version>2.4</gson-version>

View File

@ -39,7 +39,7 @@ namespace {{package}} {
{{#allParams}}* @param {{paramName}} {{description}}
{{/allParams}}*/
public {{nickname}} ({{#allParams}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}, {{/allParams}}extraHttpRequestParams?: any ) : ng.IHttpPromise<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}{}{{/returnType}}> {
const path = this.basePath + '{{path}}'{{#pathParams}}
const localVarPath = this.basePath + '{{path}}'{{#pathParams}}
.replace('{' + '{{baseName}}' + '}', String({{paramName}})){{/pathParams}};
let queryParameters: any = {};
@ -76,7 +76,7 @@ namespace {{package}} {
{{/formParams}}
let httpRequestParams: any = {
method: '{{httpMethod}}',
url: path,
url: localVarPath,
json: {{#hasFormParams}}false{{/hasFormParams}}{{^hasFormParams}}true{{/hasFormParams}},
{{#bodyParam}}data: {{paramName}},
{{/bodyParam}}

View File

@ -179,7 +179,7 @@ export class {{classname}} {
{{#allParams}}* @param {{paramName}} {{description}}
{{/allParams}}*/
public {{nickname}} ({{#allParams}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) : Promise<{ response: http.ClientResponse; {{#returnType}}body: {{{returnType}}}; {{/returnType}}{{^returnType}}body?: any; {{/returnType}} }> {
const path = this.basePath + '{{path}}'{{#pathParams}}
const localVarPath = this.basePath + '{{path}}'{{#pathParams}}
.replace('{' + '{{baseName}}' + '}', String({{paramName}})){{/pathParams}};
let queryParameters: any = {};
let headerParams: any = this.extendObj({}, this.defaultHeaders);
@ -212,13 +212,13 @@ export class {{classname}} {
{{/isFile}}
{{/formParams}}
let deferred = promise.defer<{ response: http.ClientResponse; {{#returnType}}body: {{{returnType}}}; {{/returnType}}{{^returnType}}body?: any; {{/returnType}} }>();
let localVarDeferred = promise.defer<{ response: http.ClientResponse; {{#returnType}}body: {{{returnType}}}; {{/returnType}}{{^returnType}}body?: any; {{/returnType}} }>();
let requestOptions: request.Options = {
method: '{{httpMethod}}',
qs: queryParameters,
headers: headerParams,
uri: path,
uri: localVarPath,
json: true,
{{#bodyParam}}
body: {{paramName}},
@ -241,17 +241,17 @@ export class {{classname}} {
request(requestOptions, (error, response, body) => {
if (error) {
deferred.reject(error);
localVarDeferred.reject(error);
} else {
if (response.statusCode >= 200 && response.statusCode <= 299) {
deferred.resolve({ response: response, body: body });
localVarDeferred.resolve({ response: response, body: body });
} else {
deferred.reject({ response: response, body: body });
localVarDeferred.reject({ response: response, body: body });
}
}
});
return deferred.promise;
return localVarDeferred.promise;
}
{{/operation}}
}

View File

@ -59,7 +59,7 @@ public class TypeScriptAngularModelTest {
final CodegenProperty property3 = cm.vars.get(2);
Assert.assertEquals(property3.baseName, "createdAt");
Assert.assertEquals(property3.complexType, "Date");
Assert.assertEquals(property3.complexType, null);
Assert.assertEquals(property3.datatype, "Date");
Assert.assertEquals(property3.name, "createdAt");
Assert.assertEquals(property3.defaultValue, "null");

View File

@ -59,7 +59,7 @@ public class TypeScriptNodeModelTest {
final CodegenProperty property3 = cm.vars.get(2);
Assert.assertEquals(property3.baseName, "createdAt");
Assert.assertEquals(property3.complexType, "Date");
Assert.assertEquals(property3.complexType, null);
Assert.assertEquals(property3.datatype, "Date");
Assert.assertEquals(property3.name, "createdAt");
Assert.assertEquals(property3.defaultValue, "null");

View File

@ -48,7 +48,7 @@
(defn find-pets-by-status-with-http-info
"Finds Pets by status
Multiple status values can be provided with comma seperated strings"
Multiple status values can be provided with comma separated strings"
([] (find-pets-by-status-with-http-info nil))
([{:keys [status ]}]
(call-api "/pet/findByStatus" :get
@ -62,7 +62,7 @@
(defn find-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 separated strings"
([] (find-pets-by-status nil))
([optional-params]
(:data (find-pets-by-status-with-http-info optional-params))))
@ -99,7 +99,7 @@
:form-params {}
:content-types []
:accepts ["application/json" "application/xml"]
:auth-names ["api_key"]}))
:auth-names ["petstore_auth" "api_key"]}))
(defn get-pet-by-id
"Find pet by ID
@ -169,3 +169,44 @@
([pet-id ] (upload-file pet-id nil))
([pet-id optional-params]
(:data (upload-file-with-http-info pet-id optional-params))))
(defn pet-pet-idtesting-byte-arraytrue-get-with-http-info
"Fake endpoint to test byte array return by 'Find pet by ID'
Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions"
[pet-id ]
(call-api "/pet/{petId}?testing_byte_array=true" :get
{:path-params {"petId" pet-id }
:header-params {}
:query-params {}
:form-params {}
:content-types []
:accepts ["application/json" "application/xml"]
:auth-names ["petstore_auth" "api_key"]}))
(defn pet-pet-idtesting-byte-arraytrue-get
"Fake endpoint to test byte array return by 'Find pet by ID'
Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions"
[pet-id ]
(:data (pet-pet-idtesting-byte-arraytrue-get-with-http-info pet-id)))
(defn add-pet-using-byte-array-with-http-info
"Fake endpoint to test byte array in body parameter for adding a new pet to the store
"
([] (add-pet-using-byte-array-with-http-info nil))
([{:keys [body ]}]
(call-api "/pet?testing_byte_array=true" :post
{:path-params {}
:header-params {}
:query-params {}
:form-params {}
:body-param body
:content-types ["application/json" "application/xml"]
:accepts ["application/json" "application/xml"]
:auth-names ["petstore_auth"]})))
(defn add-pet-using-byte-array
"Fake endpoint to test byte array in body parameter for adding a new pet to the store
"
([] (add-pet-using-byte-array nil))
([optional-params]
(:data (add-pet-using-byte-array-with-http-info optional-params))))

View File

@ -2,6 +2,27 @@
(:require [swagger-petstore.core :refer [call-api check-required-params with-collection-format]])
(:import (java.io File)))
(defn find-orders-by-status-with-http-info
"Finds orders by status
A single status value can be provided as a string"
([] (find-orders-by-status-with-http-info nil))
([{:keys [status ]}]
(call-api "/store/findByStatus" :get
{:path-params {}
:header-params {}
:query-params {"status" status }
:form-params {}
:content-types []
:accepts ["application/json" "application/xml"]
:auth-names ["test_api_client_id" "test_api_client_secret"]})))
(defn find-orders-by-status
"Finds orders by status
A single status value can be provided as a string"
([] (find-orders-by-status nil))
([optional-params]
(:data (find-orders-by-status-with-http-info optional-params))))
(defn get-inventory-with-http-info
"Returns pet inventories by status
Returns a map of status codes to quantities"
@ -34,7 +55,7 @@
:body-param body
:content-types []
:accepts ["application/json" "application/xml"]
:auth-names []})))
:auth-names ["test_api_client_id" "test_api_client_secret"]})))
(defn place-order
"Place an order for a pet
@ -54,7 +75,7 @@
:form-params {}
:content-types []
:accepts ["application/json" "application/xml"]
:auth-names []}))
:auth-names ["test_api_key_query" "test_api_key_header"]}))
(defn get-order-by-id
"Find purchase order by ID

View File

@ -9,7 +9,11 @@
(def auth-definitions
{"petstore_auth" {:type :oauth2}
"api_key" {:type :api-key :in :header :param-name "api_key"}})
"test_api_client_id" {:type :api-key :in :header :param-name "x-test_api_client_id"}
"test_api_client_secret" {:type :api-key :in :header :param-name "x-test_api_client_secret"}
"api_key" {:type :api-key :in :header :param-name "api_key"}
"test_api_key_query" {:type :api-key :in :query :param-name "test_api_key_query"}
"test_api_key_header" {:type :api-key :in :header :param-name "test_api_key_header"}})
(def default-api-context
"Default API context."
@ -18,7 +22,11 @@
:datetime-format "yyyy-MM-dd'T'HH:mm:ss.SSSXXX"
:debug false
:auths {"petstore_auth" nil
"api_key" nil}})
"test_api_client_id" nil
"test_api_client_secret" nil
"api_key" nil
"test_api_key_query" nil
"test_api_key_header" nil}})
(def ^:dynamic *api-context*
"Dynamic API context to be applied in API calls."

View File

@ -11,7 +11,11 @@
:datetime-format "yyyy-MM-dd'T'HH:mm:ss.SSSXXX"
:debug false
:auths {"api_key" nil
"petstore_auth" nil}}
"petstore_auth" nil
"test_api_client_id" nil
"test_api_client_secret" nil
"test_api_key_query" nil
"test_api_key_header" nil}}
default-api-context
*api-context*
(with-api-context {}
@ -25,8 +29,9 @@
:date-format "yyyy-MM-dd"
:datetime-format "yyyy-MM-dd'T'HH:mm:ss.SSSXXX"
:debug true
:auths {"api_key" "key1"
"petstore_auth" "token1"}}
:auths (merge (:auths default-api-context)
{"api_key" "key1"
"petstore_auth" "token1"})}
*api-context*))
;; nested with-api-context inherits values from the outer api context
(with-api-context {:datetime-format "yyyy-MM-dd HH:mm:ss"
@ -35,8 +40,9 @@
:date-format "yyyy-MM-dd"
:datetime-format "yyyy-MM-dd HH:mm:ss"
:debug true
:auths {"api_key" "key2"
"petstore_auth" "token1"}}
:auths (merge (:auths default-api-context)
{"api_key" "key2"
"petstore_auth" "token1"})}
*api-context*))))
;; back to default api context
(is (= {:base-url "http://petstore.swagger.io/v2"
@ -44,7 +50,11 @@
:datetime-format "yyyy-MM-dd'T'HH:mm:ss.SSSXXX"
:debug false
:auths {"api_key" nil
"petstore_auth" nil}}
"petstore_auth" nil
"test_api_client_id" nil
"test_api_client_secret" nil
"test_api_key_query" nil
"test_api_key_header" nil}}
default-api-context
*api-context*))))

View File

@ -90,9 +90,8 @@ if(hasProperty('target') && target == 'android') {
}
ext {
okhttp_version = "3.0.1"
oltu_version = "1.0.0"
retrofit_version = "2.0.0-beta3"
retrofit_version = "2.0.0-beta4"
gson_version = "2.4"
swagger_annotations_version = "1.5.0"
junit_version = "4.12"
@ -100,13 +99,10 @@ ext {
}
dependencies {
compile "com.squareup.okhttp3:okhttp:$okhttp_version"
compile "com.squareup.retrofit2:retrofit:$retrofit_version"
compile "com.squareup.retrofit2:converter-gson:$retrofit_version"
compile "com.google.code.gson:gson:$gson_version"
compile "io.swagger:swagger-annotations:$swagger_annotations_version"
compile "org.apache.oltu.oauth2:org.apache.oltu.oauth2.client:$oltu_version"

View File

@ -123,21 +123,11 @@
<artifactId>converter-gson</artifactId>
<version>${retrofit-version}</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>${gson-version}</version>
</dependency>
<dependency>
<groupId>org.apache.oltu.oauth2</groupId>
<artifactId>org.apache.oltu.oauth2.client</artifactId>
<version>${oltu-version}</version>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>${okhttp-version}</version>
</dependency>
<!-- test dependencies -->
@ -150,10 +140,7 @@
</dependencies>
<properties>
<swagger-annotations-version>1.5.0</swagger-annotations-version>
<retrofit-version>2.0.0-beta3</retrofit-version>
<okhttp-version>3.0.1</okhttp-version>
<gson-version>2.4</gson-version>
<retrofit-version>2.0.0-beta4</retrofit-version>
<oltu-version>1.0.0</oltu-version>
<maven-plugin-version>1.0.0</maven-plugin-version>
<junit-version>4.12</junit-version>

View File

@ -12,7 +12,7 @@ import org.apache.oltu.oauth2.client.request.OAuthClientRequest.TokenRequestBuil
import retrofit2.Converter;
import retrofit2.Retrofit;
import retrofit2.GsonConverterFactory;
import retrofit2.converter.gson.GsonConverterFactory;
import com.google.gson.Gson;
@ -46,10 +46,10 @@ public class ApiClient {
this();
for(String authName : authNames) {
Interceptor auth;
if (authName == "petstore_auth") {
auth = new OAuth(OAuthFlow.implicit, "http://petstore.swagger.io/api/oauth/dialog", "", "write:pets, read:pets");
} else if (authName == "api_key") {
if (authName == "api_key") {
auth = new ApiKeyAuth("header", "api_key");
} else if (authName == "petstore_auth") {
auth = new OAuth(OAuthFlow.implicit, "http://petstore.swagger.io/api/oauth/dialog", "", "write:pets, read:pets");
} else {
throw new RuntimeException("auth name \"" + authName + "\" not found in available auth names");
}
@ -102,14 +102,14 @@ public class ApiClient {
.setUsername(username)
.setPassword(password);
}
public void createDefaultAdapter() {
Gson gson = new GsonBuilder()
.setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ")
.create();
okClient = new OkHttpClient();
String baseUrl = "http://petstore.swagger.io/v2";
if(!baseUrl.endsWith("/"))
baseUrl = baseUrl + "/";
@ -124,7 +124,7 @@ public class ApiClient {
public <S> S createService(Class<S> serviceClass) {
return adapterBuilder.build().create(serviceClass);
}
/**
@ -202,7 +202,7 @@ public class ApiClient {
}
}
}
/**
* Helper method to configure the oauth accessCode/implicit flow parameters
* @param clientId
@ -224,7 +224,7 @@ public class ApiClient {
}
}
}
/**
* Configures a listener which is notified when a new access token is received.
* @param accessTokenListener
@ -271,7 +271,7 @@ public class ApiClient {
public OkHttpClient getOkClient() {
return okClient;
}
public void addAuthsToOkClient(OkHttpClient okClient) {
for(Interceptor apiAuthorization : apiAuthorizations.values()) {
okClient.interceptors().add(apiAuthorization);
@ -307,14 +307,14 @@ class GsonResponseBodyConverterToString<T> implements Converter<ResponseBody, T>
String returned = value.string();
try {
return gson.fromJson(returned, type);
}
}
catch (JsonParseException e) {
return (T) returned;
}
}
}
}
class GsonCustomConverterFactory extends Converter.Factory
class GsonCustomConverterFactory extends Converter.Factory
{
public static GsonCustomConverterFactory create(Gson gson) {
return new GsonCustomConverterFactory(gson);
@ -338,8 +338,8 @@ class GsonCustomConverterFactory extends Converter.Factory
}
@Override
public Converter<?, RequestBody> requestBodyConverter(Type type, Annotation[] annotations, Retrofit retrofit) {
return gsonConverterFactory.requestBodyConverter(type, annotations, retrofit);
public Converter<?, RequestBody> requestBodyConverter(Type type, Annotation[] parameterAnnotations, Annotation[] methodAnnotations, Retrofit retrofit) {
return gsonConverterFactory.requestBodyConverter(type, parameterAnnotations, methodAnnotations, retrofit);
}
}

View File

@ -4,18 +4,18 @@ import java.util.Arrays;
import java.util.List;
public class CollectionFormats {
public static class CSVParams {
protected List<String> params;
public CSVParams() {
}
public CSVParams(List<String> params) {
this.params = params;
}
public CSVParams(String... params) {
this.params = Arrays.asList(params);
}
@ -27,19 +27,19 @@ public class CollectionFormats {
public void setParams(List<String> params) {
this.params = params;
}
@Override
public String toString() {
return StringUtil.join(params.toArray(new String[0]), ",");
}
}
public static class SSVParams extends CSVParams {
public SSVParams() {
}
public SSVParams(List<String> params) {
super(params);
}
@ -53,16 +53,16 @@ public class CollectionFormats {
return StringUtil.join(params.toArray(new String[0]), " ");
}
}
public static class TSVParams extends CSVParams {
public TSVParams() {
}
public TSVParams(List<String> params) {
super(params);
}
public TSVParams(String... params) {
super(params);
}
@ -72,16 +72,16 @@ public class CollectionFormats {
return StringUtil.join( params.toArray(new String[0]), "\t");
}
}
public static class PIPESParams extends CSVParams {
public PIPESParams() {
}
public PIPESParams(List<String> params) {
super(params);
}
public PIPESParams(String... params) {
super(params);
}
@ -91,5 +91,5 @@ public class CollectionFormats {
return StringUtil.join(params.toArray(new String[0]), "|");
}
}
}

View File

@ -1,6 +1,6 @@
package io.swagger.client;
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2016-02-02T15:33:05.826+01:00")
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2016-02-26T13:30:07.836+01:00")
public class StringUtil {
/**
* Check if the given array contains the given value (with case-insensitive comparison).

View File

@ -90,9 +90,8 @@ if(hasProperty('target') && target == 'android') {
}
ext {
okhttp_version = "3.0.1"
oltu_version = "1.0.0"
retrofit_version = "2.0.0-beta3"
retrofit_version = "2.0.0-beta4"
gson_version = "2.4"
swagger_annotations_version = "1.5.0"
junit_version = "4.12"
@ -101,15 +100,12 @@ ext {
}
dependencies {
compile "com.squareup.okhttp3:okhttp:$okhttp_version"
compile "com.squareup.retrofit2:retrofit:$retrofit_version"
compile "com.squareup.retrofit2:converter-gson:$retrofit_version"
compile "com.squareup.retrofit2:adapter-rxjava:$retrofit_version"
compile "io.reactivex:rxjava:$rx_java_version"
compile "com.google.code.gson:gson:$gson_version"
compile "io.swagger:swagger-annotations:$swagger_annotations_version"
compile "org.apache.oltu.oauth2:org.apache.oltu.oauth2.client:$oltu_version"

View File

@ -123,21 +123,11 @@
<artifactId>converter-gson</artifactId>
<version>${retrofit-version}</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>${gson-version}</version>
</dependency>
<dependency>
<groupId>org.apache.oltu.oauth2</groupId>
<artifactId>org.apache.oltu.oauth2.client</artifactId>
<version>${oltu-version}</version>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>${okhttp-version}</version>
</dependency>
<dependency>
<groupId>io.reactivex</groupId>
@ -161,10 +151,8 @@
</dependencies>
<properties>
<swagger-annotations-version>1.5.0</swagger-annotations-version>
<retrofit-version>2.0.0-beta3</retrofit-version>
<retrofit-version>2.0.0-beta4</retrofit-version>
<rxjava-version>1.0.16</rxjava-version>
<okhttp-version>3.0.1</okhttp-version>
<gson-version>2.4</gson-version>
<oltu-version>1.0.0</oltu-version>
<maven-plugin-version>1.0.0</maven-plugin-version>
<junit-version>4.12</junit-version>

View File

@ -12,8 +12,8 @@ import org.apache.oltu.oauth2.client.request.OAuthClientRequest.TokenRequestBuil
import retrofit2.Converter;
import retrofit2.Retrofit;
import retrofit2.GsonConverterFactory;
import retrofit2.RxJavaCallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;
import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
@ -46,10 +46,10 @@ public class ApiClient {
this();
for(String authName : authNames) {
Interceptor auth;
if (authName == "petstore_auth") {
auth = new OAuth(OAuthFlow.implicit, "http://petstore.swagger.io/api/oauth/dialog", "", "write:pets, read:pets");
} else if (authName == "api_key") {
if (authName == "api_key") {
auth = new ApiKeyAuth("header", "api_key");
} else if (authName == "petstore_auth") {
auth = new OAuth(OAuthFlow.implicit, "http://petstore.swagger.io/api/oauth/dialog", "", "write:pets, read:pets");
} else {
throw new RuntimeException("auth name \"" + authName + "\" not found in available auth names");
}
@ -102,14 +102,14 @@ public class ApiClient {
.setUsername(username)
.setPassword(password);
}
public void createDefaultAdapter() {
Gson gson = new GsonBuilder()
.setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ")
.create();
okClient = new OkHttpClient();
String baseUrl = "http://petstore.swagger.io/v2";
if(!baseUrl.endsWith("/"))
baseUrl = baseUrl + "/";
@ -124,7 +124,7 @@ public class ApiClient {
public <S> S createService(Class<S> serviceClass) {
return adapterBuilder.build().create(serviceClass);
}
/**
@ -202,7 +202,7 @@ public class ApiClient {
}
}
}
/**
* Helper method to configure the oauth accessCode/implicit flow parameters
* @param clientId
@ -224,7 +224,7 @@ public class ApiClient {
}
}
}
/**
* Configures a listener which is notified when a new access token is received.
* @param accessTokenListener
@ -271,7 +271,7 @@ public class ApiClient {
public OkHttpClient getOkClient() {
return okClient;
}
public void addAuthsToOkClient(OkHttpClient okClient) {
for(Interceptor apiAuthorization : apiAuthorizations.values()) {
okClient.interceptors().add(apiAuthorization);
@ -307,14 +307,14 @@ class GsonResponseBodyConverterToString<T> implements Converter<ResponseBody, T>
String returned = value.string();
try {
return gson.fromJson(returned, type);
}
}
catch (JsonParseException e) {
return (T) returned;
}
}
}
}
class GsonCustomConverterFactory extends Converter.Factory
class GsonCustomConverterFactory extends Converter.Factory
{
public static GsonCustomConverterFactory create(Gson gson) {
return new GsonCustomConverterFactory(gson);
@ -338,8 +338,8 @@ class GsonCustomConverterFactory extends Converter.Factory
}
@Override
public Converter<?, RequestBody> requestBodyConverter(Type type, Annotation[] annotations, Retrofit retrofit) {
return gsonConverterFactory.requestBodyConverter(type, annotations, retrofit);
public Converter<?, RequestBody> requestBodyConverter(Type type, Annotation[] parameterAnnotations, Annotation[] methodAnnotations, Retrofit retrofit) {
return gsonConverterFactory.requestBodyConverter(type, parameterAnnotations, methodAnnotations, retrofit);
}
}

View File

@ -4,18 +4,18 @@ import java.util.Arrays;
import java.util.List;
public class CollectionFormats {
public static class CSVParams {
protected List<String> params;
public CSVParams() {
}
public CSVParams(List<String> params) {
this.params = params;
}
public CSVParams(String... params) {
this.params = Arrays.asList(params);
}
@ -27,19 +27,19 @@ public class CollectionFormats {
public void setParams(List<String> params) {
this.params = params;
}
@Override
public String toString() {
return StringUtil.join(params.toArray(new String[0]), ",");
}
}
public static class SSVParams extends CSVParams {
public SSVParams() {
}
public SSVParams(List<String> params) {
super(params);
}
@ -53,16 +53,16 @@ public class CollectionFormats {
return StringUtil.join(params.toArray(new String[0]), " ");
}
}
public static class TSVParams extends CSVParams {
public TSVParams() {
}
public TSVParams(List<String> params) {
super(params);
}
public TSVParams(String... params) {
super(params);
}
@ -72,16 +72,16 @@ public class CollectionFormats {
return StringUtil.join( params.toArray(new String[0]), "\t");
}
}
public static class PIPESParams extends CSVParams {
public PIPESParams() {
}
public PIPESParams(List<String> params) {
super(params);
}
public PIPESParams(String... params) {
super(params);
}
@ -91,5 +91,5 @@ public class CollectionFormats {
return StringUtil.join(params.toArray(new String[0]), "|");
}
}
}

View File

@ -1,6 +1,6 @@
package io.swagger.client;
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2016-02-02T15:33:07.490+01:00")
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2016-02-26T13:30:13.630+01:00")
public class StringUtil {
/**
* Check if the given array contains the given value (with case-insensitive comparison).

View File

@ -32,13 +32,13 @@ namespace API.Client {
* @param body Pet object that needs to be added to the store
*/
public updatePet (body?: Pet, extraHttpRequestParams?: any ) : ng.IHttpPromise<{}> {
const path = this.basePath + '/pet';
const localVarPath = this.basePath + '/pet';
let queryParameters: any = {};
let headerParams: any = this.extendObj({}, this.defaultHeaders);
let httpRequestParams: any = {
method: 'PUT',
url: path,
url: localVarPath,
json: true,
data: body,
@ -59,13 +59,13 @@ namespace API.Client {
* @param body Pet object that needs to be added to the store
*/
public addPet (body?: Pet, extraHttpRequestParams?: any ) : ng.IHttpPromise<{}> {
const path = this.basePath + '/pet';
const localVarPath = this.basePath + '/pet';
let queryParameters: any = {};
let headerParams: any = this.extendObj({}, this.defaultHeaders);
let httpRequestParams: any = {
method: 'POST',
url: path,
url: localVarPath,
json: true,
data: body,
@ -82,11 +82,11 @@ namespace API.Client {
}
/**
* Finds Pets by status
* Multiple status values can be provided with comma seperated strings
* @param status Status values that need to be considered for filter
* Multiple status values can be provided with comma separated strings
* @param status Status values that need to be considered for query
*/
public findPetsByStatus (status?: Array<string>, extraHttpRequestParams?: any ) : ng.IHttpPromise<Array<Pet>> {
const path = this.basePath + '/pet/findByStatus';
const localVarPath = this.basePath + '/pet/findByStatus';
let queryParameters: any = {};
let headerParams: any = this.extendObj({}, this.defaultHeaders);
@ -96,7 +96,7 @@ namespace API.Client {
let httpRequestParams: any = {
method: 'GET',
url: path,
url: localVarPath,
json: true,
@ -116,7 +116,7 @@ namespace API.Client {
* @param tags Tags to filter by
*/
public findPetsByTags (tags?: Array<string>, extraHttpRequestParams?: any ) : ng.IHttpPromise<Array<Pet>> {
const path = this.basePath + '/pet/findByTags';
const localVarPath = this.basePath + '/pet/findByTags';
let queryParameters: any = {};
let headerParams: any = this.extendObj({}, this.defaultHeaders);
@ -126,7 +126,7 @@ namespace API.Client {
let httpRequestParams: any = {
method: 'GET',
url: path,
url: localVarPath,
json: true,
@ -146,7 +146,7 @@ namespace API.Client {
* @param petId ID of pet that needs to be fetched
*/
public getPetById (petId: number, extraHttpRequestParams?: any ) : ng.IHttpPromise<Pet> {
const path = this.basePath + '/pet/{petId}'
const localVarPath = this.basePath + '/pet/{petId}'
.replace('{' + 'petId' + '}', String(petId));
let queryParameters: any = {};
@ -157,7 +157,7 @@ namespace API.Client {
}
let httpRequestParams: any = {
method: 'GET',
url: path,
url: localVarPath,
json: true,
@ -179,7 +179,7 @@ namespace API.Client {
* @param status Updated status of the pet
*/
public updatePetWithForm (petId: string, name?: string, status?: string, extraHttpRequestParams?: any ) : ng.IHttpPromise<{}> {
const path = this.basePath + '/pet/{petId}'
const localVarPath = this.basePath + '/pet/{petId}'
.replace('{' + 'petId' + '}', String(petId));
let queryParameters: any = {};
@ -198,7 +198,7 @@ namespace API.Client {
let httpRequestParams: any = {
method: 'POST',
url: path,
url: localVarPath,
json: false,
data: this.$httpParamSerializer(formParams),
@ -220,7 +220,7 @@ namespace API.Client {
* @param apiKey
*/
public deletePet (petId: number, apiKey?: string, extraHttpRequestParams?: any ) : ng.IHttpPromise<{}> {
const path = this.basePath + '/pet/{petId}'
const localVarPath = this.basePath + '/pet/{petId}'
.replace('{' + 'petId' + '}', String(petId));
let queryParameters: any = {};
@ -233,7 +233,7 @@ namespace API.Client {
let httpRequestParams: any = {
method: 'DELETE',
url: path,
url: localVarPath,
json: true,
@ -255,7 +255,7 @@ namespace API.Client {
* @param file file to upload
*/
public uploadFile (petId: number, additionalMetadata?: string, file?: any, extraHttpRequestParams?: any ) : ng.IHttpPromise<{}> {
const path = this.basePath + '/pet/{petId}/uploadImage'
const localVarPath = this.basePath + '/pet/{petId}/uploadImage'
.replace('{' + 'petId' + '}', String(petId));
let queryParameters: any = {};
@ -274,7 +274,7 @@ namespace API.Client {
let httpRequestParams: any = {
method: 'POST',
url: path,
url: localVarPath,
json: false,
data: this.$httpParamSerializer(formParams),
@ -294,19 +294,19 @@ namespace API.Client {
* Returns a pet when ID &lt; 10. ID &gt; 10 or nonintegers will simulate API error conditions
* @param petId ID of pet that needs to be fetched
*/
public getPetByIdWithByteArray (petId: number, extraHttpRequestParams?: any ) : ng.IHttpPromise<string> {
const path = this.basePath + '/pet/{petId}?testing_byte_array=true'
public petPetIdtestingByteArraytrueGet (petId: number, extraHttpRequestParams?: any ) : ng.IHttpPromise<string> {
const localVarPath = this.basePath + '/pet/{petId}?testing_byte_array=true'
.replace('{' + 'petId' + '}', String(petId));
let queryParameters: any = {};
let headerParams: any = this.extendObj({}, this.defaultHeaders);
// verify required parameter 'petId' is set
if (!petId) {
throw new Error('Missing required parameter petId when calling getPetByIdWithByteArray');
throw new Error('Missing required parameter petId when calling petPetIdtestingByteArraytrueGet');
}
let httpRequestParams: any = {
method: 'GET',
url: path,
url: localVarPath,
json: true,
@ -326,13 +326,13 @@ namespace API.Client {
* @param body Pet object in the form of byte array
*/
public addPetUsingByteArray (body?: string, extraHttpRequestParams?: any ) : ng.IHttpPromise<{}> {
const path = this.basePath + '/pet?testing_byte_array=true';
const localVarPath = this.basePath + '/pet?testing_byte_array=true';
let queryParameters: any = {};
let headerParams: any = this.extendObj({}, this.defaultHeaders);
let httpRequestParams: any = {
method: 'POST',
url: path,
url: localVarPath,
json: true,
data: body,

View File

@ -26,18 +26,48 @@ namespace API.Client {
return <T1&T2>objA;
}
/**
* Finds orders by status
* A single status value can be provided as a string
* @param status Status value that needs to be considered for query
*/
public findOrdersByStatus (status?: string, extraHttpRequestParams?: any ) : ng.IHttpPromise<Array<Order>> {
const localVarPath = this.basePath + '/store/findByStatus';
let queryParameters: any = {};
let headerParams: any = this.extendObj({}, this.defaultHeaders);
if (status !== undefined) {
queryParameters['status'] = status;
}
let httpRequestParams: any = {
method: 'GET',
url: localVarPath,
json: true,
params: queryParameters,
headers: headerParams
};
if (extraHttpRequestParams) {
httpRequestParams = this.extendObj(httpRequestParams, extraHttpRequestParams);
}
return this.$http(httpRequestParams);
}
/**
* Returns pet inventories by status
* Returns a map of status codes to quantities
*/
public getInventory (extraHttpRequestParams?: any ) : ng.IHttpPromise<{ [key: string]: number; }> {
const path = this.basePath + '/store/inventory';
const localVarPath = this.basePath + '/store/inventory';
let queryParameters: any = {};
let headerParams: any = this.extendObj({}, this.defaultHeaders);
let httpRequestParams: any = {
method: 'GET',
url: path,
url: localVarPath,
json: true,
@ -57,13 +87,13 @@ namespace API.Client {
* @param body order placed for purchasing the pet
*/
public placeOrder (body?: Order, extraHttpRequestParams?: any ) : ng.IHttpPromise<Order> {
const path = this.basePath + '/store/order';
const localVarPath = this.basePath + '/store/order';
let queryParameters: any = {};
let headerParams: any = this.extendObj({}, this.defaultHeaders);
let httpRequestParams: any = {
method: 'POST',
url: path,
url: localVarPath,
json: true,
data: body,
@ -84,7 +114,7 @@ namespace API.Client {
* @param orderId ID of pet that needs to be fetched
*/
public getOrderById (orderId: string, extraHttpRequestParams?: any ) : ng.IHttpPromise<Order> {
const path = this.basePath + '/store/order/{orderId}'
const localVarPath = this.basePath + '/store/order/{orderId}'
.replace('{' + 'orderId' + '}', String(orderId));
let queryParameters: any = {};
@ -95,7 +125,7 @@ namespace API.Client {
}
let httpRequestParams: any = {
method: 'GET',
url: path,
url: localVarPath,
json: true,
@ -115,7 +145,7 @@ namespace API.Client {
* @param orderId ID of the order that needs to be deleted
*/
public deleteOrder (orderId: string, extraHttpRequestParams?: any ) : ng.IHttpPromise<{}> {
const path = this.basePath + '/store/order/{orderId}'
const localVarPath = this.basePath + '/store/order/{orderId}'
.replace('{' + 'orderId' + '}', String(orderId));
let queryParameters: any = {};
@ -126,7 +156,7 @@ namespace API.Client {
}
let httpRequestParams: any = {
method: 'DELETE',
url: path,
url: localVarPath,
json: true,

View File

@ -32,13 +32,13 @@ namespace API.Client {
* @param body Created user object
*/
public createUser (body?: User, extraHttpRequestParams?: any ) : ng.IHttpPromise<{}> {
const path = this.basePath + '/user';
const localVarPath = this.basePath + '/user';
let queryParameters: any = {};
let headerParams: any = this.extendObj({}, this.defaultHeaders);
let httpRequestParams: any = {
method: 'POST',
url: path,
url: localVarPath,
json: true,
data: body,
@ -59,13 +59,13 @@ namespace API.Client {
* @param body List of user object
*/
public createUsersWithArrayInput (body?: Array<User>, extraHttpRequestParams?: any ) : ng.IHttpPromise<{}> {
const path = this.basePath + '/user/createWithArray';
const localVarPath = this.basePath + '/user/createWithArray';
let queryParameters: any = {};
let headerParams: any = this.extendObj({}, this.defaultHeaders);
let httpRequestParams: any = {
method: 'POST',
url: path,
url: localVarPath,
json: true,
data: body,
@ -86,13 +86,13 @@ namespace API.Client {
* @param body List of user object
*/
public createUsersWithListInput (body?: Array<User>, extraHttpRequestParams?: any ) : ng.IHttpPromise<{}> {
const path = this.basePath + '/user/createWithList';
const localVarPath = this.basePath + '/user/createWithList';
let queryParameters: any = {};
let headerParams: any = this.extendObj({}, this.defaultHeaders);
let httpRequestParams: any = {
method: 'POST',
url: path,
url: localVarPath,
json: true,
data: body,
@ -114,7 +114,7 @@ namespace API.Client {
* @param password The password for login in clear text
*/
public loginUser (username?: string, password?: string, extraHttpRequestParams?: any ) : ng.IHttpPromise<string> {
const path = this.basePath + '/user/login';
const localVarPath = this.basePath + '/user/login';
let queryParameters: any = {};
let headerParams: any = this.extendObj({}, this.defaultHeaders);
@ -128,7 +128,7 @@ namespace API.Client {
let httpRequestParams: any = {
method: 'GET',
url: path,
url: localVarPath,
json: true,
@ -147,13 +147,13 @@ namespace API.Client {
*
*/
public logoutUser (extraHttpRequestParams?: any ) : ng.IHttpPromise<{}> {
const path = this.basePath + '/user/logout';
const localVarPath = this.basePath + '/user/logout';
let queryParameters: any = {};
let headerParams: any = this.extendObj({}, this.defaultHeaders);
let httpRequestParams: any = {
method: 'GET',
url: path,
url: localVarPath,
json: true,
@ -173,7 +173,7 @@ namespace API.Client {
* @param username The name that needs to be fetched. Use user1 for testing.
*/
public getUserByName (username: string, extraHttpRequestParams?: any ) : ng.IHttpPromise<User> {
const path = this.basePath + '/user/{username}'
const localVarPath = this.basePath + '/user/{username}'
.replace('{' + 'username' + '}', String(username));
let queryParameters: any = {};
@ -184,7 +184,7 @@ namespace API.Client {
}
let httpRequestParams: any = {
method: 'GET',
url: path,
url: localVarPath,
json: true,
@ -205,7 +205,7 @@ namespace API.Client {
* @param body Updated user object
*/
public updateUser (username: string, body?: User, extraHttpRequestParams?: any ) : ng.IHttpPromise<{}> {
const path = this.basePath + '/user/{username}'
const localVarPath = this.basePath + '/user/{username}'
.replace('{' + 'username' + '}', String(username));
let queryParameters: any = {};
@ -216,7 +216,7 @@ namespace API.Client {
}
let httpRequestParams: any = {
method: 'PUT',
url: path,
url: localVarPath,
json: true,
data: body,
@ -237,7 +237,7 @@ namespace API.Client {
* @param username The name that needs to be deleted
*/
public deleteUser (username: string, extraHttpRequestParams?: any ) : ng.IHttpPromise<{}> {
const path = this.basePath + '/user/{username}'
const localVarPath = this.basePath + '/user/{username}'
.replace('{' + 'username' + '}', String(username));
let queryParameters: any = {};
@ -248,7 +248,7 @@ namespace API.Client {
}
let httpRequestParams: any = {
method: 'DELETE',
url: path,
url: localVarPath,
json: true,

File diff suppressed because it is too large Load Diff