forked from Qortal/qortal
ADDED: post processor stub for API resource annotations
This commit is contained in:
parent
af84cc8575
commit
b57881bc50
20
src/api/AnnotationPostProcessor.java
Normal file
20
src/api/AnnotationPostProcessor.java
Normal 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.
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -23,8 +23,9 @@ public class ApiService {
|
|||||||
this.resources = new HashSet<Class<?>>();
|
this.resources = new HashSet<Class<?>>();
|
||||||
this.resources.add(BlocksResource.class);
|
this.resources.add(BlocksResource.class);
|
||||||
this.resources.add(OpenApiResource.class); // swagger
|
this.resources.add(OpenApiResource.class); // swagger
|
||||||
|
this.resources.add(AnnotationPostProcessor.class); // for API resource annotations
|
||||||
ResourceConfig config = new ResourceConfig(this.resources);
|
ResourceConfig config = new ResourceConfig(this.resources);
|
||||||
|
|
||||||
// create RPC server
|
// create RPC server
|
||||||
this.server = new Server(Settings.getInstance().getRpcPort());
|
this.server = new Server(Settings.getInstance().getRpcPort());
|
||||||
|
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
package api;
|
package api;
|
||||||
|
|
||||||
import globalization.Translator;
|
import globalization.Translator;
|
||||||
|
import io.swagger.v3.oas.annotations.OpenAPIDefinition;
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
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.Content;
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||||
@ -19,6 +22,11 @@ import repository.RepositoryManager;
|
|||||||
|
|
||||||
@Path("blocks")
|
@Path("blocks")
|
||||||
@Produces({MediaType.APPLICATION_JSON, MediaType.TEXT_PLAIN})
|
@Produces({MediaType.APPLICATION_JSON, MediaType.TEXT_PLAIN})
|
||||||
|
@OpenAPIDefinition(
|
||||||
|
extensions = @Extension(name = "translation", properties = {
|
||||||
|
@ExtensionProperty(name="path", value="/BlocksResource"),
|
||||||
|
})
|
||||||
|
)
|
||||||
public class BlocksResource {
|
public class BlocksResource {
|
||||||
|
|
||||||
@Context
|
@Context
|
||||||
@ -37,6 +45,10 @@ public class BlocksResource {
|
|||||||
@GET
|
@GET
|
||||||
@Operation(
|
@Operation(
|
||||||
description = "Returns an array of the 50 last blocks generated by your accounts",
|
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 = {
|
responses = {
|
||||||
@ApiResponse(
|
@ApiResponse(
|
||||||
description = "The blocks"
|
description = "The blocks"
|
||||||
@ -45,6 +57,9 @@ public class BlocksResource {
|
|||||||
@ApiResponse(
|
@ApiResponse(
|
||||||
responseCode = "422",
|
responseCode = "422",
|
||||||
description = "Error: 201 - Wallet does not exist",
|
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))
|
content = @Content(schema = @Schema(implementation = ApiErrorMessage.class))
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user