private Map.Entry<String, Template> getTemplate(final Raml context, final String name) { final Optional<Map<String, Template>> templateEntry = FluentIterable.from(context.getTraits()) .firstMatch(new Predicate<Map<String, Template>>() { @Override public boolean apply(final Map<String, Template> input) { return Iterables.getFirst(input.keySet(), null).equalsIgnoreCase(name); } }); if (templateEntry.isPresent()) { final Optional<Template> template = templateEntry.transform(new Function<Map<String, Template>, Template>() { @Override public Template apply(final Map<String, Template> input) { return Iterables.getFirst(input.values(), null); } }); if (template.isPresent()) { return Maps.immutableEntry(name, template.get()); } } throw new IllegalArgumentException( "Could not find the trait '" + name + "' for the RAML's traits, please check whether you have added this trait (" + name + ") declaration in the traits section."); }
AssertJUnit.assertNotNull("RAML for Stability.raml not parseable", raml); List<Map<String,Template>> traits = raml.getTraits(); AssertJUnit.assertNotNull("RAML expected to define traits", traits); AssertJUnit.assertEquals("RAML expected to define 2 traits", 2, traits.size());
protected API transformAPI(final Context context, final org.raml.model.Raml source, final org.raml.model.Resource sourceResourceRoot, final JSONSchemaStore store, final APINamespace namespace, final boolean async) { final APIBuilder apiBuilder = API.builder(); apiBuilder.namespace(namespace); apiBuilder.name(source.getTitle()); apiBuilder.qualifier(transformAPIName(sourceResourceRoot)); apiBuilder.path(transformAPIPath(source, sourceResourceRoot)); apiBuilder.baseUri(source.getBaseUri()); apiBuilder.async(async); final List<DocumentationItem> items = source.getDocumentation(); if (items != null && !items.isEmpty()) { apiBuilder.description(source.getDocumentation().get(0).getContent()); } final TransformationContext ctx = new TransformationContext(namespace, source, store); apiBuilder.parameterGroups(traitsTransformer.transform(context, source.getTraits(), ctx)); apiBuilder.types(dtosTransformer.transform(context, ctx)); if (!context.isCompatibilityModeDisabled()) { apiBuilder.types(enumerationsTransformer.transform(context, ctx)); } apiBuilder.resource(singleResourceTransformer.transform(context, sourceResourceRoot, ctx)); return apiBuilder.build(); }