forked from loafle/openapi-generator-original
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
This commit is contained in:
parent
6b40bc6d30
commit
616f57a592
@ -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";
|
||||
|
@ -1,175 +1,41 @@
|
||||
{{>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}} = <any> {{{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<string> = [];
|
||||
public configuration: Configuration = new Configuration();
|
||||
|
||||
protected authentications = {
|
||||
'default': <Authentication>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}}
|
||||
constructor(basePath?: string, configuration?: Configuration) {
|
||||
if (basePath) {
|
||||
this.basePath = basePath;
|
||||
}
|
||||
} else {
|
||||
if (basePathOrUsername) {
|
||||
this.basePath = basePathOrUsername
|
||||
}
|
||||
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<T1, T2 extends T1>(objA: T2, objB: T2): T1|T2 {
|
||||
for(let key in objB){
|
||||
if(objB.hasOwnProperty(key)){
|
||||
for (let key in objB) {
|
||||
if (objB.hasOwnProperty(key)) {
|
||||
objA[key] = objB[key];
|
||||
}
|
||||
}
|
||||
@ -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}}'] = <string><any>{{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}}', <any>{{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}}
|
||||
|
@ -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}}
|
@ -0,0 +1,6 @@
|
||||
export class Configuration {
|
||||
apiKey: string;
|
||||
username: string;
|
||||
password: string;
|
||||
accessToken: string | (() => string);
|
||||
}
|
@ -0,0 +1,4 @@
|
||||
export * from './api/api';
|
||||
export * from './model/models';
|
||||
export * from './variables';
|
||||
export * from './configuration';
|
@ -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.
|
||||
*/
|
@ -0,0 +1,13 @@
|
||||
{{>licenseInfo}}
|
||||
import * as models from './models';
|
||||
{{#models}}
|
||||
{{#model}}
|
||||
|
||||
{{#description}}
|
||||
/**
|
||||
* {{{description}}}
|
||||
*/
|
||||
{{/description}}
|
||||
{{#isEnum}}{{>modelEnum}}{{/isEnum}}{{^isEnum}}{{>modelGeneric}}{{/isEnum}}
|
||||
{{/model}}
|
||||
{{/models}}
|
@ -0,0 +1,12 @@
|
||||
{{#description}}
|
||||
/**
|
||||
* {{{description}}}
|
||||
*/
|
||||
{{/description}}
|
||||
export enum {{classname}} {
|
||||
{{#allowableValues}}
|
||||
{{#enumVars}}
|
||||
{{{name}}} = <any> {{{value}}}{{^-last}},{{/-last}}
|
||||
{{/enumVars}}
|
||||
{{/allowableValues}}
|
||||
}
|
@ -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}}} = <any> {{{value}}}{{^-last}},{{/-last}}
|
||||
{{/enumVars}}
|
||||
{{/allowableValues}}
|
||||
}
|
||||
{{/isEnum}}
|
||||
{{/vars}}
|
||||
}{{/hasEnums}}
|
@ -0,0 +1,5 @@
|
||||
{{#models}}
|
||||
{{#model}}
|
||||
export * from './{{{ classname }}}';
|
||||
{{/model}}
|
||||
{{/models}}
|
@ -0,0 +1,7 @@
|
||||
|
||||
export const COLLECTION_FORMATS = {
|
||||
'csv': ',',
|
||||
'tsv': ' ',
|
||||
'ssv': ' ',
|
||||
'pipes': '|'
|
||||
}
|
571
samples/client/petstore/typescript-jquery/default/api/PetApi.ts
Normal file
571
samples/client/petstore/typescript-jquery/default/api/PetApi.ts
Normal file
@ -0,0 +1,571 @@
|
||||
/**
|
||||
* Swagger Petstore
|
||||
* This is a sample server Petstore server. You can find out more about Swagger at <a href=\"http://swagger.io\">http://swagger.io</a> or on irc.freenode.net, #swagger. For this sample, you can use the api key \"special-key\" to test the authorization filters
|
||||
*
|
||||
* 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<string> = [];
|
||||
public configuration: Configuration = new Configuration();
|
||||
|
||||
constructor(basePath?: string, configuration?: Configuration) {
|
||||
if (basePath) {
|
||||
this.basePath = basePath;
|
||||
}
|
||||
if (configuration) {
|
||||
this.configuration = configuration;
|
||||
}
|
||||
}
|
||||
|
||||
private extendObj<T1, T2 extends T1>(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<string>): JQueryPromise<{ response: JQueryXHR; body: Array<models.Pet>; }> {
|
||||
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<models.Pet>, 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<string>): JQueryPromise<{ response: JQueryXHR; body: Array<models.Pet>; }> {
|
||||
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<models.Pet>, 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', <any>name);
|
||||
}
|
||||
|
||||
if (status !== null && status !== undefined) {
|
||||
formParams.append('status', <any>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', <any>additionalMetadata);
|
||||
}
|
||||
|
||||
reqHasFile = true;
|
||||
if (file !== null && file !== undefined) {
|
||||
formParams.append('file', <any>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();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,239 @@
|
||||
/**
|
||||
* Swagger Petstore
|
||||
* This is a sample server Petstore server. You can find out more about Swagger at <a href=\"http://swagger.io\">http://swagger.io</a> or on irc.freenode.net, #swagger. For this sample, you can use the api key \"special-key\" to test the authorization filters
|
||||
*
|
||||
* 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<string> = [];
|
||||
public configuration: Configuration = new Configuration();
|
||||
|
||||
constructor(basePath?: string, configuration?: Configuration) {
|
||||
if (basePath) {
|
||||
this.basePath = basePath;
|
||||
}
|
||||
if (configuration) {
|
||||
this.configuration = configuration;
|
||||
}
|
||||
}
|
||||
|
||||
private extendObj<T1, T2 extends T1>(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();
|
||||
}
|
||||
|
||||
}
|
437
samples/client/petstore/typescript-jquery/default/api/UserApi.ts
Normal file
437
samples/client/petstore/typescript-jquery/default/api/UserApi.ts
Normal file
@ -0,0 +1,437 @@
|
||||
/**
|
||||
* Swagger Petstore
|
||||
* This is a sample server Petstore server. You can find out more about Swagger at <a href=\"http://swagger.io\">http://swagger.io</a> or on irc.freenode.net, #swagger. For this sample, you can use the api key \"special-key\" to test the authorization filters
|
||||
*
|
||||
* 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<string> = [];
|
||||
public configuration: Configuration = new Configuration();
|
||||
|
||||
constructor(basePath?: string, configuration?: Configuration) {
|
||||
if (basePath) {
|
||||
this.basePath = basePath;
|
||||
}
|
||||
if (configuration) {
|
||||
this.configuration = configuration;
|
||||
}
|
||||
}
|
||||
|
||||
private extendObj<T1, T2 extends T1>(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<models.User>): 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<models.User>): 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'] = <string><any>username;
|
||||
}
|
||||
if (password !== null && password !== undefined) {
|
||||
queryParameters['password'] = <string><any>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();
|
||||
}
|
||||
|
||||
}
|
@ -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];
|
@ -0,0 +1,6 @@
|
||||
export class Configuration {
|
||||
apiKey: string;
|
||||
username: string;
|
||||
password: string;
|
||||
accessToken: string | (() => string);
|
||||
}
|
@ -0,0 +1,4 @@
|
||||
export * from './api/api';
|
||||
export * from './model/models';
|
||||
export * from './variables';
|
||||
export * from './configuration';
|
@ -0,0 +1,20 @@
|
||||
/**
|
||||
* Swagger Petstore
|
||||
* This is a sample server Petstore server. You can find out more about Swagger at <a href=\"http://swagger.io\">http://swagger.io</a> or on irc.freenode.net, #swagger. For this sample, you can use the api key \"special-key\" to test the authorization filters
|
||||
*
|
||||
* 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;
|
||||
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
/**
|
||||
* Swagger Petstore
|
||||
* This is a sample server Petstore server. You can find out more about Swagger at <a href=\"http://swagger.io\">http://swagger.io</a> or on irc.freenode.net, #swagger. For this sample, you can use the api key \"special-key\" to test the authorization filters
|
||||
*
|
||||
* 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 = <any> 'placed',
|
||||
Approved = <any> 'approved',
|
||||
Delivered = <any> 'delivered'
|
||||
}
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
/**
|
||||
* Swagger Petstore
|
||||
* This is a sample server Petstore server. You can find out more about Swagger at <a href=\"http://swagger.io\">http://swagger.io</a> or on irc.freenode.net, #swagger. For this sample, you can use the api key \"special-key\" to test the authorization filters
|
||||
*
|
||||
* 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<string>;
|
||||
|
||||
tags?: Array<models.Tag>;
|
||||
|
||||
/**
|
||||
* pet status in the store
|
||||
*/
|
||||
status?: Pet.StatusEnum;
|
||||
|
||||
}
|
||||
export namespace Pet {
|
||||
export enum StatusEnum {
|
||||
Available = <any> 'available',
|
||||
Pending = <any> 'pending',
|
||||
Sold = <any> 'sold'
|
||||
}
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
/**
|
||||
* Swagger Petstore
|
||||
* This is a sample server Petstore server. You can find out more about Swagger at <a href=\"http://swagger.io\">http://swagger.io</a> or on irc.freenode.net, #swagger. For this sample, you can use the api key \"special-key\" to test the authorization filters
|
||||
*
|
||||
* 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;
|
||||
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
/**
|
||||
* Swagger Petstore
|
||||
* This is a sample server Petstore server. You can find out more about Swagger at <a href=\"http://swagger.io\">http://swagger.io</a> or on irc.freenode.net, #swagger. For this sample, you can use the api key \"special-key\" to test the authorization filters
|
||||
*
|
||||
* 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;
|
||||
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
export * from './Category';
|
||||
export * from './Order';
|
||||
export * from './Pet';
|
||||
export * from './Tag';
|
||||
export * from './User';
|
@ -0,0 +1,7 @@
|
||||
|
||||
export const COLLECTION_FORMATS = {
|
||||
'csv': ',',
|
||||
'tsv': ' ',
|
||||
'ssv': ' ',
|
||||
'pipes': '|'
|
||||
}
|
571
samples/client/petstore/typescript-jquery/npm/api/PetApi.ts
Normal file
571
samples/client/petstore/typescript-jquery/npm/api/PetApi.ts
Normal file
@ -0,0 +1,571 @@
|
||||
/**
|
||||
* Swagger Petstore
|
||||
* This is a sample server Petstore server. You can find out more about Swagger at <a href=\"http://swagger.io\">http://swagger.io</a> or on irc.freenode.net, #swagger. For this sample, you can use the api key \"special-key\" to test the authorization filters
|
||||
*
|
||||
* 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<string> = [];
|
||||
public configuration: Configuration = new Configuration();
|
||||
|
||||
constructor(basePath?: string, configuration?: Configuration) {
|
||||
if (basePath) {
|
||||
this.basePath = basePath;
|
||||
}
|
||||
if (configuration) {
|
||||
this.configuration = configuration;
|
||||
}
|
||||
}
|
||||
|
||||
private extendObj<T1, T2 extends T1>(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<string>): JQueryPromise<{ response: JQueryXHR; body: Array<models.Pet>; }> {
|
||||
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<models.Pet>, 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<string>): JQueryPromise<{ response: JQueryXHR; body: Array<models.Pet>; }> {
|
||||
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<models.Pet>, 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', <any>name);
|
||||
}
|
||||
|
||||
if (status !== null && status !== undefined) {
|
||||
formParams.append('status', <any>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', <any>additionalMetadata);
|
||||
}
|
||||
|
||||
reqHasFile = true;
|
||||
if (file !== null && file !== undefined) {
|
||||
formParams.append('file', <any>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();
|
||||
}
|
||||
|
||||
}
|
239
samples/client/petstore/typescript-jquery/npm/api/StoreApi.ts
Normal file
239
samples/client/petstore/typescript-jquery/npm/api/StoreApi.ts
Normal file
@ -0,0 +1,239 @@
|
||||
/**
|
||||
* Swagger Petstore
|
||||
* This is a sample server Petstore server. You can find out more about Swagger at <a href=\"http://swagger.io\">http://swagger.io</a> or on irc.freenode.net, #swagger. For this sample, you can use the api key \"special-key\" to test the authorization filters
|
||||
*
|
||||
* 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<string> = [];
|
||||
public configuration: Configuration = new Configuration();
|
||||
|
||||
constructor(basePath?: string, configuration?: Configuration) {
|
||||
if (basePath) {
|
||||
this.basePath = basePath;
|
||||
}
|
||||
if (configuration) {
|
||||
this.configuration = configuration;
|
||||
}
|
||||
}
|
||||
|
||||
private extendObj<T1, T2 extends T1>(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();
|
||||
}
|
||||
|
||||
}
|
437
samples/client/petstore/typescript-jquery/npm/api/UserApi.ts
Normal file
437
samples/client/petstore/typescript-jquery/npm/api/UserApi.ts
Normal file
@ -0,0 +1,437 @@
|
||||
/**
|
||||
* Swagger Petstore
|
||||
* This is a sample server Petstore server. You can find out more about Swagger at <a href=\"http://swagger.io\">http://swagger.io</a> or on irc.freenode.net, #swagger. For this sample, you can use the api key \"special-key\" to test the authorization filters
|
||||
*
|
||||
* 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<string> = [];
|
||||
public configuration: Configuration = new Configuration();
|
||||
|
||||
constructor(basePath?: string, configuration?: Configuration) {
|
||||
if (basePath) {
|
||||
this.basePath = basePath;
|
||||
}
|
||||
if (configuration) {
|
||||
this.configuration = configuration;
|
||||
}
|
||||
}
|
||||
|
||||
private extendObj<T1, T2 extends T1>(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<models.User>): 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<models.User>): 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'] = <string><any>username;
|
||||
}
|
||||
if (password !== null && password !== undefined) {
|
||||
queryParameters['password'] = <string><any>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();
|
||||
}
|
||||
|
||||
}
|
7
samples/client/petstore/typescript-jquery/npm/api/api.ts
Normal file
7
samples/client/petstore/typescript-jquery/npm/api/api.ts
Normal file
@ -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];
|
@ -0,0 +1,6 @@
|
||||
export class Configuration {
|
||||
apiKey: string;
|
||||
username: string;
|
||||
password: string;
|
||||
accessToken: string | (() => string);
|
||||
}
|
4
samples/client/petstore/typescript-jquery/npm/index.ts
Normal file
4
samples/client/petstore/typescript-jquery/npm/index.ts
Normal file
@ -0,0 +1,4 @@
|
||||
export * from './api/api';
|
||||
export * from './model/models';
|
||||
export * from './variables';
|
||||
export * from './configuration';
|
@ -0,0 +1,20 @@
|
||||
/**
|
||||
* Swagger Petstore
|
||||
* This is a sample server Petstore server. You can find out more about Swagger at <a href=\"http://swagger.io\">http://swagger.io</a> or on irc.freenode.net, #swagger. For this sample, you can use the api key \"special-key\" to test the authorization filters
|
||||
*
|
||||
* 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;
|
||||
|
||||
}
|
38
samples/client/petstore/typescript-jquery/npm/model/Order.ts
Normal file
38
samples/client/petstore/typescript-jquery/npm/model/Order.ts
Normal file
@ -0,0 +1,38 @@
|
||||
/**
|
||||
* Swagger Petstore
|
||||
* This is a sample server Petstore server. You can find out more about Swagger at <a href=\"http://swagger.io\">http://swagger.io</a> or on irc.freenode.net, #swagger. For this sample, you can use the api key \"special-key\" to test the authorization filters
|
||||
*
|
||||
* 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 = <any> 'placed',
|
||||
Approved = <any> 'approved',
|
||||
Delivered = <any> 'delivered'
|
||||
}
|
||||
}
|
38
samples/client/petstore/typescript-jquery/npm/model/Pet.ts
Normal file
38
samples/client/petstore/typescript-jquery/npm/model/Pet.ts
Normal file
@ -0,0 +1,38 @@
|
||||
/**
|
||||
* Swagger Petstore
|
||||
* This is a sample server Petstore server. You can find out more about Swagger at <a href=\"http://swagger.io\">http://swagger.io</a> or on irc.freenode.net, #swagger. For this sample, you can use the api key \"special-key\" to test the authorization filters
|
||||
*
|
||||
* 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<string>;
|
||||
|
||||
tags?: Array<models.Tag>;
|
||||
|
||||
/**
|
||||
* pet status in the store
|
||||
*/
|
||||
status?: Pet.StatusEnum;
|
||||
|
||||
}
|
||||
export namespace Pet {
|
||||
export enum StatusEnum {
|
||||
Available = <any> 'available',
|
||||
Pending = <any> 'pending',
|
||||
Sold = <any> 'sold'
|
||||
}
|
||||
}
|
20
samples/client/petstore/typescript-jquery/npm/model/Tag.ts
Normal file
20
samples/client/petstore/typescript-jquery/npm/model/Tag.ts
Normal file
@ -0,0 +1,20 @@
|
||||
/**
|
||||
* Swagger Petstore
|
||||
* This is a sample server Petstore server. You can find out more about Swagger at <a href=\"http://swagger.io\">http://swagger.io</a> or on irc.freenode.net, #swagger. For this sample, you can use the api key \"special-key\" to test the authorization filters
|
||||
*
|
||||
* 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;
|
||||
|
||||
}
|
35
samples/client/petstore/typescript-jquery/npm/model/User.ts
Normal file
35
samples/client/petstore/typescript-jquery/npm/model/User.ts
Normal file
@ -0,0 +1,35 @@
|
||||
/**
|
||||
* Swagger Petstore
|
||||
* This is a sample server Petstore server. You can find out more about Swagger at <a href=\"http://swagger.io\">http://swagger.io</a> or on irc.freenode.net, #swagger. For this sample, you can use the api key \"special-key\" to test the authorization filters
|
||||
*
|
||||
* 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;
|
||||
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
export * from './Category';
|
||||
export * from './Order';
|
||||
export * from './Pet';
|
||||
export * from './Tag';
|
||||
export * from './User';
|
@ -0,0 +1,7 @@
|
||||
|
||||
export const COLLECTION_FORMATS = {
|
||||
'csv': ',',
|
||||
'tsv': ' ',
|
||||
'ssv': ' ',
|
||||
'pipes': '|'
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user