diff --git a/app/src/main/resources/explorer-backend-openapi.json b/app/src/main/resources/explorer-backend-openapi.json index 3a35da07..f3ec44b5 100644 --- a/app/src/main/resources/explorer-backend-openapi.json +++ b/app/src/main/resources/explorer-backend-openapi.json @@ -1366,6 +1366,12 @@ "type" ] }, + "PaginationPageDefault": { + "type": "integer", + "enum": [ + 1 + ] + }, "ValBool": { "type": "object", "title": "ValBool", @@ -1382,6 +1388,13 @@ "type" ] }, + "PaginationLimitMax": { + "type": "integer", + "enum": [ + 100, + 20 + ] + }, "FungibleTokenMetadata": { "type": "object", "title": "FungibleTokenMetadata", @@ -1431,6 +1444,13 @@ "aud" ] }, + "PaginationLimitDefault": { + "type": "integer", + "enum": [ + 20, + 10 + ] + }, "AddressInfo": { "type": "object", "title": "AddressInfo", @@ -1713,7 +1733,7 @@ { "schema": { "format": "int32", - "maximum": "20", + "maximum": "100", "type": "integer", "minimum": "0" }, @@ -1958,7 +1978,7 @@ { "schema": { "format": "int32", - "maximum": "20", + "maximum": "100", "type": "integer", "minimum": "0" }, @@ -2388,7 +2408,7 @@ { "schema": { "format": "int32", - "maximum": "20", + "maximum": "100", "type": "integer", "minimum": "0" }, @@ -2660,7 +2680,7 @@ { "schema": { "format": "int32", - "maximum": "20", + "maximum": "100", "type": "integer", "minimum": "0" }, @@ -3802,7 +3822,7 @@ { "schema": { "format": "int32", - "maximum": "20", + "maximum": "100", "type": "integer", "minimum": "0" }, @@ -4087,7 +4107,7 @@ { "schema": { "format": "int32", - "maximum": "20", + "maximum": "100", "type": "integer", "minimum": "0" }, @@ -4772,7 +4792,7 @@ { "schema": { "format": "int32", - "maximum": "20", + "maximum": "100", "type": "integer", "minimum": "0" }, @@ -5057,7 +5077,7 @@ { "schema": { "format": "int32", - "maximum": "20", + "maximum": "100", "type": "integer", "minimum": "0" }, @@ -5506,7 +5526,7 @@ { "schema": { "format": "int32", - "maximum": "20", + "maximum": "100", "type": "integer", "minimum": "0" }, @@ -6442,7 +6462,7 @@ { "schema": { "format": "int32", - "maximum": "20", + "maximum": "100", "type": "integer", "minimum": "0" }, @@ -6570,7 +6590,7 @@ { "schema": { "format": "int32", - "maximum": "20", + "maximum": "100", "type": "integer", "minimum": "0" }, @@ -7022,7 +7042,7 @@ { "schema": { "format": "int32", - "maximum": "20", + "maximum": "100", "type": "integer", "minimum": "0" }, @@ -7238,7 +7258,7 @@ { "schema": { "format": "int32", - "maximum": "20", + "maximum": "100", "type": "integer", "minimum": "0" }, @@ -7374,7 +7394,7 @@ { "schema": { "format": "int32", - "maximum": "20", + "maximum": "100", "type": "integer", "minimum": "0" }, @@ -7920,7 +7940,7 @@ { "schema": { "format": "int32", - "maximum": "20", + "maximum": "100", "type": "integer", "minimum": "0" }, @@ -8252,7 +8272,7 @@ { "schema": { "format": "int32", - "maximum": "20", + "maximum": "100", "type": "integer", "minimum": "0" }, @@ -8372,7 +8392,7 @@ { "schema": { "format": "int32", - "maximum": "20", + "maximum": "100", "type": "integer", "minimum": "0" }, @@ -9210,7 +9230,7 @@ { "schema": { "format": "int32", - "maximum": "20", + "maximum": "100", "type": "integer", "minimum": "0" }, diff --git a/app/src/main/scala/org/alephium/explorer/api/model/Pagination.scala b/app/src/main/scala/org/alephium/explorer/api/model/Pagination.scala index 6ad88e1e..33d3a98f 100644 --- a/app/src/main/scala/org/alephium/explorer/api/model/Pagination.scala +++ b/app/src/main/scala/org/alephium/explorer/api/model/Pagination.scala @@ -33,9 +33,11 @@ object Pagination { Reversible(page, limit, reverse) } } - val defaultPage: Int = 1 - val defaultLimit: Int = 10 - val maxLimit: Int = 20 + val defaultPage: Int = 1 + val defaultLimit: Int = 20 + val futureDefaultLimit: Int = 10 + val maxLimit: Int = 100 + val futureMaxLimit: Int = 20 def default: Pagination = Pagination(defaultPage, defaultLimit) diff --git a/app/src/main/scala/org/alephium/explorer/docs/Documentation.scala b/app/src/main/scala/org/alephium/explorer/docs/Documentation.scala index 6ebe9867..8b6e5442 100644 --- a/app/src/main/scala/org/alephium/explorer/docs/Documentation.scala +++ b/app/src/main/scala/org/alephium/explorer/docs/Documentation.scala @@ -23,6 +23,7 @@ import sttp.apispec.openapi.OpenAPI import sttp.tapir.docs.openapi.OpenAPIDocsInterpreter import org.alephium.explorer.api._ +import org.alephium.explorer.api.model.Pagination trait Documentation extends BlockEndpoints @@ -105,10 +106,46 @@ trait Documentation ) // Expose some variables to the openAPI file + // scalastyle:off method.length @SuppressWarnings(Array("org.wartremover.warts.OptionPartial")) private def addComponents(openApi: OpenAPI): OpenAPI = openApi.components( openApi.components.get + .addSchema( + "PaginationLimitDefault", + Schema( + `type` = Some(List(SchemaType.Integer)), + `enum` = Some( + List( + ExampleSingleValue(Pagination.defaultLimit), + ExampleSingleValue(Pagination.futureDefaultLimit) + ) + ) + ) + ) + .addSchema( + "PaginationLimitMax", + Schema( + `type` = Some(List(SchemaType.Integer)), + `enum` = Some( + List( + ExampleSingleValue(Pagination.maxLimit), + ExampleSingleValue(Pagination.futureMaxLimit) + ) + ) + ) + ) + .addSchema( + "PaginationPageDefault", + Schema( + `type` = Some(List(SchemaType.Integer)), + `enum` = Some( + List( + ExampleSingleValue(Pagination.defaultPage) + ) + ) + ) + ) .addSchema( "MaxSizeTokens", Schema( diff --git a/app/src/test/scala/org/alephium/explorer/ExplorerSpec.scala b/app/src/test/scala/org/alephium/explorer/ExplorerSpec.scala index d3b9d73f..8b533391 100644 --- a/app/src/test/scala/org/alephium/explorer/ExplorerSpec.scala +++ b/app/src/test/scala/org/alephium/explorer/ExplorerSpec.scala @@ -75,7 +75,7 @@ trait ExplorerSpec val networkId: NetworkId = NetworkId.AlephiumDevNet - val txLimit = 10 + val txLimit = Pagination.defaultLimit val blockflow: ArraySeq[ArraySeq[model.BlockEntry]] = blockFlowGen(maxChainSize = 5, startTimestamp = TimeStamp.now()).sample.get diff --git a/app/src/test/scala/org/alephium/explorer/web/AddressServerSpec.scala b/app/src/test/scala/org/alephium/explorer/web/AddressServerSpec.scala index ff813031..aaa29a15 100644 --- a/app/src/test/scala/org/alephium/explorer/web/AddressServerSpec.scala +++ b/app/src/test/scala/org/alephium/explorer/web/AddressServerSpec.scala @@ -205,7 +205,7 @@ class AddressServerSpec() val routes = server.routes "validate and forward `txLimit` query param" in { - val maxLimit = 20 + val maxLimit = Pagination.maxLimit forAll(addressGen, Gen.chooseNum[Int](-10, 120)) { case (address, txLimit) => Get(s"/addresses/${address}/transactions?limit=$txLimit") check { response => if (txLimit < 0) { @@ -225,7 +225,7 @@ class AddressServerSpec() } Get(s"/addresses/${address}/transactions") check { _ => - testLimit is 10 // default txLimit + testLimit is Pagination.defaultLimit // default txLimit } } }