Skip to content

Commit

Permalink
feat: Improve ApplyGeneratorOverrides
Browse files Browse the repository at this point in the history
  • Loading branch information
davidkallesen committed Jul 8, 2024
1 parent 8e97261 commit bd7a036
Showing 1 changed file with 34 additions and 24 deletions.
58 changes: 34 additions & 24 deletions src/Atc.Rest.ApiGenerator.CLI/ApiOptionsHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,32 +130,34 @@ private static void ApplyGeneratorOverrides(
ApiOptions apiOptions,
BaseConfigurationCommandSettings settings)
{
if (settings is BaseServerCommandSettings serverSettings)
if (settings is BaseServerCommandSettings serverCommandSettings)
{
if (serverSettings.AspNetOutputType.IsSet)
if (serverCommandSettings.AspNetOutputType.IsSet)
{
apiOptions.Generator.AspNetOutputType = serverSettings.AspNetOutputType.Value;
apiOptions.Generator.AspNetOutputType = serverCommandSettings.AspNetOutputType.Value;
}

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

if (serverSettings.UseProblemDetailsAsDefaultResponseBody)
if (serverCommandSettings.UseProblemDetailsAsDefaultResponseBody)
{
apiOptions.Generator.Response.UseProblemDetailsAsDefaultBody = serverSettings.UseProblemDetailsAsDefaultResponseBody;
apiOptions.Generator.Response.UseProblemDetailsAsDefaultBody =
serverCommandSettings.UseProblemDetailsAsDefaultResponseBody;
}

if (serverSettings.ProjectPrefixName is not null)
if (serverCommandSettings.ProjectPrefixName is not null)
{
apiOptions.Generator.ProjectName = serverSettings.ProjectPrefixName
.Replace(" ", ".", StringComparison.Ordinal)
.Replace("-", ".", StringComparison.Ordinal)
.Trim();
apiOptions.Generator.ProjectName = serverCommandSettings.ProjectPrefixName;
}

apiOptions.Generator.RemoveNamespaceGroupSeparatorInGlobalUsings = serverSettings.RemoveNamespaceGroupSeparatorInGlobalUsings;
if (!serverCommandSettings.RemoveNamespaceGroupSeparatorInGlobalUsings ||
apiOptions.Generator.RemoveNamespaceGroupSeparatorInGlobalUsings)
{
apiOptions.Generator.RemoveNamespaceGroupSeparatorInGlobalUsings = serverCommandSettings.RemoveNamespaceGroupSeparatorInGlobalUsings;
}
}

switch (settings)
Expand All @@ -164,27 +166,25 @@ private static void ApplyGeneratorOverrides(
{
if (clientApiCommandSettings.UseProblemDetailsAsDefaultResponseBody)
{
apiOptions.Generator.Response.UseProblemDetailsAsDefaultBody = clientApiCommandSettings.UseProblemDetailsAsDefaultResponseBody;
apiOptions.Generator.Response.UseProblemDetailsAsDefaultBody =
clientApiCommandSettings.UseProblemDetailsAsDefaultResponseBody;
}

if (clientApiCommandSettings.ProjectPrefixName is not null)
{
apiOptions.Generator.ProjectName = clientApiCommandSettings.ProjectPrefixName;
}

apiOptions.Generator.RemoveNamespaceGroupSeparatorInGlobalUsings = clientApiCommandSettings.RemoveNamespaceGroupSeparatorInGlobalUsings;
if (!clientApiCommandSettings.RemoveNamespaceGroupSeparatorInGlobalUsings ||
apiOptions.Generator.RemoveNamespaceGroupSeparatorInGlobalUsings)
{
apiOptions.Generator.RemoveNamespaceGroupSeparatorInGlobalUsings = clientApiCommandSettings.RemoveNamespaceGroupSeparatorInGlobalUsings;
}

if (string.IsNullOrEmpty(apiOptions.Generator.ProjectSuffixName))
{
apiOptions.Generator.ProjectSuffixName = "ApiClient.Generated";
}
else
{
apiOptions.Generator.ProjectSuffixName = apiOptions.Generator.ProjectSuffixName
.Replace(" ", ".", StringComparison.Ordinal)
.Replace("-", ".", StringComparison.Ordinal)
.Trim();
}

apiOptions.Generator.Client ??= new ApiOptionsGeneratorClient();

Expand All @@ -199,16 +199,26 @@ private static void ApplyGeneratorOverrides(
{
apiOptions.Generator.Client.HttpClientName = clientApiCommandSettings.HttpClientName.Value;
}
else
else if ("ApiClient".Equals(apiOptions.Generator.Client.HttpClientName, StringComparison.Ordinal))
{
var baseGenerateCommandSettings = (BaseGenerateCommandSettings)settings;
apiOptions.Generator.Client.HttpClientName = $"{baseGenerateCommandSettings.ProjectPrefixName}-ApiClient";
}

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

break;
}
}

if (apiOptions.Generator.ProjectSuffixName.Contains(' ', StringComparison.Ordinal) ||
apiOptions.Generator.ProjectSuffixName.Contains('-', StringComparison.Ordinal))
{
apiOptions.Generator.ProjectSuffixName = apiOptions.Generator.ProjectSuffixName
.Trim()
.Replace(' ', '.')
.Replace('-', '.');
}
}
}

0 comments on commit bd7a036

Please sign in to comment.