-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(api): integrate OpenAPI client generator for frontend
- Add OpenAPI CLI generator dependency for TypeScript-Axios library - Implement resource entity fetching with generated client - Update DTO types in NestJS server - Add client library generation instructions to README
- Loading branch information
jimmypalelil
committed
Jan 29, 2025
1 parent
d8de089
commit 96491f2
Showing
24 changed files
with
2,958 additions
and
242 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
37 changes: 37 additions & 0 deletions
37
backend/src/recreation-resource/dto/paginated-recreation-resouce.dto.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { PaginatedRecreationResourceDto } from "./paginated-recreation-resouce.dto"; | ||
import { RecreationResourceDto } from "./recreation-resource.dto"; | ||
|
||
const recResourceArrayResolved: RecreationResourceDto[] = [ | ||
new RecreationResourceDto(), | ||
new RecreationResourceDto(), | ||
new RecreationResourceDto(), | ||
new RecreationResourceDto(), | ||
]; | ||
|
||
describe("PaginatedRecreationResourceDto", () => { | ||
it("should validate the structure of paginated response", () => { | ||
const paginatedResponse = new PaginatedRecreationResourceDto(); | ||
paginatedResponse.data = recResourceArrayResolved; | ||
paginatedResponse.total = 4; | ||
paginatedResponse.page = 1; | ||
paginatedResponse.limit = 10; | ||
|
||
expect(paginatedResponse).toHaveProperty("data"); | ||
expect(paginatedResponse).toHaveProperty("total"); | ||
expect(paginatedResponse).toHaveProperty("page"); | ||
expect(Array.isArray(paginatedResponse.data)).toBe(true); | ||
expect(typeof paginatedResponse.total).toBe("number"); | ||
expect(typeof paginatedResponse.page).toBe("number"); | ||
}); | ||
|
||
it("should handle empty data array", () => { | ||
const emptyPaginatedResponse = new PaginatedRecreationResourceDto(); | ||
emptyPaginatedResponse.data = []; | ||
emptyPaginatedResponse.total = 0; | ||
emptyPaginatedResponse.page = 1; | ||
emptyPaginatedResponse.limit = 10; | ||
|
||
expect(emptyPaginatedResponse.data).toHaveLength(0); | ||
expect(emptyPaginatedResponse.total).toBe(0); | ||
}); | ||
}); |
16 changes: 16 additions & 0 deletions
16
backend/src/recreation-resource/dto/paginated-recreation-resouce.dto.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { ApiProperty } from "@nestjs/swagger"; | ||
import { RecreationResourceDto } from "./recreation-resource.dto"; | ||
|
||
export class PaginatedRecreationResourceDto { | ||
@ApiProperty({ type: [RecreationResourceDto] }) | ||
data: RecreationResourceDto[]; | ||
|
||
@ApiProperty() | ||
total: number; | ||
|
||
@ApiProperty() | ||
page: number; | ||
|
||
@ApiProperty() | ||
limit: number; | ||
} |
87 changes: 87 additions & 0 deletions
87
backend/src/recreation-resource/dto/recreation-resource.dto.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import { | ||
RecreationActivityDto, | ||
RecreationStatusDto, | ||
RecreationResourceDto, | ||
} from "./recreation-resource.dto"; | ||
|
||
describe("Recreation DTOs", () => { | ||
describe("RecreationActivityDto", () => { | ||
it("should create a valid RecreationActivityDto instance", () => { | ||
const activity = new RecreationActivityDto(); | ||
activity.recreation_activity_code = "HIKING"; | ||
activity.description = "Hiking trails available for all skill levels"; | ||
|
||
expect(activity instanceof RecreationActivityDto).toBeTruthy(); | ||
expect(activity.recreation_activity_code).toBeDefined(); | ||
expect(activity.description).toBeDefined(); | ||
}); | ||
}); | ||
|
||
describe("RecreationStatusDto", () => { | ||
it("should create a valid RecreationStatusDto", () => { | ||
const status = new RecreationStatusDto(); | ||
status.status_code = "CLOSED"; | ||
status.comment = "Temporary closure due to weather conditions"; | ||
status.description = "The facility is currently closed to visitors"; | ||
|
||
expect(status.status_code).toBeDefined(); | ||
expect(status.description).toBeDefined(); | ||
}); | ||
|
||
it("should allow null comment", () => { | ||
const status: RecreationStatusDto = { | ||
status_code: "OPEN", | ||
comment: null, | ||
description: "The facility is open", | ||
}; | ||
|
||
expect(status.comment).toBeNull(); | ||
}); | ||
}); | ||
|
||
describe("RecreationResourceDto", () => { | ||
it("should create a valid RecreationResourceDto", () => { | ||
const resource: RecreationResourceDto = { | ||
rec_resource_id: "rec-123-abc", | ||
name: "Evergreen Valley Campground", | ||
description: | ||
"A scenic campground nestled in the heart of Evergreen Valley", | ||
site_location: "123 Forest Road, Mountain View, CA 94043", | ||
recreation_activity: [ | ||
{ | ||
recreation_activity_code: "HIKING", | ||
description: "Hiking trails available for all skill levels", | ||
}, | ||
], | ||
recreation_status: { | ||
status_code: "OPEN", | ||
comment: null, | ||
description: "The facility is open", | ||
}, | ||
}; | ||
|
||
expect(resource.rec_resource_id).toBeDefined(); | ||
expect(resource.name.length).toBeGreaterThanOrEqual(1); | ||
expect(resource.name.length).toBeLessThanOrEqual(100); | ||
expect(Array.isArray(resource.recreation_activity)).toBeTruthy(); | ||
expect(resource.recreation_status).toBeDefined(); | ||
}); | ||
|
||
it("should allow null description", () => { | ||
const resource: RecreationResourceDto = { | ||
rec_resource_id: "rec-123-abc", | ||
name: "Test Resource", | ||
description: null, | ||
site_location: "Test Location", | ||
recreation_activity: [], | ||
recreation_status: { | ||
status_code: "OPEN", | ||
comment: null, | ||
description: "Open", | ||
}, | ||
}; | ||
|
||
expect(resource.description).toBeNull(); | ||
}); | ||
}); | ||
}); |
67 changes: 52 additions & 15 deletions
67
backend/src/recreation-resource/dto/recreation-resource.dto.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,77 @@ | ||
import { ApiProperty } from "@nestjs/swagger"; | ||
|
||
export class RecreationActivityDto { | ||
@ApiProperty({ | ||
description: "Unique code identifying the recreation activity", | ||
example: "HIKING", | ||
}) | ||
recreation_activity_code: string; | ||
|
||
@ApiProperty({ | ||
description: "Detailed description of the activity", | ||
example: "Hiking trails available for all skill levels", | ||
}) | ||
description: string; | ||
} | ||
|
||
export class RecreationStatusDto { | ||
@ApiProperty({ | ||
description: "Status code of the resource", | ||
}) | ||
status_code: string; | ||
|
||
@ApiProperty({ | ||
description: "Additional status information", | ||
example: "Temporary closure due to weather conditions", | ||
nullable: true, | ||
}) | ||
comment: string; | ||
|
||
@ApiProperty({ | ||
description: "Detailed status description", | ||
example: "The facility is currently closed to visitors", | ||
}) | ||
description: string; | ||
} | ||
|
||
export class RecreationResourceDto { | ||
@ApiProperty({ | ||
description: "The ID of the Recreation Resource", | ||
description: "Unique identifier of the Recreation Resource", | ||
example: "rec-123-abc", | ||
format: "uuid", | ||
}) | ||
rec_resource_id: string; | ||
|
||
@ApiProperty({ | ||
description: "The name of the Recreation Resource", | ||
description: "Official name of the Recreation Resource", | ||
example: "Evergreen Valley Campground", | ||
minLength: 1, | ||
maxLength: 100, | ||
}) | ||
name: string; | ||
|
||
@ApiProperty({ | ||
description: "The description of the Recreation Resource", | ||
description: "Detailed description of the Recreation Resource", | ||
example: "A scenic campground nestled in the heart of Evergreen Valley", | ||
nullable: true, | ||
}) | ||
description: string; | ||
|
||
@ApiProperty({ | ||
description: "The location of the Recreation Resource", | ||
description: "Physical location of the Recreation Resource", | ||
example: "123 Forest Road, Mountain View, CA 94043", | ||
}) | ||
site_location: string; | ||
|
||
@ApiProperty({ | ||
description: "The list of available activities at the Recreation Resource", | ||
description: "List of recreational activities available at this resource", | ||
type: [RecreationActivityDto], | ||
}) | ||
recreation_activity: { | ||
recreation_activity_code: string; | ||
description: string; | ||
}[]; | ||
recreation_activity: RecreationActivityDto[]; | ||
|
||
@ApiProperty({ | ||
description: "The status of the Recreation Resource", | ||
description: "Current operational status of the Recreation Resource", | ||
type: RecreationStatusDto, | ||
}) | ||
recreation_status: { | ||
status_code: string; | ||
comment: string; | ||
description: string; | ||
}; | ||
recreation_status: RecreationStatusDto; | ||
} |
Oops, something went wrong.