Created
November 18, 2016 16:36
-
-
Save baronfel/41c49bbaa3917ea1433cb5cd5eafe006 to your computer and use it in GitHub Desktop.
Sample typescript output for file sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* File Response Test | |
* No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) | |
* | |
* OpenAPI spec version: 1.0.0 | |
* | |
* | |
* 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. | |
* | |
* Licensed under the Apache License, Version 2.0 (the "License"); | |
* you may not use this file except in compliance with the License. | |
* You may obtain a copy of the License at | |
* | |
* http://www.apache.org/licenses/LICENSE-2.0 | |
* | |
* Unless required by applicable law or agreed to in writing, software | |
* distributed under the License is distributed on an "AS IS" BASIS, | |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
* See the License for the specific language governing permissions and | |
* limitations under the License. | |
*/ | |
import request = require('request'); | |
import http = require('http'); | |
import Promise = require('bluebird'); | |
let defaultBasePath = 'http://localhost/v2'; | |
// =============================================== | |
// This file is autogenerated - Please do not edit | |
// =============================================== | |
/* tslint:disable:no-unused-variable */ | |
export interface Authentication { | |
/** | |
* Apply authentication settings to header and query params. | |
*/ | |
applyToRequest(requestOptions: request.Options): void; | |
} | |
export class HttpBasicAuth implements Authentication { | |
public username: string; | |
public password: string; | |
applyToRequest(requestOptions: request.Options): void { | |
requestOptions.auth = { | |
username: this.username, password: this.password | |
} | |
} | |
} | |
export class ApiKeyAuth implements Authentication { | |
public apiKey: string; | |
constructor(private location: string, private paramName: string) { | |
} | |
applyToRequest(requestOptions: request.Options): void { | |
if (this.location == "query") { | |
(<any>requestOptions.qs)[this.paramName] = this.apiKey; | |
} else if (this.location == "header") { | |
requestOptions.headers[this.paramName] = this.apiKey; | |
} | |
} | |
} | |
export class OAuth implements Authentication { | |
public accessToken: string; | |
applyToRequest(requestOptions: request.Options): void { | |
requestOptions.headers["Authorization"] = "Bearer " + this.accessToken; | |
} | |
} | |
export class VoidAuth implements Authentication { | |
public username: string; | |
public password: string; | |
applyToRequest(requestOptions: request.Options): void { | |
// Do nothing | |
} | |
} | |
export enum DefaultApiApiKeys { | |
} | |
export class DefaultApi { | |
protected basePath = defaultBasePath; | |
protected defaultHeaders : any = {}; | |
protected _useQuerystring : boolean = false; | |
protected authentications = { | |
'default': <Authentication>new VoidAuth(), | |
} | |
constructor(basePath?: string); | |
constructor(basePathOrUsername: string, password?: string, basePath?: string) { | |
if (password) { | |
if (basePath) { | |
this.basePath = basePath; | |
} | |
} else { | |
if (basePathOrUsername) { | |
this.basePath = basePathOrUsername | |
} | |
} | |
} | |
set useQuerystring(value: boolean) { | |
this._useQuerystring = value; | |
} | |
public setApiKey(key: DefaultApiApiKeys, value: string) { | |
this.authentications[DefaultApiApiKeys[key]].apiKey = value; | |
} | |
private extendObj<T1,T2>(objA: T1, objB: T2) { | |
for(let key in objB){ | |
if(objB.hasOwnProperty(key)){ | |
objA[key] = objB[key]; | |
} | |
} | |
return <T1&T2>objA; | |
} | |
/** | |
* | |
* | |
*/ | |
public fileresponsetest () : Promise<{ response: http.ClientResponse; body: any; }> { | |
const localVarPath = this.basePath + '/tests/fileResponse'; | |
let queryParameters: any = {}; | |
let headerParams: any = this.extendObj({}, this.defaultHeaders); | |
let formParams: any = {}; | |
let useFormData = false; | |
let requestOptions: request.Options = { | |
method: 'GET', | |
qs: queryParameters, | |
headers: headerParams, | |
uri: localVarPath, | |
useQuerystring: this._useQuerystring, | |
json: true, | |
}; | |
this.authentications.default.applyToRequest(requestOptions); | |
if (Object.keys(formParams).length) { | |
if (useFormData) { | |
(<any>requestOptions).formData = formParams; | |
} else { | |
requestOptions.form = formParams; | |
} | |
} | |
return new Promise<{ response: http.ClientResponse; body: any; }>((resolve, reject) => { | |
request(requestOptions, (error, response, body) => { | |
if (error) { | |
reject(error); | |
} else { | |
if (response.statusCode >= 200 && response.statusCode <= 299) { | |
resolve({ response: response, body: body }); | |
} else { | |
reject({ response: response, body: body }); | |
} | |
} | |
}); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment