diff --git a/README.md b/README.md index b99ce16bee60..a925e6d886a2 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/modules/swagger-codegen-cli/src/main/java/io/swagger/codegen/cmd/Generate.java b/modules/swagger-codegen-cli/src/main/java/io/swagger/codegen/cmd/Generate.java index c9375c6dab4c..51fd246484aa 100644 --- a/modules/swagger-codegen-cli/src/main/java/io/swagger/codegen/cmd/Generate.java +++ b/modules/swagger-codegen-cli/src/main/java/io/swagger/codegen/cmd/Generate.java @@ -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 map = createMapFromKeyValuePairs(systemProperties); - for (Map.Entry entry : map.entrySet()) { - configurator.addSystemProperty(entry.getKey(), entry.getValue()); - } - } - - private void setInstantiationTypes(CodegenConfigurator configurator) { - final Map map = createMapFromKeyValuePairs(instantiationTypes); - for (Map.Entry entry : map.entrySet()) { - configurator.addInstantiationType(entry.getKey(), entry.getValue()); - } - } - - private void setImportMappings(CodegenConfigurator configurator) { - final Map map = createMapFromKeyValuePairs(importMappings); - for (Map.Entry entry : map.entrySet()) { - configurator.addImportMapping(entry.getKey(), entry.getValue()); - } - } - - private void setTypeMappings(CodegenConfigurator configurator) { - final Map map = createMapFromKeyValuePairs(typeMappings); - for (Map.Entry entry : map.entrySet()) { - configurator.addTypeMapping(entry.getKey(), entry.getValue()); - } - } - - private void setAdditionalProperties(CodegenConfigurator configurator) { - final Map map = createMapFromKeyValuePairs(additionalProperties); - for (Map.Entry entry : map.entrySet()) { - configurator.addAdditionalProperty(entry.getKey(), entry.getValue()); - } - } - - private void setLanguageSpecificPrimitives(CodegenConfigurator configurator) { - final Set set = createSetFromCsvList(languageSpecificPrimitives); - for (String item : set) { - configurator.addLanguageSpecificPrimitive(item); - } - } - - private static Set createSetFromCsvList(String csvProperty) { - final List values = OptionUtils.splitCommaSeparatedList(csvProperty); - return new HashSet(values); - } - - private static Map createMapFromKeyValuePairs(String commaSeparatedKVPairs) { - final List> pairs = OptionUtils.parseCommaSeparatedTuples(commaSeparatedKVPairs); - - Map result = new HashMap(); - - for (Pair pair : pairs) { - result.put(pair.getLeft(), pair.getRight()); - } - - return result; - } } diff --git a/modules/swagger-codegen-maven-plugin/src/main/java/io/swagger/codegen/plugin/AdditionalParams.java b/modules/swagger-codegen-maven-plugin/src/main/java/io/swagger/codegen/plugin/AdditionalParams.java deleted file mode 100644 index 7db012f439cd..000000000000 --- a/modules/swagger-codegen-maven-plugin/src/main/java/io/swagger/codegen/plugin/AdditionalParams.java +++ /dev/null @@ -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() {} -} \ No newline at end of file diff --git a/modules/swagger-codegen-maven-plugin/src/main/java/io/swagger/codegen/plugin/CodeGenMojo.java b/modules/swagger-codegen-maven-plugin/src/main/java/io/swagger/codegen/plugin/CodeGenMojo.java index 0415f0648ca8..79a100bba216 100644 --- a/modules/swagger-codegen-maven-plugin/src/main/java/io/swagger/codegen/plugin/CodeGenMojo.java +++ b/modules/swagger-codegen-maven-plugin/src/main/java/io/swagger/codegen/plugin/CodeGenMojo.java @@ -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 definedOptions = new HashSet(); - for (CliOption langCliOption : config.cliOptions()) { - definedOptions.add(langCliOption.getOpt()); - } - - if (configOptions != null) { - if(configOptions.containsKey("import-mappings")) { - Map mappings = createMapFromKeyValuePairs(configOptions.remove("import-mappings").toString()); - config.importMapping().putAll(mappings); - } - - if(configOptions.containsKey("type-mappings")) { - Map mappings = createMapFromKeyValuePairs(configOptions.remove("type-mappings").toString()); - config.typeMapping().putAll(mappings); - } - - if(configOptions.containsKey("instantiation-types")) { - Map 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 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 createMapFromKeyValuePairs(String commaSeparatedKVPairs) { - final List> pairs = OptionUtils.parseCommaSeparatedTuples(commaSeparatedKVPairs); - - Map result = new HashMap(); - - for (Pair pair : pairs) { - result.put(pair.getLeft(), pair.getRight()); - } - - return result; - } } diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/config/CodegenConfiguratorUtils.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/config/CodegenConfiguratorUtils.java new file mode 100644 index 000000000000..a75928278797 --- /dev/null +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/config/CodegenConfiguratorUtils.java @@ -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. + * + *

+ * This class exists to facilitate testing. These methods could be applied + * to CodegenConfigurator, but this complicates things when mocking CodegenConfigurator. + *

+ */ +public final class CodegenConfiguratorUtils { + + public static void applySystemPropertiesKvp(String systemProperties, CodegenConfigurator configurator) { + final Map map = createMapFromKeyValuePairs(systemProperties); + for (Map.Entry entry : map.entrySet()) { + configurator.addSystemProperty(entry.getKey(), entry.getValue()); + } + } + + public static void applyInstantiationTypesKvp(String instantiationTypes, CodegenConfigurator configurator) { + final Map map = createMapFromKeyValuePairs(instantiationTypes); + for (Map.Entry entry : map.entrySet()) { + configurator.addInstantiationType(entry.getKey(), entry.getValue()); + } + } + + public static void applyImportMappingsKvp(String importMappings, CodegenConfigurator configurator) { + final Map map = createMapFromKeyValuePairs(importMappings); + for (Map.Entry entry : map.entrySet()) { + configurator.addImportMapping(entry.getKey(), entry.getValue()); + } + } + + public static void applyTypeMappingsKvp(String typeMappings, CodegenConfigurator configurator) { + final Map map = createMapFromKeyValuePairs(typeMappings); + for (Map.Entry entry : map.entrySet()) { + configurator.addTypeMapping(entry.getKey(), entry.getValue()); + } + } + + public static void applyAdditionalPropertiesKvp(String additionalProperties, CodegenConfigurator configurator) { + final Map map = createMapFromKeyValuePairs(additionalProperties); + for (Map.Entry entry : map.entrySet()) { + configurator.addAdditionalProperty(entry.getKey(), entry.getValue()); + } + } + + public static void applyLanguageSpecificPrimitivesCsv(String languageSpecificPrimitives, CodegenConfigurator configurator) { + final Set set = createSetFromCsvList(languageSpecificPrimitives); + for (String item : set) { + configurator.addLanguageSpecificPrimitive(item); + } + } + + private static Set createSetFromCsvList(String csvProperty) { + final List values = OptionUtils.splitCommaSeparatedList(csvProperty); + return new HashSet(values); + } + + private static Map createMapFromKeyValuePairs(String commaSeparatedKVPairs) { + final List> pairs = OptionUtils.parseCommaSeparatedTuples(commaSeparatedKVPairs); + + Map result = new HashMap(); + + for (Pair pair : pairs) { + result.put(pair.getLeft(), pair.getRight()); + } + + return result; + } +} diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/AbstractTypeScriptClientCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/AbstractTypeScriptClientCodegen.java index 61ddfd2bf856..daf3d1543b10 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/AbstractTypeScriptClientCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/AbstractTypeScriptClientCodegen.java @@ -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(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(); @@ -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 diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JavaClientCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JavaClientCodegen.java index e96d2704bd9c..516fca1e8b6e 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JavaClientCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JavaClientCodegen.java @@ -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); diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/RubyClientCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/RubyClientCodegen.java index e7305f56b38a..d8469b599ff1 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/RubyClientCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/RubyClientCodegen.java @@ -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 diff --git a/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit2/ApiClient.mustache b/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit2/ApiClient.mustache index 11903b535f56..91a88c5476cf 100644 --- a/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit2/ApiClient.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit2/ApiClient.mustache @@ -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 createService(Class 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 implements Converter 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 requestBodyConverter(Type type, Annotation[] annotations, Retrofit retrofit) { - return gsonConverterFactory.requestBodyConverter(type, annotations, retrofit); + public Converter requestBodyConverter(Type type, Annotation[] parameterAnnotations, Annotation[] methodAnnotations, Retrofit retrofit) { + return gsonConverterFactory.requestBodyConverter(type, parameterAnnotations, methodAnnotations, retrofit); } } diff --git a/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit2/CollectionFormats.mustache b/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit2/CollectionFormats.mustache index a549ea59d1c2..8c91c335dfce 100644 --- a/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit2/CollectionFormats.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit2/CollectionFormats.mustache @@ -4,18 +4,18 @@ import java.util.Arrays; import java.util.List; public class CollectionFormats { - + public static class CSVParams { protected List params; - + public CSVParams() { } - + public CSVParams(List params) { this.params = params; } - + public CSVParams(String... params) { this.params = Arrays.asList(params); } @@ -27,19 +27,19 @@ public class CollectionFormats { public void setParams(List 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 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 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 params) { super(params); } - + public PIPESParams(String... params) { super(params); } @@ -91,5 +91,5 @@ public class CollectionFormats { return StringUtil.join(params.toArray(new String[0]), "|"); } } - + } diff --git a/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit2/build.gradle.mustache b/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit2/build.gradle.mustache index d7dd471b18cb..17dfef0f2d92 100644 --- a/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit2/build.gradle.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit2/build.gradle.mustache @@ -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" diff --git a/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit2/pom.mustache b/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit2/pom.mustache index 40e537161c02..0cb14c49304d 100644 --- a/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit2/pom.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit2/pom.mustache @@ -161,7 +161,7 @@ 1.5.0 - 2.0.0-beta3 + 2.0.0-beta4 {{#useRxJava}}1.0.16{{/useRxJava}} 3.0.1 2.4 diff --git a/modules/swagger-codegen/src/main/resources/TypeScript-Angular/api.mustache b/modules/swagger-codegen/src/main/resources/TypeScript-Angular/api.mustache index 9efea198f360..427479cf6756 100644 --- a/modules/swagger-codegen/src/main/resources/TypeScript-Angular/api.mustache +++ b/modules/swagger-codegen/src/main/resources/TypeScript-Angular/api.mustache @@ -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}} diff --git a/modules/swagger-codegen/src/main/resources/TypeScript-node/api.mustache b/modules/swagger-codegen/src/main/resources/TypeScript-node/api.mustache index a4f2bf620247..9e78174b9564 100644 --- a/modules/swagger-codegen/src/main/resources/TypeScript-node/api.mustache +++ b/modules/swagger-codegen/src/main/resources/TypeScript-node/api.mustache @@ -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}} } diff --git a/modules/swagger-codegen/src/test/java/io/swagger/codegen/typescriptangular/TypeScriptAngularModelTest.java b/modules/swagger-codegen/src/test/java/io/swagger/codegen/typescriptangular/TypeScriptAngularModelTest.java index 78b14f50e876..26e8f841be9f 100644 --- a/modules/swagger-codegen/src/test/java/io/swagger/codegen/typescriptangular/TypeScriptAngularModelTest.java +++ b/modules/swagger-codegen/src/test/java/io/swagger/codegen/typescriptangular/TypeScriptAngularModelTest.java @@ -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"); diff --git a/modules/swagger-codegen/src/test/java/io/swagger/codegen/typescriptnode/TypeScriptNodeModelTest.java b/modules/swagger-codegen/src/test/java/io/swagger/codegen/typescriptnode/TypeScriptNodeModelTest.java index 95398b155cf2..81a67e87b879 100644 --- a/modules/swagger-codegen/src/test/java/io/swagger/codegen/typescriptnode/TypeScriptNodeModelTest.java +++ b/modules/swagger-codegen/src/test/java/io/swagger/codegen/typescriptnode/TypeScriptNodeModelTest.java @@ -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"); diff --git a/samples/client/petstore/clojure/src/swagger_petstore/api/pet.clj b/samples/client/petstore/clojure/src/swagger_petstore/api/pet.clj index 36bdefeffcd5..aaa6e0768e4d 100644 --- a/samples/client/petstore/clojure/src/swagger_petstore/api/pet.clj +++ b/samples/client/petstore/clojure/src/swagger_petstore/api/pet.clj @@ -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)))) diff --git a/samples/client/petstore/clojure/src/swagger_petstore/api/store.clj b/samples/client/petstore/clojure/src/swagger_petstore/api/store.clj index d3877e5887b5..1ccf78d4c3bb 100644 --- a/samples/client/petstore/clojure/src/swagger_petstore/api/store.clj +++ b/samples/client/petstore/clojure/src/swagger_petstore/api/store.clj @@ -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 diff --git a/samples/client/petstore/clojure/src/swagger_petstore/core.clj b/samples/client/petstore/clojure/src/swagger_petstore/core.clj index 665adfbc775c..2d8f596cfc87 100644 --- a/samples/client/petstore/clojure/src/swagger_petstore/core.clj +++ b/samples/client/petstore/clojure/src/swagger_petstore/core.clj @@ -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." diff --git a/samples/client/petstore/clojure/test/swagger_petstore/core_test.clj b/samples/client/petstore/clojure/test/swagger_petstore/core_test.clj index 87ac0a8b73dd..220afbf9d626 100644 --- a/samples/client/petstore/clojure/test/swagger_petstore/core_test.clj +++ b/samples/client/petstore/clojure/test/swagger_petstore/core_test.clj @@ -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*)))) diff --git a/samples/client/petstore/java/retrofit2/build.gradle b/samples/client/petstore/java/retrofit2/build.gradle index 8eee8f18489b..5f5ff488f18e 100644 --- a/samples/client/petstore/java/retrofit2/build.gradle +++ b/samples/client/petstore/java/retrofit2/build.gradle @@ -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" diff --git a/samples/client/petstore/java/retrofit2/pom.xml b/samples/client/petstore/java/retrofit2/pom.xml index 39f3857db33a..07c24f981161 100644 --- a/samples/client/petstore/java/retrofit2/pom.xml +++ b/samples/client/petstore/java/retrofit2/pom.xml @@ -123,21 +123,11 @@ converter-gson ${retrofit-version} - - com.google.code.gson - gson - ${gson-version} - org.apache.oltu.oauth2 org.apache.oltu.oauth2.client ${oltu-version} - - com.squareup.okhttp3 - okhttp - ${okhttp-version} - @@ -150,10 +140,7 @@ 1.5.0 - 2.0.0-beta3 - - 3.0.1 - 2.4 + 2.0.0-beta4 1.0.0 1.0.0 4.12 diff --git a/samples/client/petstore/java/retrofit2/src/main/java/io/swagger/client/ApiClient.java b/samples/client/petstore/java/retrofit2/src/main/java/io/swagger/client/ApiClient.java index dd3bde9372dd..398a1014c71b 100644 --- a/samples/client/petstore/java/retrofit2/src/main/java/io/swagger/client/ApiClient.java +++ b/samples/client/petstore/java/retrofit2/src/main/java/io/swagger/client/ApiClient.java @@ -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 createService(Class 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 implements Converter 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 requestBodyConverter(Type type, Annotation[] annotations, Retrofit retrofit) { - return gsonConverterFactory.requestBodyConverter(type, annotations, retrofit); + public Converter requestBodyConverter(Type type, Annotation[] parameterAnnotations, Annotation[] methodAnnotations, Retrofit retrofit) { + return gsonConverterFactory.requestBodyConverter(type, parameterAnnotations, methodAnnotations, retrofit); } } diff --git a/samples/client/petstore/java/retrofit2/src/main/java/io/swagger/client/CollectionFormats.java b/samples/client/petstore/java/retrofit2/src/main/java/io/swagger/client/CollectionFormats.java index c3cf52575143..e96d1561a7cc 100644 --- a/samples/client/petstore/java/retrofit2/src/main/java/io/swagger/client/CollectionFormats.java +++ b/samples/client/petstore/java/retrofit2/src/main/java/io/swagger/client/CollectionFormats.java @@ -4,18 +4,18 @@ import java.util.Arrays; import java.util.List; public class CollectionFormats { - + public static class CSVParams { protected List params; - + public CSVParams() { } - + public CSVParams(List params) { this.params = params; } - + public CSVParams(String... params) { this.params = Arrays.asList(params); } @@ -27,19 +27,19 @@ public class CollectionFormats { public void setParams(List 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 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 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 params) { super(params); } - + public PIPESParams(String... params) { super(params); } @@ -91,5 +91,5 @@ public class CollectionFormats { return StringUtil.join(params.toArray(new String[0]), "|"); } } - + } diff --git a/samples/client/petstore/java/retrofit2/src/main/java/io/swagger/client/StringUtil.java b/samples/client/petstore/java/retrofit2/src/main/java/io/swagger/client/StringUtil.java index f77418464bfb..22e010034b2a 100644 --- a/samples/client/petstore/java/retrofit2/src/main/java/io/swagger/client/StringUtil.java +++ b/samples/client/petstore/java/retrofit2/src/main/java/io/swagger/client/StringUtil.java @@ -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). diff --git a/samples/client/petstore/java/retrofit2rx/build.gradle b/samples/client/petstore/java/retrofit2rx/build.gradle index 6b72ef69557e..1ab839078a46 100644 --- a/samples/client/petstore/java/retrofit2rx/build.gradle +++ b/samples/client/petstore/java/retrofit2rx/build.gradle @@ -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" diff --git a/samples/client/petstore/java/retrofit2rx/pom.xml b/samples/client/petstore/java/retrofit2rx/pom.xml index 2881967993d8..e5c4e6875118 100644 --- a/samples/client/petstore/java/retrofit2rx/pom.xml +++ b/samples/client/petstore/java/retrofit2rx/pom.xml @@ -123,21 +123,11 @@ converter-gson ${retrofit-version} - - com.google.code.gson - gson - ${gson-version} - org.apache.oltu.oauth2 org.apache.oltu.oauth2.client ${oltu-version} - - com.squareup.okhttp3 - okhttp - ${okhttp-version} - io.reactivex @@ -161,10 +151,8 @@ 1.5.0 - 2.0.0-beta3 + 2.0.0-beta4 1.0.16 - 3.0.1 - 2.4 1.0.0 1.0.0 4.12 diff --git a/samples/client/petstore/java/retrofit2rx/src/main/java/io/swagger/client/ApiClient.java b/samples/client/petstore/java/retrofit2rx/src/main/java/io/swagger/client/ApiClient.java index 5b05ce22e667..800e4db8bd88 100644 --- a/samples/client/petstore/java/retrofit2rx/src/main/java/io/swagger/client/ApiClient.java +++ b/samples/client/petstore/java/retrofit2rx/src/main/java/io/swagger/client/ApiClient.java @@ -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 createService(Class 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 implements Converter 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 requestBodyConverter(Type type, Annotation[] annotations, Retrofit retrofit) { - return gsonConverterFactory.requestBodyConverter(type, annotations, retrofit); + public Converter requestBodyConverter(Type type, Annotation[] parameterAnnotations, Annotation[] methodAnnotations, Retrofit retrofit) { + return gsonConverterFactory.requestBodyConverter(type, parameterAnnotations, methodAnnotations, retrofit); } } diff --git a/samples/client/petstore/java/retrofit2rx/src/main/java/io/swagger/client/CollectionFormats.java b/samples/client/petstore/java/retrofit2rx/src/main/java/io/swagger/client/CollectionFormats.java index c3cf52575143..e96d1561a7cc 100644 --- a/samples/client/petstore/java/retrofit2rx/src/main/java/io/swagger/client/CollectionFormats.java +++ b/samples/client/petstore/java/retrofit2rx/src/main/java/io/swagger/client/CollectionFormats.java @@ -4,18 +4,18 @@ import java.util.Arrays; import java.util.List; public class CollectionFormats { - + public static class CSVParams { protected List params; - + public CSVParams() { } - + public CSVParams(List params) { this.params = params; } - + public CSVParams(String... params) { this.params = Arrays.asList(params); } @@ -27,19 +27,19 @@ public class CollectionFormats { public void setParams(List 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 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 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 params) { super(params); } - + public PIPESParams(String... params) { super(params); } @@ -91,5 +91,5 @@ public class CollectionFormats { return StringUtil.join(params.toArray(new String[0]), "|"); } } - + } diff --git a/samples/client/petstore/java/retrofit2rx/src/main/java/io/swagger/client/StringUtil.java b/samples/client/petstore/java/retrofit2rx/src/main/java/io/swagger/client/StringUtil.java index 9f06b50e8b93..1e7e09a6aa99 100644 --- a/samples/client/petstore/java/retrofit2rx/src/main/java/io/swagger/client/StringUtil.java +++ b/samples/client/petstore/java/retrofit2rx/src/main/java/io/swagger/client/StringUtil.java @@ -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). diff --git a/samples/client/petstore/typescript-angular/API/Client/PetApi.ts b/samples/client/petstore/typescript-angular/API/Client/PetApi.ts index 50a31d126a52..98a18b1124f0 100644 --- a/samples/client/petstore/typescript-angular/API/Client/PetApi.ts +++ b/samples/client/petstore/typescript-angular/API/Client/PetApi.ts @@ -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, extraHttpRequestParams?: any ) : ng.IHttpPromise> { - 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, extraHttpRequestParams?: any ) : ng.IHttpPromise> { - 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 { - 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 < 10. ID > 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 { - const path = this.basePath + '/pet/{petId}?testing_byte_array=true' + public petPetIdtestingByteArraytrueGet (petId: number, extraHttpRequestParams?: any ) : ng.IHttpPromise { + 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, diff --git a/samples/client/petstore/typescript-angular/API/Client/StoreApi.ts b/samples/client/petstore/typescript-angular/API/Client/StoreApi.ts index 3d3c445a144f..7c9115fbe8f4 100644 --- a/samples/client/petstore/typescript-angular/API/Client/StoreApi.ts +++ b/samples/client/petstore/typescript-angular/API/Client/StoreApi.ts @@ -26,18 +26,48 @@ namespace API.Client { return 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> { + 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 { - 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 { - 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, diff --git a/samples/client/petstore/typescript-angular/API/Client/UserApi.ts b/samples/client/petstore/typescript-angular/API/Client/UserApi.ts index 376bdb8935aa..719085a63ac6 100644 --- a/samples/client/petstore/typescript-angular/API/Client/UserApi.ts +++ b/samples/client/petstore/typescript-angular/API/Client/UserApi.ts @@ -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, 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, 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 { - 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 { - 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, diff --git a/samples/client/petstore/typescript-node/api.ts b/samples/client/petstore/typescript-node/api.ts index c6a0b323ebd5..8acf6f060008 100644 --- a/samples/client/petstore/typescript-node/api.ts +++ b/samples/client/petstore/typescript-node/api.ts @@ -127,7 +127,11 @@ export class UserApi { public authentications = { 'default': new VoidAuth(), + 'test_api_key_header': new ApiKeyAuth('header', 'test_api_key_header'), 'api_key': new ApiKeyAuth('header', 'api_key'), + 'test_api_client_secret': new ApiKeyAuth('header', 'x-test_api_client_secret'), + 'test_api_client_id': new ApiKeyAuth('header', 'x-test_api_client_id'), + 'test_api_key_query': new ApiKeyAuth('query', 'test_api_key_query'), 'petstore_auth': new OAuth(), } @@ -144,10 +148,26 @@ export class UserApi { } } + set apiKey(key: string) { + this.authentications.test_api_key_header.apiKey = key; + } + set apiKey(key: string) { this.authentications.api_key.apiKey = key; } + set apiKey(key: string) { + this.authentications.test_api_client_secret.apiKey = key; + } + + set apiKey(key: string) { + this.authentications.test_api_client_id.apiKey = key; + } + + set apiKey(key: string) { + this.authentications.test_api_key_query.apiKey = key; + } + set accessToken(token: string) { this.authentications.petstore_auth.accessToken = token; } @@ -165,7 +185,7 @@ export class UserApi { * @param body Created user object */ public createUser (body?: User) : Promise<{ response: http.ClientResponse; body?: any; }> { - const path = this.basePath + '/user'; + const localVarPath = this.basePath + '/user'; let queryParameters: any = {}; let headerParams: any = this.extendObj({}, this.defaultHeaders); let formParams: any = {}; @@ -173,13 +193,13 @@ export class UserApi { let useFormData = false; - let deferred = promise.defer<{ response: http.ClientResponse; body?: any; }>(); + let localVarDeferred = promise.defer<{ response: http.ClientResponse; body?: any; }>(); let requestOptions: request.Options = { method: 'POST', qs: queryParameters, headers: headerParams, - uri: path, + uri: localVarPath, json: true, body: body, } @@ -196,17 +216,17 @@ export class UserApi { 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; } /** * Creates list of users with given input array @@ -214,7 +234,7 @@ export class UserApi { * @param body List of user object */ public createUsersWithArrayInput (body?: Array) : Promise<{ response: http.ClientResponse; body?: any; }> { - const path = this.basePath + '/user/createWithArray'; + const localVarPath = this.basePath + '/user/createWithArray'; let queryParameters: any = {}; let headerParams: any = this.extendObj({}, this.defaultHeaders); let formParams: any = {}; @@ -222,13 +242,13 @@ export class UserApi { let useFormData = false; - let deferred = promise.defer<{ response: http.ClientResponse; body?: any; }>(); + let localVarDeferred = promise.defer<{ response: http.ClientResponse; body?: any; }>(); let requestOptions: request.Options = { method: 'POST', qs: queryParameters, headers: headerParams, - uri: path, + uri: localVarPath, json: true, body: body, } @@ -245,17 +265,17 @@ export class UserApi { 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; } /** * Creates list of users with given input array @@ -263,7 +283,7 @@ export class UserApi { * @param body List of user object */ public createUsersWithListInput (body?: Array) : Promise<{ response: http.ClientResponse; body?: any; }> { - const path = this.basePath + '/user/createWithList'; + const localVarPath = this.basePath + '/user/createWithList'; let queryParameters: any = {}; let headerParams: any = this.extendObj({}, this.defaultHeaders); let formParams: any = {}; @@ -271,13 +291,13 @@ export class UserApi { let useFormData = false; - let deferred = promise.defer<{ response: http.ClientResponse; body?: any; }>(); + let localVarDeferred = promise.defer<{ response: http.ClientResponse; body?: any; }>(); let requestOptions: request.Options = { method: 'POST', qs: queryParameters, headers: headerParams, - uri: path, + uri: localVarPath, json: true, body: body, } @@ -294,17 +314,17 @@ export class UserApi { 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; } /** * Logs user into the system @@ -313,7 +333,7 @@ export class UserApi { * @param password The password for login in clear text */ public loginUser (username?: string, password?: string) : Promise<{ response: http.ClientResponse; body: string; }> { - const path = this.basePath + '/user/login'; + const localVarPath = this.basePath + '/user/login'; let queryParameters: any = {}; let headerParams: any = this.extendObj({}, this.defaultHeaders); let formParams: any = {}; @@ -329,13 +349,13 @@ export class UserApi { let useFormData = false; - let deferred = promise.defer<{ response: http.ClientResponse; body: string; }>(); + let localVarDeferred = promise.defer<{ response: http.ClientResponse; body: string; }>(); let requestOptions: request.Options = { method: 'GET', qs: queryParameters, headers: headerParams, - uri: path, + uri: localVarPath, json: true, } @@ -351,24 +371,24 @@ export class UserApi { 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; } /** * Logs out current logged in user session * */ public logoutUser () : Promise<{ response: http.ClientResponse; body?: any; }> { - const path = this.basePath + '/user/logout'; + const localVarPath = this.basePath + '/user/logout'; let queryParameters: any = {}; let headerParams: any = this.extendObj({}, this.defaultHeaders); let formParams: any = {}; @@ -376,13 +396,13 @@ export class UserApi { let useFormData = false; - let deferred = promise.defer<{ response: http.ClientResponse; body?: any; }>(); + let localVarDeferred = promise.defer<{ response: http.ClientResponse; body?: any; }>(); let requestOptions: request.Options = { method: 'GET', qs: queryParameters, headers: headerParams, - uri: path, + uri: localVarPath, json: true, } @@ -398,17 +418,17 @@ export class UserApi { 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; } /** * Get user by user name @@ -416,7 +436,7 @@ export class UserApi { * @param username The name that needs to be fetched. Use user1 for testing. */ public getUserByName (username: string) : Promise<{ response: http.ClientResponse; body: User; }> { - const path = this.basePath + '/user/{username}' + const localVarPath = this.basePath + '/user/{username}' .replace('{' + 'username' + '}', String(username)); let queryParameters: any = {}; let headerParams: any = this.extendObj({}, this.defaultHeaders); @@ -430,13 +450,13 @@ export class UserApi { let useFormData = false; - let deferred = promise.defer<{ response: http.ClientResponse; body: User; }>(); + let localVarDeferred = promise.defer<{ response: http.ClientResponse; body: User; }>(); let requestOptions: request.Options = { method: 'GET', qs: queryParameters, headers: headerParams, - uri: path, + uri: localVarPath, json: true, } @@ -452,17 +472,17 @@ export class UserApi { 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; } /** * Updated user @@ -471,7 +491,7 @@ export class UserApi { * @param body Updated user object */ public updateUser (username: string, body?: User) : Promise<{ response: http.ClientResponse; body?: any; }> { - const path = this.basePath + '/user/{username}' + const localVarPath = this.basePath + '/user/{username}' .replace('{' + 'username' + '}', String(username)); let queryParameters: any = {}; let headerParams: any = this.extendObj({}, this.defaultHeaders); @@ -485,13 +505,13 @@ export class UserApi { let useFormData = false; - let deferred = promise.defer<{ response: http.ClientResponse; body?: any; }>(); + let localVarDeferred = promise.defer<{ response: http.ClientResponse; body?: any; }>(); let requestOptions: request.Options = { method: 'PUT', qs: queryParameters, headers: headerParams, - uri: path, + uri: localVarPath, json: true, body: body, } @@ -508,17 +528,17 @@ export class UserApi { 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; } /** * Delete user @@ -526,7 +546,7 @@ export class UserApi { * @param username The name that needs to be deleted */ public deleteUser (username: string) : Promise<{ response: http.ClientResponse; body?: any; }> { - const path = this.basePath + '/user/{username}' + const localVarPath = this.basePath + '/user/{username}' .replace('{' + 'username' + '}', String(username)); let queryParameters: any = {}; let headerParams: any = this.extendObj({}, this.defaultHeaders); @@ -540,13 +560,13 @@ export class UserApi { let useFormData = false; - let deferred = promise.defer<{ response: http.ClientResponse; body?: any; }>(); + let localVarDeferred = promise.defer<{ response: http.ClientResponse; body?: any; }>(); let requestOptions: request.Options = { method: 'DELETE', qs: queryParameters, headers: headerParams, - uri: path, + uri: localVarPath, json: true, } @@ -562,17 +582,17 @@ export class UserApi { 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; } } export class PetApi { @@ -583,7 +603,11 @@ export class PetApi { public authentications = { 'default': new VoidAuth(), + 'test_api_key_header': new ApiKeyAuth('header', 'test_api_key_header'), 'api_key': new ApiKeyAuth('header', 'api_key'), + 'test_api_client_secret': new ApiKeyAuth('header', 'x-test_api_client_secret'), + 'test_api_client_id': new ApiKeyAuth('header', 'x-test_api_client_id'), + 'test_api_key_query': new ApiKeyAuth('query', 'test_api_key_query'), 'petstore_auth': new OAuth(), } @@ -600,10 +624,26 @@ export class PetApi { } } + set apiKey(key: string) { + this.authentications.test_api_key_header.apiKey = key; + } + set apiKey(key: string) { this.authentications.api_key.apiKey = key; } + set apiKey(key: string) { + this.authentications.test_api_client_secret.apiKey = key; + } + + set apiKey(key: string) { + this.authentications.test_api_client_id.apiKey = key; + } + + set apiKey(key: string) { + this.authentications.test_api_key_query.apiKey = key; + } + set accessToken(token: string) { this.authentications.petstore_auth.accessToken = token; } @@ -621,7 +661,7 @@ export class PetApi { * @param body Pet object that needs to be added to the store */ public updatePet (body?: Pet) : Promise<{ response: http.ClientResponse; body?: any; }> { - const path = this.basePath + '/pet'; + const localVarPath = this.basePath + '/pet'; let queryParameters: any = {}; let headerParams: any = this.extendObj({}, this.defaultHeaders); let formParams: any = {}; @@ -629,13 +669,13 @@ export class PetApi { let useFormData = false; - let deferred = promise.defer<{ response: http.ClientResponse; body?: any; }>(); + let localVarDeferred = promise.defer<{ response: http.ClientResponse; body?: any; }>(); let requestOptions: request.Options = { method: 'PUT', qs: queryParameters, headers: headerParams, - uri: path, + uri: localVarPath, json: true, body: body, } @@ -654,17 +694,17 @@ export class PetApi { 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; } /** * Add a new pet to the store @@ -672,7 +712,7 @@ export class PetApi { * @param body Pet object that needs to be added to the store */ public addPet (body?: Pet) : Promise<{ response: http.ClientResponse; body?: any; }> { - const path = this.basePath + '/pet'; + const localVarPath = this.basePath + '/pet'; let queryParameters: any = {}; let headerParams: any = this.extendObj({}, this.defaultHeaders); let formParams: any = {}; @@ -680,13 +720,13 @@ export class PetApi { let useFormData = false; - let deferred = promise.defer<{ response: http.ClientResponse; body?: any; }>(); + let localVarDeferred = promise.defer<{ response: http.ClientResponse; body?: any; }>(); let requestOptions: request.Options = { method: 'POST', qs: queryParameters, headers: headerParams, - uri: path, + uri: localVarPath, json: true, body: body, } @@ -705,25 +745,25 @@ export class PetApi { 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; } /** * 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) : Promise<{ response: http.ClientResponse; body: Array; }> { - const path = this.basePath + '/pet/findByStatus'; + const localVarPath = this.basePath + '/pet/findByStatus'; let queryParameters: any = {}; let headerParams: any = this.extendObj({}, this.defaultHeaders); let formParams: any = {}; @@ -735,13 +775,13 @@ export class PetApi { let useFormData = false; - let deferred = promise.defer<{ response: http.ClientResponse; body: Array; }>(); + let localVarDeferred = promise.defer<{ response: http.ClientResponse; body: Array; }>(); let requestOptions: request.Options = { method: 'GET', qs: queryParameters, headers: headerParams, - uri: path, + uri: localVarPath, json: true, } @@ -759,17 +799,17 @@ export class PetApi { 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; } /** * Finds Pets by tags @@ -777,7 +817,7 @@ export class PetApi { * @param tags Tags to filter by */ public findPetsByTags (tags?: Array) : Promise<{ response: http.ClientResponse; body: Array; }> { - const path = this.basePath + '/pet/findByTags'; + const localVarPath = this.basePath + '/pet/findByTags'; let queryParameters: any = {}; let headerParams: any = this.extendObj({}, this.defaultHeaders); let formParams: any = {}; @@ -789,13 +829,13 @@ export class PetApi { let useFormData = false; - let deferred = promise.defer<{ response: http.ClientResponse; body: Array; }>(); + let localVarDeferred = promise.defer<{ response: http.ClientResponse; body: Array; }>(); let requestOptions: request.Options = { method: 'GET', qs: queryParameters, headers: headerParams, - uri: path, + uri: localVarPath, json: true, } @@ -813,17 +853,17 @@ export class PetApi { 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; } /** * Find pet by ID @@ -831,7 +871,7 @@ export class PetApi { * @param petId ID of pet that needs to be fetched */ public getPetById (petId: number) : Promise<{ response: http.ClientResponse; body: Pet; }> { - const path = this.basePath + '/pet/{petId}' + const localVarPath = this.basePath + '/pet/{petId}' .replace('{' + 'petId' + '}', String(petId)); let queryParameters: any = {}; let headerParams: any = this.extendObj({}, this.defaultHeaders); @@ -845,18 +885,20 @@ export class PetApi { let useFormData = false; - let deferred = promise.defer<{ response: http.ClientResponse; body: Pet; }>(); + let localVarDeferred = promise.defer<{ response: http.ClientResponse; body: Pet; }>(); let requestOptions: request.Options = { method: 'GET', qs: queryParameters, headers: headerParams, - uri: path, + uri: localVarPath, json: true, } this.authentications.api_key.applyToRequest(requestOptions); + this.authentications.petstore_auth.applyToRequest(requestOptions); + this.authentications.default.applyToRequest(requestOptions); if (Object.keys(formParams).length) { @@ -869,17 +911,17 @@ export class PetApi { 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; } /** * Updates a pet in the store with form data @@ -889,7 +931,7 @@ export class PetApi { * @param status Updated status of the pet */ public updatePetWithForm (petId: string, name?: string, status?: string) : Promise<{ response: http.ClientResponse; body?: any; }> { - const path = this.basePath + '/pet/{petId}' + const localVarPath = this.basePath + '/pet/{petId}' .replace('{' + 'petId' + '}', String(petId)); let queryParameters: any = {}; let headerParams: any = this.extendObj({}, this.defaultHeaders); @@ -911,13 +953,13 @@ export class PetApi { formParams['status'] = status; } - let deferred = promise.defer<{ response: http.ClientResponse; body?: any; }>(); + let localVarDeferred = promise.defer<{ response: http.ClientResponse; body?: any; }>(); let requestOptions: request.Options = { method: 'POST', qs: queryParameters, headers: headerParams, - uri: path, + uri: localVarPath, json: true, } @@ -935,17 +977,17 @@ export class PetApi { 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; } /** * Deletes a pet @@ -954,7 +996,7 @@ export class PetApi { * @param apiKey */ public deletePet (petId: number, apiKey?: string) : Promise<{ response: http.ClientResponse; body?: any; }> { - const path = this.basePath + '/pet/{petId}' + const localVarPath = this.basePath + '/pet/{petId}' .replace('{' + 'petId' + '}', String(petId)); let queryParameters: any = {}; let headerParams: any = this.extendObj({}, this.defaultHeaders); @@ -970,13 +1012,13 @@ export class PetApi { let useFormData = false; - let deferred = promise.defer<{ response: http.ClientResponse; body?: any; }>(); + let localVarDeferred = promise.defer<{ response: http.ClientResponse; body?: any; }>(); let requestOptions: request.Options = { method: 'DELETE', qs: queryParameters, headers: headerParams, - uri: path, + uri: localVarPath, json: true, } @@ -994,17 +1036,17 @@ export class PetApi { 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; } /** * uploads an image @@ -1014,7 +1056,7 @@ export class PetApi { * @param file file to upload */ public uploadFile (petId: number, additionalMetadata?: string, file?: any) : Promise<{ response: http.ClientResponse; body?: any; }> { - const path = this.basePath + '/pet/{petId}/uploadImage' + const localVarPath = this.basePath + '/pet/{petId}/uploadImage' .replace('{' + 'petId' + '}', String(petId)); let queryParameters: any = {}; let headerParams: any = this.extendObj({}, this.defaultHeaders); @@ -1037,13 +1079,13 @@ export class PetApi { } useFormData = true; - let deferred = promise.defer<{ response: http.ClientResponse; body?: any; }>(); + let localVarDeferred = promise.defer<{ response: http.ClientResponse; body?: any; }>(); let requestOptions: request.Options = { method: 'POST', qs: queryParameters, headers: headerParams, - uri: path, + uri: localVarPath, json: true, } @@ -1061,25 +1103,25 @@ export class PetApi { 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; } /** * 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 * @param petId ID of pet that needs to be fetched */ - public getPetByIdWithByteArray (petId: number) : Promise<{ response: http.ClientResponse; body: string; }> { - const path = this.basePath + '/pet/{petId}?testing_byte_array=true' + public petPetIdtestingByteArraytrueGet (petId: number) : Promise<{ response: http.ClientResponse; body: 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); @@ -1088,23 +1130,25 @@ export class PetApi { // 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 useFormData = false; - let deferred = promise.defer<{ response: http.ClientResponse; body: string; }>(); + let localVarDeferred = promise.defer<{ response: http.ClientResponse; body: string; }>(); let requestOptions: request.Options = { method: 'GET', qs: queryParameters, headers: headerParams, - uri: path, + uri: localVarPath, json: true, } this.authentications.api_key.applyToRequest(requestOptions); + this.authentications.petstore_auth.applyToRequest(requestOptions); + this.authentications.default.applyToRequest(requestOptions); if (Object.keys(formParams).length) { @@ -1117,17 +1161,17 @@ export class PetApi { 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; } /** * Fake endpoint to test byte array in body parameter for adding a new pet to the store @@ -1135,7 +1179,7 @@ export class PetApi { * @param body Pet object in the form of byte array */ public addPetUsingByteArray (body?: string) : Promise<{ response: http.ClientResponse; body?: any; }> { - 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 formParams: any = {}; @@ -1143,13 +1187,13 @@ export class PetApi { let useFormData = false; - let deferred = promise.defer<{ response: http.ClientResponse; body?: any; }>(); + let localVarDeferred = promise.defer<{ response: http.ClientResponse; body?: any; }>(); let requestOptions: request.Options = { method: 'POST', qs: queryParameters, headers: headerParams, - uri: path, + uri: localVarPath, json: true, body: body, } @@ -1168,17 +1212,17 @@ export class PetApi { 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; } } export class StoreApi { @@ -1189,7 +1233,11 @@ export class StoreApi { public authentications = { 'default': new VoidAuth(), + 'test_api_key_header': new ApiKeyAuth('header', 'test_api_key_header'), 'api_key': new ApiKeyAuth('header', 'api_key'), + 'test_api_client_secret': new ApiKeyAuth('header', 'x-test_api_client_secret'), + 'test_api_client_id': new ApiKeyAuth('header', 'x-test_api_client_id'), + 'test_api_key_query': new ApiKeyAuth('query', 'test_api_key_query'), 'petstore_auth': new OAuth(), } @@ -1206,10 +1254,26 @@ export class StoreApi { } } + set apiKey(key: string) { + this.authentications.test_api_key_header.apiKey = key; + } + set apiKey(key: string) { this.authentications.api_key.apiKey = key; } + set apiKey(key: string) { + this.authentications.test_api_client_secret.apiKey = key; + } + + set apiKey(key: string) { + this.authentications.test_api_client_id.apiKey = key; + } + + set apiKey(key: string) { + this.authentications.test_api_key_query.apiKey = key; + } + set accessToken(token: string) { this.authentications.petstore_auth.accessToken = token; } @@ -1221,12 +1285,68 @@ export class StoreApi { } return 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) : Promise<{ response: http.ClientResponse; body: Array; }> { + const localVarPath = this.basePath + '/store/findByStatus'; + let queryParameters: any = {}; + let headerParams: any = this.extendObj({}, this.defaultHeaders); + let formParams: any = {}; + + + if (status !== undefined) { + queryParameters['status'] = status; + } + + let useFormData = false; + + let localVarDeferred = promise.defer<{ response: http.ClientResponse; body: Array; }>(); + + let requestOptions: request.Options = { + method: 'GET', + qs: queryParameters, + headers: headerParams, + uri: localVarPath, + json: true, + } + + this.authentications.test_api_client_id.applyToRequest(requestOptions); + + this.authentications.test_api_client_secret.applyToRequest(requestOptions); + + this.authentications.default.applyToRequest(requestOptions); + + if (Object.keys(formParams).length) { + if (useFormData) { + (requestOptions).formData = formParams; + } else { + requestOptions.form = formParams; + } + } + + request(requestOptions, (error, response, body) => { + if (error) { + localVarDeferred.reject(error); + } else { + if (response.statusCode >= 200 && response.statusCode <= 299) { + localVarDeferred.resolve({ response: response, body: body }); + } else { + localVarDeferred.reject({ response: response, body: body }); + } + } + }); + + return localVarDeferred.promise; + } /** * Returns pet inventories by status * Returns a map of status codes to quantities */ public getInventory () : Promise<{ response: http.ClientResponse; body: { [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 formParams: any = {}; @@ -1234,13 +1354,13 @@ export class StoreApi { let useFormData = false; - let deferred = promise.defer<{ response: http.ClientResponse; body: { [key: string]: number; }; }>(); + let localVarDeferred = promise.defer<{ response: http.ClientResponse; body: { [key: string]: number; }; }>(); let requestOptions: request.Options = { method: 'GET', qs: queryParameters, headers: headerParams, - uri: path, + uri: localVarPath, json: true, } @@ -1258,17 +1378,17 @@ export class StoreApi { 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; } /** * Place an order for a pet @@ -1276,7 +1396,7 @@ export class StoreApi { * @param body order placed for purchasing the pet */ public placeOrder (body?: Order) : Promise<{ response: http.ClientResponse; body: Order; }> { - const path = this.basePath + '/store/order'; + const localVarPath = this.basePath + '/store/order'; let queryParameters: any = {}; let headerParams: any = this.extendObj({}, this.defaultHeaders); let formParams: any = {}; @@ -1284,17 +1404,21 @@ export class StoreApi { let useFormData = false; - let deferred = promise.defer<{ response: http.ClientResponse; body: Order; }>(); + let localVarDeferred = promise.defer<{ response: http.ClientResponse; body: Order; }>(); let requestOptions: request.Options = { method: 'POST', qs: queryParameters, headers: headerParams, - uri: path, + uri: localVarPath, json: true, body: body, } + this.authentications.test_api_client_id.applyToRequest(requestOptions); + + this.authentications.test_api_client_secret.applyToRequest(requestOptions); + this.authentications.default.applyToRequest(requestOptions); if (Object.keys(formParams).length) { @@ -1307,17 +1431,17 @@ export class StoreApi { 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; } /** * Find purchase order by ID @@ -1325,7 +1449,7 @@ export class StoreApi { * @param orderId ID of pet that needs to be fetched */ public getOrderById (orderId: string) : Promise<{ response: http.ClientResponse; body: Order; }> { - const path = this.basePath + '/store/order/{orderId}' + const localVarPath = this.basePath + '/store/order/{orderId}' .replace('{' + 'orderId' + '}', String(orderId)); let queryParameters: any = {}; let headerParams: any = this.extendObj({}, this.defaultHeaders); @@ -1339,16 +1463,20 @@ export class StoreApi { let useFormData = false; - let deferred = promise.defer<{ response: http.ClientResponse; body: Order; }>(); + let localVarDeferred = promise.defer<{ response: http.ClientResponse; body: Order; }>(); let requestOptions: request.Options = { method: 'GET', qs: queryParameters, headers: headerParams, - uri: path, + uri: localVarPath, json: true, } + this.authentications.test_api_key_header.applyToRequest(requestOptions); + + this.authentications.test_api_key_query.applyToRequest(requestOptions); + this.authentications.default.applyToRequest(requestOptions); if (Object.keys(formParams).length) { @@ -1361,17 +1489,17 @@ export class StoreApi { 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; } /** * Delete purchase order by ID @@ -1379,7 +1507,7 @@ export class StoreApi { * @param orderId ID of the order that needs to be deleted */ public deleteOrder (orderId: string) : Promise<{ response: http.ClientResponse; body?: any; }> { - const path = this.basePath + '/store/order/{orderId}' + const localVarPath = this.basePath + '/store/order/{orderId}' .replace('{' + 'orderId' + '}', String(orderId)); let queryParameters: any = {}; let headerParams: any = this.extendObj({}, this.defaultHeaders); @@ -1393,13 +1521,13 @@ export class StoreApi { let useFormData = false; - let deferred = promise.defer<{ response: http.ClientResponse; body?: any; }>(); + let localVarDeferred = promise.defer<{ response: http.ClientResponse; body?: any; }>(); let requestOptions: request.Options = { method: 'DELETE', qs: queryParameters, headers: headerParams, - uri: path, + uri: localVarPath, json: true, } @@ -1415,16 +1543,16 @@ export class StoreApi { 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; } }