Swagger Code Builder is a project generator from Swagger (or Open API).
Install Code Builder and generate java-service
project.
gradle installDist
gradle :api-exceptions:install
mkdir out
./build/install/swagger-code-builder/bin/swagger-code-builder \
--structure java-services \
--api-spec-path samples/minimum-full.yaml
Implement FindUserService
.
cd out/minimum-api-services
gradle eclipse # or idea
Import the project and open FindUserService
.
@Slf4j
@Singleton
public class FindUserService {
public FindUserResponse handle(FindUserRequest request) {
log.debug("request = {}", request);
return FindUserResponse.builder()
.eTag("aaaaa")
.body(FindUserResponseBody.builder()
.userId(request.getUserId())
.role("ROLE")
.build())
.build();
}
}
Install to local.
gradle install
Generate sparkjava
project and run.
./build/install/swagger-code-builder/bin/swagger-code-builder \
--structure sparkjava \
--api-spec-path samples/minimum-full.yaml
cd out/minimum-api-server
gradle run
Already you can call the API. Open another console.
curl "http://localhost:8080/api/1/users/test" -H "Authorization: foobar"
You can also generate java-awsserverless
project.
./build/install/swagger-code-builder/bin/swagger-code-builder \
--structure java-awsserverless \
--api-spec-path samples/minimum-full.yaml \
--aws-region ap-northeast-1 \
--aws-account-id 123456789012 # Your AWS account ID
cd out/minimum-api-awsserverless
gradle buildZip
./register-lambda.sh
./register-api.sh
swagger.yaml
is including vendor prefixes for AWS API Gateway.
--api-spec-path VAL : File path for Open API (Swagger) file
--aws-account-id VAL : AWS account ID to deploy
--aws-region VAL : AWS region to deploy (default: ap-northeast-1)
--java-group-id VAL : Group ID of the artifact for Java project (default:
com.worksap.webapi)
--output-path VAL : Output directory (default: out)
--structure VAL : Project structure
-h (--help) : Print usage message and exit
- java-services
- POJO business logic classes
- sparkjava
- Application server based on sparkjava which invoke POJO services
- java-awsserverless
- AWS Lambdas which invoke POJO services
Swagger Code Builder by Works Applications Co.,Ltd. is licensed under the Apache License, Version 2.0.