Class RouterBuilder
- java.lang.Object
-
- io.vertx.mutiny.ext.web.openapi.RouterBuilder
-
public class RouterBuilder extends Object
Interface to build a Vert.x Web from an OpenAPI 3 contract.
To add an handler, useoperation(java.lang.String)
(String, Handler)}
Usage example:RouterBuilder.create(vertx, "src/resources/spec.yaml", asyncResult -> { if (!asyncResult.succeeded()) { // IO failure or spec invalid
else { RouterBuilder routerBuilder = asyncResult.result(); RouterBuilder.operation("operation_id").handler(routingContext -> { // Do something }, routingContext -> { // Do something with failure handler }); Router router = routerBuilder.createRouter(); } }); }
Handlers are loaded in this order:
- Body handler (Customizable with
- Custom global handlers configurable with
- Global security handlers defined in upper spec level
- Operation specific security handlers
- Generated validation handler
- User handlers or "Not implemented" handler
original
non Mutiny-ified interface using Vert.x codegen.
-
-
Field Summary
Fields Modifier and Type Field Description static TypeArg<RouterBuilder>
__TYPE_ARG
-
Constructor Summary
Constructors Constructor Description RouterBuilder(io.vertx.ext.web.openapi.RouterBuilder delegate)
RouterBuilder(Object delegate)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description RouterBuilder
bodyHandler(BodyHandler bodyHandler)
Deprecated.Use#rootHandler(Handler)
instead.static io.smallrye.mutiny.Uni<RouterBuilder>
create(Vertx vertx, String url)
Likestatic io.smallrye.mutiny.Uni<RouterBuilder>
create(Vertx vertx, String url, io.vertx.ext.web.openapi.OpenAPILoaderOptions options)
Likestatic RouterBuilder
createAndAwait(Vertx vertx, String url)
Blocking variant ofcreate(io.vertx.mutiny.core.Vertx,String)
.static RouterBuilder
createAndAwait(Vertx vertx, String url, io.vertx.ext.web.openapi.OpenAPILoaderOptions options)
Blocking variant ofcreate(io.vertx.mutiny.core.Vertx,String,OpenAPILoaderOptions)
.static void
createAndForget(Vertx vertx, String url)
Variant ofcreate(io.vertx.mutiny.core.Vertx,String)
that ignores the result of the operation.static void
createAndForget(Vertx vertx, String url, io.vertx.ext.web.openapi.OpenAPILoaderOptions options)
Variant ofcreate(io.vertx.mutiny.core.Vertx,String,OpenAPILoaderOptions)
that ignores the result of the operation.Router
createRouter()
boolean
equals(Object o)
io.vertx.ext.web.openapi.RouterBuilder
getDelegate()
OpenAPIHolder
getOpenAPI()
io.vertx.ext.web.openapi.RouterBuilderOptions
getOptions()
SchemaParser
getSchemaParser()
Deprecated.This method exposes the internal of the OpenAPI handler, it will be removed in the future.SchemaRouter
getSchemaRouter()
Deprecated.This method exposes the internal of the OpenAPI handler, it will be removed in the future.int
hashCode()
RouterBuilder
mountServicesFromExtensions()
static RouterBuilder
newInstance(io.vertx.ext.web.openapi.RouterBuilder arg)
Operation
operation(String operationId)
List<Operation>
operations()
RouterBuilder
rootHandler(Consumer<RoutingContext> rootHandler)
SecurityScheme
securityHandler(String securitySchemeName)
RouterBuilder
securityHandler(String securitySchemeName, AuthenticationHandler handler)
RouterBuilder
serviceExtraPayloadMapper(Function<RoutingContext,io.vertx.core.json.JsonObject> serviceExtraPayloadMapper)
RouterBuilder
setOptions(io.vertx.ext.web.openapi.RouterBuilderOptions options)
String
toString()
-
-
-
Field Detail
-
__TYPE_ARG
public static final TypeArg<RouterBuilder> __TYPE_ARG
-
-
Constructor Detail
-
RouterBuilder
public RouterBuilder(io.vertx.ext.web.openapi.RouterBuilder delegate)
-
RouterBuilder
public RouterBuilder(Object delegate)
-
-
Method Detail
-
getDelegate
public io.vertx.ext.web.openapi.RouterBuilder getDelegate()
-
operation
public Operation operation(String operationId)
- Parameters:
operationId
- the id of the operation- Returns:
- the requested operation
-
bodyHandler
@Deprecated public RouterBuilder bodyHandler(BodyHandler bodyHandler)
Deprecated.Use#rootHandler(Handler)
instead. The order matters, so adding the body handler should happen after anyPLATFORM
orSECURITY_POLICY
handler(s).- Parameters:
bodyHandler
-- Returns:
- self
-
rootHandler
public RouterBuilder rootHandler(Consumer<RoutingContext> rootHandler)
- Parameters:
rootHandler
-- Returns:
-
mountServicesFromExtensions
public RouterBuilder mountServicesFromExtensions()
- Returns:
- self
-
setOptions
public RouterBuilder setOptions(io.vertx.ext.web.openapi.RouterBuilderOptions options)
- Parameters:
options
-- Returns:
- self
-
getOptions
public io.vertx.ext.web.openapi.RouterBuilderOptions getOptions()
- Returns:
- options of router builder. For more info
RouterBuilderOptions
-
getOpenAPI
public OpenAPIHolder getOpenAPI()
- Returns:
- holder used by self to process the OpenAPI. You can use it to resolve
$ref
s
-
getSchemaRouter
@Deprecated public SchemaRouter getSchemaRouter()
Deprecated.This method exposes the internal of the OpenAPI handler, it will be removed in the future. Users should configure the json schema module from the options.- Returns:
- schema router used by self to internally manage all
Schema
instances
-
getSchemaParser
@Deprecated public SchemaParser getSchemaParser()
Deprecated.This method exposes the internal of the OpenAPI handler, it will be removed in the future. Users should configure the json schema module from the options.- Returns:
- schema parser used by self to parse all
Schema
-
serviceExtraPayloadMapper
public RouterBuilder serviceExtraPayloadMapper(Function<RoutingContext,io.vertx.core.json.JsonObject> serviceExtraPayloadMapper)
- Parameters:
serviceExtraPayloadMapper
-- Returns:
- self
-
securityHandler
public SecurityScheme securityHandler(String securitySchemeName)
- Parameters:
securitySchemeName
-- Returns:
- a security scheme.
-
createRouter
public Router createRouter()
- Returns:
-
create
@CheckReturnValue public static io.smallrye.mutiny.Uni<RouterBuilder> create(Vertx vertx, String url)
LikeUnlike the bare Vert.x variant, this method returns a
Uni
. Don't forget to subscribe on it to trigger the operation.- Parameters:
vertx
-url
-- Returns:
- the
uni
firing the result of the operation when completed, or a failure if the operation failed.
-
createAndAwait
public static RouterBuilder createAndAwait(Vertx vertx, String url)
Blocking variant ofcreate(io.vertx.mutiny.core.Vertx,String)
.This method waits for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).
- Parameters:
vertx
-url
-- Returns:
- the RouterBuilder instance produced by the operation.
-
createAndForget
public static void createAndForget(Vertx vertx, String url)
Variant ofcreate(io.vertx.mutiny.core.Vertx,String)
that ignores the result of the operation.This method subscribes on the result of
create(io.vertx.mutiny.core.Vertx,String)
, but discards the outcome (item or failure). This method is useful to trigger the asynchronous operation fromcreate(io.vertx.mutiny.core.Vertx,String)
but you don't need to compose it with other operations.- Parameters:
vertx
-url
-
-
create
@CheckReturnValue public static io.smallrye.mutiny.Uni<RouterBuilder> create(Vertx vertx, String url, io.vertx.ext.web.openapi.OpenAPILoaderOptions options)
LikeUnlike the bare Vert.x variant, this method returns a
Uni
. Don't forget to subscribe on it to trigger the operation.- Parameters:
vertx
-url
-options
-- Returns:
- the
uni
firing the result of the operation when completed, or a failure if the operation failed.
-
createAndAwait
public static RouterBuilder createAndAwait(Vertx vertx, String url, io.vertx.ext.web.openapi.OpenAPILoaderOptions options)
Blocking variant ofcreate(io.vertx.mutiny.core.Vertx,String,OpenAPILoaderOptions)
.This method waits for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).
- Parameters:
vertx
-url
-options
-- Returns:
- the RouterBuilder instance produced by the operation.
-
createAndForget
public static void createAndForget(Vertx vertx, String url, io.vertx.ext.web.openapi.OpenAPILoaderOptions options)
Variant ofcreate(io.vertx.mutiny.core.Vertx,String,OpenAPILoaderOptions)
that ignores the result of the operation.This method subscribes on the result of
create(io.vertx.mutiny.core.Vertx,String,OpenAPILoaderOptions)
, but discards the outcome (item or failure). This method is useful to trigger the asynchronous operation fromcreate(io.vertx.mutiny.core.Vertx,String,OpenAPILoaderOptions)
but you don't need to compose it with other operations.- Parameters:
vertx
-url
-options
-
-
securityHandler
public RouterBuilder securityHandler(String securitySchemeName, AuthenticationHandler handler)
- Parameters:
securitySchemeName
- the components security scheme idhandler
- the authentication handler- Returns:
- self
-
newInstance
public static RouterBuilder newInstance(io.vertx.ext.web.openapi.RouterBuilder arg)
-
-