From 063288be43304002fcc9ae4cabf3e41bb2601f11 Mon Sep 17 00:00:00 2001 From: Ben Herila Date: Mon, 20 Feb 2017 14:26:58 -0800 Subject: [PATCH 1/8] Typescript jquery client wip --- .../TypeScriptJqueryClientCodegen.java | 110 ++++++++ .../services/io.swagger.codegen.CodegenConfig | 1 + .../resources/typescript-jquery/api.mustache | 249 ++++++++++++++++++ .../typescript-jquery/git_push.sh.mustache | 52 ++++ .../typescript-jquery/package.mustache | 22 ++ .../typescript-jquery/tsconfig.mustache | 18 ++ .../typescript-jquery/typings.mustache | 10 + 7 files changed, 462 insertions(+) create mode 100644 modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/TypeScriptJqueryClientCodegen.java create mode 100644 modules/swagger-codegen/src/main/resources/typescript-jquery/api.mustache create mode 100755 modules/swagger-codegen/src/main/resources/typescript-jquery/git_push.sh.mustache create mode 100644 modules/swagger-codegen/src/main/resources/typescript-jquery/package.mustache create mode 100644 modules/swagger-codegen/src/main/resources/typescript-jquery/tsconfig.mustache create mode 100644 modules/swagger-codegen/src/main/resources/typescript-jquery/typings.mustache 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 00000000000..eb319344781 --- /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 876409b50b4..e19421d3bc1 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 @@ -50,6 +50,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/typescript-jquery/api.mustache b/modules/swagger-codegen/src/main/resources/typescript-jquery/api.mustache new file mode 100644 index 00000000000..913a84e0f86 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/typescript-jquery/api.mustache @@ -0,0 +1,249 @@ +declare var $: any; + +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}}{{classname}}.{{{datatypeWithEnum}}}{{/isEnum}}{{^isEnum}}{{{datatype}}}{{/isEnum}}; +{{/vars}} +} + +{{#hasEnums}} +export namespace {{classname}} { +{{#vars}} +{{#isEnum}} + export enum {{datatypeWithEnum}} { {{#allowableValues}}{{#values}} + {{datatypeWithEnum}}_{{.}} = '{{.}}'{{^-last}},{{/-last}}{{/values}}{{/allowableValues}} + } +{{/isEnum}} +{{/vars}} +} +{{/hasEnums}} +{{/model}} +{{/models}} + +export interface Authentication { + /** + * Apply authentication settings to header and query params. + */ + applyToRequest(requestOptions: request.Options): 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: request.Options): void { + requestOptions.headers[this.paramName] = this.apiKey; + } +} + +export class OAuth implements Authentication { + public accessToken: string; + + applyToRequest(requestOptions: request.Options): void { + requestOptions.headers["Authorization"] = "Bearer " + this.accessToken; + } +} + +export class VoidAuth implements Authentication { + public username: string; + public password: string; + applyToRequest(requestOptions: request.Options): 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: T1, objB: 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}}) : Promise<{ response: any /*jqXHR*/; {{#returnType}}body: {{{returnType}}}; {{/returnType}}{{^returnType}}body?: any; {{/returnType}} }> { + const localVarPath = this.basePath + '{{path}}'{{#pathParams}} + .replace('{' + '{{baseName}}' + '}', String({{paramName}})){{/pathParams}}; + let queryParameters: any = {}; + let headerParams: any = this.extendObj({}, this.defaultHeaders); + let formParams: any = {}; + +{{#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}} +{{#formParams}} + if ({{paramName}} !== undefined) { + formParams['{{baseName}}'] = {{paramName}}; + } + +{{/formParams}} + let requestOptions = { + url: localVarPath, + type: '{{httpMethod}}', + headers: headerParams, +{{#isFile}} + enctype: 'multipart/form-data', + processData: false, // Important! + contentType: false, +{{/isFile}} +{{^isFile}} + json: true, +{{/isFile}} +{{#bodyParam}} + data: formParams +{{/bodyParam}} + }; + +{{#authMethods}} + this.authentications.{{name}}.applyToRequest(requestOptions); + +{{/authMethods}} + this.authentications.default.applyToRequest(requestOptions); + + return new Promise((resolve, reject) => { + $.ajax(requestOptions).then( + (data: {{{returnType}}}, textStatus: string, jqXHR: any) => + resolve({ response: jqXHR, body: data }), + (xhr: any, textStatus: string, errorThrown: string) => + reject({ response: jqXHR, body: errorThrown }) + ); + }); + + } +{{/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 00000000000..e153ce23ecf --- /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 00000000000..732777196fc --- /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 00000000000..1a3bd00183a --- /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 00000000000..76c4cc8e6af --- /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 From 13876bf9519ef01a493a84cc91d11bedadf88433 Mon Sep 17 00:00:00 2001 From: Ben Herila Date: Tue, 21 Feb 2017 14:00:42 -0800 Subject: [PATCH 2/8] typescript-jquery wip --- .../resources/typescript-jquery/api.mustache | 46 +++++++++++++++++-- 1 file changed, 41 insertions(+), 5 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/typescript-jquery/api.mustache b/modules/swagger-codegen/src/main/resources/typescript-jquery/api.mustache index 913a84e0f86..d16a94bf6a0 100644 --- a/modules/swagger-codegen/src/main/resources/typescript-jquery/api.mustache +++ b/modules/swagger-codegen/src/main/resources/typescript-jquery/api.mustache @@ -40,11 +40,47 @@ export namespace {{classname}} { {{/model}} {{/models}} +export interface IOptions { + accepts?: any; + async?: boolean; + cache?: boolean; + complete? (jqXHR: any, textStatus: string): any; + contents?: { [key: string]: any; }; + contentType?: any; + context?: any; + converters?: { [key: string]: any; }; + crossDomain?: boolean; + data?: any; + dataFilter? (data: any, ty: any): any; + dataType?: string; + error? (jqXHR: any, textStatus: string, errorThrown: string): any; + global?: boolean; + headers?: { [key: string]: any; }; + ifModified?: boolean; + isLocal?: boolean; + jsonp?: any; + jsonpCallback?: any; + method?: string; + mimeType?: string; + password?: string; + processData?: boolean; + scriptCharset?: string; + statusCode?: { [key: string]: any; }; + success? (data: any, textStatus: string, jqXHR: any): any; + timeout?: number; + traditional?: boolean; + type?: string; + url?: string; + username?: string; + xhr?: any; + xhrFields?: { [key: string]: any; }; +} + export interface Authentication { /** * Apply authentication settings to header and query params. */ - applyToRequest(requestOptions: request.Options): void; + applyToRequest(requestOptions: IOptions): void; } export class HttpBasicAuth implements Authentication { @@ -62,7 +98,7 @@ export class ApiKeyAuth implements Authentication { constructor(private location: string, private paramName: string) { } - applyToRequest(requestOptions: request.Options): void { + applyToRequest(requestOptions: IOptions): void { requestOptions.headers[this.paramName] = this.apiKey; } } @@ -70,7 +106,7 @@ export class ApiKeyAuth implements Authentication { export class OAuth implements Authentication { public accessToken: string; - applyToRequest(requestOptions: request.Options): void { + applyToRequest(requestOptions: IOptions): void { requestOptions.headers["Authorization"] = "Bearer " + this.accessToken; } } @@ -78,7 +114,7 @@ export class OAuth implements Authentication { export class VoidAuth implements Authentication { public username: string; public password: string; - applyToRequest(requestOptions: request.Options): void { + applyToRequest(requestOptions: IOptions): void { // Do nothing } } @@ -178,7 +214,7 @@ export class {{classname}} { {{#allParams}}* @param {{paramName}} {{description}} {{/allParams}}*/ public {{nickname}} ({{#allParams}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) : Promise<{ response: any /*jqXHR*/; {{#returnType}}body: {{{returnType}}}; {{/returnType}}{{^returnType}}body?: any; {{/returnType}} }> { - const localVarPath = this.basePath + '{{path}}'{{#pathParams}} + let localVarPath = this.basePath + '{{path}}'{{#pathParams}} .replace('{' + '{{baseName}}' + '}', String({{paramName}})){{/pathParams}}; let queryParameters: any = {}; let headerParams: any = this.extendObj({}, this.defaultHeaders); From e179c7009409ca4539727d702df812887c899e54 Mon Sep 17 00:00:00 2001 From: Ben Herila Date: Tue, 21 Feb 2017 14:16:54 -0800 Subject: [PATCH 3/8] Fix typo --- .../src/main/resources/typescript-jquery/api.mustache | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/swagger-codegen/src/main/resources/typescript-jquery/api.mustache b/modules/swagger-codegen/src/main/resources/typescript-jquery/api.mustache index d16a94bf6a0..efcbd71507a 100644 --- a/modules/swagger-codegen/src/main/resources/typescript-jquery/api.mustache +++ b/modules/swagger-codegen/src/main/resources/typescript-jquery/api.mustache @@ -273,7 +273,7 @@ export class {{classname}} { (data: {{{returnType}}}, textStatus: string, jqXHR: any) => resolve({ response: jqXHR, body: data }), (xhr: any, textStatus: string, errorThrown: string) => - reject({ response: jqXHR, body: errorThrown }) + reject({ response: xhr, body: errorThrown }) ); }); From 66567ffadb2d10be2ccf29d9cd46763b1eb7424d Mon Sep 17 00:00:00 2001 From: Ben Herila Date: Tue, 21 Feb 2017 15:24:52 -0800 Subject: [PATCH 4/8] typescript-jquery wip --- .../resources/typescript-jquery/api.mustache | 52 ++++++++++--------- 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/typescript-jquery/api.mustache b/modules/swagger-codegen/src/main/resources/typescript-jquery/api.mustache index efcbd71507a..e63245aafff 100644 --- a/modules/swagger-codegen/src/main/resources/typescript-jquery/api.mustache +++ b/modules/swagger-codegen/src/main/resources/typescript-jquery/api.mustache @@ -1,4 +1,4 @@ -declare var $: any; +import * as $ from 'jquery'; let defaultBasePath = '{{basePath}}'; @@ -10,19 +10,19 @@ let defaultBasePath = '{{basePath}}'; {{#models}} {{#model}} -{{#description}} -/** -* {{{description}}} -*/ -{{/description}} -export class {{classname}} {{#parent}}extends {{{parent}}} {{/parent}}{ -{{#vars}} {{#description}} /** * {{{description}}} */ {{/description}} - '{{name}}': {{#isEnum}}{{classname}}.{{{datatypeWithEnum}}}{{/isEnum}}{{^isEnum}}{{{datatype}}}{{/isEnum}}; +export class {{classname}} {{#parent}}extends {{{parent}}} {{/parent}}{ +{{#vars}} + {{#description}} + /** + * {{{description}}} + */ + {{/description}} + '{{name}}': {{#isEnum}}{{{datatypeWithEnum}}}{{/isEnum}}{{^isEnum}}{{{datatype}}}{{/isEnum}}; {{/vars}} } @@ -30,8 +30,12 @@ export class {{classname}} {{#parent}}extends {{{parent}}} {{/parent}}{ export namespace {{classname}} { {{#vars}} {{#isEnum}} - export enum {{datatypeWithEnum}} { {{#allowableValues}}{{#values}} - {{datatypeWithEnum}}_{{.}} = '{{.}}'{{^-last}},{{/-last}}{{/values}}{{/allowableValues}} + export enum {{enumName}} { + {{#allowableValues}} + {{#enumVars}} + {{name}} = {{{value}}}{{^-last}},{{/-last}} + {{/enumVars}} + {{/allowableValues}} } {{/isEnum}} {{/vars}} @@ -199,21 +203,22 @@ export class {{classname}} { } {{/isOAuth}} {{/authMethods}} - private extendObj(objA: T1, objB: T2) { + private extendObj(objA: T2, objB: T2): T1|T2 { for(let key in objB){ if(objB.hasOwnProperty(key)){ - objA[key] = objB[key]; + objA[key] = objB[key]; } } - return objA; + return objA; } + {{#operation}} /** * {{summary}} * {{notes}} {{#allParams}}* @param {{paramName}} {{description}} {{/allParams}}*/ - public {{nickname}} ({{#allParams}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) : Promise<{ response: any /*jqXHR*/; {{#returnType}}body: {{{returnType}}}; {{/returnType}}{{^returnType}}body?: any; {{/returnType}} }> { + 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 = {}; @@ -268,15 +273,14 @@ export class {{classname}} { {{/authMethods}} this.authentications.default.applyToRequest(requestOptions); - return new Promise((resolve, reject) => { - $.ajax(requestOptions).then( - (data: {{{returnType}}}, textStatus: string, jqXHR: any) => - resolve({ response: jqXHR, body: data }), - (xhr: any, textStatus: string, errorThrown: string) => - reject({ response: xhr, body: errorThrown }) - ); - }); - + 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}} } From f3b38f2b4f15d3ced06bc979862ad588c6a70a66 Mon Sep 17 00:00:00 2001 From: Ben Herila Date: Mon, 6 Mar 2017 15:03:46 -0800 Subject: [PATCH 5/8] Fix formatting --- .../resources/typescript-jquery/api.mustache | 316 ++++++++---------- 1 file changed, 148 insertions(+), 168 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/typescript-jquery/api.mustache b/modules/swagger-codegen/src/main/resources/typescript-jquery/api.mustache index e63245aafff..9649528630b 100644 --- a/modules/swagger-codegen/src/main/resources/typescript-jquery/api.mustache +++ b/modules/swagger-codegen/src/main/resources/typescript-jquery/api.mustache @@ -11,18 +11,18 @@ let defaultBasePath = '{{basePath}}'; {{#models}} {{#model}} {{#description}} - /** - * {{{description}}} - */ + /** + * {{{description}}} + */ {{/description}} export class {{classname}} {{#parent}}extends {{{parent}}} {{/parent}}{ {{#vars}} - {{#description}} - /** - * {{{description}}} - */ - {{/description}} - '{{name}}': {{#isEnum}}{{{datatypeWithEnum}}}{{/isEnum}}{{^isEnum}}{{{datatype}}}{{/isEnum}}; + {{#description}} + /** + * {{{description}}} + */ + {{/description}} + '{{name}}': {{#isEnum}}{{{datatypeWithEnum}}}{{/isEnum}}{{^isEnum}}{{{datatype}}}{{/isEnum}}; {{/vars}} } @@ -30,13 +30,13 @@ export class {{classname}} {{#parent}}extends {{{parent}}} {{/parent}}{ export namespace {{classname}} { {{#vars}} {{#isEnum}} - export enum {{enumName}} { - {{#allowableValues}} - {{#enumVars}} - {{name}} = {{{value}}}{{^-last}},{{/-last}} - {{/enumVars}} - {{/allowableValues}} - } + export enum {{enumName}} { + {{#allowableValues}} + {{#enumVars}} + {{name}} = {{{value}}}{{^-last}},{{/-last}} + {{/enumVars}} + {{/allowableValues}} + } {{/isEnum}} {{/vars}} } @@ -44,83 +44,47 @@ export namespace {{classname}} { {{/model}} {{/models}} -export interface IOptions { - accepts?: any; - async?: boolean; - cache?: boolean; - complete? (jqXHR: any, textStatus: string): any; - contents?: { [key: string]: any; }; - contentType?: any; - context?: any; - converters?: { [key: string]: any; }; - crossDomain?: boolean; - data?: any; - dataFilter? (data: any, ty: any): any; - dataType?: string; - error? (jqXHR: any, textStatus: string, errorThrown: string): any; - global?: boolean; - headers?: { [key: string]: any; }; - ifModified?: boolean; - isLocal?: boolean; - jsonp?: any; - jsonpCallback?: any; - method?: string; - mimeType?: string; - password?: string; - processData?: boolean; - scriptCharset?: string; - statusCode?: { [key: string]: any; }; - success? (data: any, textStatus: string, jqXHR: any): any; - timeout?: number; - traditional?: boolean; - type?: string; - url?: string; - username?: string; - xhr?: any; - xhrFields?: { [key: string]: any; }; -} - export interface Authentication { - /** - * Apply authentication settings to header and query params. - */ - applyToRequest(requestOptions: IOptions): void; + /** + * 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; - } + 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; + public apiKey: string; - constructor(private location: string, private paramName: string) { - } + constructor(private location: string, private paramName: string) { + } - applyToRequest(requestOptions: IOptions): void { - requestOptions.headers[this.paramName] = this.apiKey; - } + applyToRequest(requestOptions: JQueryAjaxSettings): void { + requestOptions.headers[this.paramName] = this.apiKey; + } } export class OAuth implements Authentication { - public accessToken: string; + public accessToken: string; - applyToRequest(requestOptions: IOptions): void { - requestOptions.headers["Authorization"] = "Bearer " + this.accessToken; - } + applyToRequest(requestOptions: JQueryAjaxSettings): void { + requestOptions.headers["Authorization"] = "Bearer " + this.accessToken; + } } export class VoidAuth implements Authentication { - public username: string; - public password: string; - applyToRequest(requestOptions: IOptions): void { - // Do nothing - } + public username: string; + public password: string; + applyToRequest(requestOptions: JQueryAjaxSettings): void { + // Do nothing + } } {{#apiInfo}} @@ -134,154 +98,170 @@ export class VoidAuth implements Authentication { export enum {{classname}}ApiKeys { {{#authMethods}} {{#isApiKey}} - {{name}}, + {{name}}, {{/isApiKey}} {{/authMethods}} } export class {{classname}} { - protected basePath = defaultBasePath; - protected defaultHeaders : any = {}; + protected basePath = defaultBasePath; + protected defaultHeaders : any = {}; - protected authentications = { - 'default': new VoidAuth(), + protected authentications = { + 'default': new VoidAuth(), {{#authMethods}} {{#isBasic}} - '{{name}}': new HttpBasicAuth(), + '{{name}}': new HttpBasicAuth(), {{/isBasic}} {{#isApiKey}} - '{{name}}': new ApiKeyAuth({{#isKeyInHeader}}'header'{{/isKeyInHeader}}{{^isKeyInHeader}}'query'{{/isKeyInHeader}}, '{{keyParamName}}'), + '{{name}}': new ApiKeyAuth({{#isKeyInHeader}}'header'{{/isKeyInHeader}}{{^isKeyInHeader}}'query'{{/isKeyInHeader}}, '{{keyParamName}}'), {{/isApiKey}} {{#isOAuth}} - '{{name}}': new OAuth(), + '{{name}}': new OAuth(), {{/isOAuth}} {{/authMethods}} - } + } - constructor(basePath?: string); + constructor(basePath?: string); {{#authMethods}} {{#isBasic}} - constructor(username: string, password: string, basePath?: string); + constructor(username: string, password: string, basePath?: string); {{/isBasic}} {{/authMethods}} - constructor(basePathOrUsername: string, password?: string, basePath?: string) { - if (password) { + constructor(basePathOrUsername: string, password?: string, basePath?: string) { + if (password) { {{#authMethods}} {{#isBasic}} - this.username = basePathOrUsername; - this.password = password + 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; - } + 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 username(username: string) { + this.authentications.{{name}}.username = username; + } - set password(password: string) { - this.authentications.{{name}}.password = password; - } + set password(password: string) { + this.authentications.{{name}}.password = password; + } {{/isBasic}} {{#isOAuth}} - set accessToken(token: string) { - this.authentications.{{name}}.accessToken = token; - } + 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; - } + 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); - let formParams: any = {}; + /** + * {{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}}.'); - } + // 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}}; - } + if ({{paramName}} !== undefined) { + queryParameters['{{baseName}}'] = {{paramName}}; + } {{/queryParams}} - localVarPath = localVarPath + "?" + $.param(queryParameters); + localVarPath = localVarPath + "?" + $.param(queryParameters); {{#headerParams}} - headerParams['{{baseName}}'] = {{paramName}}; + headerParams['{{baseName}}'] = {{paramName}}; {{/headerParams}} + +{{^bodyParam}} + let reqHasFile = false; + let reqDict = {}; + let reqFormData = new FormData(); {{#formParams}} - if ({{paramName}} !== undefined) { - formParams['{{baseName}}'] = {{paramName}}; - } +{{#isFile}} + reqHasFile = true; +{{/isFile}} + if ({{paramName}} !== undefined) { + reqFormData.append('{{baseName}}', {{paramName}}); + reqDict['{{baseName}}'] = {{paramName}}; + } {{/formParams}} - let requestOptions = { - url: localVarPath, - type: '{{httpMethod}}', - headers: headerParams, +{{/bodyParam}} +{{#bodyParam}} + let reqDict = {{paramName}}; + let reqFormData = new FormData(); + reqFormData.append('{{paramName}}', {{paramName}}); {{#isFile}} - enctype: 'multipart/form-data', - processData: false, // Important! - contentType: false, + let reqHasFile = true; {{/isFile}} {{^isFile}} - json: true, + let reqHasFile = false; {{/isFile}} -{{#bodyParam}} - data: formParams {{/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); + 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(); - } + 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}} From 43847c797bfc8498c01465d97d6172e6d06a6068 Mon Sep 17 00:00:00 2001 From: Ben Herila Date: Mon, 6 Mar 2017 15:08:39 -0800 Subject: [PATCH 6/8] Petstore sample for typescript-jquery --- .../default/.swagger-codegen-ignore | 23 + .../petstore/typescript-jquery/default/api.ts | 1213 +++++++++++++++++ .../typescript-jquery/default/git_push.sh | 52 + .../npm/.swagger-codegen-ignore | 23 + .../petstore/typescript-jquery/npm/api.ts | 1213 +++++++++++++++++ .../typescript-jquery/npm/git_push.sh | 52 + .../typescript-jquery/npm/package.json | 22 + .../typescript-jquery/npm/tsconfig.json | 18 + .../typescript-jquery/npm/typings.json | 10 + 9 files changed, 2626 insertions(+) create mode 100644 samples/client/petstore/typescript-jquery/default/.swagger-codegen-ignore create mode 100644 samples/client/petstore/typescript-jquery/default/api.ts create mode 100644 samples/client/petstore/typescript-jquery/default/git_push.sh create mode 100644 samples/client/petstore/typescript-jquery/npm/.swagger-codegen-ignore create mode 100644 samples/client/petstore/typescript-jquery/npm/api.ts create mode 100644 samples/client/petstore/typescript-jquery/npm/git_push.sh create mode 100644 samples/client/petstore/typescript-jquery/npm/package.json create mode 100644 samples/client/petstore/typescript-jquery/npm/tsconfig.json create mode 100644 samples/client/petstore/typescript-jquery/npm/typings.json 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 00000000000..c5fa491b4c5 --- /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 00000000000..9491259901e --- /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 00000000000..ed374619b13 --- /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 00000000000..c5fa491b4c5 --- /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 00000000000..9491259901e --- /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 00000000000..ed374619b13 --- /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 00000000000..89b35a0787a --- /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/tsconfig.json b/samples/client/petstore/typescript-jquery/npm/tsconfig.json new file mode 100644 index 00000000000..2dd166566e9 --- /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 00000000000..76c4cc8e6af --- /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 From e82f0db8d94bd9b20e5b1d29b59277f9c78724c0 Mon Sep 17 00:00:00 2001 From: Ben Herila Date: Mon, 6 Mar 2017 15:08:50 -0800 Subject: [PATCH 7/8] Petstore sample for typescript-jquery --- bin/typescript-jquery-all.sh | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100755 bin/typescript-jquery-all.sh diff --git a/bin/typescript-jquery-all.sh b/bin/typescript-jquery-all.sh new file mode 100755 index 00000000000..65f25060725 --- /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 node Petstore API client (default setting)" +ags="$@ generate -i modules/swagger-codegen/src/test/resources/2_0/petstore.json -l typescript-node -o samples/client/petstore/typescript-node/default" +java $JAVA_OPTS -jar $executable $ags + +echo "Typescript node Petstore API client with npm setting" +ags="$@ generate -i modules/swagger-codegen/src/test/resources/2_0/petstore.json -l typescript-node -c bin/typescript-petstore-npm.json -o samples/client/petstore/typescript-node/npm" +java $JAVA_OPTS -jar $executable $ags From f8cc9ae9c14d8de979ad8d970456d8b0466862a3 Mon Sep 17 00:00:00 2001 From: Ben Herila Date: Mon, 6 Mar 2017 15:09:04 -0800 Subject: [PATCH 8/8] wip --- bin/typescript-jquery-all.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/bin/typescript-jquery-all.sh b/bin/typescript-jquery-all.sh index 65f25060725..7203fa099a5 100755 --- a/bin/typescript-jquery-all.sh +++ b/bin/typescript-jquery-all.sh @@ -27,10 +27,10 @@ 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 node Petstore API client (default setting)" -ags="$@ generate -i modules/swagger-codegen/src/test/resources/2_0/petstore.json -l typescript-node -o samples/client/petstore/typescript-node/default" +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 node Petstore API client with npm setting" -ags="$@ generate -i modules/swagger-codegen/src/test/resources/2_0/petstore.json -l typescript-node -c bin/typescript-petstore-npm.json -o samples/client/petstore/typescript-node/npm" +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