From 0a8c06c782156dd417cc693eb97725461eb3e9bd Mon Sep 17 00:00:00 2001 From: alphaeusmote <41258468-alphaeusmote@users.noreply.replit.com> Date: Wed, 9 Apr 2025 14:44:02 +0000 Subject: [PATCH] Update API response structure to include pagination metadata. Replit-Commit-Author: Agent Replit-Commit-Session-Id: 705f2157-ef97-4fbd-89e4-8c7f2ecaea90 Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/7ed01c5f-a82d-405a-b728-b2e3d127c60c/c818a471-e356-4d5e-8f68-50e8c07bc1d5.jpg --- server/query-parser.ts | 12 ++++++------ server/swagger.ts | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 6 deletions(-) diff --git a/server/query-parser.ts b/server/query-parser.ts index 5524d74..1ffd551 100644 --- a/server/query-parser.ts +++ b/server/query-parser.ts @@ -269,7 +269,7 @@ export function generatePaginationMetadata( // If no pagination params were specified if (limit === undefined) { return { - pagination: { + metadata: { totalRecords, currentPage: 1, totalPages: 1, @@ -284,7 +284,7 @@ export function generatePaginationMetadata( const totalPages = Math.ceil(totalRecords / limit); // Prepare pagination metadata - const pagination = { + const metadata = { totalRecords, currentPage, totalPages, @@ -305,7 +305,7 @@ export function generatePaginationMetadata( const nextUrl = new URL(url.pathname, url.origin); nextUrl.search = params.toString(); - pagination.nextPage = nextUrl.toString(); + metadata.nextPage = nextUrl.toString(); } // Previous page @@ -316,11 +316,11 @@ export function generatePaginationMetadata( const prevUrl = new URL(url.pathname, url.origin); prevUrl.search = params.toString(); - pagination.previousPage = prevUrl.toString(); + metadata.previousPage = prevUrl.toString(); } } - return { pagination }; + return { metadata }; } /** @@ -419,7 +419,7 @@ The response will include pagination metadata with the following structure: \`\`\`json { "data": [...], // The actual records - "pagination": { + "metadata": { "totalRecords": 100, // Total number of records "currentPage": 3, // Current page number (1-based) "totalPages": 10, // Total number of pages diff --git a/server/swagger.ts b/server/swagger.ts index 7cd66db..c361aef 100644 --- a/server/swagger.ts +++ b/server/swagger.ts @@ -106,6 +106,7 @@ const swaggerOptions = { lastLogon: { type: "string", format: "date-time" }, memberOf: { type: "array", items: { type: "string" } }, adProperties: { type: "object" }, + objectType: { type: "string", enum: ["user"] }, }, }, AdGroup: { @@ -122,6 +123,7 @@ const swaggerOptions = { description: { type: "string" }, members: { type: "array", items: { type: "string" } }, adProperties: { type: "object" }, + objectType: { type: "string", enum: ["group"] }, }, }, AdOrgUnit: { @@ -136,6 +138,7 @@ const swaggerOptions = { name: { type: "string" }, description: { type: "string" }, adProperties: { type: "object" }, + objectType: { type: "string", enum: ["organizationalUnit"] }, }, }, AdComputer: { @@ -154,6 +157,7 @@ const swaggerOptions = { lastLogon: { type: "string", format: "date-time" }, enabled: { type: "boolean" }, adProperties: { type: "object" }, + objectType: { type: "string", enum: ["computer"] }, }, }, AdDomain: { @@ -170,6 +174,7 @@ const swaggerOptions = { forestName: { type: "string" }, domainFunctionality: { type: "string" }, adProperties: { type: "object" }, + objectType: { type: "string", enum: ["domain"] }, }, }, LdapAttribute: { @@ -312,6 +317,34 @@ const swaggerOptions = { }, }, }, + PaginatedResponse: { + description: "Successful response with pagination metadata", + content: { + "application/json": { + schema: { + type: "object", + properties: { + data: { + type: "array", + items: { + type: "object" + } + }, + metadata: { + type: "object", + properties: { + currentPage: { type: "integer" }, + totalPages: { type: "integer" }, + totalRecords: { type: "integer" }, + nextPage: { type: "string", nullable: true }, + previousPage: { type: "string", nullable: true } + } + } + } + } + } + } + } }, }, security: [