-
Notifications
You must be signed in to change notification settings - Fork 6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
Showing
109 changed files
with
7,891 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#!/bin/sh | ||
|
||
SCRIPT="$0" | ||
|
||
while [ -h "$SCRIPT" ] ; do | ||
ls=`ls -ld "$SCRIPT"` | ||
link=`expr "$ls" : '.*-> \(.*\)$'` | ||
if expr "$link" : '/.*' > /dev/null; then | ||
SCRIPT="$link" | ||
else | ||
SCRIPT=`dirname "$SCRIPT"`/"$link" | ||
fi | ||
done | ||
|
||
if [ ! -d "${APP_DIR}" ]; then | ||
APP_DIR=`dirname "$SCRIPT"`/.. | ||
APP_DIR=`cd "${APP_DIR}"; pwd` | ||
fi | ||
|
||
executable="./modules/swagger-codegen-cli/target/swagger-codegen-cli.jar" | ||
|
||
if [ ! -f "$executable" ] | ||
then | ||
mvn clean package | ||
fi | ||
|
||
# if you've executed sbt assembly previously it will use that instead. | ||
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties" | ||
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" | ||
|
||
echo "Removing files and folders under samples/server/petstore/java-pkmst/src/main" | ||
rm -rf samples/server/petstore/java-pkmst/src/main | ||
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 {} + | ||
java $JAVA_OPTS -jar $executable $ags |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
set executable=.\modules\swagger-codegen-cli\target\swagger-codegen-cli.jar | ||
|
||
If Not Exist %executable% ( | ||
mvn clean package | ||
) | ||
|
||
REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M | ||
set ags=generate -i modules\swagger-codegen\src\test\resources\2_0\petstore.yaml -l pkmst -o samples\server\petstore\java-pkmst | ||
|
||
java %JAVA_OPTS% -jar %executable% %ags% |
832 changes: 832 additions & 0 deletions
832
...es/swagger-codegen/src/main/java/io/swagger/codegen/languages/JavaPKMSTServerCodegen.java
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
modules/swagger-codegen/src/main/resources/pkmst/RFC3339DateFormat.mustache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package {{basePackage}}; | ||
|
||
import com.fasterxml.jackson.databind.util.ISO8601DateFormat; | ||
import com.fasterxml.jackson.databind.util.ISO8601Utils; | ||
|
||
import java.text.FieldPosition; | ||
import java.util.Date; | ||
|
||
|
||
public class RFC3339DateFormat extends ISO8601DateFormat { | ||
// Same as ISO8601DateFormat but serializing milliseconds. | ||
@Override | ||
public StringBuffer format(Date date, StringBuffer toAppendTo, FieldPosition fieldPosition) { | ||
String value = ISO8601Utils.format(date, true); | ||
toAppendTo.append(value); | ||
return toAppendTo; | ||
} | ||
|
||
} |
36 changes: 36 additions & 0 deletions
36
modules/swagger-codegen/src/main/resources/pkmst/SpringBootApplication.mustache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package {{basePackage}}; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker; | ||
{{#eurekaUri}} | ||
import org.springframework.cloud.netflix.eureka.EnableEurekaClient; | ||
{{/eurekaUri}} | ||
import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard; | ||
import springfox.documentation.swagger2.annotations.EnableSwagger2; | ||
|
||
/** | ||
* starts the spring boot application | ||
* @author pkmst | ||
* | ||
*/ | ||
|
||
@SpringBootApplication | ||
@EnableSwagger2 | ||
{{#eurekaUri}} | ||
@EnableEurekaClient | ||
{{/eurekaUri}} | ||
@EnableCircuitBreaker | ||
@EnableHystrixDashboard | ||
public class {{serviceName}}Application { | ||
private static final Logger LOGGER = LoggerFactory.getLogger({{serviceName}}Application.class); | ||
|
||
public static void main(String[] args) { | ||
LOGGER.debug("Running spring boot application"); | ||
SpringApplication.run({{serviceName}}Application.class, args); | ||
} | ||
} | ||
|
87 changes: 87 additions & 0 deletions
87
modules/swagger-codegen/src/main/resources/pkmst/api.mustache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/** | ||
* NOTE: This class is auto generated by the swagger code generator program ({{{generatorVersion}}}). | ||
* https://github.com/swagger-api/swagger-codegen | ||
* Do not edit the class manually. | ||
*/ | ||
package {{package}}; | ||
|
||
{{#imports}}import {{import}}; | ||
{{/imports}} | ||
|
||
import io.swagger.annotations.*; | ||
{{#jdk8}} | ||
import org.springframework.http.HttpStatus; | ||
{{/jdk8}} | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestHeader; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestMethod; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RequestPart; | ||
import org.springframework.web.multipart.MultipartFile; | ||
{{^useSpringCloudClient}} | ||
import java.io.IOException; | ||
{{/useSpringCloudClient}} | ||
|
||
import java.util.List; | ||
{{#useOptional}} | ||
import java.util.Optional; | ||
{{/useOptional}} | ||
{{#async}} | ||
import java.util.concurrent.{{^jdk8}}Callable{{/jdk8}}{{#jdk8}}CompletableFuture{{/jdk8}}; | ||
{{/async}} | ||
{{#useBeanValidation}} | ||
import org.springframework.validation.annotation.Validated; | ||
import javax.validation.constraints.*; | ||
import javax.validation.Valid; | ||
{{/useBeanValidation}} | ||
/** | ||
* Provides the info about api methods | ||
* @author pkmst | ||
* | ||
*/ | ||
{{>generatedAnnotation}} | ||
@Api(value = "{{{baseName}}}", description = "the {{{baseName}}} API") | ||
{{#operations}} | ||
public interface {{classname}} { | ||
{{#operation}} | ||
|
||
@ApiOperation(value = "{{{summary}}}", notes = "{{{notes}}}", response = {{{returnType}}}.class{{#returnContainer}}, responseContainer = "{{{returnContainer}}}"{{/returnContainer}}{{#hasAuthMethods}}, authorizations = { | ||
{{#authMethods}}@Authorization(value = "{{name}}"{{#isOAuth}}, scopes = { | ||
{{#scopes}}@AuthorizationScope(scope = "{{scope}}", description = "{{description}}"){{#hasMore}}, | ||
{{/hasMore}}{{/scopes}} | ||
}{{/isOAuth}}){{#hasMore}}, | ||
{{/hasMore}}{{/authMethods}} | ||
}{{/hasAuthMethods}}, tags={ {{#vendorExtensions.x-tags}}"{{tag}}",{{/vendorExtensions.x-tags}} }) | ||
@ApiResponses(value = { {{#responses}} | ||
@ApiResponse(code = {{{code}}}, message = "{{{message}}}"{{#baseType}}, response = {{{baseType}}}.class{{/baseType}}{{#containerType}}, responseContainer = "{{{containerType}}}"{{/containerType}}){{#hasMore}},{{/hasMore}}{{/responses}} }) | ||
{{#implicitHeaders}} | ||
@ApiImplicitParams({ | ||
{{#headerParams}}{{>implicitHeader}}{{/headerParams}} | ||
}) | ||
{{/implicitHeaders}} | ||
@RequestMapping(value = "{{{path}}}",{{#singleContentTypes}} | ||
produces = "{{{vendorExtensions.x-accepts}}}", | ||
consumes = "{{{vendorExtensions.x-contentType}}}",{{/singleContentTypes}}{{^singleContentTypes}}{{#hasProduces}} | ||
produces = { {{#produces}}"{{{mediaType}}}"{{#hasMore}}, {{/hasMore}}{{/produces}} }, {{/hasProduces}}{{#hasConsumes}} | ||
consumes = { {{#consumes}}"{{{mediaType}}}"{{#hasMore}}, {{/hasMore}}{{/consumes}} },{{/hasConsumes}}{{/singleContentTypes}} | ||
method = RequestMethod.{{httpMethod}}) | ||
{{#useSpringCloudClient}} | ||
{{#jdk8}}default {{/jdk8}}{{#responseWrapper}}{{.}}<{{/responseWrapper}}ResponseEntity<{{>returnTypes}}>{{#responseWrapper}}>{{/responseWrapper}} {{operationId}}({{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{#hasMore}},{{/hasMore}}{{/allParams}}){{^jdk8}};{{/jdk8}}{{#jdk8}} { | ||
// do some magic! | ||
return {{#async}}CompletableFuture.completedFuture({{/async}}new ResponseEntity<{{>returnTypes}}>(HttpStatus.NOT_IMPLEMENTED){{#async}}){{/async}}; | ||
}{{/jdk8}} | ||
|
||
{{/useSpringCloudClient}} | ||
{{^useSpringCloudClient}} | ||
{{#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}} { | ||
// do some magic! | ||
return {{#async}}CompletableFuture.completedFuture({{/async}}new ResponseEntity<{{>returnTypes}}>(HttpStatus.OK){{#async}}){{/async}}; | ||
}{{/jdk8}} | ||
|
||
{{/useSpringCloudClient}} | ||
{{/operation}} | ||
} | ||
{{/operations}} |
115 changes: 115 additions & 0 deletions
115
modules/swagger-codegen/src/main/resources/pkmst/apiController.mustache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
package {{package}}; | ||
|
||
{{^jdk8-no-delegate}} | ||
{{#imports}}import {{import}}; | ||
{{/imports}} | ||
|
||
import io.swagger.annotations.*; | ||
|
||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
{{/jdk8-no-delegate}} | ||
import org.springframework.stereotype.Controller; | ||
{{^jdk8-no-delegate}} | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestHeader; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RequestPart; | ||
import org.springframework.web.multipart.MultipartFile; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
||
import java.util.List; | ||
{{#useOptional}} | ||
import java.util.Optional; | ||
{{/useOptional}} | ||
{{#async}} | ||
import java.util.concurrent.Callable; | ||
{{/async}} | ||
{{/jdk8-no-delegate}} | ||
{{^useSpringCloudClient}} | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import java.io.IOException; | ||
{{/useSpringCloudClient}} | ||
{{#useBeanValidation}} | ||
import javax.validation.constraints.*; | ||
import javax.validation.Valid; | ||
{{/useBeanValidation}} | ||
/** | ||
* Api implemention | ||
* @author pkmst | ||
* | ||
*/ | ||
{{>generatedAnnotation}} | ||
@Controller | ||
{{#operations}} | ||
public class {{classname}}Controller implements {{classname}} { | ||
private final ObjectMapper objectMapper; | ||
@Autowired | ||
public {{classname}}Controller(ObjectMapper objectMapper) { | ||
this.objectMapper = objectMapper; | ||
} | ||
|
||
{{#isDelegate}} | ||
private final {{classname}}Delegate delegate; | ||
|
||
@org.springframework.beans.factory.annotation.Autowired | ||
public {{classname}}Controller({{classname}}Delegate delegate) { | ||
this.delegate = delegate; | ||
} | ||
|
||
{{/isDelegate}} | ||
{{^jdk8-no-delegate}} | ||
{{#operation}} | ||
public {{#async}}Callable<{{/async}}ResponseEntity<{{>returnTypes}}>{{#async}}>{{/async}} {{operationId}}({{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}, | ||
{{/allParams}}@RequestHeader(value = "Accept", required = false) String accept) throws Exception { | ||
// do some magic! | ||
{{#useSpringCloudClient}} | ||
{{^isDelegate}} | ||
{{^async}} | ||
return new ResponseEntity<{{>returnTypes}}>(HttpStatus.OK); | ||
{{/async}} | ||
{{#async}} | ||
return new Callable<ResponseEntity<{{>returnTypes}}>>() { | ||
@Override | ||
public ResponseEntity<{{>returnTypes}}> call() throws Exception { | ||
return new ResponseEntity<{{>returnTypes}}>(HttpStatus.OK); | ||
} | ||
}; | ||
{{/async}} | ||
{{/isDelegate}} | ||
{{#isDelegate}} | ||
return delegate.{{operationId}}({{#allParams}}{{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}); | ||
{{/isDelegate}} | ||
{{/useSpringCloudClient}} | ||
{{^useSpringCloudClient}} | ||
{{^isDelegate}} | ||
{{^async}} | ||
{{#examples}} | ||
|
||
if (accept != null && accept.contains("{{{contentType}}}")) { | ||
return new ResponseEntity<{{>returnTypes}}>(objectMapper.readValue("{{#lambdaRemoveLineBreak}}{{#lambdaEscapeDoubleQuote}}{{{example}}}{{/lambdaEscapeDoubleQuote}}{{/lambdaRemoveLineBreak}}", {{>exampleReturnTypes}}.class), HttpStatus.OK); | ||
} | ||
|
||
{{/examples}} | ||
return new ResponseEntity<{{>returnTypes}}>(HttpStatus.OK); | ||
{{/async}} | ||
{{#async}} | ||
return new Callable<ResponseEntity<{{>returnTypes}}>>() { | ||
@Override | ||
public ResponseEntity<{{>returnTypes}}> call() throws Exception { | ||
return new ResponseEntity<{{>returnTypes}}>(HttpStatus.OK); | ||
} | ||
}; | ||
{{/async}} | ||
{{/isDelegate}} | ||
{{#isDelegate}} | ||
return delegate.{{operationId}}({{#allParams}}{{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}); | ||
{{/isDelegate}} | ||
{{/useSpringCloudClient}} | ||
} | ||
|
||
{{/operation}} | ||
{{/jdk8-no-delegate}} | ||
} | ||
{{/operations}} |
57 changes: 57 additions & 0 deletions
57
modules/swagger-codegen/src/main/resources/pkmst/api_test.mustache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
{{>licenseInfo}} | ||
|
||
package {{package}}; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
{{#imports}}import {{import}}; | ||
{{/imports}} | ||
import org.junit.Test; | ||
import org.junit.Ignore; | ||
|
||
{{^fullJavaUtil}} | ||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
{{/fullJavaUtil}} | ||
|
||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
/** | ||
* API tests for {{classname}} | ||
*/ | ||
@Ignore | ||
public class {{classname}}Test { | ||
private final ObjectMapper objectMapper = new ObjectMapper(); | ||
private final {{classname}} api = new {{classname}}Controller(objectMapper); | ||
|
||
private final String accept = "application/json"; | ||
|
||
{{#operations}}{{#operation}} | ||
/** | ||
* {{summary}} | ||
* | ||
* {{notes}} | ||
* | ||
* @throws Exception | ||
* if the Api call fails | ||
*/ | ||
@Test | ||
public void {{operationId}}Test() throws Exception { | ||
{{#allParams}} | ||
{{^isFile}} | ||
{{{dataType}}} {{paramName}} = null; | ||
{{/isFile}} | ||
{{#isFile}} | ||
MultipartFile {{paramName}} = null; | ||
{{/isFile}} | ||
{{/allParams}} | ||
ResponseEntity<{{>returnTypes}}> response = api.{{operationId}}({{#allParams}}{{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}} {{#allParams}}{{^hasMore}},{{/hasMore}}{{/allParams}} accept); | ||
|
||
// TODO: test validations | ||
} | ||
{{/operation}}{{/operations}} | ||
} |
Oops, something went wrong.