How to hide select a spec in swagger-ui.html

Viewed 976

How to hide select a spec in swagger-ui.html Development environment: springboot+swagger2.9.2

enter image description here

1 Answers

To be able to customize parts of the Swagger UI provided by Springfox you have to provide your own version of a JS, HTML or CSS file. In your case, only a custom CSS file is needed.

Put a CSS file (e.g. springfox.css) in the resources folder. The content of the CSS file should be:

.select-label {
    display: none !important;
}

select-label is class name of "Select a spec" label area.

Now you have to make your CSS file accessible for Springfox. Therefore, create a simple Controller that provides your CSS file as a Resource at /webjars/springfox-swagger-ui/springfox.css path.

@Controller
@Log4j2
public class CustomizedSwaggerUI {

    @Value("classpath:springfox.css")
    private Resource cssFile;

    @ApiIgnore
    @GetMapping(value = "/webjars/springfox-swagger-ui/springfox.css")
    public void resourceCSS(HttpServletResponse response) {
        try {
            response.setHeader("content-type", "text/css;charset=UTF-8");
            byte[] file = IOUtils.toByteArray(Objects.requireNonNull(cssFile.getURI()));
            response.getOutputStream().write(file);
        } catch(Exception e) {
            log.error("Error loading customized springfox css file.", e);
        }
    }
}

That's it.

enter image description here

Related