I’m evaluating vaadin for a project. We’re a spring boot / java / postgreSQL shop. We currently user vuejs for UI, and we hope to
have less context switches when using vaadin for UI.
I have a spring boot (2.3.2.RELEASE) application which defines a REST API and uses springdoc to render a OpenAPI/Swagger UI for discovering
the API.
When I add vaadin (14.3.1) to that project and create views – which does work as intended – we find that vaadin catches all requests, and
thus the swagger UI does no longer work.
How can we configure this?
Setting vaadin.url-mapping to /ui/* gets me only blank pages – no errors – but still no swagger UI.
Am I missing something? I don’t find anything in the docs about this? Is this expected behaviour?
If you had a non-Spring Boot application, the answer would be indeed that you need a custom VaadinServlet and a @WebServlet annotation which specifies the custom url pattern. I’m not exactly sure how that works with a Spring Boot, though.
I’m a bit suprised that this doesn’t work OOTB. I briefly looked at the vaadin spring starter auto configuration to no avail. Maybe I need to invest more time.
However, we’re primarily a spring boot shop – this not working raises some red flags for me. I still think I might missing something obvious, though.
do you have @EnableSwagger2 annotation on a @Configuration class?
Does any of your configuration classes define a Bean for Docket?
do you have the dependency to io.springfox.springfox-swagger-ui ?
I have a Vaadin 14.3.0 application running that has a working swagger UI (on top of its own UI and REST API). I did not have to modify urlmapping or webservlets.
PS: the url to my swagger UI is swagger-ui.html. I’m not sure from the top of my head why we have a difference there.
PSS: I do see in my @Configuration that I have this codeblock, which the baeldung post says it’s only for non-springboot projects (I have spring-boot). Not sure if that matters.
do you have @EnableSwagger2 annotation on a @Configuration class? (springfox.documentation.swagger2.annotations.EnableSwagger2)
Does any of your configuration classes define a Bean for Docket?
Please note that the swagger UI works perfectly when I remove Vaadin. I actually started out with plain and simple spring boot, defining a rest service, adding springdocs and making sure that everything works. As soon as I add vaadin and add a UI, the vaadin UI works, but teh SwaggerUI stops working. Interestingly the REST API still works. I’ll do some debugging
later – I still think there’s something amiss with webjar resources.
This will be the most common use case in our shop – having some spring app which need a UI bolted on.
It’s indeed the case that the VaadinServlet’s serverStaticOrWebJarRequest returns NULL for all openapi resources.
I tried to wrap my head around the springdoc’s spring auto configuration – it’s at least called and it registers webjar
resources – but also a transformer. This transformer is there to rewrite requests form “/swagger-ui.html” to the actual
resource location of the swagger UI – they append the openapi UI definition JSON dynamically.
This transformer is never called, and requests to the swagger UI directly also fail. So I believe the vaadin webjar server steals requests.
Interestingly the production build of my code shows the same behaviour. The code comments suggest that the WebJar Server
only active in dev mode, though.