[typescript-rxjs] support HEAD method, improve formatting (#3766)

* feat(typescript-rxjs): add support for HEAD method

* feat(typescript-rxjs): improve formatting

* feat(typescript-rxjs): regenerate samples

* feat(typescript-rxjs): generate samples

* feat(typescript-rxjs): use better white space, regnerate samples
This commit is contained in:
Bernd Hacker 2019-08-27 11:17:41 +02:00 committed by Esteban Gehring
parent d0d545bbdd
commit 5bd63074c4
18 changed files with 126 additions and 126 deletions

View File

@ -175,7 +175,7 @@ export class {{classname}} extends BaseAPI {
responseType: 'blob' responseType: 'blob'
{{/isResponseFile}} {{/isResponseFile}}
}); });
} };
{{/operation}} {{/operation}}
} }

View File

@ -65,7 +65,7 @@ export class BaseAPI {
const next = this.clone<T>(); const next = this.clone<T>();
next.middleware = next.middleware.concat(middlewares); next.middleware = next.middleware.concat(middlewares);
return next; return next;
} };
withPreMiddleware = <T extends BaseAPI>(preMiddlewares: Array<Middleware['pre']>) => withPreMiddleware = <T extends BaseAPI>(preMiddlewares: Array<Middleware['pre']>) =>
this.withMiddleware<T>(preMiddlewares.map((pre) => ({ pre }))); this.withMiddleware<T>(preMiddlewares.map((pre) => ({ pre })));
@ -73,7 +73,7 @@ export class BaseAPI {
withPostMiddleware = <T extends BaseAPI>(postMiddlewares: Array<Middleware['post']>) => withPostMiddleware = <T extends BaseAPI>(postMiddlewares: Array<Middleware['post']>) =>
this.withMiddleware<T>(postMiddlewares.map((post) => ({ post }))); this.withMiddleware<T>(postMiddlewares.map((post) => ({ post })));
protected request = <T>(requestOpts: RequestOpts): Observable<T> => protected request = <T>(requestOpts: RequestOpts): Observable<T> =>
this.rxjsRequest(this.createRequestArgs(requestOpts)).pipe( this.rxjsRequest(this.createRequestArgs(requestOpts)).pipe(
map((res) => { map((res) => {
if (res.status >= 200 && res.status < 300) { if (res.status >= 200 && res.status < 300) {
@ -91,17 +91,17 @@ export class BaseAPI {
// do not handle correctly sometimes. // do not handle correctly sometimes.
url += '?' + queryString(requestOpts.query); url += '?' + queryString(requestOpts.query);
} }
return { return {
url, url,
method: requestOpts.method, method: requestOpts.method,
headers: requestOpts.headers, headers: requestOpts.headers,
body: requestOpts.body instanceof FormData ? requestOpts.body : JSON.stringify(requestOpts.body), body: requestOpts.body instanceof FormData ? requestOpts.body : JSON.stringify(requestOpts.body),
responseType: requestOpts.responseType || 'json' responseType: requestOpts.responseType || 'json',
}; };
} }
private rxjsRequest = (params: RequestArgs): Observable<AjaxResponse> => private rxjsRequest = (params: RequestArgs): Observable<AjaxResponse> =>
of(params).pipe( of(params).pipe(
map((request) => { map((request) => {
this.middleware.filter((item) => item.pre).forEach((mw) => (request = mw.pre!(request))); this.middleware.filter((item) => item.pre).forEach((mw) => (request = mw.pre!(request)));
@ -122,7 +122,7 @@ export class BaseAPI {
* and then shallow cloning data members. * and then shallow cloning data members.
*/ */
private clone = <T extends BaseAPI>(): T => private clone = <T extends BaseAPI>(): T =>
Object.assign(Object.create(Object.getPrototypeOf(this)), this) Object.assign(Object.create(Object.getPrototypeOf(this)), this);
} }
// export for not being a breaking change // export for not being a breaking change
@ -138,7 +138,7 @@ export const COLLECTION_FORMATS = {
}; };
export type Json = any; export type Json = any;
export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'OPTIONS'; export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'OPTIONS' | 'HEAD';
export type HttpHeaders = { [key: string]: string }; export type HttpHeaders = { [key: string]: string };
export type HttpQuery = { [key: string]: string | number | null | boolean | Array<string | number | null | boolean> }; export type HttpQuery = { [key: string]: string | number | null | boolean | Array<string | number | null | boolean> };
export type HttpBody = Json | FormData; export type HttpBody = Json | FormData;
@ -153,7 +153,7 @@ export interface RequestOpts {
responseType?: 'json' | 'blob' | 'arraybuffer' | 'text'; responseType?: 'json' | 'blob' | 'arraybuffer' | 'text';
} }
export const encodeURI = (value: any) => encodeURIComponent(String(value)) export const encodeURI = (value: any) => encodeURIComponent(String(value));
const queryString = (params: HttpQuery): string => Object.keys(params) const queryString = (params: HttpQuery): string => Object.keys(params)
.map((key) => { .map((key) => {
@ -171,7 +171,7 @@ export const throwIfRequired = (params: {[key: string]: any}, key: string, nickn
if (!params || params[key] === null || params[key] === undefined) { if (!params || params[key] === null || params[key] === undefined) {
throw new RequiredError(`Required parameter ${key} was null or undefined when calling ${nickname}.`); throw new RequiredError(`Required parameter ${key} was null or undefined when calling ${nickname}.`);
} }
} };
// alias for easier importing // alias for easier importing
export interface RequestArgs extends AjaxRequest {} export interface RequestArgs extends AjaxRequest {}

View File

@ -82,7 +82,7 @@ export class PetApi extends BaseAPI {
headers, headers,
body: requestParameters.body, body: requestParameters.body,
}); });
} };
/** /**
* Deletes a pet * Deletes a pet
@ -105,7 +105,7 @@ export class PetApi extends BaseAPI {
method: 'DELETE', method: 'DELETE',
headers, headers,
}); });
} };
/** /**
* Multiple status values can be provided with comma separated strings * Multiple status values can be provided with comma separated strings
@ -133,7 +133,7 @@ export class PetApi extends BaseAPI {
headers, headers,
query, query,
}); });
} };
/** /**
* Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. * Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
@ -161,7 +161,7 @@ export class PetApi extends BaseAPI {
headers, headers,
query, query,
}); });
} };
/** /**
* Returns a single pet * Returns a single pet
@ -179,7 +179,7 @@ export class PetApi extends BaseAPI {
method: 'GET', method: 'GET',
headers, headers,
}); });
} };
/** /**
* Update an existing pet * Update an existing pet
@ -203,7 +203,7 @@ export class PetApi extends BaseAPI {
headers, headers,
body: requestParameters.body, body: requestParameters.body,
}); });
} };
/** /**
* Updates a pet in the store with form data * Updates a pet in the store with form data
@ -235,7 +235,7 @@ export class PetApi extends BaseAPI {
headers, headers,
body: formData, body: formData,
}); });
} };
/** /**
* uploads an image * uploads an image
@ -267,7 +267,7 @@ export class PetApi extends BaseAPI {
headers, headers,
body: formData, body: formData,
}); });
} };
} }

View File

@ -45,7 +45,7 @@ export class StoreApi extends BaseAPI {
path: '/store/order/{orderId}'.replace('{orderId}', encodeURI(requestParameters.orderId)), path: '/store/order/{orderId}'.replace('{orderId}', encodeURI(requestParameters.orderId)),
method: 'DELETE', method: 'DELETE',
}); });
} };
/** /**
* Returns a map of status codes to quantities * Returns a map of status codes to quantities
@ -61,7 +61,7 @@ export class StoreApi extends BaseAPI {
method: 'GET', method: 'GET',
headers, headers,
}); });
} };
/** /**
* For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions * For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions
@ -74,7 +74,7 @@ export class StoreApi extends BaseAPI {
path: '/store/order/{orderId}'.replace('{orderId}', encodeURI(requestParameters.orderId)), path: '/store/order/{orderId}'.replace('{orderId}', encodeURI(requestParameters.orderId)),
method: 'GET', method: 'GET',
}); });
} };
/** /**
* Place an order for a pet * Place an order for a pet
@ -92,6 +92,6 @@ export class StoreApi extends BaseAPI {
headers, headers,
body: requestParameters.body, body: requestParameters.body,
}); });
} };
} }

View File

@ -69,7 +69,7 @@ export class UserApi extends BaseAPI {
headers, headers,
body: requestParameters.body, body: requestParameters.body,
}); });
} };
/** /**
* Creates list of users with given input array * Creates list of users with given input array
@ -87,7 +87,7 @@ export class UserApi extends BaseAPI {
headers, headers,
body: requestParameters.body, body: requestParameters.body,
}); });
} };
/** /**
* Creates list of users with given input array * Creates list of users with given input array
@ -105,7 +105,7 @@ export class UserApi extends BaseAPI {
headers, headers,
body: requestParameters.body, body: requestParameters.body,
}); });
} };
/** /**
* This can only be done by the logged in user. * This can only be done by the logged in user.
@ -118,7 +118,7 @@ export class UserApi extends BaseAPI {
path: '/user/{username}'.replace('{username}', encodeURI(requestParameters.username)), path: '/user/{username}'.replace('{username}', encodeURI(requestParameters.username)),
method: 'DELETE', method: 'DELETE',
}); });
} };
/** /**
* Get user by user name * Get user by user name
@ -130,7 +130,7 @@ export class UserApi extends BaseAPI {
path: '/user/{username}'.replace('{username}', encodeURI(requestParameters.username)), path: '/user/{username}'.replace('{username}', encodeURI(requestParameters.username)),
method: 'GET', method: 'GET',
}); });
} };
/** /**
* Logs user into the system * Logs user into the system
@ -149,7 +149,7 @@ export class UserApi extends BaseAPI {
method: 'GET', method: 'GET',
query, query,
}); });
} };
/** /**
* Logs out current logged in user session * Logs out current logged in user session
@ -159,7 +159,7 @@ export class UserApi extends BaseAPI {
path: '/user/logout', path: '/user/logout',
method: 'GET', method: 'GET',
}); });
} };
/** /**
* This can only be done by the logged in user. * This can only be done by the logged in user.
@ -179,6 +179,6 @@ export class UserApi extends BaseAPI {
headers, headers,
body: requestParameters.body, body: requestParameters.body,
}); });
} };
} }

View File

@ -76,7 +76,7 @@ export class BaseAPI {
const next = this.clone<T>(); const next = this.clone<T>();
next.middleware = next.middleware.concat(middlewares); next.middleware = next.middleware.concat(middlewares);
return next; return next;
} };
withPreMiddleware = <T extends BaseAPI>(preMiddlewares: Array<Middleware['pre']>) => withPreMiddleware = <T extends BaseAPI>(preMiddlewares: Array<Middleware['pre']>) =>
this.withMiddleware<T>(preMiddlewares.map((pre) => ({ pre }))); this.withMiddleware<T>(preMiddlewares.map((pre) => ({ pre })));
@ -84,7 +84,7 @@ export class BaseAPI {
withPostMiddleware = <T extends BaseAPI>(postMiddlewares: Array<Middleware['post']>) => withPostMiddleware = <T extends BaseAPI>(postMiddlewares: Array<Middleware['post']>) =>
this.withMiddleware<T>(postMiddlewares.map((post) => ({ post }))); this.withMiddleware<T>(postMiddlewares.map((post) => ({ post })));
protected request = <T>(requestOpts: RequestOpts): Observable<T> => protected request = <T>(requestOpts: RequestOpts): Observable<T> =>
this.rxjsRequest(this.createRequestArgs(requestOpts)).pipe( this.rxjsRequest(this.createRequestArgs(requestOpts)).pipe(
map((res) => { map((res) => {
if (res.status >= 200 && res.status < 300) { if (res.status >= 200 && res.status < 300) {
@ -102,17 +102,17 @@ export class BaseAPI {
// do not handle correctly sometimes. // do not handle correctly sometimes.
url += '?' + queryString(requestOpts.query); url += '?' + queryString(requestOpts.query);
} }
return { return {
url, url,
method: requestOpts.method, method: requestOpts.method,
headers: requestOpts.headers, headers: requestOpts.headers,
body: requestOpts.body instanceof FormData ? requestOpts.body : JSON.stringify(requestOpts.body), body: requestOpts.body instanceof FormData ? requestOpts.body : JSON.stringify(requestOpts.body),
responseType: requestOpts.responseType || 'json' responseType: requestOpts.responseType || 'json',
}; };
} }
private rxjsRequest = (params: RequestArgs): Observable<AjaxResponse> => private rxjsRequest = (params: RequestArgs): Observable<AjaxResponse> =>
of(params).pipe( of(params).pipe(
map((request) => { map((request) => {
this.middleware.filter((item) => item.pre).forEach((mw) => (request = mw.pre!(request))); this.middleware.filter((item) => item.pre).forEach((mw) => (request = mw.pre!(request)));
@ -133,7 +133,7 @@ export class BaseAPI {
* and then shallow cloning data members. * and then shallow cloning data members.
*/ */
private clone = <T extends BaseAPI>(): T => private clone = <T extends BaseAPI>(): T =>
Object.assign(Object.create(Object.getPrototypeOf(this)), this) Object.assign(Object.create(Object.getPrototypeOf(this)), this);
} }
// export for not being a breaking change // export for not being a breaking change
@ -149,7 +149,7 @@ export const COLLECTION_FORMATS = {
}; };
export type Json = any; export type Json = any;
export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'OPTIONS'; export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'OPTIONS' | 'HEAD';
export type HttpHeaders = { [key: string]: string }; export type HttpHeaders = { [key: string]: string };
export type HttpQuery = { [key: string]: string | number | null | boolean | Array<string | number | null | boolean> }; export type HttpQuery = { [key: string]: string | number | null | boolean | Array<string | number | null | boolean> };
export type HttpBody = Json | FormData; export type HttpBody = Json | FormData;
@ -164,7 +164,7 @@ export interface RequestOpts {
responseType?: 'json' | 'blob' | 'arraybuffer' | 'text'; responseType?: 'json' | 'blob' | 'arraybuffer' | 'text';
} }
export const encodeURI = (value: any) => encodeURIComponent(String(value)) export const encodeURI = (value: any) => encodeURIComponent(String(value));
const queryString = (params: HttpQuery): string => Object.keys(params) const queryString = (params: HttpQuery): string => Object.keys(params)
.map((key) => { .map((key) => {
@ -182,7 +182,7 @@ export const throwIfRequired = (params: {[key: string]: any}, key: string, nickn
if (!params || params[key] === null || params[key] === undefined) { if (!params || params[key] === null || params[key] === undefined) {
throw new RequiredError(`Required parameter ${key} was null or undefined when calling ${nickname}.`); throw new RequiredError(`Required parameter ${key} was null or undefined when calling ${nickname}.`);
} }
} };
// alias for easier importing // alias for easier importing
export interface RequestArgs extends AjaxRequest {} export interface RequestArgs extends AjaxRequest {}

View File

@ -82,7 +82,7 @@ export class PetApi extends BaseAPI {
headers, headers,
body: requestParameters.body, body: requestParameters.body,
}); });
} };
/** /**
* Deletes a pet * Deletes a pet
@ -105,7 +105,7 @@ export class PetApi extends BaseAPI {
method: 'DELETE', method: 'DELETE',
headers, headers,
}); });
} };
/** /**
* Multiple status values can be provided with comma separated strings * Multiple status values can be provided with comma separated strings
@ -133,7 +133,7 @@ export class PetApi extends BaseAPI {
headers, headers,
query, query,
}); });
} };
/** /**
* Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. * Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
@ -161,7 +161,7 @@ export class PetApi extends BaseAPI {
headers, headers,
query, query,
}); });
} };
/** /**
* Returns a single pet * Returns a single pet
@ -179,7 +179,7 @@ export class PetApi extends BaseAPI {
method: 'GET', method: 'GET',
headers, headers,
}); });
} };
/** /**
* Update an existing pet * Update an existing pet
@ -203,7 +203,7 @@ export class PetApi extends BaseAPI {
headers, headers,
body: requestParameters.body, body: requestParameters.body,
}); });
} };
/** /**
* Updates a pet in the store with form data * Updates a pet in the store with form data
@ -235,7 +235,7 @@ export class PetApi extends BaseAPI {
headers, headers,
body: formData, body: formData,
}); });
} };
/** /**
* uploads an image * uploads an image
@ -267,7 +267,7 @@ export class PetApi extends BaseAPI {
headers, headers,
body: formData, body: formData,
}); });
} };
} }

View File

@ -45,7 +45,7 @@ export class StoreApi extends BaseAPI {
path: '/store/order/{orderId}'.replace('{orderId}', encodeURI(requestParameters.orderId)), path: '/store/order/{orderId}'.replace('{orderId}', encodeURI(requestParameters.orderId)),
method: 'DELETE', method: 'DELETE',
}); });
} };
/** /**
* Returns a map of status codes to quantities * Returns a map of status codes to quantities
@ -61,7 +61,7 @@ export class StoreApi extends BaseAPI {
method: 'GET', method: 'GET',
headers, headers,
}); });
} };
/** /**
* For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions * For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions
@ -74,7 +74,7 @@ export class StoreApi extends BaseAPI {
path: '/store/order/{orderId}'.replace('{orderId}', encodeURI(requestParameters.orderId)), path: '/store/order/{orderId}'.replace('{orderId}', encodeURI(requestParameters.orderId)),
method: 'GET', method: 'GET',
}); });
} };
/** /**
* Place an order for a pet * Place an order for a pet
@ -92,6 +92,6 @@ export class StoreApi extends BaseAPI {
headers, headers,
body: requestParameters.body, body: requestParameters.body,
}); });
} };
} }

View File

@ -69,7 +69,7 @@ export class UserApi extends BaseAPI {
headers, headers,
body: requestParameters.body, body: requestParameters.body,
}); });
} };
/** /**
* Creates list of users with given input array * Creates list of users with given input array
@ -87,7 +87,7 @@ export class UserApi extends BaseAPI {
headers, headers,
body: requestParameters.body, body: requestParameters.body,
}); });
} };
/** /**
* Creates list of users with given input array * Creates list of users with given input array
@ -105,7 +105,7 @@ export class UserApi extends BaseAPI {
headers, headers,
body: requestParameters.body, body: requestParameters.body,
}); });
} };
/** /**
* This can only be done by the logged in user. * This can only be done by the logged in user.
@ -118,7 +118,7 @@ export class UserApi extends BaseAPI {
path: '/user/{username}'.replace('{username}', encodeURI(requestParameters.username)), path: '/user/{username}'.replace('{username}', encodeURI(requestParameters.username)),
method: 'DELETE', method: 'DELETE',
}); });
} };
/** /**
* Get user by user name * Get user by user name
@ -130,7 +130,7 @@ export class UserApi extends BaseAPI {
path: '/user/{username}'.replace('{username}', encodeURI(requestParameters.username)), path: '/user/{username}'.replace('{username}', encodeURI(requestParameters.username)),
method: 'GET', method: 'GET',
}); });
} };
/** /**
* Logs user into the system * Logs user into the system
@ -149,7 +149,7 @@ export class UserApi extends BaseAPI {
method: 'GET', method: 'GET',
query, query,
}); });
} };
/** /**
* Logs out current logged in user session * Logs out current logged in user session
@ -159,7 +159,7 @@ export class UserApi extends BaseAPI {
path: '/user/logout', path: '/user/logout',
method: 'GET', method: 'GET',
}); });
} };
/** /**
* This can only be done by the logged in user. * This can only be done by the logged in user.
@ -179,6 +179,6 @@ export class UserApi extends BaseAPI {
headers, headers,
body: requestParameters.body, body: requestParameters.body,
}); });
} };
} }

View File

@ -76,7 +76,7 @@ export class BaseAPI {
const next = this.clone<T>(); const next = this.clone<T>();
next.middleware = next.middleware.concat(middlewares); next.middleware = next.middleware.concat(middlewares);
return next; return next;
} };
withPreMiddleware = <T extends BaseAPI>(preMiddlewares: Array<Middleware['pre']>) => withPreMiddleware = <T extends BaseAPI>(preMiddlewares: Array<Middleware['pre']>) =>
this.withMiddleware<T>(preMiddlewares.map((pre) => ({ pre }))); this.withMiddleware<T>(preMiddlewares.map((pre) => ({ pre })));
@ -84,7 +84,7 @@ export class BaseAPI {
withPostMiddleware = <T extends BaseAPI>(postMiddlewares: Array<Middleware['post']>) => withPostMiddleware = <T extends BaseAPI>(postMiddlewares: Array<Middleware['post']>) =>
this.withMiddleware<T>(postMiddlewares.map((post) => ({ post }))); this.withMiddleware<T>(postMiddlewares.map((post) => ({ post })));
protected request = <T>(requestOpts: RequestOpts): Observable<T> => protected request = <T>(requestOpts: RequestOpts): Observable<T> =>
this.rxjsRequest(this.createRequestArgs(requestOpts)).pipe( this.rxjsRequest(this.createRequestArgs(requestOpts)).pipe(
map((res) => { map((res) => {
if (res.status >= 200 && res.status < 300) { if (res.status >= 200 && res.status < 300) {
@ -102,17 +102,17 @@ export class BaseAPI {
// do not handle correctly sometimes. // do not handle correctly sometimes.
url += '?' + queryString(requestOpts.query); url += '?' + queryString(requestOpts.query);
} }
return { return {
url, url,
method: requestOpts.method, method: requestOpts.method,
headers: requestOpts.headers, headers: requestOpts.headers,
body: requestOpts.body instanceof FormData ? requestOpts.body : JSON.stringify(requestOpts.body), body: requestOpts.body instanceof FormData ? requestOpts.body : JSON.stringify(requestOpts.body),
responseType: requestOpts.responseType || 'json' responseType: requestOpts.responseType || 'json',
}; };
} }
private rxjsRequest = (params: RequestArgs): Observable<AjaxResponse> => private rxjsRequest = (params: RequestArgs): Observable<AjaxResponse> =>
of(params).pipe( of(params).pipe(
map((request) => { map((request) => {
this.middleware.filter((item) => item.pre).forEach((mw) => (request = mw.pre!(request))); this.middleware.filter((item) => item.pre).forEach((mw) => (request = mw.pre!(request)));
@ -133,7 +133,7 @@ export class BaseAPI {
* and then shallow cloning data members. * and then shallow cloning data members.
*/ */
private clone = <T extends BaseAPI>(): T => private clone = <T extends BaseAPI>(): T =>
Object.assign(Object.create(Object.getPrototypeOf(this)), this) Object.assign(Object.create(Object.getPrototypeOf(this)), this);
} }
// export for not being a breaking change // export for not being a breaking change
@ -149,7 +149,7 @@ export const COLLECTION_FORMATS = {
}; };
export type Json = any; export type Json = any;
export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'OPTIONS'; export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'OPTIONS' | 'HEAD';
export type HttpHeaders = { [key: string]: string }; export type HttpHeaders = { [key: string]: string };
export type HttpQuery = { [key: string]: string | number | null | boolean | Array<string | number | null | boolean> }; export type HttpQuery = { [key: string]: string | number | null | boolean | Array<string | number | null | boolean> };
export type HttpBody = Json | FormData; export type HttpBody = Json | FormData;
@ -164,7 +164,7 @@ export interface RequestOpts {
responseType?: 'json' | 'blob' | 'arraybuffer' | 'text'; responseType?: 'json' | 'blob' | 'arraybuffer' | 'text';
} }
export const encodeURI = (value: any) => encodeURIComponent(String(value)) export const encodeURI = (value: any) => encodeURIComponent(String(value));
const queryString = (params: HttpQuery): string => Object.keys(params) const queryString = (params: HttpQuery): string => Object.keys(params)
.map((key) => { .map((key) => {
@ -182,7 +182,7 @@ export const throwIfRequired = (params: {[key: string]: any}, key: string, nickn
if (!params || params[key] === null || params[key] === undefined) { if (!params || params[key] === null || params[key] === undefined) {
throw new RequiredError(`Required parameter ${key} was null or undefined when calling ${nickname}.`); throw new RequiredError(`Required parameter ${key} was null or undefined when calling ${nickname}.`);
} }
} };
// alias for easier importing // alias for easier importing
export interface RequestArgs extends AjaxRequest {} export interface RequestArgs extends AjaxRequest {}

View File

@ -82,7 +82,7 @@ export class PetApi extends BaseAPI {
headers, headers,
body: requestParameters.body, body: requestParameters.body,
}); });
} };
/** /**
* Deletes a pet * Deletes a pet
@ -105,7 +105,7 @@ export class PetApi extends BaseAPI {
method: 'DELETE', method: 'DELETE',
headers, headers,
}); });
} };
/** /**
* Multiple status values can be provided with comma separated strings * Multiple status values can be provided with comma separated strings
@ -133,7 +133,7 @@ export class PetApi extends BaseAPI {
headers, headers,
query, query,
}); });
} };
/** /**
* Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. * Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
@ -161,7 +161,7 @@ export class PetApi extends BaseAPI {
headers, headers,
query, query,
}); });
} };
/** /**
* Returns a single pet * Returns a single pet
@ -179,7 +179,7 @@ export class PetApi extends BaseAPI {
method: 'GET', method: 'GET',
headers, headers,
}); });
} };
/** /**
* Update an existing pet * Update an existing pet
@ -203,7 +203,7 @@ export class PetApi extends BaseAPI {
headers, headers,
body: requestParameters.body, body: requestParameters.body,
}); });
} };
/** /**
* Updates a pet in the store with form data * Updates a pet in the store with form data
@ -235,7 +235,7 @@ export class PetApi extends BaseAPI {
headers, headers,
body: formData, body: formData,
}); });
} };
/** /**
* uploads an image * uploads an image
@ -267,7 +267,7 @@ export class PetApi extends BaseAPI {
headers, headers,
body: formData, body: formData,
}); });
} };
} }

View File

@ -45,7 +45,7 @@ export class StoreApi extends BaseAPI {
path: '/store/order/{orderId}'.replace('{orderId}', encodeURI(requestParameters.orderId)), path: '/store/order/{orderId}'.replace('{orderId}', encodeURI(requestParameters.orderId)),
method: 'DELETE', method: 'DELETE',
}); });
} };
/** /**
* Returns a map of status codes to quantities * Returns a map of status codes to quantities
@ -61,7 +61,7 @@ export class StoreApi extends BaseAPI {
method: 'GET', method: 'GET',
headers, headers,
}); });
} };
/** /**
* For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions * For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions
@ -74,7 +74,7 @@ export class StoreApi extends BaseAPI {
path: '/store/order/{orderId}'.replace('{orderId}', encodeURI(requestParameters.orderId)), path: '/store/order/{orderId}'.replace('{orderId}', encodeURI(requestParameters.orderId)),
method: 'GET', method: 'GET',
}); });
} };
/** /**
* Place an order for a pet * Place an order for a pet
@ -92,6 +92,6 @@ export class StoreApi extends BaseAPI {
headers, headers,
body: requestParameters.body, body: requestParameters.body,
}); });
} };
} }

View File

@ -69,7 +69,7 @@ export class UserApi extends BaseAPI {
headers, headers,
body: requestParameters.body, body: requestParameters.body,
}); });
} };
/** /**
* Creates list of users with given input array * Creates list of users with given input array
@ -87,7 +87,7 @@ export class UserApi extends BaseAPI {
headers, headers,
body: requestParameters.body, body: requestParameters.body,
}); });
} };
/** /**
* Creates list of users with given input array * Creates list of users with given input array
@ -105,7 +105,7 @@ export class UserApi extends BaseAPI {
headers, headers,
body: requestParameters.body, body: requestParameters.body,
}); });
} };
/** /**
* This can only be done by the logged in user. * This can only be done by the logged in user.
@ -118,7 +118,7 @@ export class UserApi extends BaseAPI {
path: '/user/{username}'.replace('{username}', encodeURI(requestParameters.username)), path: '/user/{username}'.replace('{username}', encodeURI(requestParameters.username)),
method: 'DELETE', method: 'DELETE',
}); });
} };
/** /**
* Get user by user name * Get user by user name
@ -130,7 +130,7 @@ export class UserApi extends BaseAPI {
path: '/user/{username}'.replace('{username}', encodeURI(requestParameters.username)), path: '/user/{username}'.replace('{username}', encodeURI(requestParameters.username)),
method: 'GET', method: 'GET',
}); });
} };
/** /**
* Logs user into the system * Logs user into the system
@ -149,7 +149,7 @@ export class UserApi extends BaseAPI {
method: 'GET', method: 'GET',
query, query,
}); });
} };
/** /**
* Logs out current logged in user session * Logs out current logged in user session
@ -159,7 +159,7 @@ export class UserApi extends BaseAPI {
path: '/user/logout', path: '/user/logout',
method: 'GET', method: 'GET',
}); });
} };
/** /**
* This can only be done by the logged in user. * This can only be done by the logged in user.
@ -179,6 +179,6 @@ export class UserApi extends BaseAPI {
headers, headers,
body: requestParameters.body, body: requestParameters.body,
}); });
} };
} }

View File

@ -76,7 +76,7 @@ export class BaseAPI {
const next = this.clone<T>(); const next = this.clone<T>();
next.middleware = next.middleware.concat(middlewares); next.middleware = next.middleware.concat(middlewares);
return next; return next;
} };
withPreMiddleware = <T extends BaseAPI>(preMiddlewares: Array<Middleware['pre']>) => withPreMiddleware = <T extends BaseAPI>(preMiddlewares: Array<Middleware['pre']>) =>
this.withMiddleware<T>(preMiddlewares.map((pre) => ({ pre }))); this.withMiddleware<T>(preMiddlewares.map((pre) => ({ pre })));
@ -84,7 +84,7 @@ export class BaseAPI {
withPostMiddleware = <T extends BaseAPI>(postMiddlewares: Array<Middleware['post']>) => withPostMiddleware = <T extends BaseAPI>(postMiddlewares: Array<Middleware['post']>) =>
this.withMiddleware<T>(postMiddlewares.map((post) => ({ post }))); this.withMiddleware<T>(postMiddlewares.map((post) => ({ post })));
protected request = <T>(requestOpts: RequestOpts): Observable<T> => protected request = <T>(requestOpts: RequestOpts): Observable<T> =>
this.rxjsRequest(this.createRequestArgs(requestOpts)).pipe( this.rxjsRequest(this.createRequestArgs(requestOpts)).pipe(
map((res) => { map((res) => {
if (res.status >= 200 && res.status < 300) { if (res.status >= 200 && res.status < 300) {
@ -102,17 +102,17 @@ export class BaseAPI {
// do not handle correctly sometimes. // do not handle correctly sometimes.
url += '?' + queryString(requestOpts.query); url += '?' + queryString(requestOpts.query);
} }
return { return {
url, url,
method: requestOpts.method, method: requestOpts.method,
headers: requestOpts.headers, headers: requestOpts.headers,
body: requestOpts.body instanceof FormData ? requestOpts.body : JSON.stringify(requestOpts.body), body: requestOpts.body instanceof FormData ? requestOpts.body : JSON.stringify(requestOpts.body),
responseType: requestOpts.responseType || 'json' responseType: requestOpts.responseType || 'json',
}; };
} }
private rxjsRequest = (params: RequestArgs): Observable<AjaxResponse> => private rxjsRequest = (params: RequestArgs): Observable<AjaxResponse> =>
of(params).pipe( of(params).pipe(
map((request) => { map((request) => {
this.middleware.filter((item) => item.pre).forEach((mw) => (request = mw.pre!(request))); this.middleware.filter((item) => item.pre).forEach((mw) => (request = mw.pre!(request)));
@ -133,7 +133,7 @@ export class BaseAPI {
* and then shallow cloning data members. * and then shallow cloning data members.
*/ */
private clone = <T extends BaseAPI>(): T => private clone = <T extends BaseAPI>(): T =>
Object.assign(Object.create(Object.getPrototypeOf(this)), this) Object.assign(Object.create(Object.getPrototypeOf(this)), this);
} }
// export for not being a breaking change // export for not being a breaking change
@ -149,7 +149,7 @@ export const COLLECTION_FORMATS = {
}; };
export type Json = any; export type Json = any;
export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'OPTIONS'; export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'OPTIONS' | 'HEAD';
export type HttpHeaders = { [key: string]: string }; export type HttpHeaders = { [key: string]: string };
export type HttpQuery = { [key: string]: string | number | null | boolean | Array<string | number | null | boolean> }; export type HttpQuery = { [key: string]: string | number | null | boolean | Array<string | number | null | boolean> };
export type HttpBody = Json | FormData; export type HttpBody = Json | FormData;
@ -164,7 +164,7 @@ export interface RequestOpts {
responseType?: 'json' | 'blob' | 'arraybuffer' | 'text'; responseType?: 'json' | 'blob' | 'arraybuffer' | 'text';
} }
export const encodeURI = (value: any) => encodeURIComponent(String(value)) export const encodeURI = (value: any) => encodeURIComponent(String(value));
const queryString = (params: HttpQuery): string => Object.keys(params) const queryString = (params: HttpQuery): string => Object.keys(params)
.map((key) => { .map((key) => {
@ -182,7 +182,7 @@ export const throwIfRequired = (params: {[key: string]: any}, key: string, nickn
if (!params || params[key] === null || params[key] === undefined) { if (!params || params[key] === null || params[key] === undefined) {
throw new RequiredError(`Required parameter ${key} was null or undefined when calling ${nickname}.`); throw new RequiredError(`Required parameter ${key} was null or undefined when calling ${nickname}.`);
} }
} };
// alias for easier importing // alias for easier importing
export interface RequestArgs extends AjaxRequest {} export interface RequestArgs extends AjaxRequest {}

View File

@ -82,7 +82,7 @@ export class PetApi extends BaseAPI {
headers, headers,
body: requestParameters.body, body: requestParameters.body,
}); });
} };
/** /**
* Deletes a pet * Deletes a pet
@ -105,7 +105,7 @@ export class PetApi extends BaseAPI {
method: 'DELETE', method: 'DELETE',
headers, headers,
}); });
} };
/** /**
* Multiple status values can be provided with comma separated strings * Multiple status values can be provided with comma separated strings
@ -133,7 +133,7 @@ export class PetApi extends BaseAPI {
headers, headers,
query, query,
}); });
} };
/** /**
* Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. * Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
@ -161,7 +161,7 @@ export class PetApi extends BaseAPI {
headers, headers,
query, query,
}); });
} };
/** /**
* Returns a single pet * Returns a single pet
@ -179,7 +179,7 @@ export class PetApi extends BaseAPI {
method: 'GET', method: 'GET',
headers, headers,
}); });
} };
/** /**
* Update an existing pet * Update an existing pet
@ -203,7 +203,7 @@ export class PetApi extends BaseAPI {
headers, headers,
body: requestParameters.body, body: requestParameters.body,
}); });
} };
/** /**
* Updates a pet in the store with form data * Updates a pet in the store with form data
@ -235,7 +235,7 @@ export class PetApi extends BaseAPI {
headers, headers,
body: formData, body: formData,
}); });
} };
/** /**
* uploads an image * uploads an image
@ -267,7 +267,7 @@ export class PetApi extends BaseAPI {
headers, headers,
body: formData, body: formData,
}); });
} };
} }

View File

@ -45,7 +45,7 @@ export class StoreApi extends BaseAPI {
path: '/store/order/{orderId}'.replace('{orderId}', encodeURI(requestParameters.orderId)), path: '/store/order/{orderId}'.replace('{orderId}', encodeURI(requestParameters.orderId)),
method: 'DELETE', method: 'DELETE',
}); });
} };
/** /**
* Returns a map of status codes to quantities * Returns a map of status codes to quantities
@ -61,7 +61,7 @@ export class StoreApi extends BaseAPI {
method: 'GET', method: 'GET',
headers, headers,
}); });
} };
/** /**
* For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions * For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions
@ -74,7 +74,7 @@ export class StoreApi extends BaseAPI {
path: '/store/order/{orderId}'.replace('{orderId}', encodeURI(requestParameters.orderId)), path: '/store/order/{orderId}'.replace('{orderId}', encodeURI(requestParameters.orderId)),
method: 'GET', method: 'GET',
}); });
} };
/** /**
* Place an order for a pet * Place an order for a pet
@ -92,6 +92,6 @@ export class StoreApi extends BaseAPI {
headers, headers,
body: requestParameters.body, body: requestParameters.body,
}); });
} };
} }

View File

@ -69,7 +69,7 @@ export class UserApi extends BaseAPI {
headers, headers,
body: requestParameters.body, body: requestParameters.body,
}); });
} };
/** /**
* Creates list of users with given input array * Creates list of users with given input array
@ -87,7 +87,7 @@ export class UserApi extends BaseAPI {
headers, headers,
body: requestParameters.body, body: requestParameters.body,
}); });
} };
/** /**
* Creates list of users with given input array * Creates list of users with given input array
@ -105,7 +105,7 @@ export class UserApi extends BaseAPI {
headers, headers,
body: requestParameters.body, body: requestParameters.body,
}); });
} };
/** /**
* This can only be done by the logged in user. * This can only be done by the logged in user.
@ -118,7 +118,7 @@ export class UserApi extends BaseAPI {
path: '/user/{username}'.replace('{username}', encodeURI(requestParameters.username)), path: '/user/{username}'.replace('{username}', encodeURI(requestParameters.username)),
method: 'DELETE', method: 'DELETE',
}); });
} };
/** /**
* Get user by user name * Get user by user name
@ -130,7 +130,7 @@ export class UserApi extends BaseAPI {
path: '/user/{username}'.replace('{username}', encodeURI(requestParameters.username)), path: '/user/{username}'.replace('{username}', encodeURI(requestParameters.username)),
method: 'GET', method: 'GET',
}); });
} };
/** /**
* Logs user into the system * Logs user into the system
@ -149,7 +149,7 @@ export class UserApi extends BaseAPI {
method: 'GET', method: 'GET',
query, query,
}); });
} };
/** /**
* Logs out current logged in user session * Logs out current logged in user session
@ -159,7 +159,7 @@ export class UserApi extends BaseAPI {
path: '/user/logout', path: '/user/logout',
method: 'GET', method: 'GET',
}); });
} };
/** /**
* This can only be done by the logged in user. * This can only be done by the logged in user.
@ -179,6 +179,6 @@ export class UserApi extends BaseAPI {
headers, headers,
body: requestParameters.body, body: requestParameters.body,
}); });
} };
} }

View File

@ -76,7 +76,7 @@ export class BaseAPI {
const next = this.clone<T>(); const next = this.clone<T>();
next.middleware = next.middleware.concat(middlewares); next.middleware = next.middleware.concat(middlewares);
return next; return next;
} };
withPreMiddleware = <T extends BaseAPI>(preMiddlewares: Array<Middleware['pre']>) => withPreMiddleware = <T extends BaseAPI>(preMiddlewares: Array<Middleware['pre']>) =>
this.withMiddleware<T>(preMiddlewares.map((pre) => ({ pre }))); this.withMiddleware<T>(preMiddlewares.map((pre) => ({ pre })));
@ -84,7 +84,7 @@ export class BaseAPI {
withPostMiddleware = <T extends BaseAPI>(postMiddlewares: Array<Middleware['post']>) => withPostMiddleware = <T extends BaseAPI>(postMiddlewares: Array<Middleware['post']>) =>
this.withMiddleware<T>(postMiddlewares.map((post) => ({ post }))); this.withMiddleware<T>(postMiddlewares.map((post) => ({ post })));
protected request = <T>(requestOpts: RequestOpts): Observable<T> => protected request = <T>(requestOpts: RequestOpts): Observable<T> =>
this.rxjsRequest(this.createRequestArgs(requestOpts)).pipe( this.rxjsRequest(this.createRequestArgs(requestOpts)).pipe(
map((res) => { map((res) => {
if (res.status >= 200 && res.status < 300) { if (res.status >= 200 && res.status < 300) {
@ -102,17 +102,17 @@ export class BaseAPI {
// do not handle correctly sometimes. // do not handle correctly sometimes.
url += '?' + queryString(requestOpts.query); url += '?' + queryString(requestOpts.query);
} }
return { return {
url, url,
method: requestOpts.method, method: requestOpts.method,
headers: requestOpts.headers, headers: requestOpts.headers,
body: requestOpts.body instanceof FormData ? requestOpts.body : JSON.stringify(requestOpts.body), body: requestOpts.body instanceof FormData ? requestOpts.body : JSON.stringify(requestOpts.body),
responseType: requestOpts.responseType || 'json' responseType: requestOpts.responseType || 'json',
}; };
} }
private rxjsRequest = (params: RequestArgs): Observable<AjaxResponse> => private rxjsRequest = (params: RequestArgs): Observable<AjaxResponse> =>
of(params).pipe( of(params).pipe(
map((request) => { map((request) => {
this.middleware.filter((item) => item.pre).forEach((mw) => (request = mw.pre!(request))); this.middleware.filter((item) => item.pre).forEach((mw) => (request = mw.pre!(request)));
@ -133,7 +133,7 @@ export class BaseAPI {
* and then shallow cloning data members. * and then shallow cloning data members.
*/ */
private clone = <T extends BaseAPI>(): T => private clone = <T extends BaseAPI>(): T =>
Object.assign(Object.create(Object.getPrototypeOf(this)), this) Object.assign(Object.create(Object.getPrototypeOf(this)), this);
} }
// export for not being a breaking change // export for not being a breaking change
@ -149,7 +149,7 @@ export const COLLECTION_FORMATS = {
}; };
export type Json = any; export type Json = any;
export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'OPTIONS'; export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'OPTIONS' | 'HEAD';
export type HttpHeaders = { [key: string]: string }; export type HttpHeaders = { [key: string]: string };
export type HttpQuery = { [key: string]: string | number | null | boolean | Array<string | number | null | boolean> }; export type HttpQuery = { [key: string]: string | number | null | boolean | Array<string | number | null | boolean> };
export type HttpBody = Json | FormData; export type HttpBody = Json | FormData;
@ -164,7 +164,7 @@ export interface RequestOpts {
responseType?: 'json' | 'blob' | 'arraybuffer' | 'text'; responseType?: 'json' | 'blob' | 'arraybuffer' | 'text';
} }
export const encodeURI = (value: any) => encodeURIComponent(String(value)) export const encodeURI = (value: any) => encodeURIComponent(String(value));
const queryString = (params: HttpQuery): string => Object.keys(params) const queryString = (params: HttpQuery): string => Object.keys(params)
.map((key) => { .map((key) => {
@ -182,7 +182,7 @@ export const throwIfRequired = (params: {[key: string]: any}, key: string, nickn
if (!params || params[key] === null || params[key] === undefined) { if (!params || params[key] === null || params[key] === undefined) {
throw new RequiredError(`Required parameter ${key} was null or undefined when calling ${nickname}.`); throw new RequiredError(`Required parameter ${key} was null or undefined when calling ${nickname}.`);
} }
} };
// alias for easier importing // alias for easier importing
export interface RequestArgs extends AjaxRequest {} export interface RequestArgs extends AjaxRequest {}