use of api.Api in project raml-for-jax-rs by mulesoft-labs.
the class JustLoadTest method justLoad.
@Test
public void justLoad() throws URISyntaxException {
/*
* RamlModelResult ramlModelResult = new RamlModelBuilder().buildApi(new
* File(JustLoadTest.class.getResource("/jaxrs-test-resources.raml").toURI()));
*/
RamlModelResult ramlModelResult = new RamlModelBuilder().buildApi(new File("target/generated-sources/raml-jaxrs/jaxrs-test-resources.raml"));
if (ramlModelResult.hasErrors()) {
for (ValidationResult validationResult : ramlModelResult.getValidationResults()) {
System.out.println(validationResult.getMessage());
}
fail("Cant load");
}
Api api = ramlModelResult.getApiV10();
/*
* Api api = ramlModelResult.getApiV10(); ObjectTypeDeclaration otd = (ObjectTypeDeclaration) api.types().get(0);
* ArrayTypeDeclaration atd = (ArrayTypeDeclaration) otd.properties().get(0); ObjectTypeDeclaration arrayItems =
* (ObjectTypeDeclaration) atd.items(); System.err.println(arrayItems.type());
*/
}
use of api.Api in project raml-for-jax-rs by mulesoft-labs.
the class ModelEmitter method emit.
@Override
public void emit(RamlApi modelApi) throws RamlEmissionException {
supportedAnnotations = modelApi.getSupportedAnnotation();
topPackage = modelApi.getTopPackage();
org.raml.simpleemitter.Emitter emitter = new org.raml.simpleemitter.Emitter();
RamlDocumentBuilder documentBuilder = RamlDocumentBuilder.document();
try {
documentBuilder.title(modelApi.getTitle()).baseUri(modelApi.getBaseUri()).mediaType(modelApi.getDefaultMediaType().toStringRepresentation()).version(modelApi.getVersion());
annotationTypes(documentBuilder, modelApi);
resources(documentBuilder, modelApi);
typeRegistry.writeAll(supportedAnnotations, topPackage != null ? Package.getPackage(topPackage) : null, documentBuilder);
} catch (IOException e) {
throw new RamlEmissionException("trying to emit", e);
}
Api api = documentBuilder.buildModel();
final GrammarPhase grammarPhase = new GrammarPhase(RamlHeader.getFragmentRule(new RamlHeader(RAML_10, Default).getFragment()));
Node node = ((NodeModel) api).getNode();
grammarPhase.apply(node);
List<ErrorNode> errors = node.findDescendantsWith(ErrorNode.class);
for (ErrorNode error : errors) {
System.err.println("error: " + error.getErrorMessage());
}
if (errors.size() == 0) {
try {
emitter.emit(api, writer);
} catch (IOException e) {
throw new RamlEmissionException("trying to emit", e);
}
}
}
use of api.Api in project raml-for-jax-rs by mulesoft-labs.
the class RamlV08 method buildResourceV08.
public static void buildResourceV08(Object test, String raml, CodeContainer<TypeSpec> container, String name, String uri) throws IOException {
Api api = buildApiV08(test, raml);
V08TypeRegistry registry = new V08TypeRegistry();
V08Finder typeFinder = new V08Finder(api, new GAbstractionFactory(), registry);
CurrentBuild currentBuild = new CurrentBuild(null, ExtensionManager.createExtensionManager());
currentBuild.constructClasses(typeFinder);
ResourceBuilder builder = new ResourceBuilder(currentBuild, new V08GResource(new GAbstractionFactory(), api.resources().get(0), typeFinder.globalSchemas().keySet(), registry), name, uri);
builder.output(container);
}
use of api.Api 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 api.Api 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