Skip to content
This repository has been archived by the owner on Apr 13, 2022. It is now read-only.

Swagger api #140

Merged
merged 32 commits into from
Jan 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
054b8fb
update api like in swagger document
Tolsi Nov 24, 2017
024e4fa
peers api like in swagger docs
Tolsi Nov 24, 2017
713f848
compilation fix
Tolsi Nov 25, 2017
612b22f
correct http codes on errors
Tolsi Nov 27, 2017
9fec150
codes moved to error objects
Tolsi Nov 27, 2017
d88812f
missed type
Tolsi Nov 27, 2017
81cb8d4
default apiKeyHash is empty
Tolsi Nov 27, 2017
05a1ccb
Merge branch 'master' into swagger-api
Tolsi Dec 11, 2017
9cfafda
Utils functions was updated
Tolsi Dec 11, 2017
04f2127
akka http circe dependency was added
Tolsi Dec 19, 2017
3637fdb
post request
Tolsi Dec 19, 2017
8fdbab1
Merge branch 'master' into swagger-api
Tolsi Dec 19, 2017
df9f3db
compilation fix
Tolsi Dec 19, 2017
ba3e3f6
npe fix
Tolsi Dec 19, 2017
434275e
Merge branch 'master' of github.com:ScorexFoundation/Scorex into swag…
catena2w Dec 20, 2017
5aa0444
Provide locally created yaml file for swagger
catena2w Dec 20, 2017
5059062
Correct yaml for HybridApp
catena2w Dec 20, 2017
1aa80b0
swaggerYaml => swaggerConfig
catena2w Dec 20, 2017
603e4f1
Remove annotations
catena2w Dec 20, 2017
ec9a2e6
New swagger
catena2w Dec 20, 2017
3b60395
Remove servers from swagger config
catena2w Dec 21, 2017
62b2a65
SettingsReaders to read files as case classes
catena2w Dec 21, 2017
5379653
SettingsReaders in HybridSettings
catena2w Dec 21, 2017
29d8205
Move take() from MemoryPool to MempoolReader
catena2w Dec 21, 2017
28972ab
Merge branch 'master' into swagger-api
Tolsi Dec 25, 2017
8fc4d79
fix failing build
terjokhin Dec 27, 2017
9c41b1f
Merge branch 'master' of github.com:ScorexFoundation/Scorex into swag…
catena2w Jan 6, 2018
674d12c
Fix declared address comparison when it is None
catena2w Jan 6, 2018
1244675
fix /peers/connect API
catena2w Jan 8, 2018
d1f0458
Add NodeView route to testApi.yaml
catena2w Jan 8, 2018
2c3620d
added tests for utils and peers routes
terjokhin Jan 8, 2018
93d4307
Merge branch 'master' into swagger-api
kushti Jan 11, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ val circeVersion = "0.8.0"

val networkDependencies = Seq(
"com.typesafe.akka" %% "akka-actor" % "2.4.+",
"com.typesafe.akka" % "akka-stream_2.12" % "2.4.+",
"org.bitlet" % "weupnp" % "0.1.+",
"commons-net" % "commons-net" % "3.+"
)
Expand All @@ -53,9 +54,8 @@ val apiDependencies = Seq(
"io.circe" %% "circe-core" % circeVersion,
"io.circe" %% "circe-generic" % circeVersion,
"io.circe" %% "circe-parser" % circeVersion,
"io.swagger" %% "swagger-scala-module" % "1.0.3",
"com.github.swagger-akka-http" %% "swagger-akka-http" % "0.10.0",
"com.typesafe.akka" %% "akka-http" % "10.+"
"com.typesafe.akka" %% "akka-http" % "10.+",
"de.heikoseeberger" %% "akka-http-circe" % "1.18.0"
)

