Skip to content

Method Rules

Rules for controlling how methods are documented and how return types are resolved.

Available Rules

Rule KeyTypeDescription
method.docstring (merge distinct)Set method documentation
method.returnstringSet method return type
method.return.mainstringSet primary return type for multiple returns
method.content.typestringSet content type
method.default.http.methodstringSet default HTTP method
method.additional.headerstring (merge)Add additional headers to method
method.additional.paramstring (merge)Add additional parameters to method
method.additional.response.headerstring (merge)Add additional response headers to method

Method Lifecycle Events

Rule KeyTypeDescription
api.method.parse.beforeeventBefore parsing a method as API
api.method.parse.aftereventAfter parsing a method as API

method.doc

Set method descriptions:

properties
method.doc=groovy:it.doc()?.split("\n")?.find { line -> !line.startsWith("@") }

method.doc=groovy:it.ann("io.swagger.annotations.ApiOperation")?.value()

method.return

Override method return types:

properties
method.return=groovy:it.ann("com.example.CustomReturn")?.value()

method.return.main

When a method has multiple possible return types, set the primary one:

properties
method.return.main=groovy:it.doc()?.find("@return\\s+(\\S+)")?.group(1)

method.default.http.method

Set the default HTTP method when not specified by annotations:

properties
method.default.http.method=groovy:it.name().startsWith("save") || it.name().startsWith("create") ? "POST" : "GET"

method.content.type

Set the content type for the request body:

properties
method.content.type=groovy:it.hasAnn("org.springframework.web.bind.annotation.PostMapping") ? "application/json" : null

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}

Released under the Apache-2.0 License.