From ec3395d97065bd63099bf4354352c27a3a0aff0b Mon Sep 17 00:00:00 2001 From: Suphonchai Phoonsawat Date: Tue, 29 Aug 2023 08:40:16 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B9=81=E0=B8=81=E0=B9=89=E0=B8=9B=E0=B8=B1?= =?UTF-8?q?=E0=B8=8D=E0=B8=AB=E0=B8=B2=20swagger=20=E0=B8=AA=E0=B8=A3?= =?UTF-8?q?=E0=B9=89=E0=B8=B2=E0=B8=87=20page=20Error=20=E0=B9=80=E0=B8=A1?= =?UTF-8?q?=E0=B8=B7=E0=B9=88=E0=B8=AD=E0=B9=83=E0=B8=8A=E0=B9=89=E0=B8=87?= =?UTF-8?q?=E0=B8=B2=E0=B8=99=20WebREportDesigner=20****=20=E0=B8=A2?= =?UTF-8?q?=E0=B8=B1=E0=B8=87=E0=B9=84=E0=B8=A1=E0=B9=88=E0=B9=84=E0=B8=94?= =?UTF-8?q?=E0=B9=89=20=E0=B9=80=E0=B8=A5=E0=B8=A2=E0=B9=80=E0=B8=AD?= =?UTF-8?q?=E0=B8=B2=E0=B8=AD=E0=B8=AD=E0=B8=81=E0=B8=88=E0=B8=B2=E0=B8=81?= =?UTF-8?q?=E0=B8=A3=E0=B8=B0=E0=B8=9A=E0=B8=9A=E0=B9=84=E0=B8=9B=E0=B8=81?= =?UTF-8?q?=E0=B9=88=E0=B8=AD=E0=B8=99=20*****?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Commands/CommandRepository.cs | 4 +-- .../BMA.EHR.Report.Service.csproj | 10 +++--- .../ConfigureSwaggerOptions.cs | 9 ++++-- .../Controllers/InsigniaReportController.cs | 8 ----- .../Controllers/ReportDesignerController.cs | 17 ---------- BMA.EHR.Report.Service/OpenApiIgnoreFilter.cs | 31 +++++++++++++++++++ BMA.EHR.Report.Service/Program.cs | 28 ++++------------- 7 files changed, 52 insertions(+), 55 deletions(-) delete mode 100644 BMA.EHR.Report.Service/Controllers/ReportDesignerController.cs create mode 100644 BMA.EHR.Report.Service/OpenApiIgnoreFilter.cs diff --git a/BMA.EHR.Application/Repositories/Commands/CommandRepository.cs b/BMA.EHR.Application/Repositories/Commands/CommandRepository.cs index b20e9dc4..69c99f0c 100644 --- a/BMA.EHR.Application/Repositories/Commands/CommandRepository.cs +++ b/BMA.EHR.Application/Repositories/Commands/CommandRepository.cs @@ -128,7 +128,7 @@ namespace BMA.EHR.Application.Repositories.Commands var seq = 1; foreach (var item in appointPeople) { - if (!(await CheckIsActiveOfficer(item.CitizenId!))) + if (!(await CheckIsActiveOfficerAsync(item.CitizenId!))) { var receiver = new CommandReceiver { @@ -192,7 +192,7 @@ namespace BMA.EHR.Application.Repositories.Commands var seq = 1; foreach (var item in appointPeople) { - if (!(await CheckIsActiveOfficer(item.CitizenId!))) + if (!(await CheckIsActiveOfficerAsync(item.CitizenId!))) { var receiver = new CommandReceiver { diff --git a/BMA.EHR.Report.Service/BMA.EHR.Report.Service.csproj b/BMA.EHR.Report.Service/BMA.EHR.Report.Service.csproj index 06c0b58a..0d1ad60c 100644 --- a/BMA.EHR.Report.Service/BMA.EHR.Report.Service.csproj +++ b/BMA.EHR.Report.Service/BMA.EHR.Report.Service.csproj @@ -11,6 +11,10 @@ BMA.EHR.Report.Service + + + + @@ -29,7 +33,7 @@ runtime; build; native; contentfiles; analyzers; buildtransitive - + @@ -41,10 +45,8 @@ - - - + diff --git a/BMA.EHR.Report.Service/ConfigureSwaggerOptions.cs b/BMA.EHR.Report.Service/ConfigureSwaggerOptions.cs index 18f4a719..17919338 100644 --- a/BMA.EHR.Report.Service/ConfigureSwaggerOptions.cs +++ b/BMA.EHR.Report.Service/ConfigureSwaggerOptions.cs @@ -1,4 +1,5 @@ -using Microsoft.AspNetCore.Mvc.ApiExplorer; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.ApiExplorer; using Microsoft.Extensions.Options; using Microsoft.OpenApi.Models; using Swashbuckle.AspNetCore.SwaggerGen; @@ -19,6 +20,9 @@ namespace BMA.EHR.Report.Service public void Configure(SwaggerGenOptions options) { // add swagger document for every API version discovered + + + foreach (var description in _provider.ApiVersionDescriptions) { options.EnableAnnotations(); @@ -26,8 +30,9 @@ namespace BMA.EHR.Report.Service options.SwaggerDoc( description.GroupName, CreateVersionInfo(description)); - } + + } options.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme { In = ParameterLocation.Header, diff --git a/BMA.EHR.Report.Service/Controllers/InsigniaReportController.cs b/BMA.EHR.Report.Service/Controllers/InsigniaReportController.cs index c6136721..dd9b8c83 100644 --- a/BMA.EHR.Report.Service/Controllers/InsigniaReportController.cs +++ b/BMA.EHR.Report.Service/Controllers/InsigniaReportController.cs @@ -1,15 +1,7 @@ using BMA.EHR.Domain.Common; -using BMA.EHR.Domain.Extensions; -using BMA.EHR.Domain.Shared; -using BMA.EHR.Application.Repositories.Reports; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.Mvc.ModelBinding.Binders; using Swashbuckle.AspNetCore.Annotations; -using DocumentFormat.OpenXml.Drawing; -using Telerik.Reporting; -using Telerik.Reporting.Processing; -using System.IO; namespace BMA.EHR.Report.Service.Controllers { diff --git a/BMA.EHR.Report.Service/Controllers/ReportDesignerController.cs b/BMA.EHR.Report.Service/Controllers/ReportDesignerController.cs deleted file mode 100644 index 1bbdf12a..00000000 --- a/BMA.EHR.Report.Service/Controllers/ReportDesignerController.cs +++ /dev/null @@ -1,17 +0,0 @@ -using Microsoft.AspNetCore.Mvc; -using Telerik.Reporting.Services; -using Telerik.WebReportDesigner.Services; -using Telerik.WebReportDesigner.Services.Controllers; - -namespace BMA.EHR.Report.Service.Controllers -{ - [Route("api/reportdesigner")] - public class ReportDesignerController : ReportDesignerControllerBase - { - public ReportDesignerController(IReportDesignerServiceConfiguration reportDesignerServiceConfiguration, - IReportServiceConfiguration reportServiceConfiguration) - : base(reportDesignerServiceConfiguration, reportServiceConfiguration) - { - } - } -} diff --git a/BMA.EHR.Report.Service/OpenApiIgnoreFilter.cs b/BMA.EHR.Report.Service/OpenApiIgnoreFilter.cs new file mode 100644 index 00000000..6a7aa28d --- /dev/null +++ b/BMA.EHR.Report.Service/OpenApiIgnoreFilter.cs @@ -0,0 +1,31 @@ +using Microsoft.AspNetCore.Mvc.Controllers; +using Microsoft.OpenApi.Models; +using NSwag.Annotations; +using Swashbuckle.AspNetCore.SwaggerGen; +using System.Reflection; + +namespace BMA.EHR.Report.Service +{ + public class OpenApiIgnoreFilter: IDocumentFilter + { + public void Apply(OpenApiDocument swaggerDoc, DocumentFilterContext context) + { + foreach (var apiDescription in context.ApiDescriptions) + { + var actionDescriptor = apiDescription.ActionDescriptor as ControllerActionDescriptor; + if (actionDescriptor != null) + { + var ignoreAttribute = actionDescriptor.MethodInfo.GetCustomAttribute(); + if (ignoreAttribute != null) + { + var routeKey = "/" + apiDescription.RelativePath.TrimEnd('/'); + if (swaggerDoc.Paths.ContainsKey(routeKey)) + { + swaggerDoc.Paths.Remove(routeKey); + } + } + } + } + } + } +} diff --git a/BMA.EHR.Report.Service/Program.cs b/BMA.EHR.Report.Service/Program.cs index 0ae0e309..b29da486 100644 --- a/BMA.EHR.Report.Service/Program.cs +++ b/BMA.EHR.Report.Service/Program.cs @@ -8,7 +8,6 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.ApiExplorer; using Microsoft.AspNetCore.Mvc.Versioning; using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.DependencyInjection.Extensions; using Microsoft.IdentityModel.Logging; using Microsoft.IdentityModel.Tokens; using Serilog; @@ -16,9 +15,6 @@ using Serilog.Exceptions; using Serilog.Sinks.Elasticsearch; using System.Reflection; using System.Text; -using Telerik.Reporting.Cache.File; -using Telerik.Reporting.Services; -using Telerik.WebReportDesigner.Services; var builder = WebApplication.CreateBuilder(args); { @@ -92,28 +88,16 @@ var builder = WebApplication.CreateBuilder(args); }) .AddNewtonsoftJson(x => x.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore); - builder.Services.AddSwaggerGen(); + builder.Services.AddSwaggerGen(c => + { + c.IgnoreObsoleteActions(); + c.ResolveConflictingActions(apiDescriptions => apiDescriptions.First()); + }); builder.Services.ConfigureOptions(); builder.Services.AddHealthChecks(); - // For Telerik Report Designer - builder.Services.TryAddSingleton(sp => - new ReportServiceConfiguration - { - ReportingEngineConfiguration = ResolveSpecificReportingConfiguration(sp.GetService()), - HostAppId = "ReportingCoreApp", - Storage = new FileStorage(), - ReportSourceResolver = new TypeReportSourceResolver().AddFallbackResolver - (new UriReportSourceResolver(Path.Combine(sp.GetService().ContentRootPath, "Reports"))) - }); - builder.Services.TryAddSingleton(sp => new ReportDesignerServiceConfiguration - { - DefinitionStorage = new FileDefinitionStorage(Path.Combine(sp.GetService().ContentRootPath, "Reports"), new[] { "Resources", "Shared Data Sources" }), - ResourceStorage = new ResourceStorage(Path.Combine(sp.GetService().ContentRootPath, "Reports", "Resources")), - SharedDataSourceStorage = new FileSharedDataSourceStorage(Path.Combine(sp.GetService().ContentRootPath, "Reports", "Shared Data Sources")), - SettingsStorage = new FileSettingsStorage(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Telerik Reporting")) - }); + }