Skip to content
This repository has been archived by the owner on Mar 12, 2020. It is now read-only.

Commit

Permalink
Add missing REST parameter annotations and improve paths #1
Browse files Browse the repository at this point in the history
  • Loading branch information
tdauth committed Nov 20, 2018
1 parent a2e5419 commit c92e022
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ For example, whenever a random action is executed with the help of monkey testin
After running the genetic algorithm, the state machine is then used to create a test suite.

## Scala API for GUI State Machines
The package [api](./src/main/scala/de/retest/guistatemachine/api/) contains all types and methods for getting and modifying the GUI state machine.
The package [api](./src/main/scala/de/retest/guistatemachine/api) contains all types and methods for getting and modifying the GUI state machine.

## REST API
At the moment there is only an initial version of a REST API which has to be mapped to the Scala API.
Expand All @@ -46,4 +46,4 @@ curl -H "Content-Type: application/json" -X POST http://localhost:8888/state-mac

### Swagger Support
The Swagger support is based on [swagger-akka-http](https://github.com/swagger-akka-http/swagger-akka-http).
The URL `http://localhost:8888/api-docs/swagger.json` should show create Swagger JSON output which can be rendered by Swagger UI.
The URL `http://localhost:8888/api-docs/swagger.json` should produce Swagger JSON output which can be rendered by [Swagger UI](https://swagger.io/tools/swagger-ui/).
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@ import akka.http.scaladsl.model.{StatusCode, StatusCodes}
import akka.http.scaladsl.server.{Directives, Route}
import de.retest.guistatemachine.api.{GuiStateMachine, GuiStateMachineApi, Id, State}
import de.retest.guistatemachine.rest.json.DefaultJsonFormats
import io.swagger.annotations.{Api, ApiOperation, ApiResponse, ApiResponses}
import io.swagger.annotations.{Api, ApiImplicitParam, ApiOperation, ApiResponse, ApiResponses}
import javax.ws.rs.Path

@Api(value = "/state-machine", description = "Gets a state machine")
@Path("/state-machine")
@Api(value = "state-machine")
@Path("state-machine")
class GuiStateMachineService(api: GuiStateMachineApi) extends Directives with DefaultJsonFormats {

def getRoute(): Route = getStateMachine() ~ deleteStateMachine() ~ postStateMachine() ~ getState()

@Path("{id}")
@ApiOperation(httpMethod = "GET", response = classOf[GuiStateMachine], value = "Returns a state machine based on the ID")
@ApiResponses(Array(new ApiResponse(code = 404, message = "State machine not found")))
def getStateMachine(): Route = get {
Expand All @@ -26,6 +27,7 @@ class GuiStateMachineService(api: GuiStateMachineApi) extends Directives with De
}
}

@Path("{id}")
@ApiOperation(httpMethod = "DELETE", response = classOf[StatusCode], value = "Returns the status code")
@ApiResponses(
Array(
Expand All @@ -49,33 +51,45 @@ class GuiStateMachineService(api: GuiStateMachineApi) extends Directives with De
}
}

@Path("{id}/get-state")
@ApiOperation(httpMethod = "POST", response = classOf[State], value = "Returns the existing or newly created state")
@ApiImplicitParam(name = "state-body",
value = "The descriptors and the initial never explored actions of the state",
required = true,
dataType = "GetStateBody",
paramType = "body")
@ApiResponses(Array(new ApiResponse(code = 404, message = "State machine not found")))
def getState(): Route = post {
path("state-machine" / LongNumber / "get-state") { id =>
val app = api.getStateMachine(Id(id))
app match {
case Some(x) => {
case Some(x) =>
entity(as[GetStateBody]) { body =>
complete(x.getState(body.descriptors, body.neverExploredActions))
}
}
case None => complete(StatusCodes.NotFound)
}
}
}

@Path("{id}/execute-state")
@ApiOperation(httpMethod = "POST", response = classOf[State], value = "Returns the state which is reached by executing this action")
@ApiImplicitParam(
name = "execute-action-body",
value = "The source state, the action and the target state in form of its descriptors and initial never explored actions",
required = true,
dataType = "ExecuteActionBody",
paramType = "body"
)
@ApiResponses(Array(new ApiResponse(code = 404, message = "State machine not found")))
def executeAction(): Route = post {
path("state-machine" / LongNumber / "execute-action") { id =>
val app = api.getStateMachine(Id(id))
app match {
case Some(x) => {
case Some(x) =>
entity(as[ExecuteActionBody]) { body =>
complete(x.executeAction(body.from, body.a, body.descriptors, body.neverExploredActions))
}
}
case None => complete(StatusCodes.NotFound)
}
}
Expand Down

0 comments on commit c92e022

Please sign in to comment.