Search in sources :

Example 6 with TypeDeclaration

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

the class V08Finder method typesInBodies.

private void typesInBodies(Resource resource, Method method, List<BodyLike> body, GFinderListener listener) {
    for (BodyLike typeDeclaration : body) {
        if (typeDeclaration.schema() == null) {
            continue;
        }
        if (globalSchemas.containsKey(typeDeclaration.schema().value())) {
            V08GType type = new V08GType(typeDeclaration.schema().value(), typeDeclaration);
            registry.addType(type);
            listener.newTypeDeclaration(type);
        } else {
            V08GType type = new V08GType(resource, method, typeDeclaration);
            registry.addType(type);
            listener.newTypeDeclaration(type);
        }
    }
    for (Response response : method.responses()) {
        for (BodyLike typeDeclaration : response.body()) {
            if (typeDeclaration.schema() == null) {
                continue;
            }
            if (globalSchemas.containsKey(typeDeclaration.schema().value())) {
                V08GType type = new V08GType(typeDeclaration.schema().value(), typeDeclaration);
                registry.addType(type);
                listener.newTypeDeclaration(type);
            } else {
                V08GType type = new V08GType(resource, method, response, typeDeclaration);
                registry.addType(type);
                listener.newTypeDeclaration(type);
            }
        }
    }
}
Also used : Response(org.raml.v2.api.model.v08.bodies.Response) BodyLike(org.raml.v2.api.model.v08.bodies.BodyLike)

Example 7 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 resource, Method method, Response response, 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 = fetchRamlToPojoBuilder().fetchType(Names.javaTypeName(resource, method, response, typeDeclaration), typeDeclaration);
        V10RamlToPojoGType type = new V10RamlToPojoGType(Names.javaTypeName(resource, method, response, typeDeclaration), typeDeclaration);
        type.setJavaType(typeName);
        return type;
    } else {
        TypeName typeName = fetchRamlToPojoBuilder().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 8 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 bigRaml.

@Test
public void bigRaml() throws Exception {
    Map<String, GType> finder = finder("big.raml");
    ObjectTypeDeclaration object = (ObjectTypeDeclaration) finder.get("RamlDataType").implementation();
    TypeDeclaration extending = findProperty(object, "NilValue");
    ObjectTypeDeclaration extended = (ObjectTypeDeclaration) finder.get(extending.type());
    assertTrue(TypeUtils.shouldCreateNewClass(extending, extended));
}
Also used : GType(org.raml.jaxrs.generator.ramltypes.GType) 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 9 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 shouldExtendingObjectWithProperties.

@Test
public void shouldExtendingObjectWithProperties() throws Exception {
    ObjectTypeDeclaration typeDeclaration = (ObjectTypeDeclaration) finder("extendObjectWithProperties.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 10 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 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));
}
Also used : GType(org.raml.jaxrs.generator.ramltypes.GType) 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)

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