Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#169 - Updated API Docs to have a request body #236

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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