Skip to content

Commit

Permalink
chore: add Api operation decorator for summary description (#37)
Browse files Browse the repository at this point in the history
# What ❔
- Adds `@ApiOperation` decorator to include summary description of API
method

## Why ❔
- Provides a description of the API call for automated documentation 

<img width="782" alt="Screenshot 2023-10-05 at 8 20 51 AM"
src="https://github.com/matter-labs/block-explorer/assets/29983536/ea461749-ecee-4b1b-b9fb-43d6c8ce74ae">

## Checklist

<!-- Check your PR fulfills the following items. -->
<!-- For draft PRs check the boxes as you complete them. -->

- [x] PR title corresponds to the body of PR (we generate changelog
entries from PRs).
- [x] Tests for the changes have been added / updated.
- [x] Documentation comments have been added / updated.
- [x] Code has been formatted via `zk fmt` and `zk lint`.
  • Loading branch information
dutterbutter authored Oct 5, 2023
1 parent fec8a49 commit da98913
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions packages/api/src/api/api.controller.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Controller, Get, Query, Req, Next, UseFilters } from "@nestjs/common";
import { ApiTags, ApiOkResponse, ApiExcludeEndpoint, ApiQuery, ApiExtraModels } from "@nestjs/swagger";
import { ApiTags, ApiOkResponse, ApiExcludeEndpoint, ApiQuery, ApiExtraModels, ApiOperation } from "@nestjs/swagger";
import { Request, NextFunction } from "express";
import { PagingOptionsWithMaxItemsLimitDto } from "./dtos/common/pagingOptionsWithMaxItemsLimit.dto";
import { ContractAbiResponseDto } from "./dtos/contract/contractAbiResponse.dto";
Expand Down Expand Up @@ -50,6 +50,7 @@ export class ApiController {

@ApiTags("Contract API")
@Get("api?module=contract&action=getabi")
@ApiOperation({ summary: "Fetch the ABI for a given contract address" })
@ApiQuery({
name: "address",
description: "The contract address that has a verified source code",
Expand All @@ -66,6 +67,7 @@ export class ApiController {

@ApiTags("Contract API")
@Get("api?module=contract&action=getsourcecode")
@ApiOperation({ summary: "Fetch the source code for a given contract address" })
@ApiQuery({
name: "address",
description: "The contract address that has a verified source code",
Expand All @@ -82,6 +84,7 @@ export class ApiController {

@ApiTags("Contract API")
@Get("api?module=contract&action=getcontractcreation")
@ApiOperation({ summary: "Fetch creation details for a list of contract addresses" })
@ApiQuery({
isArray: true,
explode: false,
Expand All @@ -92,7 +95,7 @@ export class ApiController {
})
@ApiExtraModels(ContractCreationInfoDto)
@ApiOkResponse({
description: "Contract creation info",
description: "Contract creation information",
type: ContractCreationResponseDto,
})
public async getContractCreation(): Promise<ContractCreationResponseDto> {
Expand All @@ -101,6 +104,7 @@ export class ApiController {

@ApiTags("Transaction API")
@Get("api?module=transaction&action=getstatus")
@ApiOperation({ summary: "Fetch the status for a given transaction hash" })
@ApiQuery({
name: "txhash",
description: "The transaction hash to check the execution status",
Expand All @@ -118,6 +122,7 @@ export class ApiController {

@ApiTags("Transaction API")
@Get("api?module=transaction&action=gettxreceiptstatus")
@ApiOperation({ summary: "Fetch the receipt status for a given transaction hash" })
@ApiQuery({
name: "txhash",
description: "The transaction hash to check the execution status",
Expand All @@ -134,6 +139,7 @@ export class ApiController {

@ApiTags("Account API")
@Get("api?module=account&action=txlist")
@ApiOperation({ summary: "Retrieve transactions for a given address" })
@ApiQuery({
name: "address",
description: "The address to filter transactions by",
Expand Down Expand Up @@ -168,6 +174,7 @@ export class ApiController {

@ApiTags("Account API")
@Get("api?module=account&action=txlistinternal")
@ApiOperation({ summary: "Retrieve internal transactions for a given address or transaction hash" })
@ApiQuery({
name: "address",
description: "The address to filter internal transactions by",
Expand Down Expand Up @@ -208,6 +215,7 @@ export class ApiController {

@ApiTags("Account API")
@Get("api?module=account&action=balance")
@ApiOperation({ summary: "Retrieve the balance for a given address" })
@ApiQuery({
name: "address",
description: "The address to get Ether balance for",
Expand All @@ -224,6 +232,7 @@ export class ApiController {

@ApiTags("Account API")
@Get("api?module=account&action=balancemulti")
@ApiOperation({ summary: "Retrieve the balances for a list of addresses" })
@ApiQuery({
isArray: true,
explode: false,
Expand All @@ -242,6 +251,7 @@ export class ApiController {

@ApiTags("Account API")
@Get("api?module=account&action=tokenbalance")
@ApiOperation({ summary: "Retrieve token balance for a specific address" })
@ApiQuery({
name: "address",
description: "The address to get Token balance for",
Expand All @@ -264,6 +274,7 @@ export class ApiController {

@ApiTags("Account API")
@Get("api?module=account&action=tokentx")
@ApiOperation({ summary: "Retrieve token transfers for a specific address or token contract" })
@ApiQuery({
name: "address",
description: "The address to get transfers for",
Expand Down Expand Up @@ -304,6 +315,7 @@ export class ApiController {

@ApiTags("Account API")
@Get("api?module=account&action=tokennfttx")
@ApiOperation({ summary: "Retrieve NFT transfers for a specific address" })
@ApiQuery({
name: "address",
description: "The address to get transfers for",
Expand Down Expand Up @@ -344,6 +356,7 @@ export class ApiController {

@ApiTags("Block API")
@Get("api?module=block&action=getblocknobytime")
@ApiOperation({ summary: "Retrieve block number closest to a specific timestamp" })
@ApiQuery({
name: "timestamp",
type: "integer",
Expand All @@ -368,6 +381,7 @@ export class ApiController {

@ApiTags("Block API")
@Get("api?module=block&action=getblockcountdown")
@ApiOperation({ summary: "Retrieve countdown details for a specific block number" })
@ApiQuery({
name: "blockno",
type: "integer",
Expand All @@ -385,6 +399,7 @@ export class ApiController {

@ApiTags("Block API")
@Get("api?module=block&action=getblockreward")
@ApiOperation({ summary: "Retrieve block reward details for a specific block number" })
@ApiQuery({
name: "blockno",
type: "integer",
Expand Down

0 comments on commit da98913

Please sign in to comment.