use of org.raml.yagi.framework.nodes.Node 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);
}
}
}
Aggregations