vertx / io.vertx.ext.web.api.contract / RouterFactory

RouterFactory

interface RouterFactory<Specification : Any>

Main interface for Design Driven Router factory Author: Francesco Guardiani @slinkydeveloper

Functions

addSecurityHandler

abstract fun addSecurityHandler(securitySchemaName: String, handler: Handler<RoutingContext>): RouterFactory<Any>

Mount to paths that have to follow a security schema a security handler

getOptions

abstract fun getOptions(): RouterFactoryOptions

Get options of router factory. For more info RouterFactoryOptions

getRouter

abstract fun getRouter(): Router

Construct a new router based on spec. It will fail if you are trying to mount a spec with security schemes without assigned handlers Note: Router is constructed in this function, so it will be respected the path definition ordering.

setOptions

abstract fun setOptions(options: RouterFactoryOptions): RouterFactory<Any>

Override options

Inheritors

OpenAPI3RouterFactory

interface OpenAPI3RouterFactory : RouterFactory<OpenAPI>

Interface for OpenAPI3RouterFactory. To add an handler, use OpenAPI3RouterFactory#addHandlerByOperationId(String, Handler), in this class is better than generic RouterFactory#addHandler(HttpMethod, String, Handler) If you want to use RouterFactory#addHandler(HttpMethod, String, Handler) remember that you have to pass path as declared in openapi specification Usage example:

OpenAPI3RouterFactory.createRouterFactoryFromFile(vertx, "src/resources/spec.yaml", asyncResult -> { if (!asyncResult.succeeded()) { // IO failure or spec invalid } else { OpenAPI3RouterFactory routerFactory = asyncResult.result(); routerFactory.addHandlerByOperationId("operation_id", routingContext -> { // Do something }, routingContext -> { // Do something with failure handler }); Router router = routerFactory.getRouter(); } });