public override IEndpointConventionBuilder MapApiDocument(string name, string title, string description, string version)
        {
            var assembly = typeof(TModule).Assembly;

            ServiceProvider
            .GetRequiredService <SubstrateApiVisibilityConvention>()
            .Declare(assembly.FullName !, name);

            var sgo = ServiceProvider.GetRequiredService <IOptions <SwaggerGenOptions> >().Value;

            sgo.SwaggerDoc(name,
                           new Microsoft.OpenApi.Models.OpenApiInfo
            {
                Title       = title,
                Description = description,
                Version     = version,
            });

            var file = System.IO.Path.ChangeExtension(assembly.Location, "xml");

            if (System.IO.File.Exists(file))
            {
                sgo.IncludeXmlComments(file);
            }
            else
            {
                ServiceProvider
                .GetRequiredService <ILoggerFactory>()
                .CreateLogger("Microsoft.Hosting.Lifetime")
                .LogWarning($"Documentation '{file}' is not found. Specification comments will not be registered into swagger.");
            }

            var actionLazy = new ControllerActionDescriptorWrapper("Dashboard", "ApiDoc", "Display");

            return(MapRequestDelegate(
                       "/api/doc/" + name, context =>
            {
                var routeData = new RouteData();
                routeData.PushState(router: null, context.Request.RouteValues, new RouteValueDictionary());
                routeData.Values["name"] = name;
                var actionContext = new ActionContext(context, routeData, actionLazy.GetValue(context.RequestServices));

                var invoker = context.RequestServices
                              .GetRequiredService <IActionInvokerFactory>()
                              .CreateInvoker(actionContext);

                return invoker.InvokeAsync();
            })
                   .WithDisplayName($"Swagger Document ({name})")
                   .WithMetadata(new HttpMethodMetadata(new[] { "GET" })));
        }
 public DefaultErrorHandlerBuilder(ControllerActionDescriptorWrapper actionDescriptor, IEndpointBuilder builder)
 {
     ActionDescriptor = actionDescriptor;
     Builder          = builder;
 }
Exemple #3
0
        public IErrorHandlerBuilder WithErrorHandler(string area, string controller, string action)
        {
            var ad = new ControllerActionDescriptorWrapper(area, controller, action);

            return(new DefaultErrorHandlerBuilder(ad, this));
        }