To manage swagger documentations I am using custom annotations for the methods which call the API
@SwagRef(method = POST, url = "/my/api/{pathParam1}")
public Response callMyAPI(
@MyParam(name = "pathParam1", required = true, in = PATH) String p1,
@MyParam(name = "param2", required = false, in = QUERY) String p2) {
return given()
.pathParam("pathParam1", p1)
.queryParam("param2", p2)
.get();
}
There is a separate piece of code which validates the Swagger/api/docs vs the annotations. However I'm wondering is it possible to somehow use all this already presented data in the annotations and have a common code where I can pass the method reference or the parameter reference and the RequestSpecification can be built using the annotations.
I tried with reflection, but I'm unable to fetch the value of parameters using reflection from method
I was only able to deduce the method type and API since it's constant using the methodName and stackTrace
asList(currentThread().getStackTrace())
.
.
.map(getDeclaredMethods())
.map(getAnnotation(SwagRef.class))
.Collect(toMap(s-> s.getMethod(), s.getURL());
But I'm not able to come up with a generic function for Building the request spec using method parameters
Aucun commentaire:
Enregistrer un commentaire