Commit 8378a43d authored by Bruno López Trigo's avatar Bruno López Trigo

Actualizada documentación de API a Swagger v3

parent 846d3a60
......@@ -104,9 +104,14 @@
</dependency>
<!-- Swagger -->
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-jersey2-jaxrs</artifactId>
<version>1.5.0</version>
<groupId>io.swagger.core.v3</groupId>
<artifactId>swagger-jaxrs2</artifactId>
<version>2.0.0</version>
</dependency>
<dependency>
<groupId>io.swagger.core.v3</groupId>
<artifactId>swagger-jaxrs2-servlet-initializer</artifactId>
<version>2.0.0</version>
</dependency>
</dependencies>
......@@ -164,7 +169,7 @@
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
</plugin>
</plugins>
</build>
......
......@@ -11,15 +11,6 @@ import brunolopez.expliclas.models.BuildParamsREP;
import brunolopez.expliclas.models.BuildParamsRT;
import brunolopez.expliclas.models.DatasetConfig;
import brunolopez.expliclas.models.SimpleMessage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
......@@ -31,7 +22,6 @@ import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;
@Api(value = "/builder")
@Path("/builder")
public class BuilderService {
......@@ -43,22 +33,12 @@ public class BuilderService {
@POST
@Path("{dataset}/J48")
@ApiOperation(value = "Build a classifier from specific dataset using J48 algorithm", response = DatasetConfig.class)
@ApiResponses(value = {
@ApiResponse(code = 400, message = "Wrong dataset format"),
@ApiResponse(code = 409, message = "Classifier already exists")
})
@ApiImplicitParams({
@ApiImplicitParam(value = "Authorization token", name = "authorization" , dataType = "string", paramType = "header", required = true)
})
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@TokenNeeded
public Response buildClassifierJ48(@Context HttpHeaders httpheaders,
@Context UriInfo uriInfo,
@ApiParam(value = "Dataset name", required = true)
@PathParam("dataset") String dataset,
@ApiParam(value = "J48 generation params", required = true)
BuildParamsJ48 params) {
String header = httpheaders.getHeaderString(HttpHeaders.AUTHORIZATION);
......@@ -81,22 +61,12 @@ public class BuilderService {
@POST
@Path("{dataset}/RandomTree")
@ApiOperation(value = "Build a classifier from specific dataset using RandomTree algorithm", response = DatasetConfig.class)
@ApiResponses(value = {
@ApiResponse(code = 400, message = "Wrong dataset format"),
@ApiResponse(code = 409, message = "Classifier already exists")
})
@ApiImplicitParams({
@ApiImplicitParam(value = "Authorization token", name = "authorization" , dataType = "string", paramType = "header", required = true)
})
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@TokenNeeded
public Response buildClassifierRT(@Context HttpHeaders httpheaders,
@Context UriInfo uriInfo,
@ApiParam(value = "Dataset name", required = true)
@PathParam("dataset") String dataset,
@ApiParam(value = "RandomTree generation params", required = true)
BuildParamsRT params) {
String header = httpheaders.getHeaderString(HttpHeaders.AUTHORIZATION);
......@@ -119,22 +89,12 @@ public class BuilderService {
@POST
@Path("{dataset}/REPTree")
@ApiOperation(value = "Build a classifier from specific dataset using REPTree algorithm", response = DatasetConfig.class)
@ApiResponses(value = {
@ApiResponse(code = 400, message = "Wrong dataset format"),
@ApiResponse(code = 409, message = "Classifier already exists")
})
@ApiImplicitParams({
@ApiImplicitParam(value = "Authorization token", name = "authorization" , dataType = "string", paramType = "header", required = true)
})
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@TokenNeeded
public Response buildClassifierREP(@Context HttpHeaders httpheaders,
@Context UriInfo uriInfo,
@ApiParam(value = "Dataset name", required = true)
@PathParam("dataset") String dataset,
@ApiParam(value = "REPTree generation params", required = true)
BuildParamsREP params) {
String header = httpheaders.getHeaderString(HttpHeaders.AUTHORIZATION);
......
......@@ -10,13 +10,6 @@ import brunolopez.expliclas.models.DatasetConfig;
import brunolopez.expliclas.models.Explanation;
import brunolopez.expliclas.models.SimpleMessage;
import brunolopez.expliclas.models.VisualNode;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import java.io.IOException;
import java.util.ArrayList;
import javax.ws.rs.Consumes;
......@@ -32,7 +25,6 @@ import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
@Api(value = "/explainer")
@Path("/explainer")
public class ExplainerService {
......@@ -44,22 +36,10 @@ public class ExplainerService {
@GET
@Path("{dataset}/{algorithm}")
@ApiOperation(value = "Generate tree from specific dataset and algorithm", response = DatasetConfig.class)
@ApiResponses(value = {
@ApiResponse(code = 201, message = "Successfully built tree", response = VisualNode.class),
@ApiResponse(code = 404, message = "Classifier not found"),
@ApiResponse(code = 409, message = "Tree already generated"),
@ApiResponse(code = 500, message = "Error building tree")
})
@ApiImplicitParams({
@ApiImplicitParam(value = "Authorization token", name = "authorization", dataType = "string", paramType = "header", required = true)
})
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response getGlobalExplanation(@Context HttpHeaders httpheaders,
@ApiParam(value = "Dataset name", required = true)
@PathParam("dataset") String dataset,
@ApiParam(value = "Classifier algorithm", required = true)
@PathParam("algorithm") String algorithm,
@DefaultValue("en") @QueryParam("lang") String lang) {
......@@ -84,24 +64,11 @@ public class ExplainerService {
@POST
@Path("{dataset}/{algorithm}/confusion")
@ApiOperation(value = "Generate tree from specific dataset and algorithm", response = DatasetConfig.class)
@ApiResponses(value = {
@ApiResponse(code = 201, message = "Successfully built tree", response = VisualNode.class),
@ApiResponse(code = 404, message = "Classifier not found"),
@ApiResponse(code = 409, message = "Tree already generated"),
@ApiResponse(code = 500, message = "Error building tree")
})
@ApiImplicitParams({
@ApiImplicitParam(value = "Authorization token", name = "authorization", dataType = "string", paramType = "header", required = true)
})
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response getConfusionExplanation(@Context HttpHeaders httpheaders,
@ApiParam(value = "Dataset name", required = true)
@PathParam("dataset") String dataset,
@ApiParam(value = "Classifier algorithm", required = true)
@PathParam("algorithm") String algorithm,
@ApiParam(value = "Consequent", required = true)
ArrayList<Consequent> consequents,
@DefaultValue("en") @QueryParam("lang") String lang) {
......@@ -128,24 +95,11 @@ public class ExplainerService {
@POST
@Path("{dataset}/{algorithm}")
@ApiOperation(value = "Generate tree from specific dataset and algorithm", response = DatasetConfig.class)
@ApiResponses(value = {
@ApiResponse(code = 201, message = "Successfully built tree", response = VisualNode.class),
@ApiResponse(code = 404, message = "Classifier not found"),
@ApiResponse(code = 409, message = "Tree already generated"),
@ApiResponse(code = 500, message = "Error building tree")
})
@ApiImplicitParams({
@ApiImplicitParam(value = "Authorization token", name = "authorization", dataType = "string", paramType = "header", required = true)
})
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response getLocalExplanation(@Context HttpHeaders httpheaders,
@ApiParam(value = "Dataset name", required = true)
@PathParam("dataset") String dataset,
@ApiParam(value = "Classifier algorithm", required = true)
@PathParam("algorithm") String algorithm,
@ApiParam(value = "Classification", required = true)
ArrayList<Classification> classification,
@DefaultValue("en") @QueryParam("lang") String lang) {
......
......@@ -5,11 +5,21 @@ import brunolopez.expliclas.models.SimpleMessage;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
import io.jsonwebtoken.impl.crypto.MacProvider;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ResponseHeader;
import io.swagger.v3.oas.annotations.OpenAPIDefinition;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.enums.SecuritySchemeIn;
import io.swagger.v3.oas.annotations.enums.SecuritySchemeType;
import io.swagger.v3.oas.annotations.info.Contact;
import io.swagger.v3.oas.annotations.info.Info;
import io.swagger.v3.oas.annotations.info.License;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.security.OAuthFlow;
import io.swagger.v3.oas.annotations.security.OAuthFlows;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.security.SecurityScheme;
import io.swagger.v3.oas.annotations.servers.Server;
import java.io.File;
import java.util.Calendar;
import java.util.Date;
......@@ -25,18 +35,53 @@ import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;
@OpenAPIDefinition(
info = @Info(
title = "ExpliClas API REST",
version = "2.0",
description = "API REST for the Automatic Explanation in "
+ "Natural Language of classification models in Data "
+ "Mining",
license = @License(name = "GPLv2+", url = "https://www.gnu.org/licenses/old-licenses/gpl-2.0.txt"),
contact = @Contact(name = "Bruno López Trigo", email = "bruno.lopez.trigo@rai.usc.es")
),
servers = {
@Server(
url = "http://localhost:8080/api"
)
}
)
@SecurityScheme(
name = "token",
type = SecuritySchemeType.HTTP,
scheme = "bearer",
bearerFormat = "JWT",
in = SecuritySchemeIn.HEADER,
flows = @OAuthFlows(
implicit = @OAuthFlow(
refreshUrl = "http://localhost:8080/api/session/start"
)
)
)
@Path("/session")
@Api(value = "/session")
public class SessionService {
public final static SecretKey KEY = MacProvider.generateKey();
public final String BASE = getClass().getClassLoader().getResource("").getFile();
// Gestionar inicio de sesión
@Operation(
summary = "Get token",
description = "Get new session token to identify user",
responses = {
@ApiResponse(
responseCode = "200",
description = "Token successfuly obtained",
content = @Content(mediaType = "application/json",
schema = @Schema(implementation = SimpleMessage.class)))
}
)
@GET
@Path("start")
@ApiOperation(value = "Start new anonymous session", response = SimpleMessage.class,
responseHeaders = @ResponseHeader(name = "authorization", description = "Token to identify user", response = String.class))
@Produces(MediaType.APPLICATION_JSON)
public Response startSession(@Context UriInfo uriInfo) {
......@@ -65,36 +110,47 @@ public class SessionService {
}
// Gestionar cierre de sesión
@Operation(
summary = "Close session",
description = "Close session and remove all data binded to session",
responses = {
@ApiResponse(
responseCode = "200",
description = "Succesfully logged out",
content = @Content(mediaType = "application/json",
schema = @Schema(implementation = SimpleMessage.class))),
@ApiResponse(
responseCode = "401",
description = "Unauthorized",
content = @Content(mediaType = "application/json",
schema = @Schema(implementation = SimpleMessage.class)))
}
)
@SecurityRequirement(name = "token")
@DELETE
@ApiOperation(value = "Close session and remove temporal data", response = SimpleMessage.class)
@ApiImplicitParams({
@ApiImplicitParam(value = "Authorization token", name = "authorization" , dataType = "string", paramType = "header", required = true),
})
@Path("close")
@Produces(MediaType.APPLICATION_JSON)
@TokenNeeded
public Response closeSession(@Context HttpHeaders httpheaders) {
String header = httpheaders.getHeaderString(HttpHeaders.AUTHORIZATION);
String token = header.substring("Bearer".length()).trim();
File folder = new File(this.BASE + "tmp/" + token);
File classifier, log, remove;
String[] listProblems = folder.list(), listClassifiers, listLogs;
// Eliminar archivos de sesión del usuario
if(folder.exists()){
for(String dataset: listProblems){
if (folder.exists()) {
for (String dataset : listProblems) {
classifier = new File(this.BASE + "tmp/" + token + "/" + dataset);
listClassifiers = classifier.list();
for(String c: listClassifiers){
for (String c : listClassifiers) {
log = new File(this.BASE + "tmp/" + token + "/" + dataset + "/" + c);
if(log.isDirectory()){
if (log.isDirectory()) {
listLogs = log.list();
for(String l: listLogs){
for (String l : listLogs) {
remove = new File(this.BASE + "tmp/" + token + "/" + dataset + "/" + c + "/" + l);
remove.delete();
}
......@@ -108,6 +164,6 @@ public class SessionService {
}
return Response.status(200).entity(new SimpleMessage("Successfuly logged out")).build();
}
}
......@@ -4,7 +4,7 @@
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
id="WebApp_ID" version="3.1">
<display-name>expliclas</display-name>
<display-name>ExpliClas</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
......@@ -16,15 +16,9 @@
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>
io.swagger.jaxrs.listing
brunolopez.expliclas
brunolopez.expliclas.exceptions
brunolopez.expliclas.interpreter
brunolopez.expliclas.interpreter.problembuilder
brunolopez.expliclas.interpreter.solutionbuilder
brunolopez.expliclas.explainer
brunolopez.expliclas.interpreter.logbuilder
brunolopez.expliclas.filter
brunolopez.expliclas.services,
brunolopez.expliclas.filters,
io.swagger.v3.jaxrs2.integration.resources
</param-value>
</init-param>
<init-param>
......@@ -34,25 +28,6 @@
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>Jersey2Config</servlet-name>
<servlet-class>io.swagger.jersey.config.JerseyJaxrsConfig</servlet-class>
<init-param>
<param-name>swagger.api.title</param-name>
<param-value>ExpliClas API</param-value>
</init-param>
<init-param>
<param-name>api.version</param-name>
<param-value>1.0.0</param-value>
</init-param>
<init-param>
<param-name>swagger.api.basepath</param-name>
<!--<param-value>http://demos.citius.usc.es/ExpliClasAPI/api</param-value>-->
<param-value>http://localhost:8080/api</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>ExpliClas</servlet-name>
<url-pattern>/api/*</url-pattern>
......
......@@ -42,7 +42,7 @@
// Build a system
const ui = SwaggerUIBundle({
//url: "https://demos.citius.usc.es/ExpliClasAPI/api/swagger.json",
url: "http://localhost:8080/api/swagger.json",
url: "http://localhost:8080/api/openapi.json",
dom_id: '#swagger-ui',
deepLinking: true,
presets: [
......
......@@ -4,7 +4,7 @@
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
id="WebApp_ID" version="3.1">
<display-name>expliclas</display-name>
<display-name>ExpliClas</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
......@@ -16,15 +16,9 @@
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>
io.swagger.jaxrs.listing
brunolopez.expliclas
brunolopez.expliclas.exceptions
brunolopez.expliclas.interpreter
brunolopez.expliclas.interpreter.problembuilder
brunolopez.expliclas.interpreter.solutionbuilder
brunolopez.expliclas.explainer
brunolopez.expliclas.interpreter.logbuilder
brunolopez.expliclas.filter
brunolopez.expliclas.services,
brunolopez.expliclas.filters,
io.swagger.v3.jaxrs2.integration.resources
</param-value>
</init-param>
<init-param>
......@@ -34,25 +28,6 @@
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>Jersey2Config</servlet-name>
<servlet-class>io.swagger.jersey.config.JerseyJaxrsConfig</servlet-class>
<init-param>
<param-name>swagger.api.title</param-name>
<param-value>ExpliClas API</param-value>
</init-param>
<init-param>
<param-name>api.version</param-name>
<param-value>1.0.0</param-value>
</init-param>
<init-param>
<param-name>swagger.api.basepath</param-name>
<!--<param-value>http://demos.citius.usc.es/ExpliClasAPI/api</param-value>-->
<param-value>http://localhost:8080/api</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>ExpliClas</servlet-name>
<url-pattern>/api/*</url-pattern>
......
......@@ -42,7 +42,7 @@
// Build a system
const ui = SwaggerUIBundle({
//url: "https://demos.citius.usc.es/ExpliClasAPI/api/swagger.json",
url: "http://localhost:8080/api/swagger.json",
url: "http://localhost:8080/api/openapi.json",
dom_id: '#swagger-ui',
deepLinking: true,
presets: [
......
#Generated by Maven
#Thu Oct 25 17:06:39 CEST 2018
#Fri Oct 26 18:09:47 CEST 2018
version=1.0
groupId=brunolopez
artifactId=expliclas-api
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