Activating/integrating swagger-ui

Hello,

i activated the rest-api-addon in our cuba-project. The plugin is working as far as i can tell.
I’m trying to integrate the swagger-ui into the project, but i can’t get it to work.
Could you hint me as to how i could enable it?
I added
compile ‘io.springfox:springfox-swagger-ui:2.9.2’
to our build.gradle and some configuration to the web-dispatcher-spring.xml
but it seems i still can’t access the swagger-ui.html
We are currently working with CUBA Version 7.2.4

Greetings
Paul

Hi ,

You can use the below snippet and it worked for me

@EnableSwagger2
@PropertySource("classpath:/com/company/vp/swagger.properties")
public class SwaggerConfig {

    @Bean
    public Docket api() {
        return new Docket(DocumentationType.SWAGGER_2)
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.company.vp.web.controllers"))
                .paths(PathSelectors.any())
                .build();
    }
}

swagger-properties

springfox.documentation.swagger.v2.path=/swagger-api

rest-dispatter-spring.xml

<!-- Swagger resources -->
    <mvc:resources mapping="swagger-ui.html" location="classpath:/META-INF/resources/"/>
    <mvc:resources mapping="/webjars/**" location="classpath:/META-INF/resources/webjars/"/>

    <bean id="sf_SwaggerConfig" class="com.company.vp.web.config.SwaggerConfig"/>

build
compile(‘io.springfox:springfox-swagger2:2.9.2’)
compile(‘io.springfox:springfox-swagger-ui:2.9.2’)
follow that it should work for you as well

1 Like

Hi,

thank you for your response. I tried this exactly, but somehow i can’t access the swagger-ui.html.
How would i access the site?
I think it should be at
http://localhost:8080/app/swagger-ui.html
or
http://localhost:8080/swagger-ui.html
On the first link i get redirected to the login-screen of our app and on the second i get a 404-Error.
I think im missing something obvious here. :frowning:

Found it. The swagger-ui.html is under
http://localhost:8080/app/dispatch/swagger-ui.html
Thanks for your help.

Please, could you tell how did you find that path?

The part http://localhost:8080/app should be obviously the path to your application.
The “dispatch” is the path you configured in your rest-dispatcher-spring.xml

1 Like