mp-rest-client-maven-plugin
Microprofile rest client maven plugin
Configuration parameters
Version 0.5.0+ add support for
RestControllerclass and proxy implementation.
Version 0.5.0+ contains check for generated files. If the generator generated more files with the same name the generator throws exception. The combination of the parameters
apiName,pathPrefixorgroupByTagsis use to generate corresponding java classes for the openAPI schema.
Example combination
- default configuration generated file for each REST path.
/admin/name,/adminand/user/namewill generate two java classesAdminRestClientandUserRestClient - if you add only
apiName=Usergenerator creates one java classUserRestClientfor all REST method in openAPI schema. apiName=MyRestandpathPrefix=/adminwill generated one fileMyRestRestClientfor all REST method which start with/adminoradminpath.apiName=MyRestandpathPrefix=/will generated one file with all REST method. This is equals to setting only theapiNameparameter.- if you set the
groupByTagstotruethe generator will group the REST api by the tags in the openAPI schema. This is default swagger generator but it could generated wrong java classes; depend on your openAPI schema and the parameterapiNameandpathPrefixwill be ignored.
Method of the java class are base on the
operationId. If there are multipleoperationIdmethods in the java class the tag of the operation is add as prefix to the method. If there are multipletag+operationIdmethods in the java class generator will add suffix_<number>to the method.
The plugin extends the parameter from: Swagger maven plugin Extended parameters:
| Name | Default | Values | Description |
|---|---|---|---|
| modelPackage | The package name of the models | ||
| apiPackage | The package name of the RestClient or RestController |
||
| formatter | true | The google source code formatter | |
| apiName | The api name if this is set the generator will generate one file for all REST method | ||
| interfaceOnly | true | Generate the interface only. If you need to generate RestController set this attribute to false |
|
| implType | CLASS | CLASS,INTERFACE,PROXY | This attribute is use only for interfaceOnly=false. The default implementation CLASS will generate the class with Response 501 for each method. The INTERFACE value will generate the interface with default method implementation Response 501 |
| pathPrefix | The path prefix for all interfaces. Example 'v2/' or '/'. REST method which starts not with this prefix will be ignored. | ||
| apiSuffix | RestClient | The api interface suffix | |
| annotations | The list of custom annotations for the interface. | ||
| modelAnnotations | The list of custom annotations for the model. | ||
| restClient | true | The flag to generate the micro-profile rest client for the interface. | |
| returnResponse | true | The return type will be the Response. | |
| beanParamSuffix | BeanParam | The bean parameter suffix. | |
| beanParamCount | 9 | The number of the parameters to group by the bean parameter. | |
| jsonLib | JSONB | JACKSON,JSONB | The JSON implementation. |
| fieldGen | PUBLIC | LOMBOK,GET_SET,PUBLIC | The model field generator type. |
| dateLibrary | java8 | The date library. | |
| useBeanValidation | true | Use the bean validation on the methods. | |
| apiInterfaceDoc | true | Generate the micro-profile annotation on the generated interface. | |
| groupByTags | false | Group the REST in the openAPI schema by tags (Default by swagger). Default is false to group the REST method by path |
Examples
Goal: codegen - RestClient
<plugin>
<groupId>org.lorislab.maven</groupId>
<artifactId>mp-restclient-maven-plugin</artifactId>
<version>0.5.0</version>
<executions>
<execution>
<id>test</id>
<goals>
<goal>codegen</goal>
</goals>
<configuration>
<inputSpec>src/main/resources/clients/openapi.yaml</inputSpec>
<output>${project.build.directory}/generated-sources/mprestclient</output>
<apiPackage>gen.org.lorislab.test</apiPackage>
<modelPackage>gen.org.lorislab.test.models</modelPackage>
<generateSupportingFiles>false</generateSupportingFiles>
<apiInterfaceDoc>false</apiInterfaceDoc>
<fieldGen>LOMBOK</fieldGen>
<jsonLib>JACKSON</jsonLib>
<annotations>
<annotation>javax.inject.Singleton</annotation>
<annotation>org.eclipse.microprofile.rest.client.inject.RegisterRestClient(configKey="my-client-key")</annotation>
</annotations>
<modelAnnotations>
<modelAnnotation>lombok.ToString</modelAnnotation>
<modelAnnotation>io.quarkus.runtime.annotations.RegisterForReflection</modelAnnotation>
</modelAnnotations>
<configOptions>
<sourceFolder>test</sourceFolder>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
Goal: codegen - RestController
<plugin>
<groupId>org.lorislab.maven</groupId>
<artifactId>mp-restclient-maven-plugin</artifactId>
<version>0.5.0</version>
<executions>
<execution>
<id>user</id>
<goals>
<goal>codegen</goal>
</goals>
<configuration>
<inputSpec>src/main/resources/META-INF/openapi.yaml</inputSpec>
<output>${project.build.directory}/generated-sources/endpoints</output>
<apiPackage>org.lorislab.test.rs.internal</apiPackage>
<modelPackage>org.lorislab.test.rs.internal.models</modelPackage>
<generateSupportingFiles>false</generateSupportingFiles>
<apiInterfaceDoc>false</apiInterfaceDoc>
<interfaceOnly>false</interfaceOnly>
<apiSuffix>RestController</apiSuffix>
<fieldGen>LOMBOK</fieldGen>
<jsonLib>JACKSON</jsonLib>
<annotations>
<annotation>javax.enterprise.context.ApplicationScoped</annotation>
</annotations>
<modelAnnotations>
<modelAnnotation>lombok.ToString</modelAnnotation>
<modelAnnotation>io.quarkus.runtime.annotations.RegisterForReflection</modelAnnotation>
</modelAnnotations>
<configOptions>
<sourceFolder>user</sourceFolder>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
Goal: codegen - Proxy
The
implType=PROXYwill generate the proxy REST endpoint. For this implementation you need to add theproxyClientClasswhich is the RestClient class and themodelPackageneeds to have the same value like theRestClient.
<plugin>
<groupId>org.lorislab.maven</groupId>
<artifactId>mp-restclient-maven-plugin</artifactId>
<version>0.5.0</version>
<executions>
<execution>
<id>user-client</id>
<goals>
<goal>codegen</goal>
</goals>
<configuration>
<inputSpec>src/main/resources/user/openapi.yaml</inputSpec>
<output>${project.build.directory}/generated-sources/restclients</output>
<apiPackage>org.lorislab.user.rs.proxy</apiPackage>
<modelPackage>org.lorislab.user.rs.proxy.models</modelPackage>
<generateSupportingFiles>false</generateSupportingFiles>
<apiInterfaceDoc>false</apiInterfaceDoc>
<fieldGen>LOMBOK</fieldGen>
<jsonLib>JACKSON</jsonLib>
<annotations>
<annotation>javax.inject.Singleton</annotation>
<annotation>org.eclipse.microprofile.rest.client.inject.RegisterRestClient(configKey="my-client-key")</annotation>
</annotations>
<modelAnnotations>
<modelAnnotation>lombok.ToString</modelAnnotation>
<modelAnnotation>io.quarkus.runtime.annotations.RegisterForReflection</modelAnnotation>
</modelAnnotations>
<configOptions>
<sourceFolder>user</sourceFolder>
</configOptions>
</configuration>
</execution>
<execution>
<id>user-proxy</id>
<goals>
<goal>codegen</goal>
</goals>
<configuration>
<inputSpec>src/main/resources/user/openapi.yaml</inputSpec>
<output>${project.build.directory}/generated-sources/endpoints</output>
<apiPackage>org.lorislab.user.rs.proxy</apiPackage>
<modelPackage>org.lorislab.user.rs.proxy.models</modelPackage>
<generateSupportingFiles>false</generateSupportingFiles>
<apiInterfaceDoc>false</apiInterfaceDoc>
<interfaceOnly>false</interfaceOnly>
<implType>PROXY</implType>
<fieldGen>LOMBOK</fieldGen>
<jsonLib>JACKSON</jsonLib>
<apiSuffix>RestController</apiSuffix>
<proxyClientClass>UsersRestClient</proxyClientClass>
<annotations>
<annotation>javax.enterprise.context.ApplicationScoped</annotation>
</annotations>
<modelAnnotations>
<modelAnnotation>lombok.ToString</modelAnnotation>
<modelAnnotation>io.quarkus.runtime.annotations.RegisterForReflection</modelAnnotation>
</modelAnnotations>
<configOptions>
<sourceFolder>user</sourceFolder>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
Example
<plugin>
<groupId>org.lorislab.maven</groupId>
<artifactId>mp-rest-client-maven-plugin</artifactId>
<version>999-SNAPSHOT</version>
<executions>
<execution>
<id>p6-gateway</id>
<goals>
<goal>codegen</goal>
</goals>
<configuration>
<inputSpec>src/main/resources/clients/openapi.yaml</inputSpec>
<output>${project.build.directory}/generated-sources/mprestclient</output>
<apiPackage>gen.org.lorislab.test</apiPackage>
<modelPackage>gen.org.lorislab.test.models</modelPackage>
<generateSupportingFiles>false</generateSupportingFiles>
<apiInterfaceDoc>false</apiInterfaceDoc>
<fieldGen>LOMBOK</fieldGen>
<jsonLib>JACKSON</jsonLib>
<annotations>
<annotation>javax.inject.Singleton</annotation>
<annotation>org.lorislab.quarkus.jel.log.interceptor.LoggerService</annotation>
<annotation>org.eclipse.microprofile.rest.client.inject.RegisterRestClient(configKey="my-client-key")</annotation>
</annotations>
<modelAnnotations>
<modelAnnotation>lombok.ToString(callSuper = true)</modelAnnotation>
<modelAnnotation>io.quarkus.runtime.annotations.RegisterForReflection</modelAnnotation>
</modelAnnotations>
<configOptions>
<sourceFolder>test</sourceFolder>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
Generate source code
package api;
import model.Error;
import model.Pets;
import javax.ws.rs.*;
import javax.ws.rs.core.Response;
import org.eclipse.microprofile.rest.client.inject.RegisterRestClient;
import lombok.Data;
import java.util.Map;
import java.util.List;
import javax.validation.constraints.*;
import javax.validation.Valid;
@Path("/pets")
@RegisterRestClient
@org.lorislab.quarkus.jel.log.interceptor.RestClientLogInterceptor
@org.lorislab.quarkus.jel.log.interceptor.LoggerService
@javax.annotation.Generated(
value = "org.lorislab.swagger.mp.RestClientCodegen",
date = "2019-06-13T08:26:44.867834+02:00[Europe/Berlin]")
public interface TestTestClient {
@POST
Response createPets(@BeanParam CreatePetsBeanParam beanParam, @Valid String body);
@Data
public class CreatePetsBeanParam {
@QueryParam("limit")
Integer limit;
@QueryParam("limit2")
Integer limit2;
@HeaderParam("limit3")
Integer limit3;
@PathParam("petId2")
String petId2;
@PathParam("petId")
String petId;
}
@GET
Response listPets(@QueryParam("limit") Integer limit);
@GET
@Path("/{petId}")
Response showPetById(@PathParam("petId") String petId);
}
Release process of this plugin
Create new release run
mvn semver-release:release-create
Create new patch branch run
mvn semver-release:patch-create -DpatchVersion=X.X.0