use of org.apache.tapestry5.annotations.RestInfo in project tapestry-5 by apache.
the class DefaultOpenApiTypeDescriber method describeReturnType.
@Override
public void describeReturnType(JSONObject description, Method method) {
Class<?> returnedType;
final RestInfo restInfo = method.getAnnotation(RestInfo.class);
if (restInfo != null) {
returnedType = restInfo.returnType();
} else {
returnedType = method.getReturnType();
}
describeType(description, returnedType);
}
use of org.apache.tapestry5.annotations.RestInfo in project tapestry-5 by apache.
the class DefaultOpenApiDescriptionGenerator method processRequestBody.
private void processRequestBody(Method method, final String uri, final String httpMethod, final JSONObject methodDescription, JSONArray parametersAsJsonArray, Parameter parameter) {
JSONObject requestBodyDescription = new JSONObject();
requestBodyDescription.put("required", !(parameter.getAnnotation(RequestBody.class).allowEmpty()));
getValue(method, uri, httpMethod, "requestbody.description").ifPresent((v) -> requestBodyDescription.put("description", v));
RestInfo restInfo = method.getAnnotation(RestInfo.class);
if (restInfo != null) {
JSONObject contentDescription = new JSONObject();
for (String contentType : restInfo.consumes()) {
JSONObject schemaDescription = new JSONObject();
typeDescriber.describe(schemaDescription, parameter);
schemaDescription.remove("required");
contentDescription.put(contentType, schemaDescription);
}
requestBodyDescription.put("content", contentDescription);
}
methodDescription.put("requestBody", requestBodyDescription);
}
use of org.apache.tapestry5.annotations.RestInfo in project tapestry-5 by apache.
the class DefaultOpenApiDescriptionGenerator method getProducedMediaTypes.
private String[] getProducedMediaTypes(Method method) {
String[] produces = CommonsUtils.EMPTY_STRING_ARRAY;
RestInfo restInfo = method.getAnnotation(RestInfo.class);
if (isNonEmptyConsumes(restInfo)) {
produces = restInfo.produces();
} else {
restInfo = method.getDeclaringClass().getAnnotation(RestInfo.class);
if (isNonEmptyProduces(restInfo)) {
produces = restInfo.produces();
}
}
return produces;
}
use of org.apache.tapestry5.annotations.RestInfo in project tapestry-5 by apache.
the class Index method onHttpPut.
@RestInfo(consumes = "application/json")
public Object onHttpPut(@RequestBody User user) throws UnsupportedEncodingException {
HttpStatus status;
if (!USERS.contains(user)) {
USERS.add(user);
status = HttpStatus.created();
} else {
status = HttpStatus.ok();
}
return status.withContentLocation(pageRenderLinkSource.createPageRenderLinkWithContext(Index.class, user.getEmail()));
}
use of org.apache.tapestry5.annotations.RestInfo in project tapestry-5 by apache.
the class Index method getExample.
@RestInfo(returnType = User.class, produces = "application/json")
@OnEvent(EventConstants.HTTP_GET)
public User getExample(@StaticActivationContextValue("example") String example) {
User user = new User();
user.setEmail("fulano@fulano.com");
user.setName("Fulano da Silva");
user.getAttributes().add(new Attribute("favoriteColor", "blue"));
return user;
}
Aggregations