Swagger Code Builder

Swagger Code Builder is a project generator from Swagger (or Open API).

Getting Started

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

Server project

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"

Serverless project

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.

Usage

 --api-spec-path VAL : File path for Open API (Swagger) file
 --output-path VAL   : Output directory (default: out)
 --structure VAL     : Project structure
 -h (--help)         : Print usage message and exit (default: true)

Avaiable Structures

java-services
POJO business logic classes
sparkjava
Application server based on sparkjava which invoke POJO services
java-awsserverless
AWS Lambdas which invoke POJO services

License

Swagger Code Builder by Works Applications Co.,Ltd. is licensed under the Apache License, Version 2.0.