Vert.x binding server stubs generated by Swagger codegen at runtime

116 vistas
Ir al primer mensaje no leído

Filip Panovski

no leída,
26 jul 2016, 5:38:03 a.m.26/7/16
para vert.x

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:

  1. - 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?

  2. - 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.

Filip Panovski

no leída,
26 jul 2016, 6:02:41 a.m.26/7/16
para vert.x
Here is some example pseudocode for what I would like to be able to do:

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);
}
Se borró el mensaje

Filip Panovski

no leída,
27 jul 2016, 8:38:29 a.m.27/7/16
para vert.x
Hello again everyone,

I have a small update in hopes that this will help anybody else. I found this library that aims to provide a Codegen solution for Vert.X. The Router works quite well - unfortunately I haven't been able to get the Codegen part to work so far.

It works as follows: 


Swagger swagger = new SwaggerParser().read(filePath); // Swagger 2.0 definition with e.g. GET /orders path
if (swagger != null) {
Router swaggerRouter = SwaggerRouter.swagger(Router.router(vertx), swagger, vertx.eventBus());
}

// GET <host>:<port>/orders now reachable

Has anyone dealt with the problem of using Codegen with Vert.X so far? The Codegen module of the library above does not seem complete, so I am wondering if I should maybe take a look at running a Verticle within a Spring ApplicationContext.

Then, I would use either Spring-MVC or SpringBoot with Codegen, and have Vert.X refer to those services for type enforcement and such. Some feedback on this (or suggestions for an alternative!) would be very welcome.

Best,
Filip
Responder a todos
Responder al autor
Reenviar
0 mensajes nuevos