Skip to content

Commit

Permalink
Merge pull request #236 from Yi-Jacob/task/169-api-docs-body
Browse files Browse the repository at this point in the history
#169 - Updated API Docs to have a request body
  • Loading branch information
thekevinm authored May 20, 2024
2 parents 227eb2b + 47203ea commit c7ff418
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
10 changes: 10 additions & 0 deletions src/app/adf-api-docs/df-api-docs/df-api-docs.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@ export class DfApiDocsComponent implements OnInit, AfterContentInit {
domNode: this.apiDocElement?.nativeElement,
requestInterceptor: (req: SwaggerUI.Request) => {
req['headers'][SESSION_TOKEN_HEADER] = this.userDataService.token;
// Parse the request URL
const url = new URL(req['url']);
const params = new URLSearchParams(url.search);
// Decode all parameters
params.forEach((value, key) => {
params.set(key, decodeURIComponent(value));
});
// Update the URL with decoded parameters
url.search = params.toString();
req['url'] = url.toString();
return req;
},
showMutatedRequest: true,
Expand Down
31 changes: 28 additions & 3 deletions src/app/shared/utilities/case.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,27 @@ export function mapSnakeToCamel<T>(obj: T): T {
}
}

// export const camelToSnakeString = (str: string) =>
// str.replace(/([a-z0-9]|(?=[A-Z]))([A-Z])/g, '$1_$2').toLowerCase();

// export function mapCamelToSnake<T>(obj: T): T {
// if (Array.isArray(obj)) {
// return obj.map(item => mapCamelToSnake(item)) as unknown as T;
// } else if (typeof obj === 'object' && obj !== null) {
// const newObj: Record<string, unknown> = {};
// for (const key in obj) {
// if (Object.prototype.hasOwnProperty.call(obj, key)) {
// newObj[camelToSnakeString(key)] = mapCamelToSnake(
// (obj as Record<string, unknown>)[key]
// );
// }
// }
// return newObj as unknown as T;
// } else {
// return obj;
// }
// }

export const camelToSnakeString = (str: string) =>
str.replace(/([a-z0-9]|(?=[A-Z]))([A-Z])/g, '$1_$2').toLowerCase();

Expand All @@ -29,9 +50,13 @@ export function mapCamelToSnake<T>(obj: T): T {
const newObj: Record<string, unknown> = {};
for (const key in obj) {
if (Object.prototype.hasOwnProperty.call(obj, key)) {
newObj[camelToSnakeString(key)] = mapCamelToSnake(
(obj as Record<string, unknown>)[key]
);
if (key === 'requestBody') {
newObj[key] = (obj as Record<string, unknown>)[key];
} else {
newObj[camelToSnakeString(key)] = mapCamelToSnake(
(obj as Record<string, unknown>)[key]
);
}
}
}
return newObj as unknown as T;
Expand Down

0 comments on commit c7ff418

Please sign in to comment.