com.contentgrid.spring.swagger.ui.SwaggerUIInitializerController Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of contentgrid-spring-swagger-ui Show documentation
Show all versions of contentgrid-spring-swagger-ui Show documentation
ContentGrid module to embed and serve Swagger UI
package com.contentgrid.spring.swagger.ui;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.resource.ResourceResolver;
import org.webjars.WebJarAssetLocator;
/**
* This controller serves the (static) Swagger UI configuration file 'swagger-initializer.js'.
*
*
* This static file should NOT be served with standard {@link ResourceResolver} methods:
*
* - If served via {@code /META-INF/resources/webjars/swagger-ui/}, the automatic version detection of
* {@link WebJarAssetLocator} breaks.
* - If served via {@code /META-INF/resources/webjars/swagger-ui/
/}, (automated) dependency
* updates would break the configuration.
*
*/
@RestController
public class SwaggerUIInitializerController {
private static final Resource initializerResource = new ClassPathResource("swagger-initializer.js");
@GetMapping(value = "/webjars/swagger-ui/swagger-initializer.js", produces = "text/javascript")
ResponseEntity getInitializer() {
if (!initializerResource.exists()) {
return ResponseEntity.notFound().build();
}
return ResponseEntity.ok(initializerResource);
}
}