diff --git a/README.md b/README.md index 1417007641ee..8c3bad5a30ca 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ ## Overview This is the swagger codegen project, which allows generation of API client libraries (SDK generation), server stubs and documentation automatically given an [OpenAPI Spec](https://github.com/OAI/OpenAPI-Specification). Currently, the following languages/frameworks are supported: -- **API clients**: **ActionScript**, **Bash**, **C#** (.net 2.0, 4.0 or later), **C++** (cpprest, Qt5, Tizen), **Clojure**, **Dart**, **Elixir**, **Go**, **Groovy**, **Haskell**, **Java** (Jersey1.x, Jersey2.x, OkHttp, Retrofit1.x, Retrofit2.x, Feign), **Node.js** (ES5, ES6, AngularJS with Google Closure Compiler annotations) **Objective-C**, **Perl**, **PHP**, **Python**, **Ruby**, **Scala**, **Swift** (2.x, 3.x), **Typescript** (Angular1.x, Angular2.x, Fetch, Node) +- **API clients**: **ActionScript**, **Bash**, **C#** (.net 2.0, 4.0 or later), **C++** (cpprest, Qt5, Tizen), **Clojure**, **Dart**, **Elixir**, **Go**, **Groovy**, **Haskell**, **Java** (Jersey1.x, Jersey2.x, OkHttp, Retrofit1.x, Retrofit2.x, Feign), **Node.js** (ES5, ES6, AngularJS with Google Closure Compiler annotations) **Objective-C**, **Perl**, **PHP**, **Python**, **Ruby**, **Scala**, **Swift** (2.x, 3.x), **Typescript** (Angular1.x, Angular2.x, Fetch, jQuery, Node) - **Server stubs**: **C#** (ASP.NET Core, NancyFx), **Erlang**, **Go**, **Haskell**, **Java** (MSF4J, Spring, Undertow, JAX-RS: CDI, CXF, Inflector, RestEasy), **PHP** (Lumen, Slim, Silex, [Zend Expressive](https://github.com/zendframework/zend-expressive)), **Python** (Flask), **NodeJS**, **Ruby** (Sinatra, Rails5), **Scala** ([Finch](https://github.com/finagle/finch), Scalatra) - **API documentation generators**: **HTML**, **Confluence Wiki** - **Others**: **JMeter** @@ -889,6 +889,7 @@ Here are some companies/projects using Swagger Codegen in production. To add you - [Plexxi](http://www.plexxi.com) - [Pixoneye](http://www.pixoneye.com/) - [PostAffiliatePro](https://www.postaffiliatepro.com/) +- [PracticeBird](https://www.practicebird.com/) - [Prill Tecnologia](http://www.prill.com.br) - [QAdept](http://qadept.com/) - [QuantiModo](https://quantimo.do/) @@ -1001,6 +1002,7 @@ Here is a list of template creators: * TypeScript (Angular1): @mhardorf * TypeScript (Fetch): @leonyu * TypeScript (Angular2): @roni-frantchi + * TypeScript (jQuery): @bherila * Server Stubs * C# ASP.NET5: @jimschubert * C# NancyFX: @mstefaniuk diff --git a/bin/typescript-jquery-all.sh b/bin/typescript-jquery-all.sh new file mode 100755 index 000000000000..7203fa099a55 --- /dev/null +++ b/bin/typescript-jquery-all.sh @@ -0,0 +1,36 @@ +#!/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" + +echo "Typescript jquery Petstore API client (default setting)" +ags="$@ generate -i modules/swagger-codegen/src/test/resources/2_0/petstore.json -l typescript-jquery -o samples/client/petstore/typescript-jquery/default" +java $JAVA_OPTS -jar $executable $ags + +echo "Typescript jquery Petstore API client with npm setting" +ags="$@ generate -i modules/swagger-codegen/src/test/resources/2_0/petstore.json -l typescript-jquery -c bin/typescript-petstore-npm.json -o samples/client/petstore/typescript-jquery/npm" +java $JAVA_OPTS -jar $executable $ags diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/examples/ExampleGenerator.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/examples/ExampleGenerator.java index 08a04769e876..08d5065cfd63 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/examples/ExampleGenerator.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/examples/ExampleGenerator.java @@ -32,6 +32,7 @@ import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Random; import java.util.Set; public class ExampleGenerator { @@ -47,9 +48,12 @@ public class ExampleGenerator { private static final String NONE = "none"; protected Map examples; + private Random random; public ExampleGenerator(Map examples) { this.examples = examples; + // use a fixed seed to make the "random" numbers reproducible. + this.random = new Random("ExampleGenerator".hashCode()); } public List> generate(Map examples, List mediaTypes, Property property) { @@ -187,13 +191,13 @@ public class ExampleGenerator { private double randomNumber(Double min, Double max) { if (min != null && max != null) { double range = max - min; - return Math.random() * range + min; + return random.nextDouble() * range + min; } else if (min != null) { - return Math.random() + min; + return random.nextDouble() + min; } else if (max != null) { - return Math.random() * max; + return random.nextDouble() * max; } else { - return Math.random() * 10; + return random.nextDouble() * 10; } } diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/AsyncScalaClientCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/AsyncScalaClientCodegen.java index ea8ae3080816..e323a32b41f6 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/AsyncScalaClientCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/AsyncScalaClientCodegen.java @@ -60,7 +60,7 @@ public class AsyncScalaClientCodegen extends AbstractScalaCodegen implements Cod importMapping.remove("Map"); importMapping.put("DateTime", "org.joda.time.DateTime"); - importMapping.put("ListBuffer", "scala.collections.mutable.ListBuffer"); + importMapping.put("ListBuffer", "scala.collection.mutable.ListBuffer"); typeMapping = new HashMap(); typeMapping.put("enum", "NSString"); diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/ScalaClientCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/ScalaClientCodegen.java index ea4539133af4..2044b80fc802 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/ScalaClientCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/ScalaClientCodegen.java @@ -76,7 +76,7 @@ public class ScalaClientCodegen extends AbstractScalaCodegen implements CodegenC importMapping.remove("Map"); importMapping.put("DateTime", "org.joda.time.DateTime"); - importMapping.put("ListBuffer", "scala.collections.mutable.ListBuffer"); + importMapping.put("ListBuffer", "scala.collection.mutable.ListBuffer"); typeMapping = new HashMap(); typeMapping.put("enum", "NSString"); diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/TypeScriptJqueryClientCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/TypeScriptJqueryClientCodegen.java new file mode 100644 index 000000000000..eb3193447815 --- /dev/null +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/TypeScriptJqueryClientCodegen.java @@ -0,0 +1,110 @@ +package io.swagger.codegen.languages; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.File; +import java.text.SimpleDateFormat; +import java.util.Date; + +import io.swagger.codegen.CliOption; +import io.swagger.codegen.SupportingFile; +import io.swagger.models.properties.BooleanProperty; + +public class TypeScriptJqueryClientCodegen extends AbstractTypeScriptClientCodegen { + private static final Logger LOGGER = LoggerFactory.getLogger(TypeScriptNodeClientCodegen.class); + private static final SimpleDateFormat SNAPSHOT_SUFFIX_FORMAT = new SimpleDateFormat("yyyyMMddHHmm"); + + public static final String NPM_NAME = "npmName"; + public static final String NPM_VERSION = "npmVersion"; + public static final String NPM_REPOSITORY = "npmRepository"; + public static final String SNAPSHOT = "snapshot"; + + protected String npmName = null; + protected String npmVersion = "1.0.0"; + protected String npmRepository = null; + + public TypeScriptJqueryClientCodegen() { + super(); + outputFolder = "generated-code/typescript-jquery"; + embeddedTemplateDir = templateDir = "typescript-jquery"; + + this.cliOptions.add(new CliOption(NPM_NAME, "The name under which you want to publish generated npm package")); + this.cliOptions.add(new CliOption(NPM_VERSION, "The version of your npm package")); + this.cliOptions.add(new CliOption(NPM_REPOSITORY, "Use this property to set an url your private npmRepo in the package.json")); + this.cliOptions.add(new CliOption(SNAPSHOT, "When setting this property to true the version will be suffixed with -SNAPSHOT.yyyyMMddHHmm", BooleanProperty.TYPE).defaultValue(Boolean.FALSE.toString())); + } + + + @Override + public void processOpts() { + super.processOpts(); + supportingFiles.add(new SupportingFile("api.mustache", null, "api.ts")); + supportingFiles.add(new SupportingFile("git_push.sh.mustache", "", "git_push.sh")); + + LOGGER.warn("check additionals: " + additionalProperties.get(NPM_NAME)); + if(additionalProperties.containsKey(NPM_NAME)) { + addNpmPackageGeneration(); + } + } + + private void addNpmPackageGeneration() { + if(additionalProperties.containsKey(NPM_NAME)) { + this.setNpmName(additionalProperties.get(NPM_NAME).toString()); + } + + if (additionalProperties.containsKey(NPM_VERSION)) { + this.setNpmVersion(additionalProperties.get(NPM_VERSION).toString()); + } + + if (additionalProperties.containsKey(SNAPSHOT) && Boolean.valueOf(additionalProperties.get(SNAPSHOT).toString())) { + this.setNpmVersion(npmVersion + "-SNAPSHOT." + SNAPSHOT_SUFFIX_FORMAT.format(new Date())); + } + additionalProperties.put(NPM_VERSION, npmVersion); + + if (additionalProperties.containsKey(NPM_REPOSITORY)) { + this.setNpmRepository(additionalProperties.get(NPM_REPOSITORY).toString()); + } + + //Files for building our lib + supportingFiles.add(new SupportingFile("package.mustache", getPackageRootDirectory(), "package.json")); + supportingFiles.add(new SupportingFile("typings.mustache", getPackageRootDirectory(), "typings.json")); + supportingFiles.add(new SupportingFile("tsconfig.mustache", getPackageRootDirectory(), "tsconfig.json")); + } + + private String getPackageRootDirectory() { + String indexPackage = modelPackage.substring(0, Math.max(0, modelPackage.lastIndexOf('.'))); + return indexPackage.replace('.', File.separatorChar); + } + + @Override + public String getName() { + return "typescript-jquery"; + } + + @Override + public String getHelp() { + return "Generates a TypeScript jquery client library."; + } + + + public void setNpmName(String npmName) { + this.npmName = npmName; + } + + public void setNpmVersion(String npmVersion) { + this.npmVersion = npmVersion; + } + + public String getNpmVersion() { + return npmVersion; + } + + public String getNpmRepository() { + return npmRepository; + } + + public void setNpmRepository(String npmRepository) { + this.npmRepository = npmRepository; + } +} 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 91d363e09653..ed87bdf2998d 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 @@ -52,6 +52,7 @@ io.swagger.codegen.languages.Swift3Codegen io.swagger.codegen.languages.TizenClientCodegen io.swagger.codegen.languages.TypeScriptAngular2ClientCodegen io.swagger.codegen.languages.TypeScriptAngularClientCodegen +io.swagger.codegen.languages.TypeScriptJqueryClientCodegen io.swagger.codegen.languages.TypeScriptNodeClientCodegen io.swagger.codegen.languages.TypeScriptFetchClientCodegen io.swagger.codegen.languages.AkkaScalaClientCodegen diff --git a/modules/swagger-codegen/src/main/resources/akka-scala/model.mustache b/modules/swagger-codegen/src/main/resources/akka-scala/model.mustache index 7743c15718d5..e5117e3a9cb0 100644 --- a/modules/swagger-codegen/src/main/resources/akka-scala/model.mustache +++ b/modules/swagger-codegen/src/main/resources/akka-scala/model.mustache @@ -8,6 +8,7 @@ package {{package}} import {{invokerPackage}}.ApiModel import org.joda.time.DateTime +import java.util.UUID {{#models}} {{#model}} diff --git a/modules/swagger-codegen/src/main/resources/typescript-jquery/api.mustache b/modules/swagger-codegen/src/main/resources/typescript-jquery/api.mustache new file mode 100644 index 000000000000..9649528630ba --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/typescript-jquery/api.mustache @@ -0,0 +1,269 @@ +import * as $ from 'jquery'; + +let defaultBasePath = '{{basePath}}'; + +// =============================================== +// This file is autogenerated - Please do not edit +// =============================================== + +/* tslint:disable:no-unused-variable */ + +{{#models}} +{{#model}} +{{#description}} + /** + * {{{description}}} + */ +{{/description}} +export class {{classname}} {{#parent}}extends {{{parent}}} {{/parent}}{ +{{#vars}} + {{#description}} + /** + * {{{description}}} + */ + {{/description}} + '{{name}}': {{#isEnum}}{{{datatypeWithEnum}}}{{/isEnum}}{{^isEnum}}{{{datatype}}}{{/isEnum}}; +{{/vars}} +} + +{{#hasEnums}} +export namespace {{classname}} { +{{#vars}} +{{#isEnum}} + export enum {{enumName}} { + {{#allowableValues}} + {{#enumVars}} + {{name}} = {{{value}}}{{^-last}},{{/-last}} + {{/enumVars}} + {{/allowableValues}} + } +{{/isEnum}} +{{/vars}} +} +{{/hasEnums}} +{{/model}} +{{/models}} + +export interface Authentication { + /** + * Apply authentication settings to header and query params. + */ + applyToRequest(requestOptions: JQueryAjaxSettings): void; +} + +export class HttpBasicAuth implements Authentication { + public username: string; + public password: string; + applyToRequest(requestOptions: any): void { + requestOptions.username = this.username; + requestOptions.password = this.password; + } +} + +export class ApiKeyAuth implements Authentication { + public apiKey: string; + + constructor(private location: string, private paramName: string) { + } + + applyToRequest(requestOptions: JQueryAjaxSettings): void { + requestOptions.headers[this.paramName] = this.apiKey; + } +} + +export class OAuth implements Authentication { + public accessToken: string; + + applyToRequest(requestOptions: JQueryAjaxSettings): void { + requestOptions.headers["Authorization"] = "Bearer " + this.accessToken; + } +} + +export class VoidAuth implements Authentication { + public username: string; + public password: string; + applyToRequest(requestOptions: JQueryAjaxSettings): void { + // Do nothing + } +} + +{{#apiInfo}} +{{#apis}} +{{#operations}} +{{#description}} +/** +* {{&description}} +*/ +{{/description}} +export enum {{classname}}ApiKeys { +{{#authMethods}} +{{#isApiKey}} + {{name}}, +{{/isApiKey}} +{{/authMethods}} +} + +export class {{classname}} { + protected basePath = defaultBasePath; + protected defaultHeaders : any = {}; + + protected authentications = { + 'default': new VoidAuth(), +{{#authMethods}} +{{#isBasic}} + '{{name}}': new HttpBasicAuth(), +{{/isBasic}} +{{#isApiKey}} + '{{name}}': new ApiKeyAuth({{#isKeyInHeader}}'header'{{/isKeyInHeader}}{{^isKeyInHeader}}'query'{{/isKeyInHeader}}, '{{keyParamName}}'), +{{/isApiKey}} +{{#isOAuth}} + '{{name}}': new OAuth(), +{{/isOAuth}} +{{/authMethods}} + } + + constructor(basePath?: string); +{{#authMethods}} +{{#isBasic}} + constructor(username: string, password: string, basePath?: string); +{{/isBasic}} +{{/authMethods}} + constructor(basePathOrUsername: string, password?: string, basePath?: string) { + if (password) { +{{#authMethods}} +{{#isBasic}} + this.username = basePathOrUsername; + this.password = password +{{/isBasic}} +{{/authMethods}} + if (basePath) { + this.basePath = basePath; + } + } else { + if (basePathOrUsername) { + this.basePath = basePathOrUsername + } + } + } + + public setApiKey(key: {{classname}}ApiKeys, value: string) { + this.authentications[{{classname}}ApiKeys[key]].apiKey = value; + } +{{#authMethods}} +{{#isBasic}} + + set username(username: string) { + this.authentications.{{name}}.username = username; + } + + set password(password: string) { + this.authentications.{{name}}.password = password; + } +{{/isBasic}} +{{#isOAuth}} + + set accessToken(token: string) { + this.authentications.{{name}}.accessToken = token; + } +{{/isOAuth}} +{{/authMethods}} + private extendObj(objA: T2, objB: T2): T1|T2 { + for(let key in objB){ + if(objB.hasOwnProperty(key)){ + objA[key] = objB[key]; + } + } + return objA; + } + +{{#operation}} + /** + * {{summary}} + * {{notes}} + {{#allParams}}* @param {{paramName}} {{description}} + {{/allParams}}*/ + public {{nickname}} ({{#allParams}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) : JQueryPromise<{ response: JQueryXHR; {{#returnType}}body: {{{returnType}}}; {{/returnType}}{{^returnType}}body?: any; {{/returnType}} }> { + let localVarPath = this.basePath + '{{path}}'{{#pathParams}} + .replace('{' + '{{baseName}}' + '}', String({{paramName}})){{/pathParams}}; + let queryParameters: any = {}; + let headerParams: any = this.extendObj({}, this.defaultHeaders); + +{{#allParams}}{{#required}} + // verify required parameter '{{paramName}}' is not null or undefined + if ({{paramName}} === null || {{paramName}} === undefined) { + throw new Error('Required parameter {{paramName}} was null or undefined when calling {{nickname}}.'); + } +{{/required}}{{/allParams}} +{{#queryParams}} + if ({{paramName}} !== undefined) { + queryParameters['{{baseName}}'] = {{paramName}}; + } + +{{/queryParams}} + + localVarPath = localVarPath + "?" + $.param(queryParameters); + +{{#headerParams}} + headerParams['{{baseName}}'] = {{paramName}}; + +{{/headerParams}} + +{{^bodyParam}} + let reqHasFile = false; + let reqDict = {}; + let reqFormData = new FormData(); +{{#formParams}} +{{#isFile}} + reqHasFile = true; +{{/isFile}} + if ({{paramName}} !== undefined) { + reqFormData.append('{{baseName}}', {{paramName}}); + reqDict['{{baseName}}'] = {{paramName}}; + } + +{{/formParams}} +{{/bodyParam}} +{{#bodyParam}} + let reqDict = {{paramName}}; + let reqFormData = new FormData(); + reqFormData.append('{{paramName}}', {{paramName}}); +{{#isFile}} + let reqHasFile = true; +{{/isFile}} +{{^isFile}} + let reqHasFile = false; +{{/isFile}} +{{/bodyParam}} + + let requestOptions: JQueryAjaxSettings = { + url: localVarPath, + type: '{{httpMethod}}', + headers: headerParams, + processData: false + }; + + if (Object.keys(reqDict).length) { + requestOptions.data = reqHasFile ? reqFormData : JSON.stringify(reqDict); + requestOptions.contentType = reqHasFile ? false : 'application/json; charset=utf-8'; + } + +{{#authMethods}} + this.authentications.{{name}}.applyToRequest(requestOptions); + +{{/authMethods}} + this.authentications.default.applyToRequest(requestOptions); + + let dfd = $.Deferred(); + $.ajax(requestOptions).then( + (data: {{{returnType}}}, textStatus: string, jqXHR: JQueryXHR) => + dfd.resolve({ response: jqXHR, body: data }), + (xhr: JQueryXHR, textStatus: string, errorThrown: string) => + dfd.reject({ response: xhr, body: errorThrown }) + ); + return dfd.promise(); + } +{{/operation}} +} +{{/operations}} +{{/apis}} +{{/apiInfo}} diff --git a/modules/swagger-codegen/src/main/resources/typescript-jquery/git_push.sh.mustache b/modules/swagger-codegen/src/main/resources/typescript-jquery/git_push.sh.mustache new file mode 100755 index 000000000000..e153ce23ecf4 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/typescript-jquery/git_push.sh.mustache @@ -0,0 +1,52 @@ +#!/bin/sh +# ref: https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/ +# +# Usage example: /bin/sh ./git_push.sh wing328 swagger-petstore-perl "minor update" + +git_user_id=$1 +git_repo_id=$2 +release_note=$3 + +if [ "$git_user_id" = "" ]; then + git_user_id="{{{gitUserId}}}" + echo "[INFO] No command line input provided. Set \$git_user_id to $git_user_id" +fi + +if [ "$git_repo_id" = "" ]; then + git_repo_id="{{{gitRepoId}}}" + echo "[INFO] No command line input provided. Set \$git_repo_id to $git_repo_id" +fi + +if [ "$release_note" = "" ]; then + release_note="{{{releaseNote}}}" + echo "[INFO] No command line input provided. Set \$release_note to $release_note" +fi + +# Initialize the local directory as a Git repository +git init + +# Adds the files in the local repository and stages them for commit. +git add . + +# Commits the tracked changes and prepares them to be pushed to a remote repository. +git commit -m "$release_note" + +# Sets the new remote +git_remote=`git remote` +if [ "$git_remote" = "" ]; then # git remote not defined + + if [ "$GIT_TOKEN" = "" ]; then + echo "[INFO] \$GIT_TOKEN (environment variable) is not set. Using the git crediential in your environment." + git remote add origin https://github.com/${git_user_id}/${git_repo_id}.git + else + git remote add origin https://${git_user_id}:${GIT_TOKEN}@github.com/${git_user_id}/${git_repo_id}.git + fi + +fi + +git pull origin master + +# Pushes (Forces) the changes in the local repository up to the remote repository +echo "Git pushing to https://github.com/${git_user_id}/${git_repo_id}.git" +git push origin master 2>&1 | grep -v 'To https' + diff --git a/modules/swagger-codegen/src/main/resources/typescript-jquery/package.mustache b/modules/swagger-codegen/src/main/resources/typescript-jquery/package.mustache new file mode 100644 index 000000000000..732777196fc2 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/typescript-jquery/package.mustache @@ -0,0 +1,22 @@ +{ + "name": "{{npmName}}", + "version": "{{npmVersion}}", + "description": "JQuery client for {{npmName}}", + "main": "api.js", + "scripts": { + "build": "tsc" + }, + "author": "Swagger Codegen Contributors", + "license": "MIT", + "dependencies": { + "bluebird": "^3.3.5", + "request": "^2.72.0" + }, + "devDependencies": { + "typescript": "^1.8.10", + "typings": "^0.8.1" + }{{#npmRepository}}, + "publishConfig":{ + "registry":"{{npmRepository}}" + }{{/npmRepository}} +} diff --git a/modules/swagger-codegen/src/main/resources/typescript-jquery/tsconfig.mustache b/modules/swagger-codegen/src/main/resources/typescript-jquery/tsconfig.mustache new file mode 100644 index 000000000000..1a3bd00183a3 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/typescript-jquery/tsconfig.mustache @@ -0,0 +1,18 @@ +{ + "compilerOptions": { + "module": "commonjs", + "noImplicitAny": false, + "suppressImplicitAnyIndexErrors": true, + "target": "{{#supportsES6}}ES6{{/supportsES6}}{{^supportsES6}}ES5{{/supportsES6}}", + "moduleResolution": "node", + "removeComments": true, + "sourceMap": true, + "noLib": false, + "declaration": true + }, + "files": [ + "api.ts", + "typings/main.d.ts" + ] +} + diff --git a/modules/swagger-codegen/src/main/resources/typescript-jquery/typings.mustache b/modules/swagger-codegen/src/main/resources/typescript-jquery/typings.mustache new file mode 100644 index 000000000000..76c4cc8e6af3 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/typescript-jquery/typings.mustache @@ -0,0 +1,10 @@ +{ + "ambientDependencies": { + "bluebird": "registry:dt/bluebird#2.0.0+20160319051630", + "core-js": "registry:dt/core-js#0.0.0+20160317120654", + "node": "registry:dt/node#4.0.0+20160423143914" + }, + "dependencies": { + "request": "registry:npm/request#2.69.0+20160304121250" + } +} \ No newline at end of file diff --git a/pom.xml b/pom.xml index efc5df165c6c..3002b627c293 100644 --- a/pom.xml +++ b/pom.xml @@ -758,6 +758,7 @@ + samples/client/petstore/akka-scala samples/client/petstore/ruby samples/client/petstore/android/volley samples/client/petstore/bash @@ -779,6 +780,7 @@ samples/client/petstore/typescript-fetch/tests/default samples/client/petstore/typescript-angular samples/client/petstore/typescript-node/npm + samples/client/petstore/typescript-jquery/npm samples/server/petstore/java-inflector samples/server/petstore/undertow diff --git a/samples/client/petstore/akka-scala/pom.xml b/samples/client/petstore/akka-scala/pom.xml index af37db6dbabe..d37f26cfb4cd 100644 --- a/samples/client/petstore/akka-scala/pom.xml +++ b/samples/client/petstore/akka-scala/pom.xml @@ -2,9 +2,9 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> 4.0.0 io.swagger - swagger-client + scala-akka-petstore-client jar - swagger-client + scala-akka-petstore-client 1.0.0 2.2.0 @@ -217,7 +217,7 @@ 2.3.9 1.2 2.2 - 1.5.9 + 1.5.12 1.0.0 4.8.1 diff --git a/samples/client/petstore/akka-scala/src/main/scala/io/swagger/client/api/UserApi.scala b/samples/client/petstore/akka-scala/src/main/scala/io/swagger/client/api/UserApi.scala index 642c76b8d8c0..4b8b8c3631e4 100644 --- a/samples/client/petstore/akka-scala/src/main/scala/io/swagger/client/api/UserApi.scala +++ b/samples/client/petstore/akka-scala/src/main/scala/io/swagger/client/api/UserApi.scala @@ -23,7 +23,7 @@ object UserApi { def createUser(body: User): ApiRequest[Unit] = ApiRequest[Unit](ApiMethods.POST, "http://petstore.swagger.io/v2", "/user", "application/json") .withBody(body) - .withDefaultSuccessResponse[Unit] + .withSuccessResponse[Unit](0) /** * * Expected answers: @@ -34,7 +34,7 @@ object UserApi { def createUsersWithArrayInput(body: Seq[User]): ApiRequest[Unit] = ApiRequest[Unit](ApiMethods.POST, "http://petstore.swagger.io/v2", "/user/createWithArray", "application/json") .withBody(body) - .withDefaultSuccessResponse[Unit] + .withSuccessResponse[Unit](0) /** * * Expected answers: @@ -45,7 +45,7 @@ object UserApi { def createUsersWithListInput(body: Seq[User]): ApiRequest[Unit] = ApiRequest[Unit](ApiMethods.POST, "http://petstore.swagger.io/v2", "/user/createWithList", "application/json") .withBody(body) - .withDefaultSuccessResponse[Unit] + .withSuccessResponse[Unit](0) /** * This can only be done by the logged in user. * @@ -105,7 +105,7 @@ object UserApi { */ def logoutUser(): ApiRequest[Unit] = ApiRequest[Unit](ApiMethods.GET, "http://petstore.swagger.io/v2", "/user/logout", "application/json") - .withDefaultSuccessResponse[Unit] + .withSuccessResponse[Unit](0) /** * This can only be done by the logged in user. * diff --git a/samples/client/petstore/akka-scala/src/main/scala/io/swagger/client/model/ApiResponse.scala b/samples/client/petstore/akka-scala/src/main/scala/io/swagger/client/model/ApiResponse.scala index 0b996a89cc58..4357803cae8b 100644 --- a/samples/client/petstore/akka-scala/src/main/scala/io/swagger/client/model/ApiResponse.scala +++ b/samples/client/petstore/akka-scala/src/main/scala/io/swagger/client/model/ApiResponse.scala @@ -8,6 +8,7 @@ package io.swagger.client.model import io.swagger.client.core.ApiModel import org.joda.time.DateTime +import java.util.UUID case class ApiResponse ( code: Option[Int], diff --git a/samples/client/petstore/akka-scala/src/main/scala/io/swagger/client/model/Category.scala b/samples/client/petstore/akka-scala/src/main/scala/io/swagger/client/model/Category.scala index 48af020f18d7..4cf271ca1dd6 100644 --- a/samples/client/petstore/akka-scala/src/main/scala/io/swagger/client/model/Category.scala +++ b/samples/client/petstore/akka-scala/src/main/scala/io/swagger/client/model/Category.scala @@ -8,6 +8,7 @@ package io.swagger.client.model import io.swagger.client.core.ApiModel import org.joda.time.DateTime +import java.util.UUID case class Category ( id: Option[Long], diff --git a/samples/client/petstore/akka-scala/src/main/scala/io/swagger/client/model/Order.scala b/samples/client/petstore/akka-scala/src/main/scala/io/swagger/client/model/Order.scala index 3c2d7a255e26..0c5ce261e04d 100644 --- a/samples/client/petstore/akka-scala/src/main/scala/io/swagger/client/model/Order.scala +++ b/samples/client/petstore/akka-scala/src/main/scala/io/swagger/client/model/Order.scala @@ -8,6 +8,7 @@ package io.swagger.client.model import io.swagger.client.core.ApiModel import org.joda.time.DateTime +import java.util.UUID case class Order ( id: Option[Long], diff --git a/samples/client/petstore/akka-scala/src/main/scala/io/swagger/client/model/Pet.scala b/samples/client/petstore/akka-scala/src/main/scala/io/swagger/client/model/Pet.scala index 2adadb61eaad..c7be875c9b44 100644 --- a/samples/client/petstore/akka-scala/src/main/scala/io/swagger/client/model/Pet.scala +++ b/samples/client/petstore/akka-scala/src/main/scala/io/swagger/client/model/Pet.scala @@ -8,6 +8,7 @@ package io.swagger.client.model import io.swagger.client.core.ApiModel import org.joda.time.DateTime +import java.util.UUID case class Pet ( id: Option[Long], diff --git a/samples/client/petstore/akka-scala/src/main/scala/io/swagger/client/model/Tag.scala b/samples/client/petstore/akka-scala/src/main/scala/io/swagger/client/model/Tag.scala index 6658e733b4e0..99718dd74444 100644 --- a/samples/client/petstore/akka-scala/src/main/scala/io/swagger/client/model/Tag.scala +++ b/samples/client/petstore/akka-scala/src/main/scala/io/swagger/client/model/Tag.scala @@ -8,6 +8,7 @@ package io.swagger.client.model import io.swagger.client.core.ApiModel import org.joda.time.DateTime +import java.util.UUID case class Tag ( id: Option[Long], diff --git a/samples/client/petstore/akka-scala/src/main/scala/io/swagger/client/model/User.scala b/samples/client/petstore/akka-scala/src/main/scala/io/swagger/client/model/User.scala index 6db0c80fc331..11b66fc5c007 100644 --- a/samples/client/petstore/akka-scala/src/main/scala/io/swagger/client/model/User.scala +++ b/samples/client/petstore/akka-scala/src/main/scala/io/swagger/client/model/User.scala @@ -8,6 +8,7 @@ package io.swagger.client.model import io.swagger.client.core.ApiModel import org.joda.time.DateTime +import java.util.UUID case class User ( id: Option[Long], diff --git a/samples/client/petstore/typescript-jquery/default/.swagger-codegen-ignore b/samples/client/petstore/typescript-jquery/default/.swagger-codegen-ignore new file mode 100644 index 000000000000..c5fa491b4c55 --- /dev/null +++ b/samples/client/petstore/typescript-jquery/default/.swagger-codegen-ignore @@ -0,0 +1,23 @@ +# Swagger Codegen Ignore +# Generated by swagger-codegen https://github.com/swagger-api/swagger-codegen + +# Use this file to prevent files from being overwritten by the generator. +# The patterns follow closely to .gitignore or .dockerignore. + +# As an example, the C# client generator defines ApiClient.cs. +# You can make changes and tell Swagger Codgen to ignore just this file by uncommenting the following line: +#ApiClient.cs + +# You can match any string of characters against a directory, file or extension with a single asterisk (*): +#foo/*/qux +# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux + +# You can recursively match patterns against a directory, file or extension with a double asterisk (**): +#foo/**/qux +# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux + +# You can also negate patterns with an exclamation (!). +# For example, you can ignore all files in a docs folder with the file extension .md: +#docs/*.md +# Then explicitly reverse the ignore rule for a single file: +#!docs/README.md diff --git a/samples/client/petstore/typescript-jquery/default/api.ts b/samples/client/petstore/typescript-jquery/default/api.ts new file mode 100644 index 000000000000..9491259901e3 --- /dev/null +++ b/samples/client/petstore/typescript-jquery/default/api.ts @@ -0,0 +1,1213 @@ +import * as $ from 'jquery'; + +let defaultBasePath = 'http://petstore.swagger.io/v2'; + +// =============================================== +// This file is autogenerated - Please do not edit +// =============================================== + +/* tslint:disable:no-unused-variable */ + +export class Category { + 'id': number; + 'name': string; +} + +export class Order { + 'id': number; + 'petId': number; + 'quantity': number; + 'shipDate': Date; + /** + * Order Status + */ + 'status': Order.StatusEnum; + 'complete': boolean; +} + +export namespace Order { + export enum StatusEnum { + Placed = 'placed', + Approved = 'approved', + Delivered = 'delivered' + } +} +export class Pet { + 'id': number; + 'category': Category; + 'name': string; + 'photoUrls': Array; + 'tags': Array; + /** + * pet status in the store + */ + 'status': Pet.StatusEnum; +} + +export namespace Pet { + export enum StatusEnum { + Available = 'available', + Pending = 'pending', + Sold = 'sold' + } +} +export class Tag { + 'id': number; + 'name': string; +} + +export class User { + 'id': number; + 'username': string; + 'firstName': string; + 'lastName': string; + 'email': string; + 'password': string; + 'phone': string; + /** + * User Status + */ + 'userStatus': number; +} + + +export interface Authentication { + /** + * Apply authentication settings to header and query params. + */ + applyToRequest(requestOptions: JQueryAjaxSettings): void; +} + +export class HttpBasicAuth implements Authentication { + public username: string; + public password: string; + applyToRequest(requestOptions: any): void { + requestOptions.username = this.username; + requestOptions.password = this.password; + } +} + +export class ApiKeyAuth implements Authentication { + public apiKey: string; + + constructor(private location: string, private paramName: string) { + } + + applyToRequest(requestOptions: JQueryAjaxSettings): void { + requestOptions.headers[this.paramName] = this.apiKey; + } +} + +export class OAuth implements Authentication { + public accessToken: string; + + applyToRequest(requestOptions: JQueryAjaxSettings): void { + requestOptions.headers["Authorization"] = "Bearer " + this.accessToken; + } +} + +export class VoidAuth implements Authentication { + public username: string; + public password: string; + applyToRequest(requestOptions: JQueryAjaxSettings): void { + // Do nothing + } +} + +export enum PetApiApiKeys { + api_key, +} + +export class PetApi { + protected basePath = defaultBasePath; + protected defaultHeaders : any = {}; + + protected authentications = { + 'default': new VoidAuth(), + 'api_key': new ApiKeyAuth('header', 'api_key'), + 'petstore_auth': new OAuth(), + } + + constructor(basePath?: string); + constructor(basePathOrUsername: string, password?: string, basePath?: string) { + if (password) { + if (basePath) { + this.basePath = basePath; + } + } else { + if (basePathOrUsername) { + this.basePath = basePathOrUsername + } + } + } + + public setApiKey(key: PetApiApiKeys, value: string) { + this.authentications[PetApiApiKeys[key]].apiKey = value; + } + + set accessToken(token: string) { + this.authentications.petstore_auth.accessToken = token; + } + private extendObj(objA: T2, objB: T2): T1|T2 { + for(let key in objB){ + if(objB.hasOwnProperty(key)){ + objA[key] = objB[key]; + } + } + return objA; + } + + /** + * Add a new pet to the store + * + * @param body Pet object that needs to be added to the store + */ + public addPet (body?: Pet) : JQueryPromise<{ response: JQueryXHR; body?: any; }> { + let localVarPath = this.basePath + '/pet'; + let queryParameters: any = {}; + let headerParams: any = this.extendObj({}, this.defaultHeaders); + + + + localVarPath = localVarPath + "?" + $.param(queryParameters); + + + let reqDict = body; + let reqFormData = new FormData(); + reqFormData.append('body', body); + let reqHasFile = false; + + let requestOptions: JQueryAjaxSettings = { + url: localVarPath, + type: 'POST', + headers: headerParams, + processData: false + }; + + if (Object.keys(reqDict).length) { + requestOptions.data = reqHasFile ? reqFormData : JSON.stringify(reqDict); + requestOptions.contentType = reqHasFile ? false : 'application/json; charset=utf-8'; + } + + this.authentications.petstore_auth.applyToRequest(requestOptions); + + this.authentications.default.applyToRequest(requestOptions); + + let dfd = $.Deferred(); + $.ajax(requestOptions).then( + (data: , textStatus: string, jqXHR: JQueryXHR) => + dfd.resolve({ response: jqXHR, body: data }), + (xhr: JQueryXHR, textStatus: string, errorThrown: string) => + dfd.reject({ response: xhr, body: errorThrown }) + ); + return dfd.promise(); + } + /** + * Deletes a pet + * + * @param petId Pet id to delete + * @param apiKey + */ + public deletePet (petId: number, apiKey?: string) : JQueryPromise<{ response: JQueryXHR; body?: any; }> { + let localVarPath = this.basePath + '/pet/{petId}' + .replace('{' + 'petId' + '}', String(petId)); + let queryParameters: any = {}; + let headerParams: any = this.extendObj({}, this.defaultHeaders); + + + // verify required parameter 'petId' is not null or undefined + if (petId === null || petId === undefined) { + throw new Error('Required parameter petId was null or undefined when calling deletePet.'); + } + + + localVarPath = localVarPath + "?" + $.param(queryParameters); + + headerParams['api_key'] = apiKey; + + + let reqHasFile = false; + let reqDict = {}; + let reqFormData = new FormData(); + + let requestOptions: JQueryAjaxSettings = { + url: localVarPath, + type: 'DELETE', + headers: headerParams, + processData: false + }; + + if (Object.keys(reqDict).length) { + requestOptions.data = reqHasFile ? reqFormData : JSON.stringify(reqDict); + requestOptions.contentType = reqHasFile ? false : 'application/json; charset=utf-8'; + } + + this.authentications.petstore_auth.applyToRequest(requestOptions); + + this.authentications.default.applyToRequest(requestOptions); + + let dfd = $.Deferred(); + $.ajax(requestOptions).then( + (data: , textStatus: string, jqXHR: JQueryXHR) => + dfd.resolve({ response: jqXHR, body: data }), + (xhr: JQueryXHR, textStatus: string, errorThrown: string) => + dfd.reject({ response: xhr, body: errorThrown }) + ); + return dfd.promise(); + } + /** + * Finds Pets by status + * Multiple status values can be provided with comma separated strings + * @param status Status values that need to be considered for filter + */ + public findPetsByStatus (status?: Array) : JQueryPromise<{ response: JQueryXHR; body: Array; }> { + let localVarPath = this.basePath + '/pet/findByStatus'; + let queryParameters: any = {}; + let headerParams: any = this.extendObj({}, this.defaultHeaders); + + + if (status !== undefined) { + queryParameters['status'] = status; + } + + + localVarPath = localVarPath + "?" + $.param(queryParameters); + + + let reqHasFile = false; + let reqDict = {}; + let reqFormData = new FormData(); + + let requestOptions: JQueryAjaxSettings = { + url: localVarPath, + type: 'GET', + headers: headerParams, + processData: false + }; + + if (Object.keys(reqDict).length) { + requestOptions.data = reqHasFile ? reqFormData : JSON.stringify(reqDict); + requestOptions.contentType = reqHasFile ? false : 'application/json; charset=utf-8'; + } + + this.authentications.petstore_auth.applyToRequest(requestOptions); + + this.authentications.default.applyToRequest(requestOptions); + + let dfd = $.Deferred(); + $.ajax(requestOptions).then( + (data: Array, textStatus: string, jqXHR: JQueryXHR) => + dfd.resolve({ response: jqXHR, body: data }), + (xhr: JQueryXHR, textStatus: string, errorThrown: string) => + dfd.reject({ response: xhr, body: errorThrown }) + ); + return dfd.promise(); + } + /** + * Finds Pets by tags + * Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. + * @param tags Tags to filter by + */ + public findPetsByTags (tags?: Array) : JQueryPromise<{ response: JQueryXHR; body: Array; }> { + let localVarPath = this.basePath + '/pet/findByTags'; + let queryParameters: any = {}; + let headerParams: any = this.extendObj({}, this.defaultHeaders); + + + if (tags !== undefined) { + queryParameters['tags'] = tags; + } + + + localVarPath = localVarPath + "?" + $.param(queryParameters); + + + let reqHasFile = false; + let reqDict = {}; + let reqFormData = new FormData(); + + let requestOptions: JQueryAjaxSettings = { + url: localVarPath, + type: 'GET', + headers: headerParams, + processData: false + }; + + if (Object.keys(reqDict).length) { + requestOptions.data = reqHasFile ? reqFormData : JSON.stringify(reqDict); + requestOptions.contentType = reqHasFile ? false : 'application/json; charset=utf-8'; + } + + this.authentications.petstore_auth.applyToRequest(requestOptions); + + this.authentications.default.applyToRequest(requestOptions); + + let dfd = $.Deferred(); + $.ajax(requestOptions).then( + (data: Array, textStatus: string, jqXHR: JQueryXHR) => + dfd.resolve({ response: jqXHR, body: data }), + (xhr: JQueryXHR, textStatus: string, errorThrown: string) => + dfd.reject({ response: xhr, body: errorThrown }) + ); + return dfd.promise(); + } + /** + * Find pet by ID + * Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions + * @param petId ID of pet that needs to be fetched + */ + public getPetById (petId: number) : JQueryPromise<{ response: JQueryXHR; body: Pet; }> { + let localVarPath = this.basePath + '/pet/{petId}' + .replace('{' + 'petId' + '}', String(petId)); + let queryParameters: any = {}; + let headerParams: any = this.extendObj({}, this.defaultHeaders); + + + // verify required parameter 'petId' is not null or undefined + if (petId === null || petId === undefined) { + throw new Error('Required parameter petId was null or undefined when calling getPetById.'); + } + + + localVarPath = localVarPath + "?" + $.param(queryParameters); + + + let reqHasFile = false; + let reqDict = {}; + let reqFormData = new FormData(); + + let requestOptions: JQueryAjaxSettings = { + url: localVarPath, + type: 'GET', + headers: headerParams, + processData: false + }; + + if (Object.keys(reqDict).length) { + requestOptions.data = reqHasFile ? reqFormData : JSON.stringify(reqDict); + requestOptions.contentType = reqHasFile ? false : 'application/json; charset=utf-8'; + } + + this.authentications.petstore_auth.applyToRequest(requestOptions); + + this.authentications.api_key.applyToRequest(requestOptions); + + this.authentications.default.applyToRequest(requestOptions); + + let dfd = $.Deferred(); + $.ajax(requestOptions).then( + (data: Pet, textStatus: string, jqXHR: JQueryXHR) => + dfd.resolve({ response: jqXHR, body: data }), + (xhr: JQueryXHR, textStatus: string, errorThrown: string) => + dfd.reject({ response: xhr, body: errorThrown }) + ); + return dfd.promise(); + } + /** + * Update an existing pet + * + * @param body Pet object that needs to be added to the store + */ + public updatePet (body?: Pet) : JQueryPromise<{ response: JQueryXHR; body?: any; }> { + let localVarPath = this.basePath + '/pet'; + let queryParameters: any = {}; + let headerParams: any = this.extendObj({}, this.defaultHeaders); + + + + localVarPath = localVarPath + "?" + $.param(queryParameters); + + + let reqDict = body; + let reqFormData = new FormData(); + reqFormData.append('body', body); + let reqHasFile = false; + + let requestOptions: JQueryAjaxSettings = { + url: localVarPath, + type: 'PUT', + headers: headerParams, + processData: false + }; + + if (Object.keys(reqDict).length) { + requestOptions.data = reqHasFile ? reqFormData : JSON.stringify(reqDict); + requestOptions.contentType = reqHasFile ? false : 'application/json; charset=utf-8'; + } + + this.authentications.petstore_auth.applyToRequest(requestOptions); + + this.authentications.default.applyToRequest(requestOptions); + + let dfd = $.Deferred(); + $.ajax(requestOptions).then( + (data: , textStatus: string, jqXHR: JQueryXHR) => + dfd.resolve({ response: jqXHR, body: data }), + (xhr: JQueryXHR, textStatus: string, errorThrown: string) => + dfd.reject({ response: xhr, body: errorThrown }) + ); + return dfd.promise(); + } + /** + * Updates a pet in the store with form data + * + * @param petId ID of pet that needs to be updated + * @param name Updated name of the pet + * @param status Updated status of the pet + */ + public updatePetWithForm (petId: string, name?: string, status?: string) : JQueryPromise<{ response: JQueryXHR; body?: any; }> { + let localVarPath = this.basePath + '/pet/{petId}' + .replace('{' + 'petId' + '}', String(petId)); + let queryParameters: any = {}; + let headerParams: any = this.extendObj({}, this.defaultHeaders); + + + // verify required parameter 'petId' is not null or undefined + if (petId === null || petId === undefined) { + throw new Error('Required parameter petId was null or undefined when calling updatePetWithForm.'); + } + + + localVarPath = localVarPath + "?" + $.param(queryParameters); + + + let reqHasFile = false; + let reqDict = {}; + let reqFormData = new FormData(); + if (name !== undefined) { + reqFormData.append('name', name); + reqDict['name'] = name; + } + + if (status !== undefined) { + reqFormData.append('status', status); + reqDict['status'] = status; + } + + + let requestOptions: JQueryAjaxSettings = { + url: localVarPath, + type: 'POST', + headers: headerParams, + processData: false + }; + + if (Object.keys(reqDict).length) { + requestOptions.data = reqHasFile ? reqFormData : JSON.stringify(reqDict); + requestOptions.contentType = reqHasFile ? false : 'application/json; charset=utf-8'; + } + + this.authentications.petstore_auth.applyToRequest(requestOptions); + + this.authentications.default.applyToRequest(requestOptions); + + let dfd = $.Deferred(); + $.ajax(requestOptions).then( + (data: , textStatus: string, jqXHR: JQueryXHR) => + dfd.resolve({ response: jqXHR, body: data }), + (xhr: JQueryXHR, textStatus: string, errorThrown: string) => + dfd.reject({ response: xhr, body: errorThrown }) + ); + return dfd.promise(); + } + /** + * uploads an image + * + * @param petId ID of pet to update + * @param additionalMetadata Additional data to pass to server + * @param file file to upload + */ + public uploadFile (petId: number, additionalMetadata?: string, file?: any) : JQueryPromise<{ response: JQueryXHR; body?: any; }> { + let localVarPath = this.basePath + '/pet/{petId}/uploadImage' + .replace('{' + 'petId' + '}', String(petId)); + let queryParameters: any = {}; + let headerParams: any = this.extendObj({}, this.defaultHeaders); + + + // verify required parameter 'petId' is not null or undefined + if (petId === null || petId === undefined) { + throw new Error('Required parameter petId was null or undefined when calling uploadFile.'); + } + + + localVarPath = localVarPath + "?" + $.param(queryParameters); + + + let reqHasFile = false; + let reqDict = {}; + let reqFormData = new FormData(); + if (additionalMetadata !== undefined) { + reqFormData.append('additionalMetadata', additionalMetadata); + reqDict['additionalMetadata'] = additionalMetadata; + } + + reqHasFile = true; + if (file !== undefined) { + reqFormData.append('file', file); + reqDict['file'] = file; + } + + + let requestOptions: JQueryAjaxSettings = { + url: localVarPath, + type: 'POST', + headers: headerParams, + processData: false + }; + + if (Object.keys(reqDict).length) { + requestOptions.data = reqHasFile ? reqFormData : JSON.stringify(reqDict); + requestOptions.contentType = reqHasFile ? false : 'application/json; charset=utf-8'; + } + + this.authentications.petstore_auth.applyToRequest(requestOptions); + + this.authentications.default.applyToRequest(requestOptions); + + let dfd = $.Deferred(); + $.ajax(requestOptions).then( + (data: , textStatus: string, jqXHR: JQueryXHR) => + dfd.resolve({ response: jqXHR, body: data }), + (xhr: JQueryXHR, textStatus: string, errorThrown: string) => + dfd.reject({ response: xhr, body: errorThrown }) + ); + return dfd.promise(); + } +} +export enum StoreApiApiKeys { + api_key, +} + +export class StoreApi { + protected basePath = defaultBasePath; + protected defaultHeaders : any = {}; + + protected authentications = { + 'default': new VoidAuth(), + 'api_key': new ApiKeyAuth('header', 'api_key'), + 'petstore_auth': new OAuth(), + } + + constructor(basePath?: string); + constructor(basePathOrUsername: string, password?: string, basePath?: string) { + if (password) { + if (basePath) { + this.basePath = basePath; + } + } else { + if (basePathOrUsername) { + this.basePath = basePathOrUsername + } + } + } + + public setApiKey(key: StoreApiApiKeys, value: string) { + this.authentications[StoreApiApiKeys[key]].apiKey = value; + } + + set accessToken(token: string) { + this.authentications.petstore_auth.accessToken = token; + } + private extendObj(objA: T2, objB: T2): T1|T2 { + for(let key in objB){ + if(objB.hasOwnProperty(key)){ + objA[key] = objB[key]; + } + } + return objA; + } + + /** + * Delete purchase order by ID + * For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors + * @param orderId ID of the order that needs to be deleted + */ + public deleteOrder (orderId: string) : JQueryPromise<{ response: JQueryXHR; body?: any; }> { + let localVarPath = this.basePath + '/store/order/{orderId}' + .replace('{' + 'orderId' + '}', String(orderId)); + let queryParameters: any = {}; + let headerParams: any = this.extendObj({}, this.defaultHeaders); + + + // verify required parameter 'orderId' is not null or undefined + if (orderId === null || orderId === undefined) { + throw new Error('Required parameter orderId was null or undefined when calling deleteOrder.'); + } + + + localVarPath = localVarPath + "?" + $.param(queryParameters); + + + let reqHasFile = false; + let reqDict = {}; + let reqFormData = new FormData(); + + let requestOptions: JQueryAjaxSettings = { + url: localVarPath, + type: 'DELETE', + headers: headerParams, + processData: false + }; + + if (Object.keys(reqDict).length) { + requestOptions.data = reqHasFile ? reqFormData : JSON.stringify(reqDict); + requestOptions.contentType = reqHasFile ? false : 'application/json; charset=utf-8'; + } + + this.authentications.default.applyToRequest(requestOptions); + + let dfd = $.Deferred(); + $.ajax(requestOptions).then( + (data: , textStatus: string, jqXHR: JQueryXHR) => + dfd.resolve({ response: jqXHR, body: data }), + (xhr: JQueryXHR, textStatus: string, errorThrown: string) => + dfd.reject({ response: xhr, body: errorThrown }) + ); + return dfd.promise(); + } + /** + * Returns pet inventories by status + * Returns a map of status codes to quantities + */ + public getInventory () : JQueryPromise<{ response: JQueryXHR; body: { [key: string]: number; }; }> { + let localVarPath = this.basePath + '/store/inventory'; + let queryParameters: any = {}; + let headerParams: any = this.extendObj({}, this.defaultHeaders); + + + + localVarPath = localVarPath + "?" + $.param(queryParameters); + + + let reqHasFile = false; + let reqDict = {}; + let reqFormData = new FormData(); + + let requestOptions: JQueryAjaxSettings = { + url: localVarPath, + type: 'GET', + headers: headerParams, + processData: false + }; + + if (Object.keys(reqDict).length) { + requestOptions.data = reqHasFile ? reqFormData : JSON.stringify(reqDict); + requestOptions.contentType = reqHasFile ? false : 'application/json; charset=utf-8'; + } + + this.authentications.api_key.applyToRequest(requestOptions); + + this.authentications.default.applyToRequest(requestOptions); + + let dfd = $.Deferred(); + $.ajax(requestOptions).then( + (data: { [key: string]: number; }, textStatus: string, jqXHR: JQueryXHR) => + dfd.resolve({ response: jqXHR, body: data }), + (xhr: JQueryXHR, textStatus: string, errorThrown: string) => + dfd.reject({ response: xhr, body: errorThrown }) + ); + return dfd.promise(); + } + /** + * Find purchase order by ID + * For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions + * @param orderId ID of pet that needs to be fetched + */ + public getOrderById (orderId: string) : JQueryPromise<{ response: JQueryXHR; body: Order; }> { + let localVarPath = this.basePath + '/store/order/{orderId}' + .replace('{' + 'orderId' + '}', String(orderId)); + let queryParameters: any = {}; + let headerParams: any = this.extendObj({}, this.defaultHeaders); + + + // verify required parameter 'orderId' is not null or undefined + if (orderId === null || orderId === undefined) { + throw new Error('Required parameter orderId was null or undefined when calling getOrderById.'); + } + + + localVarPath = localVarPath + "?" + $.param(queryParameters); + + + let reqHasFile = false; + let reqDict = {}; + let reqFormData = new FormData(); + + let requestOptions: JQueryAjaxSettings = { + url: localVarPath, + type: 'GET', + headers: headerParams, + processData: false + }; + + if (Object.keys(reqDict).length) { + requestOptions.data = reqHasFile ? reqFormData : JSON.stringify(reqDict); + requestOptions.contentType = reqHasFile ? false : 'application/json; charset=utf-8'; + } + + this.authentications.default.applyToRequest(requestOptions); + + let dfd = $.Deferred(); + $.ajax(requestOptions).then( + (data: Order, textStatus: string, jqXHR: JQueryXHR) => + dfd.resolve({ response: jqXHR, body: data }), + (xhr: JQueryXHR, textStatus: string, errorThrown: string) => + dfd.reject({ response: xhr, body: errorThrown }) + ); + return dfd.promise(); + } + /** + * Place an order for a pet + * + * @param body order placed for purchasing the pet + */ + public placeOrder (body?: Order) : JQueryPromise<{ response: JQueryXHR; body: Order; }> { + let localVarPath = this.basePath + '/store/order'; + let queryParameters: any = {}; + let headerParams: any = this.extendObj({}, this.defaultHeaders); + + + + localVarPath = localVarPath + "?" + $.param(queryParameters); + + + let reqDict = body; + let reqFormData = new FormData(); + reqFormData.append('body', body); + let reqHasFile = false; + + let requestOptions: JQueryAjaxSettings = { + url: localVarPath, + type: 'POST', + headers: headerParams, + processData: false + }; + + if (Object.keys(reqDict).length) { + requestOptions.data = reqHasFile ? reqFormData : JSON.stringify(reqDict); + requestOptions.contentType = reqHasFile ? false : 'application/json; charset=utf-8'; + } + + this.authentications.default.applyToRequest(requestOptions); + + let dfd = $.Deferred(); + $.ajax(requestOptions).then( + (data: Order, textStatus: string, jqXHR: JQueryXHR) => + dfd.resolve({ response: jqXHR, body: data }), + (xhr: JQueryXHR, textStatus: string, errorThrown: string) => + dfd.reject({ response: xhr, body: errorThrown }) + ); + return dfd.promise(); + } +} +export enum UserApiApiKeys { + api_key, +} + +export class UserApi { + protected basePath = defaultBasePath; + protected defaultHeaders : any = {}; + + protected authentications = { + 'default': new VoidAuth(), + 'api_key': new ApiKeyAuth('header', 'api_key'), + 'petstore_auth': new OAuth(), + } + + constructor(basePath?: string); + constructor(basePathOrUsername: string, password?: string, basePath?: string) { + if (password) { + if (basePath) { + this.basePath = basePath; + } + } else { + if (basePathOrUsername) { + this.basePath = basePathOrUsername + } + } + } + + public setApiKey(key: UserApiApiKeys, value: string) { + this.authentications[UserApiApiKeys[key]].apiKey = value; + } + + set accessToken(token: string) { + this.authentications.petstore_auth.accessToken = token; + } + private extendObj(objA: T2, objB: T2): T1|T2 { + for(let key in objB){ + if(objB.hasOwnProperty(key)){ + objA[key] = objB[key]; + } + } + return objA; + } + + /** + * Create user + * This can only be done by the logged in user. + * @param body Created user object + */ + public createUser (body?: User) : JQueryPromise<{ response: JQueryXHR; body?: any; }> { + let localVarPath = this.basePath + '/user'; + let queryParameters: any = {}; + let headerParams: any = this.extendObj({}, this.defaultHeaders); + + + + localVarPath = localVarPath + "?" + $.param(queryParameters); + + + let reqDict = body; + let reqFormData = new FormData(); + reqFormData.append('body', body); + let reqHasFile = false; + + let requestOptions: JQueryAjaxSettings = { + url: localVarPath, + type: 'POST', + headers: headerParams, + processData: false + }; + + if (Object.keys(reqDict).length) { + requestOptions.data = reqHasFile ? reqFormData : JSON.stringify(reqDict); + requestOptions.contentType = reqHasFile ? false : 'application/json; charset=utf-8'; + } + + this.authentications.default.applyToRequest(requestOptions); + + let dfd = $.Deferred(); + $.ajax(requestOptions).then( + (data: , textStatus: string, jqXHR: JQueryXHR) => + dfd.resolve({ response: jqXHR, body: data }), + (xhr: JQueryXHR, textStatus: string, errorThrown: string) => + dfd.reject({ response: xhr, body: errorThrown }) + ); + return dfd.promise(); + } + /** + * Creates list of users with given input array + * + * @param body List of user object + */ + public createUsersWithArrayInput (body?: Array) : JQueryPromise<{ response: JQueryXHR; body?: any; }> { + let localVarPath = this.basePath + '/user/createWithArray'; + let queryParameters: any = {}; + let headerParams: any = this.extendObj({}, this.defaultHeaders); + + + + localVarPath = localVarPath + "?" + $.param(queryParameters); + + + let reqDict = body; + let reqFormData = new FormData(); + reqFormData.append('body', body); + let reqHasFile = false; + + let requestOptions: JQueryAjaxSettings = { + url: localVarPath, + type: 'POST', + headers: headerParams, + processData: false + }; + + if (Object.keys(reqDict).length) { + requestOptions.data = reqHasFile ? reqFormData : JSON.stringify(reqDict); + requestOptions.contentType = reqHasFile ? false : 'application/json; charset=utf-8'; + } + + this.authentications.default.applyToRequest(requestOptions); + + let dfd = $.Deferred(); + $.ajax(requestOptions).then( + (data: , textStatus: string, jqXHR: JQueryXHR) => + dfd.resolve({ response: jqXHR, body: data }), + (xhr: JQueryXHR, textStatus: string, errorThrown: string) => + dfd.reject({ response: xhr, body: errorThrown }) + ); + return dfd.promise(); + } + /** + * Creates list of users with given input array + * + * @param body List of user object + */ + public createUsersWithListInput (body?: Array) : JQueryPromise<{ response: JQueryXHR; body?: any; }> { + let localVarPath = this.basePath + '/user/createWithList'; + let queryParameters: any = {}; + let headerParams: any = this.extendObj({}, this.defaultHeaders); + + + + localVarPath = localVarPath + "?" + $.param(queryParameters); + + + let reqDict = body; + let reqFormData = new FormData(); + reqFormData.append('body', body); + let reqHasFile = false; + + let requestOptions: JQueryAjaxSettings = { + url: localVarPath, + type: 'POST', + headers: headerParams, + processData: false + }; + + if (Object.keys(reqDict).length) { + requestOptions.data = reqHasFile ? reqFormData : JSON.stringify(reqDict); + requestOptions.contentType = reqHasFile ? false : 'application/json; charset=utf-8'; + } + + this.authentications.default.applyToRequest(requestOptions); + + let dfd = $.Deferred(); + $.ajax(requestOptions).then( + (data: , textStatus: string, jqXHR: JQueryXHR) => + dfd.resolve({ response: jqXHR, body: data }), + (xhr: JQueryXHR, textStatus: string, errorThrown: string) => + dfd.reject({ response: xhr, body: errorThrown }) + ); + return dfd.promise(); + } + /** + * Delete user + * This can only be done by the logged in user. + * @param username The name that needs to be deleted + */ + public deleteUser (username: string) : JQueryPromise<{ response: JQueryXHR; body?: any; }> { + let localVarPath = this.basePath + '/user/{username}' + .replace('{' + 'username' + '}', String(username)); + let queryParameters: any = {}; + let headerParams: any = this.extendObj({}, this.defaultHeaders); + + + // verify required parameter 'username' is not null or undefined + if (username === null || username === undefined) { + throw new Error('Required parameter username was null or undefined when calling deleteUser.'); + } + + + localVarPath = localVarPath + "?" + $.param(queryParameters); + + + let reqHasFile = false; + let reqDict = {}; + let reqFormData = new FormData(); + + let requestOptions: JQueryAjaxSettings = { + url: localVarPath, + type: 'DELETE', + headers: headerParams, + processData: false + }; + + if (Object.keys(reqDict).length) { + requestOptions.data = reqHasFile ? reqFormData : JSON.stringify(reqDict); + requestOptions.contentType = reqHasFile ? false : 'application/json; charset=utf-8'; + } + + this.authentications.default.applyToRequest(requestOptions); + + let dfd = $.Deferred(); + $.ajax(requestOptions).then( + (data: , textStatus: string, jqXHR: JQueryXHR) => + dfd.resolve({ response: jqXHR, body: data }), + (xhr: JQueryXHR, textStatus: string, errorThrown: string) => + dfd.reject({ response: xhr, body: errorThrown }) + ); + return dfd.promise(); + } + /** + * Get user by user name + * + * @param username The name that needs to be fetched. Use user1 for testing. + */ + public getUserByName (username: string) : JQueryPromise<{ response: JQueryXHR; body: User; }> { + let localVarPath = this.basePath + '/user/{username}' + .replace('{' + 'username' + '}', String(username)); + let queryParameters: any = {}; + let headerParams: any = this.extendObj({}, this.defaultHeaders); + + + // verify required parameter 'username' is not null or undefined + if (username === null || username === undefined) { + throw new Error('Required parameter username was null or undefined when calling getUserByName.'); + } + + + localVarPath = localVarPath + "?" + $.param(queryParameters); + + + let reqHasFile = false; + let reqDict = {}; + let reqFormData = new FormData(); + + let requestOptions: JQueryAjaxSettings = { + url: localVarPath, + type: 'GET', + headers: headerParams, + processData: false + }; + + if (Object.keys(reqDict).length) { + requestOptions.data = reqHasFile ? reqFormData : JSON.stringify(reqDict); + requestOptions.contentType = reqHasFile ? false : 'application/json; charset=utf-8'; + } + + this.authentications.default.applyToRequest(requestOptions); + + let dfd = $.Deferred(); + $.ajax(requestOptions).then( + (data: User, textStatus: string, jqXHR: JQueryXHR) => + dfd.resolve({ response: jqXHR, body: data }), + (xhr: JQueryXHR, textStatus: string, errorThrown: string) => + dfd.reject({ response: xhr, body: errorThrown }) + ); + return dfd.promise(); + } + /** + * Logs user into the system + * + * @param username The user name for login + * @param password The password for login in clear text + */ + public loginUser (username?: string, password?: string) : JQueryPromise<{ response: JQueryXHR; body: string; }> { + let localVarPath = this.basePath + '/user/login'; + let queryParameters: any = {}; + let headerParams: any = this.extendObj({}, this.defaultHeaders); + + + if (username !== undefined) { + queryParameters['username'] = username; + } + + if (password !== undefined) { + queryParameters['password'] = password; + } + + + localVarPath = localVarPath + "?" + $.param(queryParameters); + + + let reqHasFile = false; + let reqDict = {}; + let reqFormData = new FormData(); + + let requestOptions: JQueryAjaxSettings = { + url: localVarPath, + type: 'GET', + headers: headerParams, + processData: false + }; + + if (Object.keys(reqDict).length) { + requestOptions.data = reqHasFile ? reqFormData : JSON.stringify(reqDict); + requestOptions.contentType = reqHasFile ? false : 'application/json; charset=utf-8'; + } + + this.authentications.default.applyToRequest(requestOptions); + + let dfd = $.Deferred(); + $.ajax(requestOptions).then( + (data: string, textStatus: string, jqXHR: JQueryXHR) => + dfd.resolve({ response: jqXHR, body: data }), + (xhr: JQueryXHR, textStatus: string, errorThrown: string) => + dfd.reject({ response: xhr, body: errorThrown }) + ); + return dfd.promise(); + } + /** + * Logs out current logged in user session + * + */ + public logoutUser () : JQueryPromise<{ response: JQueryXHR; body?: any; }> { + let localVarPath = this.basePath + '/user/logout'; + let queryParameters: any = {}; + let headerParams: any = this.extendObj({}, this.defaultHeaders); + + + + localVarPath = localVarPath + "?" + $.param(queryParameters); + + + let reqHasFile = false; + let reqDict = {}; + let reqFormData = new FormData(); + + let requestOptions: JQueryAjaxSettings = { + url: localVarPath, + type: 'GET', + headers: headerParams, + processData: false + }; + + if (Object.keys(reqDict).length) { + requestOptions.data = reqHasFile ? reqFormData : JSON.stringify(reqDict); + requestOptions.contentType = reqHasFile ? false : 'application/json; charset=utf-8'; + } + + this.authentications.default.applyToRequest(requestOptions); + + let dfd = $.Deferred(); + $.ajax(requestOptions).then( + (data: , textStatus: string, jqXHR: JQueryXHR) => + dfd.resolve({ response: jqXHR, body: data }), + (xhr: JQueryXHR, textStatus: string, errorThrown: string) => + dfd.reject({ response: xhr, body: errorThrown }) + ); + return dfd.promise(); + } + /** + * Updated user + * This can only be done by the logged in user. + * @param username name that need to be deleted + * @param body Updated user object + */ + public updateUser (username: string, body?: User) : JQueryPromise<{ response: JQueryXHR; body?: any; }> { + let localVarPath = this.basePath + '/user/{username}' + .replace('{' + 'username' + '}', String(username)); + let queryParameters: any = {}; + let headerParams: any = this.extendObj({}, this.defaultHeaders); + + + // verify required parameter 'username' is not null or undefined + if (username === null || username === undefined) { + throw new Error('Required parameter username was null or undefined when calling updateUser.'); + } + + + localVarPath = localVarPath + "?" + $.param(queryParameters); + + + let reqDict = body; + let reqFormData = new FormData(); + reqFormData.append('body', body); + let reqHasFile = false; + + let requestOptions: JQueryAjaxSettings = { + url: localVarPath, + type: 'PUT', + headers: headerParams, + processData: false + }; + + if (Object.keys(reqDict).length) { + requestOptions.data = reqHasFile ? reqFormData : JSON.stringify(reqDict); + requestOptions.contentType = reqHasFile ? false : 'application/json; charset=utf-8'; + } + + this.authentications.default.applyToRequest(requestOptions); + + let dfd = $.Deferred(); + $.ajax(requestOptions).then( + (data: , textStatus: string, jqXHR: JQueryXHR) => + dfd.resolve({ response: jqXHR, body: data }), + (xhr: JQueryXHR, textStatus: string, errorThrown: string) => + dfd.reject({ response: xhr, body: errorThrown }) + ); + return dfd.promise(); + } +} diff --git a/samples/client/petstore/typescript-jquery/default/git_push.sh b/samples/client/petstore/typescript-jquery/default/git_push.sh new file mode 100644 index 000000000000..ed374619b139 --- /dev/null +++ b/samples/client/petstore/typescript-jquery/default/git_push.sh @@ -0,0 +1,52 @@ +#!/bin/sh +# ref: https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/ +# +# Usage example: /bin/sh ./git_push.sh wing328 swagger-petstore-perl "minor update" + +git_user_id=$1 +git_repo_id=$2 +release_note=$3 + +if [ "$git_user_id" = "" ]; then + git_user_id="GIT_USER_ID" + echo "[INFO] No command line input provided. Set \$git_user_id to $git_user_id" +fi + +if [ "$git_repo_id" = "" ]; then + git_repo_id="GIT_REPO_ID" + echo "[INFO] No command line input provided. Set \$git_repo_id to $git_repo_id" +fi + +if [ "$release_note" = "" ]; then + release_note="Minor update" + echo "[INFO] No command line input provided. Set \$release_note to $release_note" +fi + +# Initialize the local directory as a Git repository +git init + +# Adds the files in the local repository and stages them for commit. +git add . + +# Commits the tracked changes and prepares them to be pushed to a remote repository. +git commit -m "$release_note" + +# Sets the new remote +git_remote=`git remote` +if [ "$git_remote" = "" ]; then # git remote not defined + + if [ "$GIT_TOKEN" = "" ]; then + echo "[INFO] \$GIT_TOKEN (environment variable) is not set. Using the git crediential in your environment." + git remote add origin https://github.com/${git_user_id}/${git_repo_id}.git + else + git remote add origin https://${git_user_id}:${GIT_TOKEN}@github.com/${git_user_id}/${git_repo_id}.git + fi + +fi + +git pull origin master + +# Pushes (Forces) the changes in the local repository up to the remote repository +echo "Git pushing to https://github.com/${git_user_id}/${git_repo_id}.git" +git push origin master 2>&1 | grep -v 'To https' + diff --git a/samples/client/petstore/typescript-jquery/npm/.swagger-codegen-ignore b/samples/client/petstore/typescript-jquery/npm/.swagger-codegen-ignore new file mode 100644 index 000000000000..c5fa491b4c55 --- /dev/null +++ b/samples/client/petstore/typescript-jquery/npm/.swagger-codegen-ignore @@ -0,0 +1,23 @@ +# Swagger Codegen Ignore +# Generated by swagger-codegen https://github.com/swagger-api/swagger-codegen + +# Use this file to prevent files from being overwritten by the generator. +# The patterns follow closely to .gitignore or .dockerignore. + +# As an example, the C# client generator defines ApiClient.cs. +# You can make changes and tell Swagger Codgen to ignore just this file by uncommenting the following line: +#ApiClient.cs + +# You can match any string of characters against a directory, file or extension with a single asterisk (*): +#foo/*/qux +# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux + +# You can recursively match patterns against a directory, file or extension with a double asterisk (**): +#foo/**/qux +# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux + +# You can also negate patterns with an exclamation (!). +# For example, you can ignore all files in a docs folder with the file extension .md: +#docs/*.md +# Then explicitly reverse the ignore rule for a single file: +#!docs/README.md diff --git a/samples/client/petstore/typescript-jquery/npm/api.ts b/samples/client/petstore/typescript-jquery/npm/api.ts new file mode 100644 index 000000000000..9491259901e3 --- /dev/null +++ b/samples/client/petstore/typescript-jquery/npm/api.ts @@ -0,0 +1,1213 @@ +import * as $ from 'jquery'; + +let defaultBasePath = 'http://petstore.swagger.io/v2'; + +// =============================================== +// This file is autogenerated - Please do not edit +// =============================================== + +/* tslint:disable:no-unused-variable */ + +export class Category { + 'id': number; + 'name': string; +} + +export class Order { + 'id': number; + 'petId': number; + 'quantity': number; + 'shipDate': Date; + /** + * Order Status + */ + 'status': Order.StatusEnum; + 'complete': boolean; +} + +export namespace Order { + export enum StatusEnum { + Placed = 'placed', + Approved = 'approved', + Delivered = 'delivered' + } +} +export class Pet { + 'id': number; + 'category': Category; + 'name': string; + 'photoUrls': Array; + 'tags': Array; + /** + * pet status in the store + */ + 'status': Pet.StatusEnum; +} + +export namespace Pet { + export enum StatusEnum { + Available = 'available', + Pending = 'pending', + Sold = 'sold' + } +} +export class Tag { + 'id': number; + 'name': string; +} + +export class User { + 'id': number; + 'username': string; + 'firstName': string; + 'lastName': string; + 'email': string; + 'password': string; + 'phone': string; + /** + * User Status + */ + 'userStatus': number; +} + + +export interface Authentication { + /** + * Apply authentication settings to header and query params. + */ + applyToRequest(requestOptions: JQueryAjaxSettings): void; +} + +export class HttpBasicAuth implements Authentication { + public username: string; + public password: string; + applyToRequest(requestOptions: any): void { + requestOptions.username = this.username; + requestOptions.password = this.password; + } +} + +export class ApiKeyAuth implements Authentication { + public apiKey: string; + + constructor(private location: string, private paramName: string) { + } + + applyToRequest(requestOptions: JQueryAjaxSettings): void { + requestOptions.headers[this.paramName] = this.apiKey; + } +} + +export class OAuth implements Authentication { + public accessToken: string; + + applyToRequest(requestOptions: JQueryAjaxSettings): void { + requestOptions.headers["Authorization"] = "Bearer " + this.accessToken; + } +} + +export class VoidAuth implements Authentication { + public username: string; + public password: string; + applyToRequest(requestOptions: JQueryAjaxSettings): void { + // Do nothing + } +} + +export enum PetApiApiKeys { + api_key, +} + +export class PetApi { + protected basePath = defaultBasePath; + protected defaultHeaders : any = {}; + + protected authentications = { + 'default': new VoidAuth(), + 'api_key': new ApiKeyAuth('header', 'api_key'), + 'petstore_auth': new OAuth(), + } + + constructor(basePath?: string); + constructor(basePathOrUsername: string, password?: string, basePath?: string) { + if (password) { + if (basePath) { + this.basePath = basePath; + } + } else { + if (basePathOrUsername) { + this.basePath = basePathOrUsername + } + } + } + + public setApiKey(key: PetApiApiKeys, value: string) { + this.authentications[PetApiApiKeys[key]].apiKey = value; + } + + set accessToken(token: string) { + this.authentications.petstore_auth.accessToken = token; + } + private extendObj(objA: T2, objB: T2): T1|T2 { + for(let key in objB){ + if(objB.hasOwnProperty(key)){ + objA[key] = objB[key]; + } + } + return objA; + } + + /** + * Add a new pet to the store + * + * @param body Pet object that needs to be added to the store + */ + public addPet (body?: Pet) : JQueryPromise<{ response: JQueryXHR; body?: any; }> { + let localVarPath = this.basePath + '/pet'; + let queryParameters: any = {}; + let headerParams: any = this.extendObj({}, this.defaultHeaders); + + + + localVarPath = localVarPath + "?" + $.param(queryParameters); + + + let reqDict = body; + let reqFormData = new FormData(); + reqFormData.append('body', body); + let reqHasFile = false; + + let requestOptions: JQueryAjaxSettings = { + url: localVarPath, + type: 'POST', + headers: headerParams, + processData: false + }; + + if (Object.keys(reqDict).length) { + requestOptions.data = reqHasFile ? reqFormData : JSON.stringify(reqDict); + requestOptions.contentType = reqHasFile ? false : 'application/json; charset=utf-8'; + } + + this.authentications.petstore_auth.applyToRequest(requestOptions); + + this.authentications.default.applyToRequest(requestOptions); + + let dfd = $.Deferred(); + $.ajax(requestOptions).then( + (data: , textStatus: string, jqXHR: JQueryXHR) => + dfd.resolve({ response: jqXHR, body: data }), + (xhr: JQueryXHR, textStatus: string, errorThrown: string) => + dfd.reject({ response: xhr, body: errorThrown }) + ); + return dfd.promise(); + } + /** + * Deletes a pet + * + * @param petId Pet id to delete + * @param apiKey + */ + public deletePet (petId: number, apiKey?: string) : JQueryPromise<{ response: JQueryXHR; body?: any; }> { + let localVarPath = this.basePath + '/pet/{petId}' + .replace('{' + 'petId' + '}', String(petId)); + let queryParameters: any = {}; + let headerParams: any = this.extendObj({}, this.defaultHeaders); + + + // verify required parameter 'petId' is not null or undefined + if (petId === null || petId === undefined) { + throw new Error('Required parameter petId was null or undefined when calling deletePet.'); + } + + + localVarPath = localVarPath + "?" + $.param(queryParameters); + + headerParams['api_key'] = apiKey; + + + let reqHasFile = false; + let reqDict = {}; + let reqFormData = new FormData(); + + let requestOptions: JQueryAjaxSettings = { + url: localVarPath, + type: 'DELETE', + headers: headerParams, + processData: false + }; + + if (Object.keys(reqDict).length) { + requestOptions.data = reqHasFile ? reqFormData : JSON.stringify(reqDict); + requestOptions.contentType = reqHasFile ? false : 'application/json; charset=utf-8'; + } + + this.authentications.petstore_auth.applyToRequest(requestOptions); + + this.authentications.default.applyToRequest(requestOptions); + + let dfd = $.Deferred(); + $.ajax(requestOptions).then( + (data: , textStatus: string, jqXHR: JQueryXHR) => + dfd.resolve({ response: jqXHR, body: data }), + (xhr: JQueryXHR, textStatus: string, errorThrown: string) => + dfd.reject({ response: xhr, body: errorThrown }) + ); + return dfd.promise(); + } + /** + * Finds Pets by status + * Multiple status values can be provided with comma separated strings + * @param status Status values that need to be considered for filter + */ + public findPetsByStatus (status?: Array) : JQueryPromise<{ response: JQueryXHR; body: Array; }> { + let localVarPath = this.basePath + '/pet/findByStatus'; + let queryParameters: any = {}; + let headerParams: any = this.extendObj({}, this.defaultHeaders); + + + if (status !== undefined) { + queryParameters['status'] = status; + } + + + localVarPath = localVarPath + "?" + $.param(queryParameters); + + + let reqHasFile = false; + let reqDict = {}; + let reqFormData = new FormData(); + + let requestOptions: JQueryAjaxSettings = { + url: localVarPath, + type: 'GET', + headers: headerParams, + processData: false + }; + + if (Object.keys(reqDict).length) { + requestOptions.data = reqHasFile ? reqFormData : JSON.stringify(reqDict); + requestOptions.contentType = reqHasFile ? false : 'application/json; charset=utf-8'; + } + + this.authentications.petstore_auth.applyToRequest(requestOptions); + + this.authentications.default.applyToRequest(requestOptions); + + let dfd = $.Deferred(); + $.ajax(requestOptions).then( + (data: Array, textStatus: string, jqXHR: JQueryXHR) => + dfd.resolve({ response: jqXHR, body: data }), + (xhr: JQueryXHR, textStatus: string, errorThrown: string) => + dfd.reject({ response: xhr, body: errorThrown }) + ); + return dfd.promise(); + } + /** + * Finds Pets by tags + * Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. + * @param tags Tags to filter by + */ + public findPetsByTags (tags?: Array) : JQueryPromise<{ response: JQueryXHR; body: Array; }> { + let localVarPath = this.basePath + '/pet/findByTags'; + let queryParameters: any = {}; + let headerParams: any = this.extendObj({}, this.defaultHeaders); + + + if (tags !== undefined) { + queryParameters['tags'] = tags; + } + + + localVarPath = localVarPath + "?" + $.param(queryParameters); + + + let reqHasFile = false; + let reqDict = {}; + let reqFormData = new FormData(); + + let requestOptions: JQueryAjaxSettings = { + url: localVarPath, + type: 'GET', + headers: headerParams, + processData: false + }; + + if (Object.keys(reqDict).length) { + requestOptions.data = reqHasFile ? reqFormData : JSON.stringify(reqDict); + requestOptions.contentType = reqHasFile ? false : 'application/json; charset=utf-8'; + } + + this.authentications.petstore_auth.applyToRequest(requestOptions); + + this.authentications.default.applyToRequest(requestOptions); + + let dfd = $.Deferred(); + $.ajax(requestOptions).then( + (data: Array, textStatus: string, jqXHR: JQueryXHR) => + dfd.resolve({ response: jqXHR, body: data }), + (xhr: JQueryXHR, textStatus: string, errorThrown: string) => + dfd.reject({ response: xhr, body: errorThrown }) + ); + return dfd.promise(); + } + /** + * Find pet by ID + * Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions + * @param petId ID of pet that needs to be fetched + */ + public getPetById (petId: number) : JQueryPromise<{ response: JQueryXHR; body: Pet; }> { + let localVarPath = this.basePath + '/pet/{petId}' + .replace('{' + 'petId' + '}', String(petId)); + let queryParameters: any = {}; + let headerParams: any = this.extendObj({}, this.defaultHeaders); + + + // verify required parameter 'petId' is not null or undefined + if (petId === null || petId === undefined) { + throw new Error('Required parameter petId was null or undefined when calling getPetById.'); + } + + + localVarPath = localVarPath + "?" + $.param(queryParameters); + + + let reqHasFile = false; + let reqDict = {}; + let reqFormData = new FormData(); + + let requestOptions: JQueryAjaxSettings = { + url: localVarPath, + type: 'GET', + headers: headerParams, + processData: false + }; + + if (Object.keys(reqDict).length) { + requestOptions.data = reqHasFile ? reqFormData : JSON.stringify(reqDict); + requestOptions.contentType = reqHasFile ? false : 'application/json; charset=utf-8'; + } + + this.authentications.petstore_auth.applyToRequest(requestOptions); + + this.authentications.api_key.applyToRequest(requestOptions); + + this.authentications.default.applyToRequest(requestOptions); + + let dfd = $.Deferred(); + $.ajax(requestOptions).then( + (data: Pet, textStatus: string, jqXHR: JQueryXHR) => + dfd.resolve({ response: jqXHR, body: data }), + (xhr: JQueryXHR, textStatus: string, errorThrown: string) => + dfd.reject({ response: xhr, body: errorThrown }) + ); + return dfd.promise(); + } + /** + * Update an existing pet + * + * @param body Pet object that needs to be added to the store + */ + public updatePet (body?: Pet) : JQueryPromise<{ response: JQueryXHR; body?: any; }> { + let localVarPath = this.basePath + '/pet'; + let queryParameters: any = {}; + let headerParams: any = this.extendObj({}, this.defaultHeaders); + + + + localVarPath = localVarPath + "?" + $.param(queryParameters); + + + let reqDict = body; + let reqFormData = new FormData(); + reqFormData.append('body', body); + let reqHasFile = false; + + let requestOptions: JQueryAjaxSettings = { + url: localVarPath, + type: 'PUT', + headers: headerParams, + processData: false + }; + + if (Object.keys(reqDict).length) { + requestOptions.data = reqHasFile ? reqFormData : JSON.stringify(reqDict); + requestOptions.contentType = reqHasFile ? false : 'application/json; charset=utf-8'; + } + + this.authentications.petstore_auth.applyToRequest(requestOptions); + + this.authentications.default.applyToRequest(requestOptions); + + let dfd = $.Deferred(); + $.ajax(requestOptions).then( + (data: , textStatus: string, jqXHR: JQueryXHR) => + dfd.resolve({ response: jqXHR, body: data }), + (xhr: JQueryXHR, textStatus: string, errorThrown: string) => + dfd.reject({ response: xhr, body: errorThrown }) + ); + return dfd.promise(); + } + /** + * Updates a pet in the store with form data + * + * @param petId ID of pet that needs to be updated + * @param name Updated name of the pet + * @param status Updated status of the pet + */ + public updatePetWithForm (petId: string, name?: string, status?: string) : JQueryPromise<{ response: JQueryXHR; body?: any; }> { + let localVarPath = this.basePath + '/pet/{petId}' + .replace('{' + 'petId' + '}', String(petId)); + let queryParameters: any = {}; + let headerParams: any = this.extendObj({}, this.defaultHeaders); + + + // verify required parameter 'petId' is not null or undefined + if (petId === null || petId === undefined) { + throw new Error('Required parameter petId was null or undefined when calling updatePetWithForm.'); + } + + + localVarPath = localVarPath + "?" + $.param(queryParameters); + + + let reqHasFile = false; + let reqDict = {}; + let reqFormData = new FormData(); + if (name !== undefined) { + reqFormData.append('name', name); + reqDict['name'] = name; + } + + if (status !== undefined) { + reqFormData.append('status', status); + reqDict['status'] = status; + } + + + let requestOptions: JQueryAjaxSettings = { + url: localVarPath, + type: 'POST', + headers: headerParams, + processData: false + }; + + if (Object.keys(reqDict).length) { + requestOptions.data = reqHasFile ? reqFormData : JSON.stringify(reqDict); + requestOptions.contentType = reqHasFile ? false : 'application/json; charset=utf-8'; + } + + this.authentications.petstore_auth.applyToRequest(requestOptions); + + this.authentications.default.applyToRequest(requestOptions); + + let dfd = $.Deferred(); + $.ajax(requestOptions).then( + (data: , textStatus: string, jqXHR: JQueryXHR) => + dfd.resolve({ response: jqXHR, body: data }), + (xhr: JQueryXHR, textStatus: string, errorThrown: string) => + dfd.reject({ response: xhr, body: errorThrown }) + ); + return dfd.promise(); + } + /** + * uploads an image + * + * @param petId ID of pet to update + * @param additionalMetadata Additional data to pass to server + * @param file file to upload + */ + public uploadFile (petId: number, additionalMetadata?: string, file?: any) : JQueryPromise<{ response: JQueryXHR; body?: any; }> { + let localVarPath = this.basePath + '/pet/{petId}/uploadImage' + .replace('{' + 'petId' + '}', String(petId)); + let queryParameters: any = {}; + let headerParams: any = this.extendObj({}, this.defaultHeaders); + + + // verify required parameter 'petId' is not null or undefined + if (petId === null || petId === undefined) { + throw new Error('Required parameter petId was null or undefined when calling uploadFile.'); + } + + + localVarPath = localVarPath + "?" + $.param(queryParameters); + + + let reqHasFile = false; + let reqDict = {}; + let reqFormData = new FormData(); + if (additionalMetadata !== undefined) { + reqFormData.append('additionalMetadata', additionalMetadata); + reqDict['additionalMetadata'] = additionalMetadata; + } + + reqHasFile = true; + if (file !== undefined) { + reqFormData.append('file', file); + reqDict['file'] = file; + } + + + let requestOptions: JQueryAjaxSettings = { + url: localVarPath, + type: 'POST', + headers: headerParams, + processData: false + }; + + if (Object.keys(reqDict).length) { + requestOptions.data = reqHasFile ? reqFormData : JSON.stringify(reqDict); + requestOptions.contentType = reqHasFile ? false : 'application/json; charset=utf-8'; + } + + this.authentications.petstore_auth.applyToRequest(requestOptions); + + this.authentications.default.applyToRequest(requestOptions); + + let dfd = $.Deferred(); + $.ajax(requestOptions).then( + (data: , textStatus: string, jqXHR: JQueryXHR) => + dfd.resolve({ response: jqXHR, body: data }), + (xhr: JQueryXHR, textStatus: string, errorThrown: string) => + dfd.reject({ response: xhr, body: errorThrown }) + ); + return dfd.promise(); + } +} +export enum StoreApiApiKeys { + api_key, +} + +export class StoreApi { + protected basePath = defaultBasePath; + protected defaultHeaders : any = {}; + + protected authentications = { + 'default': new VoidAuth(), + 'api_key': new ApiKeyAuth('header', 'api_key'), + 'petstore_auth': new OAuth(), + } + + constructor(basePath?: string); + constructor(basePathOrUsername: string, password?: string, basePath?: string) { + if (password) { + if (basePath) { + this.basePath = basePath; + } + } else { + if (basePathOrUsername) { + this.basePath = basePathOrUsername + } + } + } + + public setApiKey(key: StoreApiApiKeys, value: string) { + this.authentications[StoreApiApiKeys[key]].apiKey = value; + } + + set accessToken(token: string) { + this.authentications.petstore_auth.accessToken = token; + } + private extendObj(objA: T2, objB: T2): T1|T2 { + for(let key in objB){ + if(objB.hasOwnProperty(key)){ + objA[key] = objB[key]; + } + } + return objA; + } + + /** + * Delete purchase order by ID + * For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors + * @param orderId ID of the order that needs to be deleted + */ + public deleteOrder (orderId: string) : JQueryPromise<{ response: JQueryXHR; body?: any; }> { + let localVarPath = this.basePath + '/store/order/{orderId}' + .replace('{' + 'orderId' + '}', String(orderId)); + let queryParameters: any = {}; + let headerParams: any = this.extendObj({}, this.defaultHeaders); + + + // verify required parameter 'orderId' is not null or undefined + if (orderId === null || orderId === undefined) { + throw new Error('Required parameter orderId was null or undefined when calling deleteOrder.'); + } + + + localVarPath = localVarPath + "?" + $.param(queryParameters); + + + let reqHasFile = false; + let reqDict = {}; + let reqFormData = new FormData(); + + let requestOptions: JQueryAjaxSettings = { + url: localVarPath, + type: 'DELETE', + headers: headerParams, + processData: false + }; + + if (Object.keys(reqDict).length) { + requestOptions.data = reqHasFile ? reqFormData : JSON.stringify(reqDict); + requestOptions.contentType = reqHasFile ? false : 'application/json; charset=utf-8'; + } + + this.authentications.default.applyToRequest(requestOptions); + + let dfd = $.Deferred(); + $.ajax(requestOptions).then( + (data: , textStatus: string, jqXHR: JQueryXHR) => + dfd.resolve({ response: jqXHR, body: data }), + (xhr: JQueryXHR, textStatus: string, errorThrown: string) => + dfd.reject({ response: xhr, body: errorThrown }) + ); + return dfd.promise(); + } + /** + * Returns pet inventories by status + * Returns a map of status codes to quantities + */ + public getInventory () : JQueryPromise<{ response: JQueryXHR; body: { [key: string]: number; }; }> { + let localVarPath = this.basePath + '/store/inventory'; + let queryParameters: any = {}; + let headerParams: any = this.extendObj({}, this.defaultHeaders); + + + + localVarPath = localVarPath + "?" + $.param(queryParameters); + + + let reqHasFile = false; + let reqDict = {}; + let reqFormData = new FormData(); + + let requestOptions: JQueryAjaxSettings = { + url: localVarPath, + type: 'GET', + headers: headerParams, + processData: false + }; + + if (Object.keys(reqDict).length) { + requestOptions.data = reqHasFile ? reqFormData : JSON.stringify(reqDict); + requestOptions.contentType = reqHasFile ? false : 'application/json; charset=utf-8'; + } + + this.authentications.api_key.applyToRequest(requestOptions); + + this.authentications.default.applyToRequest(requestOptions); + + let dfd = $.Deferred(); + $.ajax(requestOptions).then( + (data: { [key: string]: number; }, textStatus: string, jqXHR: JQueryXHR) => + dfd.resolve({ response: jqXHR, body: data }), + (xhr: JQueryXHR, textStatus: string, errorThrown: string) => + dfd.reject({ response: xhr, body: errorThrown }) + ); + return dfd.promise(); + } + /** + * Find purchase order by ID + * For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions + * @param orderId ID of pet that needs to be fetched + */ + public getOrderById (orderId: string) : JQueryPromise<{ response: JQueryXHR; body: Order; }> { + let localVarPath = this.basePath + '/store/order/{orderId}' + .replace('{' + 'orderId' + '}', String(orderId)); + let queryParameters: any = {}; + let headerParams: any = this.extendObj({}, this.defaultHeaders); + + + // verify required parameter 'orderId' is not null or undefined + if (orderId === null || orderId === undefined) { + throw new Error('Required parameter orderId was null or undefined when calling getOrderById.'); + } + + + localVarPath = localVarPath + "?" + $.param(queryParameters); + + + let reqHasFile = false; + let reqDict = {}; + let reqFormData = new FormData(); + + let requestOptions: JQueryAjaxSettings = { + url: localVarPath, + type: 'GET', + headers: headerParams, + processData: false + }; + + if (Object.keys(reqDict).length) { + requestOptions.data = reqHasFile ? reqFormData : JSON.stringify(reqDict); + requestOptions.contentType = reqHasFile ? false : 'application/json; charset=utf-8'; + } + + this.authentications.default.applyToRequest(requestOptions); + + let dfd = $.Deferred(); + $.ajax(requestOptions).then( + (data: Order, textStatus: string, jqXHR: JQueryXHR) => + dfd.resolve({ response: jqXHR, body: data }), + (xhr: JQueryXHR, textStatus: string, errorThrown: string) => + dfd.reject({ response: xhr, body: errorThrown }) + ); + return dfd.promise(); + } + /** + * Place an order for a pet + * + * @param body order placed for purchasing the pet + */ + public placeOrder (body?: Order) : JQueryPromise<{ response: JQueryXHR; body: Order; }> { + let localVarPath = this.basePath + '/store/order'; + let queryParameters: any = {}; + let headerParams: any = this.extendObj({}, this.defaultHeaders); + + + + localVarPath = localVarPath + "?" + $.param(queryParameters); + + + let reqDict = body; + let reqFormData = new FormData(); + reqFormData.append('body', body); + let reqHasFile = false; + + let requestOptions: JQueryAjaxSettings = { + url: localVarPath, + type: 'POST', + headers: headerParams, + processData: false + }; + + if (Object.keys(reqDict).length) { + requestOptions.data = reqHasFile ? reqFormData : JSON.stringify(reqDict); + requestOptions.contentType = reqHasFile ? false : 'application/json; charset=utf-8'; + } + + this.authentications.default.applyToRequest(requestOptions); + + let dfd = $.Deferred(); + $.ajax(requestOptions).then( + (data: Order, textStatus: string, jqXHR: JQueryXHR) => + dfd.resolve({ response: jqXHR, body: data }), + (xhr: JQueryXHR, textStatus: string, errorThrown: string) => + dfd.reject({ response: xhr, body: errorThrown }) + ); + return dfd.promise(); + } +} +export enum UserApiApiKeys { + api_key, +} + +export class UserApi { + protected basePath = defaultBasePath; + protected defaultHeaders : any = {}; + + protected authentications = { + 'default': new VoidAuth(), + 'api_key': new ApiKeyAuth('header', 'api_key'), + 'petstore_auth': new OAuth(), + } + + constructor(basePath?: string); + constructor(basePathOrUsername: string, password?: string, basePath?: string) { + if (password) { + if (basePath) { + this.basePath = basePath; + } + } else { + if (basePathOrUsername) { + this.basePath = basePathOrUsername + } + } + } + + public setApiKey(key: UserApiApiKeys, value: string) { + this.authentications[UserApiApiKeys[key]].apiKey = value; + } + + set accessToken(token: string) { + this.authentications.petstore_auth.accessToken = token; + } + private extendObj(objA: T2, objB: T2): T1|T2 { + for(let key in objB){ + if(objB.hasOwnProperty(key)){ + objA[key] = objB[key]; + } + } + return objA; + } + + /** + * Create user + * This can only be done by the logged in user. + * @param body Created user object + */ + public createUser (body?: User) : JQueryPromise<{ response: JQueryXHR; body?: any; }> { + let localVarPath = this.basePath + '/user'; + let queryParameters: any = {}; + let headerParams: any = this.extendObj({}, this.defaultHeaders); + + + + localVarPath = localVarPath + "?" + $.param(queryParameters); + + + let reqDict = body; + let reqFormData = new FormData(); + reqFormData.append('body', body); + let reqHasFile = false; + + let requestOptions: JQueryAjaxSettings = { + url: localVarPath, + type: 'POST', + headers: headerParams, + processData: false + }; + + if (Object.keys(reqDict).length) { + requestOptions.data = reqHasFile ? reqFormData : JSON.stringify(reqDict); + requestOptions.contentType = reqHasFile ? false : 'application/json; charset=utf-8'; + } + + this.authentications.default.applyToRequest(requestOptions); + + let dfd = $.Deferred(); + $.ajax(requestOptions).then( + (data: , textStatus: string, jqXHR: JQueryXHR) => + dfd.resolve({ response: jqXHR, body: data }), + (xhr: JQueryXHR, textStatus: string, errorThrown: string) => + dfd.reject({ response: xhr, body: errorThrown }) + ); + return dfd.promise(); + } + /** + * Creates list of users with given input array + * + * @param body List of user object + */ + public createUsersWithArrayInput (body?: Array) : JQueryPromise<{ response: JQueryXHR; body?: any; }> { + let localVarPath = this.basePath + '/user/createWithArray'; + let queryParameters: any = {}; + let headerParams: any = this.extendObj({}, this.defaultHeaders); + + + + localVarPath = localVarPath + "?" + $.param(queryParameters); + + + let reqDict = body; + let reqFormData = new FormData(); + reqFormData.append('body', body); + let reqHasFile = false; + + let requestOptions: JQueryAjaxSettings = { + url: localVarPath, + type: 'POST', + headers: headerParams, + processData: false + }; + + if (Object.keys(reqDict).length) { + requestOptions.data = reqHasFile ? reqFormData : JSON.stringify(reqDict); + requestOptions.contentType = reqHasFile ? false : 'application/json; charset=utf-8'; + } + + this.authentications.default.applyToRequest(requestOptions); + + let dfd = $.Deferred(); + $.ajax(requestOptions).then( + (data: , textStatus: string, jqXHR: JQueryXHR) => + dfd.resolve({ response: jqXHR, body: data }), + (xhr: JQueryXHR, textStatus: string, errorThrown: string) => + dfd.reject({ response: xhr, body: errorThrown }) + ); + return dfd.promise(); + } + /** + * Creates list of users with given input array + * + * @param body List of user object + */ + public createUsersWithListInput (body?: Array) : JQueryPromise<{ response: JQueryXHR; body?: any; }> { + let localVarPath = this.basePath + '/user/createWithList'; + let queryParameters: any = {}; + let headerParams: any = this.extendObj({}, this.defaultHeaders); + + + + localVarPath = localVarPath + "?" + $.param(queryParameters); + + + let reqDict = body; + let reqFormData = new FormData(); + reqFormData.append('body', body); + let reqHasFile = false; + + let requestOptions: JQueryAjaxSettings = { + url: localVarPath, + type: 'POST', + headers: headerParams, + processData: false + }; + + if (Object.keys(reqDict).length) { + requestOptions.data = reqHasFile ? reqFormData : JSON.stringify(reqDict); + requestOptions.contentType = reqHasFile ? false : 'application/json; charset=utf-8'; + } + + this.authentications.default.applyToRequest(requestOptions); + + let dfd = $.Deferred(); + $.ajax(requestOptions).then( + (data: , textStatus: string, jqXHR: JQueryXHR) => + dfd.resolve({ response: jqXHR, body: data }), + (xhr: JQueryXHR, textStatus: string, errorThrown: string) => + dfd.reject({ response: xhr, body: errorThrown }) + ); + return dfd.promise(); + } + /** + * Delete user + * This can only be done by the logged in user. + * @param username The name that needs to be deleted + */ + public deleteUser (username: string) : JQueryPromise<{ response: JQueryXHR; body?: any; }> { + let localVarPath = this.basePath + '/user/{username}' + .replace('{' + 'username' + '}', String(username)); + let queryParameters: any = {}; + let headerParams: any = this.extendObj({}, this.defaultHeaders); + + + // verify required parameter 'username' is not null or undefined + if (username === null || username === undefined) { + throw new Error('Required parameter username was null or undefined when calling deleteUser.'); + } + + + localVarPath = localVarPath + "?" + $.param(queryParameters); + + + let reqHasFile = false; + let reqDict = {}; + let reqFormData = new FormData(); + + let requestOptions: JQueryAjaxSettings = { + url: localVarPath, + type: 'DELETE', + headers: headerParams, + processData: false + }; + + if (Object.keys(reqDict).length) { + requestOptions.data = reqHasFile ? reqFormData : JSON.stringify(reqDict); + requestOptions.contentType = reqHasFile ? false : 'application/json; charset=utf-8'; + } + + this.authentications.default.applyToRequest(requestOptions); + + let dfd = $.Deferred(); + $.ajax(requestOptions).then( + (data: , textStatus: string, jqXHR: JQueryXHR) => + dfd.resolve({ response: jqXHR, body: data }), + (xhr: JQueryXHR, textStatus: string, errorThrown: string) => + dfd.reject({ response: xhr, body: errorThrown }) + ); + return dfd.promise(); + } + /** + * Get user by user name + * + * @param username The name that needs to be fetched. Use user1 for testing. + */ + public getUserByName (username: string) : JQueryPromise<{ response: JQueryXHR; body: User; }> { + let localVarPath = this.basePath + '/user/{username}' + .replace('{' + 'username' + '}', String(username)); + let queryParameters: any = {}; + let headerParams: any = this.extendObj({}, this.defaultHeaders); + + + // verify required parameter 'username' is not null or undefined + if (username === null || username === undefined) { + throw new Error('Required parameter username was null or undefined when calling getUserByName.'); + } + + + localVarPath = localVarPath + "?" + $.param(queryParameters); + + + let reqHasFile = false; + let reqDict = {}; + let reqFormData = new FormData(); + + let requestOptions: JQueryAjaxSettings = { + url: localVarPath, + type: 'GET', + headers: headerParams, + processData: false + }; + + if (Object.keys(reqDict).length) { + requestOptions.data = reqHasFile ? reqFormData : JSON.stringify(reqDict); + requestOptions.contentType = reqHasFile ? false : 'application/json; charset=utf-8'; + } + + this.authentications.default.applyToRequest(requestOptions); + + let dfd = $.Deferred(); + $.ajax(requestOptions).then( + (data: User, textStatus: string, jqXHR: JQueryXHR) => + dfd.resolve({ response: jqXHR, body: data }), + (xhr: JQueryXHR, textStatus: string, errorThrown: string) => + dfd.reject({ response: xhr, body: errorThrown }) + ); + return dfd.promise(); + } + /** + * Logs user into the system + * + * @param username The user name for login + * @param password The password for login in clear text + */ + public loginUser (username?: string, password?: string) : JQueryPromise<{ response: JQueryXHR; body: string; }> { + let localVarPath = this.basePath + '/user/login'; + let queryParameters: any = {}; + let headerParams: any = this.extendObj({}, this.defaultHeaders); + + + if (username !== undefined) { + queryParameters['username'] = username; + } + + if (password !== undefined) { + queryParameters['password'] = password; + } + + + localVarPath = localVarPath + "?" + $.param(queryParameters); + + + let reqHasFile = false; + let reqDict = {}; + let reqFormData = new FormData(); + + let requestOptions: JQueryAjaxSettings = { + url: localVarPath, + type: 'GET', + headers: headerParams, + processData: false + }; + + if (Object.keys(reqDict).length) { + requestOptions.data = reqHasFile ? reqFormData : JSON.stringify(reqDict); + requestOptions.contentType = reqHasFile ? false : 'application/json; charset=utf-8'; + } + + this.authentications.default.applyToRequest(requestOptions); + + let dfd = $.Deferred(); + $.ajax(requestOptions).then( + (data: string, textStatus: string, jqXHR: JQueryXHR) => + dfd.resolve({ response: jqXHR, body: data }), + (xhr: JQueryXHR, textStatus: string, errorThrown: string) => + dfd.reject({ response: xhr, body: errorThrown }) + ); + return dfd.promise(); + } + /** + * Logs out current logged in user session + * + */ + public logoutUser () : JQueryPromise<{ response: JQueryXHR; body?: any; }> { + let localVarPath = this.basePath + '/user/logout'; + let queryParameters: any = {}; + let headerParams: any = this.extendObj({}, this.defaultHeaders); + + + + localVarPath = localVarPath + "?" + $.param(queryParameters); + + + let reqHasFile = false; + let reqDict = {}; + let reqFormData = new FormData(); + + let requestOptions: JQueryAjaxSettings = { + url: localVarPath, + type: 'GET', + headers: headerParams, + processData: false + }; + + if (Object.keys(reqDict).length) { + requestOptions.data = reqHasFile ? reqFormData : JSON.stringify(reqDict); + requestOptions.contentType = reqHasFile ? false : 'application/json; charset=utf-8'; + } + + this.authentications.default.applyToRequest(requestOptions); + + let dfd = $.Deferred(); + $.ajax(requestOptions).then( + (data: , textStatus: string, jqXHR: JQueryXHR) => + dfd.resolve({ response: jqXHR, body: data }), + (xhr: JQueryXHR, textStatus: string, errorThrown: string) => + dfd.reject({ response: xhr, body: errorThrown }) + ); + return dfd.promise(); + } + /** + * Updated user + * This can only be done by the logged in user. + * @param username name that need to be deleted + * @param body Updated user object + */ + public updateUser (username: string, body?: User) : JQueryPromise<{ response: JQueryXHR; body?: any; }> { + let localVarPath = this.basePath + '/user/{username}' + .replace('{' + 'username' + '}', String(username)); + let queryParameters: any = {}; + let headerParams: any = this.extendObj({}, this.defaultHeaders); + + + // verify required parameter 'username' is not null or undefined + if (username === null || username === undefined) { + throw new Error('Required parameter username was null or undefined when calling updateUser.'); + } + + + localVarPath = localVarPath + "?" + $.param(queryParameters); + + + let reqDict = body; + let reqFormData = new FormData(); + reqFormData.append('body', body); + let reqHasFile = false; + + let requestOptions: JQueryAjaxSettings = { + url: localVarPath, + type: 'PUT', + headers: headerParams, + processData: false + }; + + if (Object.keys(reqDict).length) { + requestOptions.data = reqHasFile ? reqFormData : JSON.stringify(reqDict); + requestOptions.contentType = reqHasFile ? false : 'application/json; charset=utf-8'; + } + + this.authentications.default.applyToRequest(requestOptions); + + let dfd = $.Deferred(); + $.ajax(requestOptions).then( + (data: , textStatus: string, jqXHR: JQueryXHR) => + dfd.resolve({ response: jqXHR, body: data }), + (xhr: JQueryXHR, textStatus: string, errorThrown: string) => + dfd.reject({ response: xhr, body: errorThrown }) + ); + return dfd.promise(); + } +} diff --git a/samples/client/petstore/typescript-jquery/npm/git_push.sh b/samples/client/petstore/typescript-jquery/npm/git_push.sh new file mode 100644 index 000000000000..ed374619b139 --- /dev/null +++ b/samples/client/petstore/typescript-jquery/npm/git_push.sh @@ -0,0 +1,52 @@ +#!/bin/sh +# ref: https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/ +# +# Usage example: /bin/sh ./git_push.sh wing328 swagger-petstore-perl "minor update" + +git_user_id=$1 +git_repo_id=$2 +release_note=$3 + +if [ "$git_user_id" = "" ]; then + git_user_id="GIT_USER_ID" + echo "[INFO] No command line input provided. Set \$git_user_id to $git_user_id" +fi + +if [ "$git_repo_id" = "" ]; then + git_repo_id="GIT_REPO_ID" + echo "[INFO] No command line input provided. Set \$git_repo_id to $git_repo_id" +fi + +if [ "$release_note" = "" ]; then + release_note="Minor update" + echo "[INFO] No command line input provided. Set \$release_note to $release_note" +fi + +# Initialize the local directory as a Git repository +git init + +# Adds the files in the local repository and stages them for commit. +git add . + +# Commits the tracked changes and prepares them to be pushed to a remote repository. +git commit -m "$release_note" + +# Sets the new remote +git_remote=`git remote` +if [ "$git_remote" = "" ]; then # git remote not defined + + if [ "$GIT_TOKEN" = "" ]; then + echo "[INFO] \$GIT_TOKEN (environment variable) is not set. Using the git crediential in your environment." + git remote add origin https://github.com/${git_user_id}/${git_repo_id}.git + else + git remote add origin https://${git_user_id}:${GIT_TOKEN}@github.com/${git_user_id}/${git_repo_id}.git + fi + +fi + +git pull origin master + +# Pushes (Forces) the changes in the local repository up to the remote repository +echo "Git pushing to https://github.com/${git_user_id}/${git_repo_id}.git" +git push origin master 2>&1 | grep -v 'To https' + diff --git a/samples/client/petstore/typescript-jquery/npm/package.json b/samples/client/petstore/typescript-jquery/npm/package.json new file mode 100644 index 000000000000..89b35a0787a0 --- /dev/null +++ b/samples/client/petstore/typescript-jquery/npm/package.json @@ -0,0 +1,22 @@ +{ + "name": "@swagger/angular2-typescript-petstore", + "version": "0.0.1-SNAPSHOT.201703061507", + "description": "JQuery client for @swagger/angular2-typescript-petstore", + "main": "api.js", + "scripts": { + "build": "tsc" + }, + "author": "Swagger Codegen Contributors", + "license": "MIT", + "dependencies": { + "bluebird": "^3.3.5", + "request": "^2.72.0" + }, + "devDependencies": { + "typescript": "^1.8.10", + "typings": "^0.8.1" + }, + "publishConfig":{ + "registry":"https://skimdb.npmjs.com/registry" + } +} diff --git a/samples/client/petstore/typescript-jquery/npm/pom.xml b/samples/client/petstore/typescript-jquery/npm/pom.xml new file mode 100644 index 000000000000..5e9f6989d264 --- /dev/null +++ b/samples/client/petstore/typescript-jquery/npm/pom.xml @@ -0,0 +1,46 @@ + + 4.0.0 + io.swagger + TSJQueryNPMPestoreClientTests + pom + 1.0-SNAPSHOT + TS jQuery npm Petstore Client + + + + maven-dependency-plugin + + + package + + copy-dependencies + + + ${project.build.directory} + + + + + + org.codehaus.mojo + exec-maven-plugin + 1.2.1 + + + npm-install + pre-integration-test + + exec + + + npm + + install + + + + + + + + diff --git a/samples/client/petstore/typescript-jquery/npm/tsconfig.json b/samples/client/petstore/typescript-jquery/npm/tsconfig.json new file mode 100644 index 000000000000..2dd166566e97 --- /dev/null +++ b/samples/client/petstore/typescript-jquery/npm/tsconfig.json @@ -0,0 +1,18 @@ +{ + "compilerOptions": { + "module": "commonjs", + "noImplicitAny": false, + "suppressImplicitAnyIndexErrors": true, + "target": "ES5", + "moduleResolution": "node", + "removeComments": true, + "sourceMap": true, + "noLib": false, + "declaration": true + }, + "files": [ + "api.ts", + "typings/main.d.ts" + ] +} + diff --git a/samples/client/petstore/typescript-jquery/npm/typings.json b/samples/client/petstore/typescript-jquery/npm/typings.json new file mode 100644 index 000000000000..76c4cc8e6af3 --- /dev/null +++ b/samples/client/petstore/typescript-jquery/npm/typings.json @@ -0,0 +1,10 @@ +{ + "ambientDependencies": { + "bluebird": "registry:dt/bluebird#2.0.0+20160319051630", + "core-js": "registry:dt/core-js#0.0.0+20160317120654", + "node": "registry:dt/node#4.0.0+20160423143914" + }, + "dependencies": { + "request": "registry:npm/request#2.69.0+20160304121250" + } +} \ No newline at end of file diff --git a/samples/server/petstore/nodejs-google-cloud-functions/controllers/PetService.js b/samples/server/petstore/nodejs-google-cloud-functions/controllers/PetService.js index f9c7f30378b2..36f343427413 100644 --- a/samples/server/petstore/nodejs-google-cloud-functions/controllers/PetService.js +++ b/samples/server/petstore/nodejs-google-cloud-functions/controllers/PetService.js @@ -35,16 +35,16 @@ exports.findPetsByStatus = function(args, res, next) { examples['application/json'] = [ { "photoUrls" : [ "aeiou" ], "name" : "doggie", - "id" : 123456789, + "id" : 0, "category" : { "name" : "aeiou", - "id" : 123456789 + "id" : 6 }, "tags" : [ { "name" : "aeiou", - "id" : 123456789 + "id" : 1 } ], - "status" : "aeiou" + "status" : "available" } ]; if (Object.keys(examples).length > 0) { res.setHeader('Content-Type', 'application/json'); @@ -66,16 +66,16 @@ exports.findPetsByTags = function(args, res, next) { examples['application/json'] = [ { "photoUrls" : [ "aeiou" ], "name" : "doggie", - "id" : 123456789, + "id" : 0, "category" : { "name" : "aeiou", - "id" : 123456789 + "id" : 6 }, "tags" : [ { "name" : "aeiou", - "id" : 123456789 + "id" : 1 } ], - "status" : "aeiou" + "status" : "available" } ]; if (Object.keys(examples).length > 0) { res.setHeader('Content-Type', 'application/json'); @@ -97,16 +97,16 @@ exports.getPetById = function(args, res, next) { examples['application/json'] = { "photoUrls" : [ "aeiou" ], "name" : "doggie", - "id" : 123456789, + "id" : 0, "category" : { "name" : "aeiou", - "id" : 123456789 + "id" : 6 }, "tags" : [ { "name" : "aeiou", - "id" : 123456789 + "id" : 1 } ], - "status" : "aeiou" + "status" : "available" }; if (Object.keys(examples).length > 0) { res.setHeader('Content-Type', 'application/json'); @@ -152,7 +152,7 @@ exports.uploadFile = function(args, res, next) { **/ var examples = {}; examples['application/json'] = { - "code" : 123, + "code" : 0, "type" : "aeiou", "message" : "aeiou" }; diff --git a/samples/server/petstore/nodejs-google-cloud-functions/controllers/StoreService.js b/samples/server/petstore/nodejs-google-cloud-functions/controllers/StoreService.js index d56502daf03f..be99ec7acbc8 100644 --- a/samples/server/petstore/nodejs-google-cloud-functions/controllers/StoreService.js +++ b/samples/server/petstore/nodejs-google-cloud-functions/controllers/StoreService.js @@ -20,7 +20,7 @@ exports.getInventory = function(args, res, next) { **/ var examples = {}; examples['application/json'] = { - "key" : 123 + "key" : 0 }; if (Object.keys(examples).length > 0) { res.setHeader('Content-Type', 'application/json'); @@ -40,12 +40,12 @@ exports.getOrderById = function(args, res, next) { **/ var examples = {}; examples['application/json'] = { - "petId" : 123456789, - "quantity" : 123, - "id" : 123456789, + "petId" : 6, + "quantity" : 1, + "id" : 0, "shipDate" : "2000-01-23T04:56:07.000+00:00", - "complete" : true, - "status" : "aeiou" + "complete" : false, + "status" : "placed" }; if (Object.keys(examples).length > 0) { res.setHeader('Content-Type', 'application/json'); @@ -65,12 +65,12 @@ exports.placeOrder = function(args, res, next) { **/ var examples = {}; examples['application/json'] = { - "petId" : 123456789, - "quantity" : 123, - "id" : 123456789, + "petId" : 6, + "quantity" : 1, + "id" : 0, "shipDate" : "2000-01-23T04:56:07.000+00:00", - "complete" : true, - "status" : "aeiou" + "complete" : false, + "status" : "placed" }; if (Object.keys(examples).length > 0) { res.setHeader('Content-Type', 'application/json'); diff --git a/samples/server/petstore/nodejs-google-cloud-functions/controllers/UserService.js b/samples/server/petstore/nodejs-google-cloud-functions/controllers/UserService.js index 5b4fe750d7da..d15268eee682 100644 --- a/samples/server/petstore/nodejs-google-cloud-functions/controllers/UserService.js +++ b/samples/server/petstore/nodejs-google-cloud-functions/controllers/UserService.js @@ -57,9 +57,9 @@ exports.getUserByName = function(args, res, next) { "firstName" : "aeiou", "lastName" : "aeiou", "password" : "aeiou", - "userStatus" : 123, + "userStatus" : 6, "phone" : "aeiou", - "id" : 123456789, + "id" : 0, "email" : "aeiou", "username" : "aeiou" }; diff --git a/samples/server/petstore/nodejs/service/PetService.js b/samples/server/petstore/nodejs/service/PetService.js index 68f2925b044b..c89674e7cf54 100644 --- a/samples/server/petstore/nodejs/service/PetService.js +++ b/samples/server/petstore/nodejs/service/PetService.js @@ -43,14 +43,14 @@ exports.findPetsByStatus = function(status) { examples['application/json'] = [ { "photoUrls" : [ "aeiou" ], "name" : "doggie", - "id" : 6, + "id" : 0, "category" : { "name" : "aeiou", - "id" : 8 + "id" : 6 }, "tags" : [ { "name" : "aeiou", - "id" : 6 + "id" : 1 } ], "status" : "available" } ]; @@ -76,14 +76,14 @@ exports.findPetsByTags = function(tags) { examples['application/json'] = [ { "photoUrls" : [ "aeiou" ], "name" : "doggie", - "id" : 7, + "id" : 0, "category" : { "name" : "aeiou", - "id" : 9 + "id" : 6 }, "tags" : [ { "name" : "aeiou", - "id" : 2 + "id" : 1 } ], "status" : "available" } ]; @@ -109,14 +109,14 @@ exports.getPetById = function(petId) { examples['application/json'] = { "photoUrls" : [ "aeiou" ], "name" : "doggie", - "id" : 8, + "id" : 0, "category" : { "name" : "aeiou", - "id" : 4 + "id" : 6 }, "tags" : [ { "name" : "aeiou", - "id" : 3 + "id" : 1 } ], "status" : "available" }; @@ -172,7 +172,7 @@ exports.uploadFile = function(petId,additionalMetadata,file) { return new Promise(function(resolve, reject) { var examples = {}; examples['application/json'] = { - "code" : 8, + "code" : 0, "type" : "aeiou", "message" : "aeiou" }; diff --git a/samples/server/petstore/nodejs/service/StoreService.js b/samples/server/petstore/nodejs/service/StoreService.js index a3ddf1925612..e959c7ec9fac 100644 --- a/samples/server/petstore/nodejs/service/StoreService.js +++ b/samples/server/petstore/nodejs/service/StoreService.js @@ -25,7 +25,7 @@ exports.getInventory = function() { return new Promise(function(resolve, reject) { var examples = {}; examples['application/json'] = { - "key" : 1 + "key" : 0 }; if (Object.keys(examples).length > 0) { resolve(examples[Object.keys(examples)[0]]); @@ -47,9 +47,9 @@ exports.getOrderById = function(orderId) { return new Promise(function(resolve, reject) { var examples = {}; examples['application/json'] = { - "petId" : 8, - "quantity" : 8, - "id" : 5, + "petId" : 6, + "quantity" : 1, + "id" : 0, "shipDate" : "2000-01-23T04:56:07.000+00:00", "complete" : false, "status" : "placed" @@ -74,9 +74,9 @@ exports.placeOrder = function(body) { return new Promise(function(resolve, reject) { var examples = {}; examples['application/json'] = { - "petId" : 7, - "quantity" : 0, - "id" : 1, + "petId" : 6, + "quantity" : 1, + "id" : 0, "shipDate" : "2000-01-23T04:56:07.000+00:00", "complete" : false, "status" : "placed" diff --git a/samples/server/petstore/nodejs/service/UserService.js b/samples/server/petstore/nodejs/service/UserService.js index 0f67f912573e..afdc528f0da0 100644 --- a/samples/server/petstore/nodejs/service/UserService.js +++ b/samples/server/petstore/nodejs/service/UserService.js @@ -71,9 +71,9 @@ exports.getUserByName = function(username) { "firstName" : "aeiou", "lastName" : "aeiou", "password" : "aeiou", - "userStatus" : 8, + "userStatus" : 6, "phone" : "aeiou", - "id" : 5, + "id" : 0, "email" : "aeiou", "username" : "aeiou" };