mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-05-12 12:40:53 +00:00
Merge d44893dccab8f4da8368a85a42ac9160769117d4 into d6c46342693205f0dae441b45742d9c85d41cf33
This commit is contained in:
commit
aac62cfb5f
@ -1,38 +1,40 @@
|
||||
import IHttpClient from './IHttpClient';
|
||||
|
||||
{{^usePromise}}
|
||||
{{^useRxJS6}}
|
||||
import { Observable } from 'rxjs/Observable';
|
||||
{{/useRxJS6}}
|
||||
{{#useRxJS6}}
|
||||
import { Observable, from } from 'rxjs';
|
||||
{{/useRxJS6}}
|
||||
{{/usePromise}}
|
||||
|
||||
import {injectable} from 'inversify';
|
||||
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> {
|
||||
get(url:string, headers?: Headers): {{#usePromise}}Promise{{/usePromise}}{{^usePromise}}Observable{{/usePromise}}<HttpResponse> {
|
||||
return this.performNetworkCall(url, 'GET', undefined, headers);
|
||||
}
|
||||
|
||||
post(url: string, body?: {}|FormData, headers?: Headers): Observable<HttpResponse> {
|
||||
post(url: string, body?: {}|FormData, headers?: Headers): {{#usePromise}}Promise{{/usePromise}}{{^usePromise}}Observable{{/usePromise}}<HttpResponse> {
|
||||
return this.performNetworkCall(url, 'POST', this.getJsonBody(body), this.addJsonHeaders(headers));
|
||||
}
|
||||
|
||||
put(url: string, body?: {}, headers?: Headers): Observable<HttpResponse> {
|
||||
put(url: string, body?: {}, headers?: Headers): {{#usePromise}}Promise{{/usePromise}}{{^usePromise}}Observable{{/usePromise}}<HttpResponse> {
|
||||
return this.performNetworkCall(url, 'PUT', this.getJsonBody(body), this.addJsonHeaders(headers));
|
||||
}
|
||||
|
||||
patch(url: string, body?: {}, headers?: Headers): Observable<HttpResponse> {
|
||||
patch(url: string, body?: {}, headers?: Headers): {{#usePromise}}Promise{{/usePromise}}{{^usePromise}}Observable{{/usePromise}}<HttpResponse> {
|
||||
return this.performNetworkCall(url, 'PATCH', this.getJsonBody(body), this.addJsonHeaders(headers));
|
||||
}
|
||||
|
||||
|
||||
delete(url: string, headers?: Headers): Observable<HttpResponse> {
|
||||
delete(url: string, headers?: Headers): {{#usePromise}}Promise{{/usePromise}}{{^usePromise}}Observable{{/usePromise}}<HttpResponse> {
|
||||
return this.performNetworkCall(url, 'DELETE', undefined, headers);
|
||||
}
|
||||
|
||||
@ -50,7 +52,7 @@ class HttpClient implements IHttpClient {
|
||||
}, headers);
|
||||
};
|
||||
|
||||
private performNetworkCall(url: string, method: string, body?: any, headers?: Headers): Observable<HttpResponse> {
|
||||
private performNetworkCall(url: string, method: string, body?: any, headers?: Headers): {{#usePromise}}Promise{{/usePromise}}{{^usePromise}}Observable{{/usePromise}}<HttpResponse> {
|
||||
|
||||
// when using fetch & a multipart upload, the requests content-type is handled by the browser, so should be left unset otherwise the multipart boundary is not added
|
||||
if(headers && headers['Content-Type'] === 'multipart/form-data') {
|
||||
@ -77,12 +79,17 @@ class HttpClient implements IHttpClient {
|
||||
});
|
||||
});
|
||||
|
||||
{{#usePromise}}
|
||||
return promise;
|
||||
{{/usePromise}}
|
||||
{{^usePromise}}
|
||||
{{^useRxJS6}}
|
||||
return Observable.fromPromise(promise);
|
||||
{{/useRxJS6}}
|
||||
{{#useRxJS6}}
|
||||
return from(promise);
|
||||
{{/useRxJS6}}
|
||||
{{/usePromise}}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,18 +1,20 @@
|
||||
{{^usePromise}}
|
||||
{{^useRxJS6}}
|
||||
import { Observable } from 'rxjs/Observable';
|
||||
{{/useRxJS6}}
|
||||
{{#useRxJS6}}
|
||||
import { Observable, from } from 'rxjs';
|
||||
{{/useRxJS6}}
|
||||
{{/usePromise}}
|
||||
import HttpResponse from './HttpResponse';
|
||||
import { Headers } from './Headers';
|
||||
|
||||
interface IHttpClient {
|
||||
get(url:string, headers?: Headers):Observable<HttpResponse>
|
||||
post(url:string, body?:{}|FormData, headers?: Headers):Observable<HttpResponse>
|
||||
put(url:string, body?:{}, headers?: Headers):Observable<HttpResponse>
|
||||
patch(url:string, body?:{}, headers?: Headers):Observable<HttpResponse>
|
||||
delete(url:string, headers?: Headers):Observable<HttpResponse>
|
||||
get(url:string, headers?: Headers):{{#usePromise}}Promise{{/usePromise}}{{^usePromise}}Observable{{/usePromise}}<HttpResponse>
|
||||
post(url:string, body?:{}|FormData, headers?: Headers):{{#usePromise}}Promise{{/usePromise}}{{^usePromise}}Observable{{/usePromise}}<HttpResponse>
|
||||
put(url:string, body?:{}, headers?: Headers):{{#usePromise}}Promise{{/usePromise}}{{^usePromise}}Observable{{/usePromise}}<HttpResponse>
|
||||
patch(url:string, body?:{}, headers?: Headers):{{#usePromise}}Promise{{/usePromise}}{{^usePromise}}Observable{{/usePromise}}<HttpResponse>
|
||||
delete(url:string, headers?: Headers):{{#usePromise}}Promise{{/usePromise}}{{^usePromise}}Observable{{/usePromise}}<HttpResponse>
|
||||
}
|
||||
|
||||
export default IHttpClient
|
||||
|
@ -1,16 +1,18 @@
|
||||
{{>licenseInfo}}
|
||||
/* tslint:disable:no-unused-variable member-ordering */
|
||||
|
||||
{{^usePromise}}
|
||||
{{^useRxJS6}}
|
||||
import { Observable } from 'rxjs/Observable';
|
||||
{{/useRxJS6}}
|
||||
{{#useRxJS6}}
|
||||
import { Observable } from 'rxjs';
|
||||
{{/useRxJS6}}
|
||||
|
||||
import { map } from 'rxjs/operators';
|
||||
import IHttpClient from '../IHttpClient';
|
||||
{{/usePromise}}
|
||||
|
||||
import { inject, injectable } from 'inversify';
|
||||
import IHttpClient from '../IHttpClient';
|
||||
import { IAPIConfiguration } from '../IAPIConfiguration';
|
||||
import { Headers } from '../Headers';
|
||||
import HttpResponse from '../HttpResponse';
|
||||
@ -52,7 +54,7 @@ export class {{classname}} {
|
||||
* {{summary}}
|
||||
* {{notes}}
|
||||
{{#allParams}}* @param {{paramName}} {{description}}
|
||||
{{/allParams}}{{#useHttpClient}}* @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body.
|
||||
{{/allParams}}* {{#useHttpClient}}@param observe set whether or not to return the data as the body, response or events. defaults to returning the body.
|
||||
* @param reportProgress flag to report request and response progress.{{/useHttpClient}}
|
||||
*/
|
||||
public {{nickname}}({{#allParams}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}, {{/allParams}}observe?: 'body', headers?: Headers): {{#usePromise}}Promise{{/usePromise}}{{^usePromise}}Observable{{/usePromise}}<{{#returnType}}{{{returnType}}}{{#isResponseTypeFile}}|undefined{{/isResponseTypeFile}}{{/returnType}}{{^returnType}}any{{/returnType}}>;
|
||||
@ -179,13 +181,13 @@ export class {{classname}} {
|
||||
{{/formParams}}
|
||||
|
||||
{{/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);
|
||||
const response: {{#usePromise}}Promise{{/usePromise}}{{^usePromise}}Observable{{/usePromise}}<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') {
|
||||
return response.pipe(
|
||||
map((httpResponse: HttpResponse) => <{{#returnType}}{{{returnType}}}{{#isResponseTypeFile}}|undefined{{/isResponseTypeFile}}{{/returnType}}{{^returnType}}any{{/returnType}}>(httpResponse.response))
|
||||
){{#usePromise}}.toPromise(){{/usePromise}};
|
||||
return response.{{#usePromise}}then{{/usePromise}}{{^usePromise}}pipe{{/usePromise}}(
|
||||
{{^usePromise}}map({{/usePromise}}(httpResponse: HttpResponse) => <{{#returnType}}{{{returnType}}}{{#isResponseTypeFile}}|undefined{{/isResponseTypeFile}}{{/returnType}}{{^returnType}}any{{/returnType}}>(httpResponse.response){{^usePromise}}){{/usePromise}}
|
||||
);
|
||||
}
|
||||
return response{{#usePromise}}.toPromise(){{/usePromise}};
|
||||
return response;
|
||||
}
|
||||
|
||||
{{/operation}}}
|
||||
|
@ -1,11 +1,13 @@
|
||||
{{>licenseInfo}}
|
||||
import { Headers } from '../Headers';
|
||||
{{^usePromise}}
|
||||
{{^useRxJS6}}
|
||||
import { Observable } from 'rxjs/Observable';
|
||||
{{/useRxJS6}}
|
||||
{{#useRxJS6}}
|
||||
import { Observable } from 'rxjs';
|
||||
{{/useRxJS6}}
|
||||
{{/usePromise}}
|
||||
{{#imports}}
|
||||
import { {{classname}} } from '../{{filename}}';
|
||||
{{/imports}}
|
||||
|
@ -2,15 +2,15 @@ import IHttpClient from './IHttpClient';
|
||||
|
||||
import { Observable } from 'rxjs/Observable';
|
||||
|
||||
import {injectable} from 'inversify';
|
||||
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> {
|
||||
get(url:string, headers?: Headers): Observable<HttpResponse> {
|
||||
return this.performNetworkCall(url, 'GET', undefined, headers);
|
||||
}
|
||||
|
||||
|
@ -12,10 +12,10 @@
|
||||
/* tslint:disable:no-unused-variable member-ordering */
|
||||
|
||||
import { Observable } from 'rxjs/Observable';
|
||||
|
||||
import { map } from 'rxjs/operators';
|
||||
import IHttpClient from '../IHttpClient';
|
||||
|
||||
import { inject, injectable } from 'inversify';
|
||||
import IHttpClient from '../IHttpClient';
|
||||
import { IAPIConfiguration } from '../IAPIConfiguration';
|
||||
import { Headers } from '../Headers';
|
||||
import HttpResponse from '../HttpResponse';
|
||||
@ -41,7 +41,7 @@ export class PetService {
|
||||
* Add a new pet to the store
|
||||
*
|
||||
* @param body Pet object that needs to be added to the store
|
||||
|
||||
*
|
||||
*/
|
||||
public addPet(body: Pet, observe?: 'body', headers?: Headers): Observable<any>;
|
||||
public addPet(body: Pet, observe?: 'response', headers?: Headers): Observable<HttpResponse<any>>;
|
||||
@ -75,7 +75,7 @@ export class PetService {
|
||||
*
|
||||
* @param petId Pet id to delete
|
||||
* @param apiKey
|
||||
|
||||
*
|
||||
*/
|
||||
public deletePet(petId: number, apiKey?: string, observe?: 'body', headers?: Headers): Observable<any>;
|
||||
public deletePet(petId: number, apiKey?: string, observe?: 'response', headers?: Headers): Observable<HttpResponse<any>>;
|
||||
@ -111,7 +111,7 @@ export class PetService {
|
||||
* 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<'available' | 'pending' | 'sold'>, observe?: 'body', headers?: Headers): Observable<Array<Pet>>;
|
||||
public findPetsByStatus(status: Array<'available' | 'pending' | 'sold'>, observe?: 'response', headers?: Headers): Observable<HttpResponse<Array<Pet>>>;
|
||||
@ -148,7 +148,7 @@ export class PetService {
|
||||
* 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>, observe?: 'body', headers?: Headers): Observable<Array<Pet>>;
|
||||
public findPetsByTags(tags: Array<string>, observe?: 'response', headers?: Headers): Observable<HttpResponse<Array<Pet>>>;
|
||||
@ -185,7 +185,7 @@ export class PetService {
|
||||
* Find pet by ID
|
||||
* Returns a single pet
|
||||
* @param petId ID of pet to return
|
||||
|
||||
*
|
||||
*/
|
||||
public getPetById(petId: number, observe?: 'body', headers?: Headers): Observable<Pet>;
|
||||
public getPetById(petId: number, observe?: 'response', headers?: Headers): Observable<HttpResponse<Pet>>;
|
||||
@ -214,7 +214,7 @@ export class PetService {
|
||||
* Update an existing pet
|
||||
*
|
||||
* @param body Pet object that needs to be added to the store
|
||||
|
||||
*
|
||||
*/
|
||||
public updatePet(body: Pet, observe?: 'body', headers?: Headers): Observable<any>;
|
||||
public updatePet(body: Pet, observe?: 'response', headers?: Headers): Observable<HttpResponse<any>>;
|
||||
@ -249,7 +249,7 @@ export class PetService {
|
||||
* @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: number, name?: string, status?: string, observe?: 'body', headers?: Headers): Observable<any>;
|
||||
public updatePetWithForm(petId: number, name?: string, status?: string, observe?: 'response', headers?: Headers): Observable<HttpResponse<any>>;
|
||||
@ -292,7 +292,7 @@ export class PetService {
|
||||
* @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?: Blob, observe?: 'body', headers?: Headers): Observable<ApiResponse>;
|
||||
public uploadFile(petId: number, additionalMetadata?: string, file?: Blob, observe?: 'response', headers?: Headers): Observable<HttpResponse<ApiResponse>>;
|
||||
|
@ -12,10 +12,10 @@
|
||||
/* tslint:disable:no-unused-variable member-ordering */
|
||||
|
||||
import { Observable } from 'rxjs/Observable';
|
||||
|
||||
import { map } from 'rxjs/operators';
|
||||
import IHttpClient from '../IHttpClient';
|
||||
|
||||
import { inject, injectable } from 'inversify';
|
||||
import IHttpClient from '../IHttpClient';
|
||||
import { IAPIConfiguration } from '../IAPIConfiguration';
|
||||
import { Headers } from '../Headers';
|
||||
import HttpResponse from '../HttpResponse';
|
||||
@ -40,7 +40,7 @@ export class StoreService {
|
||||
* 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, observe?: 'body', headers?: Headers): Observable<any>;
|
||||
public deleteOrder(orderId: string, observe?: 'response', headers?: Headers): Observable<HttpResponse<any>>;
|
||||
@ -64,7 +64,7 @@ export class StoreService {
|
||||
/**
|
||||
* Returns pet inventories by status
|
||||
* Returns a map of status codes to quantities
|
||||
|
||||
*
|
||||
*/
|
||||
public getInventory(observe?: 'body', headers?: Headers): Observable<{ [key: string]: number; }>;
|
||||
public getInventory(observe?: 'response', headers?: Headers): Observable<HttpResponse<{ [key: string]: number; }>>;
|
||||
@ -89,7 +89,7 @@ export class StoreService {
|
||||
* Find purchase order by ID
|
||||
* For valid response try integer IDs with value <= 5 or > 10. Other values will generate exceptions
|
||||
* @param orderId ID of pet that needs to be fetched
|
||||
|
||||
*
|
||||
*/
|
||||
public getOrderById(orderId: number, observe?: 'body', headers?: Headers): Observable<Order>;
|
||||
public getOrderById(orderId: number, observe?: 'response', headers?: Headers): Observable<HttpResponse<Order>>;
|
||||
@ -114,7 +114,7 @@ export class StoreService {
|
||||
* Place an order for a pet
|
||||
*
|
||||
* @param body order placed for purchasing the pet
|
||||
|
||||
*
|
||||
*/
|
||||
public placeOrder(body: Order, observe?: 'body', headers?: Headers): Observable<Order>;
|
||||
public placeOrder(body: Order, observe?: 'response', headers?: Headers): Observable<HttpResponse<Order>>;
|
||||
|
@ -12,10 +12,10 @@
|
||||
/* tslint:disable:no-unused-variable member-ordering */
|
||||
|
||||
import { Observable } from 'rxjs/Observable';
|
||||
|
||||
import { map } from 'rxjs/operators';
|
||||
import IHttpClient from '../IHttpClient';
|
||||
|
||||
import { inject, injectable } from 'inversify';
|
||||
import IHttpClient from '../IHttpClient';
|
||||
import { IAPIConfiguration } from '../IAPIConfiguration';
|
||||
import { Headers } from '../Headers';
|
||||
import HttpResponse from '../HttpResponse';
|
||||
@ -40,7 +40,7 @@ export class UserService {
|
||||
* Create user
|
||||
* This can only be done by the logged in user.
|
||||
* @param body Created user object
|
||||
|
||||
*
|
||||
*/
|
||||
public createUser(body: User, observe?: 'body', headers?: Headers): Observable<any>;
|
||||
public createUser(body: User, observe?: 'response', headers?: Headers): Observable<HttpResponse<any>>;
|
||||
@ -66,7 +66,7 @@ export class UserService {
|
||||
* Creates list of users with given input array
|
||||
*
|
||||
* @param body List of user object
|
||||
|
||||
*
|
||||
*/
|
||||
public createUsersWithArrayInput(body: Array<User>, observe?: 'body', headers?: Headers): Observable<any>;
|
||||
public createUsersWithArrayInput(body: Array<User>, observe?: 'response', headers?: Headers): Observable<HttpResponse<any>>;
|
||||
@ -92,7 +92,7 @@ export class UserService {
|
||||
* Creates list of users with given input array
|
||||
*
|
||||
* @param body List of user object
|
||||
|
||||
*
|
||||
*/
|
||||
public createUsersWithListInput(body: Array<User>, observe?: 'body', headers?: Headers): Observable<any>;
|
||||
public createUsersWithListInput(body: Array<User>, observe?: 'response', headers?: Headers): Observable<HttpResponse<any>>;
|
||||
@ -118,7 +118,7 @@ export class UserService {
|
||||
* 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, observe?: 'body', headers?: Headers): Observable<any>;
|
||||
public deleteUser(username: string, observe?: 'response', headers?: Headers): Observable<HttpResponse<any>>;
|
||||
@ -143,7 +143,7 @@ export class UserService {
|
||||
* Get user by user name
|
||||
*
|
||||
* @param username The name that needs to be fetched. Use user1 for testing.
|
||||
|
||||
*
|
||||
*/
|
||||
public getUserByName(username: string, observe?: 'body', headers?: Headers): Observable<User>;
|
||||
public getUserByName(username: string, observe?: 'response', headers?: Headers): Observable<HttpResponse<User>>;
|
||||
@ -169,7 +169,7 @@ export class UserService {
|
||||
*
|
||||
* @param username The user name for login
|
||||
* @param password The password for login in clear text
|
||||
|
||||
*
|
||||
*/
|
||||
public loginUser(username: string, password: string, observe?: 'body', headers?: Headers): Observable<string>;
|
||||
public loginUser(username: string, password: string, observe?: 'response', headers?: Headers): Observable<HttpResponse<string>>;
|
||||
@ -205,7 +205,7 @@ export class UserService {
|
||||
/**
|
||||
* Logs out current logged in user session
|
||||
*
|
||||
|
||||
*
|
||||
*/
|
||||
public logoutUser(observe?: 'body', headers?: Headers): Observable<any>;
|
||||
public logoutUser(observe?: 'response', headers?: Headers): Observable<HttpResponse<any>>;
|
||||
@ -227,7 +227,7 @@ export class UserService {
|
||||
* This can only be done by the logged in user.
|
||||
* @param username name that need to be deleted
|
||||
* @param body Updated user object
|
||||
|
||||
*
|
||||
*/
|
||||
public updateUser(username: string, body: User, observe?: 'body', headers?: Headers): Observable<any>;
|
||||
public updateUser(username: string, body: User, observe?: 'response', headers?: Headers): Observable<HttpResponse<any>>;
|
||||
|
Loading…
x
Reference in New Issue
Block a user