Search in sources :

Example 11 with TypeDeclaration

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));
}
Also used : ObjectTypeDeclaration(org.raml.v2.api.model.v10.datamodel.ObjectTypeDeclaration) ObjectTypeDeclaration(org.raml.v2.api.model.v10.datamodel.ObjectTypeDeclaration) TypeDeclaration(org.raml.v2.api.model.v10.datamodel.TypeDeclaration) Test(org.junit.Test)

Example 12 with TypeDeclaration

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));
}
Also used : ObjectTypeDeclaration(org.raml.v2.api.model.v10.datamodel.ObjectTypeDeclaration) ObjectTypeDeclaration(org.raml.v2.api.model.v10.datamodel.ObjectTypeDeclaration) TypeDeclaration(org.raml.v2.api.model.v10.datamodel.TypeDeclaration) Test(org.junit.Test)

Example 13 with TypeDeclaration

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);
        }
    }
}
Also used : Resource(org.raml.v2.api.model.v10.resources.Resource) Method(org.raml.v2.api.model.v10.methods.Method)

Example 14 with TypeDeclaration

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;
    }
}
Also used : XMLTypeDeclaration(org.raml.v2.api.model.v10.datamodel.XMLTypeDeclaration) TypeName(com.squareup.javapoet.TypeName) V10RamlToPojoGType(org.raml.jaxrs.generator.v10.types.V10RamlToPojoGType) JSONTypeDeclaration(org.raml.v2.api.model.v10.datamodel.JSONTypeDeclaration)

Example 15 with TypeDeclaration

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;
    }
}
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

TypeDeclaration (org.raml.v2.api.model.v10.datamodel.TypeDeclaration)9 Test (org.junit.Test)8 ObjectTypeDeclaration (org.raml.v2.api.model.v10.datamodel.ObjectTypeDeclaration)8 GType (org.raml.jaxrs.generator.ramltypes.GType)4 TypeName (com.squareup.javapoet.TypeName)2 V10RamlToPojoGType (org.raml.jaxrs.generator.v10.types.V10RamlToPojoGType)2 JSONTypeDeclaration (org.raml.v2.api.model.v10.datamodel.JSONTypeDeclaration)2 XMLTypeDeclaration (org.raml.v2.api.model.v10.datamodel.XMLTypeDeclaration)2 BodyLike (org.raml.v2.api.model.v08.bodies.BodyLike)1 Response (org.raml.v2.api.model.v08.bodies.Response)1 Library (org.raml.v2.api.model.v10.api.Library)1 Response (org.raml.v2.api.model.v10.bodies.Response)1 FileTypeDeclaration (org.raml.v2.api.model.v10.datamodel.FileTypeDeclaration)1 Method (org.raml.v2.api.model.v10.methods.Method)1 Resource (org.raml.v2.api.model.v10.resources.Resource)1