Project

General

Profile

« Previous | Next » 

Revision 7a3e2b35

Added by Andreas Kohlbecker about 8 years ago

#5657 futher fixes for the static swagger doc

View differences:

cdmlib-remote-webapp/src/main/java/eu/etaxonomy/cdm/remote/staticSwagger/StaticSwaggerApiDoc.java
42 42
public class StaticSwaggerApiDoc {
43 43

  
44 44
    public static final String SWAGGER_STATIC = "swagger-static";
45
    public static final String HOST = "{HOST}";
46
    public static final String HOST_REGEX = "\\{HOST\\}";
47
    public static final String BASE_PATH = "{BASE_PATH}";
48
    public static final String BASE_PATH_REGEX = "\\{BASE_PATH\\}";
45 49

  
46 50

  
47 51
    @RequestMapping(value = "configuration/ui", method = RequestMethod.GET)
......
74 78
             HttpServletRequest request,
75 79
            HttpServletResponse response) throws IOException {
76 80

  
81
        String hostValue = request.getServerName() + ":" + request.getServerPort();
82
        String basePathValue = request.getContextPath();
83

  
77 84
        SwaggerGroupsConfig groupConfig = SwaggerGroupsConfig.byGroupName(group);
78 85
        if(groupConfig == null) {
79 86
            HttpStatusMessage.create("Unknown swagger group name.", 400).send(response);
......
83 90
            HttpStatusMessage.create("Static swagger api doc file for group '" + group + "' not found.", 500).send(response);
84 91
        } else {
85 92
            response.addHeader("Content-Type", "application/json;charset=utf-8");
86
            IOUtils.copy(staticDocStream,  response.getOutputStream());
93
            String staticDocText = IOUtils.toString(staticDocStream);
94
            staticDocText = staticDocText.replaceFirst(HOST_REGEX, hostValue);
95
            staticDocText = staticDocText.replaceFirst(BASE_PATH_REGEX, basePathValue);
96

  
97
            IOUtils.write(staticDocText, response.getOutputStream());
87 98
            staticDocStream.close();
88 99
        }
89 100
    }
cdmlib-remote-webapp/src/test/java/eu/etaxonomy/cdm/remote/SwaggerStaticIT.java
69 69
        for(SwaggerGroupsConfig group : SwaggerGroupsConfig.values()) {
70 70
            logger.info(group.groupName());
71 71
            String response =  httpGetJson(swagger2Endpoint, "group=" + group.groupName());
72
            response = response.replaceAll(",\"host\":\"([^\"]*)", ",\"host\":\"" + StaticSwaggerApiDoc.HOST);
73
            response = response.replaceAll(",\"basePath\":\"([^\"]*)", ",\"basePath\":\"" + StaticSwaggerApiDoc.BASE_PATH);
72 74
            try {
73 75
                FileUtils.write(new File(staticApiDocFolder + group.name()), response);
74 76
            } catch (IOException e) {

Also available in: Unified diff