Search in sources :

Example 1 with RestInfo

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);
}
Also used : RestInfo(org.apache.tapestry5.annotations.RestInfo)

Example 2 with RestInfo

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);
}
Also used : JSONObject(org.apache.tapestry5.json.JSONObject) RestInfo(org.apache.tapestry5.annotations.RestInfo)

Example 3 with RestInfo

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;
}
Also used : RestInfo(org.apache.tapestry5.annotations.RestInfo)

Example 4 with RestInfo

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()));
}
Also used : HttpStatus(org.apache.tapestry5.services.HttpStatus) RestInfo(org.apache.tapestry5.annotations.RestInfo)

Example 5 with RestInfo

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;
}
Also used : User(org.apache.tapestry5.rest.jackson.test.rest.entities.User) Attribute(org.apache.tapestry5.rest.jackson.test.rest.entities.Attribute) RestInfo(org.apache.tapestry5.annotations.RestInfo) OnEvent(org.apache.tapestry5.annotations.OnEvent)

Aggregations

RestInfo (org.apache.tapestry5.annotations.RestInfo)5 OnEvent (org.apache.tapestry5.annotations.OnEvent)1 JSONObject (org.apache.tapestry5.json.JSONObject)1 Attribute (org.apache.tapestry5.rest.jackson.test.rest.entities.Attribute)1 User (org.apache.tapestry5.rest.jackson.test.rest.entities.User)1 HttpStatus (org.apache.tapestry5.services.HttpStatus)1