Skip to content

Commit

Permalink
[typescript-rxjs] support HEAD method, improve formatting (#3766)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
denyo authored and macjohnny committed Aug 27, 2019
1 parent d0d545b commit 5bd6307
Show file tree
Hide file tree
Showing 18 changed files with 126 additions and 126 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ export class {{classname}} extends BaseAPI {
responseType: 'blob'
{{/isResponseFile}}
});
}
};

{{/operation}}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,15 @@ export class BaseAPI {
const next = this.clone<T>();
next.middleware = next.middleware.concat(middlewares);
return next;
}
};

withPreMiddleware = <T extends BaseAPI>(preMiddlewares: Array<Middleware['pre']>) =>
this.withMiddleware<T>(preMiddlewares.map((pre) => ({ pre })));

withPostMiddleware = <T extends BaseAPI>(postMiddlewares: Array<Middleware['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(
map((res) => {
if (res.status >= 200 && res.status < 300) {
Expand All @@ -91,17 +91,17 @@ export class BaseAPI {
// do not handle correctly sometimes.
url += '?' + queryString(requestOpts.query);
}

return {
url,
method: requestOpts.method,
headers: requestOpts.headers,
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(
map((request) => {
this.middleware.filter((item) => item.pre).forEach((mw) => (request = mw.pre!(request)));
Expand All @@ -122,7 +122,7 @@ export class BaseAPI {
* and then shallow cloning data members.
*/
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
Expand All @@ -138,7 +138,7 @@ export const COLLECTION_FORMATS = {
};

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 HttpQuery = { [key: string]: string | number | null | boolean | Array<string | number | null | boolean> };
export type HttpBody = Json | FormData;
Expand All @@ -153,7 +153,7 @@ export interface RequestOpts {
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)
.map((key) => {
Expand All @@ -171,7 +171,7 @@ export const throwIfRequired = (params: {[key: string]: any}, key: string, nickn
if (!params || params[key] === null || params[key] === undefined) {
throw new RequiredError(`Required parameter ${key} was null or undefined when calling ${nickname}.`);
}
}
};

// alias for easier importing
export interface RequestArgs extends AjaxRequest {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export class PetApi extends BaseAPI {
headers,
body: requestParameters.body,
});
}
};

/**
* Deletes a pet
Expand All @@ -105,7 +105,7 @@ export class PetApi extends BaseAPI {
method: 'DELETE',
headers,
});
}
};

/**
* Multiple status values can be provided with comma separated strings
Expand Down Expand Up @@ -133,7 +133,7 @@ export class PetApi extends BaseAPI {
headers,
query,
});
}
};

/**
* Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
Expand Down Expand Up @@ -161,7 +161,7 @@ export class PetApi extends BaseAPI {
headers,
query,
});
}
};

/**
* Returns a single pet
Expand All @@ -179,7 +179,7 @@ export class PetApi extends BaseAPI {
method: 'GET',
headers,
});
}
};

/**
* Update an existing pet
Expand All @@ -203,7 +203,7 @@ export class PetApi extends BaseAPI {
headers,
body: requestParameters.body,
});
}
};

/**
* Updates a pet in the store with form data
Expand Down Expand Up @@ -235,7 +235,7 @@ export class PetApi extends BaseAPI {
headers,
body: formData,
});
}
};

/**
* uploads an image
Expand Down Expand Up @@ -267,7 +267,7 @@ export class PetApi extends BaseAPI {
headers,
body: formData,
});
}
};

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class StoreApi extends BaseAPI {
path: '/store/order/{orderId}'.replace('{orderId}', encodeURI(requestParameters.orderId)),
method: 'DELETE',
});
}
};

/**
* Returns a map of status codes to quantities
Expand All @@ -61,7 +61,7 @@ export class StoreApi extends BaseAPI {
method: 'GET',
headers,
});
}
};

/**
* For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions
Expand All @@ -74,7 +74,7 @@ export class StoreApi extends BaseAPI {
path: '/store/order/{orderId}'.replace('{orderId}', encodeURI(requestParameters.orderId)),
method: 'GET',
});
}
};

/**
* Place an order for a pet
Expand All @@ -92,6 +92,6 @@ export class StoreApi extends BaseAPI {
headers,
body: requestParameters.body,
});
}
};

}
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export class UserApi extends BaseAPI {
headers,
body: requestParameters.body,
});
}
};

/**
* Creates list of users with given input array
Expand All @@ -87,7 +87,7 @@ export class UserApi extends BaseAPI {
headers,
body: requestParameters.body,
});
}
};

/**
* Creates list of users with given input array
Expand All @@ -105,7 +105,7 @@ export class UserApi extends BaseAPI {
headers,
body: requestParameters.body,
});
}
};

/**
* This can only be done by the logged in user.
Expand All @@ -118,7 +118,7 @@ export class UserApi extends BaseAPI {
path: '/user/{username}'.replace('{username}', encodeURI(requestParameters.username)),
method: 'DELETE',
});
}
};

/**
* Get user by user name
Expand All @@ -130,7 +130,7 @@ export class UserApi extends BaseAPI {
path: '/user/{username}'.replace('{username}', encodeURI(requestParameters.username)),
method: 'GET',
});
}
};

/**
* Logs user into the system
Expand All @@ -149,7 +149,7 @@ export class UserApi extends BaseAPI {
method: 'GET',
query,
});
}
};

/**
* Logs out current logged in user session
Expand All @@ -159,7 +159,7 @@ export class UserApi extends BaseAPI {
path: '/user/logout',
method: 'GET',
});
}
};

/**
* This can only be done by the logged in user.
Expand All @@ -179,6 +179,6 @@ export class UserApi extends BaseAPI {
headers,
body: requestParameters.body,
});
}
};

}
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,15 @@ export class BaseAPI {
const next = this.clone<T>();
next.middleware = next.middleware.concat(middlewares);
return next;
}
};

withPreMiddleware = <T extends BaseAPI>(preMiddlewares: Array<Middleware['pre']>) =>
this.withMiddleware<T>(preMiddlewares.map((pre) => ({ pre })));

withPostMiddleware = <T extends BaseAPI>(postMiddlewares: Array<Middleware['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(
map((res) => {
if (res.status >= 200 && res.status < 300) {
Expand All @@ -102,17 +102,17 @@ export class BaseAPI {
// do not handle correctly sometimes.
url += '?' + queryString(requestOpts.query);
}

return {
url,
method: requestOpts.method,
headers: requestOpts.headers,
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(
map((request) => {
this.middleware.filter((item) => item.pre).forEach((mw) => (request = mw.pre!(request)));
Expand All @@ -133,7 +133,7 @@ export class BaseAPI {
* and then shallow cloning data members.
*/
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
Expand All @@ -149,7 +149,7 @@ export const COLLECTION_FORMATS = {
};

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 HttpQuery = { [key: string]: string | number | null | boolean | Array<string | number | null | boolean> };
export type HttpBody = Json | FormData;
Expand All @@ -164,7 +164,7 @@ export interface RequestOpts {
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)
.map((key) => {
Expand All @@ -182,7 +182,7 @@ export const throwIfRequired = (params: {[key: string]: any}, key: string, nickn
if (!params || params[key] === null || params[key] === undefined) {
throw new RequiredError(`Required parameter ${key} was null or undefined when calling ${nickname}.`);
}
}
};

// alias for easier importing
export interface RequestArgs extends AjaxRequest {}
Expand Down
Loading

0 comments on commit 5bd6307

Please sign in to comment.