Skip to content

Commit

Permalink
Fix Swagger definitions (#2008)
Browse files Browse the repository at this point in the history
Fixes some issues in the Swagger schema:

- All nullable values are defined in `ApiOptionalProperty` decorators, flagged as `nullable` with the correct `type`
- All array-expected values leverage the `isArray` property instead of TypeScript annotations
  • Loading branch information
iamacook authored Oct 11, 2024
1 parent dd1cfb0 commit c61ff00
Show file tree
Hide file tree
Showing 24 changed files with 80 additions and 35 deletions.
6 changes: 3 additions & 3 deletions src/routes/chains/entities/backbone.entity.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { Backbone as DomainBackbone } from '@/domain/backbone/entities/backbone.entity';
import { ApiProperty } from '@nestjs/swagger';
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';

export class Backbone implements DomainBackbone {
@ApiProperty()
api_version!: string;
@ApiProperty()
@ApiPropertyOptional({ type: String, nullable: true })
headers!: string[] | null;
@ApiProperty()
host!: string;
@ApiProperty()
name!: string;
@ApiProperty()
secure!: boolean;
@ApiProperty()
@ApiProperty({ type: Object, nullable: true })
settings!: Record<string, unknown> | null;
@ApiProperty()
version!: string;
Expand Down
2 changes: 1 addition & 1 deletion src/routes/chains/entities/chain-page.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ import { Chain } from '@/routes/chains/entities/chain.entity';
import { Page } from '@/routes/common/entities/page.entity';

export class ChainPage extends Page<Chain> {
@ApiProperty({ type: Chain })
@ApiProperty({ type: Chain, isArray: true })
results!: Chain[];
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ import { CampaignActivity } from '@/routes/community/entities/campaign-activity.
import { ApiProperty } from '@nestjs/swagger';

export class CampaignActivityPage extends Page<CampaignActivity> {
@ApiProperty({ type: [CampaignActivity] })
@ApiProperty({ type: CampaignActivity, isArray: true })
results!: Array<CampaignActivity>;
}
6 changes: 5 additions & 1 deletion src/routes/community/entities/campaign.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ export class Campaign implements DomainCampaign {
endDate!: Date;
@ApiPropertyOptional({ type: String, nullable: true })
lastUpdated!: Date | null;
@ApiPropertyOptional({ type: [ActivityMetadata], nullable: true })
@ApiPropertyOptional({
type: ActivityMetadata,
isArray: true,
nullable: true,
})
activitiesMetadata!: ActivityMetadata[] | null;
@ApiPropertyOptional({ type: String, nullable: true })
rewardValue!: string | null;
Expand Down
2 changes: 1 addition & 1 deletion src/routes/community/entities/campaign.page.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ import { Campaign } from '@/routes/community/entities/campaign.entity';
import { ApiProperty } from '@nestjs/swagger';

export class CampaignPage extends Page<Campaign> {
@ApiProperty({ type: [Campaign] })
@ApiProperty({ type: Campaign, isArray: true })
results!: Array<Campaign>;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { DataDecodedParameter as DomainDataDecodedParameter } from '@/domain/data-decoder/entities/data-decoded.entity';
import { ApiProperty } from '@nestjs/swagger';
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';

export class DataDecodedParameter implements DomainDataDecodedParameter {
@ApiProperty()
Expand All @@ -8,7 +8,10 @@ export class DataDecodedParameter implements DomainDataDecodedParameter {
type: string;
@ApiProperty()
value: Required<unknown>;
@ApiProperty()
@ApiPropertyOptional({
oneOf: [{ type: 'object' }, { type: 'array', items: { type: 'object' } }],
nullable: true,
})
valueDecoded: Record<string, unknown> | Record<string, unknown>[] | null;

constructor(
Expand Down
6 changes: 5 additions & 1 deletion src/routes/data-decode/entities/data-decoded.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ import { DataDecoded as DomainDataDecoded } from '@/domain/data-decoder/entities
export class DataDecoded implements DomainDataDecoded {
@ApiProperty()
method: string;
@ApiPropertyOptional({ type: [DataDecodedParameter], nullable: true })
@ApiPropertyOptional({
type: DataDecodedParameter,
isArray: true,
nullable: true,
})
parameters: DataDecodedParameter[] | null;

constructor(method: string, parameters: DataDecodedParameter[] | null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { z } from 'zod';
export class CreateDelegateDto
implements z.infer<typeof CreateDelegateDtoSchema>
{
@ApiPropertyOptional()
@ApiPropertyOptional({ type: String, nullable: true })
safe!: `0x${string}` | null;
@ApiProperty()
delegate!: `0x${string}`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import { z } from 'zod';
export class DeleteDelegateV2Dto
implements z.infer<typeof DeleteDelegateV2DtoSchema>
{
@ApiPropertyOptional()
@ApiPropertyOptional({ type: String, nullable: true })
delegator!: `0x${string}` | null;
@ApiPropertyOptional()
@ApiPropertyOptional({ type: String, nullable: true })
safe!: `0x${string}` | null;
@ApiProperty()
signature!: string;
Expand Down
2 changes: 1 addition & 1 deletion src/routes/safe-apps/entities/safe-app.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export class SafeApp {
url: string;
@ApiProperty()
name: string;
@ApiProperty()
@ApiPropertyOptional({ type: String, nullable: true })
iconUrl: string | null;
@ApiProperty()
description: string;
Expand Down
8 changes: 4 additions & 4 deletions src/routes/safes/entities/safe-info.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ export class SafeState {
readonly version: string | null;
@ApiProperty({ enum: Object.values(MasterCopyVersionState) })
readonly implementationVersionState: MasterCopyVersionState;
@ApiProperty()
@ApiPropertyOptional({ type: String, nullable: true })
readonly collectiblesTag: string | null;
@ApiProperty()
@ApiPropertyOptional({ type: String, nullable: true })
readonly txQueuedTag: string | null;
@ApiProperty()
@ApiPropertyOptional({ type: String, nullable: true })
readonly txHistoryTag: string | null;
@ApiProperty()
@ApiPropertyOptional({ type: String, nullable: true })
readonly messagesTag: string | null;

constructor(
Expand Down
4 changes: 2 additions & 2 deletions src/routes/safes/entities/safe-overview.entity.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AddressInfo } from '@/routes/common/entities/address-info.entity';
import { ApiProperty } from '@nestjs/swagger';
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';

export class SafeOverview {
@ApiProperty()
Expand All @@ -14,7 +14,7 @@ export class SafeOverview {
readonly fiatTotal: string;
@ApiProperty()
readonly queued: number;
@ApiProperty()
@ApiPropertyOptional({ type: Number, nullable: true })
readonly awaitingConfirmation: number | null;

constructor(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ export class BaselineConfirmationView implements Baseline {
@ApiProperty()
method: string;

@ApiPropertyOptional({ type: [DataDecodedParameter], nullable: true })
@ApiPropertyOptional({
type: DataDecodedParameter,
isArray: true,
nullable: true,
})
parameters: DataDecodedParameter[] | null;

constructor(args: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export class CustomTransactionInfo extends TransactionInfo {
to: AddressInfo;
@ApiProperty()
dataSize: string;
@ApiProperty()
@ApiPropertyOptional({ type: String, nullable: true })
value: string | null;
@ApiProperty()
isCancellation: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
export class SettingsChangeTransaction extends TransactionInfo {
@ApiProperty()
dataDecoded: DataDecoded;
@ApiPropertyOptional()
@ApiPropertyOptional({ type: SettingsChange, nullable: true })
settingsInfo: SettingsChange | null;

constructor(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ export class NativeStakingDepositConfirmationView
@ApiProperty()
method: string;

@ApiPropertyOptional({ type: [DataDecodedParameter], nullable: true })
@ApiPropertyOptional({
type: DataDecodedParameter,
isArray: true,
nullable: true,
})
parameters: DataDecodedParameter[] | null;

@ApiProperty()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
TransactionInfo,
TransactionInfoType,
} from '@/routes/transactions/entities/transaction-info.entity';
import { ApiProperty } from '@nestjs/swagger';
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';

export type NativeStakingDepositInfo = StakingTimeInfo & StakingFinancialInfo;

Expand Down Expand Up @@ -61,7 +61,10 @@ export class NativeStakingDepositTransactionInfo
@ApiProperty()
tokenInfo: TokenInfo;

@ApiProperty({
@ApiPropertyOptional({
type: String,
isArray: true,
nullable: true,
description: 'Populated after transaction has been executed',
})
validators: Array<`0x${string}`> | null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ export class NativeStakingValidatorsExitConfirmationView implements Baseline {
@ApiProperty()
method: string;

@ApiPropertyOptional({ type: [DataDecodedParameter], nullable: true })
@ApiPropertyOptional({
type: DataDecodedParameter,
isArray: true,
nullable: true,
})
parameters: DataDecodedParameter[] | null;

@ApiProperty()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ export class NativeStakingWithdrawConfirmationView implements Baseline {
@ApiProperty()
method: string;

@ApiPropertyOptional({ type: [DataDecodedParameter], nullable: true })
@ApiPropertyOptional({
type: DataDecodedParameter,
isArray: true,
nullable: true,
})
parameters: DataDecodedParameter[] | null;

@ApiProperty()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ export class CowSwapConfirmationView implements Baseline, OrderInfo {
@ApiProperty()
method: string;

@ApiPropertyOptional({ type: [DataDecodedParameter], nullable: true })
@ApiPropertyOptional({
type: DataDecodedParameter,
isArray: true,
nullable: true,
})
parameters: DataDecodedParameter[] | null;

// OrderInfo implementation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ export class CowSwapTwapConfirmationView implements Baseline, TwapOrderInfo {
@ApiProperty()
method: string;

@ApiPropertyOptional({ type: [DataDecodedParameter], nullable: true })
@ApiPropertyOptional({
type: DataDecodedParameter,
isArray: true,
nullable: true,
})
parameters: DataDecodedParameter[] | null;

// TwapOrderInfo implementation
Expand Down Expand Up @@ -62,20 +66,23 @@ export class CowSwapTwapConfirmationView implements Baseline, TwapOrderInfo {
buyAmount: string;

@ApiPropertyOptional({
type: String,
nullable: true,
description:
'The executed sell token raw amount (no decimals), or null if there are too many parts',
})
executedSellAmount: string | null;

@ApiPropertyOptional({
type: String,
nullable: true,
description:
'The executed surplus fee raw amount (no decimals), or null if there are too many parts',
})
executedSurplusFee: string | null;

@ApiPropertyOptional({
type: String,
nullable: true,
description:
'The executed buy token raw amount (no decimals), or null if there are too many parts',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ export class TwapOrderTransactionInfo
@ApiPropertyOptional({ enum: OrderClass })
class: OrderClass.Limit;

@ApiProperty({
@ApiPropertyOptional({
type: String,
nullable: true,
description: 'The order UID of the active order, or null if none is active',
})
Expand All @@ -95,20 +96,23 @@ export class TwapOrderTransactionInfo
buyAmount: string;

@ApiPropertyOptional({
type: String,
nullable: true,
description:
'The executed sell token raw amount (no decimals), or null if there are too many parts',
})
executedSellAmount: string | null;

@ApiPropertyOptional({
type: String,
nullable: true,
description:
'The executed buy token raw amount (no decimals), or null if there are too many parts',
})
executedBuyAmount: string | null;

@ApiPropertyOptional({
type: String,
nullable: true,
description:
'The executed surplus fee raw amount (no decimals), or null if there are too many parts',
Expand Down
4 changes: 2 additions & 2 deletions src/routes/transactions/entities/transaction.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ import { NativeStakingWithdrawTransactionInfo } from '@/routes/transactions/enti
export class Transaction {
@ApiProperty()
id: string;
@ApiProperty()
@ApiPropertyOptional({ type: String, nullable: true })
txHash: `0x${string}` | null;
@ApiProperty()
@ApiPropertyOptional({ type: Number, nullable: true })
timestamp: number | null;
@ApiProperty()
txStatus: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { ApiProperty } from '@nestjs/swagger';
import { ApiPropertyOptional } from '@nestjs/swagger';
import {
Transfer,
TransferType,
} from '@/routes/transactions/entities/transfers/transfer.entity';

export class NativeCoinTransfer extends Transfer {
@ApiProperty()
@ApiPropertyOptional({ type: String, nullable: true })
value: string | null;

constructor(value: string | null) {
Expand Down

0 comments on commit c61ff00

Please sign in to comment.