REST API client plugin tasks

The client plugin provides Gradle Codegen plugin tasks that you use to generate REST API:

Using gwUrlDownload

Downloads the OpenAPI for a given RESTful service endpoint and saves it as a local JSON file. This local file can be used as a source by the gwRestCodegen task. The gwUrlDownload task accepts the following parameters:

Table 1. Parameters
Params Description
sourceUrl The REST service endpoint OpenAPI Spec URL
target The file path to save the OpenAPI Spec content
gradle gwUrlDownload -DsourceUrl="https://petstore3.swagger.io/api/v3/openapi.json" -Dtarget="petshop.json"

Using gwConfigCodegen

Generates a configuration file that can be updated by the developers to customize the REST client code generation. The file is stored in the project root folder.

Table 2. Parameters
Params Description
packageName The name of the Java package that the generated code has to be associated with
projectName The name of the Gradle subproject and folder that the generated client has to be placed in
gradle gwConfigCodegen -DpackageName="com.example" -DprojectName="petshop"

Using gwRestCodegen

Generates a REST HTTP client project, Java source code, tests and support files.

Table 3. Parameters
Params Description
packageName The REST client Java package name to use
source The source can be defined as one of the following:
  • a REST service endpoint OpenAPI spec URL
  • a local file path to the OpenAPI spec JSON file
target The output folder where the generated client has to be saved
configFile (optional) The file path to the YAML OpenAPI Codegen configuration settings file
isInsuranceSuite (optional) A flag indicating that the task runs within an InsuranceSuite project

Common usage:

gradle gwRestCodegen -Dtarget="~/petshop" -Dsource="https://petstore3.swagger.io/api/v3/openapi.json"

Generation that uses a configuration file

Use the gwConfigCodegen task to generate the configuration file:

gradle gwRestCodegen -Dtarget="~/petshop" -Dsource="https://petstore3.swagger.io/api/v3/openapi.json" -DconfigFile="petshop/codegen.config.yaml"

Using subproject auto-generated tasks

Tasks Description
restDownload For URL-based endpoint sources, this all-in-one task downloads the REST API definition for that endpoint, generates client code and compiles a JAR library. This task is not present if the endpoint source is file-based.
restConfig This task auto-generates codegen.config.yaml file with default settings inside your endpoint sub-project folder. See Using gwConfigCodegen for more information. If a configuration of the code generation is necessary, then first generate the configuration file and then the code.
restCodegen This task generates code that is based on the given endpoint definition and configuration settings. See Using gwRestCodegen task. This task automatically compiles and generates a JAR library for the endpoint in the build directory of the subproject.