Skip to content

Commit

Permalink
fix: apply proper type to each @apiquery decorator in the API contr… (#…
Browse files Browse the repository at this point in the history
…311)

Hi!

The hosted OpenAPI spec that is abstracted from the `@ApiProperty`
decorators using `@nestjs/swagger` is missing certain types. This is
easy to check by simply opening the [OpenAPI
spec](https://block-explorer-api.mainnet.zksync.io/docs-json) and
checking the very first method and it's input parameters.

<img width="790" alt="Screenshot 2024-11-07 at 16 31 07"
src="https://github.com/user-attachments/assets/088623ab-e6f8-40d7-b0a9-a1175488b138">


The schema type the input parameter `address` is set to `{}` - this
causes request client generators like [OpenAPI
generator](https://github.com/OpenAPITools/openapi-generator) to
interpret the parameter as an object, rather than the desired string.

To mitigate this, I simply added the `type` property in every
`@ApiQuery` decorator instance, which should lead to proper output in
the OpenAPI spec.

Let me know if you would like to see any changes here.

Co-authored-by: Vasyl Ivanchuk <[email protected]>
  • Loading branch information
RobbyUitbeijerse and vasyl-ivanchuk authored Nov 11, 2024
1 parent dc26198 commit ad1dc14
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion packages/api/src/api/api.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ export class ApiController {
@ApiOperation({ summary: "Fetch the ABI for a given contract address" })
@ApiQuery({
name: "address",
type: String,
description: "The contract address that has a verified source code",
example: constants.verifiedContractAddress,
required: true,
Expand All @@ -101,6 +102,7 @@ export class ApiController {
@ApiOperation({ summary: "Fetch the source code for a given contract address" })
@ApiQuery({
name: "address",
type: String,
description: "The contract address that has a verified source code",
example: constants.verifiedContractAddress,
required: true,
Expand All @@ -118,6 +120,7 @@ export class ApiController {
@ApiOperation({ summary: "Fetch creation details for a list of contract addresses" })
@ApiQuery({
isArray: true,
type: [String],
explode: false,
name: "contractaddresses",
description: "List of contract addresses, up to 5 at a time",
Expand Down Expand Up @@ -150,6 +153,7 @@ export class ApiController {
@ApiOperation({ summary: "Check source code verification submission status" })
@ApiQuery({
name: "guid",
type: String,
description: "Verification ID",
example: "44071",
required: true,
Expand All @@ -167,6 +171,7 @@ export class ApiController {
@ApiOperation({ summary: "Fetch the status for a given transaction hash" })
@ApiQuery({
name: "txhash",
type: String,
description: "The transaction hash to check the execution status",
example: constants.txHash,
required: true,
Expand All @@ -185,6 +190,7 @@ export class ApiController {
@ApiOperation({ summary: "Fetch the receipt status for a given transaction hash" })
@ApiQuery({
name: "txhash",
type: String,
description: "The transaction hash to check the execution status",
example: constants.txHash,
required: true,
Expand All @@ -202,6 +208,7 @@ export class ApiController {
@ApiOperation({ summary: "Retrieve transactions for a given address" })
@ApiQuery({
name: "address",
type: String,
description: "The address to filter transactions by",
example: constants.address,
required: true,
Expand Down Expand Up @@ -274,6 +281,7 @@ export class ApiController {
})
@ApiQuery({
name: "address",
type: String,
description: "The address to filter internal transactions by",
example: constants.addressWithInternalTx,
required: true,
Expand Down Expand Up @@ -313,6 +321,7 @@ export class ApiController {
})
@ApiQuery({
name: "txhash",
type: String,
description: "The transaction hash to filter internal transaction by",
example: constants.addressTxWithInternalTransfers,
required: true,
Expand Down Expand Up @@ -350,6 +359,7 @@ export class ApiController {
@ApiOperation({ summary: "Retrieve the balance for a given address" })
@ApiQuery({
name: "address",
type: String,
description: "The address to get Ether balance for",
example: constants.address,
required: true,
Expand All @@ -367,6 +377,7 @@ export class ApiController {
@ApiOperation({ summary: "Retrieve the balances for a list of addresses" })
@ApiQuery({
isArray: true,
type: [String],
explode: false,
name: "address",
description: "List of addresses to get Ether balance for",
Expand All @@ -386,12 +397,14 @@ export class ApiController {
@ApiOperation({ summary: "Retrieve token balance for a specific address" })
@ApiQuery({
name: "address",
type: String,
description: "The address to get Token balance for",
example: constants.address,
required: true,
})
@ApiQuery({
name: "contractaddress",
type: String,
description: "The Token contract address to get balance for",
example: constants.erc20TokenAddress,
required: true,
Expand All @@ -409,12 +422,14 @@ export class ApiController {
@ApiOperation({ summary: "Retrieve token transfers for a specific address or token contract" })
@ApiQuery({
name: "address",
type: String,
description: "The address to get transfers for",
example: constants.address,
required: false,
})
@ApiQuery({
name: "contractaddress",
type: String,
description: "The Token contract address to get transfers for",
example: constants.erc20TokenAddress,
required: false,
Expand Down Expand Up @@ -452,12 +467,14 @@ export class ApiController {
@ApiOperation({ summary: "Retrieve NFT transfers for a specific address" })
@ApiQuery({
name: "address",
type: String,
description: "The address to get transfers for",
example: constants.erc721TokenHolderAddress,
required: false,
})
@ApiQuery({
name: "contractaddress",
type: String,
description: "The Token contract address to get transfers for",
example: constants.erc721TokenAddress,
required: false,
Expand Down Expand Up @@ -495,6 +512,7 @@ export class ApiController {
@ApiOperation({ summary: "Get list of Blocks Validated by Address" })
@ApiQuery({
name: "address",
type: String,
description: "The address to get validated blocks by",
example: "0x0000000000000000000000000000000000000000",
required: true,
Expand Down Expand Up @@ -523,7 +541,7 @@ export class ApiController {
})
@ApiQuery({
name: "closest",
type: "string",
type: String,
description: "The closest available block to the provided timestamp, either before or after",
example: "before",
required: false,
Expand Down Expand Up @@ -577,6 +595,7 @@ export class ApiController {
@ApiOperation({ summary: "Retrieve the event logs for an address, with optional filtering by block range" })
@ApiQuery({
name: "address",
type: String,
description: "The address to filter logs by",
example: constants.contractAddressWithLogs,
required: true,
Expand Down Expand Up @@ -615,6 +634,7 @@ export class ApiController {
})
@ApiQuery({
name: "contractaddress",
type: String,
description: "The contract address of the ERC-20/ERC-721 token to retrieve token info",
example: constants.tokenAddress,
required: true,
Expand Down

0 comments on commit ad1dc14

Please sign in to comment.