Skip to content

Commit

Permalink
Change method of serving documentation from auto-generated to static …
Browse files Browse the repository at this point in the history
…(but reads auto-generated info)
  • Loading branch information
wcgunter committed Apr 9, 2024
1 parent 61580ff commit 1f6b4a1
Show file tree
Hide file tree
Showing 11 changed files with 98 additions and 46 deletions.
4 changes: 0 additions & 4 deletions cws-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -262,10 +262,6 @@
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
</dependency>
</dependencies>
</profile>
</profiles>
Expand Down
15 changes: 15 additions & 0 deletions cws-service/src/main/java/jpl/cws/controller/MvcCore.java
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,21 @@ protected ModelAndView buildModelerModel(String message) {
}
return model;
}

protected ModelAndView buildApiDocsModel(String message) {
log.trace("Building apidocs's model...");
ModelAndView model = new ModelAndView("api-docs");
try {
model.addObject("base", appRoot);
model.addObject("msg", message);

log.trace("MODEL for Modeler page: "+model.getModel());
}
catch (Throwable t) {
log.error("Unexpected exception", t);
}
return model;
}

}

6 changes: 6 additions & 0 deletions cws-service/src/main/java/jpl/cws/controller/MvcService.java
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,12 @@ public ModelAndView documentation() {
public ModelAndView modeler() {
return buildModelerModel("");
}

@ApiIgnore
@RequestMapping(value = "/api-docs", method = GET)
public ModelAndView apidocs() {
return buildApiDocsModel("");
}


/**
Expand Down
31 changes: 16 additions & 15 deletions cws-service/src/main/java/jpl/cws/controller/RestService.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
import jpl.cws.scheduler.LogHistory;
import jpl.cws.scheduler.Scheduler;
import jpl.cws.service.CwsConsoleService;
import springfox.documentation.annotations.ApiIgnore;

@Controller
@RequestMapping("/api")
Expand Down Expand Up @@ -563,7 +564,7 @@ private Boolean elasticsearchUseAuth() {
})
@RequestMapping(value = "/process/{processDefKey}/schedule", method = POST)
public @ResponseBody String scheduleProcess(
final HttpSession session,
@ApiIgnore final HttpSession session,
@PathVariable String processDefKey,
@RequestParam (value = "processBusinessKey", required=false) String processBusinessKey,
@RequestParam (value = "initiationKey", required=false) String initiationKey,
Expand Down Expand Up @@ -629,7 +630,7 @@ private Boolean elasticsearchUseAuth() {
@RequestMapping(value = "/process-instance/{uuid}/status", method = GET, produces="application/json")
public @ResponseBody String getProcessInstanceStatus(
@PathVariable String uuid,
final HttpSession session) {
@ApiIgnore final HttpSession session) {

log.debug("REST: getProcessInstanceStatus(" + uuid + ")");

Expand Down Expand Up @@ -696,7 +697,7 @@ private Boolean elasticsearchUseAuth() {
@RequestMapping(value = "/snippets/validateAndSaveSnippets", method = POST)
public ModelAndView validateAndSaveSnippets(
@RequestParam String code,
final HttpSession session) {
@ApiIgnore final HttpSession session) {
log.debug("REST: validateAndSaveSnippets");
log.trace("REST: validateAndSaveSnippets, code=" + code);

Expand Down Expand Up @@ -1188,7 +1189,7 @@ public GsonUTCDateAdapter() {
})
@RequestMapping(value = "/worker/{workerId}/{procDefKey}/updateWorkerProcDefLimit/{newLimit}", method = POST)
public @ResponseBody String updateWorkerProcDefLimit(
final HttpSession session,
@ApiIgnore final HttpSession session,
@PathVariable String workerId,
@PathVariable String procDefKey,
@PathVariable String newLimit,
Expand Down Expand Up @@ -1505,7 +1506,7 @@ public GsonUTCDateAdapter() {
})
@RequestMapping(value = "/processes/makeDisabledRowsPending", method = POST)
public @ResponseBody String makeDisabledRowsPending(
final HttpSession session,
@ApiIgnore final HttpSession session,
@RequestBody List<String> uuids) {

log.info("*** REST CALL *** /processes/makeDisabledRowsPending ... " + uuids.size());
Expand Down Expand Up @@ -1533,7 +1534,7 @@ public GsonUTCDateAdapter() {
})
@RequestMapping(value = "/processes/makePendingRowsDisabled", method = POST)
public @ResponseBody String makePendingRowsDisabled(
final HttpSession session,
@ApiIgnore final HttpSession session,
@RequestBody List<String> uuids) {

log.info("*** REST CALL *** /processes/makePendingRowsDisabled ... " + uuids.size());
Expand Down Expand Up @@ -1561,7 +1562,7 @@ public GsonUTCDateAdapter() {
})
@RequestMapping(value = "/processes/retryIncidentRows", method = POST)
public @ResponseBody ResponseEntity<String> retryIncidentRows(
final HttpSession session,
@ApiIgnore final HttpSession session,
@RequestParam(defaultValue = "1") String retries,
@RequestBody List<String> uuids) {

Expand Down Expand Up @@ -1598,7 +1599,7 @@ public GsonUTCDateAdapter() {
})
@RequestMapping(value = "/processes/retryFailedToStart", method = POST)
public @ResponseBody ResponseEntity<String> retryFailedToStart(
final HttpSession session,
@ApiIgnore final HttpSession session,
@RequestBody List<String> uuids) {

log.info("*** REST CALL *** /processes/retryFailedToStart ... " + uuids.size());
Expand All @@ -1623,7 +1624,7 @@ public GsonUTCDateAdapter() {
})
@RequestMapping(value = "/processes/markResolved", method = POST)
public @ResponseBody ResponseEntity<String> markResolved(
final HttpSession session,
@ApiIgnore final HttpSession session,
@RequestBody List<String> procInstIds) {

log.info("*** REST CALL *** /processes/markResolved ... " + procInstIds.size());
Expand Down Expand Up @@ -1651,7 +1652,7 @@ public GsonUTCDateAdapter() {
})
@RequestMapping(value = "/worker/{workerId}/{procDefKey}/updateWorkerProcDefEnabled/{enabledFlag}", method = POST)
public @ResponseBody String updateWorkerProcDefEnabled(
final HttpSession session,
@ApiIgnore final HttpSession session,
@PathVariable String workerId,
@PathVariable String procDefKey,
@PathVariable String enabledFlag,
Expand Down Expand Up @@ -1716,7 +1717,7 @@ public GsonUTCDateAdapter() {
})
@RequestMapping(value = "/processes/delete", method = POST)
public @ResponseBody String deleteRunningProcInsts(
final HttpSession session,
@ApiIgnore final HttpSession session,
@RequestBody List<String> procInstIds) {
log.debug("*** REST CALL *** deleteRunningProcInsts");
String result = cwsConsoleService.deleteRunningProcInst(procInstIds);
Expand All @@ -1734,7 +1735,7 @@ public GsonUTCDateAdapter() {
})
@RequestMapping(value = "/worker/{workerId}/updateNumJobExecThreads/{numThreads}", method = POST)
public @ResponseBody String updateWorkerNumJobExecThreads(
final HttpSession session,
@ApiIgnore final HttpSession session,
@PathVariable String workerId,
@PathVariable String numThreads) {

Expand Down Expand Up @@ -1782,7 +1783,7 @@ public GsonUTCDateAdapter() {
@ApiOperation(value = "Authenticates the user via GET.", tags = {"Security"}, produces = "application/json")
@RequestMapping(value="/authenticate", method = GET)
public @ResponseBody String authenticateViaGet(
final HttpSession session) {
@ApiIgnore final HttpSession session) {
log.debug("/authenticate call got through CWS security!");
return "{\"status\" : \"SUCCESS\", \"session\" : \"" + session.getId() + "\"}";
}
Expand All @@ -1799,7 +1800,7 @@ public GsonUTCDateAdapter() {
@ApiOperation(value = "Authenticates the user via POST.", tags = {"Security"}, produces = "application/json")
@RequestMapping(value = "/authenticate", method = POST)
public @ResponseBody String authenticateViaPost(
final HttpSession session,
@ApiIgnore final HttpSession session,
HttpServletResponse response) {
log.debug("/authenticate call got through CWS security!");
return "{\"status\" : \"SUCCESS\", \"session\" : \"" + session.getId() + "\"}";
Expand All @@ -1816,7 +1817,7 @@ public GsonUTCDateAdapter() {
})
@RequestMapping(value = "/validateCwsToken", method = POST)
public @ResponseBody String validateCwsToken(
final HttpSession session,
@ApiIgnore final HttpSession session,
HttpServletResponse response,
@RequestParam String cwsToken) {
log.trace("validateCwsToken... (cwsToken="+cwsToken+", session.id="+session.getId()+")");
Expand Down
15 changes: 4 additions & 11 deletions cws-service/src/main/java/jpl/cws/controller/SwaggerConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger.web.UiConfiguration;
import springfox.documentation.swagger.web.UiConfigurationBuilder;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@EnableSwagger2
Expand All @@ -26,21 +24,16 @@ public Docket api() {
.pathMapping("/rest/");
}

// add apikey to swagger auth


private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("CWS API")
.description("Documentation of the endpoints used by CWS. Once authenticated, requests can be made to these endpoints (ensure that you are sending the cookie that results from the authentication call!")
.description("Documentation of the endpoints used by CWS. Once authenticated, requests can be made to these endpoints (submit the cwsToken cookie).")
.version("2.6.0")
.license("Apache 2.0")
.licenseUrl("https://github.com/NASA-AMMOS/common-workflow-service?tab=Apache-2.0-1-ov-file")
.build();
}

@Bean
public UiConfiguration uiConfiguration() {
return UiConfigurationBuilder
.builder()
.defaultModelExpandDepth(-1)
.build();
}
}
3 changes: 0 additions & 3 deletions cws-ui/src/main/webapp/WEB-INF/springmvc-servlet.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@

<context:property-placeholder location="classpath:cws-ui.properties"/>

<mvc:resources mapping="/swagger-ui/**" location="classpath:/META-INF/resources/webjars/springfox-swagger-ui/"/>
<mvc:view-controller path="/swagger-ui/" view-name="forward:/swagger-ui/index.html"/>
<mvc:resources mapping="index.html" location="classpath:/META-INF/resources/webjars/springfox-swagger-ui/"/>
<bean id="swaggerConfig" class="jpl.cws.controller.SwaggerConfig"/>

<mvc:annotation-driven>
Expand Down
13 changes: 1 addition & 12 deletions cws-ui/src/main/webapp/WEB-INF/web.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
<url-pattern>/home</url-pattern>
<url-pattern>/processes</url-pattern>
<url-pattern>/configuration</url-pattern>
<url-pattern>/api-docs</url-pattern>
<url-pattern>/documentation</url-pattern>
<url-pattern>/summary</url-pattern>
<url-pattern>/deployments</url-pattern>
Expand All @@ -65,18 +66,6 @@
<url-pattern>/initiators</url-pattern>
<url-pattern>/logout</url-pattern>
<url-pattern>/not_authorized</url-pattern>
<url-pattern>/swagger-ui/index.html</url-pattern>
<url-pattern>/swagger-ui/springfox.css</url-pattern>
<url-pattern>/swagger-ui/swagger-ui.css</url-pattern>
<url-pattern>/swagger-ui/springfox.js</url-pattern>
<url-pattern>/swagger-ui/swagger-ui.js</url-pattern>
<url-pattern>/swagger-ui/swagger-ui-bundle.js</url-pattern>
<url-pattern>/swagger-ui/swagger-ui-standalone-preset.js</url-pattern>
<url-pattern>/swagger-ui/favicon-32x32.png</url-pattern>
<url-pattern>/swagger-ui/favicon-16x16.png</url-pattern>
<url-pattern>/swagger-resources/configuration/ui</url-pattern>
<url-pattern>/swagger-resources/configuration/security</url-pattern>
<url-pattern>/swagger-resources</url-pattern>
<url-pattern>/v2/api-docs</url-pattern>
<url-pattern>*.mvc</url-pattern>
</servlet-mapping>
Expand Down
3 changes: 3 additions & 0 deletions cws-ui/src/main/webapp/css/swagger-ui.css

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions cws-ui/src/main/webapp/js/swagger-ui-bundle.js

Large diffs are not rendered by default.

49 changes: 49 additions & 0 deletions install/cws-ui/api-docs.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="description" content="SwaggerUI" />
<title>SwaggerUI</title>
<link href="/${base}/css/swagger-ui.css" rel="stylesheet">
<script src="/${base}/js/jquery.min.js"></script>
</head>
<body>
<div id="swagger-ui"></div>
<script src="/${base}/js/swagger-ui-bundle.js"></script>
<script>
window.onload = () => {
$.getJSON('/${base}/v2/api-docs', function(data) {
//under the "paths" property, we have all the endpoints.
//loop through and change anywhere we find "/rest/cws-ui/api/" to "/cws-ui/rest/"
//also, add the securityDefinitions property
for (var path in data.paths) {
var newPath = path.replace("/rest/cws-ui/api/", "/cws-ui/rest/");
data.paths[newPath] = data.paths[path];
delete data.paths[path];
}
data["securityDefinitions"] = {
"cwsToken": {
"type": "apiKey",
"name": "cwsToken",
"in": "header"
}
};
data["security"] = [
{
"cwsToken": []
}
];
delete data.tags;
window.ui = SwaggerUIBundle({
spec: data,
dom_id: '#swagger-ui',
deepLinking: true,
docExpansion: 'none',
});
});
};
</script>
</body>
</html>
2 changes: 1 addition & 1 deletion install/cws-ui/documentation.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
<td><a href="http://www.bpmnquickguide.com/quickguide/index.html" target="_blank">BP Incubator BPMN Quick Guide</a></td>
</tr>
<tr>
<td><a href="/cws-ui/swagger-ui/index.html" target="_blank">API Documentation</a></td>
<td><a href="/cws-ui/api-docs" target="_blank">API Documentation</a></td>
</tr>
<tr>
<td><a href="https://docs.camunda.org/rest/camunda-bpm-platform/7.20/" target="_blank">Camunda API Documentation</a></td>
Expand Down

0 comments on commit 1f6b4a1

Please sign in to comment.