Skip to content

Commit

Permalink
refac: Optimize use of RemoveNamespaceGroupSeparatorInGlobalUsings
Browse files Browse the repository at this point in the history
  • Loading branch information
davidkallesen committed Jul 14, 2024
1 parent 92b80ec commit dd1ca97
Show file tree
Hide file tree
Showing 13 changed files with 18 additions and 73 deletions.
9 changes: 3 additions & 6 deletions src/Atc.Rest.ApiGenerator.CLI/ApiOptionsHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,7 @@ private static void ApplyGeneratorOverrides(
apiOptions.Generator.ProjectName = serverCommandSettings.ProjectPrefixName;
}

if (!serverCommandSettings.RemoveNamespaceGroupSeparatorInGlobalUsings ||
apiOptions.Generator.RemoveNamespaceGroupSeparatorInGlobalUsings)
if (serverCommandSettings.RemoveNamespaceGroupSeparatorInGlobalUsings)
{
apiOptions.Generator.RemoveNamespaceGroupSeparatorInGlobalUsings = serverCommandSettings.RemoveNamespaceGroupSeparatorInGlobalUsings;
}
Expand All @@ -175,8 +174,7 @@ private static void ApplyGeneratorOverrides(
apiOptions.Generator.ProjectName = clientApiCommandSettings.ProjectPrefixName;
}

if (!clientApiCommandSettings.RemoveNamespaceGroupSeparatorInGlobalUsings ||
apiOptions.Generator.RemoveNamespaceGroupSeparatorInGlobalUsings)
if (clientApiCommandSettings.RemoveNamespaceGroupSeparatorInGlobalUsings)
{
apiOptions.Generator.RemoveNamespaceGroupSeparatorInGlobalUsings = clientApiCommandSettings.RemoveNamespaceGroupSeparatorInGlobalUsings;
}
Expand Down Expand Up @@ -205,8 +203,7 @@ private static void ApplyGeneratorOverrides(
apiOptions.Generator.Client.HttpClientName = $"{baseGenerateCommandSettings.ProjectPrefixName}-ApiClient";
}

apiOptions.Generator.Client.ExcludeEndpointGeneration =
clientApiCommandSettings.ExcludeEndpointGeneration;
apiOptions.Generator.Client.ExcludeEndpointGeneration = clientApiCommandSettings.ExcludeEndpointGeneration;

