Skip to content

API Rules

Rules for controlling how APIs are named, grouped, and identified.

Available Rules

Rule KeyTypeDescription
api.namestringSet API name
folder.namestringSet folder/group name for API
class.docstring (merge distinct)Set class documentation
class.prefix.pathstringSet class-level prefix path
endpoint.prefix.pathstringSet endpoint-level prefix path
ignorebooleanIgnore a class or method
method.docstring (merge distinct)Set method documentation
method.default.http.methodstringSet default HTTP method
method.content.typestringSet content type
method.returnstringSet method return type
method.return.mainstringSet primary return type
method.additional.headerstring (merge)Add additional headers
method.additional.paramstring (merge)Add additional parameters
method.additional.response.headerstring (merge)Add additional response headers
path.multistringHandle multiple paths

Property Resolution Rules

Rule KeyTypeDescription
properties.prefixstringSet property prefix for @ConfigurationProperties classes
properties.additionalstringLoad additional properties files

Class Recognition Rules

Rule KeyTypeAliasesDescription
class.is.ctrlbooleanclass.is.spring.ctrlDetermine if a class is a Spring controller
class.is.feign.ctrlbooleanDetermine if a class is a Feign client
class.is.jaxrs.ctrlbooleanDetermine if a class is a JAX-RS resource
class.is.quarkus.ctrlbooleanDetermine if a class is a Quarkus resource
class.is.grpcbooleanDetermine if a class is a gRPC service

API Lifecycle Events

Rule KeyTypeAliasesDescription
api.class.parse.beforeeventBefore parsing a class as API
api.class.parse.aftereventAfter parsing a class as API
api.method.parse.beforeeventBefore parsing a method as API
api.method.parse.aftereventAfter parsing a method as API
api.param.parse.beforeeventparam.beforeBefore parsing a parameter
api.param.parse.aftereventparam.afterAfter parsing a parameter
export.aftereventAfter export completes

HTTP Call Events

Rule KeyTypeDescription
http.call.beforeeventBefore making an HTTP call (in API Call feature)
http.call.aftereventAfter an HTTP call completes

api.name

Set the API name for a class:

properties
api.name=#regex:^(.+)Controller$=$1

api.name=groovy:it.name().replace("Controller", "").replace("Resource", "")

class.is.ctrl

Determine if a class should be treated as an API controller:

properties
class.is.ctrl=groovy:it.hasAnn("org.springframework.web.bind.annotation.RestController")

class.is.feign.ctrl

Recognize Feign client interfaces:

properties
class.is.feign.ctrl=groovy:it.hasAnn("org.springframework.cloud.openfeign.FeignClient")

class.is.jaxrs.ctrl

Recognize JAX-RS resource classes:

properties
class.is.jaxrs.ctrl=groovy:it.hasAnn("javax.ws.rs.Path")

class.is.grpc

Recognize gRPC service classes:

properties
class.is.grpc=groovy:it.isExtend("io.grpc.BindableService")

class.prefix.path

Set the prefix path for all APIs in a class:

properties
###set ignoreUnresolved = true
class.prefix.path=${server.servlet.context-path}
###set ignoreUnresolved = false

class.prefix.path=groovy:"/api/v1" + it.ann("org.springframework.web.bind.annotation.RequestMapping")?.value()

endpoint.prefix.path

Set a prefix path at the endpoint level (applied after class.prefix.path):

properties
endpoint.prefix.path=groovy:"/v2"

folder.name

Group APIs into folders:

properties
folder.name=groovy:it.packageName().split("\\.")[-1]

folder.name=groovy:it.ann("org.springframework.web.bind.annotation.RequestMapping")?.value()?.replace("/", "-") ?: "default"

ignore

Ignore specific classes or methods:

properties
ignore=groovy:it.hasAnn("java.lang.Deprecated")

ignore=#regex:^internal.*

method.additional.header

Add extra headers to API methods:

properties
method.additional.header=groovy:{"name":"Authorization","value":"Bearer ${token}","desc":"Auth token","required":true}

method.additional.param

Add extra parameters to API methods:

properties
method.additional.param=groovy:{"name":"version","value":"v1","desc":"API version","required":false}

method.additional.response.header

Add extra response headers to API methods:

properties
method.additional.response.header=groovy:{"name":"X-Total-Count","value":"0","desc":"Total count","required":false}

properties.prefix

Set the property prefix for @ConfigurationProperties classes. This is used by the spring-configuration extension:

properties
properties.prefix=@org.springframework.boot.context.properties.ConfigurationProperties
properties.prefix=@org.springframework.boot.context.properties.ConfigurationProperties#prefix

When a class is annotated with @ConfigurationProperties(prefix = "app.security"), the prefix app.security will be used to resolve property placeholders in that class.

properties.additional

Load additional properties files for placeholder resolution:

properties
properties.additional=${module_path}/src/main/resources/application.properties
properties.additional=${module_path}/src/main/resources/application.yml
properties.additional=${module_path}/src/main/resources/application.yaml

You can also load remote properties:

properties
properties.additional=https://raw.githubusercontent.com/example/config/main/application.properties

Use ###set ignoreNotFoundFile = true to suppress errors when a file doesn't exist:

properties
###set ignoreNotFoundFile = true
properties.additional=${module_path}/src/main/resources/application.properties
###set ignoreNotFoundFile = false

Released under the Apache-2.0 License.