@Test void testSwaggerHostAddsPort() { MockHttpServletRequest request = new MockHttpServletRequest(); request.setScheme("http"); request.setMethod("GET"); request.setServletPath("/plugin/swagger/"); request.setServerPort(8080); RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(request)); when(metaDataService.getEntityTypes()).thenReturn(Stream.empty()); assertEquals("view-swagger", swaggerController.swagger(model, response)); verify(model).addAttribute("scheme", "http"); verify(model).addAttribute("host", "localhost:8080"); }
@GetMapping(value = "/swagger.yml", produces = "text/yaml") public String swagger(Model model, HttpServletResponse response) { response.setContentType("text/yaml"); response.setCharacterEncoding("UTF-8"); final UriComponents uriComponents = ServletUriComponentsBuilder.fromCurrentContextPath().build(); model.addAttribute("scheme", uriComponents.getScheme()); String host = uriComponents.getHost(); if (uriComponents.getPort() >= 0) { host += ":" + uriComponents.getPort(); } model.addAttribute("host", host); model.addAttribute( "entityTypes", metaDataService .getEntityTypes() .filter(e -> !e.isAbstract()) .map(EntityType::getId) .sorted() .collect(toList())); model.addAttribute("attributeTypes", AttributeType.getOptionsLowercase()); model.addAttribute("languageCodes", getLanguageCodes().collect(toList())); return "view-swagger"; }
SwaggerController extends PluginController { @GetMapping(value = "/swagger.yml", produces = "text/yaml") public String swagger(Model model, HttpServletResponse response) { response.setContentType("text/yaml"); response.setCharacterEncoding("UTF-8"); final UriComponents uriComponents = ServletUriComponentsBuilder.fromCurrentContextPath().build(); model.addAttribute("scheme", uriComponents.getScheme()); String host = uriComponents.getHost(); if (uriComponents.getPort() >= 0) { host += ":" + uriComponents.getPort(); } model.addAttribute("host", host); model.addAttribute( "entityTypes", metaDataService .getEntityTypes() .filter(e -> !e.isAbstract()) .map(EntityType::getId) .sorted() .collect(toList())); model.addAttribute("attributeTypes", AttributeType.getOptionsLowercase()); model.addAttribute("languageCodes", getLanguageCodes().collect(toList())); return "view-swagger"; } }
SwaggerController extends PluginController { @GetMapping(value = "/swagger.yml", produces = "text/yaml") public String swagger(Model model, HttpServletResponse response) { response.setContentType("text/yaml"); response.setCharacterEncoding("UTF-8"); final UriComponents uriComponents = ServletUriComponentsBuilder.fromCurrentContextPath().build(); model.addAttribute("scheme", uriComponents.getScheme()); String host = uriComponents.getHost(); if (uriComponents.getPort() >= 0) { host += ":" + uriComponents.getPort(); } model.addAttribute("host", host); model.addAttribute( "entityTypes", metaDataService .getEntityTypes() .filter(e -> !e.isAbstract()) .map(EntityType::getId) .sorted() .collect(toList())); model.addAttribute("attributeTypes", AttributeType.getOptionsLowercase()); model.addAttribute("languageCodes", getLanguageCodes().collect(toList())); return "view-swagger"; } SwaggerController(MetaDataService metaDataService, TokenService tokenService); }
SwaggerController extends PluginController { @GetMapping(value = "/swagger.yml", produces = "text/yaml") public String swagger(Model model, HttpServletResponse response) { response.setContentType("text/yaml"); response.setCharacterEncoding("UTF-8"); final UriComponents uriComponents = ServletUriComponentsBuilder.fromCurrentContextPath().build(); model.addAttribute("scheme", uriComponents.getScheme()); String host = uriComponents.getHost(); if (uriComponents.getPort() >= 0) { host += ":" + uriComponents.getPort(); } model.addAttribute("host", host); model.addAttribute( "entityTypes", metaDataService .getEntityTypes() .filter(e -> !e.isAbstract()) .map(EntityType::getId) .sorted() .collect(toList())); model.addAttribute("attributeTypes", AttributeType.getOptionsLowercase()); model.addAttribute("languageCodes", getLanguageCodes().collect(toList())); return "view-swagger"; } SwaggerController(MetaDataService metaDataService, TokenService tokenService); @GetMapping String init(Model model); @GetMapping(value = "/swagger.yml", produces = "text/yaml") String swagger(Model model, HttpServletResponse response); }
SwaggerController extends PluginController { @GetMapping(value = "/swagger.yml", produces = "text/yaml") public String swagger(Model model, HttpServletResponse response) { response.setContentType("text/yaml"); response.setCharacterEncoding("UTF-8"); final UriComponents uriComponents = ServletUriComponentsBuilder.fromCurrentContextPath().build(); model.addAttribute("scheme", uriComponents.getScheme()); String host = uriComponents.getHost(); if (uriComponents.getPort() >= 0) { host += ":" + uriComponents.getPort(); } model.addAttribute("host", host); model.addAttribute( "entityTypes", metaDataService .getEntityTypes() .filter(e -> !e.isAbstract()) .map(EntityType::getId) .sorted() .collect(toList())); model.addAttribute("attributeTypes", AttributeType.getOptionsLowercase()); model.addAttribute("languageCodes", getLanguageCodes().collect(toList())); return "view-swagger"; } SwaggerController(MetaDataService metaDataService, TokenService tokenService); @GetMapping String init(Model model); @GetMapping(value = "/swagger.yml", produces = "text/yaml") String swagger(Model model, HttpServletResponse response); static final String URI; }