Skip to content

Commit 3e53b5a

Browse files
Merge pull request #726 from prayas17/feat-Generate-Variables-Collection-Page
feat: generate variables in collection page
2 parents fc749a7 + bb960f9 commit 3e53b5a

File tree

3 files changed

+656
-2
lines changed

3 files changed

+656
-2
lines changed

src/modules/workspace/controllers/collection.controller.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1601,6 +1601,36 @@ export class collectionController {
16011601
return res.status(responseData.httpStatusCode).send(responseData);
16021602
}
16031603

1604+
/**
1605+
* Endpoint to Generate the Variables of whole Collection using AI.
1606+
*/
1607+
@Post("generate-variables/:collectionId")
1608+
@ApiOperation({
1609+
summary: "Generate Variables",
1610+
description:
1611+
"This will Generate Variables for the Collection using AI",
1612+
})
1613+
@UseGuards(JwtAuthGuard)
1614+
@ApiResponse({ status: 200, description: "Variables Generated Successfully" })
1615+
@ApiResponse({ status: 400, description: "Failed to Generate Variables" })
1616+
async generateVariables(
1617+
@Param("collectionId") collectionId: string,
1618+
@Body() collectionDto: Partial<CollectionRequestDto>,
1619+
@Res() res: FastifyReply,
1620+
@Req() request: ExtendedFastifyRequest,
1621+
) {
1622+
const user = request?.user;
1623+
const workspaceId = collectionDto?.workspaceId
1624+
const collectionVariables = await this.collectionRequestService.generateVariables(
1625+
collectionId,
1626+
workspaceId,
1627+
user
1628+
);
1629+
const responseData = new ApiResponseService(
1630+
"Success",
1631+
HttpStatusCode.OK,
1632+
collectionVariables);
1633+
};
16041634
/**
16051635
* Endpoint to update all the New generated Variables in requests.
16061636
*

src/modules/workspace/payloads/collectionRequest.payload.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ import {
3232
Auth,
3333
KeyValue,
3434
} from "@src/modules/common/models/collection.rxdb.model";
35+
import { IsObject } from 'class-validator';
36+
3537
import { VariableDto } from "@src/modules/common/models/environment.model";
3638

3739
// eslint-disable-next-line @typescript-eslint/no-unused-vars
@@ -921,6 +923,36 @@ export class UpdateMockResponseRatioDto {
921923
mockResponseRatios: MockResponseRatioDto[];
922924
}
923925

926+
export class GeneratedVariablesDto {
927+
@ApiProperty({
928+
example: { '{{url_var1}}': 'https://example.com/api' },
929+
description: 'Key-value pairs of URL variables'
930+
})
931+
@IsObject()
932+
url: Record<string, string>;
933+
934+
@ApiProperty({
935+
example: { '{{body_var1}}': 'someValue' },
936+
description: 'Key-value pairs of body variables'
937+
})
938+
@IsObject()
939+
body: Record<string, string>;
940+
941+
@ApiProperty({
942+
example: { '{{query_var1}}': 'someQueryValue' },
943+
description: 'Key-value pairs of query parameters'
944+
})
945+
@IsObject()
946+
query: Record<string, string>;
947+
948+
@ApiProperty({
949+
example: { '{{headers_var1}}': 'someHeadersValue' },
950+
description: 'Key-value pairs of headers parameters'
951+
})
952+
@IsObject()
953+
headers: Record<string, string>;
954+
}
955+
924956
export class CollectionGeneratedVariableDto {
925957
@ApiProperty({ example: "6538e910aa77d958912371f5" })
926958
@IsString()

0 commit comments

Comments
 (0)