Skip to content

Commit

Permalink
fix: required field marks in Swagger annotations
Browse files Browse the repository at this point in the history
In the previous version `required` and `nullable` annotations in
`@ApiProperty` decorators were not accurate. Required fields frequently
had `nullable` declarations and vice versa. It created difficulties for
maintainers of external services that use Keys API under the hood
because it was not possible to understand all the details of Keys API
endpoint interfaces by just looking at the Swagger.

Now all annotations are brought into compliance with actual endpoint
interfaces that Keys API uses internally.
  • Loading branch information
AlexanderLukin committed Apr 10, 2024
1 parent e43b486 commit 0a3119e
Show file tree
Hide file tree
Showing 25 changed files with 128 additions and 64 deletions.
2 changes: 1 addition & 1 deletion src/app/simple-dvt-deploy.e2e-chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ describe('Simple DVT deploy', () => {
session = await sdk.env.hardhat({
fork: forkUrl,
chainId: 1,
forkBlockNumber: 19282216
forkBlockNumber: 19282216,
});

moduleRef = await Test.createTestingModule({ imports: [AppModule] })
Expand Down
1 change: 1 addition & 0 deletions src/http/common/entities/cl-meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { ApiProperty } from '@nestjs/swagger';
export class CLMeta {
@ApiProperty({
type: () => CLBlockSnapshot,
required: true,
description: 'Consensus layer block information',
})
clBlockSnapshot!: CLBlockSnapshot;
Expand Down
1 change: 1 addition & 0 deletions src/http/common/entities/el-meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { ELBlockSnapshot } from './el-block-snapshot';
export class ELMeta {
@ApiProperty({
type: () => ELBlockSnapshot,
required: true,
description: 'Execution layer block information',
})
elBlockSnapshot!: ELBlockSnapshot;
Expand Down
32 changes: 26 additions & 6 deletions src/http/common/entities/operator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,51 @@ export class Operator implements Omit<RegistryOperator, 'finalizedUsedSigningKey
}

@ApiProperty({
required: true,
description: 'Index of Operator',
})
index: number;

@ApiProperty({
required: true,
description: 'This value shows if node operator active',
})
active: boolean;

@ApiProperty({ description: 'Operator name' })
@ApiProperty({
required: true,
description: 'Operator name',
})
name: string;

@ApiProperty({ description: 'Ethereum 1 address which receives stETH rewards for this operator' })
@ApiProperty({
required: true,
description: 'Ethereum 1 address which receives stETH rewards for this operator',
})
rewardAddress: string;

@ApiProperty({ description: 'The number of keys vetted by the DAO and that can be used for the deposit' })
@ApiProperty({
required: true,
description: 'The number of keys vetted by the DAO and that can be used for the deposit',
})
stakingLimit: number;

@ApiProperty({ description: 'Amount of stopped validators' })
@ApiProperty({
required: true,
description: 'Amount of stopped validators',
})
stoppedValidators: number;

@ApiProperty({ description: 'Total signing keys amount' })
@ApiProperty({
required: true,
description: 'Total signing keys amount',
})
totalSigningKeys: number;

@ApiProperty({ description: 'Amount of used signing keys' })
@ApiProperty({
required: true,
description: 'Amount of used signing keys',
})
usedSigningKeys: number;

@ApiProperty({
Expand Down
16 changes: 14 additions & 2 deletions src/http/common/entities/sr-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,69 +21,81 @@ export class StakingModuleResponse implements Omit<SrModuleEntity, 'id' | 'modul
}

@ApiProperty({
required: true,
description:
"Counter that MUST change value if keys were added, removed, node operator was activated/deactivated, a node operator's ready to deposit keys count is changed",
"Counter that MUST change value if keys were added, removed, node operator was activated/deactivated, a node operator's ready to deposit keys count is changed",
})
nonce: number;

@ApiProperty({
required: true,
description: 'Type of module',
})
type: string; //STAKING_MODULE_TYPE;

@ApiProperty({
required: true,
description: 'Unique id of the module',
})
id: number;

@ApiProperty({
required: true,
description: 'Address of module',
})
stakingModuleAddress: string;

@ApiProperty({
required: true,
description: 'Reward fee of the module',
})
moduleFee: number;

@ApiProperty({
required: true,
description: 'Treasury fee',
})
treasuryFee: number;

@ApiProperty({
required: true,
description: 'Target percent of total keys in protocol, in BP',
})
targetShare: number;

@ApiProperty({
required: true,
description:
'Module status if module can not accept the deposits or can participate in further reward distribution',
})
status: number;

@ApiProperty({
required: true,
description: 'Name of module',
})
name: string;

@ApiProperty({
required: true,
description: 'block.timestamp of the last deposit of the module',
})
lastDepositAt: number;

@ApiProperty({
required: true,
description: 'block.number of the last deposit of the module',
nullable: true,
})
lastDepositBlock: number;

@ApiProperty({
required: true,
description: 'Exited validators count',
})
exitedValidatorsCount: number;

@ApiProperty({
required: true,
description: 'Module activation status',
})
active: boolean;
Expand Down
2 changes: 1 addition & 1 deletion src/http/keys/entities/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from './response';
export * from './keys.response';
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import { ELMeta, Key } from '../../common/entities';
export class KeyListResponse {
@ApiProperty({
type: () => [Key],
required: true,
description: 'List of keys for all modules',
})
data!: Key[];

@ApiProperty({
type: () => ELMeta,
nullable: true,
required: true,
description: 'Meta',
})
meta!: ELMeta;
Expand Down
2 changes: 1 addition & 1 deletion src/http/keys/keys.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export class KeysController {
})
@ApiResponse({
status: HttpStatus.OK,
description: 'Staking Router module keys.',
description: 'Staking Router module keys',
type: KeyListResponse,
})
@ApiOperation({ summary: 'Get list of found keys in DB from pubkey list' })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,32 @@ import { Key, StakingModuleResponse, ELMeta } from '../../common/entities/';

export class KeyListWithModule {
@ApiProperty({
description: 'Keys of staking router module',
type: () => [Key],
required: true,
description: 'Keys of staking router module',
})
keys!: Key[];

@ApiProperty({
description: 'Detailed Staking Router information',
type: () => StakingModuleResponse,
required: true,
description: 'Detailed Staking Router information',
})
module!: StakingModuleResponse;
}

export class GroupedByModuleKeyListResponse {
@ApiProperty({
description: 'Keys for all modules grouped by staking router module',
type: () => [KeyListWithModule],
required: true,
description: 'Keys for all modules grouped by staking router module',
})
data!: KeyListWithModule[];

@ApiProperty({
nullable: true,
type: () => ELMeta,
required: true,
description: 'Meta',
})
meta!: ELMeta;
}
11 changes: 7 additions & 4 deletions src/http/sr-modules-keys/entities/sr-module-keys.response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,31 @@ import { StakingModuleResponse, Key, ELMeta } from '../../common/entities/';
export class SRKeyListWithModule {
@ApiProperty({
type: () => [Key],
required: true,
description: 'Keys of staking router module',
})
keys!: Key[];

@ApiProperty({
description: 'Detailed Staking Router information',
type: () => StakingModuleResponse,
required: true,
description: 'Detailed Staking Router information',
})
module!: StakingModuleResponse;
}

export class SRModuleKeyListResponse {
@ApiProperty({
description: 'Staking router module keys.',
nullable: true,
type: () => SRKeyListWithModule,
required: true,
description: 'Staking router module keys',
})
data!: SRKeyListWithModule;

@ApiProperty({
nullable: true,
type: () => ELMeta,
required: true,
description: 'Meta',
})
meta!: ELMeta;
}
12 changes: 6 additions & 6 deletions src/http/sr-modules-keys/sr-modules-keys.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export class SRModulesKeysController {
) {}

@Version('1')
@ApiOperation({ summary: 'Get keys for all modules grouped by staking router module.' })
@ApiOperation({ summary: 'Get keys for all modules grouped by staking router module' })
@ApiResponse({
status: 200,
description:
Expand All @@ -54,7 +54,7 @@ export class SRModulesKeysController {
}

@Version('1')
@ApiOperation({ summary: 'Staking router module keys.' })
@ApiOperation({ summary: 'Staking router module keys' })
@ApiResponse({
status: 200,
description: 'List of all modules supported in API',
Expand All @@ -73,7 +73,7 @@ export class SRModulesKeysController {
@ApiParam({
name: 'module_id',
type: String,
description: 'Staking router module_id or contract address.',
description: 'Staking router module_id or contract address',
})
@Get(':module_id/keys')
async getModuleKeys(
Expand Down Expand Up @@ -118,10 +118,10 @@ export class SRModulesKeysController {
@Version('1')
@Post(':module_id/keys/find')
@HttpCode(HttpStatus.OK)
@ApiOperation({ summary: 'Get list of found staking router module keys in db from pubkey list.' })
@ApiOperation({ summary: 'Get list of found staking router module keys in db from pubkey list' })
@ApiResponse({
status: 200,
description: 'Staking Router module keys.',
description: 'Staking Router module keys',
type: SRModuleKeyListResponse,
})
@ApiResponse({
Expand All @@ -137,7 +137,7 @@ export class SRModulesKeysController {
@ApiParam({
name: 'module_id',
type: String,
description: 'Staking router module_id or contract address.',
description: 'Staking router module_id or contract address',
})
getModuleKeysByPubkeys(@Param('module_id', ModuleIdPipe) module_id: string | number, @Body() keys: KeysFindBody) {
return this.srModulesKeysService.getModuleKeysByPubKeys(module_id, keys.pubkeys);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,60 +4,68 @@ import { Key, Operator, StakingModuleResponse, ELMeta } from '../../common/entit
export class SROperatorsKeysModule {
@ApiProperty({
type: () => [Operator],
required: true,
description: 'Operators of staking router module',
})
operators!: Operator[];

@ApiProperty({
type: () => [Key],
required: true,
description: 'Keys of staking router module',
})
keys!: Key[];

@ApiProperty({
description: 'Detailed Staking Router information',
type: () => StakingModuleResponse,
required: true,
description: 'Detailed Staking Router information',
})
module!: StakingModuleResponse;
}

export class SRModuleOperatorsKeysResponse {
@ApiProperty({
description: 'Staking router module keys.',
nullable: true,
type: () => SROperatorsKeysModule,
required: true,
description: 'Staking router module keys',
})
data!: SROperatorsKeysModule;

@ApiProperty({
nullable: true,
type: () => ELMeta,
required: true,
description: 'Meta',
})
meta!: ELMeta;
}

export class SRModulesOperatorsKeysStreamResponse {
@ApiProperty({
type: () => Operator,
nullable: true,
description: 'Operator of staking router module',
})
operator!: Operator | null;

@ApiProperty({
type: () => Key,
nullable: true,
description: 'Key of staking router module',
})
key!: Key | null;

@ApiProperty({
type: () => StakingModuleResponse,
nullable: true,
description: 'Staking Router module',
})
stakingModule!: StakingModuleResponse | null;

@ApiProperty({
nullable: true,
type: () => ELMeta,
nullable: true,
description: 'Meta',
})
meta!: ELMeta | null;
}
Loading

0 comments on commit 0a3119e

Please sign in to comment.