ADDED: post processor stub for API resource annotations

This commit is contained in:
Kc 2018-10-11 08:56:25 +02:00
parent af84cc8575
commit b57881bc50
3 changed files with 37 additions and 1 deletions

View File

@ -0,0 +1,20 @@
package api;
import io.swagger.v3.jaxrs2.Reader;
import io.swagger.v3.jaxrs2.ReaderListener;
import io.swagger.v3.oas.models.OpenAPI;
public class AnnotationPostProcessor implements ReaderListener {
@Override
public void beforeScan(Reader reader, OpenAPI openAPI) {}
@Override
public void afterScan(Reader reader, OpenAPI openAPI) {
// TODO: use context path and keys from "x-translation" extension annotations
// to translate "descriptions" and finally remove "x-translation" extensions
// from output.
}
}

View File

@ -23,8 +23,9 @@ public class ApiService {
this.resources = new HashSet<Class<?>>();
this.resources.add(BlocksResource.class);
this.resources.add(OpenApiResource.class); // swagger
this.resources.add(AnnotationPostProcessor.class); // for API resource annotations
ResourceConfig config = new ResourceConfig(this.resources);
// create RPC server
this.server = new Server(Settings.getInstance().getRpcPort());

View File

@ -1,7 +1,10 @@
package api;
import globalization.Translator;
import io.swagger.v3.oas.annotations.OpenAPIDefinition;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.extensions.Extension;
import io.swagger.v3.oas.annotations.extensions.ExtensionProperty;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
@ -19,6 +22,11 @@ import repository.RepositoryManager;
@Path("blocks")
@Produces({MediaType.APPLICATION_JSON, MediaType.TEXT_PLAIN})
@OpenAPIDefinition(
extensions = @Extension(name = "translation", properties = {
@ExtensionProperty(name="path", value="/BlocksResource"),
})
)
public class BlocksResource {
@Context
@ -37,6 +45,10 @@ public class BlocksResource {
@GET
@Operation(
description = "Returns an array of the 50 last blocks generated by your accounts",
extensions = @Extension(name = "translation", properties = {
@ExtensionProperty(name="path", value="getBlocks"),
@ExtensionProperty(name="key", value="description")
}),
responses = {
@ApiResponse(
description = "The blocks"
@ -45,6 +57,9 @@ public class BlocksResource {
@ApiResponse(
responseCode = "422",
description = "Error: 201 - Wallet does not exist",
extensions = @Extension(name = "translation", properties = {
@ExtensionProperty(name="key", value="ApiError/201")
}),
content = @Content(schema = @Schema(implementation = ApiErrorMessage.class))
)
}