KengoTODA / swagger-code-builder

A project generator from Swagger specification

Home Page:http://worksapplications.github.io/swagger-code-builder/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Swagger Code Builder

License Build Status

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
 --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

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.

About

A project generator from Swagger specification

http://worksapplications.github.io/swagger-code-builder/

License:Apache License 2.0


Languages

Language:Java 97.9%Language:Shell 2.1%