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());
}
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);
}
}
}
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;
}
}
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());
}
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());
}
Aggregations