From b95027194001818cb6ab4a2f9eee1c9d49dbb130 Mon Sep 17 00:00:00 2001 From: Andrew Z Allen Date: Wed, 27 Jan 2016 19:08:09 -0700 Subject: [PATCH 1/6] Add a Javascript (Closure) Angular generator. --- ...JavascriptClosureAngularClientCodegen.java | 206 ++++++++++++++++++ .../Javascript-Closure-Angular/api.mustache | 143 ++++++++++++ .../Javascript-Closure-Angular/model.mustache | 40 ++++ .../services/io.swagger.codegen.CodegenConfig | 1 + ...iptClosureAnularClientOptionsProvider.java | 30 +++ 5 files changed, 420 insertions(+) create mode 100644 modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JavascriptClosureAngularClientCodegen.java create mode 100644 modules/swagger-codegen/src/main/resources/Javascript-Closure-Angular/api.mustache create mode 100644 modules/swagger-codegen/src/main/resources/Javascript-Closure-Angular/model.mustache create mode 100644 modules/swagger-codegen/src/test/java/io/swagger/codegen/options/JavascriptClosureAnularClientOptionsProvider.java diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JavascriptClosureAngularClientCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JavascriptClosureAngularClientCodegen.java new file mode 100644 index 000000000000..e74dff5f8617 --- /dev/null +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JavascriptClosureAngularClientCodegen.java @@ -0,0 +1,206 @@ +package io.swagger.codegen.languages; + +import io.swagger.codegen.CodegenModel; +import io.swagger.codegen.*; +import io.swagger.models.properties.*; + +import java.util.TreeSet; +import java.util.*; +import java.io.File; + +public class JavascriptClosureAngularClientCodegen extends DefaultCodegen implements CodegenConfig { + public JavascriptClosureAngularClientCodegen() { + super(); + + supportsInheritance = false; + reservedWords = new HashSet(Arrays.asList("abstract", + "continue", "for", "new", "switch", "assert", "default", "if", + "package", "synchronized", "do", "goto", "private", + "this", "break", "double", "implements", "protected", "throw", + "byte", "else", "import", "public", "throws", "case", "enum", + "instanceof", "return", "transient", "catch", "extends", "int", + "short", "try", "char", "final", "interface", "static", "void", + "class", "finally", "const", "super", "while")); + + languageSpecificPrimitives = new HashSet(Arrays.asList( + "string", + "boolean", + "number", + "Object", + "Blob", + "Date")); + instantiationTypes.put("array", "Array"); + + typeMapping = new HashMap(); + typeMapping.put("Array", "Array"); + typeMapping.put("array", "Array"); + typeMapping.put("List", "Array"); + typeMapping.put("boolean", "boolean"); + typeMapping.put("string", "string"); + typeMapping.put("int", "number"); + typeMapping.put("float", "number"); + typeMapping.put("number", "number"); + typeMapping.put("long", "number"); + typeMapping.put("short", "number"); + typeMapping.put("char", "string"); + typeMapping.put("double", "number"); + typeMapping.put("object", "Object"); + typeMapping.put("Object", "Object"); + typeMapping.put("File", "Blob"); + typeMapping.put("file", "Blob"); + typeMapping.put("integer", "number"); + typeMapping.put("Map", "Object"); + typeMapping.put("map", "Object"); + typeMapping.put("DateTime", "Date"); + + outputFolder = "generated-code/javascript-closure-angular"; + modelTemplateFiles.put("model.mustache", ".js"); + apiTemplateFiles.put("api.mustache", ".js"); + embeddedTemplateDir = templateDir = "Javascript-Closure-Angular"; + apiPackage = "API.Client"; + modelPackage = "API.Client"; + } + + @Override + public String getName() { + return "javascript-closure-angular"; + } + + @Override + public String getHelp() { + return "Generates a Javascript AngularJS client library annotated with Google Closure Compiler annotations" + + "(https://developers.google.com/closure/compiler/docs/js-for-compiler?hl=en)"; + } + + @Override + public CodegenType getTag() { + return CodegenType.CLIENT; + } + + @Override + public String escapeReservedWord(String name) { + return "_" + name; + } + + @Override + public String apiFileFolder() { + return outputFolder + "/" + apiPackage().replace('.', File.separatorChar); + } + + public String modelFileFolder() { + return outputFolder + "/" + modelPackage().replace('.', File.separatorChar); + } + + @Override + public String toVarName(String name) { + // replace - with _ e.g. created-at => created_at + name = name.replaceAll("-", "_"); + + // if it's all uppper case, do nothing + if (name.matches("^[A-Z_]*$")) + return name; + + // camelize the variable name + // pet_id => PetId + name = camelize(name, true); + + // for reserved word or word starting with number, append _ + if (reservedWords.contains(name) || name.matches("^\\d.*")) + name = escapeReservedWord(name); + + return name; + } + + @Override + public String toParamName(String name) { + // should be the same as variable name + return toVarName(name); + } + + @Override + public String toModelName(String name) { + // model name cannot use reserved keyword, e.g. return + if (reservedWords.contains(name)) + throw new RuntimeException(name + + " (reserved word) cannot be used as a model name"); + + // camelize the model name + // phone_number => PhoneNumber + return camelize(name); + } + + @Override + public String toModelFilename(String name) { + // should be the same as the model name + return toModelName(name); + } + + @Override + public String getTypeDeclaration(Property p) { + if (p instanceof ArrayProperty) { + ArrayProperty ap = (ArrayProperty) p; + Property inner = ap.getItems(); + return getSwaggerType(p) + ""; + } else if (p instanceof MapProperty) { + MapProperty mp = (MapProperty) p; + Property inner = mp.getAdditionalProperties(); + return "Object"; + } else if (p instanceof FileProperty) { + return "Object"; + } + String type = super.getTypeDeclaration(p); + if (type.equals("boolean") || + type.equals("Date") || + type.equals("number") || + type.equals("string")) { + return type; + } + return apiPackage + "." + type; + } + + @Override + public String getSwaggerType(Property p) { + String swaggerType = super.getSwaggerType(p); + String type = null; + if (typeMapping.containsKey(swaggerType)) { + type = typeMapping.get(swaggerType); + if (languageSpecificPrimitives.contains(type)) + return type; + } else + type = swaggerType; + return type; + } + + @Override + public Map postProcessModels(Map objs) { + + List models = (List) objs.get("models"); + for (Object _mo : models) { + Map mo = (Map) _mo; + CodegenModel cm = (CodegenModel) mo.get("model"); + cm.imports = new TreeSet(cm.imports); + for (CodegenProperty var : cm.vars) { + // handle default value for enum, e.g. available => StatusEnum.available + if (var.isEnum && var.defaultValue != null && !"null".equals(var.defaultValue)) { + var.defaultValue = var.datatypeWithEnum + "." + var.defaultValue; + } + } + } + return objs; + } + + @Override + public Map postProcessOperations(Map objs) { + if (objs.get("imports") instanceof List) { + List> imports = (ArrayList>)objs.get("imports"); + Collections.sort(imports, new Comparator>() { + public int compare(Map o1, Map o2) { + return o1.get("import").compareTo(o2.get("import")); + } + }); + objs.put("imports", imports); + } + return objs; + } + +} diff --git a/modules/swagger-codegen/src/main/resources/Javascript-Closure-Angular/api.mustache b/modules/swagger-codegen/src/main/resources/Javascript-Closure-Angular/api.mustache new file mode 100644 index 000000000000..e6934799f529 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/Javascript-Closure-Angular/api.mustache @@ -0,0 +1,143 @@ +/** + * @fileoverview AUTOMATICALLY GENERATED service for {{package}}.{{classname}}. + * Do not edit this file by hand or your changes will be lost next time it is + * generated.{{#appDescription}} + * + * {{ appDescription }}{{/appDescription}}{{#version}} + * Version: {{version}}{{/version}}{{#appContact}} + * Contact: {{appContact}}{{/appContact}} + * Generated at: {{generatedDate}} + * Generated by: {{generatorClass}} + */{{#licenseInfo}} +/** + * @license {{licenseInfo}}{{#licenseUrl}} + * {{licenseUrl}}{{/licenseUrl}} + */ +{{/licenseInfo}} + +goog.provide('{{package}}.{{classname}}'); + +{{#imports}} +goog.require('{{import}}'); +{{/imports}} +{{#operations}} + +/** +{{#description}} + * {{&description}} +{{/description}} + * @constructor + * @param {!angular.$http} $http + * @param {!angular.$injector} $injector + * @struct + */ +{{package}}.{{classname}} = function($http, $injector) { + /** @private {!string} */ + this.basePath_ = $injector.has('{{classname}}BasePath') ? + /** @type {!string} */ ($injector.get('{{classname}}BasePath')) : + '{{basePath}}'; + + /** @private {!Object} */ + this.defaultHeaders_ = $injector.has('{{classname}}DefaultHeaders') ? + /** @type {!Object} */ ( + $injector.get('{{classname}}DefaultHeaders')) : + {}; + + /** @private {!angular.$http} */ + this.http_ = $http; +} +{{package}}.{{classname}}.$inject = ['$http', '$injector']; +{{#operation}} + +/** + * {{summary}} + * {{notes}}{{#allParams}} + * @param {!{{{dataType}}}{{^required}}={{/required}}} {{^required}}opt_{{/required}}{{paramName}} {{description}}{{/allParams}} + * @param {!angular.$http.Config=} opt_extraHttpRequestParams Extra HTTP parameters to send. + * @return {!angular.$q.Promise{{#returnType}}{{/returnType}}} + */ +{{package}}.{{classname}}.prototype.{{nickname}} = function({{#allParams}}{{^required}}opt_{{/required}}{{paramName}}, {{/allParams}}opt_extraHttpRequestParams) { + /** @const {!string} */ + var path = this.basePath_ + '{{path}}'{{#pathParams}} + .replace('{' + '{{baseName}}' + '}', String({{^required}}opt_{{/required}}{{paramName}})){{/pathParams}}; +{{#required}} + + // verify required parameter '{{paramName}}' is set + if (!{{paramName}}) { + throw new Error('Missing required parameter {{paramName}} when calling {{nickname}}'); + } +{{/required}} + + /** @type {!Object} */ + var queryParameters = {}; +{{#queryParams}} + if ({{^required}}opt_{{/required}}{{paramName}} !== undefined) { + queryParameters['{{baseName}}'] = String({{^required}}opt_{{/required}}{{paramName}}); + } +{{/queryParams}} + + /** @type {!Object} */ + var headerParams = angular.copy(this.defaultHeaders_); +{{#headerParams}} + if ({{^required}}opt_{{/required}}{{paramName}} !== undefined) { + headerParams['{{baseName}}'] = {{^required}}opt_{{/required}}{{paramName}}; + } +{{/headerParams}} +{{#hasFormParams}} + + /** @type {!FormData} */ + var formParams = new FormData(); +{{/hasFormParams}} +{{#formParams}} + if ({{^required}}opt_{{/required}}{{paramName}} !== undefined) { + var {{paramName}}_ = /** @type {?} */ ({{^required}}opt_{{/required}}{{paramName}}); + if ({{paramName}}_ instanceof Blob) { + formParams.append('{{baseName}}', {{paramName}}_); + } else if (typeof {{paramName}}_ === 'string') { + formParams.append('{{baseName}}', {{paramName}}_); + } else { + throw new Error('Forms parameter {{^required}}opt_{{/required}}{{paramName}} is required to be a string or a Blob (https://developer.mozilla.org/en-US/docs/Web/API/Blob/Blob)'); + } + } +{{/formParams}} +{{#allParams}} +{{/allParams}} + + /** @type {!angular.$http.Config} */ + var httpRequestConfig = /** @type {!angular.$http.Config} */ ({ + url: path, + json: {{#hasFormParams}}false{{/hasFormParams}}{{^hasFormParams}}true{{/hasFormParams}},{{#bodyParam}} + data: {{paramName}},{{/bodyParam}}{{#hasFormParams}} + data: formParams,{{/hasFormParams}} + params: queryParameters, + headers: headerParams + }); + + if (opt_extraHttpRequestParams) { + // If an opt_extraHttpRequestParams object is passed in, override values + // set the generated config with the passed in values. + httpRequestConfig = angular.merge(httpRequestConfig, opt_extraHttpRequestParams); + } + + // This whole block is to work around a limitation in closure compiler. It + // would be better to call the $http service directly as a function, but that + // isn't permitted since it has methods attached to it. Manually confirmed to + // compile down to just a single method even with only SIMPLE optimization on. + // https://github.com/google/closure-compiler/blob/90769b826df65eabfb0211517b0d6d85c0c1c60b/contrib/externs/angular-1.4.js#L1393 + switch ('{{httpMethod}}') { + case 'GET': + return this.http_.get(path, httpRequestConfig); + case 'HEAD': + return this.http_.head(path, httpRequestConfig); + case 'POST': + return this.http_.post(path, {}, httpRequestConfig); + case 'PUT': + return this.http_.put(path, {}, httpRequestConfig); + case 'DELETE': + return this.http_.delete(path, httpRequestConfig); + case 'PATCH': + return this.http_.patch(path, {}, httpRequestConfig); + } +} +{{/operation}} +{{/operations}} diff --git a/modules/swagger-codegen/src/main/resources/Javascript-Closure-Angular/model.mustache b/modules/swagger-codegen/src/main/resources/Javascript-Closure-Angular/model.mustache new file mode 100644 index 000000000000..81ec7591c877 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/Javascript-Closure-Angular/model.mustache @@ -0,0 +1,40 @@ +{{#models}} +{{#model}} +goog.provide('{{package}}.{{name}}'); +{{/model}} +{{/models}} + +{{#models}} +{{#model}} +/** +{{#description}} + * {{{description}}} +{{/description}} + * @record + */ +{{package}}.{{classname}} = function() {} +{{#vars}} + +/** +{{#description}} + * {{{description}}} +{{/description}} +{{! Explicitly force types to be non-nullable using !. This is redundant but valid }} + * @type {!{{{datatype}}}} + * @export + */ +{{package}}.{{classname}}.prototype.{{name}}; +{{/vars}} + +{{#hasEnums}} +{{#vars}} +{{#isEnum}} +/** @enum {string} */ +{{package}}.{{classname}}.{{datatypeWithEnum}} = { {{#allowableValues}}{{#values}} + {{.}}: '{{.}}',{{/values}}{{/allowableValues}} +} +{{/isEnum}} +{{/vars}} +{{/hasEnums}} +{{/model}} +{{/models}} diff --git a/modules/swagger-codegen/src/main/resources/META-INF/services/io.swagger.codegen.CodegenConfig b/modules/swagger-codegen/src/main/resources/META-INF/services/io.swagger.codegen.CodegenConfig index 18015a9328bd..d023052aa555 100644 --- a/modules/swagger-codegen/src/main/resources/META-INF/services/io.swagger.codegen.CodegenConfig +++ b/modules/swagger-codegen/src/main/resources/META-INF/services/io.swagger.codegen.CodegenConfig @@ -10,6 +10,7 @@ io.swagger.codegen.languages.JavaJerseyServerCodegen io.swagger.codegen.languages.JavaCXFServerCodegen io.swagger.codegen.languages.JavaInflectorServerCodegen io.swagger.codegen.languages.JavascriptClientCodegen +io.swagger.codegen.languages.JavascriptClosureAngularClientCodegen io.swagger.codegen.languages.JMeterCodegen io.swagger.codegen.languages.NodeJSServerCodegen io.swagger.codegen.languages.ObjcClientCodegen diff --git a/modules/swagger-codegen/src/test/java/io/swagger/codegen/options/JavascriptClosureAnularClientOptionsProvider.java b/modules/swagger-codegen/src/test/java/io/swagger/codegen/options/JavascriptClosureAnularClientOptionsProvider.java new file mode 100644 index 000000000000..3bc5a3df22df --- /dev/null +++ b/modules/swagger-codegen/src/test/java/io/swagger/codegen/options/JavascriptClosureAnularClientOptionsProvider.java @@ -0,0 +1,30 @@ +package io.swagger.codegen.options; + +import io.swagger.codegen.CodegenConstants; + +import com.google.common.collect.ImmutableMap; + +import java.util.Map; + +public class JavascriptClosureAnularClientOptionsProvider implements OptionsProvider { + public static final String SORT_PARAMS_VALUE = "false"; + public static final String ENSURE_UNIQUE_PARAMS_VALUE = "true"; + + @Override + public String getLanguage() { + return "javascript-closure-angular"; + } + + @Override + public Map createOptions() { + ImmutableMap.Builder builder = new ImmutableMap.Builder(); + return builder.put(CodegenConstants.SORT_PARAMS_BY_REQUIRED_FLAG, SORT_PARAMS_VALUE) + .put(CodegenConstants.ENSURE_UNIQUE_PARAMS, ENSURE_UNIQUE_PARAMS_VALUE) + .build(); + } + + @Override + public boolean isServer() { + return false; + } +} From 8ea7cbc79d7b081b2c4fdc6122a4a361d24b5264 Mon Sep 17 00:00:00 2001 From: Andrew Z Allen Date: Wed, 27 Jan 2016 21:52:20 -0700 Subject: [PATCH 2/6] Add bash script to run --- bin/javascript-closure-angular.sh | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100755 bin/javascript-closure-angular.sh diff --git a/bin/javascript-closure-angular.sh b/bin/javascript-closure-angular.sh new file mode 100755 index 000000000000..efd830034dc4 --- /dev/null +++ b/bin/javascript-closure-angular.sh @@ -0,0 +1,31 @@ +#!/bin/sh + +SCRIPT="$0" + +while [ -h "$SCRIPT" ] ; do + ls=`ls -ld "$SCRIPT"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + SCRIPT="$link" + else + SCRIPT=`dirname "$SCRIPT"`/"$link" + fi +done + +if [ ! -d "${APP_DIR}" ]; then + APP_DIR=`dirname "$SCRIPT"`/.. + APP_DIR=`cd "${APP_DIR}"; pwd` +fi + +executable="./modules/swagger-codegen-cli/target/swagger-codegen-cli.jar" + +if [ ! -f "$executable" ] +then + mvn clean package +fi + +# if you've executed sbt assembly previously it will use that instead. +export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties" +ags="$@ generate -i modules/swagger-codegen/src/test/resources/2_0/petstore.json -l javascript-closure-angular -o samples/client/petstore/javascript-closure-angular" + +java $JAVA_OPTS -jar $executable $ags From af6926bd6f092b3d34b1e7207feb6c15e3a652a2 Mon Sep 17 00:00:00 2001 From: Andrew Z Allen Date: Wed, 27 Jan 2016 23:29:51 -0700 Subject: [PATCH 3/6] Add sample output from Javascript Closure Angular --- .../API/Client/Category.js | 19 + .../API/Client/Order.js | 50 ++ .../API/Client/Pet.js | 50 ++ .../API/Client/PetApi.js | 632 ++++++++++++++++++ .../API/Client/StoreApi.js | 251 +++++++ .../API/Client/Tag.js | 19 + .../API/Client/User.js | 56 ++ .../API/Client/UserApi.js | 472 +++++++++++++ 8 files changed, 1549 insertions(+) create mode 100644 samples/client/petstore/javascript-closure-angular/API/Client/Category.js create mode 100644 samples/client/petstore/javascript-closure-angular/API/Client/Order.js create mode 100644 samples/client/petstore/javascript-closure-angular/API/Client/Pet.js create mode 100644 samples/client/petstore/javascript-closure-angular/API/Client/PetApi.js create mode 100644 samples/client/petstore/javascript-closure-angular/API/Client/StoreApi.js create mode 100644 samples/client/petstore/javascript-closure-angular/API/Client/Tag.js create mode 100644 samples/client/petstore/javascript-closure-angular/API/Client/User.js create mode 100644 samples/client/petstore/javascript-closure-angular/API/Client/UserApi.js diff --git a/samples/client/petstore/javascript-closure-angular/API/Client/Category.js b/samples/client/petstore/javascript-closure-angular/API/Client/Category.js new file mode 100644 index 000000000000..fe9d23c34ffe --- /dev/null +++ b/samples/client/petstore/javascript-closure-angular/API/Client/Category.js @@ -0,0 +1,19 @@ +goog.provide('API.Client.Category'); + +/** + * @record + */ +API.Client.Category = function() {} + +/** + * @type {!number} + * @export + */ +API.Client.Category.prototype.id; + +/** + * @type {!string} + * @export + */ +API.Client.Category.prototype.name; + diff --git a/samples/client/petstore/javascript-closure-angular/API/Client/Order.js b/samples/client/petstore/javascript-closure-angular/API/Client/Order.js new file mode 100644 index 000000000000..c4ec23a066a7 --- /dev/null +++ b/samples/client/petstore/javascript-closure-angular/API/Client/Order.js @@ -0,0 +1,50 @@ +goog.provide('API.Client.Order'); + +/** + * @record + */ +API.Client.Order = function() {} + +/** + * @type {!number} + * @export + */ +API.Client.Order.prototype.id; + +/** + * @type {!number} + * @export + */ +API.Client.Order.prototype.petId; + +/** + * @type {!number} + * @export + */ +API.Client.Order.prototype.quantity; + +/** + * @type {!Date} + * @export + */ +API.Client.Order.prototype.shipDate; + +/** + * Order Status + * @type {!string} + * @export + */ +API.Client.Order.prototype.status; + +/** + * @type {!boolean} + * @export + */ +API.Client.Order.prototype.complete; + +/** @enum {string} */ +API.Client.Order.StatusEnum = { + placed: 'placed', + approved: 'approved', + delivered: 'delivered', +} diff --git a/samples/client/petstore/javascript-closure-angular/API/Client/Pet.js b/samples/client/petstore/javascript-closure-angular/API/Client/Pet.js new file mode 100644 index 000000000000..2c734557b647 --- /dev/null +++ b/samples/client/petstore/javascript-closure-angular/API/Client/Pet.js @@ -0,0 +1,50 @@ +goog.provide('API.Client.Pet'); + +/** + * @record + */ +API.Client.Pet = function() {} + +/** + * @type {!number} + * @export + */ +API.Client.Pet.prototype.id; + +/** + * @type {!API.Client.Category} + * @export + */ +API.Client.Pet.prototype.category; + +/** + * @type {!string} + * @export + */ +API.Client.Pet.prototype.name; + +/** + * @type {!Array} + * @export + */ +API.Client.Pet.prototype.photoUrls; + +/** + * @type {!Array} + * @export + */ +API.Client.Pet.prototype.tags; + +/** + * pet status in the store + * @type {!string} + * @export + */ +API.Client.Pet.prototype.status; + +/** @enum {string} */ +API.Client.Pet.StatusEnum = { + available: 'available', + pending: 'pending', + sold: 'sold', +} diff --git a/samples/client/petstore/javascript-closure-angular/API/Client/PetApi.js b/samples/client/petstore/javascript-closure-angular/API/Client/PetApi.js new file mode 100644 index 000000000000..395a3d4041d3 --- /dev/null +++ b/samples/client/petstore/javascript-closure-angular/API/Client/PetApi.js @@ -0,0 +1,632 @@ +/** + * @fileoverview AUTOMATICALLY GENERATED service for API.Client.PetApi. + * Do not edit this file by hand or your changes will be lost next time it is + * generated. + * + * This is a sample server Petstore server. You can find out more about Swagger at <a href=\"http://swagger.io\">http://swagger.io</a> or on irc.freenode.net, #swagger. For this sample, you can use the api key \"special-key\" to test the authorization filters + * Version: 1.0.0 + * Generated at: 2016-01-27T23:29:24.021-07:00 + * Generated by: class io.swagger.codegen.languages.JavascriptClosureAngularClientCodegen + */ +/** + * @license Apache 2.0 + * http://www.apache.org/licenses/LICENSE-2.0.html + */ + +goog.provide('API.Client.PetApi'); + +goog.require('API.Client.Pet'); +goog.require('API.Client.binary'); + +/** + * @constructor + * @param {!angular.$http} $http + * @param {!angular.$injector} $injector + * @struct + */ +API.Client.PetApi = function($http, $injector) { + /** @private {!string} */ + this.basePath_ = $injector.has('PetApiBasePath') ? + /** @type {!string} */ ($injector.get('PetApiBasePath')) : + 'http://petstore.swagger.io/v2'; + + /** @private {!Object} */ + this.defaultHeaders_ = $injector.has('PetApiDefaultHeaders') ? + /** @type {!Object} */ ( + $injector.get('PetApiDefaultHeaders')) : + {}; + + /** @private {!angular.$http} */ + this.http_ = $http; +} +API.Client.PetApi.$inject = ['$http', '$injector']; + +/** + * Update an existing pet + * + * @param {!Pet=} opt_body Pet object that needs to be added to the store + * @param {!angular.$http.Config=} opt_extraHttpRequestParams Extra HTTP parameters to send. + * @return {!angular.$q.Promise} + */ +API.Client.PetApi.prototype.updatePet = function(opt_body, opt_extraHttpRequestParams) { + /** @const {!string} */ + var path = this.basePath_ + '/pet'; + + /** @type {!Object} */ + var queryParameters = {}; + + /** @type {!Object} */ + var headerParams = angular.copy(this.defaultHeaders_); + + /** @type {!angular.$http.Config} */ + var httpRequestConfig = /** @type {!angular.$http.Config} */ ({ + url: path, + json: true, + data: body, + params: queryParameters, + headers: headerParams + }); + + if (opt_extraHttpRequestParams) { + // If an opt_extraHttpRequestParams object is passed in, override values + // set the generated config with the passed in values. + httpRequestConfig = angular.merge(httpRequestConfig, opt_extraHttpRequestParams); + } + + // This whole block is to work around a limitation in closure compiler. It + // would be better to call the $http service directly as a function, but that + // isn't permitted since it has methods attached to it. Manually confirmed to + // compile down to just a single method even with only SIMPLE optimization on. + // https://github.com/google/closure-compiler/blob/90769b826df65eabfb0211517b0d6d85c0c1c60b/contrib/externs/angular-1.4.js#L1393 + switch ('PUT') { + case 'GET': + return this.http_.get(path, httpRequestConfig); + case 'HEAD': + return this.http_.head(path, httpRequestConfig); + case 'POST': + return this.http_.post(path, {}, httpRequestConfig); + case 'PUT': + return this.http_.put(path, {}, httpRequestConfig); + case 'DELETE': + return this.http_.delete(path, httpRequestConfig); + case 'PATCH': + return this.http_.patch(path, {}, httpRequestConfig); + } +} + +/** + * Add a new pet to the store + * + * @param {!Pet=} opt_body Pet object that needs to be added to the store + * @param {!angular.$http.Config=} opt_extraHttpRequestParams Extra HTTP parameters to send. + * @return {!angular.$q.Promise} + */ +API.Client.PetApi.prototype.addPet = function(opt_body, opt_extraHttpRequestParams) { + /** @const {!string} */ + var path = this.basePath_ + '/pet'; + + /** @type {!Object} */ + var queryParameters = {}; + + /** @type {!Object} */ + var headerParams = angular.copy(this.defaultHeaders_); + + /** @type {!angular.$http.Config} */ + var httpRequestConfig = /** @type {!angular.$http.Config} */ ({ + url: path, + json: true, + data: body, + params: queryParameters, + headers: headerParams + }); + + if (opt_extraHttpRequestParams) { + // If an opt_extraHttpRequestParams object is passed in, override values + // set the generated config with the passed in values. + httpRequestConfig = angular.merge(httpRequestConfig, opt_extraHttpRequestParams); + } + + // This whole block is to work around a limitation in closure compiler. It + // would be better to call the $http service directly as a function, but that + // isn't permitted since it has methods attached to it. Manually confirmed to + // compile down to just a single method even with only SIMPLE optimization on. + // https://github.com/google/closure-compiler/blob/90769b826df65eabfb0211517b0d6d85c0c1c60b/contrib/externs/angular-1.4.js#L1393 + switch ('POST') { + case 'GET': + return this.http_.get(path, httpRequestConfig); + case 'HEAD': + return this.http_.head(path, httpRequestConfig); + case 'POST': + return this.http_.post(path, {}, httpRequestConfig); + case 'PUT': + return this.http_.put(path, {}, httpRequestConfig); + case 'DELETE': + return this.http_.delete(path, httpRequestConfig); + case 'PATCH': + return this.http_.patch(path, {}, httpRequestConfig); + } +} + +/** + * Finds Pets by status + * Multiple status values can be provided with comma seperated strings + * @param {!Array=} opt_status Status values that need to be considered for filter + * @param {!angular.$http.Config=} opt_extraHttpRequestParams Extra HTTP parameters to send. + * @return {!angular.$q.Promise>} + */ +API.Client.PetApi.prototype.findPetsByStatus = function(opt_status, opt_extraHttpRequestParams) { + /** @const {!string} */ + var path = this.basePath_ + '/pet/findByStatus'; + + /** @type {!Object} */ + var queryParameters = {}; + if (opt_status !== undefined) { + queryParameters['status'] = String(opt_status); + } + + /** @type {!Object} */ + var headerParams = angular.copy(this.defaultHeaders_); + + /** @type {!angular.$http.Config} */ + var httpRequestConfig = /** @type {!angular.$http.Config} */ ({ + url: path, + json: true, + params: queryParameters, + headers: headerParams + }); + + if (opt_extraHttpRequestParams) { + // If an opt_extraHttpRequestParams object is passed in, override values + // set the generated config with the passed in values. + httpRequestConfig = angular.merge(httpRequestConfig, opt_extraHttpRequestParams); + } + + // This whole block is to work around a limitation in closure compiler. It + // would be better to call the $http service directly as a function, but that + // isn't permitted since it has methods attached to it. Manually confirmed to + // compile down to just a single method even with only SIMPLE optimization on. + // https://github.com/google/closure-compiler/blob/90769b826df65eabfb0211517b0d6d85c0c1c60b/contrib/externs/angular-1.4.js#L1393 + switch ('GET') { + case 'GET': + return this.http_.get(path, httpRequestConfig); + case 'HEAD': + return this.http_.head(path, httpRequestConfig); + case 'POST': + return this.http_.post(path, {}, httpRequestConfig); + case 'PUT': + return this.http_.put(path, {}, httpRequestConfig); + case 'DELETE': + return this.http_.delete(path, httpRequestConfig); + case 'PATCH': + return this.http_.patch(path, {}, httpRequestConfig); + } +} + +/** + * Finds Pets by tags + * Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing. + * @param {!Array=} opt_tags Tags to filter by + * @param {!angular.$http.Config=} opt_extraHttpRequestParams Extra HTTP parameters to send. + * @return {!angular.$q.Promise>} + */ +API.Client.PetApi.prototype.findPetsByTags = function(opt_tags, opt_extraHttpRequestParams) { + /** @const {!string} */ + var path = this.basePath_ + '/pet/findByTags'; + + /** @type {!Object} */ + var queryParameters = {}; + if (opt_tags !== undefined) { + queryParameters['tags'] = String(opt_tags); + } + + /** @type {!Object} */ + var headerParams = angular.copy(this.defaultHeaders_); + + /** @type {!angular.$http.Config} */ + var httpRequestConfig = /** @type {!angular.$http.Config} */ ({ + url: path, + json: true, + params: queryParameters, + headers: headerParams + }); + + if (opt_extraHttpRequestParams) { + // If an opt_extraHttpRequestParams object is passed in, override values + // set the generated config with the passed in values. + httpRequestConfig = angular.merge(httpRequestConfig, opt_extraHttpRequestParams); + } + + // This whole block is to work around a limitation in closure compiler. It + // would be better to call the $http service directly as a function, but that + // isn't permitted since it has methods attached to it. Manually confirmed to + // compile down to just a single method even with only SIMPLE optimization on. + // https://github.com/google/closure-compiler/blob/90769b826df65eabfb0211517b0d6d85c0c1c60b/contrib/externs/angular-1.4.js#L1393 + switch ('GET') { + case 'GET': + return this.http_.get(path, httpRequestConfig); + case 'HEAD': + return this.http_.head(path, httpRequestConfig); + case 'POST': + return this.http_.post(path, {}, httpRequestConfig); + case 'PUT': + return this.http_.put(path, {}, httpRequestConfig); + case 'DELETE': + return this.http_.delete(path, httpRequestConfig); + case 'PATCH': + return this.http_.patch(path, {}, httpRequestConfig); + } +} + +/** + * Find pet by ID + * Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions + * @param {!number} petId ID of pet that needs to be fetched + * @param {!angular.$http.Config=} opt_extraHttpRequestParams Extra HTTP parameters to send. + * @return {!angular.$q.Promise} + */ +API.Client.PetApi.prototype.getPetById = function(petId, opt_extraHttpRequestParams) { + /** @const {!string} */ + var path = this.basePath_ + '/pet/{petId}' + .replace('{' + 'petId' + '}', String(petId)); + + /** @type {!Object} */ + var queryParameters = {}; + + /** @type {!Object} */ + var headerParams = angular.copy(this.defaultHeaders_); + + /** @type {!angular.$http.Config} */ + var httpRequestConfig = /** @type {!angular.$http.Config} */ ({ + url: path, + json: true, + params: queryParameters, + headers: headerParams + }); + + if (opt_extraHttpRequestParams) { + // If an opt_extraHttpRequestParams object is passed in, override values + // set the generated config with the passed in values. + httpRequestConfig = angular.merge(httpRequestConfig, opt_extraHttpRequestParams); + } + + // This whole block is to work around a limitation in closure compiler. It + // would be better to call the $http service directly as a function, but that + // isn't permitted since it has methods attached to it. Manually confirmed to + // compile down to just a single method even with only SIMPLE optimization on. + // https://github.com/google/closure-compiler/blob/90769b826df65eabfb0211517b0d6d85c0c1c60b/contrib/externs/angular-1.4.js#L1393 + switch ('GET') { + case 'GET': + return this.http_.get(path, httpRequestConfig); + case 'HEAD': + return this.http_.head(path, httpRequestConfig); + case 'POST': + return this.http_.post(path, {}, httpRequestConfig); + case 'PUT': + return this.http_.put(path, {}, httpRequestConfig); + case 'DELETE': + return this.http_.delete(path, httpRequestConfig); + case 'PATCH': + return this.http_.patch(path, {}, httpRequestConfig); + } +} + +/** + * Updates a pet in the store with form data + * + * @param {!string} petId ID of pet that needs to be updated + * @param {!string=} opt_name Updated name of the pet + * @param {!string=} opt_status Updated status of the pet + * @param {!angular.$http.Config=} opt_extraHttpRequestParams Extra HTTP parameters to send. + * @return {!angular.$q.Promise} + */ +API.Client.PetApi.prototype.updatePetWithForm = function(petId, opt_name, opt_status, opt_extraHttpRequestParams) { + /** @const {!string} */ + var path = this.basePath_ + '/pet/{petId}' + .replace('{' + 'petId' + '}', String(petId)); + + /** @type {!Object} */ + var queryParameters = {}; + + /** @type {!Object} */ + var headerParams = angular.copy(this.defaultHeaders_); + + /** @type {!FormData} */ + var formParams = new FormData(); + if (opt_name !== undefined) { + var name_ = /** @type {?} */ (opt_name); + if (name_ instanceof Blob) { + formParams.append('name', name_); + } else if (typeof name_ === 'string') { + formParams.append('name', name_); + } else { + throw new Error('Forms parameter opt_name is required to be a string or a Blob (https://developer.mozilla.org/en-US/docs/Web/API/Blob/Blob)'); + } + } + if (opt_status !== undefined) { + var status_ = /** @type {?} */ (opt_status); + if (status_ instanceof Blob) { + formParams.append('status', status_); + } else if (typeof status_ === 'string') { + formParams.append('status', status_); + } else { + throw new Error('Forms parameter opt_status is required to be a string or a Blob (https://developer.mozilla.org/en-US/docs/Web/API/Blob/Blob)'); + } + } + + /** @type {!angular.$http.Config} */ + var httpRequestConfig = /** @type {!angular.$http.Config} */ ({ + url: path, + json: false, + data: formParams, + params: queryParameters, + headers: headerParams + }); + + if (opt_extraHttpRequestParams) { + // If an opt_extraHttpRequestParams object is passed in, override values + // set the generated config with the passed in values. + httpRequestConfig = angular.merge(httpRequestConfig, opt_extraHttpRequestParams); + } + + // This whole block is to work around a limitation in closure compiler. It + // would be better to call the $http service directly as a function, but that + // isn't permitted since it has methods attached to it. Manually confirmed to + // compile down to just a single method even with only SIMPLE optimization on. + // https://github.com/google/closure-compiler/blob/90769b826df65eabfb0211517b0d6d85c0c1c60b/contrib/externs/angular-1.4.js#L1393 + switch ('POST') { + case 'GET': + return this.http_.get(path, httpRequestConfig); + case 'HEAD': + return this.http_.head(path, httpRequestConfig); + case 'POST': + return this.http_.post(path, {}, httpRequestConfig); + case 'PUT': + return this.http_.put(path, {}, httpRequestConfig); + case 'DELETE': + return this.http_.delete(path, httpRequestConfig); + case 'PATCH': + return this.http_.patch(path, {}, httpRequestConfig); + } +} + +/** + * Deletes a pet + * + * @param {!number} petId Pet id to delete + * @param {!string=} opt_apiKey + * @param {!angular.$http.Config=} opt_extraHttpRequestParams Extra HTTP parameters to send. + * @return {!angular.$q.Promise} + */ +API.Client.PetApi.prototype.deletePet = function(petId, opt_apiKey, opt_extraHttpRequestParams) { + /** @const {!string} */ + var path = this.basePath_ + '/pet/{petId}' + .replace('{' + 'petId' + '}', String(petId)); + + /** @type {!Object} */ + var queryParameters = {}; + + /** @type {!Object} */ + var headerParams = angular.copy(this.defaultHeaders_); + if (opt_apiKey !== undefined) { + headerParams['api_key'] = opt_apiKey; + } + + /** @type {!angular.$http.Config} */ + var httpRequestConfig = /** @type {!angular.$http.Config} */ ({ + url: path, + json: true, + params: queryParameters, + headers: headerParams + }); + + if (opt_extraHttpRequestParams) { + // If an opt_extraHttpRequestParams object is passed in, override values + // set the generated config with the passed in values. + httpRequestConfig = angular.merge(httpRequestConfig, opt_extraHttpRequestParams); + } + + // This whole block is to work around a limitation in closure compiler. It + // would be better to call the $http service directly as a function, but that + // isn't permitted since it has methods attached to it. Manually confirmed to + // compile down to just a single method even with only SIMPLE optimization on. + // https://github.com/google/closure-compiler/blob/90769b826df65eabfb0211517b0d6d85c0c1c60b/contrib/externs/angular-1.4.js#L1393 + switch ('DELETE') { + case 'GET': + return this.http_.get(path, httpRequestConfig); + case 'HEAD': + return this.http_.head(path, httpRequestConfig); + case 'POST': + return this.http_.post(path, {}, httpRequestConfig); + case 'PUT': + return this.http_.put(path, {}, httpRequestConfig); + case 'DELETE': + return this.http_.delete(path, httpRequestConfig); + case 'PATCH': + return this.http_.patch(path, {}, httpRequestConfig); + } +} + +/** + * uploads an image + * + * @param {!number} petId ID of pet to update + * @param {!string=} opt_additionalMetadata Additional data to pass to server + * @param {!Object=} opt_file file to upload + * @param {!angular.$http.Config=} opt_extraHttpRequestParams Extra HTTP parameters to send. + * @return {!angular.$q.Promise} + */ +API.Client.PetApi.prototype.uploadFile = function(petId, opt_additionalMetadata, opt_file, opt_extraHttpRequestParams) { + /** @const {!string} */ + var path = this.basePath_ + '/pet/{petId}/uploadImage' + .replace('{' + 'petId' + '}', String(petId)); + + /** @type {!Object} */ + var queryParameters = {}; + + /** @type {!Object} */ + var headerParams = angular.copy(this.defaultHeaders_); + + /** @type {!FormData} */ + var formParams = new FormData(); + if (opt_additionalMetadata !== undefined) { + var additionalMetadata_ = /** @type {?} */ (opt_additionalMetadata); + if (additionalMetadata_ instanceof Blob) { + formParams.append('additionalMetadata', additionalMetadata_); + } else if (typeof additionalMetadata_ === 'string') { + formParams.append('additionalMetadata', additionalMetadata_); + } else { + throw new Error('Forms parameter opt_additionalMetadata is required to be a string or a Blob (https://developer.mozilla.org/en-US/docs/Web/API/Blob/Blob)'); + } + } + if (opt_file !== undefined) { + var file_ = /** @type {?} */ (opt_file); + if (file_ instanceof Blob) { + formParams.append('file', file_); + } else if (typeof file_ === 'string') { + formParams.append('file', file_); + } else { + throw new Error('Forms parameter opt_file is required to be a string or a Blob (https://developer.mozilla.org/en-US/docs/Web/API/Blob/Blob)'); + } + } + + /** @type {!angular.$http.Config} */ + var httpRequestConfig = /** @type {!angular.$http.Config} */ ({ + url: path, + json: false, + data: formParams, + params: queryParameters, + headers: headerParams + }); + + if (opt_extraHttpRequestParams) { + // If an opt_extraHttpRequestParams object is passed in, override values + // set the generated config with the passed in values. + httpRequestConfig = angular.merge(httpRequestConfig, opt_extraHttpRequestParams); + } + + // This whole block is to work around a limitation in closure compiler. It + // would be better to call the $http service directly as a function, but that + // isn't permitted since it has methods attached to it. Manually confirmed to + // compile down to just a single method even with only SIMPLE optimization on. + // https://github.com/google/closure-compiler/blob/90769b826df65eabfb0211517b0d6d85c0c1c60b/contrib/externs/angular-1.4.js#L1393 + switch ('POST') { + case 'GET': + return this.http_.get(path, httpRequestConfig); + case 'HEAD': + return this.http_.head(path, httpRequestConfig); + case 'POST': + return this.http_.post(path, {}, httpRequestConfig); + case 'PUT': + return this.http_.put(path, {}, httpRequestConfig); + case 'DELETE': + return this.http_.delete(path, httpRequestConfig); + case 'PATCH': + return this.http_.patch(path, {}, httpRequestConfig); + } +} + +/** + * 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 {!number} petId ID of pet that needs to be fetched + * @param {!angular.$http.Config=} opt_extraHttpRequestParams Extra HTTP parameters to send. + * @return {!angular.$q.Promise} + */ +API.Client.PetApi.prototype.getPetByIdWithByteArray = function(petId, opt_extraHttpRequestParams) { + /** @const {!string} */ + var path = this.basePath_ + '/pet/{petId}?testing_byte_array=true' + .replace('{' + 'petId' + '}', String(petId)); + + /** @type {!Object} */ + var queryParameters = {}; + + /** @type {!Object} */ + var headerParams = angular.copy(this.defaultHeaders_); + + /** @type {!angular.$http.Config} */ + var httpRequestConfig = /** @type {!angular.$http.Config} */ ({ + url: path, + json: true, + params: queryParameters, + headers: headerParams + }); + + if (opt_extraHttpRequestParams) { + // If an opt_extraHttpRequestParams object is passed in, override values + // set the generated config with the passed in values. + httpRequestConfig = angular.merge(httpRequestConfig, opt_extraHttpRequestParams); + } + + // This whole block is to work around a limitation in closure compiler. It + // would be better to call the $http service directly as a function, but that + // isn't permitted since it has methods attached to it. Manually confirmed to + // compile down to just a single method even with only SIMPLE optimization on. + // https://github.com/google/closure-compiler/blob/90769b826df65eabfb0211517b0d6d85c0c1c60b/contrib/externs/angular-1.4.js#L1393 + switch ('GET') { + case 'GET': + return this.http_.get(path, httpRequestConfig); + case 'HEAD': + return this.http_.head(path, httpRequestConfig); + case 'POST': + return this.http_.post(path, {}, httpRequestConfig); + case 'PUT': + return this.http_.put(path, {}, httpRequestConfig); + case 'DELETE': + return this.http_.delete(path, httpRequestConfig); + case 'PATCH': + return this.http_.patch(path, {}, httpRequestConfig); + } +} + +/** + * Fake endpoint to test byte array in body parameter for adding a new pet to the store + * + * @param {!API.Client.binary=} opt_body Pet object in the form of byte array + * @param {!angular.$http.Config=} opt_extraHttpRequestParams Extra HTTP parameters to send. + * @return {!angular.$q.Promise} + */ +API.Client.PetApi.prototype.addPetUsingByteArray = function(opt_body, opt_extraHttpRequestParams) { + /** @const {!string} */ + var path = this.basePath_ + '/pet?testing_byte_array=true'; + + /** @type {!Object} */ + var queryParameters = {}; + + /** @type {!Object} */ + var headerParams = angular.copy(this.defaultHeaders_); + + /** @type {!angular.$http.Config} */ + var httpRequestConfig = /** @type {!angular.$http.Config} */ ({ + url: path, + json: true, + data: body, + params: queryParameters, + headers: headerParams + }); + + if (opt_extraHttpRequestParams) { + // If an opt_extraHttpRequestParams object is passed in, override values + // set the generated config with the passed in values. + httpRequestConfig = angular.merge(httpRequestConfig, opt_extraHttpRequestParams); + } + + // This whole block is to work around a limitation in closure compiler. It + // would be better to call the $http service directly as a function, but that + // isn't permitted since it has methods attached to it. Manually confirmed to + // compile down to just a single method even with only SIMPLE optimization on. + // https://github.com/google/closure-compiler/blob/90769b826df65eabfb0211517b0d6d85c0c1c60b/contrib/externs/angular-1.4.js#L1393 + switch ('POST') { + case 'GET': + return this.http_.get(path, httpRequestConfig); + case 'HEAD': + return this.http_.head(path, httpRequestConfig); + case 'POST': + return this.http_.post(path, {}, httpRequestConfig); + case 'PUT': + return this.http_.put(path, {}, httpRequestConfig); + case 'DELETE': + return this.http_.delete(path, httpRequestConfig); + case 'PATCH': + return this.http_.patch(path, {}, httpRequestConfig); + } +} diff --git a/samples/client/petstore/javascript-closure-angular/API/Client/StoreApi.js b/samples/client/petstore/javascript-closure-angular/API/Client/StoreApi.js new file mode 100644 index 000000000000..db9ec948a70b --- /dev/null +++ b/samples/client/petstore/javascript-closure-angular/API/Client/StoreApi.js @@ -0,0 +1,251 @@ +/** + * @fileoverview AUTOMATICALLY GENERATED service for API.Client.StoreApi. + * Do not edit this file by hand or your changes will be lost next time it is + * generated. + * + * This is a sample server Petstore server. You can find out more about Swagger at <a href=\"http://swagger.io\">http://swagger.io</a> or on irc.freenode.net, #swagger. For this sample, you can use the api key \"special-key\" to test the authorization filters + * Version: 1.0.0 + * Generated at: 2016-01-27T23:29:24.021-07:00 + * Generated by: class io.swagger.codegen.languages.JavascriptClosureAngularClientCodegen + */ +/** + * @license Apache 2.0 + * http://www.apache.org/licenses/LICENSE-2.0.html + */ + +goog.provide('API.Client.StoreApi'); + +goog.require('API.Client.Order'); + +/** + * @constructor + * @param {!angular.$http} $http + * @param {!angular.$injector} $injector + * @struct + */ +API.Client.StoreApi = function($http, $injector) { + /** @private {!string} */ + this.basePath_ = $injector.has('StoreApiBasePath') ? + /** @type {!string} */ ($injector.get('StoreApiBasePath')) : + 'http://petstore.swagger.io/v2'; + + /** @private {!Object} */ + this.defaultHeaders_ = $injector.has('StoreApiDefaultHeaders') ? + /** @type {!Object} */ ( + $injector.get('StoreApiDefaultHeaders')) : + {}; + + /** @private {!angular.$http} */ + this.http_ = $http; +} +API.Client.StoreApi.$inject = ['$http', '$injector']; + +/** + * Returns pet inventories by status + * Returns a map of status codes to quantities + * @param {!angular.$http.Config=} opt_extraHttpRequestParams Extra HTTP parameters to send. + * @return {!angular.$q.Promise>} + */ +API.Client.StoreApi.prototype.getInventory = function(opt_extraHttpRequestParams) { + /** @const {!string} */ + var path = this.basePath_ + '/store/inventory'; + + /** @type {!Object} */ + var queryParameters = {}; + + /** @type {!Object} */ + var headerParams = angular.copy(this.defaultHeaders_); + + /** @type {!angular.$http.Config} */ + var httpRequestConfig = /** @type {!angular.$http.Config} */ ({ + url: path, + json: true, + params: queryParameters, + headers: headerParams + }); + + if (opt_extraHttpRequestParams) { + // If an opt_extraHttpRequestParams object is passed in, override values + // set the generated config with the passed in values. + httpRequestConfig = angular.merge(httpRequestConfig, opt_extraHttpRequestParams); + } + + // This whole block is to work around a limitation in closure compiler. It + // would be better to call the $http service directly as a function, but that + // isn't permitted since it has methods attached to it. Manually confirmed to + // compile down to just a single method even with only SIMPLE optimization on. + // https://github.com/google/closure-compiler/blob/90769b826df65eabfb0211517b0d6d85c0c1c60b/contrib/externs/angular-1.4.js#L1393 + switch ('GET') { + case 'GET': + return this.http_.get(path, httpRequestConfig); + case 'HEAD': + return this.http_.head(path, httpRequestConfig); + case 'POST': + return this.http_.post(path, {}, httpRequestConfig); + case 'PUT': + return this.http_.put(path, {}, httpRequestConfig); + case 'DELETE': + return this.http_.delete(path, httpRequestConfig); + case 'PATCH': + return this.http_.patch(path, {}, httpRequestConfig); + } +} + +/** + * Place an order for a pet + * + * @param {!Order=} opt_body order placed for purchasing the pet + * @param {!angular.$http.Config=} opt_extraHttpRequestParams Extra HTTP parameters to send. + * @return {!angular.$q.Promise} + */ +API.Client.StoreApi.prototype.placeOrder = function(opt_body, opt_extraHttpRequestParams) { + /** @const {!string} */ + var path = this.basePath_ + '/store/order'; + + /** @type {!Object} */ + var queryParameters = {}; + + /** @type {!Object} */ + var headerParams = angular.copy(this.defaultHeaders_); + + /** @type {!angular.$http.Config} */ + var httpRequestConfig = /** @type {!angular.$http.Config} */ ({ + url: path, + json: true, + data: body, + params: queryParameters, + headers: headerParams + }); + + if (opt_extraHttpRequestParams) { + // If an opt_extraHttpRequestParams object is passed in, override values + // set the generated config with the passed in values. + httpRequestConfig = angular.merge(httpRequestConfig, opt_extraHttpRequestParams); + } + + // This whole block is to work around a limitation in closure compiler. It + // would be better to call the $http service directly as a function, but that + // isn't permitted since it has methods attached to it. Manually confirmed to + // compile down to just a single method even with only SIMPLE optimization on. + // https://github.com/google/closure-compiler/blob/90769b826df65eabfb0211517b0d6d85c0c1c60b/contrib/externs/angular-1.4.js#L1393 + switch ('POST') { + case 'GET': + return this.http_.get(path, httpRequestConfig); + case 'HEAD': + return this.http_.head(path, httpRequestConfig); + case 'POST': + return this.http_.post(path, {}, httpRequestConfig); + case 'PUT': + return this.http_.put(path, {}, httpRequestConfig); + case 'DELETE': + return this.http_.delete(path, httpRequestConfig); + case 'PATCH': + return this.http_.patch(path, {}, httpRequestConfig); + } +} + +/** + * Find purchase order by ID + * For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions + * @param {!string} orderId ID of pet that needs to be fetched + * @param {!angular.$http.Config=} opt_extraHttpRequestParams Extra HTTP parameters to send. + * @return {!angular.$q.Promise} + */ +API.Client.StoreApi.prototype.getOrderById = function(orderId, opt_extraHttpRequestParams) { + /** @const {!string} */ + var path = this.basePath_ + '/store/order/{orderId}' + .replace('{' + 'orderId' + '}', String(orderId)); + + /** @type {!Object} */ + var queryParameters = {}; + + /** @type {!Object} */ + var headerParams = angular.copy(this.defaultHeaders_); + + /** @type {!angular.$http.Config} */ + var httpRequestConfig = /** @type {!angular.$http.Config} */ ({ + url: path, + json: true, + params: queryParameters, + headers: headerParams + }); + + if (opt_extraHttpRequestParams) { + // If an opt_extraHttpRequestParams object is passed in, override values + // set the generated config with the passed in values. + httpRequestConfig = angular.merge(httpRequestConfig, opt_extraHttpRequestParams); + } + + // This whole block is to work around a limitation in closure compiler. It + // would be better to call the $http service directly as a function, but that + // isn't permitted since it has methods attached to it. Manually confirmed to + // compile down to just a single method even with only SIMPLE optimization on. + // https://github.com/google/closure-compiler/blob/90769b826df65eabfb0211517b0d6d85c0c1c60b/contrib/externs/angular-1.4.js#L1393 + switch ('GET') { + case 'GET': + return this.http_.get(path, httpRequestConfig); + case 'HEAD': + return this.http_.head(path, httpRequestConfig); + case 'POST': + return this.http_.post(path, {}, httpRequestConfig); + case 'PUT': + return this.http_.put(path, {}, httpRequestConfig); + case 'DELETE': + return this.http_.delete(path, httpRequestConfig); + case 'PATCH': + return this.http_.patch(path, {}, httpRequestConfig); + } +} + +/** + * Delete purchase order by ID + * For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors + * @param {!string} orderId ID of the order that needs to be deleted + * @param {!angular.$http.Config=} opt_extraHttpRequestParams Extra HTTP parameters to send. + * @return {!angular.$q.Promise} + */ +API.Client.StoreApi.prototype.deleteOrder = function(orderId, opt_extraHttpRequestParams) { + /** @const {!string} */ + var path = this.basePath_ + '/store/order/{orderId}' + .replace('{' + 'orderId' + '}', String(orderId)); + + /** @type {!Object} */ + var queryParameters = {}; + + /** @type {!Object} */ + var headerParams = angular.copy(this.defaultHeaders_); + + /** @type {!angular.$http.Config} */ + var httpRequestConfig = /** @type {!angular.$http.Config} */ ({ + url: path, + json: true, + params: queryParameters, + headers: headerParams + }); + + if (opt_extraHttpRequestParams) { + // If an opt_extraHttpRequestParams object is passed in, override values + // set the generated config with the passed in values. + httpRequestConfig = angular.merge(httpRequestConfig, opt_extraHttpRequestParams); + } + + // This whole block is to work around a limitation in closure compiler. It + // would be better to call the $http service directly as a function, but that + // isn't permitted since it has methods attached to it. Manually confirmed to + // compile down to just a single method even with only SIMPLE optimization on. + // https://github.com/google/closure-compiler/blob/90769b826df65eabfb0211517b0d6d85c0c1c60b/contrib/externs/angular-1.4.js#L1393 + switch ('DELETE') { + case 'GET': + return this.http_.get(path, httpRequestConfig); + case 'HEAD': + return this.http_.head(path, httpRequestConfig); + case 'POST': + return this.http_.post(path, {}, httpRequestConfig); + case 'PUT': + return this.http_.put(path, {}, httpRequestConfig); + case 'DELETE': + return this.http_.delete(path, httpRequestConfig); + case 'PATCH': + return this.http_.patch(path, {}, httpRequestConfig); + } +} diff --git a/samples/client/petstore/javascript-closure-angular/API/Client/Tag.js b/samples/client/petstore/javascript-closure-angular/API/Client/Tag.js new file mode 100644 index 000000000000..a65ee4658c85 --- /dev/null +++ b/samples/client/petstore/javascript-closure-angular/API/Client/Tag.js @@ -0,0 +1,19 @@ +goog.provide('API.Client.Tag'); + +/** + * @record + */ +API.Client.Tag = function() {} + +/** + * @type {!number} + * @export + */ +API.Client.Tag.prototype.id; + +/** + * @type {!string} + * @export + */ +API.Client.Tag.prototype.name; + diff --git a/samples/client/petstore/javascript-closure-angular/API/Client/User.js b/samples/client/petstore/javascript-closure-angular/API/Client/User.js new file mode 100644 index 000000000000..332c98a80283 --- /dev/null +++ b/samples/client/petstore/javascript-closure-angular/API/Client/User.js @@ -0,0 +1,56 @@ +goog.provide('API.Client.User'); + +/** + * @record + */ +API.Client.User = function() {} + +/** + * @type {!number} + * @export + */ +API.Client.User.prototype.id; + +/** + * @type {!string} + * @export + */ +API.Client.User.prototype.username; + +/** + * @type {!string} + * @export + */ +API.Client.User.prototype.firstName; + +/** + * @type {!string} + * @export + */ +API.Client.User.prototype.lastName; + +/** + * @type {!string} + * @export + */ +API.Client.User.prototype.email; + +/** + * @type {!string} + * @export + */ +API.Client.User.prototype.password; + +/** + * @type {!string} + * @export + */ +API.Client.User.prototype.phone; + +/** + * User Status + * @type {!number} + * @export + */ +API.Client.User.prototype.userStatus; + diff --git a/samples/client/petstore/javascript-closure-angular/API/Client/UserApi.js b/samples/client/petstore/javascript-closure-angular/API/Client/UserApi.js new file mode 100644 index 000000000000..017e750150c9 --- /dev/null +++ b/samples/client/petstore/javascript-closure-angular/API/Client/UserApi.js @@ -0,0 +1,472 @@ +/** + * @fileoverview AUTOMATICALLY GENERATED service for API.Client.UserApi. + * Do not edit this file by hand or your changes will be lost next time it is + * generated. + * + * This is a sample server Petstore server. You can find out more about Swagger at <a href=\"http://swagger.io\">http://swagger.io</a> or on irc.freenode.net, #swagger. For this sample, you can use the api key \"special-key\" to test the authorization filters + * Version: 1.0.0 + * Generated at: 2016-01-27T23:29:24.021-07:00 + * Generated by: class io.swagger.codegen.languages.JavascriptClosureAngularClientCodegen + */ +/** + * @license Apache 2.0 + * http://www.apache.org/licenses/LICENSE-2.0.html + */ + +goog.provide('API.Client.UserApi'); + +goog.require('API.Client.User'); +goog.require('java.util.List'); + +/** + * @constructor + * @param {!angular.$http} $http + * @param {!angular.$injector} $injector + * @struct + */ +API.Client.UserApi = function($http, $injector) { + /** @private {!string} */ + this.basePath_ = $injector.has('UserApiBasePath') ? + /** @type {!string} */ ($injector.get('UserApiBasePath')) : + 'http://petstore.swagger.io/v2'; + + /** @private {!Object} */ + this.defaultHeaders_ = $injector.has('UserApiDefaultHeaders') ? + /** @type {!Object} */ ( + $injector.get('UserApiDefaultHeaders')) : + {}; + + /** @private {!angular.$http} */ + this.http_ = $http; +} +API.Client.UserApi.$inject = ['$http', '$injector']; + +/** + * Create user + * This can only be done by the logged in user. + * @param {!User=} opt_body Created user object + * @param {!angular.$http.Config=} opt_extraHttpRequestParams Extra HTTP parameters to send. + * @return {!angular.$q.Promise} + */ +API.Client.UserApi.prototype.createUser = function(opt_body, opt_extraHttpRequestParams) { + /** @const {!string} */ + var path = this.basePath_ + '/user'; + + /** @type {!Object} */ + var queryParameters = {}; + + /** @type {!Object} */ + var headerParams = angular.copy(this.defaultHeaders_); + + /** @type {!angular.$http.Config} */ + var httpRequestConfig = /** @type {!angular.$http.Config} */ ({ + url: path, + json: true, + data: body, + params: queryParameters, + headers: headerParams + }); + + if (opt_extraHttpRequestParams) { + // If an opt_extraHttpRequestParams object is passed in, override values + // set the generated config with the passed in values. + httpRequestConfig = angular.merge(httpRequestConfig, opt_extraHttpRequestParams); + } + + // This whole block is to work around a limitation in closure compiler. It + // would be better to call the $http service directly as a function, but that + // isn't permitted since it has methods attached to it. Manually confirmed to + // compile down to just a single method even with only SIMPLE optimization on. + // https://github.com/google/closure-compiler/blob/90769b826df65eabfb0211517b0d6d85c0c1c60b/contrib/externs/angular-1.4.js#L1393 + switch ('POST') { + case 'GET': + return this.http_.get(path, httpRequestConfig); + case 'HEAD': + return this.http_.head(path, httpRequestConfig); + case 'POST': + return this.http_.post(path, {}, httpRequestConfig); + case 'PUT': + return this.http_.put(path, {}, httpRequestConfig); + case 'DELETE': + return this.http_.delete(path, httpRequestConfig); + case 'PATCH': + return this.http_.patch(path, {}, httpRequestConfig); + } +} + +/** + * Creates list of users with given input array + * + * @param {!Array=} opt_body List of user object + * @param {!angular.$http.Config=} opt_extraHttpRequestParams Extra HTTP parameters to send. + * @return {!angular.$q.Promise} + */ +API.Client.UserApi.prototype.createUsersWithArrayInput = function(opt_body, opt_extraHttpRequestParams) { + /** @const {!string} */ + var path = this.basePath_ + '/user/createWithArray'; + + /** @type {!Object} */ + var queryParameters = {}; + + /** @type {!Object} */ + var headerParams = angular.copy(this.defaultHeaders_); + + /** @type {!angular.$http.Config} */ + var httpRequestConfig = /** @type {!angular.$http.Config} */ ({ + url: path, + json: true, + data: body, + params: queryParameters, + headers: headerParams + }); + + if (opt_extraHttpRequestParams) { + // If an opt_extraHttpRequestParams object is passed in, override values + // set the generated config with the passed in values. + httpRequestConfig = angular.merge(httpRequestConfig, opt_extraHttpRequestParams); + } + + // This whole block is to work around a limitation in closure compiler. It + // would be better to call the $http service directly as a function, but that + // isn't permitted since it has methods attached to it. Manually confirmed to + // compile down to just a single method even with only SIMPLE optimization on. + // https://github.com/google/closure-compiler/blob/90769b826df65eabfb0211517b0d6d85c0c1c60b/contrib/externs/angular-1.4.js#L1393 + switch ('POST') { + case 'GET': + return this.http_.get(path, httpRequestConfig); + case 'HEAD': + return this.http_.head(path, httpRequestConfig); + case 'POST': + return this.http_.post(path, {}, httpRequestConfig); + case 'PUT': + return this.http_.put(path, {}, httpRequestConfig); + case 'DELETE': + return this.http_.delete(path, httpRequestConfig); + case 'PATCH': + return this.http_.patch(path, {}, httpRequestConfig); + } +} + +/** + * Creates list of users with given input array + * + * @param {!Array=} opt_body List of user object + * @param {!angular.$http.Config=} opt_extraHttpRequestParams Extra HTTP parameters to send. + * @return {!angular.$q.Promise} + */ +API.Client.UserApi.prototype.createUsersWithListInput = function(opt_body, opt_extraHttpRequestParams) { + /** @const {!string} */ + var path = this.basePath_ + '/user/createWithList'; + + /** @type {!Object} */ + var queryParameters = {}; + + /** @type {!Object} */ + var headerParams = angular.copy(this.defaultHeaders_); + + /** @type {!angular.$http.Config} */ + var httpRequestConfig = /** @type {!angular.$http.Config} */ ({ + url: path, + json: true, + data: body, + params: queryParameters, + headers: headerParams + }); + + if (opt_extraHttpRequestParams) { + // If an opt_extraHttpRequestParams object is passed in, override values + // set the generated config with the passed in values. + httpRequestConfig = angular.merge(httpRequestConfig, opt_extraHttpRequestParams); + } + + // This whole block is to work around a limitation in closure compiler. It + // would be better to call the $http service directly as a function, but that + // isn't permitted since it has methods attached to it. Manually confirmed to + // compile down to just a single method even with only SIMPLE optimization on. + // https://github.com/google/closure-compiler/blob/90769b826df65eabfb0211517b0d6d85c0c1c60b/contrib/externs/angular-1.4.js#L1393 + switch ('POST') { + case 'GET': + return this.http_.get(path, httpRequestConfig); + case 'HEAD': + return this.http_.head(path, httpRequestConfig); + case 'POST': + return this.http_.post(path, {}, httpRequestConfig); + case 'PUT': + return this.http_.put(path, {}, httpRequestConfig); + case 'DELETE': + return this.http_.delete(path, httpRequestConfig); + case 'PATCH': + return this.http_.patch(path, {}, httpRequestConfig); + } +} + +/** + * Logs user into the system + * + * @param {!string=} opt_username The user name for login + * @param {!string=} opt_password The password for login in clear text + * @param {!angular.$http.Config=} opt_extraHttpRequestParams Extra HTTP parameters to send. + * @return {!angular.$q.Promise} + */ +API.Client.UserApi.prototype.loginUser = function(opt_username, opt_password, opt_extraHttpRequestParams) { + /** @const {!string} */ + var path = this.basePath_ + '/user/login'; + + /** @type {!Object} */ + var queryParameters = {}; + if (opt_username !== undefined) { + queryParameters['username'] = String(opt_username); + } + if (opt_password !== undefined) { + queryParameters['password'] = String(opt_password); + } + + /** @type {!Object} */ + var headerParams = angular.copy(this.defaultHeaders_); + + /** @type {!angular.$http.Config} */ + var httpRequestConfig = /** @type {!angular.$http.Config} */ ({ + url: path, + json: true, + params: queryParameters, + headers: headerParams + }); + + if (opt_extraHttpRequestParams) { + // If an opt_extraHttpRequestParams object is passed in, override values + // set the generated config with the passed in values. + httpRequestConfig = angular.merge(httpRequestConfig, opt_extraHttpRequestParams); + } + + // This whole block is to work around a limitation in closure compiler. It + // would be better to call the $http service directly as a function, but that + // isn't permitted since it has methods attached to it. Manually confirmed to + // compile down to just a single method even with only SIMPLE optimization on. + // https://github.com/google/closure-compiler/blob/90769b826df65eabfb0211517b0d6d85c0c1c60b/contrib/externs/angular-1.4.js#L1393 + switch ('GET') { + case 'GET': + return this.http_.get(path, httpRequestConfig); + case 'HEAD': + return this.http_.head(path, httpRequestConfig); + case 'POST': + return this.http_.post(path, {}, httpRequestConfig); + case 'PUT': + return this.http_.put(path, {}, httpRequestConfig); + case 'DELETE': + return this.http_.delete(path, httpRequestConfig); + case 'PATCH': + return this.http_.patch(path, {}, httpRequestConfig); + } +} + +/** + * Logs out current logged in user session + * + * @param {!angular.$http.Config=} opt_extraHttpRequestParams Extra HTTP parameters to send. + * @return {!angular.$q.Promise} + */ +API.Client.UserApi.prototype.logoutUser = function(opt_extraHttpRequestParams) { + /** @const {!string} */ + var path = this.basePath_ + '/user/logout'; + + /** @type {!Object} */ + var queryParameters = {}; + + /** @type {!Object} */ + var headerParams = angular.copy(this.defaultHeaders_); + + /** @type {!angular.$http.Config} */ + var httpRequestConfig = /** @type {!angular.$http.Config} */ ({ + url: path, + json: true, + params: queryParameters, + headers: headerParams + }); + + if (opt_extraHttpRequestParams) { + // If an opt_extraHttpRequestParams object is passed in, override values + // set the generated config with the passed in values. + httpRequestConfig = angular.merge(httpRequestConfig, opt_extraHttpRequestParams); + } + + // This whole block is to work around a limitation in closure compiler. It + // would be better to call the $http service directly as a function, but that + // isn't permitted since it has methods attached to it. Manually confirmed to + // compile down to just a single method even with only SIMPLE optimization on. + // https://github.com/google/closure-compiler/blob/90769b826df65eabfb0211517b0d6d85c0c1c60b/contrib/externs/angular-1.4.js#L1393 + switch ('GET') { + case 'GET': + return this.http_.get(path, httpRequestConfig); + case 'HEAD': + return this.http_.head(path, httpRequestConfig); + case 'POST': + return this.http_.post(path, {}, httpRequestConfig); + case 'PUT': + return this.http_.put(path, {}, httpRequestConfig); + case 'DELETE': + return this.http_.delete(path, httpRequestConfig); + case 'PATCH': + return this.http_.patch(path, {}, httpRequestConfig); + } +} + +/** + * Get user by user name + * + * @param {!string} username The name that needs to be fetched. Use user1 for testing. + * @param {!angular.$http.Config=} opt_extraHttpRequestParams Extra HTTP parameters to send. + * @return {!angular.$q.Promise} + */ +API.Client.UserApi.prototype.getUserByName = function(username, opt_extraHttpRequestParams) { + /** @const {!string} */ + var path = this.basePath_ + '/user/{username}' + .replace('{' + 'username' + '}', String(username)); + + /** @type {!Object} */ + var queryParameters = {}; + + /** @type {!Object} */ + var headerParams = angular.copy(this.defaultHeaders_); + + /** @type {!angular.$http.Config} */ + var httpRequestConfig = /** @type {!angular.$http.Config} */ ({ + url: path, + json: true, + params: queryParameters, + headers: headerParams + }); + + if (opt_extraHttpRequestParams) { + // If an opt_extraHttpRequestParams object is passed in, override values + // set the generated config with the passed in values. + httpRequestConfig = angular.merge(httpRequestConfig, opt_extraHttpRequestParams); + } + + // This whole block is to work around a limitation in closure compiler. It + // would be better to call the $http service directly as a function, but that + // isn't permitted since it has methods attached to it. Manually confirmed to + // compile down to just a single method even with only SIMPLE optimization on. + // https://github.com/google/closure-compiler/blob/90769b826df65eabfb0211517b0d6d85c0c1c60b/contrib/externs/angular-1.4.js#L1393 + switch ('GET') { + case 'GET': + return this.http_.get(path, httpRequestConfig); + case 'HEAD': + return this.http_.head(path, httpRequestConfig); + case 'POST': + return this.http_.post(path, {}, httpRequestConfig); + case 'PUT': + return this.http_.put(path, {}, httpRequestConfig); + case 'DELETE': + return this.http_.delete(path, httpRequestConfig); + case 'PATCH': + return this.http_.patch(path, {}, httpRequestConfig); + } +} + +/** + * Updated user + * This can only be done by the logged in user. + * @param {!string} username name that need to be deleted + * @param {!User=} opt_body Updated user object + * @param {!angular.$http.Config=} opt_extraHttpRequestParams Extra HTTP parameters to send. + * @return {!angular.$q.Promise} + */ +API.Client.UserApi.prototype.updateUser = function(username, opt_body, opt_extraHttpRequestParams) { + /** @const {!string} */ + var path = this.basePath_ + '/user/{username}' + .replace('{' + 'username' + '}', String(username)); + + /** @type {!Object} */ + var queryParameters = {}; + + /** @type {!Object} */ + var headerParams = angular.copy(this.defaultHeaders_); + + /** @type {!angular.$http.Config} */ + var httpRequestConfig = /** @type {!angular.$http.Config} */ ({ + url: path, + json: true, + data: body, + params: queryParameters, + headers: headerParams + }); + + if (opt_extraHttpRequestParams) { + // If an opt_extraHttpRequestParams object is passed in, override values + // set the generated config with the passed in values. + httpRequestConfig = angular.merge(httpRequestConfig, opt_extraHttpRequestParams); + } + + // This whole block is to work around a limitation in closure compiler. It + // would be better to call the $http service directly as a function, but that + // isn't permitted since it has methods attached to it. Manually confirmed to + // compile down to just a single method even with only SIMPLE optimization on. + // https://github.com/google/closure-compiler/blob/90769b826df65eabfb0211517b0d6d85c0c1c60b/contrib/externs/angular-1.4.js#L1393 + switch ('PUT') { + case 'GET': + return this.http_.get(path, httpRequestConfig); + case 'HEAD': + return this.http_.head(path, httpRequestConfig); + case 'POST': + return this.http_.post(path, {}, httpRequestConfig); + case 'PUT': + return this.http_.put(path, {}, httpRequestConfig); + case 'DELETE': + return this.http_.delete(path, httpRequestConfig); + case 'PATCH': + return this.http_.patch(path, {}, httpRequestConfig); + } +} + +/** + * Delete user + * This can only be done by the logged in user. + * @param {!string} username The name that needs to be deleted + * @param {!angular.$http.Config=} opt_extraHttpRequestParams Extra HTTP parameters to send. + * @return {!angular.$q.Promise} + */ +API.Client.UserApi.prototype.deleteUser = function(username, opt_extraHttpRequestParams) { + /** @const {!string} */ + var path = this.basePath_ + '/user/{username}' + .replace('{' + 'username' + '}', String(username)); + + /** @type {!Object} */ + var queryParameters = {}; + + /** @type {!Object} */ + var headerParams = angular.copy(this.defaultHeaders_); + + /** @type {!angular.$http.Config} */ + var httpRequestConfig = /** @type {!angular.$http.Config} */ ({ + url: path, + json: true, + params: queryParameters, + headers: headerParams + }); + + if (opt_extraHttpRequestParams) { + // If an opt_extraHttpRequestParams object is passed in, override values + // set the generated config with the passed in values. + httpRequestConfig = angular.merge(httpRequestConfig, opt_extraHttpRequestParams); + } + + // This whole block is to work around a limitation in closure compiler. It + // would be better to call the $http service directly as a function, but that + // isn't permitted since it has methods attached to it. Manually confirmed to + // compile down to just a single method even with only SIMPLE optimization on. + // https://github.com/google/closure-compiler/blob/90769b826df65eabfb0211517b0d6d85c0c1c60b/contrib/externs/angular-1.4.js#L1393 + switch ('DELETE') { + case 'GET': + return this.http_.get(path, httpRequestConfig); + case 'HEAD': + return this.http_.head(path, httpRequestConfig); + case 'POST': + return this.http_.post(path, {}, httpRequestConfig); + case 'PUT': + return this.http_.put(path, {}, httpRequestConfig); + case 'DELETE': + return this.http_.delete(path, httpRequestConfig); + case 'PATCH': + return this.http_.patch(path, {}, httpRequestConfig); + } +} From b1a508012104de90167d5a655082209204532bfe Mon Sep 17 00:00:00 2001 From: Andrew Z Allen Date: Wed, 27 Jan 2016 23:51:25 -0700 Subject: [PATCH 4/6] Add default includes for Array and Object. --- .../languages/JavascriptClosureAngularClientCodegen.java | 6 ++++++ .../javascript-closure-angular/API/Client/PetApi.js | 2 +- .../javascript-closure-angular/API/Client/StoreApi.js | 2 +- .../javascript-closure-angular/API/Client/UserApi.js | 3 +-- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JavascriptClosureAngularClientCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JavascriptClosureAngularClientCodegen.java index e74dff5f8617..71bf84f5c4f3 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JavascriptClosureAngularClientCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JavascriptClosureAngularClientCodegen.java @@ -53,6 +53,12 @@ public class JavascriptClosureAngularClientCodegen extends DefaultCodegen implem typeMapping.put("map", "Object"); typeMapping.put("DateTime", "Date"); + importMapping = new HashMap(); + defaultIncludes = new HashSet(Arrays.asList( + "Object", + "Array" + )); + outputFolder = "generated-code/javascript-closure-angular"; modelTemplateFiles.put("model.mustache", ".js"); apiTemplateFiles.put("api.mustache", ".js"); diff --git a/samples/client/petstore/javascript-closure-angular/API/Client/PetApi.js b/samples/client/petstore/javascript-closure-angular/API/Client/PetApi.js index 395a3d4041d3..d7c1b7b98410 100644 --- a/samples/client/petstore/javascript-closure-angular/API/Client/PetApi.js +++ b/samples/client/petstore/javascript-closure-angular/API/Client/PetApi.js @@ -5,7 +5,7 @@ * * This is a sample server Petstore server. You can find out more about Swagger at <a href=\"http://swagger.io\">http://swagger.io</a> or on irc.freenode.net, #swagger. For this sample, you can use the api key \"special-key\" to test the authorization filters * Version: 1.0.0 - * Generated at: 2016-01-27T23:29:24.021-07:00 + * Generated at: 2016-01-27T23:51:03.092-07:00 * Generated by: class io.swagger.codegen.languages.JavascriptClosureAngularClientCodegen */ /** diff --git a/samples/client/petstore/javascript-closure-angular/API/Client/StoreApi.js b/samples/client/petstore/javascript-closure-angular/API/Client/StoreApi.js index db9ec948a70b..4e85bb35c510 100644 --- a/samples/client/petstore/javascript-closure-angular/API/Client/StoreApi.js +++ b/samples/client/petstore/javascript-closure-angular/API/Client/StoreApi.js @@ -5,7 +5,7 @@ * * This is a sample server Petstore server. You can find out more about Swagger at <a href=\"http://swagger.io\">http://swagger.io</a> or on irc.freenode.net, #swagger. For this sample, you can use the api key \"special-key\" to test the authorization filters * Version: 1.0.0 - * Generated at: 2016-01-27T23:29:24.021-07:00 + * Generated at: 2016-01-27T23:51:03.092-07:00 * Generated by: class io.swagger.codegen.languages.JavascriptClosureAngularClientCodegen */ /** diff --git a/samples/client/petstore/javascript-closure-angular/API/Client/UserApi.js b/samples/client/petstore/javascript-closure-angular/API/Client/UserApi.js index 017e750150c9..a8762b531db0 100644 --- a/samples/client/petstore/javascript-closure-angular/API/Client/UserApi.js +++ b/samples/client/petstore/javascript-closure-angular/API/Client/UserApi.js @@ -5,7 +5,7 @@ * * This is a sample server Petstore server. You can find out more about Swagger at <a href=\"http://swagger.io\">http://swagger.io</a> or on irc.freenode.net, #swagger. For this sample, you can use the api key \"special-key\" to test the authorization filters * Version: 1.0.0 - * Generated at: 2016-01-27T23:29:24.021-07:00 + * Generated at: 2016-01-27T23:51:03.092-07:00 * Generated by: class io.swagger.codegen.languages.JavascriptClosureAngularClientCodegen */ /** @@ -16,7 +16,6 @@ goog.provide('API.Client.UserApi'); goog.require('API.Client.User'); -goog.require('java.util.List'); /** * @constructor From b9eb26baff33381c06f603c0ffc6a48a5a0c7bce Mon Sep 17 00:00:00 2001 From: Andrew Z Allen Date: Thu, 28 Jan 2016 21:38:45 -0700 Subject: [PATCH 5/6] Change indentation to +4 and map binary to string --- ...JavascriptClosureAngularClientCodegen.java | 374 +++++++++--------- 1 file changed, 189 insertions(+), 185 deletions(-) diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JavascriptClosureAngularClientCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JavascriptClosureAngularClientCodegen.java index 71bf84f5c4f3..382b804d9f03 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JavascriptClosureAngularClientCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JavascriptClosureAngularClientCodegen.java @@ -9,204 +9,208 @@ import java.util.*; import java.io.File; public class JavascriptClosureAngularClientCodegen extends DefaultCodegen implements CodegenConfig { - public JavascriptClosureAngularClientCodegen() { - super(); + public JavascriptClosureAngularClientCodegen() { + super(); - supportsInheritance = false; - reservedWords = new HashSet(Arrays.asList("abstract", - "continue", "for", "new", "switch", "assert", "default", "if", - "package", "synchronized", "do", "goto", "private", - "this", "break", "double", "implements", "protected", "throw", - "byte", "else", "import", "public", "throws", "case", "enum", - "instanceof", "return", "transient", "catch", "extends", "int", - "short", "try", "char", "final", "interface", "static", "void", - "class", "finally", "const", "super", "while")); + supportsInheritance = false; + reservedWords = new HashSet(Arrays.asList("abstract", + "continue", "for", "new", "switch", "assert", "default", "if", + "package", "synchronized", "do", "goto", "private", + "this", "break", "double", "implements", "protected", "throw", + "byte", "else", "import", "public", "throws", "case", "enum", + "instanceof", "return", "transient", "catch", "extends", "int", + "short", "try", "char", "final", "interface", "static", "void", + "class", "finally", "const", "super", "while")); - languageSpecificPrimitives = new HashSet(Arrays.asList( - "string", - "boolean", - "number", - "Object", - "Blob", - "Date")); - instantiationTypes.put("array", "Array"); + languageSpecificPrimitives = new HashSet(Arrays.asList( + "string", + "boolean", + "number", + "Object", + "Blob", + "Date")); + instantiationTypes.put("array", "Array"); - typeMapping = new HashMap(); - typeMapping.put("Array", "Array"); - typeMapping.put("array", "Array"); - typeMapping.put("List", "Array"); - typeMapping.put("boolean", "boolean"); - typeMapping.put("string", "string"); - typeMapping.put("int", "number"); - typeMapping.put("float", "number"); - typeMapping.put("number", "number"); - typeMapping.put("long", "number"); - typeMapping.put("short", "number"); - typeMapping.put("char", "string"); - typeMapping.put("double", "number"); - typeMapping.put("object", "Object"); - typeMapping.put("Object", "Object"); - typeMapping.put("File", "Blob"); - typeMapping.put("file", "Blob"); - typeMapping.put("integer", "number"); - typeMapping.put("Map", "Object"); - typeMapping.put("map", "Object"); - typeMapping.put("DateTime", "Date"); + typeMapping = new HashMap(); + typeMapping.put("Array", "Array"); + typeMapping.put("array", "Array"); + typeMapping.put("List", "Array"); + typeMapping.put("boolean", "boolean"); + typeMapping.put("string", "string"); + typeMapping.put("int", "number"); + typeMapping.put("float", "number"); + typeMapping.put("number", "number"); + typeMapping.put("long", "number"); + typeMapping.put("short", "number"); + typeMapping.put("char", "string"); + typeMapping.put("double", "number"); + typeMapping.put("object", "Object"); + typeMapping.put("Object", "Object"); + typeMapping.put("File", "Blob"); + typeMapping.put("file", "Blob"); + typeMapping.put("integer", "number"); + typeMapping.put("Map", "Object"); + typeMapping.put("map", "Object"); + typeMapping.put("DateTime", "Date"); - importMapping = new HashMap(); - defaultIncludes = new HashSet(Arrays.asList( - "Object", - "Array" - )); + importMapping = new HashMap(); + defaultIncludes = new HashSet(Arrays.asList( + "Object", + "Array", + "Blob" + )); - outputFolder = "generated-code/javascript-closure-angular"; - modelTemplateFiles.put("model.mustache", ".js"); - apiTemplateFiles.put("api.mustache", ".js"); - embeddedTemplateDir = templateDir = "Javascript-Closure-Angular"; - apiPackage = "API.Client"; - modelPackage = "API.Client"; - } + typeMapping.put("binary", "string"); - @Override - public String getName() { - return "javascript-closure-angular"; - } - - @Override - public String getHelp() { - return "Generates a Javascript AngularJS client library annotated with Google Closure Compiler annotations" + - "(https://developers.google.com/closure/compiler/docs/js-for-compiler?hl=en)"; - } - - @Override - public CodegenType getTag() { - return CodegenType.CLIENT; - } - - @Override - public String escapeReservedWord(String name) { - return "_" + name; - } - - @Override - public String apiFileFolder() { - return outputFolder + "/" + apiPackage().replace('.', File.separatorChar); - } - - public String modelFileFolder() { - return outputFolder + "/" + modelPackage().replace('.', File.separatorChar); - } - - @Override - public String toVarName(String name) { - // replace - with _ e.g. created-at => created_at - name = name.replaceAll("-", "_"); - - // if it's all uppper case, do nothing - if (name.matches("^[A-Z_]*$")) - return name; - - // camelize the variable name - // pet_id => PetId - name = camelize(name, true); - - // for reserved word or word starting with number, append _ - if (reservedWords.contains(name) || name.matches("^\\d.*")) - name = escapeReservedWord(name); - - return name; - } - - @Override - public String toParamName(String name) { - // should be the same as variable name - return toVarName(name); - } - - @Override - public String toModelName(String name) { - // model name cannot use reserved keyword, e.g. return - if (reservedWords.contains(name)) - throw new RuntimeException(name - + " (reserved word) cannot be used as a model name"); - - // camelize the model name - // phone_number => PhoneNumber - return camelize(name); - } - - @Override - public String toModelFilename(String name) { - // should be the same as the model name - return toModelName(name); - } - - @Override - public String getTypeDeclaration(Property p) { - if (p instanceof ArrayProperty) { - ArrayProperty ap = (ArrayProperty) p; - Property inner = ap.getItems(); - return getSwaggerType(p) + ""; - } else if (p instanceof MapProperty) { - MapProperty mp = (MapProperty) p; - Property inner = mp.getAdditionalProperties(); - return "Object"; - } else if (p instanceof FileProperty) { - return "Object"; + outputFolder = "generated-code/javascript-closure-angular"; + modelTemplateFiles.put("model.mustache", ".js"); + apiTemplateFiles.put("api.mustache", ".js"); + embeddedTemplateDir = templateDir = "Javascript-Closure-Angular"; + apiPackage = "API.Client"; + modelPackage = "API.Client"; } - String type = super.getTypeDeclaration(p); - if (type.equals("boolean") || - type.equals("Date") || - type.equals("number") || - type.equals("string")) { - return type; + + @Override + public String getName() { + return "javascript-closure-angular"; } - return apiPackage + "." + type; - } - @Override - public String getSwaggerType(Property p) { - String swaggerType = super.getSwaggerType(p); - String type = null; - if (typeMapping.containsKey(swaggerType)) { - type = typeMapping.get(swaggerType); - if (languageSpecificPrimitives.contains(type)) - return type; - } else - type = swaggerType; - return type; - } + @Override + public String getHelp() { + return "Generates a Javascript AngularJS client library annotated with Google Closure Compiler annotations" + + "(https://developers.google.com/closure/compiler/docs/js-for-compiler?hl=en)"; + } - @Override - public Map postProcessModels(Map objs) { + @Override + public CodegenType getTag() { + return CodegenType.CLIENT; + } - List models = (List) objs.get("models"); - for (Object _mo : models) { - Map mo = (Map) _mo; - CodegenModel cm = (CodegenModel) mo.get("model"); - cm.imports = new TreeSet(cm.imports); - for (CodegenProperty var : cm.vars) { - // handle default value for enum, e.g. available => StatusEnum.available - if (var.isEnum && var.defaultValue != null && !"null".equals(var.defaultValue)) { - var.defaultValue = var.datatypeWithEnum + "." + var.defaultValue; - } - } - } - return objs; - } + @Override + public String escapeReservedWord(String name) { + return "_" + name; + } - @Override - public Map postProcessOperations(Map objs) { - if (objs.get("imports") instanceof List) { - List> imports = (ArrayList>)objs.get("imports"); - Collections.sort(imports, new Comparator>() { - public int compare(Map o1, Map o2) { - return o1.get("import").compareTo(o2.get("import")); + @Override + public String apiFileFolder() { + return outputFolder + "/" + apiPackage().replace('.', File.separatorChar); + } + + public String modelFileFolder() { + return outputFolder + "/" + modelPackage().replace('.', File.separatorChar); + } + + @Override + public String toVarName(String name) { + // replace - with _ e.g. created-at => created_at + name = name.replaceAll("-", "_"); + + // if it's all uppper case, do nothing + if (name.matches("^[A-Z_]*$")) + return name; + + // camelize the variable name + // pet_id => PetId + name = camelize(name, true); + + // for reserved word or word starting with number, append _ + if (reservedWords.contains(name) || name.matches("^\\d.*")) + name = escapeReservedWord(name); + + return name; + } + + @Override + public String toParamName(String name) { + // should be the same as variable name + return toVarName(name); + } + + @Override + public String toModelName(String name) { + // model name cannot use reserved keyword, e.g. return + if (reservedWords.contains(name)) + throw new RuntimeException(name + + " (reserved word) cannot be used as a model name"); + + // camelize the model name + // phone_number => PhoneNumber + return camelize(name); + } + + @Override + public String toModelFilename(String name) { + // should be the same as the model name + return toModelName(name); + } + + @Override + public String getTypeDeclaration(Property p) { + if (p instanceof ArrayProperty) { + ArrayProperty ap = (ArrayProperty) p; + Property inner = ap.getItems(); + return getSwaggerType(p) + ""; + } else if (p instanceof MapProperty) { + MapProperty mp = (MapProperty) p; + Property inner = mp.getAdditionalProperties(); + return "Object"; + } else if (p instanceof FileProperty) { + return "Object"; } - }); - objs.put("imports", imports); + String type = super.getTypeDeclaration(p); + if (type.equals("boolean") || + type.equals("Date") || + type.equals("number") || + type.equals("string")) { + return type; + } + return apiPackage + "." + type; + } + + @Override + public String getSwaggerType(Property p) { + String swaggerType = super.getSwaggerType(p); + String type = null; + if (typeMapping.containsKey(swaggerType)) { + type = typeMapping.get(swaggerType); + if (languageSpecificPrimitives.contains(type)) { + return type; + } + } else + type = swaggerType; + return type; + } + + @Override + public Map postProcessModels(Map objs) { + + List models = (List) objs.get("models"); + for (Object _mo : models) { + Map mo = (Map) _mo; + CodegenModel cm = (CodegenModel) mo.get("model"); + cm.imports = new TreeSet(cm.imports); + for (CodegenProperty var : cm.vars) { + // handle default value for enum, e.g. available => StatusEnum.available + if (var.isEnum && var.defaultValue != null && !"null".equals(var.defaultValue)) { + var.defaultValue = var.datatypeWithEnum + "." + var.defaultValue; + } + } + } + return objs; + } + + @Override + public Map postProcessOperations(Map objs) { + if (objs.get("imports") instanceof List) { + List> imports = (ArrayList>)objs.get("imports"); + Collections.sort(imports, new Comparator>() { + public int compare(Map o1, Map o2) { + return o1.get("import").compareTo(o2.get("import")); + } + }); + objs.put("imports", imports); + } + return objs; } - return objs; - } } From 42f669031dba86c00b5c21089249e967a2766a89 Mon Sep 17 00:00:00 2001 From: Andrew Z Allen Date: Tue, 2 Feb 2016 00:07:53 -0700 Subject: [PATCH 6/6] Add tests for API --- .../Javascript-Closure-Angular/api.mustache | 107 +- .../javascript-closure-angular/.gitignore | 2 + .../API/Client/PetApi.js | 604 +++---- .../API/Client/StoreApi.js | 220 +-- .../API/Client/UserApi.js | 436 ++--- .../javascript-closure-angular/compile.py | 63 + .../javascript-closure-angular/karma.conf.js | 78 + .../lib/goog/base.js | 1548 +++++++++++++++++ .../javascript-closure-angular/package.json | 8 + .../test/petapi.spec.js | 98 ++ .../test/storeapi.spec.js | 68 + .../test/userapi.spec.js | 81 + 12 files changed, 2435 insertions(+), 878 deletions(-) create mode 100644 samples/client/petstore/javascript-closure-angular/.gitignore create mode 100755 samples/client/petstore/javascript-closure-angular/compile.py create mode 100644 samples/client/petstore/javascript-closure-angular/karma.conf.js create mode 100644 samples/client/petstore/javascript-closure-angular/lib/goog/base.js create mode 100644 samples/client/petstore/javascript-closure-angular/package.json create mode 100644 samples/client/petstore/javascript-closure-angular/test/petapi.spec.js create mode 100644 samples/client/petstore/javascript-closure-angular/test/storeapi.spec.js create mode 100644 samples/client/petstore/javascript-closure-angular/test/userapi.spec.js diff --git a/modules/swagger-codegen/src/main/resources/Javascript-Closure-Angular/api.mustache b/modules/swagger-codegen/src/main/resources/Javascript-Closure-Angular/api.mustache index e6934799f529..957add6753ef 100644 --- a/modules/swagger-codegen/src/main/resources/Javascript-Closure-Angular/api.mustache +++ b/modules/swagger-codegen/src/main/resources/Javascript-Closure-Angular/api.mustache @@ -28,10 +28,11 @@ goog.require('{{import}}'); {{/description}} * @constructor * @param {!angular.$http} $http + * @param {!Object} $httpParamSerializer * @param {!angular.$injector} $injector * @struct */ -{{package}}.{{classname}} = function($http, $injector) { +{{package}}.{{classname}} = function($http, $httpParamSerializer, $injector) { /** @private {!string} */ this.basePath_ = $injector.has('{{classname}}BasePath') ? /** @type {!string} */ ($injector.get('{{classname}}BasePath')) : @@ -45,8 +46,11 @@ goog.require('{{import}}'); /** @private {!angular.$http} */ this.http_ = $http; + + /** @private {!Object} */ + this.httpParamSerializer_ = $injector.get('$httpParamSerializer'); } -{{package}}.{{classname}}.$inject = ['$http', '$injector']; +{{package}}.{{classname}}.$inject = ['$http', '$httpParamSerializer', '$injector']; {{#operation}} /** @@ -57,87 +61,64 @@ goog.require('{{import}}'); * @return {!angular.$q.Promise{{#returnType}}{{/returnType}}} */ {{package}}.{{classname}}.prototype.{{nickname}} = function({{#allParams}}{{^required}}opt_{{/required}}{{paramName}}, {{/allParams}}opt_extraHttpRequestParams) { - /** @const {!string} */ + /** @const {string} */ var path = this.basePath_ + '{{path}}'{{#pathParams}} .replace('{' + '{{baseName}}' + '}', String({{^required}}opt_{{/required}}{{paramName}})){{/pathParams}}; -{{#required}} - // verify required parameter '{{paramName}}' is set - if (!{{paramName}}) { - throw new Error('Missing required parameter {{paramName}} when calling {{nickname}}'); + /** @type {!Object} */ + var queryParameters = {}; + + /** @type {!Object} */ + var headerParams = angular.extend({}, this.defaultHeaders); +{{#hasFormParams}} + /** @type {!Object} */ + var formParams = {}; + +{{/hasFormParams}} +{{#allParams}} +{{#required}} + // verify required parameter '{{^required}}opt_{{/required}}{{paramName}}' is set + if (!{{^required}}opt_{{/required}}{{paramName}}) { + throw new Error('Missing required parameter {{^required}}opt_{{/required}}{{paramName}} when calling {{nickname}}'); } {{/required}} - - /** @type {!Object} */ - var queryParameters = {}; +{{/allParams}} {{#queryParams}} if ({{^required}}opt_{{/required}}{{paramName}} !== undefined) { - queryParameters['{{baseName}}'] = String({{^required}}opt_{{/required}}{{paramName}}); + queryParameters['{{baseName}}'] = {{^required}}opt_{{/required}}{{paramName}}; } -{{/queryParams}} - /** @type {!Object} */ - var headerParams = angular.copy(this.defaultHeaders_); +{{/queryParams}} {{#headerParams}} - if ({{^required}}opt_{{/required}}{{paramName}} !== undefined) { - headerParams['{{baseName}}'] = {{^required}}opt_{{/required}}{{paramName}}; - } + headerParams['{{baseName}}'] = {{^required}}opt_{{/required}}{{paramName}}; + {{/headerParams}} {{#hasFormParams}} + headerParams['Content-Type'] = 'application/x-www-form-urlencoded'; - /** @type {!FormData} */ - var formParams = new FormData(); {{/hasFormParams}} {{#formParams}} - if ({{^required}}opt_{{/required}}{{paramName}} !== undefined) { - var {{paramName}}_ = /** @type {?} */ ({{^required}}opt_{{/required}}{{paramName}}); - if ({{paramName}}_ instanceof Blob) { - formParams.append('{{baseName}}', {{paramName}}_); - } else if (typeof {{paramName}}_ === 'string') { - formParams.append('{{baseName}}', {{paramName}}_); - } else { - throw new Error('Forms parameter {{^required}}opt_{{/required}}{{paramName}} is required to be a string or a Blob (https://developer.mozilla.org/en-US/docs/Web/API/Blob/Blob)'); - } - } -{{/formParams}} -{{#allParams}} -{{/allParams}} + formParams['{{baseName}}'] = {{^required}}opt_{{/required}}{{paramName}}; - /** @type {!angular.$http.Config} */ - var httpRequestConfig = /** @type {!angular.$http.Config} */ ({ - url: path, - json: {{#hasFormParams}}false{{/hasFormParams}}{{^hasFormParams}}true{{/hasFormParams}},{{#bodyParam}} - data: {{paramName}},{{/bodyParam}}{{#hasFormParams}} - data: formParams,{{/hasFormParams}} - params: queryParameters, - headers: headerParams - }); +{{/formParams}} + /** @type {!Object} */ + var httpRequestParams = { + method: '{{httpMethod}}', + url: path, + json: {{#hasFormParams}}false{{/hasFormParams}}{{^hasFormParams}}true{{/hasFormParams}}, + {{#bodyParam}}data: {{^required}}opt_{{/required}}{{paramName}}, + {{/bodyParam}} + {{#hasFormParams}}data: this.httpParamSerializer_(formParams), + {{/hasFormParams}} + params: queryParameters, + headers: headerParams + }; if (opt_extraHttpRequestParams) { - // If an opt_extraHttpRequestParams object is passed in, override values - // set the generated config with the passed in values. - httpRequestConfig = angular.merge(httpRequestConfig, opt_extraHttpRequestParams); + httpRequestParams = angular.extend(httpRequestParams, opt_extraHttpRequestParams); } - // This whole block is to work around a limitation in closure compiler. It - // would be better to call the $http service directly as a function, but that - // isn't permitted since it has methods attached to it. Manually confirmed to - // compile down to just a single method even with only SIMPLE optimization on. - // https://github.com/google/closure-compiler/blob/90769b826df65eabfb0211517b0d6d85c0c1c60b/contrib/externs/angular-1.4.js#L1393 - switch ('{{httpMethod}}') { - case 'GET': - return this.http_.get(path, httpRequestConfig); - case 'HEAD': - return this.http_.head(path, httpRequestConfig); - case 'POST': - return this.http_.post(path, {}, httpRequestConfig); - case 'PUT': - return this.http_.put(path, {}, httpRequestConfig); - case 'DELETE': - return this.http_.delete(path, httpRequestConfig); - case 'PATCH': - return this.http_.patch(path, {}, httpRequestConfig); - } + return this.http_(httpRequestParams); } {{/operation}} {{/operations}} diff --git a/samples/client/petstore/javascript-closure-angular/.gitignore b/samples/client/petstore/javascript-closure-angular/.gitignore new file mode 100644 index 000000000000..ea9d108fa3e7 --- /dev/null +++ b/samples/client/petstore/javascript-closure-angular/.gitignore @@ -0,0 +1,2 @@ +*.compiled.js +node_modules diff --git a/samples/client/petstore/javascript-closure-angular/API/Client/PetApi.js b/samples/client/petstore/javascript-closure-angular/API/Client/PetApi.js index d7c1b7b98410..e39dcfc7e242 100644 --- a/samples/client/petstore/javascript-closure-angular/API/Client/PetApi.js +++ b/samples/client/petstore/javascript-closure-angular/API/Client/PetApi.js @@ -5,7 +5,7 @@ * * This is a sample server Petstore server. You can find out more about Swagger at <a href=\"http://swagger.io\">http://swagger.io</a> or on irc.freenode.net, #swagger. For this sample, you can use the api key \"special-key\" to test the authorization filters * Version: 1.0.0 - * Generated at: 2016-01-27T23:51:03.092-07:00 + * Generated at: 2016-02-02T00:45:38.616-07:00 * Generated by: class io.swagger.codegen.languages.JavascriptClosureAngularClientCodegen */ /** @@ -16,15 +16,15 @@ goog.provide('API.Client.PetApi'); goog.require('API.Client.Pet'); -goog.require('API.Client.binary'); /** * @constructor * @param {!angular.$http} $http + * @param {!Object} $httpParamSerializer * @param {!angular.$injector} $injector * @struct */ -API.Client.PetApi = function($http, $injector) { +API.Client.PetApi = function($http, $httpParamSerializer, $injector) { /** @private {!string} */ this.basePath_ = $injector.has('PetApiBasePath') ? /** @type {!string} */ ($injector.get('PetApiBasePath')) : @@ -38,8 +38,11 @@ API.Client.PetApi = function($http, $injector) { /** @private {!angular.$http} */ this.http_ = $http; + + /** @private {!Object} */ + this.httpParamSerializer_ = $injector.get('$httpParamSerializer'); } -API.Client.PetApi.$inject = ['$http', '$injector']; +API.Client.PetApi.$inject = ['$http', '$httpParamSerializer', '$injector']; /** * Update an existing pet @@ -49,49 +52,31 @@ API.Client.PetApi.$inject = ['$http', '$injector']; * @return {!angular.$q.Promise} */ API.Client.PetApi.prototype.updatePet = function(opt_body, opt_extraHttpRequestParams) { - /** @const {!string} */ + /** @const {string} */ var path = this.basePath_ + '/pet'; - /** @type {!Object} */ + /** @type {!Object} */ var queryParameters = {}; - /** @type {!Object} */ - var headerParams = angular.copy(this.defaultHeaders_); - - /** @type {!angular.$http.Config} */ - var httpRequestConfig = /** @type {!angular.$http.Config} */ ({ - url: path, - json: true, - data: body, - params: queryParameters, - headers: headerParams - }); + /** @type {!Object} */ + var headerParams = angular.extend({}, this.defaultHeaders); + /** @type {!Object} */ + var httpRequestParams = { + method: 'PUT', + url: path, + json: true, + data: opt_body, + + + params: queryParameters, + headers: headerParams + }; if (opt_extraHttpRequestParams) { - // If an opt_extraHttpRequestParams object is passed in, override values - // set the generated config with the passed in values. - httpRequestConfig = angular.merge(httpRequestConfig, opt_extraHttpRequestParams); + httpRequestParams = angular.extend(httpRequestParams, opt_extraHttpRequestParams); } - // This whole block is to work around a limitation in closure compiler. It - // would be better to call the $http service directly as a function, but that - // isn't permitted since it has methods attached to it. Manually confirmed to - // compile down to just a single method even with only SIMPLE optimization on. - // https://github.com/google/closure-compiler/blob/90769b826df65eabfb0211517b0d6d85c0c1c60b/contrib/externs/angular-1.4.js#L1393 - switch ('PUT') { - case 'GET': - return this.http_.get(path, httpRequestConfig); - case 'HEAD': - return this.http_.head(path, httpRequestConfig); - case 'POST': - return this.http_.post(path, {}, httpRequestConfig); - case 'PUT': - return this.http_.put(path, {}, httpRequestConfig); - case 'DELETE': - return this.http_.delete(path, httpRequestConfig); - case 'PATCH': - return this.http_.patch(path, {}, httpRequestConfig); - } + return this.http_(httpRequestParams); } /** @@ -102,49 +87,31 @@ API.Client.PetApi.prototype.updatePet = function(opt_body, opt_extraHttpRequestP * @return {!angular.$q.Promise} */ API.Client.PetApi.prototype.addPet = function(opt_body, opt_extraHttpRequestParams) { - /** @const {!string} */ + /** @const {string} */ var path = this.basePath_ + '/pet'; - /** @type {!Object} */ + /** @type {!Object} */ var queryParameters = {}; - /** @type {!Object} */ - var headerParams = angular.copy(this.defaultHeaders_); - - /** @type {!angular.$http.Config} */ - var httpRequestConfig = /** @type {!angular.$http.Config} */ ({ - url: path, - json: true, - data: body, - params: queryParameters, - headers: headerParams - }); + /** @type {!Object} */ + var headerParams = angular.extend({}, this.defaultHeaders); + /** @type {!Object} */ + var httpRequestParams = { + method: 'POST', + url: path, + json: true, + data: opt_body, + + + params: queryParameters, + headers: headerParams + }; if (opt_extraHttpRequestParams) { - // If an opt_extraHttpRequestParams object is passed in, override values - // set the generated config with the passed in values. - httpRequestConfig = angular.merge(httpRequestConfig, opt_extraHttpRequestParams); + httpRequestParams = angular.extend(httpRequestParams, opt_extraHttpRequestParams); } - // This whole block is to work around a limitation in closure compiler. It - // would be better to call the $http service directly as a function, but that - // isn't permitted since it has methods attached to it. Manually confirmed to - // compile down to just a single method even with only SIMPLE optimization on. - // https://github.com/google/closure-compiler/blob/90769b826df65eabfb0211517b0d6d85c0c1c60b/contrib/externs/angular-1.4.js#L1393 - switch ('POST') { - case 'GET': - return this.http_.get(path, httpRequestConfig); - case 'HEAD': - return this.http_.head(path, httpRequestConfig); - case 'POST': - return this.http_.post(path, {}, httpRequestConfig); - case 'PUT': - return this.http_.put(path, {}, httpRequestConfig); - case 'DELETE': - return this.http_.delete(path, httpRequestConfig); - case 'PATCH': - return this.http_.patch(path, {}, httpRequestConfig); - } + return this.http_(httpRequestParams); } /** @@ -155,51 +122,34 @@ API.Client.PetApi.prototype.addPet = function(opt_body, opt_extraHttpRequestPara * @return {!angular.$q.Promise>} */ API.Client.PetApi.prototype.findPetsByStatus = function(opt_status, opt_extraHttpRequestParams) { - /** @const {!string} */ + /** @const {string} */ var path = this.basePath_ + '/pet/findByStatus'; - /** @type {!Object} */ + /** @type {!Object} */ var queryParameters = {}; + + /** @type {!Object} */ + var headerParams = angular.extend({}, this.defaultHeaders); if (opt_status !== undefined) { - queryParameters['status'] = String(opt_status); + queryParameters['status'] = opt_status; } - /** @type {!Object} */ - var headerParams = angular.copy(this.defaultHeaders_); - - /** @type {!angular.$http.Config} */ - var httpRequestConfig = /** @type {!angular.$http.Config} */ ({ - url: path, - json: true, - params: queryParameters, - headers: headerParams - }); + /** @type {!Object} */ + var httpRequestParams = { + method: 'GET', + url: path, + json: true, + + + params: queryParameters, + headers: headerParams + }; if (opt_extraHttpRequestParams) { - // If an opt_extraHttpRequestParams object is passed in, override values - // set the generated config with the passed in values. - httpRequestConfig = angular.merge(httpRequestConfig, opt_extraHttpRequestParams); + httpRequestParams = angular.extend(httpRequestParams, opt_extraHttpRequestParams); } - // This whole block is to work around a limitation in closure compiler. It - // would be better to call the $http service directly as a function, but that - // isn't permitted since it has methods attached to it. Manually confirmed to - // compile down to just a single method even with only SIMPLE optimization on. - // https://github.com/google/closure-compiler/blob/90769b826df65eabfb0211517b0d6d85c0c1c60b/contrib/externs/angular-1.4.js#L1393 - switch ('GET') { - case 'GET': - return this.http_.get(path, httpRequestConfig); - case 'HEAD': - return this.http_.head(path, httpRequestConfig); - case 'POST': - return this.http_.post(path, {}, httpRequestConfig); - case 'PUT': - return this.http_.put(path, {}, httpRequestConfig); - case 'DELETE': - return this.http_.delete(path, httpRequestConfig); - case 'PATCH': - return this.http_.patch(path, {}, httpRequestConfig); - } + return this.http_(httpRequestParams); } /** @@ -210,51 +160,34 @@ API.Client.PetApi.prototype.findPetsByStatus = function(opt_status, opt_extraHtt * @return {!angular.$q.Promise>} */ API.Client.PetApi.prototype.findPetsByTags = function(opt_tags, opt_extraHttpRequestParams) { - /** @const {!string} */ + /** @const {string} */ var path = this.basePath_ + '/pet/findByTags'; - /** @type {!Object} */ + /** @type {!Object} */ var queryParameters = {}; + + /** @type {!Object} */ + var headerParams = angular.extend({}, this.defaultHeaders); if (opt_tags !== undefined) { - queryParameters['tags'] = String(opt_tags); + queryParameters['tags'] = opt_tags; } - /** @type {!Object} */ - var headerParams = angular.copy(this.defaultHeaders_); - - /** @type {!angular.$http.Config} */ - var httpRequestConfig = /** @type {!angular.$http.Config} */ ({ - url: path, - json: true, - params: queryParameters, - headers: headerParams - }); + /** @type {!Object} */ + var httpRequestParams = { + method: 'GET', + url: path, + json: true, + + + params: queryParameters, + headers: headerParams + }; if (opt_extraHttpRequestParams) { - // If an opt_extraHttpRequestParams object is passed in, override values - // set the generated config with the passed in values. - httpRequestConfig = angular.merge(httpRequestConfig, opt_extraHttpRequestParams); + httpRequestParams = angular.extend(httpRequestParams, opt_extraHttpRequestParams); } - // This whole block is to work around a limitation in closure compiler. It - // would be better to call the $http service directly as a function, but that - // isn't permitted since it has methods attached to it. Manually confirmed to - // compile down to just a single method even with only SIMPLE optimization on. - // https://github.com/google/closure-compiler/blob/90769b826df65eabfb0211517b0d6d85c0c1c60b/contrib/externs/angular-1.4.js#L1393 - switch ('GET') { - case 'GET': - return this.http_.get(path, httpRequestConfig); - case 'HEAD': - return this.http_.head(path, httpRequestConfig); - case 'POST': - return this.http_.post(path, {}, httpRequestConfig); - case 'PUT': - return this.http_.put(path, {}, httpRequestConfig); - case 'DELETE': - return this.http_.delete(path, httpRequestConfig); - case 'PATCH': - return this.http_.patch(path, {}, httpRequestConfig); - } + return this.http_(httpRequestParams); } /** @@ -265,49 +198,35 @@ API.Client.PetApi.prototype.findPetsByTags = function(opt_tags, opt_extraHttpReq * @return {!angular.$q.Promise} */ API.Client.PetApi.prototype.getPetById = function(petId, opt_extraHttpRequestParams) { - /** @const {!string} */ + /** @const {string} */ var path = this.basePath_ + '/pet/{petId}' .replace('{' + 'petId' + '}', String(petId)); - /** @type {!Object} */ + /** @type {!Object} */ var queryParameters = {}; - /** @type {!Object} */ - var headerParams = angular.copy(this.defaultHeaders_); - - /** @type {!angular.$http.Config} */ - var httpRequestConfig = /** @type {!angular.$http.Config} */ ({ - url: path, - json: true, - params: queryParameters, - headers: headerParams - }); + /** @type {!Object} */ + var headerParams = angular.extend({}, this.defaultHeaders); + // verify required parameter 'petId' is set + if (!petId) { + throw new Error('Missing required parameter petId when calling getPetById'); + } + /** @type {!Object} */ + var httpRequestParams = { + method: 'GET', + url: path, + json: true, + + + params: queryParameters, + headers: headerParams + }; if (opt_extraHttpRequestParams) { - // If an opt_extraHttpRequestParams object is passed in, override values - // set the generated config with the passed in values. - httpRequestConfig = angular.merge(httpRequestConfig, opt_extraHttpRequestParams); + httpRequestParams = angular.extend(httpRequestParams, opt_extraHttpRequestParams); } - // This whole block is to work around a limitation in closure compiler. It - // would be better to call the $http service directly as a function, but that - // isn't permitted since it has methods attached to it. Manually confirmed to - // compile down to just a single method even with only SIMPLE optimization on. - // https://github.com/google/closure-compiler/blob/90769b826df65eabfb0211517b0d6d85c0c1c60b/contrib/externs/angular-1.4.js#L1393 - switch ('GET') { - case 'GET': - return this.http_.get(path, httpRequestConfig); - case 'HEAD': - return this.http_.head(path, httpRequestConfig); - case 'POST': - return this.http_.post(path, {}, httpRequestConfig); - case 'PUT': - return this.http_.put(path, {}, httpRequestConfig); - case 'DELETE': - return this.http_.delete(path, httpRequestConfig); - case 'PATCH': - return this.http_.patch(path, {}, httpRequestConfig); - } + return this.http_(httpRequestParams); } /** @@ -320,73 +239,45 @@ API.Client.PetApi.prototype.getPetById = function(petId, opt_extraHttpRequestPar * @return {!angular.$q.Promise} */ API.Client.PetApi.prototype.updatePetWithForm = function(petId, opt_name, opt_status, opt_extraHttpRequestParams) { - /** @const {!string} */ + /** @const {string} */ var path = this.basePath_ + '/pet/{petId}' .replace('{' + 'petId' + '}', String(petId)); - /** @type {!Object} */ + /** @type {!Object} */ var queryParameters = {}; - /** @type {!Object} */ - var headerParams = angular.copy(this.defaultHeaders_); + /** @type {!Object} */ + var headerParams = angular.extend({}, this.defaultHeaders); + /** @type {!Object} */ + var formParams = {}; - /** @type {!FormData} */ - var formParams = new FormData(); - if (opt_name !== undefined) { - var name_ = /** @type {?} */ (opt_name); - if (name_ instanceof Blob) { - formParams.append('name', name_); - } else if (typeof name_ === 'string') { - formParams.append('name', name_); - } else { - throw new Error('Forms parameter opt_name is required to be a string or a Blob (https://developer.mozilla.org/en-US/docs/Web/API/Blob/Blob)'); - } - } - if (opt_status !== undefined) { - var status_ = /** @type {?} */ (opt_status); - if (status_ instanceof Blob) { - formParams.append('status', status_); - } else if (typeof status_ === 'string') { - formParams.append('status', status_); - } else { - throw new Error('Forms parameter opt_status is required to be a string or a Blob (https://developer.mozilla.org/en-US/docs/Web/API/Blob/Blob)'); - } + // verify required parameter 'petId' is set + if (!petId) { + throw new Error('Missing required parameter petId when calling updatePetWithForm'); } + headerParams['Content-Type'] = 'application/x-www-form-urlencoded'; - /** @type {!angular.$http.Config} */ - var httpRequestConfig = /** @type {!angular.$http.Config} */ ({ - url: path, - json: false, - data: formParams, - params: queryParameters, - headers: headerParams - }); + formParams['name'] = opt_name; + + formParams['status'] = opt_status; + + /** @type {!Object} */ + var httpRequestParams = { + method: 'POST', + url: path, + json: false, + + data: this.httpParamSerializer_(formParams), + + params: queryParameters, + headers: headerParams + }; if (opt_extraHttpRequestParams) { - // If an opt_extraHttpRequestParams object is passed in, override values - // set the generated config with the passed in values. - httpRequestConfig = angular.merge(httpRequestConfig, opt_extraHttpRequestParams); + httpRequestParams = angular.extend(httpRequestParams, opt_extraHttpRequestParams); } - // This whole block is to work around a limitation in closure compiler. It - // would be better to call the $http service directly as a function, but that - // isn't permitted since it has methods attached to it. Manually confirmed to - // compile down to just a single method even with only SIMPLE optimization on. - // https://github.com/google/closure-compiler/blob/90769b826df65eabfb0211517b0d6d85c0c1c60b/contrib/externs/angular-1.4.js#L1393 - switch ('POST') { - case 'GET': - return this.http_.get(path, httpRequestConfig); - case 'HEAD': - return this.http_.head(path, httpRequestConfig); - case 'POST': - return this.http_.post(path, {}, httpRequestConfig); - case 'PUT': - return this.http_.put(path, {}, httpRequestConfig); - case 'DELETE': - return this.http_.delete(path, httpRequestConfig); - case 'PATCH': - return this.http_.patch(path, {}, httpRequestConfig); - } + return this.http_(httpRequestParams); } /** @@ -398,52 +289,37 @@ API.Client.PetApi.prototype.updatePetWithForm = function(petId, opt_name, opt_st * @return {!angular.$q.Promise} */ API.Client.PetApi.prototype.deletePet = function(petId, opt_apiKey, opt_extraHttpRequestParams) { - /** @const {!string} */ + /** @const {string} */ var path = this.basePath_ + '/pet/{petId}' .replace('{' + 'petId' + '}', String(petId)); - /** @type {!Object} */ + /** @type {!Object} */ var queryParameters = {}; - /** @type {!Object} */ - var headerParams = angular.copy(this.defaultHeaders_); - if (opt_apiKey !== undefined) { - headerParams['api_key'] = opt_apiKey; + /** @type {!Object} */ + var headerParams = angular.extend({}, this.defaultHeaders); + // verify required parameter 'petId' is set + if (!petId) { + throw new Error('Missing required parameter petId when calling deletePet'); } + headerParams['api_key'] = opt_apiKey; - /** @type {!angular.$http.Config} */ - var httpRequestConfig = /** @type {!angular.$http.Config} */ ({ - url: path, - json: true, - params: queryParameters, - headers: headerParams - }); + /** @type {!Object} */ + var httpRequestParams = { + method: 'DELETE', + url: path, + json: true, + + + params: queryParameters, + headers: headerParams + }; if (opt_extraHttpRequestParams) { - // If an opt_extraHttpRequestParams object is passed in, override values - // set the generated config with the passed in values. - httpRequestConfig = angular.merge(httpRequestConfig, opt_extraHttpRequestParams); + httpRequestParams = angular.extend(httpRequestParams, opt_extraHttpRequestParams); } - // This whole block is to work around a limitation in closure compiler. It - // would be better to call the $http service directly as a function, but that - // isn't permitted since it has methods attached to it. Manually confirmed to - // compile down to just a single method even with only SIMPLE optimization on. - // https://github.com/google/closure-compiler/blob/90769b826df65eabfb0211517b0d6d85c0c1c60b/contrib/externs/angular-1.4.js#L1393 - switch ('DELETE') { - case 'GET': - return this.http_.get(path, httpRequestConfig); - case 'HEAD': - return this.http_.head(path, httpRequestConfig); - case 'POST': - return this.http_.post(path, {}, httpRequestConfig); - case 'PUT': - return this.http_.put(path, {}, httpRequestConfig); - case 'DELETE': - return this.http_.delete(path, httpRequestConfig); - case 'PATCH': - return this.http_.patch(path, {}, httpRequestConfig); - } + return this.http_(httpRequestParams); } /** @@ -456,73 +332,45 @@ API.Client.PetApi.prototype.deletePet = function(petId, opt_apiKey, opt_extraHtt * @return {!angular.$q.Promise} */ API.Client.PetApi.prototype.uploadFile = function(petId, opt_additionalMetadata, opt_file, opt_extraHttpRequestParams) { - /** @const {!string} */ + /** @const {string} */ var path = this.basePath_ + '/pet/{petId}/uploadImage' .replace('{' + 'petId' + '}', String(petId)); - /** @type {!Object} */ + /** @type {!Object} */ var queryParameters = {}; - /** @type {!Object} */ - var headerParams = angular.copy(this.defaultHeaders_); + /** @type {!Object} */ + var headerParams = angular.extend({}, this.defaultHeaders); + /** @type {!Object} */ + var formParams = {}; - /** @type {!FormData} */ - var formParams = new FormData(); - if (opt_additionalMetadata !== undefined) { - var additionalMetadata_ = /** @type {?} */ (opt_additionalMetadata); - if (additionalMetadata_ instanceof Blob) { - formParams.append('additionalMetadata', additionalMetadata_); - } else if (typeof additionalMetadata_ === 'string') { - formParams.append('additionalMetadata', additionalMetadata_); - } else { - throw new Error('Forms parameter opt_additionalMetadata is required to be a string or a Blob (https://developer.mozilla.org/en-US/docs/Web/API/Blob/Blob)'); - } - } - if (opt_file !== undefined) { - var file_ = /** @type {?} */ (opt_file); - if (file_ instanceof Blob) { - formParams.append('file', file_); - } else if (typeof file_ === 'string') { - formParams.append('file', file_); - } else { - throw new Error('Forms parameter opt_file is required to be a string or a Blob (https://developer.mozilla.org/en-US/docs/Web/API/Blob/Blob)'); - } + // verify required parameter 'petId' is set + if (!petId) { + throw new Error('Missing required parameter petId when calling uploadFile'); } + headerParams['Content-Type'] = 'application/x-www-form-urlencoded'; - /** @type {!angular.$http.Config} */ - var httpRequestConfig = /** @type {!angular.$http.Config} */ ({ - url: path, - json: false, - data: formParams, - params: queryParameters, - headers: headerParams - }); + formParams['additionalMetadata'] = opt_additionalMetadata; + + formParams['file'] = opt_file; + + /** @type {!Object} */ + var httpRequestParams = { + method: 'POST', + url: path, + json: false, + + data: this.httpParamSerializer_(formParams), + + params: queryParameters, + headers: headerParams + }; if (opt_extraHttpRequestParams) { - // If an opt_extraHttpRequestParams object is passed in, override values - // set the generated config with the passed in values. - httpRequestConfig = angular.merge(httpRequestConfig, opt_extraHttpRequestParams); + httpRequestParams = angular.extend(httpRequestParams, opt_extraHttpRequestParams); } - // This whole block is to work around a limitation in closure compiler. It - // would be better to call the $http service directly as a function, but that - // isn't permitted since it has methods attached to it. Manually confirmed to - // compile down to just a single method even with only SIMPLE optimization on. - // https://github.com/google/closure-compiler/blob/90769b826df65eabfb0211517b0d6d85c0c1c60b/contrib/externs/angular-1.4.js#L1393 - switch ('POST') { - case 'GET': - return this.http_.get(path, httpRequestConfig); - case 'HEAD': - return this.http_.head(path, httpRequestConfig); - case 'POST': - return this.http_.post(path, {}, httpRequestConfig); - case 'PUT': - return this.http_.put(path, {}, httpRequestConfig); - case 'DELETE': - return this.http_.delete(path, httpRequestConfig); - case 'PATCH': - return this.http_.patch(path, {}, httpRequestConfig); - } + return this.http_(httpRequestParams); } /** @@ -530,103 +378,71 @@ API.Client.PetApi.prototype.uploadFile = function(petId, opt_additionalMetadata, * Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions * @param {!number} petId ID of pet that needs to be fetched * @param {!angular.$http.Config=} opt_extraHttpRequestParams Extra HTTP parameters to send. - * @return {!angular.$q.Promise} + * @return {!angular.$q.Promise} */ API.Client.PetApi.prototype.getPetByIdWithByteArray = function(petId, opt_extraHttpRequestParams) { - /** @const {!string} */ + /** @const {string} */ var path = this.basePath_ + '/pet/{petId}?testing_byte_array=true' .replace('{' + 'petId' + '}', String(petId)); - /** @type {!Object} */ + /** @type {!Object} */ var queryParameters = {}; - /** @type {!Object} */ - var headerParams = angular.copy(this.defaultHeaders_); - - /** @type {!angular.$http.Config} */ - var httpRequestConfig = /** @type {!angular.$http.Config} */ ({ - url: path, - json: true, - params: queryParameters, - headers: headerParams - }); + /** @type {!Object} */ + var headerParams = angular.extend({}, this.defaultHeaders); + // verify required parameter 'petId' is set + if (!petId) { + throw new Error('Missing required parameter petId when calling getPetByIdWithByteArray'); + } + /** @type {!Object} */ + var httpRequestParams = { + method: 'GET', + url: path, + json: true, + + + params: queryParameters, + headers: headerParams + }; if (opt_extraHttpRequestParams) { - // If an opt_extraHttpRequestParams object is passed in, override values - // set the generated config with the passed in values. - httpRequestConfig = angular.merge(httpRequestConfig, opt_extraHttpRequestParams); + httpRequestParams = angular.extend(httpRequestParams, opt_extraHttpRequestParams); } - // This whole block is to work around a limitation in closure compiler. It - // would be better to call the $http service directly as a function, but that - // isn't permitted since it has methods attached to it. Manually confirmed to - // compile down to just a single method even with only SIMPLE optimization on. - // https://github.com/google/closure-compiler/blob/90769b826df65eabfb0211517b0d6d85c0c1c60b/contrib/externs/angular-1.4.js#L1393 - switch ('GET') { - case 'GET': - return this.http_.get(path, httpRequestConfig); - case 'HEAD': - return this.http_.head(path, httpRequestConfig); - case 'POST': - return this.http_.post(path, {}, httpRequestConfig); - case 'PUT': - return this.http_.put(path, {}, httpRequestConfig); - case 'DELETE': - return this.http_.delete(path, httpRequestConfig); - case 'PATCH': - return this.http_.patch(path, {}, httpRequestConfig); - } + return this.http_(httpRequestParams); } /** * Fake endpoint to test byte array in body parameter for adding a new pet to the store * - * @param {!API.Client.binary=} opt_body Pet object in the form of byte array + * @param {!string=} opt_body Pet object in the form of byte array * @param {!angular.$http.Config=} opt_extraHttpRequestParams Extra HTTP parameters to send. * @return {!angular.$q.Promise} */ API.Client.PetApi.prototype.addPetUsingByteArray = function(opt_body, opt_extraHttpRequestParams) { - /** @const {!string} */ + /** @const {string} */ var path = this.basePath_ + '/pet?testing_byte_array=true'; - /** @type {!Object} */ + /** @type {!Object} */ var queryParameters = {}; - /** @type {!Object} */ - var headerParams = angular.copy(this.defaultHeaders_); - - /** @type {!angular.$http.Config} */ - var httpRequestConfig = /** @type {!angular.$http.Config} */ ({ - url: path, - json: true, - data: body, - params: queryParameters, - headers: headerParams - }); + /** @type {!Object} */ + var headerParams = angular.extend({}, this.defaultHeaders); + /** @type {!Object} */ + var httpRequestParams = { + method: 'POST', + url: path, + json: true, + data: opt_body, + + + params: queryParameters, + headers: headerParams + }; if (opt_extraHttpRequestParams) { - // If an opt_extraHttpRequestParams object is passed in, override values - // set the generated config with the passed in values. - httpRequestConfig = angular.merge(httpRequestConfig, opt_extraHttpRequestParams); + httpRequestParams = angular.extend(httpRequestParams, opt_extraHttpRequestParams); } - // This whole block is to work around a limitation in closure compiler. It - // would be better to call the $http service directly as a function, but that - // isn't permitted since it has methods attached to it. Manually confirmed to - // compile down to just a single method even with only SIMPLE optimization on. - // https://github.com/google/closure-compiler/blob/90769b826df65eabfb0211517b0d6d85c0c1c60b/contrib/externs/angular-1.4.js#L1393 - switch ('POST') { - case 'GET': - return this.http_.get(path, httpRequestConfig); - case 'HEAD': - return this.http_.head(path, httpRequestConfig); - case 'POST': - return this.http_.post(path, {}, httpRequestConfig); - case 'PUT': - return this.http_.put(path, {}, httpRequestConfig); - case 'DELETE': - return this.http_.delete(path, httpRequestConfig); - case 'PATCH': - return this.http_.patch(path, {}, httpRequestConfig); - } + return this.http_(httpRequestParams); } diff --git a/samples/client/petstore/javascript-closure-angular/API/Client/StoreApi.js b/samples/client/petstore/javascript-closure-angular/API/Client/StoreApi.js index 4e85bb35c510..f312b7b20ce0 100644 --- a/samples/client/petstore/javascript-closure-angular/API/Client/StoreApi.js +++ b/samples/client/petstore/javascript-closure-angular/API/Client/StoreApi.js @@ -5,7 +5,7 @@ * * This is a sample server Petstore server. You can find out more about Swagger at <a href=\"http://swagger.io\">http://swagger.io</a> or on irc.freenode.net, #swagger. For this sample, you can use the api key \"special-key\" to test the authorization filters * Version: 1.0.0 - * Generated at: 2016-01-27T23:51:03.092-07:00 + * Generated at: 2016-02-02T00:45:38.616-07:00 * Generated by: class io.swagger.codegen.languages.JavascriptClosureAngularClientCodegen */ /** @@ -20,10 +20,11 @@ goog.require('API.Client.Order'); /** * @constructor * @param {!angular.$http} $http + * @param {!Object} $httpParamSerializer * @param {!angular.$injector} $injector * @struct */ -API.Client.StoreApi = function($http, $injector) { +API.Client.StoreApi = function($http, $httpParamSerializer, $injector) { /** @private {!string} */ this.basePath_ = $injector.has('StoreApiBasePath') ? /** @type {!string} */ ($injector.get('StoreApiBasePath')) : @@ -37,8 +38,11 @@ API.Client.StoreApi = function($http, $injector) { /** @private {!angular.$http} */ this.http_ = $http; + + /** @private {!Object} */ + this.httpParamSerializer_ = $injector.get('$httpParamSerializer'); } -API.Client.StoreApi.$inject = ['$http', '$injector']; +API.Client.StoreApi.$inject = ['$http', '$httpParamSerializer', '$injector']; /** * Returns pet inventories by status @@ -47,48 +51,30 @@ API.Client.StoreApi.$inject = ['$http', '$injector']; * @return {!angular.$q.Promise>} */ API.Client.StoreApi.prototype.getInventory = function(opt_extraHttpRequestParams) { - /** @const {!string} */ + /** @const {string} */ var path = this.basePath_ + '/store/inventory'; - /** @type {!Object} */ + /** @type {!Object} */ var queryParameters = {}; - /** @type {!Object} */ - var headerParams = angular.copy(this.defaultHeaders_); - - /** @type {!angular.$http.Config} */ - var httpRequestConfig = /** @type {!angular.$http.Config} */ ({ - url: path, - json: true, - params: queryParameters, - headers: headerParams - }); + /** @type {!Object} */ + var headerParams = angular.extend({}, this.defaultHeaders); + /** @type {!Object} */ + var httpRequestParams = { + method: 'GET', + url: path, + json: true, + + + params: queryParameters, + headers: headerParams + }; if (opt_extraHttpRequestParams) { - // If an opt_extraHttpRequestParams object is passed in, override values - // set the generated config with the passed in values. - httpRequestConfig = angular.merge(httpRequestConfig, opt_extraHttpRequestParams); + httpRequestParams = angular.extend(httpRequestParams, opt_extraHttpRequestParams); } - // This whole block is to work around a limitation in closure compiler. It - // would be better to call the $http service directly as a function, but that - // isn't permitted since it has methods attached to it. Manually confirmed to - // compile down to just a single method even with only SIMPLE optimization on. - // https://github.com/google/closure-compiler/blob/90769b826df65eabfb0211517b0d6d85c0c1c60b/contrib/externs/angular-1.4.js#L1393 - switch ('GET') { - case 'GET': - return this.http_.get(path, httpRequestConfig); - case 'HEAD': - return this.http_.head(path, httpRequestConfig); - case 'POST': - return this.http_.post(path, {}, httpRequestConfig); - case 'PUT': - return this.http_.put(path, {}, httpRequestConfig); - case 'DELETE': - return this.http_.delete(path, httpRequestConfig); - case 'PATCH': - return this.http_.patch(path, {}, httpRequestConfig); - } + return this.http_(httpRequestParams); } /** @@ -99,49 +85,31 @@ API.Client.StoreApi.prototype.getInventory = function(opt_extraHttpRequestParams * @return {!angular.$q.Promise} */ API.Client.StoreApi.prototype.placeOrder = function(opt_body, opt_extraHttpRequestParams) { - /** @const {!string} */ + /** @const {string} */ var path = this.basePath_ + '/store/order'; - /** @type {!Object} */ + /** @type {!Object} */ var queryParameters = {}; - /** @type {!Object} */ - var headerParams = angular.copy(this.defaultHeaders_); - - /** @type {!angular.$http.Config} */ - var httpRequestConfig = /** @type {!angular.$http.Config} */ ({ - url: path, - json: true, - data: body, - params: queryParameters, - headers: headerParams - }); + /** @type {!Object} */ + var headerParams = angular.extend({}, this.defaultHeaders); + /** @type {!Object} */ + var httpRequestParams = { + method: 'POST', + url: path, + json: true, + data: opt_body, + + + params: queryParameters, + headers: headerParams + }; if (opt_extraHttpRequestParams) { - // If an opt_extraHttpRequestParams object is passed in, override values - // set the generated config with the passed in values. - httpRequestConfig = angular.merge(httpRequestConfig, opt_extraHttpRequestParams); + httpRequestParams = angular.extend(httpRequestParams, opt_extraHttpRequestParams); } - // This whole block is to work around a limitation in closure compiler. It - // would be better to call the $http service directly as a function, but that - // isn't permitted since it has methods attached to it. Manually confirmed to - // compile down to just a single method even with only SIMPLE optimization on. - // https://github.com/google/closure-compiler/blob/90769b826df65eabfb0211517b0d6d85c0c1c60b/contrib/externs/angular-1.4.js#L1393 - switch ('POST') { - case 'GET': - return this.http_.get(path, httpRequestConfig); - case 'HEAD': - return this.http_.head(path, httpRequestConfig); - case 'POST': - return this.http_.post(path, {}, httpRequestConfig); - case 'PUT': - return this.http_.put(path, {}, httpRequestConfig); - case 'DELETE': - return this.http_.delete(path, httpRequestConfig); - case 'PATCH': - return this.http_.patch(path, {}, httpRequestConfig); - } + return this.http_(httpRequestParams); } /** @@ -152,49 +120,35 @@ API.Client.StoreApi.prototype.placeOrder = function(opt_body, opt_extraHttpReque * @return {!angular.$q.Promise} */ API.Client.StoreApi.prototype.getOrderById = function(orderId, opt_extraHttpRequestParams) { - /** @const {!string} */ + /** @const {string} */ var path = this.basePath_ + '/store/order/{orderId}' .replace('{' + 'orderId' + '}', String(orderId)); - /** @type {!Object} */ + /** @type {!Object} */ var queryParameters = {}; - /** @type {!Object} */ - var headerParams = angular.copy(this.defaultHeaders_); - - /** @type {!angular.$http.Config} */ - var httpRequestConfig = /** @type {!angular.$http.Config} */ ({ - url: path, - json: true, - params: queryParameters, - headers: headerParams - }); + /** @type {!Object} */ + var headerParams = angular.extend({}, this.defaultHeaders); + // verify required parameter 'orderId' is set + if (!orderId) { + throw new Error('Missing required parameter orderId when calling getOrderById'); + } + /** @type {!Object} */ + var httpRequestParams = { + method: 'GET', + url: path, + json: true, + + + params: queryParameters, + headers: headerParams + }; if (opt_extraHttpRequestParams) { - // If an opt_extraHttpRequestParams object is passed in, override values - // set the generated config with the passed in values. - httpRequestConfig = angular.merge(httpRequestConfig, opt_extraHttpRequestParams); + httpRequestParams = angular.extend(httpRequestParams, opt_extraHttpRequestParams); } - // This whole block is to work around a limitation in closure compiler. It - // would be better to call the $http service directly as a function, but that - // isn't permitted since it has methods attached to it. Manually confirmed to - // compile down to just a single method even with only SIMPLE optimization on. - // https://github.com/google/closure-compiler/blob/90769b826df65eabfb0211517b0d6d85c0c1c60b/contrib/externs/angular-1.4.js#L1393 - switch ('GET') { - case 'GET': - return this.http_.get(path, httpRequestConfig); - case 'HEAD': - return this.http_.head(path, httpRequestConfig); - case 'POST': - return this.http_.post(path, {}, httpRequestConfig); - case 'PUT': - return this.http_.put(path, {}, httpRequestConfig); - case 'DELETE': - return this.http_.delete(path, httpRequestConfig); - case 'PATCH': - return this.http_.patch(path, {}, httpRequestConfig); - } + return this.http_(httpRequestParams); } /** @@ -205,47 +159,33 @@ API.Client.StoreApi.prototype.getOrderById = function(orderId, opt_extraHttpRequ * @return {!angular.$q.Promise} */ API.Client.StoreApi.prototype.deleteOrder = function(orderId, opt_extraHttpRequestParams) { - /** @const {!string} */ + /** @const {string} */ var path = this.basePath_ + '/store/order/{orderId}' .replace('{' + 'orderId' + '}', String(orderId)); - /** @type {!Object} */ + /** @type {!Object} */ var queryParameters = {}; - /** @type {!Object} */ - var headerParams = angular.copy(this.defaultHeaders_); - - /** @type {!angular.$http.Config} */ - var httpRequestConfig = /** @type {!angular.$http.Config} */ ({ - url: path, - json: true, - params: queryParameters, - headers: headerParams - }); + /** @type {!Object} */ + var headerParams = angular.extend({}, this.defaultHeaders); + // verify required parameter 'orderId' is set + if (!orderId) { + throw new Error('Missing required parameter orderId when calling deleteOrder'); + } + /** @type {!Object} */ + var httpRequestParams = { + method: 'DELETE', + url: path, + json: true, + + + params: queryParameters, + headers: headerParams + }; if (opt_extraHttpRequestParams) { - // If an opt_extraHttpRequestParams object is passed in, override values - // set the generated config with the passed in values. - httpRequestConfig = angular.merge(httpRequestConfig, opt_extraHttpRequestParams); + httpRequestParams = angular.extend(httpRequestParams, opt_extraHttpRequestParams); } - // This whole block is to work around a limitation in closure compiler. It - // would be better to call the $http service directly as a function, but that - // isn't permitted since it has methods attached to it. Manually confirmed to - // compile down to just a single method even with only SIMPLE optimization on. - // https://github.com/google/closure-compiler/blob/90769b826df65eabfb0211517b0d6d85c0c1c60b/contrib/externs/angular-1.4.js#L1393 - switch ('DELETE') { - case 'GET': - return this.http_.get(path, httpRequestConfig); - case 'HEAD': - return this.http_.head(path, httpRequestConfig); - case 'POST': - return this.http_.post(path, {}, httpRequestConfig); - case 'PUT': - return this.http_.put(path, {}, httpRequestConfig); - case 'DELETE': - return this.http_.delete(path, httpRequestConfig); - case 'PATCH': - return this.http_.patch(path, {}, httpRequestConfig); - } + return this.http_(httpRequestParams); } diff --git a/samples/client/petstore/javascript-closure-angular/API/Client/UserApi.js b/samples/client/petstore/javascript-closure-angular/API/Client/UserApi.js index a8762b531db0..4c97786fa9fc 100644 --- a/samples/client/petstore/javascript-closure-angular/API/Client/UserApi.js +++ b/samples/client/petstore/javascript-closure-angular/API/Client/UserApi.js @@ -5,7 +5,7 @@ * * This is a sample server Petstore server. You can find out more about Swagger at <a href=\"http://swagger.io\">http://swagger.io</a> or on irc.freenode.net, #swagger. For this sample, you can use the api key \"special-key\" to test the authorization filters * Version: 1.0.0 - * Generated at: 2016-01-27T23:51:03.092-07:00 + * Generated at: 2016-02-02T00:45:38.616-07:00 * Generated by: class io.swagger.codegen.languages.JavascriptClosureAngularClientCodegen */ /** @@ -20,10 +20,11 @@ goog.require('API.Client.User'); /** * @constructor * @param {!angular.$http} $http + * @param {!Object} $httpParamSerializer * @param {!angular.$injector} $injector * @struct */ -API.Client.UserApi = function($http, $injector) { +API.Client.UserApi = function($http, $httpParamSerializer, $injector) { /** @private {!string} */ this.basePath_ = $injector.has('UserApiBasePath') ? /** @type {!string} */ ($injector.get('UserApiBasePath')) : @@ -37,8 +38,11 @@ API.Client.UserApi = function($http, $injector) { /** @private {!angular.$http} */ this.http_ = $http; + + /** @private {!Object} */ + this.httpParamSerializer_ = $injector.get('$httpParamSerializer'); } -API.Client.UserApi.$inject = ['$http', '$injector']; +API.Client.UserApi.$inject = ['$http', '$httpParamSerializer', '$injector']; /** * Create user @@ -48,49 +52,31 @@ API.Client.UserApi.$inject = ['$http', '$injector']; * @return {!angular.$q.Promise} */ API.Client.UserApi.prototype.createUser = function(opt_body, opt_extraHttpRequestParams) { - /** @const {!string} */ + /** @const {string} */ var path = this.basePath_ + '/user'; - /** @type {!Object} */ + /** @type {!Object} */ var queryParameters = {}; - /** @type {!Object} */ - var headerParams = angular.copy(this.defaultHeaders_); - - /** @type {!angular.$http.Config} */ - var httpRequestConfig = /** @type {!angular.$http.Config} */ ({ - url: path, - json: true, - data: body, - params: queryParameters, - headers: headerParams - }); + /** @type {!Object} */ + var headerParams = angular.extend({}, this.defaultHeaders); + /** @type {!Object} */ + var httpRequestParams = { + method: 'POST', + url: path, + json: true, + data: opt_body, + + + params: queryParameters, + headers: headerParams + }; if (opt_extraHttpRequestParams) { - // If an opt_extraHttpRequestParams object is passed in, override values - // set the generated config with the passed in values. - httpRequestConfig = angular.merge(httpRequestConfig, opt_extraHttpRequestParams); + httpRequestParams = angular.extend(httpRequestParams, opt_extraHttpRequestParams); } - // This whole block is to work around a limitation in closure compiler. It - // would be better to call the $http service directly as a function, but that - // isn't permitted since it has methods attached to it. Manually confirmed to - // compile down to just a single method even with only SIMPLE optimization on. - // https://github.com/google/closure-compiler/blob/90769b826df65eabfb0211517b0d6d85c0c1c60b/contrib/externs/angular-1.4.js#L1393 - switch ('POST') { - case 'GET': - return this.http_.get(path, httpRequestConfig); - case 'HEAD': - return this.http_.head(path, httpRequestConfig); - case 'POST': - return this.http_.post(path, {}, httpRequestConfig); - case 'PUT': - return this.http_.put(path, {}, httpRequestConfig); - case 'DELETE': - return this.http_.delete(path, httpRequestConfig); - case 'PATCH': - return this.http_.patch(path, {}, httpRequestConfig); - } + return this.http_(httpRequestParams); } /** @@ -101,49 +87,31 @@ API.Client.UserApi.prototype.createUser = function(opt_body, opt_extraHttpReques * @return {!angular.$q.Promise} */ API.Client.UserApi.prototype.createUsersWithArrayInput = function(opt_body, opt_extraHttpRequestParams) { - /** @const {!string} */ + /** @const {string} */ var path = this.basePath_ + '/user/createWithArray'; - /** @type {!Object} */ + /** @type {!Object} */ var queryParameters = {}; - /** @type {!Object} */ - var headerParams = angular.copy(this.defaultHeaders_); - - /** @type {!angular.$http.Config} */ - var httpRequestConfig = /** @type {!angular.$http.Config} */ ({ - url: path, - json: true, - data: body, - params: queryParameters, - headers: headerParams - }); + /** @type {!Object} */ + var headerParams = angular.extend({}, this.defaultHeaders); + /** @type {!Object} */ + var httpRequestParams = { + method: 'POST', + url: path, + json: true, + data: opt_body, + + + params: queryParameters, + headers: headerParams + }; if (opt_extraHttpRequestParams) { - // If an opt_extraHttpRequestParams object is passed in, override values - // set the generated config with the passed in values. - httpRequestConfig = angular.merge(httpRequestConfig, opt_extraHttpRequestParams); + httpRequestParams = angular.extend(httpRequestParams, opt_extraHttpRequestParams); } - // This whole block is to work around a limitation in closure compiler. It - // would be better to call the $http service directly as a function, but that - // isn't permitted since it has methods attached to it. Manually confirmed to - // compile down to just a single method even with only SIMPLE optimization on. - // https://github.com/google/closure-compiler/blob/90769b826df65eabfb0211517b0d6d85c0c1c60b/contrib/externs/angular-1.4.js#L1393 - switch ('POST') { - case 'GET': - return this.http_.get(path, httpRequestConfig); - case 'HEAD': - return this.http_.head(path, httpRequestConfig); - case 'POST': - return this.http_.post(path, {}, httpRequestConfig); - case 'PUT': - return this.http_.put(path, {}, httpRequestConfig); - case 'DELETE': - return this.http_.delete(path, httpRequestConfig); - case 'PATCH': - return this.http_.patch(path, {}, httpRequestConfig); - } + return this.http_(httpRequestParams); } /** @@ -154,49 +122,31 @@ API.Client.UserApi.prototype.createUsersWithArrayInput = function(opt_body, opt_ * @return {!angular.$q.Promise} */ API.Client.UserApi.prototype.createUsersWithListInput = function(opt_body, opt_extraHttpRequestParams) { - /** @const {!string} */ + /** @const {string} */ var path = this.basePath_ + '/user/createWithList'; - /** @type {!Object} */ + /** @type {!Object} */ var queryParameters = {}; - /** @type {!Object} */ - var headerParams = angular.copy(this.defaultHeaders_); - - /** @type {!angular.$http.Config} */ - var httpRequestConfig = /** @type {!angular.$http.Config} */ ({ - url: path, - json: true, - data: body, - params: queryParameters, - headers: headerParams - }); + /** @type {!Object} */ + var headerParams = angular.extend({}, this.defaultHeaders); + /** @type {!Object} */ + var httpRequestParams = { + method: 'POST', + url: path, + json: true, + data: opt_body, + + + params: queryParameters, + headers: headerParams + }; if (opt_extraHttpRequestParams) { - // If an opt_extraHttpRequestParams object is passed in, override values - // set the generated config with the passed in values. - httpRequestConfig = angular.merge(httpRequestConfig, opt_extraHttpRequestParams); + httpRequestParams = angular.extend(httpRequestParams, opt_extraHttpRequestParams); } - // This whole block is to work around a limitation in closure compiler. It - // would be better to call the $http service directly as a function, but that - // isn't permitted since it has methods attached to it. Manually confirmed to - // compile down to just a single method even with only SIMPLE optimization on. - // https://github.com/google/closure-compiler/blob/90769b826df65eabfb0211517b0d6d85c0c1c60b/contrib/externs/angular-1.4.js#L1393 - switch ('POST') { - case 'GET': - return this.http_.get(path, httpRequestConfig); - case 'HEAD': - return this.http_.head(path, httpRequestConfig); - case 'POST': - return this.http_.post(path, {}, httpRequestConfig); - case 'PUT': - return this.http_.put(path, {}, httpRequestConfig); - case 'DELETE': - return this.http_.delete(path, httpRequestConfig); - case 'PATCH': - return this.http_.patch(path, {}, httpRequestConfig); - } + return this.http_(httpRequestParams); } /** @@ -208,54 +158,38 @@ API.Client.UserApi.prototype.createUsersWithListInput = function(opt_body, opt_e * @return {!angular.$q.Promise} */ API.Client.UserApi.prototype.loginUser = function(opt_username, opt_password, opt_extraHttpRequestParams) { - /** @const {!string} */ + /** @const {string} */ var path = this.basePath_ + '/user/login'; - /** @type {!Object} */ + /** @type {!Object} */ var queryParameters = {}; + + /** @type {!Object} */ + var headerParams = angular.extend({}, this.defaultHeaders); if (opt_username !== undefined) { - queryParameters['username'] = String(opt_username); + queryParameters['username'] = opt_username; } + if (opt_password !== undefined) { - queryParameters['password'] = String(opt_password); + queryParameters['password'] = opt_password; } - /** @type {!Object} */ - var headerParams = angular.copy(this.defaultHeaders_); - - /** @type {!angular.$http.Config} */ - var httpRequestConfig = /** @type {!angular.$http.Config} */ ({ - url: path, - json: true, - params: queryParameters, - headers: headerParams - }); + /** @type {!Object} */ + var httpRequestParams = { + method: 'GET', + url: path, + json: true, + + + params: queryParameters, + headers: headerParams + }; if (opt_extraHttpRequestParams) { - // If an opt_extraHttpRequestParams object is passed in, override values - // set the generated config with the passed in values. - httpRequestConfig = angular.merge(httpRequestConfig, opt_extraHttpRequestParams); + httpRequestParams = angular.extend(httpRequestParams, opt_extraHttpRequestParams); } - // This whole block is to work around a limitation in closure compiler. It - // would be better to call the $http service directly as a function, but that - // isn't permitted since it has methods attached to it. Manually confirmed to - // compile down to just a single method even with only SIMPLE optimization on. - // https://github.com/google/closure-compiler/blob/90769b826df65eabfb0211517b0d6d85c0c1c60b/contrib/externs/angular-1.4.js#L1393 - switch ('GET') { - case 'GET': - return this.http_.get(path, httpRequestConfig); - case 'HEAD': - return this.http_.head(path, httpRequestConfig); - case 'POST': - return this.http_.post(path, {}, httpRequestConfig); - case 'PUT': - return this.http_.put(path, {}, httpRequestConfig); - case 'DELETE': - return this.http_.delete(path, httpRequestConfig); - case 'PATCH': - return this.http_.patch(path, {}, httpRequestConfig); - } + return this.http_(httpRequestParams); } /** @@ -265,48 +199,30 @@ API.Client.UserApi.prototype.loginUser = function(opt_username, opt_password, op * @return {!angular.$q.Promise} */ API.Client.UserApi.prototype.logoutUser = function(opt_extraHttpRequestParams) { - /** @const {!string} */ + /** @const {string} */ var path = this.basePath_ + '/user/logout'; - /** @type {!Object} */ + /** @type {!Object} */ var queryParameters = {}; - /** @type {!Object} */ - var headerParams = angular.copy(this.defaultHeaders_); - - /** @type {!angular.$http.Config} */ - var httpRequestConfig = /** @type {!angular.$http.Config} */ ({ - url: path, - json: true, - params: queryParameters, - headers: headerParams - }); + /** @type {!Object} */ + var headerParams = angular.extend({}, this.defaultHeaders); + /** @type {!Object} */ + var httpRequestParams = { + method: 'GET', + url: path, + json: true, + + + params: queryParameters, + headers: headerParams + }; if (opt_extraHttpRequestParams) { - // If an opt_extraHttpRequestParams object is passed in, override values - // set the generated config with the passed in values. - httpRequestConfig = angular.merge(httpRequestConfig, opt_extraHttpRequestParams); + httpRequestParams = angular.extend(httpRequestParams, opt_extraHttpRequestParams); } - // This whole block is to work around a limitation in closure compiler. It - // would be better to call the $http service directly as a function, but that - // isn't permitted since it has methods attached to it. Manually confirmed to - // compile down to just a single method even with only SIMPLE optimization on. - // https://github.com/google/closure-compiler/blob/90769b826df65eabfb0211517b0d6d85c0c1c60b/contrib/externs/angular-1.4.js#L1393 - switch ('GET') { - case 'GET': - return this.http_.get(path, httpRequestConfig); - case 'HEAD': - return this.http_.head(path, httpRequestConfig); - case 'POST': - return this.http_.post(path, {}, httpRequestConfig); - case 'PUT': - return this.http_.put(path, {}, httpRequestConfig); - case 'DELETE': - return this.http_.delete(path, httpRequestConfig); - case 'PATCH': - return this.http_.patch(path, {}, httpRequestConfig); - } + return this.http_(httpRequestParams); } /** @@ -317,49 +233,35 @@ API.Client.UserApi.prototype.logoutUser = function(opt_extraHttpRequestParams) { * @return {!angular.$q.Promise} */ API.Client.UserApi.prototype.getUserByName = function(username, opt_extraHttpRequestParams) { - /** @const {!string} */ + /** @const {string} */ var path = this.basePath_ + '/user/{username}' .replace('{' + 'username' + '}', String(username)); - /** @type {!Object} */ + /** @type {!Object} */ var queryParameters = {}; - /** @type {!Object} */ - var headerParams = angular.copy(this.defaultHeaders_); - - /** @type {!angular.$http.Config} */ - var httpRequestConfig = /** @type {!angular.$http.Config} */ ({ - url: path, - json: true, - params: queryParameters, - headers: headerParams - }); + /** @type {!Object} */ + var headerParams = angular.extend({}, this.defaultHeaders); + // verify required parameter 'username' is set + if (!username) { + throw new Error('Missing required parameter username when calling getUserByName'); + } + /** @type {!Object} */ + var httpRequestParams = { + method: 'GET', + url: path, + json: true, + + + params: queryParameters, + headers: headerParams + }; if (opt_extraHttpRequestParams) { - // If an opt_extraHttpRequestParams object is passed in, override values - // set the generated config with the passed in values. - httpRequestConfig = angular.merge(httpRequestConfig, opt_extraHttpRequestParams); + httpRequestParams = angular.extend(httpRequestParams, opt_extraHttpRequestParams); } - // This whole block is to work around a limitation in closure compiler. It - // would be better to call the $http service directly as a function, but that - // isn't permitted since it has methods attached to it. Manually confirmed to - // compile down to just a single method even with only SIMPLE optimization on. - // https://github.com/google/closure-compiler/blob/90769b826df65eabfb0211517b0d6d85c0c1c60b/contrib/externs/angular-1.4.js#L1393 - switch ('GET') { - case 'GET': - return this.http_.get(path, httpRequestConfig); - case 'HEAD': - return this.http_.head(path, httpRequestConfig); - case 'POST': - return this.http_.post(path, {}, httpRequestConfig); - case 'PUT': - return this.http_.put(path, {}, httpRequestConfig); - case 'DELETE': - return this.http_.delete(path, httpRequestConfig); - case 'PATCH': - return this.http_.patch(path, {}, httpRequestConfig); - } + return this.http_(httpRequestParams); } /** @@ -371,50 +273,36 @@ API.Client.UserApi.prototype.getUserByName = function(username, opt_extraHttpReq * @return {!angular.$q.Promise} */ API.Client.UserApi.prototype.updateUser = function(username, opt_body, opt_extraHttpRequestParams) { - /** @const {!string} */ + /** @const {string} */ var path = this.basePath_ + '/user/{username}' .replace('{' + 'username' + '}', String(username)); - /** @type {!Object} */ + /** @type {!Object} */ var queryParameters = {}; - /** @type {!Object} */ - var headerParams = angular.copy(this.defaultHeaders_); - - /** @type {!angular.$http.Config} */ - var httpRequestConfig = /** @type {!angular.$http.Config} */ ({ - url: path, - json: true, - data: body, - params: queryParameters, - headers: headerParams - }); + /** @type {!Object} */ + var headerParams = angular.extend({}, this.defaultHeaders); + // verify required parameter 'username' is set + if (!username) { + throw new Error('Missing required parameter username when calling updateUser'); + } + /** @type {!Object} */ + var httpRequestParams = { + method: 'PUT', + url: path, + json: true, + data: opt_body, + + + params: queryParameters, + headers: headerParams + }; if (opt_extraHttpRequestParams) { - // If an opt_extraHttpRequestParams object is passed in, override values - // set the generated config with the passed in values. - httpRequestConfig = angular.merge(httpRequestConfig, opt_extraHttpRequestParams); + httpRequestParams = angular.extend(httpRequestParams, opt_extraHttpRequestParams); } - // This whole block is to work around a limitation in closure compiler. It - // would be better to call the $http service directly as a function, but that - // isn't permitted since it has methods attached to it. Manually confirmed to - // compile down to just a single method even with only SIMPLE optimization on. - // https://github.com/google/closure-compiler/blob/90769b826df65eabfb0211517b0d6d85c0c1c60b/contrib/externs/angular-1.4.js#L1393 - switch ('PUT') { - case 'GET': - return this.http_.get(path, httpRequestConfig); - case 'HEAD': - return this.http_.head(path, httpRequestConfig); - case 'POST': - return this.http_.post(path, {}, httpRequestConfig); - case 'PUT': - return this.http_.put(path, {}, httpRequestConfig); - case 'DELETE': - return this.http_.delete(path, httpRequestConfig); - case 'PATCH': - return this.http_.patch(path, {}, httpRequestConfig); - } + return this.http_(httpRequestParams); } /** @@ -425,47 +313,33 @@ API.Client.UserApi.prototype.updateUser = function(username, opt_body, opt_extra * @return {!angular.$q.Promise} */ API.Client.UserApi.prototype.deleteUser = function(username, opt_extraHttpRequestParams) { - /** @const {!string} */ + /** @const {string} */ var path = this.basePath_ + '/user/{username}' .replace('{' + 'username' + '}', String(username)); - /** @type {!Object} */ + /** @type {!Object} */ var queryParameters = {}; - /** @type {!Object} */ - var headerParams = angular.copy(this.defaultHeaders_); - - /** @type {!angular.$http.Config} */ - var httpRequestConfig = /** @type {!angular.$http.Config} */ ({ - url: path, - json: true, - params: queryParameters, - headers: headerParams - }); + /** @type {!Object} */ + var headerParams = angular.extend({}, this.defaultHeaders); + // verify required parameter 'username' is set + if (!username) { + throw new Error('Missing required parameter username when calling deleteUser'); + } + /** @type {!Object} */ + var httpRequestParams = { + method: 'DELETE', + url: path, + json: true, + + + params: queryParameters, + headers: headerParams + }; if (opt_extraHttpRequestParams) { - // If an opt_extraHttpRequestParams object is passed in, override values - // set the generated config with the passed in values. - httpRequestConfig = angular.merge(httpRequestConfig, opt_extraHttpRequestParams); + httpRequestParams = angular.extend(httpRequestParams, opt_extraHttpRequestParams); } - // This whole block is to work around a limitation in closure compiler. It - // would be better to call the $http service directly as a function, but that - // isn't permitted since it has methods attached to it. Manually confirmed to - // compile down to just a single method even with only SIMPLE optimization on. - // https://github.com/google/closure-compiler/blob/90769b826df65eabfb0211517b0d6d85c0c1c60b/contrib/externs/angular-1.4.js#L1393 - switch ('DELETE') { - case 'GET': - return this.http_.get(path, httpRequestConfig); - case 'HEAD': - return this.http_.head(path, httpRequestConfig); - case 'POST': - return this.http_.post(path, {}, httpRequestConfig); - case 'PUT': - return this.http_.put(path, {}, httpRequestConfig); - case 'DELETE': - return this.http_.delete(path, httpRequestConfig); - case 'PATCH': - return this.http_.patch(path, {}, httpRequestConfig); - } + return this.http_(httpRequestParams); } diff --git a/samples/client/petstore/javascript-closure-angular/compile.py b/samples/client/petstore/javascript-closure-angular/compile.py new file mode 100755 index 000000000000..2797a6f3456a --- /dev/null +++ b/samples/client/petstore/javascript-closure-angular/compile.py @@ -0,0 +1,63 @@ +#!/usr/bin/python + +import httplib, urllib, sys + +# Collect all the files in an order that will work. That is Models first then APIs +def concatFiles(files): + code = "" + for file in files: + code += open(file).read() + return code + +def makeRequest(params): + # Always use the following value for the Content-type header. + headers = { "Content-type": "application/x-www-form-urlencoded" } + conn = httplib.HTTPConnection('closure-compiler.appspot.com') + conn.request('POST', '/compile', params, headers) + response = conn.getresponse() + data = response.read() + conn.close() + return data + +def checkForCompilerErrors(files): + params = urllib.urlencode([ + ('js_code', concatFiles(files)), + ('compilation_level', 'SIMPLE_OPTIMIZATIONS'), + ('language', 'ECMASCRIPT5_STRICT'), + ('output_format', 'text'), + ('output_info', 'errors'), + ]) + + return makeRequest(params) + +def compile(output, files): + params = urllib.urlencode([ + ('js_code', concatFiles(files)), + ('compilation_level', 'SIMPLE_OPTIMIZATIONS'), + ('language', 'ECMASCRIPT5_STRICT'), + ('output_format', 'text'), + ('output_info', 'compiled_code'), + ]) + + f = open(output, 'w') + f.write(makeRequest(params)) + f.close() + +targets = { + "PetAPI": ["API/Client/Tag.js", "API/Client/Category.js", "API/Client/Pet.js", "API/Client/PetApi.js"], + "StoreAPI": ["API/Client/Order.js", "API/Client/StoreApi.js"], + "UserAPI": ["API/Client/User.js", "API/Client/UserApi.js"], +} + +def main(): + for name, targetFiles in targets.iteritems(): + errors = checkForCompilerErrors(targetFiles) + if errors: + print "Compiler errors when building %s" % name + print errors + + for name, targetFiles in targets.iteritems(): + compile("%s.compiled.js" % name, targets[name]) + +if __name__ == "__main__": + sys.exit(main()) diff --git a/samples/client/petstore/javascript-closure-angular/karma.conf.js b/samples/client/petstore/javascript-closure-angular/karma.conf.js new file mode 100644 index 000000000000..b3994e2a3098 --- /dev/null +++ b/samples/client/petstore/javascript-closure-angular/karma.conf.js @@ -0,0 +1,78 @@ +// Karma configuration +// Generated on Tue Feb 02 2016 00:09:34 GMT-0700 (MST) + +module.exports = function(config) { + config.set({ + + // base path, that will be used to resolve files and exclude + basePath: '', + + + // frameworks to use + frameworks: ['jasmine', 'closure'], + + + // list of files / patterns to load in the browser + files: [ + 'node_modules/angular/angular.js', + 'node_modules/angular-mocks/angular-mocks.js', + {pattern: 'lib/**/*.js', included: true}, + {pattern: 'API/**/*.js', included: false}, + {pattern: 'test/**/*.js'}, + ], + + preprocessors: { + // tests are preprocessed for dependencies (closure) + 'test/**/*.js': ['closure', 'closure-iit'], + // source files are preprocessed for dependencies + 'API/**/*.js': ['closure'], + // external deps + 'lib/goog/deps.js': ['closure-deps'] + }, + + // list of files to exclude + exclude: [], + + + // test results reporter to use + // possible values: 'dots', 'progress', 'junit', 'growl', 'coverage' + reporters: ['dots'], + + + // web server port + port: 9876, + + + // enable / disable colors in the output (reporters and logs) + colors: true, + + + // level of logging + // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG + logLevel: config.LOG_INFO, + + + // enable / disable watching file and executing tests whenever any file changes + autoWatch: true, + + + // Start these browsers, currently available: + // - Chrome + // - ChromeCanary + // - Firefox + // - Opera (has to be installed with `npm install karma-opera-launcher`) + // - Safari (only Mac; has to be installed with `npm install karma-safari-launcher`) + // - PhantomJS + // - IE (only Windows; has to be installed with `npm install karma-ie-launcher`) + browsers: ['PhantomJS'], + + + // If browser does not capture in given timeout [ms], kill it + captureTimeout: 60000, + + + // Continuous Integration mode + // if true, it capture browsers, run tests and exit + singleRun: false + }); +}; diff --git a/samples/client/petstore/javascript-closure-angular/lib/goog/base.js b/samples/client/petstore/javascript-closure-angular/lib/goog/base.js new file mode 100644 index 000000000000..58674377024c --- /dev/null +++ b/samples/client/petstore/javascript-closure-angular/lib/goog/base.js @@ -0,0 +1,1548 @@ +// Copyright 2006 The Closure Library Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS-IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/** + * @fileoverview Bootstrap for the Google JS Library (Closure). + * + * In uncompiled mode base.js will write out Closure's deps file, unless the + * global CLOSURE_NO_DEPS is set to true. This allows projects to + * include their own deps file(s) from different locations. + * + * + * @provideGoog + */ + + +/** + * @define {boolean} Overridden to true by the compiler when --closure_pass + * or --mark_as_compiled is specified. + */ +var COMPILED = false; + + +/** + * Base namespace for the Closure library. Checks to see goog is + * already defined in the current scope before assigning to prevent + * clobbering if base.js is loaded more than once. + * + * @const + */ +var goog = goog || {}; // Identifies this file as the Closure base. + + +/** + * Reference to the global context. In most cases this will be 'window'. + */ +goog.global = this; + + +/** + * @define {boolean} DEBUG is provided as a convenience so that debugging code + * that should not be included in a production js_binary can be easily stripped + * by specifying --define goog.DEBUG=false to the JSCompiler. For example, most + * toString() methods should be declared inside an "if (goog.DEBUG)" conditional + * because they are generally used for debugging purposes and it is difficult + * for the JSCompiler to statically determine whether they are used. + */ +goog.DEBUG = true; + + +/** + * @define {string} LOCALE defines the locale being used for compilation. It is + * used to select locale specific data to be compiled in js binary. BUILD rule + * can specify this value by "--define goog.LOCALE=" as JSCompiler + * option. + * + * Take into account that the locale code format is important. You should use + * the canonical Unicode format with hyphen as a delimiter. Language must be + * lowercase, Language Script - Capitalized, Region - UPPERCASE. + * There are few examples: pt-BR, en, en-US, sr-Latin-BO, zh-Hans-CN. + * + * See more info about locale codes here: + * http://www.unicode.org/reports/tr35/#Unicode_Language_and_Locale_Identifiers + * + * For language codes you should use values defined by ISO 693-1. See it here + * http://www.w3.org/WAI/ER/IG/ert/iso639.htm. There is only one exception from + * this rule: the Hebrew language. For legacy reasons the old code (iw) should + * be used instead of the new code (he), see http://wiki/Main/IIISynonyms. + */ +goog.LOCALE = 'en'; // default to en + + +/** + * @define {boolean} Whether this code is running on trusted sites. + * + * On untrusted sites, several native functions can be defined or overridden by + * external libraries like Prototype, Datejs, and JQuery and setting this flag + * to false forces closure to use its own implementations when possible. + * + * If your javascript can be loaded by a third party site and you are wary about + * relying on non-standard implementations, specify + * "--define goog.TRUSTED_SITE=false" to the JSCompiler. + */ +goog.TRUSTED_SITE = true; + + +/** + * Creates object stubs for a namespace. The presence of one or more + * goog.provide() calls indicate that the file defines the given + * objects/namespaces. Build tools also scan for provide/require statements + * to discern dependencies, build dependency files (see deps.js), etc. + * @see goog.require + * @param {string} name Namespace provided by this file in the form + * "goog.package.part". + */ +goog.provide = function(name) { + if (!COMPILED) { + // Ensure that the same namespace isn't provided twice. This is intended + // to teach new developers that 'goog.provide' is effectively a variable + // declaration. And when JSCompiler transforms goog.provide into a real + // variable declaration, the compiled JS should work the same as the raw + // JS--even when the raw JS uses goog.provide incorrectly. + if (goog.isProvided_(name)) { + throw Error('Namespace "' + name + '" already declared.'); + } + delete goog.implicitNamespaces_[name]; + + var namespace = name; + while ((namespace = namespace.substring(0, namespace.lastIndexOf('.')))) { + if (goog.getObjectByName(namespace)) { + break; + } + goog.implicitNamespaces_[namespace] = true; + } + } + + goog.exportPath_(name); +}; + + +/** + * Marks that the current file should only be used for testing, and never for + * live code in production. + * @param {string=} opt_message Optional message to add to the error that's + * raised when used in production code. + */ +goog.setTestOnly = function(opt_message) { + if (COMPILED && !goog.DEBUG) { + opt_message = opt_message || ''; + throw Error('Importing test-only code into non-debug environment' + + opt_message ? ': ' + opt_message : '.'); + } +}; + + +if (!COMPILED) { + + /** + * Check if the given name has been goog.provided. This will return false for + * names that are available only as implicit namespaces. + * @param {string} name name of the object to look for. + * @return {boolean} Whether the name has been provided. + * @private + */ + goog.isProvided_ = function(name) { + return !goog.implicitNamespaces_[name] && !!goog.getObjectByName(name); + }; + + /** + * Namespaces implicitly defined by goog.provide. For example, + * goog.provide('goog.events.Event') implicitly declares + * that 'goog' and 'goog.events' must be namespaces. + * + * @type {Object} + * @private + */ + goog.implicitNamespaces_ = {}; +} + + +/** + * Builds an object structure for the provided namespace path, + * ensuring that names that already exist are not overwritten. For + * example: + * "a.b.c" -> a = {};a.b={};a.b.c={}; + * Used by goog.provide and goog.exportSymbol. + * @param {string} name name of the object that this file defines. + * @param {*=} opt_object the object to expose at the end of the path. + * @param {Object=} opt_objectToExportTo The object to add the path to; default + * is |goog.global|. + * @private + */ +goog.exportPath_ = function(name, opt_object, opt_objectToExportTo) { + var parts = name.split('.'); + var cur = opt_objectToExportTo || goog.global; + + // Internet Explorer exhibits strange behavior when throwing errors from + // methods externed in this manner. See the testExportSymbolExceptions in + // base_test.html for an example. + if (!(parts[0] in cur) && cur.execScript) { + cur.execScript('var ' + parts[0]); + } + + // Certain browsers cannot parse code in the form for((a in b); c;); + // This pattern is produced by the JSCompiler when it collapses the + // statement above into the conditional loop below. To prevent this from + // happening, use a for-loop and reserve the init logic as below. + + // Parentheses added to eliminate strict JS warning in Firefox. + for (var part; parts.length && (part = parts.shift());) { + if (!parts.length && goog.isDef(opt_object)) { + // last part and we have an object; use it + cur[part] = opt_object; + } else if (cur[part]) { + cur = cur[part]; + } else { + cur = cur[part] = {}; + } + } +}; + + +/** + * Returns an object based on its fully qualified external name. If you are + * using a compilation pass that renames property names beware that using this + * function will not find renamed properties. + * + * @param {string} name The fully qualified name. + * @param {Object=} opt_obj The object within which to look; default is + * |goog.global|. + * @return {?} The value (object or primitive) or, if not found, null. + */ +goog.getObjectByName = function(name, opt_obj) { + var parts = name.split('.'); + var cur = opt_obj || goog.global; + for (var part; part = parts.shift(); ) { + if (goog.isDefAndNotNull(cur[part])) { + cur = cur[part]; + } else { + return null; + } + } + return cur; +}; + + +/** + * Globalizes a whole namespace, such as goog or goog.lang. + * + * @param {Object} obj The namespace to globalize. + * @param {Object=} opt_global The object to add the properties to. + * @deprecated Properties may be explicitly exported to the global scope, but + * this should no longer be done in bulk. + */ +goog.globalize = function(obj, opt_global) { + var global = opt_global || goog.global; + for (var x in obj) { + global[x] = obj[x]; + } +}; + + +/** + * Adds a dependency from a file to the files it requires. + * @param {string} relPath The path to the js file. + * @param {Array} provides An array of strings with the names of the objects + * this file provides. + * @param {Array} requires An array of strings with the names of the objects + * this file requires. + */ +goog.addDependency = function(relPath, provides, requires) { + if (!COMPILED) { + var provide, require; + var path = relPath.replace(/\\/g, '/'); + var deps = goog.dependencies_; + for (var i = 0; provide = provides[i]; i++) { + deps.nameToPath[provide] = path; + if (!(path in deps.pathToNames)) { + deps.pathToNames[path] = {}; + } + deps.pathToNames[path][provide] = true; + } + for (var j = 0; require = requires[j]; j++) { + if (!(path in deps.requires)) { + deps.requires[path] = {}; + } + deps.requires[path][require] = true; + } + } +}; + + + + +// NOTE(nnaze): The debug DOM loader was included in base.js as an orignal +// way to do "debug-mode" development. The dependency system can sometimes +// be confusing, as can the debug DOM loader's asyncronous nature. +// +// With the DOM loader, a call to goog.require() is not blocking -- the +// script will not load until some point after the current script. If a +// namespace is needed at runtime, it needs to be defined in a previous +// script, or loaded via require() with its registered dependencies. +// User-defined namespaces may need their own deps file. See http://go/js_deps, +// http://go/genjsdeps, or, externally, DepsWriter. +// http://code.google.com/closure/library/docs/depswriter.html +// +// Because of legacy clients, the DOM loader can't be easily removed from +// base.js. Work is being done to make it disableable or replaceable for +// different environments (DOM-less JavaScript interpreters like Rhino or V8, +// for example). See bootstrap/ for more information. + + +/** + * @define {boolean} Whether to enable the debug loader. + * + * If enabled, a call to goog.require() will attempt to load the namespace by + * appending a script tag to the DOM (if the namespace has been registered). + * + * If disabled, goog.require() will simply assert that the namespace has been + * provided (and depend on the fact that some outside tool correctly ordered + * the script). + */ +goog.ENABLE_DEBUG_LOADER = true; + + +/** + * Implements a system for the dynamic resolution of dependencies + * that works in parallel with the BUILD system. Note that all calls + * to goog.require will be stripped by the JSCompiler when the + * --closure_pass option is used. + * @see goog.provide + * @param {string} name Namespace to include (as was given in goog.provide()) + * in the form "goog.package.part". + */ +goog.require = function(name) { + + // if the object already exists we do not need do do anything + // TODO(arv): If we start to support require based on file name this has + // to change + // TODO(arv): If we allow goog.foo.* this has to change + // TODO(arv): If we implement dynamic load after page load we should probably + // not remove this code for the compiled output + if (!COMPILED) { + if (goog.isProvided_(name)) { + return; + } + + if (goog.ENABLE_DEBUG_LOADER) { + var path = goog.getPathFromDeps_(name); + if (path) { + goog.included_[path] = true; + goog.writeScripts_(); + return; + } + } + + var errorMessage = 'goog.require could not find: ' + name; + if (goog.global.console) { + goog.global.console['error'](errorMessage); + } + + + throw Error(errorMessage); + + } +}; + + +/** + * Path for included scripts + * @type {string} + */ +goog.basePath = ''; + + +/** + * A hook for overriding the base path. + * @type {string|undefined} + */ +goog.global.CLOSURE_BASE_PATH; + + +/** + * Whether to write out Closure's deps file. By default, + * the deps are written. + * @type {boolean|undefined} + */ +goog.global.CLOSURE_NO_DEPS; + + +/** + * A function to import a single script. This is meant to be overridden when + * Closure is being run in non-HTML contexts, such as web workers. It's defined + * in the global scope so that it can be set before base.js is loaded, which + * allows deps.js to be imported properly. + * + * The function is passed the script source, which is a relative URI. It should + * return true if the script was imported, false otherwise. + */ +goog.global.CLOSURE_IMPORT_SCRIPT; + + +/** + * Null function used for default values of callbacks, etc. + * @return {void} Nothing. + */ +goog.nullFunction = function() {}; + + +/** + * The identity function. Returns its first argument. + * + * @param {*=} opt_returnValue The single value that will be returned. + * @param {...*} var_args Optional trailing arguments. These are ignored. + * @return {?} The first argument. We can't know the type -- just pass it along + * without type. + * @deprecated Use goog.functions.identity instead. + */ +goog.identityFunction = function(opt_returnValue, var_args) { + return opt_returnValue; +}; + + +/** + * When defining a class Foo with an abstract method bar(), you can do: + * + * Foo.prototype.bar = goog.abstractMethod + * + * Now if a subclass of Foo fails to override bar(), an error + * will be thrown when bar() is invoked. + * + * Note: This does not take the name of the function to override as + * an argument because that would make it more difficult to obfuscate + * our JavaScript code. + * + * @type {!Function} + * @throws {Error} when invoked to indicate the method should be + * overridden. + */ +goog.abstractMethod = function() { + throw Error('unimplemented abstract method'); +}; + + +/** + * Adds a {@code getInstance} static method that always return the same instance + * object. + * @param {!Function} ctor The constructor for the class to add the static + * method to. + */ +goog.addSingletonGetter = function(ctor) { + ctor.getInstance = function() { + if (ctor.instance_) { + return ctor.instance_; + } + if (goog.DEBUG) { + // NOTE: JSCompiler can't optimize away Array#push. + goog.instantiatedSingletons_[goog.instantiatedSingletons_.length] = ctor; + } + return ctor.instance_ = new ctor; + }; +}; + + +/** + * All singleton classes that have been instantiated, for testing. Don't read + * it directly, use the {@code goog.testing.singleton} module. The compiler + * removes this variable if unused. + * @type {!Array.} + * @private + */ +goog.instantiatedSingletons_ = []; + + +if (!COMPILED && goog.ENABLE_DEBUG_LOADER) { + /** + * Object used to keep track of urls that have already been added. This + * record allows the prevention of circular dependencies. + * @type {Object} + * @private + */ + goog.included_ = {}; + + + /** + * This object is used to keep track of dependencies and other data that is + * used for loading scripts + * @private + * @type {Object} + */ + goog.dependencies_ = { + pathToNames: {}, // 1 to many + nameToPath: {}, // 1 to 1 + requires: {}, // 1 to many + // used when resolving dependencies to prevent us from + // visiting the file twice + visited: {}, + written: {} // used to keep track of script files we have written + }; + + + /** + * Tries to detect whether is in the context of an HTML document. + * @return {boolean} True if it looks like HTML document. + * @private + */ + goog.inHtmlDocument_ = function() { + var doc = goog.global.document; + return typeof doc != 'undefined' && + 'write' in doc; // XULDocument misses write. + }; + + + /** + * Tries to detect the base path of the base.js script that bootstraps Closure + * @private + */ + goog.findBasePath_ = function() { + if (goog.global.CLOSURE_BASE_PATH) { + goog.basePath = goog.global.CLOSURE_BASE_PATH; + return; + } else if (!goog.inHtmlDocument_()) { + return; + } + var doc = goog.global.document; + var scripts = doc.getElementsByTagName('script'); + // Search backwards since the current script is in almost all cases the one + // that has base.js. + for (var i = scripts.length - 1; i >= 0; --i) { + var src = scripts[i].src; + var qmark = src.lastIndexOf('?'); + var l = qmark == -1 ? src.length : qmark; + if (src.substr(l - 7, 7) == 'base.js') { + goog.basePath = src.substr(0, l - 7); + return; + } + } + }; + + + /** + * Imports a script if, and only if, that script hasn't already been imported. + * (Must be called at execution time) + * @param {string} src Script source. + * @private + */ + goog.importScript_ = function(src) { + var importScript = goog.global.CLOSURE_IMPORT_SCRIPT || + goog.writeScriptTag_; + if (!goog.dependencies_.written[src] && importScript(src)) { + goog.dependencies_.written[src] = true; + } + }; + + + /** + * The default implementation of the import function. Writes a script tag to + * import the script. + * + * @param {string} src The script source. + * @return {boolean} True if the script was imported, false otherwise. + * @private + */ + goog.writeScriptTag_ = function(src) { + if (goog.inHtmlDocument_()) { + var doc = goog.global.document; + + // If the user tries to require a new symbol after document load, + // something has gone terribly wrong. Doing a document.write would + // wipe out the page. + if (doc.readyState == 'complete') { + // Certain test frameworks load base.js multiple times, which tries + // to write deps.js each time. If that happens, just fail silently. + // These frameworks wipe the page between each load of base.js, so this + // is OK. + var isDeps = /\bdeps.js$/.test(src); + if (isDeps) { + return false; + } else { + throw Error('Cannot write "' + src + '" after document load'); + } + } + + doc.write( + '