val loggingDependencies = Seq(
Expand All @@ -65,6 +65,7 @@ val loggingDependencies = Seq(

val testingDependencies = Seq(
"com.typesafe.akka" %% "akka-testkit" % "2.5.3" % "test",
"com.typesafe.akka" %% "akka-http-testkit" % "10.+" % "test",
"org.scalactic" %% "scalactic" % "3.0.3" % "test",
"org.scalatest" %% "scalatest" % "3.0.3" % "test",
"org.scalacheck" %% "scalacheck" % "1.13.+",
Expand Down
251 changes: 251 additions & 0 deletions examples/src/main/resources/api/testApi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,251 @@
openapi: "3.0.0"

info:
version: "0.1"
title: Scorex Node API example
description: API docs for example Scorex project.
contact:
name: Scorex framework Team
email: kushi@protonmail.com
url: https://github.com/scorexfoundation/scorex
license:
name: CC0 1.0 Universal
url: https://raw.githubusercontent.com/ScorexFoundation/Scorex/master/COPYING

components:
schemas:
# Objects
ModifierId:
description: Base58-encoded 32 byte modifier id
type: object
required:
- modifierId
properties:
modifierId:
type: string
example: D2bXMwWN8P9nWJ9qqwZJLauAdcZHX9n6s91QQ9vK6Zu4

Digest32:
description: Base58-encoded 32 byte digest
type: object
required:
- digest
properties:
digest:
type: string
example: FjX5cPuwMc2ocDLPWzt6jq29BXjvU6d5w5XURDJ6dmoM
Peer:
type: object
required:
- address
properties:
address:
type: string
example: 127.0.0.1:5673
name:
type: string
example: mynode
nonce:
type: integer
# int32
format: int64
example: 123456
lastSeen:
type: integer
# int32
format: int64
example: 123456


paths:

/nodeView/openSurface:
get:
summary: Get history open surface
operationId: getOpenSurface
tags:
- nodeView
responses:
200:
description: Array of modifier ids
content:
application/json:
schema:
type: array
example: ["D2bXMwWN8P9nWJ9qqwZJLauAdcZHX9n6s91QQ9vK6Zu4"]
items:
type: string
example: D2bXMwWN8P9nWJ9qqwZJLauAdcZHX9n6s91QQ9vK6Zu4

/nodeView/persistentModifier/{modifierId}:
get:
summary: Get history open surface
operationId: getPersistentModifierById
tags:
- nodeView
parameters:
- in: path
name: modifierId
required: true
description: ID of a requested modifier
schema:
type: string
responses:
200:
description: Node view modifier
content:
application/json:
schema:
type: object
required:
- id

/nodeView/pool:
get:
summary: Get memory pool
operationId: getPool
tags:
- nodeView
responses:
200:
description: Memory pool
content:
application/json:
schema:
type: object
required:
- size
- transactions

/peers/all:
get:
summary: Get all known peers
operationId: getAllPeers
tags:
- peers
responses:
200:
description: Array of peer objects
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/Peer'

/peers/connected:
get:
summary: Get current connected peers
operationId: getConnectedPeers
tags:
- peers
responses:
200:
description: Array of peer objects
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/Peer'

/peers/connect:
post:
summary: Add address to peers list
operationId: connectToPeer
tags:
- peers
requestBody:
required: true
content:
application/json:
schema:
type: string
example: 127.0.0.1:5673
responses:
200:
description: Attempt to connect to the peer
default:
description: Error
content:
application/json:
schema:
type: string
enum:
- invalid.peer.address
- invalid.json

/peers/blacklisted:
get:
summary: Get blacklisted peers
operationId: getBlacklistedPeers
tags:
- peers
responses:
200:
description: Array of peer objects
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/Peer'

/utils/seed:
get:
summary: Get random seed with 32 bytes size
operationId: getRandomSeed
tags:
- utils
responses:
200:
description: Base58-encoded 32 byte seed
content:
text/plain:
schema:
type: string
example: 7yaASMijGEGTbttYHg1MrXnWB8EbzjJnFLSWvmNoHrXV

/utils/seed/{length}:
get:
summary: Generate random seed of specified length in bytes
operationId: getRandomSeedWithLength
tags:
- utils
parameters:
- in: path
name: length
required: true
description: seed length in bytes
schema:
type: string
responses:
200:
description: Base58-encoded N byte seed
content:
text/plain:
schema:
type: string
example: 7yaASMijGEGTbttYHg1MrXnWB8EbzjJnFLSWvmNoHrXV

/utils/hash/blake2b:
post:
summary: Return Blake2b hash of specified message
operationId: hashBlake2b
tags:
- utils
requestBody:
required: true
content:
text/plain:
schema:
type: string
example: 7yaASMijGEGTbttYHg1MrXnWB8EbzjJnFLSWvmNoHrXV
responses:
200:
description: Base58-encoded 32 byte hash
content:
text/plain:
schema:
type: string
example: 6QLZkR1RdHvF7gUw7oms1XdQM6kc9kxpmyHRADN5x7uQ
3 changes: 2 additions & 1 deletion examples/src/main/scala/examples/curvepos/SimpleApp.scala
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ class SimpleApp(val settingsFilename: String) extends Application {
actorSystem.actorOf(Props(new NodeViewSynchronizer[P, TX, SimpleSyncInfo, SimpleSyncInfoMessageSpec.type, PMOD, SimpleBlockchain, SimpleMemPool]
(networkController, nodeViewHolderRef, localInterface, SimpleSyncInfoMessageSpec, settings.network)))

override val apiTypes: Set[Class[_]] = Set(classOf[UtilsApiRoute], classOf[NodeViewApiRoute[P, TX]])
override val swaggerConfig = ""

override val apiRoutes: Seq[ApiRoute] = Seq(UtilsApiRoute(settings.restApi),
NodeViewApiRoute[P, TX](settings.restApi, nodeViewHolderRef))
}
Expand Down
4 changes: 2 additions & 2 deletions examples/src/main/scala/examples/hybrid/HybridApp.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import scorex.core.settings.ScorexSettings
import scorex.core.transaction.box.proposition.PublicKey25519Proposition

import scala.concurrent.duration._
import scala.io.Source
import scala.language.postfixOps

class HybridApp(val settingsFilename: String) extends Application {
Expand Down Expand Up @@ -43,8 +44,7 @@ class HybridApp(val settingsFilename: String) extends Application {
PeersApiRoute(peerManagerRef, networkController, settings.restApi)
)

override val apiTypes: Set[Class[_]] = Set(classOf[UtilsApiRoute], classOf[DebugApiRoute], classOf[WalletApiRoute],
classOf[NodeViewApiRoute[P, TX]], classOf[PeersApiRoute], classOf[StatsApiRoute])
override val swaggerConfig: String = Source.fromResource("api/testApi.yaml").getLines.mkString("\n")

val miner = actorSystem.actorOf(Props(new PowMiner(nodeViewHolderRef, hybridSettings.mining)))
val forger = actorSystem.actorOf(Props(new PosForger(hybridSettings, nodeViewHolderRef)))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package examples.hybrid.api.http

import javax.ws.rs.Path

import akka.actor.{ActorRef, ActorRefFactory}
import akka.http.scaladsl.server.Route
import examples.commons.SimpleBoxTransactionMemPool
Expand All @@ -10,10 +8,9 @@ import examples.hybrid.history.HybridHistory
import examples.hybrid.state.HBoxStoredState
import examples.hybrid.wallet.HWallet
import io.circe.syntax._
import io.swagger.annotations._
import scorex.core.ModifierId
import scorex.core.api.http.{ApiRouteWithFullView, SuccessApiResponse}
import scorex.core.settings.{RESTApiSettings, ScorexSettings}
import scorex.core.settings.RESTApiSettings
import scorex.crypto.encode.Base58

import scala.concurrent.ExecutionContext.Implicits.global
Expand Down Expand Up @@ -43,7 +40,7 @@ case class DebugApiRoute(override val settings: RESTApiSettings, nodeViewHolderR
def infoRoute: Route = path("info") {
getJsonRoute {
viewAsync().map { view =>
SuccessApiResponse( Map(
SuccessApiResponse(Map(
"height" -> view.history.height.toString.asJson,
"bestPoS" -> Base58.encode(view.history.bestPosId).asJson,
"bestPoW" -> Base58.encode(view.history.bestPowId).asJson,
Expand All @@ -58,14 +55,17 @@ case class DebugApiRoute(override val settings: RESTApiSettings, nodeViewHolderR
getJsonRoute {
viewAsync().map { view =>
val pubkeys = view.vault.publicKeys

def isMyPosBlock(b: HybridBlock): Boolean = b match {
case pos: PosBlock => pubkeys.exists(_.pubKeyBytes sameElements pos.generatorBox.proposition.pubKeyBytes)
case _ => false
}

def isMyPowBlock(b: HybridBlock): Boolean = b match {
case pow: PowBlock => pubkeys.exists(_.pubKeyBytes sameElements pow.generatorProposition.pubKeyBytes)
case _ => false
}

val posCount = view.history.count(isMyPosBlock)
val powCount = view.history.count(isMyPowBlock)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package examples.hybrid.api.http

import javax.ws.rs.Path

import akka.actor.{ActorRef, ActorRefFactory}
import akka.http.scaladsl.server.Route
import examples.commons.SimpleBoxTransactionMemPool
Expand All @@ -10,16 +8,14 @@ import examples.hybrid.state.HBoxStoredState
import examples.hybrid.wallet.HWallet
import io.circe.Json
import io.circe.syntax._
import io.swagger.annotations._
import scorex.core.ModifierId
import scorex.core.api.http.{ApiRouteWithFullView, ApiTry, SuccessApiResponse}
import scorex.core.settings.{RESTApiSettings, ScorexSettings}
import scorex.core.settings.RESTApiSettings
import scorex.crypto.encode.Base58

import scala.concurrent.ExecutionContext.Implicits.global
import scala.util.Try


case class StatsApiRoute(override val settings: RESTApiSettings, nodeViewHolderRef: ActorRef)
(implicit val context: ActorRefFactory)
extends ApiRouteWithFullView[HybridHistory, HBoxStoredState, HWallet, SimpleBoxTransactionMemPool] {
Expand Down
Loading