io.lsdconsulting.stub.handler.MethodMappingAnnotationHandler.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of spring-wiremock-stub-generator Show documentation
Show all versions of spring-wiremock-stub-generator Show documentation
A tool for generating Java based Wiremock stubs from Spring MVC controllers
package io.lsdconsulting.stub.handler
import io.lsdconsulting.stub.model.Model
import org.apache.commons.lang3.StringUtils.capitalize
import org.springframework.http.HttpMethod
import javax.lang.model.element.Element
class MethodMappingAnnotationHandler {
fun handle(
element: Element,
model: Model,
path: Array,
value: Array,
httpMethod: HttpMethod,
responseType: String? = null,
) {
val methodModelKey = element.toString()
val methodName = element.simpleName.toString()
val controllerModel = model.getControllerModel(element.enclosingElement.toString())
controllerModel.getResourceModel(methodModelKey).subResource = subResource(path, value)
controllerModel.getResourceModel(methodModelKey).httpMethod = httpMethod
controllerModel.getResourceModel(methodModelKey).methodName = capitalize(methodName)
controllerModel.getResourceModel(methodModelKey).responseType = responseType
}
private fun subResource(path: Array, value: Array) =
if (path.isNotEmpty()) {
path[0]
} else if (value.isNotEmpty()) {
value[0]
} else null
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy