typescript-inversify: client compile error, type casting warning and apostrophes (#6970)

This commit is contained in:
Michał Zubkowicz
2020-07-23 08:09:27 +02:00
committed by GitHub
parent 90d8c32906
commit 1bfd86a350
13 changed files with 164 additions and 164 deletions

View File

@@ -1,4 +1,4 @@
import {interfaces} from "inversify";
import {interfaces} from 'inversify';
{{#apiInfo}}
{{#apis}}
@@ -13,7 +13,7 @@ export class ApiServiceBinder {
public static with(container: interfaces.Container) {
{{#apiInfo}}
{{#apis}}
container.bind<{{classname}}{{#withInterfaces}}Interface{{/withInterfaces}}>("{{classname}}").to({{classname}}).inSingletonScope();
container.bind<{{classname}}{{#withInterfaces}}Interface{{/withInterfaces}}>('{{classname}}').to({{classname}}).inSingletonScope();
{{/apis}}
{{/apiInfo}}
}

View File

@@ -1,39 +1,39 @@
import IHttpClient from "./IHttpClient";
import IHttpClient from './IHttpClient';
{{^useRxJS6}}
import { Observable } from "rxjs/Observable";
import { Observable } from 'rxjs/Observable';
{{/useRxJS6}}
{{#useRxJS6}}
import { Observable, from } from "rxjs";
import { Observable, from } from 'rxjs';
{{/useRxJS6}}
import "whatwg-fetch";
import HttpResponse from "./HttpResponse";
import {injectable} from "inversify";
import { Headers } from "./Headers";
import 'whatwg-fetch';
import HttpResponse from './HttpResponse';
import {injectable} from 'inversify';
import { Headers } from './Headers';
@injectable()
class HttpClient implements IHttpClient {
get(url:string, headers?: Headers):Observable<HttpResponse> {
return this.performNetworkCall(url, "GET", undefined, headers);
return this.performNetworkCall(url, 'GET', undefined, headers);
}
post(url: string, body?: {}|FormData, headers?: Headers): Observable<HttpResponse> {
return this.performNetworkCall(url, "POST", this.getJsonBody(body), this.addJsonHeaders(headers));
return this.performNetworkCall(url, 'POST', this.getJsonBody(body), this.addJsonHeaders(headers));
}
put(url: string, body?: {}, headers?: Headers): Observable<HttpResponse> {
return this.performNetworkCall(url, "PUT", this.getJsonBody(body), this.addJsonHeaders(headers));
return this.performNetworkCall(url, 'PUT', this.getJsonBody(body), this.addJsonHeaders(headers));
}
patch(url: string, body?: {}, headers?: Headers): Observable<HttpResponse> {
return this.performNetworkCall(url, "PATCH", this.getJsonBody(body), this.addJsonHeaders(headers));
return this.performNetworkCall(url, 'PATCH', this.getJsonBody(body), this.addJsonHeaders(headers));
}
delete(url: string, headers?: Headers): Observable<HttpResponse> {
return this.performNetworkCall(url, "DELETE", undefined, headers);
return this.performNetworkCall(url, 'DELETE', undefined, headers);
}
private getJsonBody(body?: {}|FormData) {
@@ -45,16 +45,16 @@ class HttpClient implements IHttpClient {
private addJsonHeaders(headers?: Headers) {
return Object.assign({}, {
"Accept": "application/json",
"Content-Type": "application/json"
'Accept': 'application/json',
'Content-Type': 'application/json'
}, headers);
};
private performNetworkCall(url: string, method: string, body?: any, headers?: Headers): Observable<HttpResponse> {
// when using fetch & a multipart upload, the requests content-type is handled by the browser, so should be left unset otherwise the multipart boundry is not added
if(headers && headers["Content-Type"] === "multipart/form-data") {
delete headers["Content-Type"];
if(headers && headers['Content-Type'] === 'multipart/form-data') {
delete headers['Content-Type'];
}
let promise = window.fetch(url, {
@@ -67,8 +67,8 @@ class HttpClient implements IHttpClient {
headers[name.toString().toLowerCase()] = value;
});
return response.text().then(text => {
let contentType = headers["content-type"] || "";
let payload = contentType.match("application/json") ? JSON.parse(text) : text;
let contentType = headers['content-type'] || '';
let payload = contentType.match('application/json') ? JSON.parse(text) : text;
let httpResponse = new HttpResponse(payload, response.status, headers);
if (response.status >= 400)

View File

@@ -1,8 +1,8 @@
import { Headers } from "./Headers"
import { Headers } from './Headers'
class HttpResponse<T = any> {
constructor(public response: T, public status:number, public headers?: Headers) {
}
}
export default HttpResponse
export default HttpResponse

View File

@@ -1,11 +1,11 @@
{{^useRxJS6}}
import { Observable } from "rxjs/Observable";
import { Observable } from 'rxjs/Observable';
{{/useRxJS6}}
{{#useRxJS6}}
import { Observable, from } from "rxjs";
import { Observable, from } from 'rxjs';
{{/useRxJS6}}
import HttpResponse from "./HttpResponse";
import { Headers } from "./Headers";
import HttpResponse from './HttpResponse';
import { Headers } from './Headers';
interface IHttpClient {
get(url:string, headers?: Headers):Observable<HttpResponse>
@@ -15,4 +15,4 @@ interface IHttpClient {
delete(url:string, headers?: Headers):Observable<HttpResponse>
}
export default IHttpClient
export default IHttpClient

View File

@@ -2,26 +2,26 @@
/* tslint:disable:no-unused-variable member-ordering */
{{^useRxJS6}}
import { Observable } from "rxjs/Observable";
import { Observable } from 'rxjs/Observable';
{{/useRxJS6}}
{{#useRxJS6}}
import { Observable } from "rxjs";
import { Observable } from 'rxjs';
{{/useRxJS6}}
import { map } from "rxjs/operators";
import IHttpClient from "../IHttpClient";
import { inject, injectable } from "inversify";
import { IAPIConfiguration } from "../IAPIConfiguration";
import { Headers } from "../Headers";
import HttpResponse from "../HttpResponse";
import { map } from 'rxjs/operators';
import IHttpClient from '../IHttpClient';
import { inject, injectable } from 'inversify';
import { IAPIConfiguration } from '../IAPIConfiguration';
import { Headers } from '../Headers';
import HttpResponse from '../HttpResponse';
{{#imports}}
import { {{classname}} } from "../{{filename}}";
import { {{classname}} } from '../{{filename}}';
{{/imports}}
import { COLLECTION_FORMATS } from "../variables";
import { COLLECTION_FORMATS } from '../variables';
{{#withInterfaces}}
import { {{classname}}Interface } from "./{{classFilename}}Interface";
import { {{classname}}Interface } from './{{classFilename}}Interface';
{{/withInterfaces}}
{{#operations}}
@@ -41,8 +41,8 @@ export class {{classname}} {
{{/withInterfaces}}
private basePath: string = '{{{basePath}}}';
constructor(@inject("IApiHttpClient") private httpClient: IHttpClient,
@inject("IAPIConfiguration") private APIConfiguration: IAPIConfiguration ) {
constructor(@inject('IApiHttpClient') private httpClient: IHttpClient,
@inject('IAPIConfiguration') private APIConfiguration: IAPIConfiguration ) {
if(this.APIConfiguration.basePath)
this.basePath = this.APIConfiguration.basePath;
}
@@ -73,21 +73,21 @@ export class {{classname}} {
if ({{paramName}}) {
{{#isCollectionFormatMulti}}
{{paramName}}.forEach((element) => {
queryParameters.push("{{paramName}}="+encodeURIComponent(String({{paramName}})));
queryParameters.push('{{paramName}}='+encodeURIComponent(String({{paramName}})));
})
{{/isCollectionFormatMulti}}
{{^isCollectionFormatMulti}}
queryParameters.push("{{paramName}}="+encodeURIComponent({{paramName}}.join(COLLECTION_FORMATS['{{collectionFormat}}'])));
queryParameters.push('{{paramName}}='+encodeURIComponent({{paramName}}.join(COLLECTION_FORMATS['{{collectionFormat}}'])));
{{/isCollectionFormatMulti}}
}
{{/isListContainer}}
{{^isListContainer}}
if ({{paramName}} !== undefined) {
{{#isDateTime}}
queryParameters.push("{{paramName}}="+encodeURIComponent(<any>{{paramName}}.toISOString()));
queryParameters.push('{{paramName}}='+encodeURIComponent(({{paramName}} as Date).toISOString()));
{{/isDateTime}}
{{^isDateTime}}
queryParameters.push("{{paramName}}="+encodeURIComponent(String({{paramName}})));
queryParameters.push('{{paramName}}='+encodeURIComponent(String({{paramName}})));
{{/isDateTime}}
}
{{/isListContainer}}
@@ -111,13 +111,13 @@ export class {{classname}} {
// authentication ({{name}}) required
{{#isApiKey}}
{{#isKeyInHeader}}
if (this.APIConfiguration.apiKeys && this.APIConfiguration.apiKeys["{{keyParamName}}"]) {
headers['{{keyParamName}}'] = this.APIConfiguration.apiKeys["{{keyParamName}}"];
if (this.APIConfiguration.apiKeys && this.APIConfiguration.apiKeys['{{keyParamName}}']) {
headers['{{keyParamName}}'] = this.APIConfiguration.apiKeys['{{keyParamName}}'];
}
{{/isKeyInHeader}}
{{#isKeyInQuery}}
if (this.APIConfiguration.apiKeys && this.APIConfiguration.apiKeys["{{keyParamName}}"]) {
queryParameters.push("{{paramName}}="+encodeURIComponent(String(this.APIConfiguration.apiKeys["{{keyParamName}}"])));
if (this.APIConfiguration.apiKeys && this.APIConfiguration.apiKeys['{{keyParamName}}']) {
queryParameters.push('{{paramName}}='+encodeURIComponent(String(this.APIConfiguration.apiKeys['{{keyParamName}}'])));
}
{{/isKeyInQuery}}
{{/isApiKey}}
@@ -180,9 +180,9 @@ export class {{classname}} {
{{/hasFormParams}}
const response: Observable<HttpResponse<{{#returnType}}{{{returnType}}}{{#isResponseTypeFile}}|undefined{{/isResponseTypeFile}}{{/returnType}}{{^returnType}}any{{/returnType}}>> = this.httpClient.{{httpMethod}}(`${this.basePath}{{{path}}}{{#hasQueryParams}}?${queryParameters.join('&')}{{/hasQueryParams}}`{{#bodyParam}}, {{paramName}} {{/bodyParam}}{{#hasFormParams}}, formData{{/hasFormParams}}, headers);
if (observe == 'body') {
if (observe === 'body') {
return response.pipe(
map(httpResponse => <{{#returnType}}{{{returnType}}}{{#isResponseTypeFile}}|undefined{{/isResponseTypeFile}}{{/returnType}}{{^returnType}}any{{/returnType}}>(httpResponse.response))
map((httpResponse: HttpResponse) => <{{#returnType}}{{{returnType}}}{{#isResponseTypeFile}}|undefined{{/isResponseTypeFile}}{{/returnType}}{{^returnType}}any{{/returnType}}>(httpResponse.response))
){{#usePromise}}.toPromise(){{/usePromise}};
}
return response{{#usePromise}}.toPromise(){{/usePromise}};

View File

@@ -1,15 +1,15 @@
{{>licenseInfo}}
import { Headers } from "../Headers";
import { Headers } from '../Headers';
{{^useRxJS6}}
import { Observable } from "rxjs/Observable";
import { Observable } from 'rxjs/Observable';
{{/useRxJS6}}
{{#useRxJS6}}
import { Observable } from "rxjs";
import { Observable } from 'rxjs';
{{/useRxJS6}}
{{#imports}}
import { {{classname}} } from "../{{filename}}";
import { {{classname}} } from '../{{filename}}';
{{/imports}}
import HttpResponse from "../HttpResponse";
import HttpResponse from '../HttpResponse';
{{#operations}}

View File

@@ -1,4 +1,4 @@
import {interfaces} from "inversify";
import {interfaces} from 'inversify';
import { PetService } from './api/pet.service';
import { StoreService } from './api/store.service';
@@ -6,8 +6,8 @@ import { UserService } from './api/user.service';
export class ApiServiceBinder {
public static with(container: interfaces.Container) {
container.bind<PetService>("PetService").to(PetService).inSingletonScope();
container.bind<StoreService>("StoreService").to(StoreService).inSingletonScope();
container.bind<UserService>("UserService").to(UserService).inSingletonScope();
container.bind<PetService>('PetService').to(PetService).inSingletonScope();
container.bind<StoreService>('StoreService').to(StoreService).inSingletonScope();
container.bind<UserService>('UserService').to(UserService).inSingletonScope();
}
}

View File

@@ -1,34 +1,34 @@
import IHttpClient from "./IHttpClient";
import IHttpClient from './IHttpClient';
import { Observable } from "rxjs/Observable";
import { Observable } from 'rxjs/Observable';
import "whatwg-fetch";
import HttpResponse from "./HttpResponse";
import {injectable} from "inversify";
import { Headers } from "./Headers";
import 'whatwg-fetch';
import HttpResponse from './HttpResponse';
import {injectable} from 'inversify';
import { Headers } from './Headers';
@injectable()
class HttpClient implements IHttpClient {
get(url:string, headers?: Headers):Observable<HttpResponse> {
return this.performNetworkCall(url, "GET", undefined, headers);
return this.performNetworkCall(url, 'GET', undefined, headers);
}
post(url: string, body?: {}|FormData, headers?: Headers): Observable<HttpResponse> {
return this.performNetworkCall(url, "POST", this.getJsonBody(body), this.addJsonHeaders(headers));
return this.performNetworkCall(url, 'POST', this.getJsonBody(body), this.addJsonHeaders(headers));
}
put(url: string, body?: {}, headers?: Headers): Observable<HttpResponse> {
return this.performNetworkCall(url, "PUT", this.getJsonBody(body), this.addJsonHeaders(headers));
return this.performNetworkCall(url, 'PUT', this.getJsonBody(body), this.addJsonHeaders(headers));
}
patch(url: string, body?: {}, headers?: Headers): Observable<HttpResponse> {
return this.performNetworkCall(url, "PATCH", this.getJsonBody(body), this.addJsonHeaders(headers));
return this.performNetworkCall(url, 'PATCH', this.getJsonBody(body), this.addJsonHeaders(headers));
}
delete(url: string, headers?: Headers): Observable<HttpResponse> {
return this.performNetworkCall(url, "DELETE", undefined, headers);
return this.performNetworkCall(url, 'DELETE', undefined, headers);
}
private getJsonBody(body?: {}|FormData) {
@@ -40,16 +40,16 @@ class HttpClient implements IHttpClient {
private addJsonHeaders(headers?: Headers) {
return Object.assign({}, {
"Accept": "application/json",
"Content-Type": "application/json"
'Accept': 'application/json',
'Content-Type': 'application/json'
}, headers);
};
private performNetworkCall(url: string, method: string, body?: any, headers?: Headers): Observable<HttpResponse> {
// when using fetch & a multipart upload, the requests content-type is handled by the browser, so should be left unset otherwise the multipart boundry is not added
if(headers && headers["Content-Type"] === "multipart/form-data") {
delete headers["Content-Type"];
if(headers && headers['Content-Type'] === 'multipart/form-data') {
delete headers['Content-Type'];
}
let promise = window.fetch(url, {
@@ -62,8 +62,8 @@ class HttpClient implements IHttpClient {
headers[name.toString().toLowerCase()] = value;
});
return response.text().then(text => {
let contentType = headers["content-type"] || "";
let payload = contentType.match("application/json") ? JSON.parse(text) : text;
let contentType = headers['content-type'] || '';
let payload = contentType.match('application/json') ? JSON.parse(text) : text;
let httpResponse = new HttpResponse(payload, response.status, headers);
if (response.status >= 400)

View File

@@ -1,8 +1,8 @@
import { Headers } from "./Headers"
import { Headers } from './Headers'
class HttpResponse<T = any> {
constructor(public response: T, public status:number, public headers?: Headers) {
}
}
export default HttpResponse
export default HttpResponse

View File

@@ -1,6 +1,6 @@
import { Observable } from "rxjs/Observable";
import HttpResponse from "./HttpResponse";
import { Headers } from "./Headers";
import { Observable } from 'rxjs/Observable';
import HttpResponse from './HttpResponse';
import { Headers } from './Headers';
interface IHttpClient {
get(url:string, headers?: Headers):Observable<HttpResponse>
@@ -10,4 +10,4 @@ interface IHttpClient {
delete(url:string, headers?: Headers):Observable<HttpResponse>
}
export default IHttpClient
export default IHttpClient

View File

@@ -11,19 +11,19 @@
*/
/* tslint:disable:no-unused-variable member-ordering */
import { Observable } from "rxjs/Observable";
import { Observable } from 'rxjs/Observable';
import { map } from "rxjs/operators";
import IHttpClient from "../IHttpClient";
import { inject, injectable } from "inversify";
import { IAPIConfiguration } from "../IAPIConfiguration";
import { Headers } from "../Headers";
import HttpResponse from "../HttpResponse";
import { map } from 'rxjs/operators';
import IHttpClient from '../IHttpClient';
import { inject, injectable } from 'inversify';
import { IAPIConfiguration } from '../IAPIConfiguration';
import { Headers } from '../Headers';
import HttpResponse from '../HttpResponse';
import { ApiResponse } from "../model/apiResponse";
import { Pet } from "../model/pet";
import { ApiResponse } from '../model/apiResponse';
import { Pet } from '../model/pet';
import { COLLECTION_FORMATS } from "../variables";
import { COLLECTION_FORMATS } from '../variables';
@@ -31,8 +31,8 @@ import { COLLECTION_FORMATS } from "../variables";
export class PetService {
private basePath: string = 'http://petstore.swagger.io/v2';
constructor(@inject("IApiHttpClient") private httpClient: IHttpClient,
@inject("IAPIConfiguration") private APIConfiguration: IAPIConfiguration ) {
constructor(@inject('IApiHttpClient') private httpClient: IHttpClient,
@inject('IAPIConfiguration') private APIConfiguration: IAPIConfiguration ) {
if(this.APIConfiguration.basePath)
this.basePath = this.APIConfiguration.basePath;
}
@@ -61,9 +61,9 @@ export class PetService {
headers['Content-Type'] = 'application/json';
const response: Observable<HttpResponse<any>> = this.httpClient.post(`${this.basePath}/pet`, body , headers);
if (observe == 'body') {
if (observe === 'body') {
return response.pipe(
map(httpResponse => <any>(httpResponse.response))
map((httpResponse: HttpResponse) => <any>(httpResponse.response))
);
}
return response;
@@ -98,9 +98,9 @@ export class PetService {
headers['Accept'] = 'application/json';
const response: Observable<HttpResponse<any>> = this.httpClient.delete(`${this.basePath}/pet/${encodeURIComponent(String(petId))}`, headers);
if (observe == 'body') {
if (observe === 'body') {
return response.pipe(
map(httpResponse => <any>(httpResponse.response))
map((httpResponse: HttpResponse) => <any>(httpResponse.response))
);
}
return response;
@@ -122,7 +122,7 @@ export class PetService {
let queryParameters: string[] = [];
if (status) {
queryParameters.push("status="+encodeURIComponent(status.join(COLLECTION_FORMATS['csv'])));
queryParameters.push('status='+encodeURIComponent(status.join(COLLECTION_FORMATS['csv'])));
}
// authentication (petstore_auth) required
@@ -135,9 +135,9 @@ export class PetService {
headers['Accept'] = 'application/xml, application/json';
const response: Observable<HttpResponse<Array<Pet>>> = this.httpClient.get(`${this.basePath}/pet/findByStatus?${queryParameters.join('&')}`, headers);
if (observe == 'body') {
if (observe === 'body') {
return response.pipe(
map(httpResponse => <Array<Pet>>(httpResponse.response))
map((httpResponse: HttpResponse) => <Array<Pet>>(httpResponse.response))
);
}
return response;
@@ -159,7 +159,7 @@ export class PetService {
let queryParameters: string[] = [];
if (tags) {
queryParameters.push("tags="+encodeURIComponent(tags.join(COLLECTION_FORMATS['csv'])));
queryParameters.push('tags='+encodeURIComponent(tags.join(COLLECTION_FORMATS['csv'])));
}
// authentication (petstore_auth) required
@@ -172,9 +172,9 @@ export class PetService {
headers['Accept'] = 'application/xml, application/json';
const response: Observable<HttpResponse<Array<Pet>>> = this.httpClient.get(`${this.basePath}/pet/findByTags?${queryParameters.join('&')}`, headers);
if (observe == 'body') {
if (observe === 'body') {
return response.pipe(
map(httpResponse => <Array<Pet>>(httpResponse.response))
map((httpResponse: HttpResponse) => <Array<Pet>>(httpResponse.response))
);
}
return response;
@@ -195,15 +195,15 @@ export class PetService {
}
// authentication (api_key) required
if (this.APIConfiguration.apiKeys && this.APIConfiguration.apiKeys["api_key"]) {
headers['api_key'] = this.APIConfiguration.apiKeys["api_key"];
if (this.APIConfiguration.apiKeys && this.APIConfiguration.apiKeys['api_key']) {
headers['api_key'] = this.APIConfiguration.apiKeys['api_key'];
}
headers['Accept'] = 'application/xml, application/json';
const response: Observable<HttpResponse<Pet>> = this.httpClient.get(`${this.basePath}/pet/${encodeURIComponent(String(petId))}`, headers);
if (observe == 'body') {
if (observe === 'body') {
return response.pipe(
map(httpResponse => <Pet>(httpResponse.response))
map((httpResponse: HttpResponse) => <Pet>(httpResponse.response))
);
}
return response;
@@ -234,9 +234,9 @@ export class PetService {
headers['Content-Type'] = 'application/json';
const response: Observable<HttpResponse<any>> = this.httpClient.put(`${this.basePath}/pet`, body , headers);
if (observe == 'body') {
if (observe === 'body') {
return response.pipe(
map(httpResponse => <any>(httpResponse.response))
map((httpResponse: HttpResponse) => <any>(httpResponse.response))
);
}
return response;
@@ -277,9 +277,9 @@ export class PetService {
}
const response: Observable<HttpResponse<any>> = this.httpClient.post(`${this.basePath}/pet/${encodeURIComponent(String(petId))}`, formData, headers);
if (observe == 'body') {
if (observe === 'body') {
return response.pipe(
map(httpResponse => <any>(httpResponse.response))
map((httpResponse: HttpResponse) => <any>(httpResponse.response))
);
}
return response;
@@ -320,9 +320,9 @@ export class PetService {
}
const response: Observable<HttpResponse<ApiResponse>> = this.httpClient.post(`${this.basePath}/pet/${encodeURIComponent(String(petId))}/uploadImage`, formData, headers);
if (observe == 'body') {
if (observe === 'body') {
return response.pipe(
map(httpResponse => <ApiResponse>(httpResponse.response))
map((httpResponse: HttpResponse) => <ApiResponse>(httpResponse.response))
);
}
return response;

View File

@@ -11,18 +11,18 @@
*/
/* tslint:disable:no-unused-variable member-ordering */
import { Observable } from "rxjs/Observable";
import { Observable } from 'rxjs/Observable';
import { map } from "rxjs/operators";
import IHttpClient from "../IHttpClient";
import { inject, injectable } from "inversify";
import { IAPIConfiguration } from "../IAPIConfiguration";
import { Headers } from "../Headers";
import HttpResponse from "../HttpResponse";
import { map } from 'rxjs/operators';
import IHttpClient from '../IHttpClient';
import { inject, injectable } from 'inversify';
import { IAPIConfiguration } from '../IAPIConfiguration';
import { Headers } from '../Headers';
import HttpResponse from '../HttpResponse';
import { Order } from "../model/order";
import { Order } from '../model/order';
import { COLLECTION_FORMATS } from "../variables";
import { COLLECTION_FORMATS } from '../variables';
@@ -30,8 +30,8 @@ import { COLLECTION_FORMATS } from "../variables";
export class StoreService {
private basePath: string = 'http://petstore.swagger.io/v2';
constructor(@inject("IApiHttpClient") private httpClient: IHttpClient,
@inject("IAPIConfiguration") private APIConfiguration: IAPIConfiguration ) {
constructor(@inject('IApiHttpClient') private httpClient: IHttpClient,
@inject('IAPIConfiguration') private APIConfiguration: IAPIConfiguration ) {
if(this.APIConfiguration.basePath)
this.basePath = this.APIConfiguration.basePath;
}
@@ -52,9 +52,9 @@ export class StoreService {
headers['Accept'] = 'application/json';
const response: Observable<HttpResponse<any>> = this.httpClient.delete(`${this.basePath}/store/order/${encodeURIComponent(String(orderId))}`, headers);
if (observe == 'body') {
if (observe === 'body') {
return response.pipe(
map(httpResponse => <any>(httpResponse.response))
map((httpResponse: HttpResponse) => <any>(httpResponse.response))
);
}
return response;
@@ -70,15 +70,15 @@ export class StoreService {
public getInventory(observe?: 'response', headers?: Headers): Observable<HttpResponse<{ [key: string]: number; }>>;
public getInventory(observe: any = 'body', headers: Headers = {}): Observable<any> {
// authentication (api_key) required
if (this.APIConfiguration.apiKeys && this.APIConfiguration.apiKeys["api_key"]) {
headers['api_key'] = this.APIConfiguration.apiKeys["api_key"];
if (this.APIConfiguration.apiKeys && this.APIConfiguration.apiKeys['api_key']) {
headers['api_key'] = this.APIConfiguration.apiKeys['api_key'];
}
headers['Accept'] = 'application/json';
const response: Observable<HttpResponse<{ [key: string]: number; }>> = this.httpClient.get(`${this.basePath}/store/inventory`, headers);
if (observe == 'body') {
if (observe === 'body') {
return response.pipe(
map(httpResponse => <{ [key: string]: number; }>(httpResponse.response))
map((httpResponse: HttpResponse) => <{ [key: string]: number; }>(httpResponse.response))
);
}
return response;
@@ -101,9 +101,9 @@ export class StoreService {
headers['Accept'] = 'application/xml, application/json';
const response: Observable<HttpResponse<Order>> = this.httpClient.get(`${this.basePath}/store/order/${encodeURIComponent(String(orderId))}`, headers);
if (observe == 'body') {
if (observe === 'body') {
return response.pipe(
map(httpResponse => <Order>(httpResponse.response))
map((httpResponse: HttpResponse) => <Order>(httpResponse.response))
);
}
return response;
@@ -127,9 +127,9 @@ export class StoreService {
headers['Content-Type'] = 'application/json';
const response: Observable<HttpResponse<Order>> = this.httpClient.post(`${this.basePath}/store/order`, body , headers);
if (observe == 'body') {
if (observe === 'body') {
return response.pipe(
map(httpResponse => <Order>(httpResponse.response))
map((httpResponse: HttpResponse) => <Order>(httpResponse.response))
);
}
return response;

View File

@@ -11,18 +11,18 @@
*/
/* tslint:disable:no-unused-variable member-ordering */
import { Observable } from "rxjs/Observable";
import { Observable } from 'rxjs/Observable';
import { map } from "rxjs/operators";
import IHttpClient from "../IHttpClient";
import { inject, injectable } from "inversify";
import { IAPIConfiguration } from "../IAPIConfiguration";
import { Headers } from "../Headers";
import HttpResponse from "../HttpResponse";
import { map } from 'rxjs/operators';
import IHttpClient from '../IHttpClient';
import { inject, injectable } from 'inversify';
import { IAPIConfiguration } from '../IAPIConfiguration';
import { Headers } from '../Headers';
import HttpResponse from '../HttpResponse';
import { User } from "../model/user";
import { User } from '../model/user';
import { COLLECTION_FORMATS } from "../variables";
import { COLLECTION_FORMATS } from '../variables';
@@ -30,8 +30,8 @@ import { COLLECTION_FORMATS } from "../variables";
export class UserService {
private basePath: string = 'http://petstore.swagger.io/v2';
constructor(@inject("IApiHttpClient") private httpClient: IHttpClient,
@inject("IAPIConfiguration") private APIConfiguration: IAPIConfiguration ) {
constructor(@inject('IApiHttpClient') private httpClient: IHttpClient,
@inject('IAPIConfiguration') private APIConfiguration: IAPIConfiguration ) {
if(this.APIConfiguration.basePath)
this.basePath = this.APIConfiguration.basePath;
}
@@ -53,9 +53,9 @@ export class UserService {
headers['Content-Type'] = 'application/json';
const response: Observable<HttpResponse<any>> = this.httpClient.post(`${this.basePath}/user`, body , headers);
if (observe == 'body') {
if (observe === 'body') {
return response.pipe(
map(httpResponse => <any>(httpResponse.response))
map((httpResponse: HttpResponse) => <any>(httpResponse.response))
);
}
return response;
@@ -79,9 +79,9 @@ export class UserService {
headers['Content-Type'] = 'application/json';
const response: Observable<HttpResponse<any>> = this.httpClient.post(`${this.basePath}/user/createWithArray`, body , headers);
if (observe == 'body') {
if (observe === 'body') {
return response.pipe(
map(httpResponse => <any>(httpResponse.response))
map((httpResponse: HttpResponse) => <any>(httpResponse.response))
);
}
return response;
@@ -105,9 +105,9 @@ export class UserService {
headers['Content-Type'] = 'application/json';
const response: Observable<HttpResponse<any>> = this.httpClient.post(`${this.basePath}/user/createWithList`, body , headers);
if (observe == 'body') {
if (observe === 'body') {
return response.pipe(
map(httpResponse => <any>(httpResponse.response))
map((httpResponse: HttpResponse) => <any>(httpResponse.response))
);
}
return response;
@@ -130,9 +130,9 @@ export class UserService {
headers['Accept'] = 'application/json';
const response: Observable<HttpResponse<any>> = this.httpClient.delete(`${this.basePath}/user/${encodeURIComponent(String(username))}`, headers);
if (observe == 'body') {
if (observe === 'body') {
return response.pipe(
map(httpResponse => <any>(httpResponse.response))
map((httpResponse: HttpResponse) => <any>(httpResponse.response))
);
}
return response;
@@ -155,9 +155,9 @@ export class UserService {
headers['Accept'] = 'application/xml, application/json';
const response: Observable<HttpResponse<User>> = this.httpClient.get(`${this.basePath}/user/${encodeURIComponent(String(username))}`, headers);
if (observe == 'body') {
if (observe === 'body') {
return response.pipe(
map(httpResponse => <User>(httpResponse.response))
map((httpResponse: HttpResponse) => <User>(httpResponse.response))
);
}
return response;
@@ -184,18 +184,18 @@ export class UserService {
let queryParameters: string[] = [];
if (username !== undefined) {
queryParameters.push("username="+encodeURIComponent(String(username)));
queryParameters.push('username='+encodeURIComponent(String(username)));
}
if (password !== undefined) {
queryParameters.push("password="+encodeURIComponent(String(password)));
queryParameters.push('password='+encodeURIComponent(String(password)));
}
headers['Accept'] = 'application/xml, application/json';
const response: Observable<HttpResponse<string>> = this.httpClient.get(`${this.basePath}/user/login?${queryParameters.join('&')}`, headers);
if (observe == 'body') {
if (observe === 'body') {
return response.pipe(
map(httpResponse => <string>(httpResponse.response))
map((httpResponse: HttpResponse) => <string>(httpResponse.response))
);
}
return response;
@@ -213,9 +213,9 @@ export class UserService {
headers['Accept'] = 'application/json';
const response: Observable<HttpResponse<any>> = this.httpClient.get(`${this.basePath}/user/logout`, headers);
if (observe == 'body') {
if (observe === 'body') {
return response.pipe(
map(httpResponse => <any>(httpResponse.response))
map((httpResponse: HttpResponse) => <any>(httpResponse.response))
);
}
return response;
@@ -244,9 +244,9 @@ export class UserService {
headers['Content-Type'] = 'application/json';
const response: Observable<HttpResponse<any>> = this.httpClient.put(`${this.basePath}/user/${encodeURIComponent(String(username))}`, body , headers);
if (observe == 'body') {
if (observe === 'body') {
return response.pipe(
map(httpResponse => <any>(httpResponse.response))
map((httpResponse: HttpResponse) => <any>(httpResponse.response))
);
}
return response;