Skip to content

Commit

Permalink
Merge pull request #304 from virtualeconomy/riemann_swagger_fix
Browse files Browse the repository at this point in the history
Riemann swagger Fix
  • Loading branch information
ncying authored Oct 26, 2021
2 parents e8719a5 + 39c1208 commit 9bccb90
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 12 deletions.
9 changes: 8 additions & 1 deletion src/main/scala/vsys/api/http/TransactionsApiRoute.scala
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ case class TransactionsApiRoute(
@Path("/count")
@ApiOperation(value = "Count",
notes = "Get count of transactions where specified address (wallet address or contract address) has been involved. *This is a custom api, you need to enable it in configuration file.*",
httpMethod = "GET")
httpMethod = "GET",
response = classOf[Int])
@ApiImplicitParams(Array(
new ApiImplicitParam(name = "address", value = "Wallet address or contract address", required = true, dataType = "string", paramType = "query"),
new ApiImplicitParam(name = "txType", value = "Transaction type", required = false, dataType = "integer", paramType = "query")
Expand Down Expand Up @@ -86,6 +87,9 @@ case class TransactionsApiRoute(
@ApiOperation(value = "List",
notes = "Get list of transactions where specified address (wallet address or contract address) has been involved. *This is a custom api, you need to enable it in configuration file.*",
httpMethod = "GET")
@ApiResponses(Array(
new ApiResponse(code = 200, message = "Json response with a list of transactions or error")
))
@ApiImplicitParams(Array(
new ApiImplicitParam(name = "address", value = "Wallet address or contract address", required = true, dataType = "string", paramType = "query"),
new ApiImplicitParam(name = "txType", value = "Transaction type", required = false, dataType = "integer", paramType = "query"),
Expand Down Expand Up @@ -130,6 +134,9 @@ case class TransactionsApiRoute(

@Path("/address/{address}/limit/{limit}")
@ApiOperation(value = "Address", notes = "Get list of transactions where specified address (wallet address or contract address) has been involved", httpMethod = "GET")
@ApiResponses(Array(
new ApiResponse(code = 200, message = "Json response with a list of transactions or error")
))
@ApiImplicitParams(Array(
new ApiImplicitParam(name = "address", value = "Wallet address or contract address", required = true, dataType = "string", paramType = "path"),
new ApiImplicitParam(name = "limit", value = "Specified number of records to be returned", required = true, dataType = "integer", paramType = "path")
Expand Down
12 changes: 8 additions & 4 deletions src/main/scala/vsys/api/http/contract/ContractApiRoute.scala
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ case class ContractApiRoute (settings: RestAPISettings,

@Path("/lastTokenIndex/{contractId}")
@ApiOperation(value = "Last Token Index", notes = "Token contract last token index", httpMethod = "Get")
@ApiResponses(Array(
new ApiResponse(code = 200, message = "Json response with Last Token Index or error")
))
@ApiImplicitParams(Array(
new ApiImplicitParam(name = "contractId", value = "Contract ID", required = true, dataType = "string", paramType = "path")
))
Expand All @@ -86,10 +89,7 @@ case class ContractApiRoute (settings: RestAPISettings,
if (lastTokenIndex == -1) {
complete(CustomValidationError("No token generated in this contract"))
} else {
complete(Json.obj(
"contractId" -> contractId,
"lastTokenIndex" -> lastTokenIndex
))
complete(TokenIndex(contractId, lastTokenIndex))
}
}
case _ => complete(InvalidContractAddress)
Expand Down Expand Up @@ -343,4 +343,8 @@ object ContractApiRoute {

implicit val balanceFormat: Format[Balance] = Json.format

case class TokenIndex(contractId: String, lastTokenIndex: Int)

implicit val tokenIndexFormat: Format[TokenIndex] = Json.format

}
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ case class SposConsensusApiRoute(
}

@Path("/allSlotsInfo")
@ApiOperation(value = "Get all slots' info", notes = "Get all slots' information", httpMethod = "GET")
@ApiResponses(Array(
new ApiResponse(code = 200, message = "Json response of all slots details or error")
))
Expand Down
9 changes: 2 additions & 7 deletions src/main/scala/vsys/api/http/swagger/SwaggerDocService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import com.github.swagger.akka.SwaggerHttpService
import vsys.Version
import vsys.settings.RestAPISettings
import io.swagger.util.{Json, Yaml}
import io.swagger.models.{Swagger, Scheme, Path}
import io.swagger.models.{Path, Scheme, Swagger}
import io.swagger.models.auth.{ApiKeyAuthDefinition, In}
import vsys.utils.ScorexLogging
import scala.collection.immutable.Map

import scala.collection.immutable.Map
import scala.util.control.NonFatal
import scala.collection.JavaConverters._

Expand Down Expand Up @@ -59,11 +59,6 @@ class SwaggerDocService(val actorSystem: ActorSystem, val materializer: ActorMat
val filteredPaths: Map[String, Path] = swagger.getPaths().asScala.toMap.filterKeys(cumstomPathsConfig.getOrElse(_, true))
swagger.addSecurityDefinition("api_key", new ApiKeyAuthDefinition("api_key", In.HEADER))
swagger.paths(collection.mutable.Map(filteredPaths.toSeq: _*).asJava)
val unwantedDefinitions: Seq[String] = Seq("Function1", "Function1RequestContextFutureRouteResult")
if (unwantedDefinitions.nonEmpty) {
swagger.setDefinitions(swagger.getDefinitions.asScala.filterKeys(definitionName => !unwantedDefinitions.contains(definitionName)).asJava)
}
swagger
}

//Let swagger-ui determine the host and port
Expand Down

0 comments on commit 9bccb90

Please sign in to comment.