From 616f57a592ec23f8fa7a2c59aaff83240fc7bde3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Fran=C3=A7ois=20C=C3=B4t=C3=A9?= Date: Mon, 3 Jul 2017 11:08:48 -0400 Subject: [PATCH] Typescript-Jquery refactor/improvement proposition (#5751) * First commit of the Java Play Framework server generator. It is highly based on Spring so there might me a couple of things that don't make sense (like options or parameters) for the Play Framework. * Fix suggestions in the PR discussion + add .bat and .sh file as requested. * Updated Readme.md file * Remove unused mustache file + fix baseName vs paramName in all the mustache files. * Fix the compilation error when we have a body which is a list or map. Doesn't fix the problem with the annotation itself. * Fix the problem with the Http.MultipartFormData.FilePart * First iteration of updating the typescript-jquery template/generator * first RC of the new version of Typescript-JQuery using better models. * Minor fix to the generation * first RC of the new version of Typescript-JQuery using better models. * Add an options for people using this client in a legacy app and that already have jquery loaded with a script tag somewhere * Generation of the samples based on the latest changes from the typescript-jquery generator * Fix to the check if the value is null and undefined * Small fix when using collection --- .../TypeScriptJqueryClientCodegen.java | 79 ++- .../resources/typescript-jquery/api.mustache | 375 +++++------- .../resources/typescript-jquery/apis.mustache | 9 + .../typescript-jquery/configuration.mustache | 6 + .../typescript-jquery/index.mustache | 4 + .../typescript-jquery/licenseInfo.mustache | 11 + .../typescript-jquery/masterApiEntry.mustache | 0 .../typescript-jquery/model.mustache | 13 + .../typescript-jquery/modelEnum.mustache | 12 + .../typescript-jquery/modelGeneric.mustache | 28 + .../typescript-jquery/models.mustache | 5 + .../typescript-jquery/variables.mustache | 7 + .../typescript-jquery/default/api/PetApi.ts | 571 ++++++++++++++++++ .../typescript-jquery/default/api/StoreApi.ts | 239 ++++++++ .../typescript-jquery/default/api/UserApi.ts | 437 ++++++++++++++ .../typescript-jquery/default/api/api.ts | 7 + .../default/configuration.ts | 6 + .../typescript-jquery/default/index.ts | 4 + .../default/model/Category.ts | 20 + .../typescript-jquery/default/model/Order.ts | 38 ++ .../typescript-jquery/default/model/Pet.ts | 38 ++ .../typescript-jquery/default/model/Tag.ts | 20 + .../typescript-jquery/default/model/User.ts | 35 ++ .../typescript-jquery/default/model/models.ts | 5 + .../typescript-jquery/default/variables.ts | 7 + .../typescript-jquery/npm/api/PetApi.ts | 571 ++++++++++++++++++ .../typescript-jquery/npm/api/StoreApi.ts | 239 ++++++++ .../typescript-jquery/npm/api/UserApi.ts | 437 ++++++++++++++ .../petstore/typescript-jquery/npm/api/api.ts | 7 + .../typescript-jquery/npm/configuration.ts | 6 + .../petstore/typescript-jquery/npm/index.ts | 4 + .../typescript-jquery/npm/model/Category.ts | 20 + .../typescript-jquery/npm/model/Order.ts | 38 ++ .../typescript-jquery/npm/model/Pet.ts | 38 ++ .../typescript-jquery/npm/model/Tag.ts | 20 + .../typescript-jquery/npm/model/User.ts | 35 ++ .../typescript-jquery/npm/model/models.ts | 5 + .../typescript-jquery/npm/variables.ts | 7 + 38 files changed, 3189 insertions(+), 214 deletions(-) create mode 100644 modules/swagger-codegen/src/main/resources/typescript-jquery/apis.mustache create mode 100644 modules/swagger-codegen/src/main/resources/typescript-jquery/configuration.mustache create mode 100644 modules/swagger-codegen/src/main/resources/typescript-jquery/index.mustache create mode 100644 modules/swagger-codegen/src/main/resources/typescript-jquery/licenseInfo.mustache create mode 100644 modules/swagger-codegen/src/main/resources/typescript-jquery/masterApiEntry.mustache create mode 100644 modules/swagger-codegen/src/main/resources/typescript-jquery/model.mustache create mode 100644 modules/swagger-codegen/src/main/resources/typescript-jquery/modelEnum.mustache create mode 100644 modules/swagger-codegen/src/main/resources/typescript-jquery/modelGeneric.mustache create mode 100644 modules/swagger-codegen/src/main/resources/typescript-jquery/models.mustache create mode 100644 modules/swagger-codegen/src/main/resources/typescript-jquery/variables.mustache create mode 100644 samples/client/petstore/typescript-jquery/default/api/PetApi.ts create mode 100644 samples/client/petstore/typescript-jquery/default/api/StoreApi.ts create mode 100644 samples/client/petstore/typescript-jquery/default/api/UserApi.ts create mode 100644 samples/client/petstore/typescript-jquery/default/api/api.ts create mode 100644 samples/client/petstore/typescript-jquery/default/configuration.ts create mode 100644 samples/client/petstore/typescript-jquery/default/index.ts create mode 100644 samples/client/petstore/typescript-jquery/default/model/Category.ts create mode 100644 samples/client/petstore/typescript-jquery/default/model/Order.ts create mode 100644 samples/client/petstore/typescript-jquery/default/model/Pet.ts create mode 100644 samples/client/petstore/typescript-jquery/default/model/Tag.ts create mode 100644 samples/client/petstore/typescript-jquery/default/model/User.ts create mode 100644 samples/client/petstore/typescript-jquery/default/model/models.ts create mode 100644 samples/client/petstore/typescript-jquery/default/variables.ts create mode 100644 samples/client/petstore/typescript-jquery/npm/api/PetApi.ts create mode 100644 samples/client/petstore/typescript-jquery/npm/api/StoreApi.ts create mode 100644 samples/client/petstore/typescript-jquery/npm/api/UserApi.ts create mode 100644 samples/client/petstore/typescript-jquery/npm/api/api.ts create mode 100644 samples/client/petstore/typescript-jquery/npm/configuration.ts create mode 100644 samples/client/petstore/typescript-jquery/npm/index.ts create mode 100644 samples/client/petstore/typescript-jquery/npm/model/Category.ts create mode 100644 samples/client/petstore/typescript-jquery/npm/model/Order.ts create mode 100644 samples/client/petstore/typescript-jquery/npm/model/Pet.ts create mode 100644 samples/client/petstore/typescript-jquery/npm/model/Tag.ts create mode 100644 samples/client/petstore/typescript-jquery/npm/model/User.ts create mode 100644 samples/client/petstore/typescript-jquery/npm/model/models.ts create mode 100644 samples/client/petstore/typescript-jquery/npm/variables.ts 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 index eb319344781..ab12f1a5b60 100644 --- 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 @@ -1,5 +1,9 @@ package io.swagger.codegen.languages; +import io.swagger.codegen.CodegenModel; +import io.swagger.codegen.CodegenParameter; +import io.swagger.models.ModelImpl; +import io.swagger.models.properties.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -9,7 +13,6 @@ 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); @@ -19,6 +22,7 @@ public class TypeScriptJqueryClientCodegen extends AbstractTypeScriptClientCodeg public static final String NPM_VERSION = "npmVersion"; public static final String NPM_REPOSITORY = "npmRepository"; public static final String SNAPSHOT = "snapshot"; + public static final String JQUERY_ALREADY_IMPORTED = "jqueryAlreadyImported"; protected String npmName = null; protected String npmVersion = "1.0.0"; @@ -26,6 +30,13 @@ public class TypeScriptJqueryClientCodegen extends AbstractTypeScriptClientCodeg public TypeScriptJqueryClientCodegen() { super(); + + modelTemplateFiles.put("model.mustache", ".ts"); + apiTemplateFiles.put("api.mustache", ".ts"); + typeMapping.put("Date", "Date"); + apiPackage = "api"; + modelPackage = "model"; + outputFolder = "generated-code/typescript-jquery"; embeddedTemplateDir = templateDir = "typescript-jquery"; @@ -33,23 +44,75 @@ public class TypeScriptJqueryClientCodegen extends AbstractTypeScriptClientCodeg 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())); + this.cliOptions.add(new CliOption(JQUERY_ALREADY_IMPORTED, "When using this in legacy app using mix of typescript and javascript, this will only declare jquery and not import it", 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")); + supportingFiles.add(new SupportingFile("models.mustache", modelPackage().replace('.', File.separatorChar), "models.ts")); + supportingFiles.add(new SupportingFile("apis.mustache", apiPackage().replace('.', File.separatorChar), "api.ts")); + supportingFiles.add(new SupportingFile("configuration.mustache", getIndexDirectory(), "configuration.ts")); + supportingFiles.add(new SupportingFile("index.mustache", getIndexDirectory(), "index.ts")); + supportingFiles.add(new SupportingFile("variables.mustache", getIndexDirectory(), "variables.ts")); LOGGER.warn("check additionals: " + additionalProperties.get(NPM_NAME)); - if(additionalProperties.containsKey(NPM_NAME)) { + if (additionalProperties.containsKey(NPM_NAME)) { addNpmPackageGeneration(); } } + private String getIndexDirectory() { + String indexPackage = modelPackage.substring(0, Math.max(0, modelPackage.lastIndexOf('.'))); + return indexPackage.replace('.', File.separatorChar); + } + + @Override + public String getSwaggerType(Property p) { + String swaggerType = super.getSwaggerType(p); + if (isLanguagePrimitive(swaggerType) || isLanguageGenericType(swaggerType)) { + return swaggerType; + } + return addModelPrefix(swaggerType); + } + + private String addModelPrefix(String swaggerType) { + String type = null; + if (typeMapping.containsKey(swaggerType)) { + type = typeMapping.get(swaggerType); + } else { + type = swaggerType; + } + + if (!isLanguagePrimitive(type) && !isLanguageGenericType(type)) { + type = "models." + swaggerType; + } + return type; + } + + private boolean isLanguagePrimitive(String type) { + return languageSpecificPrimitives.contains(type); + } + + private boolean isLanguageGenericType(String type) { + for (String genericType : languageGenericTypes) { + if (type.startsWith(genericType + "<")) { + return true; + } + } + return false; + } + + @Override + public void postProcessParameter(CodegenParameter parameter) { + super.postProcessParameter(parameter); + parameter.dataType = addModelPrefix(parameter.dataType); + } + private void addNpmPackageGeneration() { - if(additionalProperties.containsKey(NPM_NAME)) { + if (additionalProperties.containsKey(NPM_NAME)) { this.setNpmName(additionalProperties.get(NPM_NAME).toString()); } @@ -77,6 +140,12 @@ public class TypeScriptJqueryClientCodegen extends AbstractTypeScriptClientCodeg return indexPackage.replace('.', File.separatorChar); } + @Override + protected void addAdditionPropertiesToCodeGenModel(CodegenModel codegenModel, ModelImpl swaggerModel) { + codegenModel.additionalPropertiesType = getSwaggerType(swaggerModel.getAdditionalProperties()); + addImport(codegenModel, codegenModel.additionalPropertiesType); + } + @Override public String getName() { return "typescript-jquery"; 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 319c16e9bf8..ffa5128b4f5 100644 --- a/modules/swagger-codegen/src/main/resources/typescript-jquery/api.mustache +++ b/modules/swagger-codegen/src/main/resources/typescript-jquery/api.mustache @@ -1,176 +1,42 @@ +{{>licenseInfo}} + +{{#jqueryAlreadyImported}} +declare var $ : any; +{{/jqueryAlreadyImported}} +{{^jqueryAlreadyImported}} import * as $ from 'jquery'; +{{/jqueryAlreadyImported}} +import * as models from '../model/models'; +import { COLLECTION_FORMATS } from '../variables'; +import { Configuration } from '../configuration'; -let defaultBasePath = '{{{basePath}}}'; +/* tslint:disable:no-unused-variable member-ordering */ -// =============================================== -// This file is autogenerated - Please do not edit -// =============================================== - -/* tslint:disable:no-unused-variable */ - -{{#models}} -{{#model}} -{{#description}} - /** - * {{{description}}} - */ -{{/description}} -export class {{classname}} {{#parent}}extends {{{parent}}} {{/parent}}{ -{{#vars}} - {{#description}} - /** - * {{{description}}} - */ - {{/description}} - '{{name}}': {{#isEnum}}{{{datatypeWithEnum}}}{{/isEnum}}{{^isEnum}}{{{datatype}}}{{/isEnum}}; -{{/vars}} -} - -{{#hasEnums}} -export namespace {{classname}} { -{{#vars}} -{{#isEnum}} - export enum {{enumName}} { - {{#allowableValues}} - {{#enumVars}} - {{name}} = {{{value}}}{{^-last}},{{/-last}} - {{/enumVars}} - {{/allowableValues}} - } -{{/isEnum}} -{{/vars}} -} -{{/hasEnums}} -{{/model}} -{{/models}} - -export interface Authentication { - /** - * Apply authentication settings to header and query params. - */ - applyToRequest(requestOptions: JQueryAjaxSettings): void; -} - -export class HttpBasicAuth implements Authentication { - public username: string; - public password: string; - applyToRequest(requestOptions: any): void { - requestOptions.username = this.username; - requestOptions.password = this.password; - } -} - -export class ApiKeyAuth implements Authentication { - public apiKey: string; - - constructor(private location: string, private paramName: string) { - } - - applyToRequest(requestOptions: JQueryAjaxSettings): void { - requestOptions.headers[this.paramName] = this.apiKey; - } -} - -export class OAuth implements Authentication { - public accessToken: string; - - applyToRequest(requestOptions: JQueryAjaxSettings): void { - requestOptions.headers["Authorization"] = "Bearer " + this.accessToken; - } -} - -export class VoidAuth implements Authentication { - public username: string; - public password: string; - applyToRequest(requestOptions: JQueryAjaxSettings): void { - // Do nothing - } -} - -{{#apiInfo}} -{{#apis}} {{#operations}} + {{#description}} /** -* {{&description}} -*/ + * {{&description}} + */ {{/description}} -export enum {{classname}}ApiKeys { -{{#authMethods}} -{{#isApiKey}} - {{name}}, -{{/isApiKey}} -{{/authMethods}} -} - export class {{classname}} { - protected basePath = defaultBasePath; - protected defaultHeaders : any = {}; + protected basePath = '{{{basePath}}}'; + public defaultHeaders: Array = []; + public configuration: Configuration = new Configuration(); - 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 - } + constructor(basePath?: string, configuration?: Configuration) { + if (basePath) { + this.basePath = basePath; + } + if (configuration) { + this.configuration = configuration; } } - public setApiKey(key: {{classname}}ApiKeys, value: string) { - this.authentications[{{classname}}ApiKeys[key]].apiKey = value; - } -{{#authMethods}} -{{#isBasic}} - - set username(username: string) { - this.authentications.{{name}}.username = username; - } - - set password(password: string) { - this.authentications.{{name}}.password = password; - } -{{/isBasic}} -{{#isOAuth}} - - set accessToken(token: string) { - this.authentications.{{name}}.accessToken = token; - } -{{/isOAuth}} -{{/authMethods}} private extendObj(objA: T2, objB: T2): T1|T2 { - for(let key in objB){ - if(objB.hasOwnProperty(key)){ - objA[key] = objB[key]; + for (let key in objB) { + if (objB.hasOwnProperty(key)) { + objA[key] = objB[key]; } } return objA; @@ -182,59 +48,149 @@ export class {{classname}} { * {{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); + 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}}; -{{#allParams}}{{#required}} + let queryParameters: any = {}; + let headerParams: any = {}; +{{#hasFormParams}} + let formParams = new FormData(); + let reqHasFile = false; + +{{/hasFormParams}} +{{#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}}; - } +{{/required}} +{{/allParams}} +{{#queryParams}} + {{#isListContainer}} + if ({{paramName}}) { + {{#isCollectionFormatMulti}} + {{paramName}}.forEach((element: any) => { + queryParameters['{{baseName}}'].push(element); + }); + {{/isCollectionFormatMulti}} + {{^isCollectionFormatMulti}} + queryParameters['{{baseName}}'] = {{paramName}}.join(COLLECTION_FORMATS['{{collectionFormat}}']); + {{/isCollectionFormatMulti}} + } + {{/isListContainer}} + {{^isListContainer}} + if ({{paramName}} !== null && {{paramName}} !== undefined) { + {{#isDateTime}} + queryParameters['{{baseName}}'] = {{paramName}}.toISOString(); + {{/isDateTime}} + {{^isDateTime}} + {{#isDate}} + queryParameters['{{baseName}}'] = {{paramName}}.toISOString(); + {{/isDate}} + {{^isDate}} + queryParameters['{{baseName}}'] = {{paramName}}; + {{/isDate}} + {{/isDateTime}} + } + {{/isListContainer}} {{/queryParams}} localVarPath = localVarPath + "?" + $.param(queryParameters); - -{{#headerParams}} - headerParams['{{baseName}}'] = {{paramName}}; - -{{/headerParams}} - -{{^bodyParam}} - let reqHasFile = false; - let reqDict = {}; - let reqFormData = new FormData(); {{#formParams}} {{#isFile}} reqHasFile = true; {{/isFile}} - if ({{paramName}} !== undefined) { - reqFormData.append('{{baseName}}', {{paramName}}); - reqDict['{{baseName}}'] = {{paramName}}; + {{#isListContainer}} + if ({{paramName}}) { + {{#isCollectionFormatMulti}} + {{paramName}}.forEach((element: any) => { + formParams.append('{{baseName}}', element); + }); + {{/isCollectionFormatMulti}} + {{^isCollectionFormatMulti}} + formParams.append('{{baseName}}', {{paramName}}.join(COLLECTION_FORMATS['{{collectionFormat}}'])); + {{/isCollectionFormatMulti}} } + {{/isListContainer}} + {{^isListContainer}} + if ({{paramName}} !== null && {{paramName}} !== undefined) { + formParams.append('{{baseName}}', {{paramName}}); + } + {{/isListContainer}} {{/formParams}} -{{/bodyParam}} -{{#bodyParam}} - let reqDict = {{paramName}}; - let reqFormData = new FormData(); - reqFormData.append('{{paramName}}', {{paramName}}); -{{#isFile}} - let reqHasFile = true; -{{/isFile}} -{{^isFile}} - let reqHasFile = false; -{{/isFile}} -{{/bodyParam}} +{{#headerParams}} + {{#isListContainer}} + if ({{paramName}}) { + headerParams['{{baseName}}'] = {{paramName}}.join(COLLECTION_FORMATS['{{collectionFormat}}']); + } + {{/isListContainer}} + {{^isListContainer}} + headerParams['{{baseName}}'] = String({{paramName}}); + {{/isListContainer}} +{{/headerParams}} + // to determine the Content-Type header + let consumes: string[] = [ + {{#consumes}} + '{{{mediaType}}}'{{#hasMore}}, {{/hasMore}} + {{/consumes}} + ]; + + // to determine the Accept header + let produces: string[] = [ + {{#produces}} + '{{{mediaType}}}'{{#hasMore}}, {{/hasMore}} + {{/produces}} + ]; + +{{#authMethods}} + // authentication ({{name}}) required +{{#isApiKey}} +{{#isKeyInHeader}} + if (this.configuration.apiKey) { + headerParams['{{keyParamName}}'] = this.configuration.apiKey; + } + +{{/isKeyInHeader}} +{{#isKeyInQuery}} + if (this.configuration.apiKey) { + queryParameters.set('{{keyParamName}}', this.configuration.apiKey); + } + +{{/isKeyInQuery}} +{{/isApiKey}} +{{#isBasic}} + // http basic authentication required + if (this.configuration.username || this.configuration.password) { + headerParams['Authorization'] = 'Basic ' + btoa(this.configuration.username + ':' + this.configuration.password); + } + +{{/isBasic}} +{{#isOAuth}} + // oauth required + if (this.configuration.accessToken) { + let accessToken = typeof this.configuration.accessToken === 'function' + ? this.configuration.accessToken() + : this.configuration.accessToken; + headerParams['Authorization'] = 'Bearer ' + accessToken; + } + +{{/isOAuth}} +{{/authMethods}} +{{#hasFormParams}} + if (!reqHasFile) { + headerParams['Content-Type'] = 'application/x-www-form-urlencoded'; + } + +{{/hasFormParams}} + +{{#bodyParam}} + headerParams['Content-Type'] = 'application/json'; + +{{/bodyParam}} let requestOptions: JQueryAjaxSettings = { url: localVarPath, type: '{{httpMethod}}', @@ -242,28 +198,29 @@ export class {{classname}} { processData: false }; - if (Object.keys(reqDict).length) { - requestOptions.data = reqHasFile ? reqFormData : JSON.stringify(reqDict); - requestOptions.contentType = reqHasFile ? false : 'application/json; charset=utf-8'; +{{#bodyParam}} + requestOptions.data = JSON.stringify({{paramName}}); +{{/bodyParam}} + if (headerParams['Content-Type']) { + requestOptions.contentType = headerParams['Content-Type']; } - -{{#authMethods}} - this.authentications.{{name}}.applyToRequest(requestOptions); - -{{/authMethods}} - this.authentications.default.applyToRequest(requestOptions); +{{#hasFormParams}} + requestOptions.data = formParams; + if (reqHasFile) { + requestOptions.contentType = false; + } +{{/hasFormParams}} let dfd = $.Deferred(); $.ajax(requestOptions).then( (data: {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}any{{/returnType}}, textStatus: string, jqXHR: JQueryXHR) => - dfd.resolve({ response: jqXHR, body: data }), + dfd.resolve(jqXHR, data), (xhr: JQueryXHR, textStatus: string, errorThrown: string) => - dfd.reject({ response: xhr, body: errorThrown }) + dfd.reject(xhr, errorThrown) ); return dfd.promise(); } + {{/operation}} } {{/operations}} -{{/apis}} -{{/apiInfo}} diff --git a/modules/swagger-codegen/src/main/resources/typescript-jquery/apis.mustache b/modules/swagger-codegen/src/main/resources/typescript-jquery/apis.mustache new file mode 100644 index 00000000000..9d3e92349d0 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/typescript-jquery/apis.mustache @@ -0,0 +1,9 @@ +{{#apiInfo}} +{{#apis}} +{{#operations}} +export * from './{{ classFilename }}'; +import { {{ classname }} } from './{{ classFilename }}'; +{{/operations}} +{{/apis}} +export const APIS = [{{#apis}}{{#operations}}{{ classname }}{{/operations}}{{^-last}}, {{/-last}}{{/apis}}]; +{{/apiInfo}} diff --git a/modules/swagger-codegen/src/main/resources/typescript-jquery/configuration.mustache b/modules/swagger-codegen/src/main/resources/typescript-jquery/configuration.mustache new file mode 100644 index 00000000000..a566a180e4e --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/typescript-jquery/configuration.mustache @@ -0,0 +1,6 @@ +export class Configuration { + apiKey: string; + username: string; + password: string; + accessToken: string | (() => string); +} \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/typescript-jquery/index.mustache b/modules/swagger-codegen/src/main/resources/typescript-jquery/index.mustache new file mode 100644 index 00000000000..d097c728017 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/typescript-jquery/index.mustache @@ -0,0 +1,4 @@ +export * from './api/api'; +export * from './model/models'; +export * from './variables'; +export * from './configuration'; \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/typescript-jquery/licenseInfo.mustache b/modules/swagger-codegen/src/main/resources/typescript-jquery/licenseInfo.mustache new file mode 100644 index 00000000000..bbd8742e52a --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/typescript-jquery/licenseInfo.mustache @@ -0,0 +1,11 @@ +/** + * {{{appName}}} + * {{{appDescription}}} + * + * {{#version}}OpenAPI spec version: {{{version}}}{{/version}} + * {{#infoEmail}}Contact: {{{infoEmail}}}{{/infoEmail}} + * + * NOTE: This class is auto generated by the swagger code generator program. + * https://github.com/swagger-api/swagger-codegen.git + * Do not edit the class manually. + */ diff --git a/modules/swagger-codegen/src/main/resources/typescript-jquery/masterApiEntry.mustache b/modules/swagger-codegen/src/main/resources/typescript-jquery/masterApiEntry.mustache new file mode 100644 index 00000000000..e69de29bb2d diff --git a/modules/swagger-codegen/src/main/resources/typescript-jquery/model.mustache b/modules/swagger-codegen/src/main/resources/typescript-jquery/model.mustache new file mode 100644 index 00000000000..39fa04722e6 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/typescript-jquery/model.mustache @@ -0,0 +1,13 @@ +{{>licenseInfo}} +import * as models from './models'; +{{#models}} +{{#model}} + +{{#description}} +/** + * {{{description}}} + */ +{{/description}} +{{#isEnum}}{{>modelEnum}}{{/isEnum}}{{^isEnum}}{{>modelGeneric}}{{/isEnum}} +{{/model}} +{{/models}} \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/typescript-jquery/modelEnum.mustache b/modules/swagger-codegen/src/main/resources/typescript-jquery/modelEnum.mustache new file mode 100644 index 00000000000..47886484118 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/typescript-jquery/modelEnum.mustache @@ -0,0 +1,12 @@ +{{#description}} + /** + * {{{description}}} + */ +{{/description}} +export enum {{classname}} { +{{#allowableValues}} +{{#enumVars}} + {{{name}}} = {{{value}}}{{^-last}},{{/-last}} +{{/enumVars}} +{{/allowableValues}} +} \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/typescript-jquery/modelGeneric.mustache b/modules/swagger-codegen/src/main/resources/typescript-jquery/modelGeneric.mustache new file mode 100644 index 00000000000..fbe96c21506 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/typescript-jquery/modelGeneric.mustache @@ -0,0 +1,28 @@ +export interface {{classname}} {{#parent}}extends models.{{{parent}}} {{/parent}}{ +{{#additionalPropertiesType}} + [key: string]: {{{additionalPropertiesType}}}{{#hasVars}} | any{{/hasVars}}; + +{{/additionalPropertiesType}} +{{#vars}} + {{#description}} + /** + * {{{description}}} + */ + {{/description}} + {{name}}{{^required}}?{{/required}}: {{#isEnum}}{{{datatypeWithEnum}}}{{/isEnum}}{{^isEnum}}{{{datatype}}}{{/isEnum}}; + +{{/vars}} +}{{#hasEnums}} +export namespace {{classname}} { +{{#vars}} + {{#isEnum}} + export enum {{enumName}} { + {{#allowableValues}} + {{#enumVars}} + {{{name}}} = {{{value}}}{{^-last}},{{/-last}} + {{/enumVars}} + {{/allowableValues}} + } + {{/isEnum}} +{{/vars}} +}{{/hasEnums}} \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/typescript-jquery/models.mustache b/modules/swagger-codegen/src/main/resources/typescript-jquery/models.mustache new file mode 100644 index 00000000000..c6e732bffbb --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/typescript-jquery/models.mustache @@ -0,0 +1,5 @@ +{{#models}} +{{#model}} +export * from './{{{ classname }}}'; +{{/model}} +{{/models}} \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/typescript-jquery/variables.mustache b/modules/swagger-codegen/src/main/resources/typescript-jquery/variables.mustache new file mode 100644 index 00000000000..505ce9355e2 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/typescript-jquery/variables.mustache @@ -0,0 +1,7 @@ + +export const COLLECTION_FORMATS = { + 'csv': ',', + 'tsv': ' ', + 'ssv': ' ', + 'pipes': '|' +} \ No newline at end of file diff --git a/samples/client/petstore/typescript-jquery/default/api/PetApi.ts b/samples/client/petstore/typescript-jquery/default/api/PetApi.ts new file mode 100644 index 00000000000..fdf053b7303 --- /dev/null +++ b/samples/client/petstore/typescript-jquery/default/api/PetApi.ts @@ -0,0 +1,571 @@ +/** + * Swagger Petstore + * This is a sample server Petstore server. You can find out more about Swagger at http://swagger.io or on irc.freenode.net, #swagger. For this sample, you can use the api key \"special-key\" to test the authorization filters + * + * OpenAPI spec version: 1.0.0 + * Contact: apiteam@wordnik.com + * + * NOTE: This class is auto generated by the swagger code generator program. + * https://github.com/swagger-api/swagger-codegen.git + * Do not edit the class manually. + */ + + +import * as $ from 'jquery'; +import * as models from '../model/models'; +import { COLLECTION_FORMATS } from '../variables'; +import { Configuration } from '../configuration'; + +/* tslint:disable:no-unused-variable member-ordering */ + + +export class PetApi { + protected basePath = 'http://petstore.swagger.io/v2'; + public defaultHeaders: Array = []; + public configuration: Configuration = new Configuration(); + + constructor(basePath?: string, configuration?: Configuration) { + if (basePath) { + this.basePath = basePath; + } + if (configuration) { + this.configuration = configuration; + } + } + + 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?: models.Pet): JQueryPromise<{ response: JQueryXHR; body?: any; }> { + let localVarPath = this.basePath + '/pet'; + + let queryParameters: any = {}; + let headerParams: any = {}; + + + localVarPath = localVarPath + "?" + $.param(queryParameters); + // to determine the Content-Type header + let consumes: string[] = [ + 'application/json', + 'application/xml' + ]; + + // to determine the Accept header + let produces: string[] = [ + 'application/json', + 'application/xml' + ]; + + // authentication (petstore_auth) required + // oauth required + if (this.configuration.accessToken) { + let accessToken = typeof this.configuration.accessToken === 'function' + ? this.configuration.accessToken() + : this.configuration.accessToken; + headerParams['Authorization'] = 'Bearer ' + accessToken; + } + + + headerParams['Content-Type'] = 'application/json'; + + let requestOptions: JQueryAjaxSettings = { + url: localVarPath, + type: 'POST', + headers: headerParams, + processData: false + }; + + requestOptions.data = JSON.stringify(body); + if (headerParams['Content-Type']) { + requestOptions.contentType = headerParams['Content-Type']; + } + + let dfd = $.Deferred(); + $.ajax(requestOptions).then( + (data: any, textStatus: string, jqXHR: JQueryXHR) => + dfd.resolve(jqXHR, data), + (xhr: JQueryXHR, textStatus: string, errorThrown: string) => + dfd.reject(xhr, 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 = {}; + // 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'] = String(apiKey); + + // to determine the Content-Type header + let consumes: string[] = [ + ]; + + // to determine the Accept header + let produces: string[] = [ + 'application/json', + 'application/xml' + ]; + + // authentication (petstore_auth) required + // oauth required + if (this.configuration.accessToken) { + let accessToken = typeof this.configuration.accessToken === 'function' + ? this.configuration.accessToken() + : this.configuration.accessToken; + headerParams['Authorization'] = 'Bearer ' + accessToken; + } + + + let requestOptions: JQueryAjaxSettings = { + url: localVarPath, + type: 'DELETE', + headers: headerParams, + processData: false + }; + + if (headerParams['Content-Type']) { + requestOptions.contentType = headerParams['Content-Type']; + } + + let dfd = $.Deferred(); + $.ajax(requestOptions).then( + (data: any, textStatus: string, jqXHR: JQueryXHR) => + dfd.resolve(jqXHR, data), + (xhr: JQueryXHR, textStatus: string, errorThrown: string) => + dfd.reject(xhr, 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 = {}; + + if (status) { + status.forEach((element: any) => { + queryParameters['status'].push(element); + }); + } + + localVarPath = localVarPath + "?" + $.param(queryParameters); + // to determine the Content-Type header + let consumes: string[] = [ + ]; + + // to determine the Accept header + let produces: string[] = [ + 'application/json', + 'application/xml' + ]; + + // authentication (petstore_auth) required + // oauth required + if (this.configuration.accessToken) { + let accessToken = typeof this.configuration.accessToken === 'function' + ? this.configuration.accessToken() + : this.configuration.accessToken; + headerParams['Authorization'] = 'Bearer ' + accessToken; + } + + + let requestOptions: JQueryAjaxSettings = { + url: localVarPath, + type: 'GET', + headers: headerParams, + processData: false + }; + + if (headerParams['Content-Type']) { + requestOptions.contentType = headerParams['Content-Type']; + } + + let dfd = $.Deferred(); + $.ajax(requestOptions).then( + (data: Array, textStatus: string, jqXHR: JQueryXHR) => + dfd.resolve(jqXHR, data), + (xhr: JQueryXHR, textStatus: string, errorThrown: string) => + dfd.reject(xhr, 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 = {}; + + if (tags) { + tags.forEach((element: any) => { + queryParameters['tags'].push(element); + }); + } + + localVarPath = localVarPath + "?" + $.param(queryParameters); + // to determine the Content-Type header + let consumes: string[] = [ + ]; + + // to determine the Accept header + let produces: string[] = [ + 'application/json', + 'application/xml' + ]; + + // authentication (petstore_auth) required + // oauth required + if (this.configuration.accessToken) { + let accessToken = typeof this.configuration.accessToken === 'function' + ? this.configuration.accessToken() + : this.configuration.accessToken; + headerParams['Authorization'] = 'Bearer ' + accessToken; + } + + + let requestOptions: JQueryAjaxSettings = { + url: localVarPath, + type: 'GET', + headers: headerParams, + processData: false + }; + + if (headerParams['Content-Type']) { + requestOptions.contentType = headerParams['Content-Type']; + } + + let dfd = $.Deferred(); + $.ajax(requestOptions).then( + (data: Array, textStatus: string, jqXHR: JQueryXHR) => + dfd.resolve(jqXHR, data), + (xhr: JQueryXHR, textStatus: string, errorThrown: string) => + dfd.reject(xhr, 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: models.Pet; }> { + let localVarPath = this.basePath + '/pet/{petId}'.replace('{' + 'petId' + '}', String(petId)); + + let queryParameters: any = {}; + let headerParams: any = {}; + // 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); + // to determine the Content-Type header + let consumes: string[] = [ + ]; + + // to determine the Accept header + let produces: string[] = [ + 'application/json', + 'application/xml' + ]; + + // authentication (api_key) required + if (this.configuration.apiKey) { + headerParams['api_key'] = this.configuration.apiKey; + } + + // authentication (petstore_auth) required + // oauth required + if (this.configuration.accessToken) { + let accessToken = typeof this.configuration.accessToken === 'function' + ? this.configuration.accessToken() + : this.configuration.accessToken; + headerParams['Authorization'] = 'Bearer ' + accessToken; + } + + + let requestOptions: JQueryAjaxSettings = { + url: localVarPath, + type: 'GET', + headers: headerParams, + processData: false + }; + + if (headerParams['Content-Type']) { + requestOptions.contentType = headerParams['Content-Type']; + } + + let dfd = $.Deferred(); + $.ajax(requestOptions).then( + (data: models.Pet, textStatus: string, jqXHR: JQueryXHR) => + dfd.resolve(jqXHR, data), + (xhr: JQueryXHR, textStatus: string, errorThrown: string) => + dfd.reject(xhr, errorThrown) + ); + return dfd.promise(); + } + + /** + * Update an existing pet + * + * @param body Pet object that needs to be added to the store + */ + public updatePet(body?: models.Pet): JQueryPromise<{ response: JQueryXHR; body?: any; }> { + let localVarPath = this.basePath + '/pet'; + + let queryParameters: any = {}; + let headerParams: any = {}; + + + localVarPath = localVarPath + "?" + $.param(queryParameters); + // to determine the Content-Type header + let consumes: string[] = [ + 'application/json', + 'application/xml' + ]; + + // to determine the Accept header + let produces: string[] = [ + 'application/json', + 'application/xml' + ]; + + // authentication (petstore_auth) required + // oauth required + if (this.configuration.accessToken) { + let accessToken = typeof this.configuration.accessToken === 'function' + ? this.configuration.accessToken() + : this.configuration.accessToken; + headerParams['Authorization'] = 'Bearer ' + accessToken; + } + + + headerParams['Content-Type'] = 'application/json'; + + let requestOptions: JQueryAjaxSettings = { + url: localVarPath, + type: 'PUT', + headers: headerParams, + processData: false + }; + + requestOptions.data = JSON.stringify(body); + if (headerParams['Content-Type']) { + requestOptions.contentType = headerParams['Content-Type']; + } + + let dfd = $.Deferred(); + $.ajax(requestOptions).then( + (data: any, textStatus: string, jqXHR: JQueryXHR) => + dfd.resolve(jqXHR, data), + (xhr: JQueryXHR, textStatus: string, errorThrown: string) => + dfd.reject(xhr, 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 = {}; + let formParams = new FormData(); + let reqHasFile = false; + + // 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); + if (name !== null && name !== undefined) { + formParams.append('name', name); + } + + if (status !== null && status !== undefined) { + formParams.append('status', status); + } + + // to determine the Content-Type header + let consumes: string[] = [ + 'application/x-www-form-urlencoded' + ]; + + // to determine the Accept header + let produces: string[] = [ + 'application/json', + 'application/xml' + ]; + + // authentication (petstore_auth) required + // oauth required + if (this.configuration.accessToken) { + let accessToken = typeof this.configuration.accessToken === 'function' + ? this.configuration.accessToken() + : this.configuration.accessToken; + headerParams['Authorization'] = 'Bearer ' + accessToken; + } + + if (!reqHasFile) { + headerParams['Content-Type'] = 'application/x-www-form-urlencoded'; + } + + + let requestOptions: JQueryAjaxSettings = { + url: localVarPath, + type: 'POST', + headers: headerParams, + processData: false + }; + + if (headerParams['Content-Type']) { + requestOptions.contentType = headerParams['Content-Type']; + } + requestOptions.data = formParams; + if (reqHasFile) { + requestOptions.contentType = false; + } + + let dfd = $.Deferred(); + $.ajax(requestOptions).then( + (data: any, textStatus: string, jqXHR: JQueryXHR) => + dfd.resolve(jqXHR, data), + (xhr: JQueryXHR, textStatus: string, errorThrown: string) => + dfd.reject(xhr, 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 = {}; + let formParams = new FormData(); + let reqHasFile = false; + + // 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); + if (additionalMetadata !== null && additionalMetadata !== undefined) { + formParams.append('additionalMetadata', additionalMetadata); + } + + reqHasFile = true; + if (file !== null && file !== undefined) { + formParams.append('file', file); + } + + // to determine the Content-Type header + let consumes: string[] = [ + 'multipart/form-data' + ]; + + // to determine the Accept header + let produces: string[] = [ + 'application/json', + 'application/xml' + ]; + + // authentication (petstore_auth) required + // oauth required + if (this.configuration.accessToken) { + let accessToken = typeof this.configuration.accessToken === 'function' + ? this.configuration.accessToken() + : this.configuration.accessToken; + headerParams['Authorization'] = 'Bearer ' + accessToken; + } + + if (!reqHasFile) { + headerParams['Content-Type'] = 'application/x-www-form-urlencoded'; + } + + + let requestOptions: JQueryAjaxSettings = { + url: localVarPath, + type: 'POST', + headers: headerParams, + processData: false + }; + + if (headerParams['Content-Type']) { + requestOptions.contentType = headerParams['Content-Type']; + } + requestOptions.data = formParams; + if (reqHasFile) { + requestOptions.contentType = false; + } + + let dfd = $.Deferred(); + $.ajax(requestOptions).then( + (data: any, textStatus: string, jqXHR: JQueryXHR) => + dfd.resolve(jqXHR, data), + (xhr: JQueryXHR, textStatus: string, errorThrown: string) => + dfd.reject(xhr, errorThrown) + ); + return dfd.promise(); + } + +} diff --git a/samples/client/petstore/typescript-jquery/default/api/StoreApi.ts b/samples/client/petstore/typescript-jquery/default/api/StoreApi.ts new file mode 100644 index 00000000000..a2495cc0f30 --- /dev/null +++ b/samples/client/petstore/typescript-jquery/default/api/StoreApi.ts @@ -0,0 +1,239 @@ +/** + * Swagger Petstore + * This is a sample server Petstore server. You can find out more about Swagger at http://swagger.io or on irc.freenode.net, #swagger. For this sample, you can use the api key \"special-key\" to test the authorization filters + * + * OpenAPI spec version: 1.0.0 + * Contact: apiteam@wordnik.com + * + * NOTE: This class is auto generated by the swagger code generator program. + * https://github.com/swagger-api/swagger-codegen.git + * Do not edit the class manually. + */ + + +import * as $ from 'jquery'; +import * as models from '../model/models'; +import { COLLECTION_FORMATS } from '../variables'; +import { Configuration } from '../configuration'; + +/* tslint:disable:no-unused-variable member-ordering */ + + +export class StoreApi { + protected basePath = 'http://petstore.swagger.io/v2'; + public defaultHeaders: Array = []; + public configuration: Configuration = new Configuration(); + + constructor(basePath?: string, configuration?: Configuration) { + if (basePath) { + this.basePath = basePath; + } + if (configuration) { + this.configuration = configuration; + } + } + + 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 = {}; + // 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); + // to determine the Content-Type header + let consumes: string[] = [ + ]; + + // to determine the Accept header + let produces: string[] = [ + 'application/json', + 'application/xml' + ]; + + + let requestOptions: JQueryAjaxSettings = { + url: localVarPath, + type: 'DELETE', + headers: headerParams, + processData: false + }; + + if (headerParams['Content-Type']) { + requestOptions.contentType = headerParams['Content-Type']; + } + + let dfd = $.Deferred(); + $.ajax(requestOptions).then( + (data: any, textStatus: string, jqXHR: JQueryXHR) => + dfd.resolve(jqXHR, data), + (xhr: JQueryXHR, textStatus: string, errorThrown: string) => + dfd.reject(xhr, 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 = {}; + + localVarPath = localVarPath + "?" + $.param(queryParameters); + // to determine the Content-Type header + let consumes: string[] = [ + ]; + + // to determine the Accept header + let produces: string[] = [ + 'application/json', + 'application/xml' + ]; + + // authentication (api_key) required + if (this.configuration.apiKey) { + headerParams['api_key'] = this.configuration.apiKey; + } + + + let requestOptions: JQueryAjaxSettings = { + url: localVarPath, + type: 'GET', + headers: headerParams, + processData: false + }; + + if (headerParams['Content-Type']) { + requestOptions.contentType = headerParams['Content-Type']; + } + + let dfd = $.Deferred(); + $.ajax(requestOptions).then( + (data: { [key: string]: number; }, textStatus: string, jqXHR: JQueryXHR) => + dfd.resolve(jqXHR, data), + (xhr: JQueryXHR, textStatus: string, errorThrown: string) => + dfd.reject(xhr, 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: models.Order; }> { + let localVarPath = this.basePath + '/store/order/{orderId}'.replace('{' + 'orderId' + '}', String(orderId)); + + let queryParameters: any = {}; + let headerParams: any = {}; + // 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); + // to determine the Content-Type header + let consumes: string[] = [ + ]; + + // to determine the Accept header + let produces: string[] = [ + 'application/json', + 'application/xml' + ]; + + + let requestOptions: JQueryAjaxSettings = { + url: localVarPath, + type: 'GET', + headers: headerParams, + processData: false + }; + + if (headerParams['Content-Type']) { + requestOptions.contentType = headerParams['Content-Type']; + } + + let dfd = $.Deferred(); + $.ajax(requestOptions).then( + (data: models.Order, textStatus: string, jqXHR: JQueryXHR) => + dfd.resolve(jqXHR, data), + (xhr: JQueryXHR, textStatus: string, errorThrown: string) => + dfd.reject(xhr, errorThrown) + ); + return dfd.promise(); + } + + /** + * Place an order for a pet + * + * @param body order placed for purchasing the pet + */ + public placeOrder(body?: models.Order): JQueryPromise<{ response: JQueryXHR; body: models.Order; }> { + let localVarPath = this.basePath + '/store/order'; + + let queryParameters: any = {}; + let headerParams: any = {}; + + + localVarPath = localVarPath + "?" + $.param(queryParameters); + // to determine the Content-Type header + let consumes: string[] = [ + ]; + + // to determine the Accept header + let produces: string[] = [ + 'application/json', + 'application/xml' + ]; + + + headerParams['Content-Type'] = 'application/json'; + + let requestOptions: JQueryAjaxSettings = { + url: localVarPath, + type: 'POST', + headers: headerParams, + processData: false + }; + + requestOptions.data = JSON.stringify(body); + if (headerParams['Content-Type']) { + requestOptions.contentType = headerParams['Content-Type']; + } + + let dfd = $.Deferred(); + $.ajax(requestOptions).then( + (data: models.Order, textStatus: string, jqXHR: JQueryXHR) => + dfd.resolve(jqXHR, data), + (xhr: JQueryXHR, textStatus: string, errorThrown: string) => + dfd.reject(xhr, errorThrown) + ); + return dfd.promise(); + } + +} diff --git a/samples/client/petstore/typescript-jquery/default/api/UserApi.ts b/samples/client/petstore/typescript-jquery/default/api/UserApi.ts new file mode 100644 index 00000000000..53349124ed6 --- /dev/null +++ b/samples/client/petstore/typescript-jquery/default/api/UserApi.ts @@ -0,0 +1,437 @@ +/** + * Swagger Petstore + * This is a sample server Petstore server. You can find out more about Swagger at http://swagger.io or on irc.freenode.net, #swagger. For this sample, you can use the api key \"special-key\" to test the authorization filters + * + * OpenAPI spec version: 1.0.0 + * Contact: apiteam@wordnik.com + * + * NOTE: This class is auto generated by the swagger code generator program. + * https://github.com/swagger-api/swagger-codegen.git + * Do not edit the class manually. + */ + + +import * as $ from 'jquery'; +import * as models from '../model/models'; +import { COLLECTION_FORMATS } from '../variables'; +import { Configuration } from '../configuration'; + +/* tslint:disable:no-unused-variable member-ordering */ + + +export class UserApi { + protected basePath = 'http://petstore.swagger.io/v2'; + public defaultHeaders: Array = []; + public configuration: Configuration = new Configuration(); + + constructor(basePath?: string, configuration?: Configuration) { + if (basePath) { + this.basePath = basePath; + } + if (configuration) { + this.configuration = configuration; + } + } + + 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?: models.User): JQueryPromise<{ response: JQueryXHR; body?: any; }> { + let localVarPath = this.basePath + '/user'; + + let queryParameters: any = {}; + let headerParams: any = {}; + + + localVarPath = localVarPath + "?" + $.param(queryParameters); + // to determine the Content-Type header + let consumes: string[] = [ + ]; + + // to determine the Accept header + let produces: string[] = [ + 'application/json', + 'application/xml' + ]; + + + headerParams['Content-Type'] = 'application/json'; + + let requestOptions: JQueryAjaxSettings = { + url: localVarPath, + type: 'POST', + headers: headerParams, + processData: false + }; + + requestOptions.data = JSON.stringify(body); + if (headerParams['Content-Type']) { + requestOptions.contentType = headerParams['Content-Type']; + } + + let dfd = $.Deferred(); + $.ajax(requestOptions).then( + (data: any, textStatus: string, jqXHR: JQueryXHR) => + dfd.resolve(jqXHR, data), + (xhr: JQueryXHR, textStatus: string, errorThrown: string) => + dfd.reject(xhr, 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 = {}; + + + localVarPath = localVarPath + "?" + $.param(queryParameters); + // to determine the Content-Type header + let consumes: string[] = [ + ]; + + // to determine the Accept header + let produces: string[] = [ + 'application/json', + 'application/xml' + ]; + + + headerParams['Content-Type'] = 'application/json'; + + let requestOptions: JQueryAjaxSettings = { + url: localVarPath, + type: 'POST', + headers: headerParams, + processData: false + }; + + requestOptions.data = JSON.stringify(body); + if (headerParams['Content-Type']) { + requestOptions.contentType = headerParams['Content-Type']; + } + + let dfd = $.Deferred(); + $.ajax(requestOptions).then( + (data: any, textStatus: string, jqXHR: JQueryXHR) => + dfd.resolve(jqXHR, data), + (xhr: JQueryXHR, textStatus: string, errorThrown: string) => + dfd.reject(xhr, 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 = {}; + + + localVarPath = localVarPath + "?" + $.param(queryParameters); + // to determine the Content-Type header + let consumes: string[] = [ + ]; + + // to determine the Accept header + let produces: string[] = [ + 'application/json', + 'application/xml' + ]; + + + headerParams['Content-Type'] = 'application/json'; + + let requestOptions: JQueryAjaxSettings = { + url: localVarPath, + type: 'POST', + headers: headerParams, + processData: false + }; + + requestOptions.data = JSON.stringify(body); + if (headerParams['Content-Type']) { + requestOptions.contentType = headerParams['Content-Type']; + } + + let dfd = $.Deferred(); + $.ajax(requestOptions).then( + (data: any, textStatus: string, jqXHR: JQueryXHR) => + dfd.resolve(jqXHR, data), + (xhr: JQueryXHR, textStatus: string, errorThrown: string) => + dfd.reject(xhr, 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 = {}; + // 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); + // to determine the Content-Type header + let consumes: string[] = [ + ]; + + // to determine the Accept header + let produces: string[] = [ + 'application/json', + 'application/xml' + ]; + + + let requestOptions: JQueryAjaxSettings = { + url: localVarPath, + type: 'DELETE', + headers: headerParams, + processData: false + }; + + if (headerParams['Content-Type']) { + requestOptions.contentType = headerParams['Content-Type']; + } + + let dfd = $.Deferred(); + $.ajax(requestOptions).then( + (data: any, textStatus: string, jqXHR: JQueryXHR) => + dfd.resolve(jqXHR, data), + (xhr: JQueryXHR, textStatus: string, errorThrown: string) => + dfd.reject(xhr, 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: models.User; }> { + let localVarPath = this.basePath + '/user/{username}'.replace('{' + 'username' + '}', String(username)); + + let queryParameters: any = {}; + let headerParams: any = {}; + // 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); + // to determine the Content-Type header + let consumes: string[] = [ + ]; + + // to determine the Accept header + let produces: string[] = [ + 'application/json', + 'application/xml' + ]; + + + let requestOptions: JQueryAjaxSettings = { + url: localVarPath, + type: 'GET', + headers: headerParams, + processData: false + }; + + if (headerParams['Content-Type']) { + requestOptions.contentType = headerParams['Content-Type']; + } + + let dfd = $.Deferred(); + $.ajax(requestOptions).then( + (data: models.User, textStatus: string, jqXHR: JQueryXHR) => + dfd.resolve(jqXHR, data), + (xhr: JQueryXHR, textStatus: string, errorThrown: string) => + dfd.reject(xhr, 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 = {}; + + + if (username !== null && username !== undefined) { + queryParameters['username'] = username; + } + if (password !== null && password !== undefined) { + queryParameters['password'] = password; + } + + localVarPath = localVarPath + "?" + $.param(queryParameters); + // to determine the Content-Type header + let consumes: string[] = [ + ]; + + // to determine the Accept header + let produces: string[] = [ + 'application/json', + 'application/xml' + ]; + + + let requestOptions: JQueryAjaxSettings = { + url: localVarPath, + type: 'GET', + headers: headerParams, + processData: false + }; + + if (headerParams['Content-Type']) { + requestOptions.contentType = headerParams['Content-Type']; + } + + let dfd = $.Deferred(); + $.ajax(requestOptions).then( + (data: string, textStatus: string, jqXHR: JQueryXHR) => + dfd.resolve(jqXHR, data), + (xhr: JQueryXHR, textStatus: string, errorThrown: string) => + dfd.reject(xhr, 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 = {}; + + localVarPath = localVarPath + "?" + $.param(queryParameters); + // to determine the Content-Type header + let consumes: string[] = [ + ]; + + // to determine the Accept header + let produces: string[] = [ + 'application/json', + 'application/xml' + ]; + + + let requestOptions: JQueryAjaxSettings = { + url: localVarPath, + type: 'GET', + headers: headerParams, + processData: false + }; + + if (headerParams['Content-Type']) { + requestOptions.contentType = headerParams['Content-Type']; + } + + let dfd = $.Deferred(); + $.ajax(requestOptions).then( + (data: any, textStatus: string, jqXHR: JQueryXHR) => + dfd.resolve(jqXHR, data), + (xhr: JQueryXHR, textStatus: string, errorThrown: string) => + dfd.reject(xhr, 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?: models.User): JQueryPromise<{ response: JQueryXHR; body?: any; }> { + let localVarPath = this.basePath + '/user/{username}'.replace('{' + 'username' + '}', String(username)); + + let queryParameters: any = {}; + let headerParams: any = {}; + // 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); + // to determine the Content-Type header + let consumes: string[] = [ + ]; + + // to determine the Accept header + let produces: string[] = [ + 'application/json', + 'application/xml' + ]; + + + headerParams['Content-Type'] = 'application/json'; + + let requestOptions: JQueryAjaxSettings = { + url: localVarPath, + type: 'PUT', + headers: headerParams, + processData: false + }; + + requestOptions.data = JSON.stringify(body); + if (headerParams['Content-Type']) { + requestOptions.contentType = headerParams['Content-Type']; + } + + let dfd = $.Deferred(); + $.ajax(requestOptions).then( + (data: any, textStatus: string, jqXHR: JQueryXHR) => + dfd.resolve(jqXHR, data), + (xhr: JQueryXHR, textStatus: string, errorThrown: string) => + dfd.reject(xhr, errorThrown) + ); + return dfd.promise(); + } + +} diff --git a/samples/client/petstore/typescript-jquery/default/api/api.ts b/samples/client/petstore/typescript-jquery/default/api/api.ts new file mode 100644 index 00000000000..4ddd9e29663 --- /dev/null +++ b/samples/client/petstore/typescript-jquery/default/api/api.ts @@ -0,0 +1,7 @@ +export * from './PetApi'; +import { PetApi } from './PetApi'; +export * from './StoreApi'; +import { StoreApi } from './StoreApi'; +export * from './UserApi'; +import { UserApi } from './UserApi'; +export const APIS = [PetApi, StoreApi, UserApi]; diff --git a/samples/client/petstore/typescript-jquery/default/configuration.ts b/samples/client/petstore/typescript-jquery/default/configuration.ts new file mode 100644 index 00000000000..a566a180e4e --- /dev/null +++ b/samples/client/petstore/typescript-jquery/default/configuration.ts @@ -0,0 +1,6 @@ +export class Configuration { + apiKey: string; + username: string; + password: string; + accessToken: string | (() => string); +} \ No newline at end of file diff --git a/samples/client/petstore/typescript-jquery/default/index.ts b/samples/client/petstore/typescript-jquery/default/index.ts new file mode 100644 index 00000000000..d097c728017 --- /dev/null +++ b/samples/client/petstore/typescript-jquery/default/index.ts @@ -0,0 +1,4 @@ +export * from './api/api'; +export * from './model/models'; +export * from './variables'; +export * from './configuration'; \ No newline at end of file diff --git a/samples/client/petstore/typescript-jquery/default/model/Category.ts b/samples/client/petstore/typescript-jquery/default/model/Category.ts new file mode 100644 index 00000000000..ffdacd4f707 --- /dev/null +++ b/samples/client/petstore/typescript-jquery/default/model/Category.ts @@ -0,0 +1,20 @@ +/** + * Swagger Petstore + * This is a sample server Petstore server. You can find out more about Swagger at http://swagger.io or on irc.freenode.net, #swagger. For this sample, you can use the api key \"special-key\" to test the authorization filters + * + * OpenAPI spec version: 1.0.0 + * Contact: apiteam@wordnik.com + * + * NOTE: This class is auto generated by the swagger code generator program. + * https://github.com/swagger-api/swagger-codegen.git + * Do not edit the class manually. + */ + +import * as models from './models'; + +export interface Category { + id?: number; + + name?: string; + +} diff --git a/samples/client/petstore/typescript-jquery/default/model/Order.ts b/samples/client/petstore/typescript-jquery/default/model/Order.ts new file mode 100644 index 00000000000..9c47071c5b6 --- /dev/null +++ b/samples/client/petstore/typescript-jquery/default/model/Order.ts @@ -0,0 +1,38 @@ +/** + * Swagger Petstore + * This is a sample server Petstore server. You can find out more about Swagger at http://swagger.io or on irc.freenode.net, #swagger. For this sample, you can use the api key \"special-key\" to test the authorization filters + * + * OpenAPI spec version: 1.0.0 + * Contact: apiteam@wordnik.com + * + * NOTE: This class is auto generated by the swagger code generator program. + * https://github.com/swagger-api/swagger-codegen.git + * Do not edit the class manually. + */ + +import * as models from './models'; + +export interface 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' + } +} diff --git a/samples/client/petstore/typescript-jquery/default/model/Pet.ts b/samples/client/petstore/typescript-jquery/default/model/Pet.ts new file mode 100644 index 00000000000..d64dc809e53 --- /dev/null +++ b/samples/client/petstore/typescript-jquery/default/model/Pet.ts @@ -0,0 +1,38 @@ +/** + * Swagger Petstore + * This is a sample server Petstore server. You can find out more about Swagger at http://swagger.io or on irc.freenode.net, #swagger. For this sample, you can use the api key \"special-key\" to test the authorization filters + * + * OpenAPI spec version: 1.0.0 + * Contact: apiteam@wordnik.com + * + * NOTE: This class is auto generated by the swagger code generator program. + * https://github.com/swagger-api/swagger-codegen.git + * Do not edit the class manually. + */ + +import * as models from './models'; + +export interface Pet { + id?: number; + + category?: models.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' + } +} diff --git a/samples/client/petstore/typescript-jquery/default/model/Tag.ts b/samples/client/petstore/typescript-jquery/default/model/Tag.ts new file mode 100644 index 00000000000..8a3b99ae9ca --- /dev/null +++ b/samples/client/petstore/typescript-jquery/default/model/Tag.ts @@ -0,0 +1,20 @@ +/** + * Swagger Petstore + * This is a sample server Petstore server. You can find out more about Swagger at http://swagger.io or on irc.freenode.net, #swagger. For this sample, you can use the api key \"special-key\" to test the authorization filters + * + * OpenAPI spec version: 1.0.0 + * Contact: apiteam@wordnik.com + * + * NOTE: This class is auto generated by the swagger code generator program. + * https://github.com/swagger-api/swagger-codegen.git + * Do not edit the class manually. + */ + +import * as models from './models'; + +export interface Tag { + id?: number; + + name?: string; + +} diff --git a/samples/client/petstore/typescript-jquery/default/model/User.ts b/samples/client/petstore/typescript-jquery/default/model/User.ts new file mode 100644 index 00000000000..43d00f7b318 --- /dev/null +++ b/samples/client/petstore/typescript-jquery/default/model/User.ts @@ -0,0 +1,35 @@ +/** + * Swagger Petstore + * This is a sample server Petstore server. You can find out more about Swagger at http://swagger.io or on irc.freenode.net, #swagger. For this sample, you can use the api key \"special-key\" to test the authorization filters + * + * OpenAPI spec version: 1.0.0 + * Contact: apiteam@wordnik.com + * + * NOTE: This class is auto generated by the swagger code generator program. + * https://github.com/swagger-api/swagger-codegen.git + * Do not edit the class manually. + */ + +import * as models from './models'; + +export interface User { + id?: number; + + username?: string; + + firstName?: string; + + lastName?: string; + + email?: string; + + password?: string; + + phone?: string; + + /** + * User Status + */ + userStatus?: number; + +} diff --git a/samples/client/petstore/typescript-jquery/default/model/models.ts b/samples/client/petstore/typescript-jquery/default/model/models.ts new file mode 100644 index 00000000000..92dac02846c --- /dev/null +++ b/samples/client/petstore/typescript-jquery/default/model/models.ts @@ -0,0 +1,5 @@ +export * from './Category'; +export * from './Order'; +export * from './Pet'; +export * from './Tag'; +export * from './User'; diff --git a/samples/client/petstore/typescript-jquery/default/variables.ts b/samples/client/petstore/typescript-jquery/default/variables.ts new file mode 100644 index 00000000000..505ce9355e2 --- /dev/null +++ b/samples/client/petstore/typescript-jquery/default/variables.ts @@ -0,0 +1,7 @@ + +export const COLLECTION_FORMATS = { + 'csv': ',', + 'tsv': ' ', + 'ssv': ' ', + 'pipes': '|' +} \ No newline at end of file diff --git a/samples/client/petstore/typescript-jquery/npm/api/PetApi.ts b/samples/client/petstore/typescript-jquery/npm/api/PetApi.ts new file mode 100644 index 00000000000..fdf053b7303 --- /dev/null +++ b/samples/client/petstore/typescript-jquery/npm/api/PetApi.ts @@ -0,0 +1,571 @@ +/** + * Swagger Petstore + * This is a sample server Petstore server. You can find out more about Swagger at http://swagger.io or on irc.freenode.net, #swagger. For this sample, you can use the api key \"special-key\" to test the authorization filters + * + * OpenAPI spec version: 1.0.0 + * Contact: apiteam@wordnik.com + * + * NOTE: This class is auto generated by the swagger code generator program. + * https://github.com/swagger-api/swagger-codegen.git + * Do not edit the class manually. + */ + + +import * as $ from 'jquery'; +import * as models from '../model/models'; +import { COLLECTION_FORMATS } from '../variables'; +import { Configuration } from '../configuration'; + +/* tslint:disable:no-unused-variable member-ordering */ + + +export class PetApi { + protected basePath = 'http://petstore.swagger.io/v2'; + public defaultHeaders: Array = []; + public configuration: Configuration = new Configuration(); + + constructor(basePath?: string, configuration?: Configuration) { + if (basePath) { + this.basePath = basePath; + } + if (configuration) { + this.configuration = configuration; + } + } + + 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?: models.Pet): JQueryPromise<{ response: JQueryXHR; body?: any; }> { + let localVarPath = this.basePath + '/pet'; + + let queryParameters: any = {}; + let headerParams: any = {}; + + + localVarPath = localVarPath + "?" + $.param(queryParameters); + // to determine the Content-Type header + let consumes: string[] = [ + 'application/json', + 'application/xml' + ]; + + // to determine the Accept header + let produces: string[] = [ + 'application/json', + 'application/xml' + ]; + + // authentication (petstore_auth) required + // oauth required + if (this.configuration.accessToken) { + let accessToken = typeof this.configuration.accessToken === 'function' + ? this.configuration.accessToken() + : this.configuration.accessToken; + headerParams['Authorization'] = 'Bearer ' + accessToken; + } + + + headerParams['Content-Type'] = 'application/json'; + + let requestOptions: JQueryAjaxSettings = { + url: localVarPath, + type: 'POST', + headers: headerParams, + processData: false + }; + + requestOptions.data = JSON.stringify(body); + if (headerParams['Content-Type']) { + requestOptions.contentType = headerParams['Content-Type']; + } + + let dfd = $.Deferred(); + $.ajax(requestOptions).then( + (data: any, textStatus: string, jqXHR: JQueryXHR) => + dfd.resolve(jqXHR, data), + (xhr: JQueryXHR, textStatus: string, errorThrown: string) => + dfd.reject(xhr, 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 = {}; + // 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'] = String(apiKey); + + // to determine the Content-Type header + let consumes: string[] = [ + ]; + + // to determine the Accept header + let produces: string[] = [ + 'application/json', + 'application/xml' + ]; + + // authentication (petstore_auth) required + // oauth required + if (this.configuration.accessToken) { + let accessToken = typeof this.configuration.accessToken === 'function' + ? this.configuration.accessToken() + : this.configuration.accessToken; + headerParams['Authorization'] = 'Bearer ' + accessToken; + } + + + let requestOptions: JQueryAjaxSettings = { + url: localVarPath, + type: 'DELETE', + headers: headerParams, + processData: false + }; + + if (headerParams['Content-Type']) { + requestOptions.contentType = headerParams['Content-Type']; + } + + let dfd = $.Deferred(); + $.ajax(requestOptions).then( + (data: any, textStatus: string, jqXHR: JQueryXHR) => + dfd.resolve(jqXHR, data), + (xhr: JQueryXHR, textStatus: string, errorThrown: string) => + dfd.reject(xhr, 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 = {}; + + if (status) { + status.forEach((element: any) => { + queryParameters['status'].push(element); + }); + } + + localVarPath = localVarPath + "?" + $.param(queryParameters); + // to determine the Content-Type header + let consumes: string[] = [ + ]; + + // to determine the Accept header + let produces: string[] = [ + 'application/json', + 'application/xml' + ]; + + // authentication (petstore_auth) required + // oauth required + if (this.configuration.accessToken) { + let accessToken = typeof this.configuration.accessToken === 'function' + ? this.configuration.accessToken() + : this.configuration.accessToken; + headerParams['Authorization'] = 'Bearer ' + accessToken; + } + + + let requestOptions: JQueryAjaxSettings = { + url: localVarPath, + type: 'GET', + headers: headerParams, + processData: false + }; + + if (headerParams['Content-Type']) { + requestOptions.contentType = headerParams['Content-Type']; + } + + let dfd = $.Deferred(); + $.ajax(requestOptions).then( + (data: Array, textStatus: string, jqXHR: JQueryXHR) => + dfd.resolve(jqXHR, data), + (xhr: JQueryXHR, textStatus: string, errorThrown: string) => + dfd.reject(xhr, 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 = {}; + + if (tags) { + tags.forEach((element: any) => { + queryParameters['tags'].push(element); + }); + } + + localVarPath = localVarPath + "?" + $.param(queryParameters); + // to determine the Content-Type header + let consumes: string[] = [ + ]; + + // to determine the Accept header + let produces: string[] = [ + 'application/json', + 'application/xml' + ]; + + // authentication (petstore_auth) required + // oauth required + if (this.configuration.accessToken) { + let accessToken = typeof this.configuration.accessToken === 'function' + ? this.configuration.accessToken() + : this.configuration.accessToken; + headerParams['Authorization'] = 'Bearer ' + accessToken; + } + + + let requestOptions: JQueryAjaxSettings = { + url: localVarPath, + type: 'GET', + headers: headerParams, + processData: false + }; + + if (headerParams['Content-Type']) { + requestOptions.contentType = headerParams['Content-Type']; + } + + let dfd = $.Deferred(); + $.ajax(requestOptions).then( + (data: Array, textStatus: string, jqXHR: JQueryXHR) => + dfd.resolve(jqXHR, data), + (xhr: JQueryXHR, textStatus: string, errorThrown: string) => + dfd.reject(xhr, 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: models.Pet; }> { + let localVarPath = this.basePath + '/pet/{petId}'.replace('{' + 'petId' + '}', String(petId)); + + let queryParameters: any = {}; + let headerParams: any = {}; + // 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); + // to determine the Content-Type header + let consumes: string[] = [ + ]; + + // to determine the Accept header + let produces: string[] = [ + 'application/json', + 'application/xml' + ]; + + // authentication (api_key) required + if (this.configuration.apiKey) { + headerParams['api_key'] = this.configuration.apiKey; + } + + // authentication (petstore_auth) required + // oauth required + if (this.configuration.accessToken) { + let accessToken = typeof this.configuration.accessToken === 'function' + ? this.configuration.accessToken() + : this.configuration.accessToken; + headerParams['Authorization'] = 'Bearer ' + accessToken; + } + + + let requestOptions: JQueryAjaxSettings = { + url: localVarPath, + type: 'GET', + headers: headerParams, + processData: false + }; + + if (headerParams['Content-Type']) { + requestOptions.contentType = headerParams['Content-Type']; + } + + let dfd = $.Deferred(); + $.ajax(requestOptions).then( + (data: models.Pet, textStatus: string, jqXHR: JQueryXHR) => + dfd.resolve(jqXHR, data), + (xhr: JQueryXHR, textStatus: string, errorThrown: string) => + dfd.reject(xhr, errorThrown) + ); + return dfd.promise(); + } + + /** + * Update an existing pet + * + * @param body Pet object that needs to be added to the store + */ + public updatePet(body?: models.Pet): JQueryPromise<{ response: JQueryXHR; body?: any; }> { + let localVarPath = this.basePath + '/pet'; + + let queryParameters: any = {}; + let headerParams: any = {}; + + + localVarPath = localVarPath + "?" + $.param(queryParameters); + // to determine the Content-Type header + let consumes: string[] = [ + 'application/json', + 'application/xml' + ]; + + // to determine the Accept header + let produces: string[] = [ + 'application/json', + 'application/xml' + ]; + + // authentication (petstore_auth) required + // oauth required + if (this.configuration.accessToken) { + let accessToken = typeof this.configuration.accessToken === 'function' + ? this.configuration.accessToken() + : this.configuration.accessToken; + headerParams['Authorization'] = 'Bearer ' + accessToken; + } + + + headerParams['Content-Type'] = 'application/json'; + + let requestOptions: JQueryAjaxSettings = { + url: localVarPath, + type: 'PUT', + headers: headerParams, + processData: false + }; + + requestOptions.data = JSON.stringify(body); + if (headerParams['Content-Type']) { + requestOptions.contentType = headerParams['Content-Type']; + } + + let dfd = $.Deferred(); + $.ajax(requestOptions).then( + (data: any, textStatus: string, jqXHR: JQueryXHR) => + dfd.resolve(jqXHR, data), + (xhr: JQueryXHR, textStatus: string, errorThrown: string) => + dfd.reject(xhr, 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 = {}; + let formParams = new FormData(); + let reqHasFile = false; + + // 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); + if (name !== null && name !== undefined) { + formParams.append('name', name); + } + + if (status !== null && status !== undefined) { + formParams.append('status', status); + } + + // to determine the Content-Type header + let consumes: string[] = [ + 'application/x-www-form-urlencoded' + ]; + + // to determine the Accept header + let produces: string[] = [ + 'application/json', + 'application/xml' + ]; + + // authentication (petstore_auth) required + // oauth required + if (this.configuration.accessToken) { + let accessToken = typeof this.configuration.accessToken === 'function' + ? this.configuration.accessToken() + : this.configuration.accessToken; + headerParams['Authorization'] = 'Bearer ' + accessToken; + } + + if (!reqHasFile) { + headerParams['Content-Type'] = 'application/x-www-form-urlencoded'; + } + + + let requestOptions: JQueryAjaxSettings = { + url: localVarPath, + type: 'POST', + headers: headerParams, + processData: false + }; + + if (headerParams['Content-Type']) { + requestOptions.contentType = headerParams['Content-Type']; + } + requestOptions.data = formParams; + if (reqHasFile) { + requestOptions.contentType = false; + } + + let dfd = $.Deferred(); + $.ajax(requestOptions).then( + (data: any, textStatus: string, jqXHR: JQueryXHR) => + dfd.resolve(jqXHR, data), + (xhr: JQueryXHR, textStatus: string, errorThrown: string) => + dfd.reject(xhr, 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 = {}; + let formParams = new FormData(); + let reqHasFile = false; + + // 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); + if (additionalMetadata !== null && additionalMetadata !== undefined) { + formParams.append('additionalMetadata', additionalMetadata); + } + + reqHasFile = true; + if (file !== null && file !== undefined) { + formParams.append('file', file); + } + + // to determine the Content-Type header + let consumes: string[] = [ + 'multipart/form-data' + ]; + + // to determine the Accept header + let produces: string[] = [ + 'application/json', + 'application/xml' + ]; + + // authentication (petstore_auth) required + // oauth required + if (this.configuration.accessToken) { + let accessToken = typeof this.configuration.accessToken === 'function' + ? this.configuration.accessToken() + : this.configuration.accessToken; + headerParams['Authorization'] = 'Bearer ' + accessToken; + } + + if (!reqHasFile) { + headerParams['Content-Type'] = 'application/x-www-form-urlencoded'; + } + + + let requestOptions: JQueryAjaxSettings = { + url: localVarPath, + type: 'POST', + headers: headerParams, + processData: false + }; + + if (headerParams['Content-Type']) { + requestOptions.contentType = headerParams['Content-Type']; + } + requestOptions.data = formParams; + if (reqHasFile) { + requestOptions.contentType = false; + } + + let dfd = $.Deferred(); + $.ajax(requestOptions).then( + (data: any, textStatus: string, jqXHR: JQueryXHR) => + dfd.resolve(jqXHR, data), + (xhr: JQueryXHR, textStatus: string, errorThrown: string) => + dfd.reject(xhr, errorThrown) + ); + return dfd.promise(); + } + +} diff --git a/samples/client/petstore/typescript-jquery/npm/api/StoreApi.ts b/samples/client/petstore/typescript-jquery/npm/api/StoreApi.ts new file mode 100644 index 00000000000..a2495cc0f30 --- /dev/null +++ b/samples/client/petstore/typescript-jquery/npm/api/StoreApi.ts @@ -0,0 +1,239 @@ +/** + * Swagger Petstore + * This is a sample server Petstore server. You can find out more about Swagger at http://swagger.io or on irc.freenode.net, #swagger. For this sample, you can use the api key \"special-key\" to test the authorization filters + * + * OpenAPI spec version: 1.0.0 + * Contact: apiteam@wordnik.com + * + * NOTE: This class is auto generated by the swagger code generator program. + * https://github.com/swagger-api/swagger-codegen.git + * Do not edit the class manually. + */ + + +import * as $ from 'jquery'; +import * as models from '../model/models'; +import { COLLECTION_FORMATS } from '../variables'; +import { Configuration } from '../configuration'; + +/* tslint:disable:no-unused-variable member-ordering */ + + +export class StoreApi { + protected basePath = 'http://petstore.swagger.io/v2'; + public defaultHeaders: Array = []; + public configuration: Configuration = new Configuration(); + + constructor(basePath?: string, configuration?: Configuration) { + if (basePath) { + this.basePath = basePath; + } + if (configuration) { + this.configuration = configuration; + } + } + + 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 = {}; + // 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); + // to determine the Content-Type header + let consumes: string[] = [ + ]; + + // to determine the Accept header + let produces: string[] = [ + 'application/json', + 'application/xml' + ]; + + + let requestOptions: JQueryAjaxSettings = { + url: localVarPath, + type: 'DELETE', + headers: headerParams, + processData: false + }; + + if (headerParams['Content-Type']) { + requestOptions.contentType = headerParams['Content-Type']; + } + + let dfd = $.Deferred(); + $.ajax(requestOptions).then( + (data: any, textStatus: string, jqXHR: JQueryXHR) => + dfd.resolve(jqXHR, data), + (xhr: JQueryXHR, textStatus: string, errorThrown: string) => + dfd.reject(xhr, 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 = {}; + + localVarPath = localVarPath + "?" + $.param(queryParameters); + // to determine the Content-Type header + let consumes: string[] = [ + ]; + + // to determine the Accept header + let produces: string[] = [ + 'application/json', + 'application/xml' + ]; + + // authentication (api_key) required + if (this.configuration.apiKey) { + headerParams['api_key'] = this.configuration.apiKey; + } + + + let requestOptions: JQueryAjaxSettings = { + url: localVarPath, + type: 'GET', + headers: headerParams, + processData: false + }; + + if (headerParams['Content-Type']) { + requestOptions.contentType = headerParams['Content-Type']; + } + + let dfd = $.Deferred(); + $.ajax(requestOptions).then( + (data: { [key: string]: number; }, textStatus: string, jqXHR: JQueryXHR) => + dfd.resolve(jqXHR, data), + (xhr: JQueryXHR, textStatus: string, errorThrown: string) => + dfd.reject(xhr, 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: models.Order; }> { + let localVarPath = this.basePath + '/store/order/{orderId}'.replace('{' + 'orderId' + '}', String(orderId)); + + let queryParameters: any = {}; + let headerParams: any = {}; + // 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); + // to determine the Content-Type header + let consumes: string[] = [ + ]; + + // to determine the Accept header + let produces: string[] = [ + 'application/json', + 'application/xml' + ]; + + + let requestOptions: JQueryAjaxSettings = { + url: localVarPath, + type: 'GET', + headers: headerParams, + processData: false + }; + + if (headerParams['Content-Type']) { + requestOptions.contentType = headerParams['Content-Type']; + } + + let dfd = $.Deferred(); + $.ajax(requestOptions).then( + (data: models.Order, textStatus: string, jqXHR: JQueryXHR) => + dfd.resolve(jqXHR, data), + (xhr: JQueryXHR, textStatus: string, errorThrown: string) => + dfd.reject(xhr, errorThrown) + ); + return dfd.promise(); + } + + /** + * Place an order for a pet + * + * @param body order placed for purchasing the pet + */ + public placeOrder(body?: models.Order): JQueryPromise<{ response: JQueryXHR; body: models.Order; }> { + let localVarPath = this.basePath + '/store/order'; + + let queryParameters: any = {}; + let headerParams: any = {}; + + + localVarPath = localVarPath + "?" + $.param(queryParameters); + // to determine the Content-Type header + let consumes: string[] = [ + ]; + + // to determine the Accept header + let produces: string[] = [ + 'application/json', + 'application/xml' + ]; + + + headerParams['Content-Type'] = 'application/json'; + + let requestOptions: JQueryAjaxSettings = { + url: localVarPath, + type: 'POST', + headers: headerParams, + processData: false + }; + + requestOptions.data = JSON.stringify(body); + if (headerParams['Content-Type']) { + requestOptions.contentType = headerParams['Content-Type']; + } + + let dfd = $.Deferred(); + $.ajax(requestOptions).then( + (data: models.Order, textStatus: string, jqXHR: JQueryXHR) => + dfd.resolve(jqXHR, data), + (xhr: JQueryXHR, textStatus: string, errorThrown: string) => + dfd.reject(xhr, errorThrown) + ); + return dfd.promise(); + } + +} diff --git a/samples/client/petstore/typescript-jquery/npm/api/UserApi.ts b/samples/client/petstore/typescript-jquery/npm/api/UserApi.ts new file mode 100644 index 00000000000..53349124ed6 --- /dev/null +++ b/samples/client/petstore/typescript-jquery/npm/api/UserApi.ts @@ -0,0 +1,437 @@ +/** + * Swagger Petstore + * This is a sample server Petstore server. You can find out more about Swagger at http://swagger.io or on irc.freenode.net, #swagger. For this sample, you can use the api key \"special-key\" to test the authorization filters + * + * OpenAPI spec version: 1.0.0 + * Contact: apiteam@wordnik.com + * + * NOTE: This class is auto generated by the swagger code generator program. + * https://github.com/swagger-api/swagger-codegen.git + * Do not edit the class manually. + */ + + +import * as $ from 'jquery'; +import * as models from '../model/models'; +import { COLLECTION_FORMATS } from '../variables'; +import { Configuration } from '../configuration'; + +/* tslint:disable:no-unused-variable member-ordering */ + + +export class UserApi { + protected basePath = 'http://petstore.swagger.io/v2'; + public defaultHeaders: Array = []; + public configuration: Configuration = new Configuration(); + + constructor(basePath?: string, configuration?: Configuration) { + if (basePath) { + this.basePath = basePath; + } + if (configuration) { + this.configuration = configuration; + } + } + + 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?: models.User): JQueryPromise<{ response: JQueryXHR; body?: any; }> { + let localVarPath = this.basePath + '/user'; + + let queryParameters: any = {}; + let headerParams: any = {}; + + + localVarPath = localVarPath + "?" + $.param(queryParameters); + // to determine the Content-Type header + let consumes: string[] = [ + ]; + + // to determine the Accept header + let produces: string[] = [ + 'application/json', + 'application/xml' + ]; + + + headerParams['Content-Type'] = 'application/json'; + + let requestOptions: JQueryAjaxSettings = { + url: localVarPath, + type: 'POST', + headers: headerParams, + processData: false + }; + + requestOptions.data = JSON.stringify(body); + if (headerParams['Content-Type']) { + requestOptions.contentType = headerParams['Content-Type']; + } + + let dfd = $.Deferred(); + $.ajax(requestOptions).then( + (data: any, textStatus: string, jqXHR: JQueryXHR) => + dfd.resolve(jqXHR, data), + (xhr: JQueryXHR, textStatus: string, errorThrown: string) => + dfd.reject(xhr, 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 = {}; + + + localVarPath = localVarPath + "?" + $.param(queryParameters); + // to determine the Content-Type header + let consumes: string[] = [ + ]; + + // to determine the Accept header + let produces: string[] = [ + 'application/json', + 'application/xml' + ]; + + + headerParams['Content-Type'] = 'application/json'; + + let requestOptions: JQueryAjaxSettings = { + url: localVarPath, + type: 'POST', + headers: headerParams, + processData: false + }; + + requestOptions.data = JSON.stringify(body); + if (headerParams['Content-Type']) { + requestOptions.contentType = headerParams['Content-Type']; + } + + let dfd = $.Deferred(); + $.ajax(requestOptions).then( + (data: any, textStatus: string, jqXHR: JQueryXHR) => + dfd.resolve(jqXHR, data), + (xhr: JQueryXHR, textStatus: string, errorThrown: string) => + dfd.reject(xhr, 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 = {}; + + + localVarPath = localVarPath + "?" + $.param(queryParameters); + // to determine the Content-Type header + let consumes: string[] = [ + ]; + + // to determine the Accept header + let produces: string[] = [ + 'application/json', + 'application/xml' + ]; + + + headerParams['Content-Type'] = 'application/json'; + + let requestOptions: JQueryAjaxSettings = { + url: localVarPath, + type: 'POST', + headers: headerParams, + processData: false + }; + + requestOptions.data = JSON.stringify(body); + if (headerParams['Content-Type']) { + requestOptions.contentType = headerParams['Content-Type']; + } + + let dfd = $.Deferred(); + $.ajax(requestOptions).then( + (data: any, textStatus: string, jqXHR: JQueryXHR) => + dfd.resolve(jqXHR, data), + (xhr: JQueryXHR, textStatus: string, errorThrown: string) => + dfd.reject(xhr, 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 = {}; + // 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); + // to determine the Content-Type header + let consumes: string[] = [ + ]; + + // to determine the Accept header + let produces: string[] = [ + 'application/json', + 'application/xml' + ]; + + + let requestOptions: JQueryAjaxSettings = { + url: localVarPath, + type: 'DELETE', + headers: headerParams, + processData: false + }; + + if (headerParams['Content-Type']) { + requestOptions.contentType = headerParams['Content-Type']; + } + + let dfd = $.Deferred(); + $.ajax(requestOptions).then( + (data: any, textStatus: string, jqXHR: JQueryXHR) => + dfd.resolve(jqXHR, data), + (xhr: JQueryXHR, textStatus: string, errorThrown: string) => + dfd.reject(xhr, 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: models.User; }> { + let localVarPath = this.basePath + '/user/{username}'.replace('{' + 'username' + '}', String(username)); + + let queryParameters: any = {}; + let headerParams: any = {}; + // 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); + // to determine the Content-Type header + let consumes: string[] = [ + ]; + + // to determine the Accept header + let produces: string[] = [ + 'application/json', + 'application/xml' + ]; + + + let requestOptions: JQueryAjaxSettings = { + url: localVarPath, + type: 'GET', + headers: headerParams, + processData: false + }; + + if (headerParams['Content-Type']) { + requestOptions.contentType = headerParams['Content-Type']; + } + + let dfd = $.Deferred(); + $.ajax(requestOptions).then( + (data: models.User, textStatus: string, jqXHR: JQueryXHR) => + dfd.resolve(jqXHR, data), + (xhr: JQueryXHR, textStatus: string, errorThrown: string) => + dfd.reject(xhr, 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 = {}; + + + if (username !== null && username !== undefined) { + queryParameters['username'] = username; + } + if (password !== null && password !== undefined) { + queryParameters['password'] = password; + } + + localVarPath = localVarPath + "?" + $.param(queryParameters); + // to determine the Content-Type header + let consumes: string[] = [ + ]; + + // to determine the Accept header + let produces: string[] = [ + 'application/json', + 'application/xml' + ]; + + + let requestOptions: JQueryAjaxSettings = { + url: localVarPath, + type: 'GET', + headers: headerParams, + processData: false + }; + + if (headerParams['Content-Type']) { + requestOptions.contentType = headerParams['Content-Type']; + } + + let dfd = $.Deferred(); + $.ajax(requestOptions).then( + (data: string, textStatus: string, jqXHR: JQueryXHR) => + dfd.resolve(jqXHR, data), + (xhr: JQueryXHR, textStatus: string, errorThrown: string) => + dfd.reject(xhr, 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 = {}; + + localVarPath = localVarPath + "?" + $.param(queryParameters); + // to determine the Content-Type header + let consumes: string[] = [ + ]; + + // to determine the Accept header + let produces: string[] = [ + 'application/json', + 'application/xml' + ]; + + + let requestOptions: JQueryAjaxSettings = { + url: localVarPath, + type: 'GET', + headers: headerParams, + processData: false + }; + + if (headerParams['Content-Type']) { + requestOptions.contentType = headerParams['Content-Type']; + } + + let dfd = $.Deferred(); + $.ajax(requestOptions).then( + (data: any, textStatus: string, jqXHR: JQueryXHR) => + dfd.resolve(jqXHR, data), + (xhr: JQueryXHR, textStatus: string, errorThrown: string) => + dfd.reject(xhr, 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?: models.User): JQueryPromise<{ response: JQueryXHR; body?: any; }> { + let localVarPath = this.basePath + '/user/{username}'.replace('{' + 'username' + '}', String(username)); + + let queryParameters: any = {}; + let headerParams: any = {}; + // 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); + // to determine the Content-Type header + let consumes: string[] = [ + ]; + + // to determine the Accept header + let produces: string[] = [ + 'application/json', + 'application/xml' + ]; + + + headerParams['Content-Type'] = 'application/json'; + + let requestOptions: JQueryAjaxSettings = { + url: localVarPath, + type: 'PUT', + headers: headerParams, + processData: false + }; + + requestOptions.data = JSON.stringify(body); + if (headerParams['Content-Type']) { + requestOptions.contentType = headerParams['Content-Type']; + } + + let dfd = $.Deferred(); + $.ajax(requestOptions).then( + (data: any, textStatus: string, jqXHR: JQueryXHR) => + dfd.resolve(jqXHR, data), + (xhr: JQueryXHR, textStatus: string, errorThrown: string) => + dfd.reject(xhr, errorThrown) + ); + return dfd.promise(); + } + +} diff --git a/samples/client/petstore/typescript-jquery/npm/api/api.ts b/samples/client/petstore/typescript-jquery/npm/api/api.ts new file mode 100644 index 00000000000..4ddd9e29663 --- /dev/null +++ b/samples/client/petstore/typescript-jquery/npm/api/api.ts @@ -0,0 +1,7 @@ +export * from './PetApi'; +import { PetApi } from './PetApi'; +export * from './StoreApi'; +import { StoreApi } from './StoreApi'; +export * from './UserApi'; +import { UserApi } from './UserApi'; +export const APIS = [PetApi, StoreApi, UserApi]; diff --git a/samples/client/petstore/typescript-jquery/npm/configuration.ts b/samples/client/petstore/typescript-jquery/npm/configuration.ts new file mode 100644 index 00000000000..a566a180e4e --- /dev/null +++ b/samples/client/petstore/typescript-jquery/npm/configuration.ts @@ -0,0 +1,6 @@ +export class Configuration { + apiKey: string; + username: string; + password: string; + accessToken: string | (() => string); +} \ No newline at end of file diff --git a/samples/client/petstore/typescript-jquery/npm/index.ts b/samples/client/petstore/typescript-jquery/npm/index.ts new file mode 100644 index 00000000000..d097c728017 --- /dev/null +++ b/samples/client/petstore/typescript-jquery/npm/index.ts @@ -0,0 +1,4 @@ +export * from './api/api'; +export * from './model/models'; +export * from './variables'; +export * from './configuration'; \ No newline at end of file diff --git a/samples/client/petstore/typescript-jquery/npm/model/Category.ts b/samples/client/petstore/typescript-jquery/npm/model/Category.ts new file mode 100644 index 00000000000..ffdacd4f707 --- /dev/null +++ b/samples/client/petstore/typescript-jquery/npm/model/Category.ts @@ -0,0 +1,20 @@ +/** + * Swagger Petstore + * This is a sample server Petstore server. You can find out more about Swagger at http://swagger.io or on irc.freenode.net, #swagger. For this sample, you can use the api key \"special-key\" to test the authorization filters + * + * OpenAPI spec version: 1.0.0 + * Contact: apiteam@wordnik.com + * + * NOTE: This class is auto generated by the swagger code generator program. + * https://github.com/swagger-api/swagger-codegen.git + * Do not edit the class manually. + */ + +import * as models from './models'; + +export interface Category { + id?: number; + + name?: string; + +} diff --git a/samples/client/petstore/typescript-jquery/npm/model/Order.ts b/samples/client/petstore/typescript-jquery/npm/model/Order.ts new file mode 100644 index 00000000000..9c47071c5b6 --- /dev/null +++ b/samples/client/petstore/typescript-jquery/npm/model/Order.ts @@ -0,0 +1,38 @@ +/** + * Swagger Petstore + * This is a sample server Petstore server. You can find out more about Swagger at http://swagger.io or on irc.freenode.net, #swagger. For this sample, you can use the api key \"special-key\" to test the authorization filters + * + * OpenAPI spec version: 1.0.0 + * Contact: apiteam@wordnik.com + * + * NOTE: This class is auto generated by the swagger code generator program. + * https://github.com/swagger-api/swagger-codegen.git + * Do not edit the class manually. + */ + +import * as models from './models'; + +export interface 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' + } +} diff --git a/samples/client/petstore/typescript-jquery/npm/model/Pet.ts b/samples/client/petstore/typescript-jquery/npm/model/Pet.ts new file mode 100644 index 00000000000..d64dc809e53 --- /dev/null +++ b/samples/client/petstore/typescript-jquery/npm/model/Pet.ts @@ -0,0 +1,38 @@ +/** + * Swagger Petstore + * This is a sample server Petstore server. You can find out more about Swagger at http://swagger.io or on irc.freenode.net, #swagger. For this sample, you can use the api key \"special-key\" to test the authorization filters + * + * OpenAPI spec version: 1.0.0 + * Contact: apiteam@wordnik.com + * + * NOTE: This class is auto generated by the swagger code generator program. + * https://github.com/swagger-api/swagger-codegen.git + * Do not edit the class manually. + */ + +import * as models from './models'; + +export interface Pet { + id?: number; + + category?: models.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' + } +} diff --git a/samples/client/petstore/typescript-jquery/npm/model/Tag.ts b/samples/client/petstore/typescript-jquery/npm/model/Tag.ts new file mode 100644 index 00000000000..8a3b99ae9ca --- /dev/null +++ b/samples/client/petstore/typescript-jquery/npm/model/Tag.ts @@ -0,0 +1,20 @@ +/** + * Swagger Petstore + * This is a sample server Petstore server. You can find out more about Swagger at http://swagger.io or on irc.freenode.net, #swagger. For this sample, you can use the api key \"special-key\" to test the authorization filters + * + * OpenAPI spec version: 1.0.0 + * Contact: apiteam@wordnik.com + * + * NOTE: This class is auto generated by the swagger code generator program. + * https://github.com/swagger-api/swagger-codegen.git + * Do not edit the class manually. + */ + +import * as models from './models'; + +export interface Tag { + id?: number; + + name?: string; + +} diff --git a/samples/client/petstore/typescript-jquery/npm/model/User.ts b/samples/client/petstore/typescript-jquery/npm/model/User.ts new file mode 100644 index 00000000000..43d00f7b318 --- /dev/null +++ b/samples/client/petstore/typescript-jquery/npm/model/User.ts @@ -0,0 +1,35 @@ +/** + * Swagger Petstore + * This is a sample server Petstore server. You can find out more about Swagger at http://swagger.io or on irc.freenode.net, #swagger. For this sample, you can use the api key \"special-key\" to test the authorization filters + * + * OpenAPI spec version: 1.0.0 + * Contact: apiteam@wordnik.com + * + * NOTE: This class is auto generated by the swagger code generator program. + * https://github.com/swagger-api/swagger-codegen.git + * Do not edit the class manually. + */ + +import * as models from './models'; + +export interface User { + id?: number; + + username?: string; + + firstName?: string; + + lastName?: string; + + email?: string; + + password?: string; + + phone?: string; + + /** + * User Status + */ + userStatus?: number; + +} diff --git a/samples/client/petstore/typescript-jquery/npm/model/models.ts b/samples/client/petstore/typescript-jquery/npm/model/models.ts new file mode 100644 index 00000000000..92dac02846c --- /dev/null +++ b/samples/client/petstore/typescript-jquery/npm/model/models.ts @@ -0,0 +1,5 @@ +export * from './Category'; +export * from './Order'; +export * from './Pet'; +export * from './Tag'; +export * from './User'; diff --git a/samples/client/petstore/typescript-jquery/npm/variables.ts b/samples/client/petstore/typescript-jquery/npm/variables.ts new file mode 100644 index 00000000000..505ce9355e2 --- /dev/null +++ b/samples/client/petstore/typescript-jquery/npm/variables.ts @@ -0,0 +1,7 @@ + +export const COLLECTION_FORMATS = { + 'csv': ',', + 'tsv': ' ', + 'ssv': ' ', + 'pipes': '|' +} \ No newline at end of file