Search in sources :

Example 1 with Response

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

the class V10Finder method typesInBodies.

private void typesInBodies(Resource resource, Method method, List<TypeDeclaration> body, GFinderListener listener) {
    for (TypeDeclaration typeDeclaration : body) {
        if (!isInline(typeDeclaration)) {
            continue;
        }
        V10GType type = createInlineFromResourcesAndSuch(Names.ramlTypeName(resource, method, typeDeclaration), Names.javaTypeName(resource, method, typeDeclaration), typeDeclaration);
        listener.newTypeDeclaration(type);
    }
    for (TypeDeclaration parameterTypeDeclaration : method.queryParameters()) {
        if (!isInline(parameterTypeDeclaration)) {
            continue;
        }
        V10GType type = createInlineFromResourcesAndSuch(Names.ramlTypeName(resource, method, parameterTypeDeclaration), Names.javaTypeName(resource, method, parameterTypeDeclaration), parameterTypeDeclaration);
        listener.newTypeDeclaration(type);
    }
    for (TypeDeclaration headerType : method.headers()) {
        if (!isInline(headerType)) {
            continue;
        }
        V10GType type = createInlineFromResourcesAndSuch(Names.ramlTypeName(resource, method, headerType), Names.javaTypeName(resource, method, headerType), headerType);
        listener.newTypeDeclaration(type);
    }
    for (Response response : method.responses()) {
        for (TypeDeclaration typeDeclaration : response.body()) {
            if (!isInline(typeDeclaration)) {
                continue;
            }
            V10GType type = createInlineFromResourcesAndSuch(Names.ramlTypeName(resource, method, response, typeDeclaration), Names.javaTypeName(resource, method, response, typeDeclaration), typeDeclaration);
            listener.newTypeDeclaration(type);
        }
    }
}
Also used : Response(org.raml.v2.api.model.v10.bodies.Response)

Example 2 with Response

use of org.raml.v2.api.model.v10.bodies.Response 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 3 with Response

use of org.raml.v2.api.model.v10.bodies.Response 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 4 with Response

use of org.raml.v2.api.model.v10.bodies.Response 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 5 with Response

use of org.raml.v2.api.model.v10.bodies.Response 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)2 CurrentBuild (org.raml.jaxrs.generator.CurrentBuild)2 GAbstractionFactory (org.raml.jaxrs.generator.GAbstractionFactory)2 GResponseType (org.raml.jaxrs.generator.ramltypes.GResponseType)2 Api (org.raml.v2.api.model.v10.api.Api)2 TypeName (com.squareup.javapoet.TypeName)1 V10RamlToPojoGType (org.raml.jaxrs.generator.v10.types.V10RamlToPojoGType)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 JSONTypeDeclaration (org.raml.v2.api.model.v10.datamodel.JSONTypeDeclaration)1 XMLTypeDeclaration (org.raml.v2.api.model.v10.datamodel.XMLTypeDeclaration)1