Skip to content

Commit

Permalink
fixes #149 Generation of REST /health and /server/info endpoints shal…
Browse files Browse the repository at this point in the history
…l be configurable
  • Loading branch information
stevehu committed Aug 22, 2018
1 parent 7e8ed7b commit add7cc9
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@
public class OpenApiGenerator implements Generator {
private Map<String, String> typeMapping = new HashMap<>();
boolean prometheusMetrics =false;
boolean skipHealthCheck = false;
boolean skipServerInfo = false;

public OpenApiGenerator() {
typeMapping.put("array", "java.util.List");
typeMapping.put("map", "java.util.Map");
Expand Down Expand Up @@ -86,6 +89,9 @@ public void generate(String targetPath, Object model, Any config) throws IOExcep
boolean supportClient = config.toBoolean("supportClient");
String dockerOrganization = config.toString("dockerOrganization");
prometheusMetrics = config.toBoolean("prometheusMetrics");
skipHealthCheck = config.toBoolean("skipHealthCheck");
skipServerInfo = config.toBoolean("skipServerInfo");

String version = config.toString("version");
String serviceId = config.get("groupId") + "." + config.get("artifactId") + "-" + config.get("version");

Expand Down Expand Up @@ -134,7 +140,7 @@ public void generate(String targetPath, Object model, Any config) throws IOExcep

List<Map<String, Object>> operationList = getOperationList(model);
// routing
transfer(targetPath, ("src.main.resources.config").replace(".", separator), "handler.yml", templates.rest.openapi.handlerYml.template(serviceId, handlerPackage, operationList, prometheusMetrics));
transfer(targetPath, ("src.main.resources.config").replace(".", separator), "handler.yml", templates.rest.openapi.handlerYml.template(serviceId, handlerPackage, operationList, prometheusMetrics, !skipHealthCheck, !skipServerInfo));

// model
Any anyComponents;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public class SwaggerGenerator implements Generator {

private Map<String, String> typeMapping = new HashMap<>();
boolean prometheusMetrics =false;
boolean skipHealthCheck = false;
boolean skipServerInfo = false;
public SwaggerGenerator() {
typeMapping.put("array", "java.util.List");
typeMapping.put("map", "java.util.Map");
Expand Down Expand Up @@ -84,6 +86,8 @@ public void generate(String targetPath, Object model, Any config) throws IOExcep
boolean supportClient = config.toBoolean("supportClient");
String dockerOrganization = config.toString("dockerOrganization");
prometheusMetrics = config.toBoolean("prometheusMetrics");
skipHealthCheck = config.toBoolean("skipHealthCheck");
skipServerInfo = config.toBoolean("skipServerInfo");
String version = config.toString("version");
String serviceId = config.get("groupId") + "." + config.get("artifactId") + "-" + config.get("version");

Expand Down Expand Up @@ -132,8 +136,7 @@ public void generate(String targetPath, Object model, Any config) throws IOExcep

List<Map<String, Any>> operationList = getOperationList(model);
// routing
transfer(targetPath, ("src.main.resources.config").replace(".", separator), "handler.yml", templates.rest.swagger.handlerYml.template(serviceId, handlerPackage, operationList, prometheusMetrics));

transfer(targetPath, ("src.main.resources.config").replace(".", separator), "handler.yml", templates.rest.swagger.handlerYml.template(serviceId, handlerPackage, operationList, prometheusMetrics, !skipHealthCheck, !skipServerInfo));

// model
Any any = ((Any)model).get("definitions");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@import java.util.Map
@import java.util.List
@import com.jsoniter.any.Any
@args (String serviceId, String handlerPackage, List<Map<String, Object>> items, boolean prometheusMetrics)
@args (String serviceId, String handlerPackage, List<Map<String, Object>> items, boolean prometheusMetrics, boolean healthCheck, boolean serverInfo)

# Handler middleware chain configuration
---
Expand Down Expand Up @@ -75,14 +75,16 @@ paths:
- default
- @with (p = handlerPackage + ".") {@p}@item.get("handlerName")
}
- path: '/health/@serviceId'
@if(healthCheck){ - path: '/health/@serviceId'
method: 'get'
exec:
- health
- path: '/server/info'
}
@if(serverInfo){ - path: '/server/info'
method: 'get'
exec:
- info
}
@if(prometheusMetrics){ - path: '/prometheus'
method: 'get'
exec:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@import java.util.Map
@import java.util.List
@import com.jsoniter.any.Any
@args (String serviceId, String handlerPackage, List<Map<String, Any>> items, boolean prometheusMetrics)
@args (String serviceId, String handlerPackage, List<Map<String, Any>> items, boolean prometheusMetrics, boolean healthCheck, boolean serverInfo)

# Handler middleware chain configuration
---
Expand Down Expand Up @@ -75,14 +75,16 @@ paths:
- default
- @with (p = handlerPackage + ".") {@p}@item.get("handlerName")
}
- path: '/health/@serviceId'
@if(healthCheck){ - path: '/health/@serviceId'
method: 'get'
exec:
- health
- path: '/server/info'
}
@if(serverInfo){ - path: '/server/info'
method: 'get'
exec:
- info
}
@if(prometheusMetrics){ - path: '/prometheus'
method: 'get'
exec:
Expand Down

0 comments on commit add7cc9

Please sign in to comment.