break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,6 @@ private async Task<int> ExecuteInternalAsync(
var shouldScaffoldCodingRules = CodingRulesHelper.ShouldScaffoldCodingRules(outputSlnPath, settings.DisableCodingRules);
var isUsingCodingRules = CodingRulesHelper.IsUsingCodingRules(outputSlnPath, settings.DisableCodingRules);

if (settings.AspNetOutputType.IsSet)
{
apiOptions.Generator.AspNetOutputType = settings.AspNetOutputType.Value;
}

if (settings.SwaggerThemeMode.IsSet)
{
apiOptions.Generator.SwaggerThemeMode = settings.SwaggerThemeMode.Value;
}

if (shouldScaffoldCodingRules &&
!NetworkInformationHelper.HasHttpConnection())
{
Expand All @@ -100,8 +90,7 @@ private async Task<int> ExecuteInternalAsync(
outputTestPath,
apiDocumentContainer,
apiOptions,
isUsingCodingRules,
settings.RemoveNamespaceGroupSeparatorInGlobalUsings))
isUsingCodingRules))
{
return ConsoleExitStatusCodes.Failure;
}
Expand All @@ -116,7 +105,6 @@ private async Task<int> ExecuteInternalAsync(
apiDocumentContainer,
apiOptions,
isUsingCodingRules,
settings.RemoveNamespaceGroupSeparatorInGlobalUsings,
outputSrcPath))
{
return ConsoleExitStatusCodes.Failure;
Expand All @@ -132,7 +120,6 @@ private async Task<int> ExecuteInternalAsync(
apiDocumentContainer,
apiOptions,
isUsingCodingRules,
settings.RemoveNamespaceGroupSeparatorInGlobalUsings,
outputSrcPath,
outputSrcPath))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,6 @@ private async Task<int> ExecuteInternalAsync(
var shouldScaffoldCodingRules = CodingRulesHelper.ShouldScaffoldCodingRules(settings.OutputPath, settings.DisableCodingRules);
var isUsingCodingRules = CodingRulesHelper.IsUsingCodingRules(settings.OutputPath, settings.DisableCodingRules);

if (settings.AspNetOutputType.IsSet)
{
apiOptions.Generator.AspNetOutputType = settings.AspNetOutputType.Value;
}

if (shouldScaffoldCodingRules &&
!NetworkInformationHelper.HasHttpConnection())
{
Expand All @@ -88,8 +83,7 @@ private async Task<int> ExecuteInternalAsync(
outputTestPath,
apiDocumentContainer,
apiOptions,
isUsingCodingRules,
settings.RemoveNamespaceGroupSeparatorInGlobalUsings))
isUsingCodingRules))
{
return ConsoleExitStatusCodes.Failure;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,6 @@ private async Task<int> ExecuteInternalAsync(
var shouldScaffoldCodingRules = CodingRulesHelper.ShouldScaffoldCodingRules(settings.OutputPath, settings.DisableCodingRules);
var isUsingCodingRules = CodingRulesHelper.IsUsingCodingRules(settings.OutputPath, settings.DisableCodingRules);

if (settings.AspNetOutputType.IsSet)
{
apiOptions.Generator.AspNetOutputType = settings.AspNetOutputType.Value;
}

if (shouldScaffoldCodingRules &&
!NetworkInformationHelper.HasHttpConnection())
{
Expand Down Expand Up @@ -89,7 +84,6 @@ private async Task<int> ExecuteInternalAsync(
apiDocumentContainer,
apiOptions,
isUsingCodingRules,
settings.RemoveNamespaceGroupSeparatorInGlobalUsings,
new DirectoryInfo(settings.ApiPath)))
{
return ConsoleExitStatusCodes.Failure;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,6 @@ private async Task<int> ExecuteInternalAsync(
var shouldScaffoldCodingRules = CodingRulesHelper.ShouldScaffoldCodingRules(settings.OutputPath, settings.DisableCodingRules);
var isUsingCodingRules = CodingRulesHelper.IsUsingCodingRules(settings.OutputPath, settings.DisableCodingRules);

if (settings.AspNetOutputType.IsSet)
{
apiOptions.Generator.AspNetOutputType = settings.AspNetOutputType.Value;
}

if (settings.SwaggerThemeMode.IsSet)
{
apiOptions.Generator.SwaggerThemeMode = settings.SwaggerThemeMode.Value;
}

if (shouldScaffoldCodingRules &&
!NetworkInformationHelper.HasHttpConnection())
{
Expand Down Expand Up @@ -94,7 +84,6 @@ private async Task<int> ExecuteInternalAsync(
apiDocumentContainer,
apiOptions,
isUsingCodingRules,
settings.RemoveNamespaceGroupSeparatorInGlobalUsings,
new DirectoryInfo(settings.ApiPath),
new DirectoryInfo(settings.DomainPath)))
{
Expand Down
4 changes: 2 additions & 2 deletions src/Atc.Rest.ApiGenerator/Generators/ServerApiGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public async Task<bool> Generate()

serverApiGeneratorMvc.MaintainApiSpecification(projectOptions.DocumentFile);
serverApiGeneratorMvc.MaintainGlobalUsings(
projectOptions.RemoveNamespaceGroupSeparatorInGlobalUsings);
projectOptions.ApiOptions.Generator.RemoveNamespaceGroupSeparatorInGlobalUsings);
}
else
{
Expand All @@ -95,7 +95,7 @@ public async Task<bool> Generate()

serverApiGeneratorMinimalApi.MaintainApiSpecification(projectOptions.DocumentFile);
serverApiGeneratorMinimalApi.MaintainGlobalUsings(
projectOptions.RemoveNamespaceGroupSeparatorInGlobalUsings);
projectOptions.ApiOptions.Generator.RemoveNamespaceGroupSeparatorInGlobalUsings);
}

return true;
Expand Down
6 changes: 3 additions & 3 deletions src/Atc.Rest.ApiGenerator/Generators/ServerDomainGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public async Task<bool> Generate()
serverDomainGeneratorMvc.GenerateAssemblyMarker();

serverDomainGeneratorMvc.MaintainGlobalUsings(
projectOptions.RemoveNamespaceGroupSeparatorInGlobalUsings);
projectOptions.ApiOptions.Generator.RemoveNamespaceGroupSeparatorInGlobalUsings);
}
else
{
Expand All @@ -98,7 +98,7 @@ public async Task<bool> Generate()
serverDomainGeneratorMinimalApi.GenerateServiceCollectionExtensions();

serverDomainGeneratorMinimalApi.MaintainGlobalUsings(
projectOptions.RemoveNamespaceGroupSeparatorInGlobalUsings);
projectOptions.ApiOptions.Generator.RemoveNamespaceGroupSeparatorInGlobalUsings);
}

if (serverDomainTestGenerator is not null &&
Expand All @@ -112,7 +112,7 @@ public async Task<bool> Generate()

serverDomainTestGenerator.MaintainGlobalUsings(
projectOptions.UsingCodingRules,
projectOptions.RemoveNamespaceGroupSeparatorInGlobalUsings);
projectOptions.ApiOptions.Generator.RemoveNamespaceGroupSeparatorInGlobalUsings);
}

return true;
Expand Down
8 changes: 4 additions & 4 deletions src/Atc.Rest.ApiGenerator/Generators/ServerHostGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public async Task<bool> Generate()
serverHostGeneratorMvc.GenerateConfigureSwaggerDocOptions();

serverHostGeneratorMvc.MaintainGlobalUsings(
projectOptions.RemoveNamespaceGroupSeparatorInGlobalUsings);
projectOptions.ApiOptions.Generator.RemoveNamespaceGroupSeparatorInGlobalUsings);

if (serverHostTestGeneratorMvc is not null &&
projectOptions.PathForTestGenerate is not null)
Expand All @@ -131,7 +131,7 @@ public async Task<bool> Generate()

serverHostTestGeneratorMvc.MaintainGlobalUsings(
projectOptions.UsingCodingRules,
projectOptions.RemoveNamespaceGroupSeparatorInGlobalUsings);
projectOptions.ApiOptions.Generator.RemoveNamespaceGroupSeparatorInGlobalUsings);
}
}
else
Expand All @@ -152,7 +152,7 @@ public async Task<bool> Generate()
serverHostGeneratorMinimalApi.GenerateConfigureSwaggerDocOptions();

serverHostGeneratorMinimalApi.MaintainGlobalUsings(
projectOptions.RemoveNamespaceGroupSeparatorInGlobalUsings);
projectOptions.ApiOptions.Generator.RemoveNamespaceGroupSeparatorInGlobalUsings);
serverHostGeneratorMinimalApi.MaintainWwwResources();

if (serverHostTestGeneratorMinimalApi is not null &&
Expand All @@ -170,7 +170,7 @@ public async Task<bool> Generate()

serverHostTestGeneratorMinimalApi.MaintainGlobalUsings(
projectOptions.UsingCodingRules,
projectOptions.RemoveNamespaceGroupSeparatorInGlobalUsings);
projectOptions.ApiOptions.Generator.RemoveNamespaceGroupSeparatorInGlobalUsings);
}
}

Expand Down
10 changes: 2 additions & 8 deletions src/Atc.Rest.ApiGenerator/Helpers/GenerateHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ public static bool GenerateServerApi(
DirectoryInfo? outputTestPath,
OpenApiDocumentContainer apiDocumentContainer,
ApiOptions apiOptions,
bool useCodingRules,
bool removeNamespaceGroupSeparatorInGlobalUsings)
bool useCodingRules)
{
ArgumentNullException.ThrowIfNull(apiOperationExtractor);
ArgumentNullException.ThrowIfNull(projectPrefixName);
Expand All @@ -29,8 +28,7 @@ public static bool GenerateServerApi(
projectPrefixName,
"Api.Generated",
apiOptions,
useCodingRules,
removeNamespaceGroupSeparatorInGlobalUsings);
useCodingRules);
var serverApiGenerator = new ServerApiGenerator(loggerFactory, apiOperationExtractor, nugetPackageReferenceProvider, projectOptions);

var generateResult = false;
Expand All @@ -52,7 +50,6 @@ public static bool GenerateServerDomain(
OpenApiDocumentContainer apiDocumentContainer,
ApiOptions apiOptions,
bool useCodingRules,
bool removeNamespaceGroupSeparatorInGlobalUsings,
DirectoryInfo apiPath)
{
ArgumentNullException.ThrowIfNull(projectPrefixName);
Expand All @@ -69,7 +66,6 @@ public static bool GenerateServerDomain(
projectPrefixName,
apiOptions,
useCodingRules,
removeNamespaceGroupSeparatorInGlobalUsings,
apiPath);
var serverDomainGenerator = new ServerDomainGenerator(loggerFactory, apiOperationExtractor, nugetPackageReferenceProvider, domainProjectOptions);

Expand All @@ -92,7 +88,6 @@ public static bool GenerateServerHost(
OpenApiDocumentContainer apiDocumentContainer,
ApiOptions apiOptions,
bool usingCodingRules,
bool removeNamespaceGroupSeparatorInGlobalUsings,
DirectoryInfo apiPath,
DirectoryInfo domainPath)
{
Expand All @@ -111,7 +106,6 @@ public static bool GenerateServerHost(
projectPrefixName,
apiOptions,
usingCodingRules,
removeNamespaceGroupSeparatorInGlobalUsings,
apiPath,
domainPath);
var serverHostGenerator = new ServerHostGenerator(loggerFactory, apiOperationExtractor, nugetPackageReferenceProvider, hostProjectOptions);
Expand Down
2 changes: 0 additions & 2 deletions src/Atc.Rest.ApiGenerator/Models/ApiProjectOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ public ApiProjectOptions(
string? projectSuffixName,
ApiOptions apiOptions,
bool usingCodingRules,
bool removeNamespaceGroupSeparatorInGlobalUsings,
bool forClient = false,
string? clientFolderName = null)
: base(
Expand All @@ -23,7 +22,6 @@ public ApiProjectOptions(
projectSuffixName,
apiOptions,
usingCodingRules,
removeNamespaceGroupSeparatorInGlobalUsings,
forClient,
clientFolderName)
{
Expand Down
4 changes: 0 additions & 4 deletions src/Atc.Rest.ApiGenerator/Models/BaseProjectOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ protected BaseProjectOptions(
string? projectSuffixName,
ApiOptions apiOptions,
bool usingCodingRules,
bool removeNamespaceGroupSeparatorInGlobalUsings,
bool forClient = false,
string? clientFolderName = null)
{
Expand Down Expand Up @@ -70,7 +69,6 @@ protected BaseProjectOptions(
}

UsingCodingRules = usingCodingRules;
RemoveNamespaceGroupSeparatorInGlobalUsings = removeNamespaceGroupSeparatorInGlobalUsings;
IsForClient = forClient;
ClientFolderName = clientFolderName;

Expand All @@ -79,8 +77,6 @@ protected BaseProjectOptions(

public bool UsingCodingRules { get; }

public bool RemoveNamespaceGroupSeparatorInGlobalUsings { get; }

public bool UseNullableReferenceTypes { get; } = true;

public string ApiGeneratorName { get; }
Expand Down
4 changes: 1 addition & 3 deletions src/Atc.Rest.ApiGenerator/Models/DomainProjectOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ public DomainProjectOptions(
string projectPrefixName,
ApiOptions apiOptions,
bool useCodingRules,
bool removeNamespaceGroupSeparatorInGlobalUsings,
DirectoryInfo apiProjectSrcPath)
: base(
projectSourceGeneratePath,
Expand All @@ -20,8 +19,7 @@ public DomainProjectOptions(
projectPrefixName,
"Domain",
apiOptions,
useCodingRules,
removeNamespaceGroupSeparatorInGlobalUsings)
useCodingRules)
{
ApiProjectSrcPath = apiProjectSrcPath ?? throw new ArgumentNullException(nameof(apiProjectSrcPath));
PathForSrcHandlers = new DirectoryInfo(Path.Combine(PathForSrcGenerate.FullName, ContentGeneratorConstants.Handlers));
Expand Down
4 changes: 1 addition & 3 deletions src/Atc.Rest.ApiGenerator/Models/HostProjectOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ public HostProjectOptions(
string projectPrefixName,
ApiOptions apiOptions,
bool usingCodingRules,
bool removeNamespaceGroupSeparatorInGlobalUsings,
DirectoryInfo apiProjectSrcPath,
DirectoryInfo domainProjectSrcPath)
: base(
Expand All @@ -22,8 +21,7 @@ public HostProjectOptions(
projectPrefixName,
"Api",
apiOptions,
usingCodingRules,
removeNamespaceGroupSeparatorInGlobalUsings)
usingCodingRules)
{
ArgumentNullException.ThrowIfNull(apiOptions);

Expand Down

0 comments on commit dd1ca97

Please sign in to comment.