Hello everyone!
I am currently using Vert.x to implement a front-facing REST entry point for our application. I wanted to be able to use it with our existing API definitions however. I had a few questions to which I could not find the answer:
- Does it make sense to have an unrelated service running alongside Vert.x (since there is no fleshed out Swagger Codegen for Vert.x, sadly) which is responsible solely for generating the server stubs? Is there a better way?
- How can I dynamically mount routes on a Vert.x deployment after the deployment has started, using a trigger of sorts (i.e. new server stubs available after Swagger definition file upload generated them)? I found a topic on mounting subrouters dynamically in another post on this group, but sadly it did not have an answer on how exactly one would go about doing that.
I initially wanted something like a Spring service that took care of the code generation (since there is a codegen library for Spring MVC), but thought that it might be overkill for this use case, and it would also still leave the second question open.
Any suggestions would be quite welcome.
private Router router;
...
private Router createRouter() {
Router router = Router.router(vertx);
router.route("/").handler(routingContext -> {
// ... handle root routing, cookies, sesssions etc
}
// ...
// bind the definitions update path to the internal handler
router.route("/swagger").handler(this::handleSwaggerUpload);
// other routes
}
private void handleSwaggerUpload() {
// receive Swagger definition, handle codegen using a different service
// running elsewhere and create a Router with the generated stubs
Router importedAPIRouter = // ... definitions from codegen
String APIname = "..." // server stub class names from swagger codegen
// once server stubs are generated, add the route to the router
router.mountSubRouter(APIname, importerAPIRouter);
}