use of org.raml.v2.api.model.v10.datamodel.TypeDeclaration 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.TypeDeclaration 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.TypeDeclaration in project raml-for-jax-rs by mulesoft-labs.
the class V10Finder method resourceTypes.
private void resourceTypes(List<Resource> resources, GFinderListener listener) {
for (Resource resource : resources) {
resourceTypes(resource.resources(), listener);
for (TypeDeclaration parameterTypeDeclaration : resource.uriParameters()) {
if (!isInline(parameterTypeDeclaration)) {
continue;
}
V10GType type = createInlineFromResourcesAndSuch(Names.ramlTypeName(resource, parameterTypeDeclaration), Names.javaTypeName(resource, parameterTypeDeclaration), parameterTypeDeclaration);
listener.newTypeDeclaration(type);
}
for (Method method : resource.methods()) {
typesInBodies(resource, method, method.body(), listener);
}
}
}
use of org.raml.v2.api.model.v10.datamodel.TypeDeclaration in project raml-for-jax-rs by mulesoft-labs.
the class CurrentBuild method fetchType.
public V10GType fetchType(Resource implementation, Method method, TypeDeclaration typeDeclaration) {
if (typeDeclaration instanceof JSONTypeDeclaration) {
return (V10GType) ((JsonSchemaTypeGenerator) builtTypes.get(typeDeclaration.type())).getType();
}
if (typeDeclaration instanceof XMLTypeDeclaration) {
return (V10GType) ((XmlSchemaTypeGenerator) builtTypes.get(typeDeclaration.type())).getType();
}
RamlToPojo ramlToPojo = fetchRamlToPojoBuilder();
if (ramlToPojo.isInline(typeDeclaration)) {
TypeName typeName = ramlToPojo.fetchType(Names.javaTypeName(implementation, method, typeDeclaration), typeDeclaration);
V10RamlToPojoGType type = new V10RamlToPojoGType(Names.javaTypeName(implementation, method, typeDeclaration), typeDeclaration);
type.setJavaType(typeName);
return type;
} else {
TypeName typeName = ramlToPojo.fetchType(typeDeclaration.type(), typeDeclaration);
V10RamlToPojoGType type = new V10RamlToPojoGType(typeDeclaration.type(), typeDeclaration);
type.setJavaType(typeName);
return type;
}
}
use of org.raml.v2.api.model.v10.datamodel.TypeDeclaration 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