Search in sources :

Example 1 with NodeModel

use of org.raml.yagi.framework.model.NodeModel 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);
        }
    }
}
Also used : ParameterEmitter(org.raml.jaxrs.emitters.ParameterEmitter) GrammarPhase(org.raml.yagi.framework.phase.GrammarPhase) ErrorNode(org.raml.yagi.framework.nodes.ErrorNode) Node(org.raml.yagi.framework.nodes.Node) IOException(java.io.IOException) NodeModel(org.raml.yagi.framework.model.NodeModel) RamlHeader(org.raml.v2.internal.impl.commons.RamlHeader) ErrorNode(org.raml.yagi.framework.nodes.ErrorNode) Api(org.raml.v2.api.model.v10.api.Api)

Aggregations

IOException (java.io.IOException)1 ParameterEmitter (org.raml.jaxrs.emitters.ParameterEmitter)1 Api (org.raml.v2.api.model.v10.api.Api)1 RamlHeader (org.raml.v2.internal.impl.commons.RamlHeader)1 NodeModel (org.raml.yagi.framework.model.NodeModel)1 ErrorNode (org.raml.yagi.framework.nodes.ErrorNode)1 Node (org.raml.yagi.framework.nodes.Node)1 GrammarPhase (org.raml.yagi.framework.phase.GrammarPhase)1