Springfox: How to hide groups from doc list on swagger ui

Created on 30 Nov 2017  路  3Comments  路  Source: springfox/springfox

Hi all,

I have a question about hiding docket group on swagger ui.
I'm using springfox-swagger2 and springfox-swagger-ui version 2.7.0 now.

I've defined two dockets in the swagger config like following codes.
So I can see two groups on swagger-ui.html page.
image

I don't want to expose a specific group to not authorized access ("external" in this case).
How can I hide a group on swagger-ui?

Thanks in advance

    @Bean
    public Docket externalApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("external").select().apis(RequestHandlerSelectors.any())
                .apiInfo(apiInfo())
                .paths(PathSelectors.regex("/api/external.*")).build();

    }

    @Bean
    public Docket internalApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("internal").apiInfo(internalApiInfo())
                .select().apis(RequestHandlerSelectors.any())
                .paths(PathSelectors.regex("/api/internal.*"))
                .build();
    }

Best regards,
Changgyun

question

All 3 comments

Dunno if it helps but I had the same issue.
A solution I found is to implement a component for the swagger resource provider like

@Component
@Primary
public class CustomInMemorySwaggerResourcesProvider implements SwaggerResourcesProvider {
....
}

and using the SpringSecurity autowired user to know if we should include or not the group, can post a more detailed example if you want. This will also allow to include "external" groups if needed

@andrea-sdl couldn't have said it better! 馃

@andrea-sdl Can you please provide a more detailed implementation?

Was this page helpful?
0 / 5 - 0 ratings