use of org.raml.v2.api.model.v10.datamodel.ObjectTypeDeclaration in project raml-for-jax-rs by mulesoft-labs.
the class TypeUtilsTest method shouldExtendingAnotherWithProperties.
@Test
public void shouldExtendingAnotherWithProperties() throws Exception {
Map<String, GType> finder = finder("extendingAnotherWithProperties.raml");
ObjectTypeDeclaration object = (ObjectTypeDeclaration) finder.get("ObjectOne").implementation();
TypeDeclaration extending = findProperty(object, "name");
ObjectTypeDeclaration extended = (ObjectTypeDeclaration) finder.get(extending.type()).implementation();
assertTrue(TypeUtils.shouldCreateNewClass(extending, extended));
}
use of org.raml.v2.api.model.v10.datamodel.ObjectTypeDeclaration in project raml-for-jax-rs by mulesoft-labs.
the class TypeUtilsTest method shouldExtendingString.
@Test
public void shouldExtendingString() throws Exception {
ObjectTypeDeclaration typeDeclaration = (ObjectTypeDeclaration) finder("extendString.raml").get("ObjectOne").implementation();
TypeDeclaration property = findProperty(typeDeclaration, "name");
assertFalse(TypeUtils.shouldCreateNewClass(property, null));
}
use of org.raml.v2.api.model.v10.datamodel.ObjectTypeDeclaration in project raml-for-jax-rs by mulesoft-labs.
the class TypeUtilsTest method shouldExtendingObject.
@Test
public void shouldExtendingObject() throws Exception {
ObjectTypeDeclaration typeDeclaration = (ObjectTypeDeclaration) finder("extendObject.raml").get("ObjectOne").implementation();
TypeDeclaration property = findProperty(typeDeclaration, "name");
assertTrue(TypeUtils.shouldCreateNewClass(property, null));
}
use of org.raml.v2.api.model.v10.datamodel.ObjectTypeDeclaration 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;
}
}
Aggregations