Search in sources :

Example 6 with Resource

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

the class RamlScanner method handle.

public void handle(org.raml.v2.api.model.v10.api.Api api) throws IOException {
    CurrentBuild build = new CurrentBuild(api, ExtensionManager.createExtensionManager());
    configuration.setupBuild(build);
    build.constructClasses(new V10Finder(build, api));
    ResourceHandler resourceHandler = new ResourceHandler(build);
    // handle resources.
    for (Resource resource : api.resources()) {
        resourceHandler.handle(resource);
    }
    build.generate(configuration.getOutputDirectory());
}
Also used : Resource(org.raml.v2.api.model.v10.resources.Resource) ResourceHandler(org.raml.jaxrs.generator.v10.ResourceHandler) V10Finder(org.raml.jaxrs.generator.v10.V10Finder)

Example 7 with Resource

use of org.raml.v2.api.model.v10.resources.Resource 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 8 with Resource

use of org.raml.v2.api.model.v10.resources.Resource 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 9 with Resource

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

the class V10GResourceTest method simpleResponse.

@Test
public void simpleResponse() throws Exception {
    Api api = RamlV10.buildApiV10(this, "resource-response-simple.raml");
    GAbstractionFactory fac = new GAbstractionFactory();
    V10GResource gr = new V10GResource(new CurrentBuild(api, null), fac, api.resources().get(0));
    GResponseType resp = gr.methods().get(0).responses().get(0).body().get(0);
    assertEquals("application/json", resp.mediaType());
    assertEquals("ObjectBase", resp.type().type());
    assertEquals("ObjectBase", resp.type().name());
}
Also used : CurrentBuild(org.raml.jaxrs.generator.CurrentBuild) GAbstractionFactory(org.raml.jaxrs.generator.GAbstractionFactory) GResponseType(org.raml.jaxrs.generator.ramltypes.GResponseType) Api(org.raml.v2.api.model.v10.api.Api) Test(org.junit.Test)

Example 10 with Resource

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

the class V10GResourceTest method extendingResponse.

@Test
public void extendingResponse() throws Exception {
    Api api = RamlV10.buildApiV10(this, "resource-response-extending.raml");
    GAbstractionFactory fac = new GAbstractionFactory();
    V10GResource gr = new V10GResource(new CurrentBuild(api, null), fac, api.resources().get(0));
    GResponseType req = gr.methods().get(0).responses().get(0).body().get(0);
    assertEquals("application/json", req.mediaType());
    assertEquals("ObjectBase", req.type().type());
    assertEquals("FunPut200ApplicationJson", req.type().name());
    assertEquals("model.FunPut200ApplicationJson", req.type().defaultJavaTypeName("").toString());
}
Also used : CurrentBuild(org.raml.jaxrs.generator.CurrentBuild) GAbstractionFactory(org.raml.jaxrs.generator.GAbstractionFactory) GResponseType(org.raml.jaxrs.generator.ramltypes.GResponseType) Api(org.raml.v2.api.model.v10.api.Api) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)4 CurrentBuild (org.raml.jaxrs.generator.CurrentBuild)4 GAbstractionFactory (org.raml.jaxrs.generator.GAbstractionFactory)4 Api (org.raml.v2.api.model.v10.api.Api)4 TypeName (com.squareup.javapoet.TypeName)2 GRequest (org.raml.jaxrs.generator.ramltypes.GRequest)2 GResponseType (org.raml.jaxrs.generator.ramltypes.GResponseType)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 Resource (org.raml.v2.api.model.v10.resources.Resource)2 ResourceHandler (org.raml.jaxrs.generator.v10.ResourceHandler)1 V10Finder (org.raml.jaxrs.generator.v10.V10Finder)1 BodyLike (org.raml.v2.api.model.v08.bodies.BodyLike)1 Response (org.raml.v2.api.model.v08.bodies.Response)1 Response (org.raml.v2.api.model.v10.bodies.Response)1 Method (org.raml.v2.api.model.v10.methods.Method)1