Search in sources :

Example 1 with FileTypeDeclaration

use of org.raml.v2.api.model.v10.datamodel.FileTypeDeclaration in project raml-for-jax-rs by mulesoft-labs.

the class JerseyMultipartFormDataResourceExtension method onMethod.

@Override
public MethodSpec.Builder onMethod(ResourceContext context, GMethod method, GRequest gRequest, MethodSpec.Builder methodSpec) {
    if (gRequest != null && "multipart/form-data".equals(gRequest.mediaType())) {
        MethodSpec old = methodSpec.build();
        MethodSpec.Builder newMethod = MethodSpec.methodBuilder(old.name).returns(old.returnType);
        addExistingParameters(old, newMethod);
        for (AnnotationSpec annotation : old.annotations) {
            newMethod.addAnnotation(annotation);
        }
        for (TypeName exception : old.exceptions) {
            newMethod.addException(exception);
        }
        newMethod.addJavadoc("$L", old.javadoc);
        newMethod.addModifiers(old.modifiers);
        ObjectTypeDeclaration declaration = (ObjectTypeDeclaration) gRequest.type().implementation();
        for (TypeDeclaration property : declaration.properties()) {
            if (property instanceof FileTypeDeclaration) {
                newMethod.addParameter(ParameterSpec.builder(ClassName.get(InputStream.class), property.name() + "Stream").addAnnotation(AnnotationSpec.builder(ClassName.bestGuess("org.glassfish.jersey.media.multipart.FormDataParam")).addMember("value", "$S", property.name()).build()).build());
                newMethod.addParameter(ParameterSpec.builder(ClassName.bestGuess("org.glassfish.jersey.media.multipart.FormDataContentDisposition"), property.name() + "Disposition").addAnnotation(AnnotationSpec.builder(ClassName.bestGuess("org.glassfish.jersey.media.multipart.FormDataParam")).addMember("value", "$S", property.name()).build()).build());
            } else {
                TypeName typeName = context.fetchRamlToPojoBuilder().fetchType(property.type(), property);
                methodSpec.addParameter(ParameterSpec.builder(typeName, property.name()).addAnnotation(AnnotationSpec.builder(ClassName.bestGuess("org.glassfish.jersey.media.multipart.FormDataParam")).addMember("value", "$S", property.name()).build()).build());
            }
        }
        return newMethod;
    } else {
        return methodSpec;
    }
}
Also used : FileTypeDeclaration(org.raml.v2.api.model.v10.datamodel.FileTypeDeclaration) ObjectTypeDeclaration(org.raml.v2.api.model.v10.datamodel.ObjectTypeDeclaration) FileTypeDeclaration(org.raml.v2.api.model.v10.datamodel.FileTypeDeclaration) ObjectTypeDeclaration(org.raml.v2.api.model.v10.datamodel.ObjectTypeDeclaration) TypeDeclaration(org.raml.v2.api.model.v10.datamodel.TypeDeclaration)

Aggregations

FileTypeDeclaration (org.raml.v2.api.model.v10.datamodel.FileTypeDeclaration)1 ObjectTypeDeclaration (org.raml.v2.api.model.v10.datamodel.ObjectTypeDeclaration)1 TypeDeclaration (org.raml.v2.api.model.v10.datamodel.TypeDeclaration)1