Last active
November 13, 2018 13:33
-
-
Save koert/139cd4b643a38daa203fec9e603f4a99 to your computer and use it in GitHub Desktop.
JAXRS endpoint to retrieve Swagger UI HTML page
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import io.swagger.annotations.ApiOperation; | |
| import javax.ejb.Stateless; | |
| import javax.inject.Inject; | |
| import javax.servlet.ServletContext; | |
| import javax.ws.rs.GET; | |
| import javax.ws.rs.Path; | |
| import javax.ws.rs.core.Response; | |
| import java.io.InputStream; | |
| import static javax.ws.rs.core.Response.Status.NOT_FOUND; | |
| /** | |
| * Swagger UI endpoint. | |
| * @author Koert Zeilstra | |
| */ | |
| @Path("") | |
| @Stateless | |
| public class SwaggerUiResource { | |
| @Inject ServletContext context; | |
| @ApiOperation(value = "HTML of Swagger UI.", hidden = true) | |
| @GET | |
| @Path("/swagger-ui.html") | |
| public Response indexResource() { | |
| final InputStream resource = context.getResourceAsStream("/WEB-INF/static/swagger-ui.html"); | |
| return null == resource | |
| ? Response.status(NOT_FOUND).build() | |
| : Response.ok().entity(resource).build(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment