10

I want to implement Swagger-UI in Vert.X app. I have listed all routes and I want to see them in swagger-ui like in SpringBoot. I have also manually edited them in swagger-editor. So, how to open localhost:8080/swagger-ui.html from vert.x app and there to see all routers.

I read that i need to save the json from swagger-editor and to put it in src/resources. After that what?

Also i found a great stuff here: https://github.com/phiz71/vertx-swagger and http://vertx.io/blog/presentation-of-the-vert-x-swagger-project/

But how to implement it?

xmlParser
  • 1,903
  • 4
  • 19
  • 48

1 Answers1

9

Well, you started in the wrong direction a bit. Those examples demonstrate how to build VertX application out of Swagger files. What you want is to serve Swagger UI through VertX. I've put an example project for you: https://github.com/AlexeySoshin/VertxSwaggerUI

When you open http://localhost:8080/swagger/ you'll see all Swagger documentation, as usual.

If you want to do that by yourself:

  1. Copy https://github.com/swagger-api/swagger-ui/tree/master/dist contents under your resources/webroot
  2. Put swagger.json along with those files
  3. Create StaticHandler in VertX: router.route("/*").handler(StaticHandler.create());
Alexey Soshin
  • 16,718
  • 2
  • 31
  • 40
  • 2
    I have already done that. Thank you a lot! But the problem now is that anytime when we add a new route, we must edit swagger.json With spring boot its automatically. So is it possible to make when we add a new route, to see it in the swagger docs without editing swagger.json ? – xmlParser Feb 01 '18 at 09:28
  • 1
    Where you using SpringFox Swagger2? – Alexey Soshin Feb 01 '18 at 16:08
  • 1
    I think that is not working with vert.x in the same way as Spring Boot. Am I wrong? – xmlParser Feb 02 '18 at 07:21
  • 1
    Not aware of such project in VertX. I guess it would be possible to develop something like that, but I'm not sure it'll we as good. VertX doesn't carry as much data about endpoints as Spring does. – Alexey Soshin Feb 02 '18 at 08:29
  • 1
    @AlexeySoshin with this solution I just see the petstore json, what we need is the swagger to be created dynamically based on the java controllers – The Strong Programmer Oct 02 '18 at 12:38
  • 1
    @AlexeySoshin thank you for the example, it helped a lot! I saw though that you're referencing petstore in your swagger index.html – if you want to serve the swagger.json from your project, the URL should be `"./swagger.json"` instead of `"http://petstore.swagger.io/v2/swagger.json"` (which of course, in your example, amounts to the same since you're also serving petstore) – s-heins Sep 12 '21 at 11:13