From e2a232eda6dfa24a1054aaf3093c023bb1d50986 Mon Sep 17 00:00:00 2001 From: Yi-Jacob Date: Sat, 18 May 2024 18:27:03 -0500 Subject: [PATCH 1/3] #169 - Updated API Docs to have a request body --- src/app/shared/utilities/case.ts | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/src/app/shared/utilities/case.ts b/src/app/shared/utilities/case.ts index eb99a8b5..f6cbb4f4 100644 --- a/src/app/shared/utilities/case.ts +++ b/src/app/shared/utilities/case.ts @@ -19,6 +19,27 @@ export function mapSnakeToCamel(obj: T): T { } } +// export const camelToSnakeString = (str: string) => +// str.replace(/([a-z0-9]|(?=[A-Z]))([A-Z])/g, '$1_$2').toLowerCase(); + +// export function mapCamelToSnake(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 = {}; +// for (const key in obj) { +// if (Object.prototype.hasOwnProperty.call(obj, key)) { +// newObj[camelToSnakeString(key)] = mapCamelToSnake( +// (obj as Record)[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(); @@ -29,9 +50,13 @@ export function mapCamelToSnake(obj: T): T { const newObj: Record = {}; for (const key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { - newObj[camelToSnakeString(key)] = mapCamelToSnake( - (obj as Record)[key] - ); + if (key === 'requestBody') { + newObj[key] = (obj as Record)[key]; + } else { + newObj[camelToSnakeString(key)] = mapCamelToSnake( + (obj as Record)[key] + ); + } } } return newObj as unknown as T; From 4b733610985abe235c754bc7a6e69a2003e9cbc4 Mon Sep 17 00:00:00 2001 From: Yi-Jacob Date: Sat, 18 May 2024 18:42:11 -0500 Subject: [PATCH 2/3] decode url params --- .../adf-api-docs/df-api-docs/df-api-docs.component.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/app/adf-api-docs/df-api-docs/df-api-docs.component.ts b/src/app/adf-api-docs/df-api-docs/df-api-docs.component.ts index f9ebe5e8..c7f0eea5 100644 --- a/src/app/adf-api-docs/df-api-docs/df-api-docs.component.ts +++ b/src/app/adf-api-docs/df-api-docs/df-api-docs.component.ts @@ -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; + const url = new URL(req['url']); + const params = new URLSearchParams(url.search); + if (params.has('fields')) { + params.set( + 'fields', + decodeURIComponent(params.get('fields')?.toString() || '') + ); + url.search = params.toString(); + req['url'] = url.toString(); + } return req; }, showMutatedRequest: true, From 47203ea41f20ad3d533b78d2b7bacf8211126eb2 Mon Sep 17 00:00:00 2001 From: Yi-Jacob Date: Sat, 18 May 2024 18:43:48 -0500 Subject: [PATCH 3/3] decode url params --- .../df-api-docs/df-api-docs.component.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/app/adf-api-docs/df-api-docs/df-api-docs.component.ts b/src/app/adf-api-docs/df-api-docs/df-api-docs.component.ts index c7f0eea5..e063080b 100644 --- a/src/app/adf-api-docs/df-api-docs/df-api-docs.component.ts +++ b/src/app/adf-api-docs/df-api-docs/df-api-docs.component.ts @@ -53,16 +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); - if (params.has('fields')) { - params.set( - 'fields', - decodeURIComponent(params.get('fields')?.toString() || '') - ); - url.search = params.toString(); - req['url'] = url.toString(); - } + // 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,