mirror of
https://github.com/jdalrymple/gitbeaker.git
synced 2026-01-25 16:04:01 +00:00
feat: Adding the option to conditionally camelize response body
This commit is contained in:
parent
03e85ef171
commit
5f97193dfd
@ -183,6 +183,7 @@ import { Projects } from 'gitlab';
|
||||
const service = new Projects({
|
||||
host: 'http://example.com', // Defaults to https://gitlab.com
|
||||
token: 'abcdefghij123456', // Can be created in your profile.
|
||||
camelize = false, //Response Key Camelize. Camelizes all response body keys. Optional, Default: false
|
||||
});
|
||||
```
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@ interface BaseModelOptions {
|
||||
public readonly url: string;
|
||||
token?: string;
|
||||
oauthToken?: string;
|
||||
useXMLHttpRequest?: boolean;
|
||||
public readonly camelize: boolean;
|
||||
version?: string;
|
||||
sudo?: string | number;
|
||||
rejectUnauthorized?: boolean;
|
||||
@ -29,6 +29,7 @@ class BaseModel {
|
||||
host = 'https://gitlab.com',
|
||||
url = '',
|
||||
version = 'v4',
|
||||
camelize = false,
|
||||
rejectUnauthorized = true,
|
||||
}: BaseModelContructorOptions) {
|
||||
}: BaseServiceOptions) {
|
||||
@ -38,6 +39,7 @@ class BaseModel {
|
||||
? XMLHttpRequester : (Request as temporaryAny as XhrStaticPromisified);
|
||||
this.useXMLHttpRequest = useXMLHttpRequest;
|
||||
this.rejectUnauthorized = rejectUnauthorized;
|
||||
this.camelize = camelize;
|
||||
|
||||
// Handle auth tokens
|
||||
if (oauthToken) this.headers.authorization = `Bearer ${oauthToken}`;
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import Humps from 'humps';
|
||||
import LinkParser from 'parse-link-header';
|
||||
import { camelizeKeys } from 'humps';
|
||||
import QS from 'qs';
|
||||
import URLJoin from 'url-join';
|
||||
import StreamableRequest from 'request';
|
||||
@ -46,8 +46,8 @@ function defaultRequest(
|
||||
|
||||
if (body) params.body = Humps.decamelizeKeys(body);
|
||||
|
||||
if (qs) {
|
||||
if (useXMLHttpRequest) {
|
||||
// Camelize response body if specified
|
||||
if (service.camelize) body = camelizeKeys(body);
|
||||
// The xhr package doesn't have a way of passing in a qs object until v3
|
||||
params.url = URLJoin(params.url, `?${QS.stringify(Humps.decamelizeKeys(qs), { arrayFormat: 'brackets' })}`);
|
||||
} else {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user