@Test public void testGetHtmlDoc() throws Exception { Request request = mock(Request.class); Variant variant = mock(Variant.class); when(variant.getMediaType()).thenReturn(MediaType.TEXT_HTML_TYPE); when(request.selectVariant(any(List.class))).thenReturn(variant); Response result = apiResource.api(request); assertThat(result.getEntity()).isNotNull(); assertThat(result.getStatus()).isEqualTo(200); assertThat(result.getMediaType()).isEqualTo(MediaType.TEXT_HTML_TYPE); }
@GET @Produces({APPLICATION_JSON, TEXT_HTML}) @ApiResponses({@ApiResponse(code = 200, message = "Returns JSON or HTML OpenAPI document")}) public Response api(@Context final Request request) throws IOException { final Variant variant = request.selectVariant(VARIANTS); final URL url; if (variant.getMediaType() == APPLICATION_JSON_TYPE) { url = getClass().getResource("/swagger.json"); } else if (variant.getMediaType() == TEXT_HTML_TYPE) { url = getClass().getResource("/swagger.html"); } else { return Response.status(Status.BAD_REQUEST).build(); } return Response.ok(url.openStream(), variant.getMediaType()).build(); }
ApiResource { @GET @Produces({APPLICATION_JSON, TEXT_HTML}) @ApiResponses({@ApiResponse(code = 200, message = "Returns JSON or HTML OpenAPI document")}) public Response api(@Context final Request request) throws IOException { final Variant variant = request.selectVariant(VARIANTS); final URL url; if (variant.getMediaType() == APPLICATION_JSON_TYPE) { url = getClass().getResource("/swagger.json"); } else if (variant.getMediaType() == TEXT_HTML_TYPE) { url = getClass().getResource("/swagger.html"); } else { return Response.status(Status.BAD_REQUEST).build(); } return Response.ok(url.openStream(), variant.getMediaType()).build(); } }
ApiResource { @GET @Produces({APPLICATION_JSON, TEXT_HTML}) @ApiResponses({@ApiResponse(code = 200, message = "Returns JSON or HTML OpenAPI document")}) public Response api(@Context final Request request) throws IOException { final Variant variant = request.selectVariant(VARIANTS); final URL url; if (variant.getMediaType() == APPLICATION_JSON_TYPE) { url = getClass().getResource("/swagger.json"); } else if (variant.getMediaType() == TEXT_HTML_TYPE) { url = getClass().getResource("/swagger.html"); } else { return Response.status(Status.BAD_REQUEST).build(); } return Response.ok(url.openStream(), variant.getMediaType()).build(); }  }
ApiResource { @GET @Produces({APPLICATION_JSON, TEXT_HTML}) @ApiResponses({@ApiResponse(code = 200, message = "Returns JSON or HTML OpenAPI document")}) public Response api(@Context final Request request) throws IOException { final Variant variant = request.selectVariant(VARIANTS); final URL url; if (variant.getMediaType() == APPLICATION_JSON_TYPE) { url = getClass().getResource("/swagger.json"); } else if (variant.getMediaType() == TEXT_HTML_TYPE) { url = getClass().getResource("/swagger.html"); } else { return Response.status(Status.BAD_REQUEST).build(); } return Response.ok(url.openStream(), variant.getMediaType()).build(); }  @GET @Produces({APPLICATION_JSON, TEXT_HTML}) @ApiResponses({@ApiResponse(code = 200, message = "Returns JSON or HTML OpenAPI document")}) Response api(@Context final Request request); }
ApiResource { @GET @Produces({APPLICATION_JSON, TEXT_HTML}) @ApiResponses({@ApiResponse(code = 200, message = "Returns JSON or HTML OpenAPI document")}) public Response api(@Context final Request request) throws IOException { final Variant variant = request.selectVariant(VARIANTS); final URL url; if (variant.getMediaType() == APPLICATION_JSON_TYPE) { url = getClass().getResource("/swagger.json"); } else if (variant.getMediaType() == TEXT_HTML_TYPE) { url = getClass().getResource("/swagger.html"); } else { return Response.status(Status.BAD_REQUEST).build(); } return Response.ok(url.openStream(), variant.getMediaType()).build(); }  @GET @Produces({APPLICATION_JSON, TEXT_HTML}) @ApiResponses({@ApiResponse(code = 200, message = "Returns JSON or HTML OpenAPI document")}) Response api(@Context final Request request);  }