/**
  * Generate a raml file describing the application.
  *
  * @param ApplicationManifestInterface $manifest
  * @param RamlEncoderOptions $options
  *
  * @return string
  */
 public function encode(ApplicationManifestInterface $manifest, RamlEncoderOptions $options = null)
 {
     $options = Std::coalesceThunk($options, function () use($manifest) {
         if ($manifest->hasProperty('ramlEncoderOptions')) {
             return $manifest->getProperty('ramlEncoderOptions');
         }
         return RamlEncoderOptions::defaultOptions();
     });
     $root = ['title' => $manifest->getName(), 'version' => $manifest->getCurrentVersion(), 'mediaType' => 'application/json', 'baseUri' => $manifest->getBaseUri()];
     if (count($manifest->getProse())) {
         foreach ($manifest->getProse() as $title => $content) {
             $root['documentation'][] = ['title' => $title, 'content' => $content];
         }
     }
     foreach ($manifest->getApiResources() as $resource) {
         $path = $resource->getPrefix();
         if ($path == '') {
             $path = '/';
         }
         if (Arr::has($root, $path)) {
             $root[$path] = Arr::merge($root[$path], $this->encodeResource($resource, $options));
             continue;
         }
         $root[$path] = $this->encodeResource($resource, $options);
     }
     if ($options !== null) {
         $root['securitySchemes'] = Std::map(function ($scheme) {
             $result = [];
             foreach ($scheme as $key => $property) {
                 $result[$key] = $property->toArray();
             }
             return $result;
         }, $options->getSecuritySchemes());
     }
     $yaml = yaml_emit(RamlUtils::filterEmptyValues($root));
     return str_replace("---\n", "#%RAML 0.8\n", $yaml);
 }