Skip to content

Commit cb59591

Browse files
sanshumanwing328
authored andcommitted
pkmst- Prokarma microservice toolkit for java (#7023)
* Added pkmst-microservice toolkit * formatted * replaces tab with blank spaces * adding documentation folder * adding documentation folder * Update readme.mustache Added feature set offered by pkmst * updated readme * Update io.swagger.codegen.CodegenConfig Arranged pkmstServerCodeGen and SymfonyServerCodegen in aphabatical order * Update readme.mustache * renamed according to convention and added typeinfoannotation * removed tabs * updated codegen which extends abstractjavacodegen * Added the script files and rectified the errors * folder name changed and commons -lang3 version upgraded * updated readme.mustache * updated logging filter * Added petstore to samples and updated the pom for the same * Added java-pkmst sample to pom.xml.circleci * updated readme.mustache
1 parent 7d96f61 commit cb59591

File tree

109 files changed

+7891
-3
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

109 files changed

+7891
-3
lines changed

bin/java-petstore-pkmst-server.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/bin/sh
2+
3+
SCRIPT="$0"
4+
5+
while [ -h "$SCRIPT" ] ; do
6+
ls=`ls -ld "$SCRIPT"`
7+
link=`expr "$ls" : '.*-> \(.*\)$'`
8+
if expr "$link" : '/.*' > /dev/null; then
9+
SCRIPT="$link"
10+
else
11+
SCRIPT=`dirname "$SCRIPT"`/"$link"
12+
fi
13+
done
14+
15+
if [ ! -d "${APP_DIR}" ]; then
16+
APP_DIR=`dirname "$SCRIPT"`/..
17+
APP_DIR=`cd "${APP_DIR}"; pwd`
18+
fi
19+
20+
executable="./modules/swagger-codegen-cli/target/swagger-codegen-cli.jar"
21+
22+
if [ ! -f "$executable" ]
23+
then
24+
mvn clean package
25+
fi
26+
27+
# if you've executed sbt assembly previously it will use that instead.
28+
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
29+
ags="$@ generate -t modules/swagger-codegen/src/main/resources/pkmst -i modules/swagger-codegen/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml -l pkmst -o samples/server/petstore/java-pkmst/ -DhideGenerationTimestamp=true"
30+
31+
echo "Removing files and folders under samples/server/petstore/java-pkmst/src/main"
32+
rm -rf samples/server/petstore/java-pkmst/src/main
33+
find samples/server/petstore/java-pkmst -maxdepth 1 -type f ! -name "README.md" ! -name "pom.xml" ! -name "mvn_test_jdk8_only.sh" ! -name ".swagger-codegen-ignore" -exec rm {} +
34+
java $JAVA_OPTS -jar $executable $ags
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
set executable=.\modules\swagger-codegen-cli\target\swagger-codegen-cli.jar
2+
3+
If Not Exist %executable% (
4+
mvn clean package
5+
)
6+
7+
REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M
8+
set ags=generate -i modules\swagger-codegen\src\test\resources\2_0\petstore.yaml -l pkmst -o samples\server\petstore\java-pkmst
9+
10+
java %JAVA_OPTS% -jar %executable% %ags%

modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JavaPKMSTServerCodegen.java

Lines changed: 832 additions & 0 deletions
Large diffs are not rendered by default.

modules/swagger-codegen/src/main/resources/META-INF/services/io.swagger.codegen.CodegenConfig

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ io.swagger.codegen.languages.JavaJAXRSSpecServerCodegen
3333
io.swagger.codegen.languages.JavaJerseyServerCodegen
3434
io.swagger.codegen.languages.JavaJerseyServerCodegen
3535
io.swagger.codegen.languages.JavaMSF4JServerCodegen
36+
io.swagger.codegen.languages.JavaPKMSTServerCodegen
3637
io.swagger.codegen.languages.JavaPlayFrameworkCodegen
3738
io.swagger.codegen.languages.JavaResteasyEapServerCodegen
3839
io.swagger.codegen.languages.JavaResteasyServerCodegen
@@ -47,7 +48,6 @@ io.swagger.codegen.languages.NodeJSServerCodegen
4748
io.swagger.codegen.languages.ObjcClientCodegen
4849
io.swagger.codegen.languages.PerlClientCodegen
4950
io.swagger.codegen.languages.PhpClientCodegen
50-
io.swagger.codegen.languages.SymfonyServerCodegen
5151
io.swagger.codegen.languages.PowerShellClientCodegen
5252
io.swagger.codegen.languages.PistacheServerCodegen
5353
io.swagger.codegen.languages.PythonClientCodegen
@@ -74,6 +74,7 @@ io.swagger.codegen.languages.SwaggerYamlGenerator
7474
io.swagger.codegen.languages.Swift4Codegen
7575
io.swagger.codegen.languages.Swift3Codegen
7676
io.swagger.codegen.languages.SwiftCodegen
77+
io.swagger.codegen.languages.SymfonyServerCodegen
7778
io.swagger.codegen.languages.TizenClientCodegen
7879
io.swagger.codegen.languages.TypeScriptAureliaClientCodegen
7980
io.swagger.codegen.languages.TypeScriptAngularClientCodegen
@@ -82,4 +83,4 @@ io.swagger.codegen.languages.TypeScriptFetchClientCodegen
8283
io.swagger.codegen.languages.TypeScriptJqueryClientCodegen
8384
io.swagger.codegen.languages.TypeScriptNodeClientCodegen
8485
io.swagger.codegen.languages.UndertowCodegen
85-
io.swagger.codegen.languages.ZendExpressivePathHandlerServerCodegen
86+
io.swagger.codegen.languages.ZendExpressivePathHandlerServerCodegen
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package {{basePackage}};
2+
3+
import com.fasterxml.jackson.databind.util.ISO8601DateFormat;
4+
import com.fasterxml.jackson.databind.util.ISO8601Utils;
5+
6+
import java.text.FieldPosition;
7+
import java.util.Date;
8+
9+
10+
public class RFC3339DateFormat extends ISO8601DateFormat {
11+
12+
// Same as ISO8601DateFormat but serializing milliseconds.
13+
@Override
14+
public StringBuffer format(Date date, StringBuffer toAppendTo, FieldPosition fieldPosition) {
15+
String value = ISO8601Utils.format(date, true);
16+
toAppendTo.append(value);
17+
return toAppendTo;
18+
}
19+
20+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package {{basePackage}};
2+
3+
import org.slf4j.Logger;
4+
import org.slf4j.LoggerFactory;
5+
import org.springframework.boot.SpringApplication;
6+
import org.springframework.boot.autoconfigure.SpringBootApplication;
7+
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
8+
{{#eurekaUri}}
9+
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
10+
{{/eurekaUri}}
11+
import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;
12+
import springfox.documentation.swagger2.annotations.EnableSwagger2;
13+
14+
/**
15+
* starts the spring boot application
16+
* @author pkmst
17+
*
18+
*/
19+
20+
@SpringBootApplication
21+
@EnableSwagger2
22+
{{#eurekaUri}}
23+
@EnableEurekaClient
24+
{{/eurekaUri}}
25+
@EnableCircuitBreaker
26+
@EnableHystrixDashboard
27+
public class {{serviceName}}Application {
28+
29+
private static final Logger LOGGER = LoggerFactory.getLogger({{serviceName}}Application.class);
30+
31+
public static void main(String[] args) {
32+
LOGGER.debug("Running spring boot application");
33+
SpringApplication.run({{serviceName}}Application.class, args);
34+
}
35+
}
36+
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/**
2+
* NOTE: This class is auto generated by the swagger code generator program ({{{generatorVersion}}}).
3+
* https://github.com/swagger-api/swagger-codegen
4+
* Do not edit the class manually.
5+
*/
6+
package {{package}};
7+
8+
{{#imports}}import {{import}};
9+
{{/imports}}
10+
11+
import io.swagger.annotations.*;
12+
{{#jdk8}}
13+
import org.springframework.http.HttpStatus;
14+
{{/jdk8}}
15+
import org.springframework.http.ResponseEntity;
16+
import org.springframework.web.bind.annotation.PathVariable;
17+
import org.springframework.web.bind.annotation.RequestBody;
18+
import org.springframework.web.bind.annotation.RequestHeader;
19+
import org.springframework.web.bind.annotation.RequestMapping;
20+
import org.springframework.web.bind.annotation.RequestMethod;
21+
import org.springframework.web.bind.annotation.RequestParam;
22+
import org.springframework.web.bind.annotation.RequestPart;
23+
import org.springframework.web.multipart.MultipartFile;
24+
{{^useSpringCloudClient}}
25+
import java.io.IOException;
26+
{{/useSpringCloudClient}}
27+
28+
import java.util.List;
29+
{{#useOptional}}
30+
import java.util.Optional;
31+
{{/useOptional}}
32+
{{#async}}
33+
import java.util.concurrent.{{^jdk8}}Callable{{/jdk8}}{{#jdk8}}CompletableFuture{{/jdk8}};
34+
{{/async}}
35+
{{#useBeanValidation}}
36+
import org.springframework.validation.annotation.Validated;
37+
import javax.validation.constraints.*;
38+
import javax.validation.Valid;
39+
{{/useBeanValidation}}
40+
/**
41+
* Provides the info about api methods
42+
* @author pkmst
43+
*
44+
*/
45+
{{>generatedAnnotation}}
46+
@Api(value = "{{{baseName}}}", description = "the {{{baseName}}} API")
47+
{{#operations}}
48+
public interface {{classname}} {
49+
{{#operation}}
50+
51+
@ApiOperation(value = "{{{summary}}}", notes = "{{{notes}}}", response = {{{returnType}}}.class{{#returnContainer}}, responseContainer = "{{{returnContainer}}}"{{/returnContainer}}{{#hasAuthMethods}}, authorizations = {
52+
{{#authMethods}}@Authorization(value = "{{name}}"{{#isOAuth}}, scopes = {
53+
{{#scopes}}@AuthorizationScope(scope = "{{scope}}", description = "{{description}}"){{#hasMore}},
54+
{{/hasMore}}{{/scopes}}
55+
}{{/isOAuth}}){{#hasMore}},
56+
{{/hasMore}}{{/authMethods}}
57+
}{{/hasAuthMethods}}, tags={ {{#vendorExtensions.x-tags}}"{{tag}}",{{/vendorExtensions.x-tags}} })
58+
@ApiResponses(value = { {{#responses}}
59+
@ApiResponse(code = {{{code}}}, message = "{{{message}}}"{{#baseType}}, response = {{{baseType}}}.class{{/baseType}}{{#containerType}}, responseContainer = "{{{containerType}}}"{{/containerType}}){{#hasMore}},{{/hasMore}}{{/responses}} })
60+
{{#implicitHeaders}}
61+
@ApiImplicitParams({
62+
{{#headerParams}}{{>implicitHeader}}{{/headerParams}}
63+
})
64+
{{/implicitHeaders}}
65+
@RequestMapping(value = "{{{path}}}",{{#singleContentTypes}}
66+
produces = "{{{vendorExtensions.x-accepts}}}",
67+
consumes = "{{{vendorExtensions.x-contentType}}}",{{/singleContentTypes}}{{^singleContentTypes}}{{#hasProduces}}
68+
produces = { {{#produces}}"{{{mediaType}}}"{{#hasMore}}, {{/hasMore}}{{/produces}} }, {{/hasProduces}}{{#hasConsumes}}
69+
consumes = { {{#consumes}}"{{{mediaType}}}"{{#hasMore}}, {{/hasMore}}{{/consumes}} },{{/hasConsumes}}{{/singleContentTypes}}
70+
method = RequestMethod.{{httpMethod}})
71+
{{#useSpringCloudClient}}
72+
{{#jdk8}}default {{/jdk8}}{{#responseWrapper}}{{.}}<{{/responseWrapper}}ResponseEntity<{{>returnTypes}}>{{#responseWrapper}}>{{/responseWrapper}} {{operationId}}({{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{#hasMore}},{{/hasMore}}{{/allParams}}){{^jdk8}};{{/jdk8}}{{#jdk8}} {
73+
// do some magic!
74+
return {{#async}}CompletableFuture.completedFuture({{/async}}new ResponseEntity<{{>returnTypes}}>(HttpStatus.NOT_IMPLEMENTED){{#async}}){{/async}};
75+
}{{/jdk8}}
76+
77+
{{/useSpringCloudClient}}
78+
{{^useSpringCloudClient}}
79+
{{#jdk8}}default {{/jdk8}}{{#responseWrapper}}{{.}}<{{/responseWrapper}}ResponseEntity<{{>returnTypes}}>{{#responseWrapper}}>{{/responseWrapper}} {{operationId}}({{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}},{{/allParams}} @RequestHeader(value = "Accept", required = false) String accept) throws Exception{{^jdk8}};{{/jdk8}}{{#jdk8}} {
80+
// do some magic!
81+
return {{#async}}CompletableFuture.completedFuture({{/async}}new ResponseEntity<{{>returnTypes}}>(HttpStatus.OK){{#async}}){{/async}};
82+
}{{/jdk8}}
83+
84+
{{/useSpringCloudClient}}
85+
{{/operation}}
86+
}
87+
{{/operations}}
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
package {{package}};
2+
3+
{{^jdk8-no-delegate}}
4+
{{#imports}}import {{import}};
5+
{{/imports}}
6+
7+
import io.swagger.annotations.*;
8+
9+
import org.springframework.http.HttpStatus;
10+
import org.springframework.http.ResponseEntity;
11+
{{/jdk8-no-delegate}}
12+
import org.springframework.stereotype.Controller;
13+
{{^jdk8-no-delegate}}
14+
import org.springframework.web.bind.annotation.PathVariable;
15+
import org.springframework.web.bind.annotation.RequestBody;
16+
import org.springframework.web.bind.annotation.RequestHeader;
17+
import org.springframework.web.bind.annotation.RequestParam;
18+
import org.springframework.web.bind.annotation.RequestPart;
19+
import org.springframework.web.multipart.MultipartFile;
20+
import org.springframework.beans.factory.annotation.Autowired;
21+
22+
import java.util.List;
23+
{{#useOptional}}
24+
import java.util.Optional;
25+
{{/useOptional}}
26+
{{#async}}
27+
import java.util.concurrent.Callable;
28+
{{/async}}
29+
{{/jdk8-no-delegate}}
30+
{{^useSpringCloudClient}}
31+
import com.fasterxml.jackson.databind.ObjectMapper;
32+
import java.io.IOException;
33+
{{/useSpringCloudClient}}
34+
{{#useBeanValidation}}
35+
import javax.validation.constraints.*;
36+
import javax.validation.Valid;
37+
{{/useBeanValidation}}
38+
/**
39+
* Api implemention
40+
* @author pkmst
41+
*
42+
*/
43+
{{>generatedAnnotation}}
44+
@Controller
45+
{{#operations}}
46+
public class {{classname}}Controller implements {{classname}} {
47+
private final ObjectMapper objectMapper;
48+
@Autowired
49+
public {{classname}}Controller(ObjectMapper objectMapper) {
50+
this.objectMapper = objectMapper;
51+
}
52+
53+
{{#isDelegate}}
54+
private final {{classname}}Delegate delegate;
55+
56+
@org.springframework.beans.factory.annotation.Autowired
57+
public {{classname}}Controller({{classname}}Delegate delegate) {
58+
this.delegate = delegate;
59+
}
60+
61+
{{/isDelegate}}
62+
{{^jdk8-no-delegate}}
63+
{{#operation}}
64+
public {{#async}}Callable<{{/async}}ResponseEntity<{{>returnTypes}}>{{#async}}>{{/async}} {{operationId}}({{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}},
65+
{{/allParams}}@RequestHeader(value = "Accept", required = false) String accept) throws Exception {
66+
// do some magic!
67+
{{#useSpringCloudClient}}
68+
{{^isDelegate}}
69+
{{^async}}
70+
return new ResponseEntity<{{>returnTypes}}>(HttpStatus.OK);
71+
{{/async}}
72+
{{#async}}
73+
return new Callable<ResponseEntity<{{>returnTypes}}>>() {
74+
@Override
75+
public ResponseEntity<{{>returnTypes}}> call() throws Exception {
76+
return new ResponseEntity<{{>returnTypes}}>(HttpStatus.OK);
77+
}
78+
};
79+
{{/async}}
80+
{{/isDelegate}}
81+
{{#isDelegate}}
82+
return delegate.{{operationId}}({{#allParams}}{{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}});
83+
{{/isDelegate}}
84+
{{/useSpringCloudClient}}
85+
{{^useSpringCloudClient}}
86+
{{^isDelegate}}
87+
{{^async}}
88+
{{#examples}}
89+
90+
if (accept != null && accept.contains("{{{contentType}}}")) {
91+
return new ResponseEntity<{{>returnTypes}}>(objectMapper.readValue("{{#lambdaRemoveLineBreak}}{{#lambdaEscapeDoubleQuote}}{{{example}}}{{/lambdaEscapeDoubleQuote}}{{/lambdaRemoveLineBreak}}", {{>exampleReturnTypes}}.class), HttpStatus.OK);
92+
}
93+
94+
{{/examples}}
95+
return new ResponseEntity<{{>returnTypes}}>(HttpStatus.OK);
96+
{{/async}}
97+
{{#async}}
98+
return new Callable<ResponseEntity<{{>returnTypes}}>>() {
99+
@Override
100+
public ResponseEntity<{{>returnTypes}}> call() throws Exception {
101+
return new ResponseEntity<{{>returnTypes}}>(HttpStatus.OK);
102+
}
103+
};
104+
{{/async}}
105+
{{/isDelegate}}
106+
{{#isDelegate}}
107+
return delegate.{{operationId}}({{#allParams}}{{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}});
108+
{{/isDelegate}}
109+
{{/useSpringCloudClient}}
110+
}
111+
112+
{{/operation}}
113+
{{/jdk8-no-delegate}}
114+
}
115+
{{/operations}}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
{{>licenseInfo}}
2+
3+
package {{package}};
4+
5+
import com.fasterxml.jackson.databind.ObjectMapper;
6+
{{#imports}}import {{import}};
7+
{{/imports}}
8+
import org.junit.Test;
9+
import org.junit.Ignore;
10+
11+
{{^fullJavaUtil}}
12+
import java.util.ArrayList;
13+
import java.util.HashMap;
14+
import java.util.List;
15+
import java.util.Map;
16+
{{/fullJavaUtil}}
17+
18+
import org.springframework.http.ResponseEntity;
19+
import org.springframework.web.multipart.MultipartFile;
20+
21+
/**
22+
* API tests for {{classname}}
23+
*/
24+
@Ignore
25+
public class {{classname}}Test {
26+
27+
private final ObjectMapper objectMapper = new ObjectMapper();
28+
29+
private final {{classname}} api = new {{classname}}Controller(objectMapper);
30+
31+
private final String accept = "application/json";
32+
33+
{{#operations}}{{#operation}}
34+
/**
35+
* {{summary}}
36+
*
37+
* {{notes}}
38+
*
39+
* @throws Exception
40+
* if the Api call fails
41+
*/
42+
@Test
43+
public void {{operationId}}Test() throws Exception {
44+
{{#allParams}}
45+
{{^isFile}}
46+
{{{dataType}}} {{paramName}} = null;
47+
{{/isFile}}
48+
{{#isFile}}
49+
MultipartFile {{paramName}} = null;
50+
{{/isFile}}
51+
{{/allParams}}
52+
ResponseEntity<{{>returnTypes}}> response = api.{{operationId}}({{#allParams}}{{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}} {{#allParams}}{{^hasMore}},{{/hasMore}}{{/allParams}} accept);
53+
54+
// TODO: test validations
55+
}
56+
{{/operation}}{{/operations}}
57+
}

0 commit comments

Comments
 (0)