Commit 261e17c7 authored by hengwen's avatar hengwen
Browse files

Add auto generated swagger-ui page for API documentation

parent 7987cd52
......@@ -39,6 +39,9 @@ After installation, start at least one rmiserver, by default it should be listen
Go to the rpc module for installation guid.
Start at least one RPC server on **localhost:6000**
After all services are up, there are some simple scenarios and maps for testing purpose
available in `restful/src/test/resources`.
## Configuration
The configuration file are located at `restful/src/main/resources/config.properties`.
Several options are available in there.
......@@ -123,211 +126,7 @@ The sequence should be:
6. Once finished, retrieve all results with `GET /simulation/{id}/result`
7. Individual sector map data can downloaded with `GET /simulation/{id}/map-data/{sectorIdx}`. The minimal sector index is 0, maximal is *num_sectors* - 1.
## Endpoints
The restful endpoints are defined in the `openapi.yml`.
### Map
#### `POST /map`
Upload a map.
| arg | value |
| --- | --- |
| file | map file |
Return:
```json
{
"id": 1,
"name": null,
"path": null,
"streets": null,
"buildings": null,
"bound": null
}
```
#### `GET /map`
List all available maps.
Return:
```json
[
{
"id": 1,
"name": "map.osm",
"path": null,
"streets": null,
"buildings": null,
"bound": null
},
{
"id": 2,
"name": "straight.osm",
"path": null,
"streets": null,
"buildings": null,
"bound": null
}
]
```
### Scenario
#### `POST /scenario`
Upload a scenario.
| arg | value |
| --- | --- |
| file | .sim file |
```json
{
"id": 1,
"name": "straight",
"path": null
}
```
#### `GET /scenario`
List all available scenarios.
Return:
```json
[
{
"id": 1,
"name": "straight",
"path": null
},
{
"id": 2,
"name": "aachen",
"path": null
}
]
```
### Simulation
#### `POST /simulation`
Configure an simulation, mainly choose an scenario file, and number of sectors that you want you simulation
to be split into.
| arg | type |
| --- | --- |
| scenario_id | int |
| num_sectors | int |
Return:
```json
{
"id": 1,
"scenarioID": 1,
"numSectors": 1,
"mapID": -1
}
```
#### `GET /simulation`
List all available simulations.
Return:
```json
[
{
"id": 1,
"scenarioID": 1,
"numSectors": 1,
"mapID": 0
},
{
"id": 2,
"scenarioID": 3,
"numSectors": 5,
"mapID": 0
}
]
```
#### `POST /simulation/{id}/start`
Start to run a simulation
Return
```json
{"result": "ok"}
```
#### `GET /simulation/{id}/result`
Retrieve the result of a given simulation. It will return all up-to-date result if the simulation is
not finish yet.
Results contains a list of vehicles. Id is a UUID for the vehicle, frames are the actual simulation results.
```json
[
{
"id": "eb280a97-0a22-4b36-986e-cc1dfb3a5302",
"frames": [
{
"posX": 73.1795654296875,
"posY": 0,
"posZ": 0.5429999828338623,
"steering": 0,
"engine": 0,
"brake": 0,
"deltaTime": 33,
"totalTime": 33
}
]
}
]
```
#### `GET /simulation/{id}/map-data/{sector-idx}`
Get the map data of a specific sector of a given simulation.
Return:
```json
{
"id": 0,
"name": null,
"path": null,
"streets": [
{
"id": 6767361,
"width": 6,
"nodes": [
{
"id": 875165172,
"longitude": 5.881338596343994,
"latitude": 50.83610153198242,
"altitude": 0
}
],
"intersections": [],
"type": "A_ROAD",
"streetPavements": "QUALITY",
"speedLimit": 50,
"oneWay": false
}
],
"buildings": [],
"bound": {
"minX": 5.88016939163208,
"minY": 50.835357666015625,
"minZ": 0,
"maxX": 5.881338596343994,
"maxY": 50.8371467590332,
"maxZ": 0
}
}
```
\ No newline at end of file
## API Documentation
The APIs are defined using OpenAPI2.0 in `openapi.yml`.
However, the restful server also provides an auto generated API documentation page at
[http://localhost:8080/swagger-ui.html](http://localhost:8080/swagger-ui.html).
......@@ -35,6 +35,7 @@
<groupId>montisim</groupId>
<artifactId>rpc</artifactId>
<version>1.0.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
......@@ -196,6 +197,16 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
</dependencies>
<build>
......
......@@ -3,7 +3,6 @@ package server.restful;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Import;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import server.restful.view.MapView;
import server.restful.view.ScenarioView;
......@@ -15,11 +14,6 @@ import server.restful.view.SimulationView;
@RestController
public class Server {
@RequestMapping("/")
public String hello(){
return "hello";
}
public static void main(String[] args) {
try {
SpringApplication.run(Server.class, args);
......
package server.restful;
import com.google.common.base.Predicates;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(Predicates.not(RequestHandlerSelectors.basePackage("org.springframework.boot")))
.paths(PathSelectors.any())
.build();
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment