Skip to content

Commit

Permalink
feat: Added GroupByTags setting.
Browse files Browse the repository at this point in the history
  • Loading branch information
HavenDV committed May 23, 2024
1 parent 1724a36 commit 49cde92
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/libs/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
</ItemGroup>

<PropertyGroup Label="Versioning">
<Version>0.7.1</Version>
<Version>0.7.2</Version>
<MinVerMinimumMajorMinor>0.1</MinVerMinimumMajorMinor>
<MinVerTagPrefix>v</MinVerTagPrefix>
<MinVerDefaultPreReleaseIdentifiers>dev</MinVerDefaultPreReleaseIdentifiers>
Expand Down
1 change: 1 addition & 0 deletions src/libs/OpenApiGenerator.Cli/Commands/GenerateCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ private static async Task HandleAsync(
JsonSerializerType: default,
UseRequiredKeyword: default,
GenerateConstructors: false,
GroupByTags: false,
GenerateMethods: false,
MethodNamingConvention: default,
MethodNamingConventionFallback: MethodNamingConvention.MethodAndPath,
Expand Down
19 changes: 19 additions & 0 deletions src/libs/OpenApiGenerator.Core/Generation/Data.Methods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,25 @@ public static ImmutableArray<EndPoint> PrepareData(
Summary: string.Empty,
RequestType: string.Empty,
ResponseType: string.Empty)] : [];
if (settings.GroupByTags && (settings.GenerateSdk || settings.GenerateConstructors))
{
constructors = constructors.Concat(openApiDocument.Tags.Select(x => new EndPoint(
Id: "Constructors",
Namespace: settings.Namespace,
ClassName: x.Name.ToPropertyName(),
BaseUrl: openApiDocument.Servers.FirstOrDefault()?.Url ?? string.Empty,
Stream: false,
Path: string.Empty,
AuthorizationScheme: string.Empty,
Properties: ImmutableArray<PropertyData>.Empty,
TargetFramework: settings.TargetFramework,
JsonSerializerType: settings.JsonSerializerType,
JsonSerializerContext: settings.JsonSerializerContext,
HttpMethod: OperationType.Get,
Summary: string.Empty,
RequestType: string.Empty,
ResponseType: string.Empty))).ToArray();
}

return [
..operations,
Expand Down
1 change: 1 addition & 0 deletions src/libs/OpenApiGenerator.Core/Models/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public readonly record struct Settings(
SdkFeatureUsage UseRequiredKeyword,

bool GenerateConstructors,
bool GroupByTags,
bool GenerateMethods,
MethodNamingConvention MethodNamingConvention,
MethodNamingConvention MethodNamingConventionFallback,
Expand Down
2 changes: 2 additions & 0 deletions src/libs/OpenApiGenerator/OpenApiGenerator.props
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
<!-- true/false. Default: false -->
<CompilerVisibleProperty Include="OpenApiGenerator_GenerateConstructors"/>
<!-- true/false. Default: false -->
<CompilerVisibleProperty Include="OpenApiGenerator_GroupByTags"/>
<!-- true/false. Default: false -->
<CompilerVisibleProperty Include="OpenApiGenerator_GenerateMethods"/>
<!-- SimpleOperationId/MethodAndPath/OperationIdWithDots. Default: SimpleOperationId -->
<CompilerVisibleProperty Include="OpenApiGenerator_MethodNamingConvention"/>
Expand Down
1 change: 1 addition & 0 deletions src/libs/OpenApiGenerator/OptionsExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public static Settings GetSettings(
UseRequiredKeyword: options.GetEnumGlobalOption<SdkFeatureUsage>(nameof(Settings.UseRequiredKeyword), prefix),

GenerateConstructors: options.GetBoolGlobalOption(nameof(Settings.GenerateConstructors), prefix),
GroupByTags: options.GetBoolGlobalOption(nameof(Settings.GroupByTags), prefix),
GenerateMethods: options.GetBoolGlobalOption(nameof(Settings.GenerateMethods), prefix),
MethodNamingConvention: options.GetEnumGlobalOption<MethodNamingConvention>(nameof(Settings.MethodNamingConvention), prefix),
MethodNamingConventionFallback: options.GetEnumGlobalOption(nameof(Settings.MethodNamingConventionFallback), prefix, defaultValue: MethodNamingConvention.MethodAndPath),
Expand Down
1 change: 1 addition & 0 deletions src/tests/OpenApiGenerator.UnitTests/CacheTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class CacheTests
JsonSerializerType: default,
UseRequiredKeyword: default,
GenerateConstructors: false,
GroupByTags: false,
GenerateMethods: false,
MethodNamingConvention: default,
MethodNamingConventionFallback: MethodNamingConvention.MethodAndPath,
Expand Down
1 change: 1 addition & 0 deletions src/tests/OpenApiGenerator.UnitTests/ClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class ClientTests :
JsonSerializerType: default,
UseRequiredKeyword: default,
GenerateConstructors: false,
GroupByTags: false,
GenerateMethods: false,
MethodNamingConvention: default,
MethodNamingConventionFallback: MethodNamingConvention.MethodAndPath,
Expand Down
1 change: 1 addition & 0 deletions src/tests/OpenApiGenerator.UnitTests/ModelTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class ModelTests :
JsonSerializerType: default,
UseRequiredKeyword: default,
GenerateConstructors: false,
GroupByTags: false,
GenerateMethods: false,
MethodNamingConvention: default,
MethodNamingConventionFallback: MethodNamingConvention.MethodAndPath,
Expand Down

0 comments on commit 49cde92

Please sign in to comment.