Class RouterBuilder


  • public class RouterBuilder
    extends Object
    Interface to build a Vert.x Web from an OpenAPI 3 contract.
    To add an handler, use operation(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:
    1. Body handler (Customizable with
    2. Custom global handlers configurable with
    3. Global security handlers defined in upper spec level
    4. Operation specific security handlers
    5. Generated validation handler
    6. User handlers or "Not implemented" handler

    NOTE: This class has been automatically generated from the original non RX-ified interface using Vert.x codegen.

    • Constructor Detail

      • RouterBuilder

        public RouterBuilder​(RouterBuilder delegate)
      • RouterBuilder

        public RouterBuilder​(Object delegate)
    • Method Detail

      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
      • operation

        public Operation operation​(String operationId)
        Access to an operation defined in the contract with operationId
        Parameters:
        operationId - the id of the operation
        Returns:
        the requested operation
      • operations

        public List<Operation> operations()
        Returns:
        all operations defined in the contract
      • bodyHandler

        @Deprecated
        public RouterBuilder bodyHandler​(BodyHandler bodyHandler)
        Deprecated.
        Supply your own BodyHandler if you would like to control body limit, uploads directory and deletion of uploaded files. If you provide a null body handler, you won't be able to validate request bodies
        Parameters:
        bodyHandler -
        Returns:
        self
      • mountServicesFromExtensions

        public RouterBuilder mountServicesFromExtensions()
        Introspect the OpenAPI spec to mount handlers for all operations that specifies a x-vertx-event-bus annotation. Please give a look at vertx-web-api-service documentation for more informations
        Returns:
        self
      • getOpenAPI

        public OpenAPIHolder getOpenAPI()
        Returns:
        holder used by self to process the OpenAPI. You can use it to resolve $refs
      • getSchemaRouter

        @Deprecated
        public SchemaRouter getSchemaRouter()
        Deprecated.
        Returns:
        schema router used by self to internally manage all Schema instances
      • serviceExtraPayloadMapper

        public RouterBuilder serviceExtraPayloadMapper​(Function<RoutingContext,​JsonObject> serviceExtraPayloadMapper)
        When set, this function is called while creating the payload of
        Parameters:
        serviceExtraPayloadMapper -
        Returns:
        self
      • securityHandler

        public SecurityScheme securityHandler​(String securitySchemeName)
        Creates a new security scheme for the required .
        Parameters:
        securitySchemeName -
        Returns:
        a security scheme.
      • createRouter

        public Router createRouter()
        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 built when this function is called and the path definition ordering in contract is respected.
        Returns:
      • create

        public static void create​(Vertx vertx,
                                  String url)
        Like
        Parameters:
        vertx -
        url -
      • rxCreate

        public static io.reactivex.Single<RouterBuilder> rxCreate​(Vertx vertx,
                                                                  String url)
        Like
        Parameters:
        vertx -
        url -
        Returns:
      • securityHandler

        public RouterBuilder securityHandler​(String securitySchemeName,
                                             AuthenticationHandler handler)
        Mount to paths that have to follow a security schema a security handler. This method will not perform any validation weather or not the given securitySchemeName is present in the OpenAPI document. For must use cases the method securityHandler(java.lang.String) should be used.
        Parameters:
        securitySchemeName - the components security scheme id
        handler - the authentication handler
        Returns:
        self