Search in sources :

Example 6 with Api

use of org.raml.v2.api.model.v08.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());
     */
}
Also used : RamlModelBuilder(org.raml.v2.api.RamlModelBuilder) Api(org.raml.v2.api.model.v10.api.Api) RamlModelResult(org.raml.v2.api.RamlModelResult) ValidationResult(org.raml.v2.api.model.common.ValidationResult) File(java.io.File) Test(org.junit.Test)

Example 7 with Api

use of org.raml.v2.api.model.v08.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);
        }
    }
}
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)

Example 8 with Api

use of org.raml.v2.api.model.v08.api.Api 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());
}
Also used : Resource(org.raml.v2.api.model.v10.resources.Resource) ResourceHandler(org.raml.jaxrs.generator.v10.ResourceHandler) V10Finder(org.raml.jaxrs.generator.v10.V10Finder)

Example 9 with Api

use of org.raml.v2.api.model.v08.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);
}
Also used : ResourceBuilder(org.raml.jaxrs.generator.builders.resources.ResourceBuilder) V08Finder(org.raml.jaxrs.generator.v08.V08Finder) CurrentBuild(org.raml.jaxrs.generator.CurrentBuild) V08GResource(org.raml.jaxrs.generator.v08.V08GResource) GAbstractionFactory(org.raml.jaxrs.generator.GAbstractionFactory) V08TypeRegistry(org.raml.jaxrs.generator.v08.V08TypeRegistry) Api(org.raml.v2.api.model.v08.api.Api)

Example 10 with Api

use of org.raml.v2.api.model.v08.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());
}
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

Api (org.raml.v2.api.model.v10.api.Api)9 Test (org.junit.Test)7 CurrentBuild (org.raml.jaxrs.generator.CurrentBuild)6 GAbstractionFactory (org.raml.jaxrs.generator.GAbstractionFactory)6 TrialResourceClassExtension (org.raml.jaxrs.generator.builders.extensions.resources.TrialResourceClassExtension)2 ResourceBuilder (org.raml.jaxrs.generator.builders.resources.ResourceBuilder)2 GRequest (org.raml.jaxrs.generator.ramltypes.GRequest)2 GResponseType (org.raml.jaxrs.generator.ramltypes.GResponseType)2 V10Finder (org.raml.jaxrs.generator.v10.V10Finder)2 Api (api.Api)1 File (java.io.File)1 IOException (java.io.IOException)1 ParameterEmitter (org.raml.jaxrs.emitters.ParameterEmitter)1 TrialResourceMethodExtension (org.raml.jaxrs.generator.builders.extensions.resources.TrialResourceMethodExtension)1 TrialResponseClassExtension (org.raml.jaxrs.generator.builders.extensions.resources.TrialResponseClassExtension)1 TrialResponseMethodExtension (org.raml.jaxrs.generator.builders.extensions.resources.TrialResponseMethodExtension)1 V08Finder (org.raml.jaxrs.generator.v08.V08Finder)1 V08GResource (org.raml.jaxrs.generator.v08.V08GResource)1 V08TypeRegistry (org.raml.jaxrs.generator.v08.V08TypeRegistry)1 ResourceHandler (org.raml.jaxrs.generator.v10.ResourceHandler)1