private static string GetRamlContents(string version)
        {
            var config = GlobalConfiguration.Configuration;
            var apiExplorer = config.Services.GetApiExplorer();
            var ramlVersion = (version == "0.8" ? RamlVersion.Version08 : RamlVersion.Version1);
            ApiExplorerService apiExplorerService;
            if (ramlVersion == RamlVersion.Version1)
                apiExplorerService = new ApiExplorerServiceVersion1(apiExplorer, config.VirtualPathRoot);
            else
                apiExplorerService = new ApiExplorerServiceVersion08(apiExplorer, config.VirtualPathRoot);

            var ramlDocument = apiExplorerService.GetRaml(ramlVersion);
            var ramlContents = new RamlSerializer().Serialize(ramlDocument);
            return ramlContents;
        }
Ejemplo n.º 2
0
        private static string GetRamlContents(string version)
        {
            var config      = GlobalConfiguration.Configuration;
            var apiExplorer = config.Services.GetApiExplorer();
            var ramlVersion = (version == "0.8" ? RamlVersion.Version08 : RamlVersion.Version1);
            ApiExplorerService apiExplorerService;

            if (ramlVersion == RamlVersion.Version1)
            {
                apiExplorerService = new ApiExplorerServiceVersion1(apiExplorer, config.VirtualPathRoot);
            }
            else
            {
                apiExplorerService = new ApiExplorerServiceVersion08(apiExplorer, config.VirtualPathRoot);
            }

            var ramlDocument = apiExplorerService.GetRaml(ramlVersion);
            var ramlContents = new RamlSerializer().Serialize(ramlDocument);

            return(ramlContents);
        }
        public virtual void OnResourceExecuting(ResourceExecutingContext context)
        {
            if (!IsRamlController(context))
            {
                return;
            }

            if (!IsRawAction(context))
            {
                return;
            }

            var ramlVersion = GetRamlVersion(context);

            ApiExplorerService apiExplorerService;

            if (ramlVersion == RamlVersion.Version1)
            {
                apiExplorerService = new ApiExplorerServiceVersion1(_descriptionProvider);
            }
            else
            {
                apiExplorerService = new ApiExplorerServiceVersion08(_descriptionProvider);
            }

            var ramlDocument = GetRamlContents(apiExplorerService);

            var raml   = new RamlSerializer().Serialize(ramlDocument);
            var result = new ContentResult
            {
                ContentType = "text/raml",
                Content     = raml,
                StatusCode  = 200
            };

            context.Result = result;
        }