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

Add missing ApiQuery decorators for Swagger #1937

Merged
merged 1 commit into from
Sep 20, 2024
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
4 changes: 3 additions & 1 deletion src/routes/balances/balances.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
ParseBoolPipe,
Query,
} from '@nestjs/common';
import { ApiOkResponse, ApiTags } from '@nestjs/swagger';
import { ApiOkResponse, ApiQuery, ApiTags } from '@nestjs/swagger';
import { BalancesService } from '@/routes/balances/balances.service';
import { Balances } from '@/routes/balances/entities/balances.entity';
import { ValidationPipe } from '@/validation/pipes/validation.pipe';
Expand All @@ -21,6 +21,8 @@ export class BalancesController {
constructor(private readonly balancesService: BalancesService) {}

@ApiOkResponse({ type: Balances })
@ApiQuery({ name: 'trusted', required: false, type: Boolean })
@ApiQuery({ name: 'exclude_spam', required: false, type: Boolean })
@Get('chains/:chainId/safes/:safeAddress/balances/:fiatCode')
async getBalances(
@Param('chainId') chainId: string,
Expand Down
2 changes: 2 additions & 0 deletions src/routes/community/community.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ export class CommunityController {
}

@Get('/campaigns/:resourceId/activities')
@ApiQuery({ name: 'cursor', required: false, type: String })
@ApiQuery({ name: 'holder', required: false, type: String })
async getCampaignActivities(
@Param('resourceId') resourceId: string,
@RouteUrlDecorator() routeUrl: URL,
Expand Down
6 changes: 5 additions & 1 deletion src/routes/safes/safes.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ export class SafesController {
return this.service.getNonces({ chainId, safeAddress });
}

@ApiQuery({ name: 'wallet_address', required: false })
@ApiQuery({ name: 'wallet_address', required: false, type: String })
@ApiQuery({ name: 'currency', required: true, type: String })
@ApiQuery({ name: 'safes', required: true, type: String })
@ApiQuery({ name: 'trusted', required: false, type: Boolean })
@ApiQuery({ name: 'exclude_spam', required: false, type: Boolean })
@Get('safes')
async getSafeOverview(
@Query('currency') currency: string,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: When parameters are optional, mark them as optional in the code by appending a question mark (?) to the end of the parameter name. This way, Swagger may automatically recognize the parameter as optional. e.g.

Suggested change
@Query('currency') currency: string,
@Query('currency') currency?: string,

Implementing this requires additional effort and is outside the scope of the current PR.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which parameters are not marked as optional? In this case, currency is required.

Copy link
Contributor

@PooyaRaki PooyaRaki Sep 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@iamacook I have seen some instances, but here for example excludeSpam. It has a default value though.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps we should reconsider usage of the default pipes, and instead assign a default value manually. This would negate the requirement of ApiQuery. I'll merge this for now and we can reconsider this later.

Expand Down
4 changes: 4 additions & 0 deletions src/routes/transactions/transactions.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ export class TransactionsController {
@ApiQuery({ name: 'to', required: false, type: String })
@ApiQuery({ name: 'module', required: false, type: String })
@ApiQuery({ name: 'cursor', required: false, type: String })
@ApiQuery({ name: 'transaction_hash', required: false, type: String })
async getModuleTransactions(
@Param('chainId') chainId: string,
@RouteUrlDecorator() routeUrl: URL,
Expand Down Expand Up @@ -163,6 +164,7 @@ export class TransactionsController {
@ApiQuery({ name: 'value', required: false, type: String })
@ApiQuery({ name: 'token_address', required: false, type: String })
@ApiQuery({ name: 'cursor', required: false, type: String })
@ApiQuery({ name: 'trusted', required: false, type: Boolean })
async getIncomingTransfers(
@Param('chainId') chainId: string,
@RouteUrlDecorator() routeUrl: URL,
Expand Down Expand Up @@ -240,6 +242,8 @@ export class TransactionsController {
})
@ApiQuery({ name: 'cursor', required: false, type: String })
@ApiQuery({ name: 'timezone', required: false, type: String })
@ApiQuery({ name: 'trusted', required: false, type: Boolean })
@ApiQuery({ name: 'imitation', required: false, type: Boolean })
async getTransactionsHistory(
@Param('chainId') chainId: string,
@RouteUrlDecorator() routeUrl: URL,
Expand Down