From 612b3e67e11cb1ffc6c0f1ac7dfd80dd4755ca15 Mon Sep 17 00:00:00 2001 From: David Kallesen Date: Sat, 10 Aug 2024 00:38:31 +0200 Subject: [PATCH 1/2] feat: rename GenerateServiceCollectionExtensions to GenerateServiceCollectionEndpointHandlerExtensions and cleanup for minimal api --- .../ContentGeneratorServerProgram.cs | 2 +- .../ProjectGenerator/ServerDomainGenerator.cs | 38 ++++--------------- .../ProjectGenerator/ServerDomainGenerator.cs | 4 +- .../IServerDomainGenerator.cs | 2 +- .../Generators/ServerDomainGenerator.cs | 2 +- 5 files changed, 12 insertions(+), 36 deletions(-) diff --git a/src/Atc.Rest.ApiGenerator.Framework.Minimal/ContentGenerators/ContentGeneratorServerProgram.cs b/src/Atc.Rest.ApiGenerator.Framework.Minimal/ContentGenerators/ContentGeneratorServerProgram.cs index 5103691c..010f6b20 100644 --- a/src/Atc.Rest.ApiGenerator.Framework.Minimal/ContentGenerators/ContentGeneratorServerProgram.cs +++ b/src/Atc.Rest.ApiGenerator.Framework.Minimal/ContentGenerators/ContentGeneratorServerProgram.cs @@ -31,7 +31,7 @@ public string Generate() sb.AppendLine(); sb.AppendLine(8, "services.AddMemoryCache();"); sb.AppendLine(); - sb.AppendLine(8, "services.ConfigureDomainServices(builder.Configuration);"); + sb.AppendLine(8, "services.ConfigureDomainHandlers(builder.Configuration);"); sb.AppendLine(); sb.AppendLine(8, "services.AddValidatorsFromAssemblyContaining(ServiceLifetime.Singleton);"); sb.AppendLine(); diff --git a/src/Atc.Rest.ApiGenerator.Framework.Minimal/ProjectGenerator/ServerDomainGenerator.cs b/src/Atc.Rest.ApiGenerator.Framework.Minimal/ProjectGenerator/ServerDomainGenerator.cs index 1d9dd6ed..6c364806 100644 --- a/src/Atc.Rest.ApiGenerator.Framework.Minimal/ProjectGenerator/ServerDomainGenerator.cs +++ b/src/Atc.Rest.ApiGenerator.Framework.Minimal/ProjectGenerator/ServerDomainGenerator.cs @@ -169,7 +169,7 @@ public void GenerateAssemblyMarker() content); } - public void GenerateServiceCollectionExtensions() + public void GenerateServiceCollectionEndpointHandlerExtensions() { var sbServicesHandlerRegistrations = new StringBuilder(); foreach (var urlPath in openApiDocument.Paths) @@ -182,13 +182,16 @@ public void GenerateServiceCollectionExtensions() } } + sbServicesHandlerRegistrations.AppendLine(); + sbServicesHandlerRegistrations.AppendLine("return services;"); + var methodConfigureDomainServices = new MethodParameters( DocumentationTags: null, Attributes: null, AccessModifiers.PublicStatic, ReturnGenericTypeName: null, ReturnTypeName: "IServiceCollection", - Name: "ConfigureDomainServices", + Name: "ConfigureDomainHandlers", Parameters: [ new( @@ -212,32 +215,6 @@ public void GenerateServiceCollectionExtensions() ], AlwaysBreakDownParameters: true, UseExpressionBody: false, - Content: """ - services.DefineHandlersAndServices(); - return services; - """); - - var methodDefineHandlersAndServices = new MethodParameters( - DocumentationTags: null, - Attributes: null, - AccessModifiers.PublicStatic, - ReturnGenericTypeName: null, - ReturnTypeName: "void", - Name: "DefineHandlersAndServices", - Parameters: - [ - new( - Attributes: null, - GenericTypeName: null, - IsGenericListType: false, - TypeName: "this IServiceCollection", - IsNullableType: false, - IsReferenceType: false, - Name: "services", - DefaultValue: null), - ], - AlwaysBreakDownParameters: true, - UseExpressionBody: false, Content: sbServicesHandlerRegistrations.ToString()); var classParameters = new ClassParameters( @@ -246,7 +223,7 @@ public void GenerateServiceCollectionExtensions() DocumentationTags: null, Attributes: [codeGeneratorAttribute], AccessModifiers.PublicStaticClass, - ClassTypeName: "ServiceCollectionExtensions", + ClassTypeName: "ServiceCollectionEndpointHandlerExtensions", GenericTypeName: null, InheritedClassTypeName: null, InheritedGenericClassTypeName: null, @@ -256,7 +233,6 @@ public void GenerateServiceCollectionExtensions() Methods: [ methodConfigureDomainServices, - methodDefineHandlersAndServices, ], GenerateToStringMethod: false); @@ -269,7 +245,7 @@ public void GenerateServiceCollectionExtensions() var contentWriter = new ContentWriter(logger); contentWriter.Write( projectPath, - projectPath.CombineFileInfo("Extensions", "ServiceCollectionExtensions.cs"), + projectPath.CombineFileInfo("Extensions", "ServiceCollectionEndpointHandlerExtensions.cs"), ContentWriterArea.Src, content); } diff --git a/src/Atc.Rest.ApiGenerator.Framework.Mvc/ProjectGenerator/ServerDomainGenerator.cs b/src/Atc.Rest.ApiGenerator.Framework.Mvc/ProjectGenerator/ServerDomainGenerator.cs index a0dd79de..9c90ffc5 100644 --- a/src/Atc.Rest.ApiGenerator.Framework.Mvc/ProjectGenerator/ServerDomainGenerator.cs +++ b/src/Atc.Rest.ApiGenerator.Framework.Mvc/ProjectGenerator/ServerDomainGenerator.cs @@ -148,8 +148,8 @@ public void GenerateAssemblyMarker() content); } - public void GenerateServiceCollectionExtensions() - => throw new NotSupportedException($"{nameof(GenerateServiceCollectionExtensions)} is not supported for MVC"); + public void GenerateServiceCollectionEndpointHandlerExtensions() + => throw new NotSupportedException($"{nameof(GenerateServiceCollectionEndpointHandlerExtensions)} is not supported for MVC"); public void MaintainGlobalUsings( bool removeNamespaceGroupSeparatorInGlobalUsings) diff --git a/src/Atc.Rest.ApiGenerator.Framework/ProjectGenerator/IServerDomainGenerator.cs b/src/Atc.Rest.ApiGenerator.Framework/ProjectGenerator/IServerDomainGenerator.cs index deda48fb..abe70d03 100644 --- a/src/Atc.Rest.ApiGenerator.Framework/ProjectGenerator/IServerDomainGenerator.cs +++ b/src/Atc.Rest.ApiGenerator.Framework/ProjectGenerator/IServerDomainGenerator.cs @@ -17,7 +17,7 @@ public interface IServerDomainGenerator void GenerateAssemblyMarker(); - void GenerateServiceCollectionExtensions(); + void GenerateServiceCollectionEndpointHandlerExtensions(); void MaintainGlobalUsings( bool removeNamespaceGroupSeparatorInGlobalUsings); diff --git a/src/Atc.Rest.ApiGenerator/Generators/ServerDomainGenerator.cs b/src/Atc.Rest.ApiGenerator/Generators/ServerDomainGenerator.cs index 4ce38bcb..77fbcb29 100644 --- a/src/Atc.Rest.ApiGenerator/Generators/ServerDomainGenerator.cs +++ b/src/Atc.Rest.ApiGenerator/Generators/ServerDomainGenerator.cs @@ -95,7 +95,7 @@ public async Task Generate() serverDomainGeneratorMinimalApi.ScaffoldHandlers(); serverDomainGeneratorMinimalApi.GenerateAssemblyMarker(); - serverDomainGeneratorMinimalApi.GenerateServiceCollectionExtensions(); + serverDomainGeneratorMinimalApi.GenerateServiceCollectionEndpointHandlerExtensions(); serverDomainGeneratorMinimalApi.MaintainGlobalUsings( projectOptions.ApiOptions.Generator.RemoveNamespaceGroupSeparatorInGlobalUsings); From a83645ba8d343e6e6064cc5cb240e686859d0b63 Mon Sep 17 00:00:00 2001 From: David Kallesen Date: Sat, 10 Aug 2024 00:39:46 +0200 Subject: [PATCH 2/2] fix: change the timer for the logo remove function - change from 10ms to 100ms --- .../Resources/wwwroot/swagger-ui/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Atc.Rest.ApiGenerator.Framework/Resources/wwwroot/swagger-ui/main.js b/src/Atc.Rest.ApiGenerator.Framework/Resources/wwwroot/swagger-ui/main.js index 8f12a226..a07b5763 100644 --- a/src/Atc.Rest.ApiGenerator.Framework/Resources/wwwroot/swagger-ui/main.js +++ b/src/Atc.Rest.ApiGenerator.Framework/Resources/wwwroot/swagger-ui/main.js @@ -10,5 +10,5 @@ document.addEventListener('DOMContentLoaded', function () { if (svgElement) { svgElement.remove() } - }, 10); + }, 100); }, false); \ No newline at end of file