diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json
new file mode 100644
index 0000000..257d421
--- /dev/null
+++ b/.config/dotnet-tools.json
@@ -0,0 +1,13 @@
+{
+ "version": 1,
+ "isRoot": true,
+ "tools": {
+ "csharpier": {
+ "version": "1.0.3",
+ "commands": [
+ "csharpier"
+ ],
+ "rollForward": false
+ }
+ }
+}
\ No newline at end of file
diff --git a/.csharpierrc b/.csharpierrc
new file mode 100644
index 0000000..c295ad9
--- /dev/null
+++ b/.csharpierrc
@@ -0,0 +1,10 @@
+{
+ "printWidth": 110,
+ "useTabs": false,
+ "tabWidth": 4,
+ "preprocessorSymbolSets": [
+ "",
+ "DEBUG",
+ "DEBUG,CODE_STYLE"
+ ]
+}
diff --git a/.editorconfig b/.editorconfig
index d9f8b09..44e1550 100644
--- a/.editorconfig
+++ b/.editorconfig
@@ -15,8 +15,25 @@ indent_size = 4
indent_style = space
# New line preferences
-end_of_line = unset
+end_of_line = crlf
insert_final_newline = false
+dotnet_style_operator_placement_when_wrapping = beginning_of_line
+dotnet_style_coalesce_expression = true:suggestion
+dotnet_style_null_propagation = true:suggestion
+dotnet_style_prefer_is_null_check_over_reference_equality_method = true:suggestion
+dotnet_style_prefer_auto_properties = true:silent
+dotnet_style_object_initializer = true:suggestion
+dotnet_style_collection_initializer = true:suggestion
+dotnet_style_prefer_simplified_boolean_expressions = true:suggestion
+dotnet_style_prefer_conditional_expression_over_assignment = true:silent
+dotnet_style_prefer_conditional_expression_over_return = true:silent
+dotnet_style_explicit_tuple_names = true:suggestion
+dotnet_style_prefer_inferred_tuple_names = true:suggestion
+dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion
+dotnet_style_prefer_compound_assignment = true:suggestion
+dotnet_style_prefer_simplified_interpolation = true:suggestion
+dotnet_style_prefer_collection_expression = when_types_loosely_match:suggestion
+dotnet_style_namespace_match_folder = true:suggestion
#### Build files ####
@@ -50,10 +67,10 @@ file_header_template = This Source Code Form is subject to the terms of the MIT
#### .NET Coding Conventions ####
# this. and Me. preferences
-dotnet_style_qualification_for_event = false:warning
-dotnet_style_qualification_for_field = true:warning
-dotnet_style_qualification_for_method = false:warning
-dotnet_style_qualification_for_property = false:warning
+dotnet_style_qualification_for_event = false:none
+dotnet_style_qualification_for_field = false:none
+dotnet_style_qualification_for_method = false:none
+dotnet_style_qualification_for_property = false:none
# Language keywords vs BCL types preferences
dotnet_style_predefined_type_for_locals_parameters_members = true:warning
@@ -99,13 +116,13 @@ csharp_style_var_for_built_in_types = false:warning
csharp_style_var_when_type_is_apparent = false:warning
# Expression-bodied members
-csharp_style_expression_bodied_accessors = false:silent
+csharp_style_expression_bodied_accessors = true:silent
csharp_style_expression_bodied_constructors = false:silent
-csharp_style_expression_bodied_indexers = false:silent
+csharp_style_expression_bodied_indexers = true:silent
csharp_style_expression_bodied_lambdas = true:silent
csharp_style_expression_bodied_methods = false:silent
csharp_style_expression_bodied_operators = false:silent
-csharp_style_expression_bodied_properties = false:silent
+csharp_style_expression_bodied_properties = true:silent
# Pattern matching preferences
csharp_style_prefer_pattern_matching = true:suggestion
@@ -119,9 +136,9 @@ csharp_style_conditional_delegate_call = true:suggestion
csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async
# Code-block preferences
-csharp_prefer_braces = true:suggestion
-csharp_using_directive_placement = outside_namespace:warning
-csharp_style_namespace_declarations = file_scoped:warning
+csharp_prefer_braces = true:silent
+csharp_using_directive_placement = outside_namespace:silent
+csharp_style_namespace_declarations = block_scoped:silent
csharp_style_unused_value_assignment_preference = discard_variable:none
csharp_style_unused_value_expression_statement_preference = discard_variable:none
csharp_style_allow_blank_lines_between_consecutive_braces_experimental = false:warning
@@ -147,7 +164,7 @@ csharp_indent_block_contents = true
csharp_indent_braces = false
csharp_indent_case_contents = true
csharp_indent_case_contents_when_block = false
-csharp_indent_labels = no_change
+csharp_indent_labels = one_less_than_current
csharp_indent_switch_labels = true
# Space preferences
@@ -387,3 +404,10 @@ dotnet_diagnostic.SA1629.severity = none
dotnet_diagnostic.SA1633.severity = none
dotnet_diagnostic.SA1634.severity = none
dotnet_diagnostic.SA1652.severity = none
+csharp_prefer_simple_using_statement = true:suggestion
+csharp_style_prefer_method_group_conversion = true:silent
+csharp_style_prefer_top_level_statements = true:silent
+csharp_style_prefer_primary_constructors = true:suggestion
+csharp_prefer_system_threading_lock = true:suggestion
+csharp_style_expression_bodied_local_functions = false:silent
+csharp_style_prefer_null_check_over_type_check = true:suggestion
diff --git a/.github/funding.yml b/.github/funding.yml
index 249b02c..41fafec 100644
--- a/.github/funding.yml
+++ b/.github/funding.yml
@@ -1 +1 @@
-github: [lepoco]
+github: [pomianowski]
diff --git a/Directory.Build.props b/Directory.Build.props
index e4d09a4..0cfe808 100644
--- a/Directory.Build.props
+++ b/Directory.Build.props
@@ -1,15 +1,14 @@
-
$(MSBuildThisFileDirectory)
$(RepositoryDirectory)build\
-
1.0.0
- 1.0.0-preview.3
+ $(Version)
+ $(Version)-preview.7
+ net9.0
-
lepo.co
lepo.co
@@ -23,23 +22,19 @@
Icon.png
https://github.com/lepoco/openapi.client/main/build/nuget.png
-
true
moderate
true
false
-
true
-
true
- 12.0
+ 13.0
enable
-
$(NoWarn);CS8500
-
$(MSBuildProjectName.Contains('Test'))
False
True
-
true
true
$(TF_BUILD)
-
@@ -75,15 +67,6 @@
-
-
-
-
- all
- build; analyzers
-
-
-
@@ -99,5 +82,4 @@
-
diff --git a/Directory.Build.targets b/Directory.Build.targets
index f9136a8..1119032 100644
--- a/Directory.Build.targets
+++ b/Directory.Build.targets
@@ -1,37 +1,34 @@
-
$(Product) Asset
-
$(CommonTags);.NET
$(CommonTags);$(PackageTags)
$(CommonTags)
-
-
-
+
<_Parameter1>CommitHash
<_Parameter2>$(SourceRevisionId)
-
NETSTANDARD2_1_OR_GREATER
-
true
@@ -39,7 +36,6 @@
true
true
-
- $(IntermediateOutputPath)$(MSBuildProjectName).SkipLocalsInit.g.cs
+ $(IntermediateOutputPath)$(MSBuildProjectName).SkipLocalsInit.g.cs
@@ -63,17 +61,21 @@
[module: global::System.Runtime.CompilerServices.SkipLocalsInitAttribute]]]>
-
-
-
+
-
-
+
diff --git a/Directory.Packages.props b/Directory.Packages.props
index 77d3ad0..0bf6e36 100644
--- a/Directory.Packages.props
+++ b/Directory.Packages.props
@@ -1,26 +1,31 @@
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
\ No newline at end of file
+
diff --git a/OpenApi.Client.sln b/OpenApi.Client.sln
index b90502b..204e21f 100644
--- a/OpenApi.Client.sln
+++ b/OpenApi.Client.sln
@@ -3,8 +3,6 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.5.002.0
MinimumVisualStudioVersion = 10.0.40219.1
-Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenApi.Client", "src\OpenApi.Client\OpenApi.Client.csproj", "{3FBC6663-B59A-4A68-A129-10A97ABE66BC}"
-EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{D8B6F9EF-D1AA-4331-804E-39C224975632}"
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
@@ -17,17 +15,17 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
ThirdPartyNotices.txt = ThirdPartyNotices.txt
EndProjectSection
EndProject
-Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenApi.Client.SourceGenerators.Roslyn401", "src\OpenApi.Client.SourceGenerators.Roslyn401\OpenApi.Client.SourceGenerators.Roslyn401.csproj", "{7A1D6A44-DD20-4AD1-95DB-C98F1C0DEA60}"
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{723E5DFE-E809-4C07-90CC-03F44C29E259}"
EndProject
-Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenApi.Client.SourceGenerators.Roslyn431", "src\OpenApi.Client.SourceGenerators.Roslyn431\OpenApi.Client.SourceGenerators.Roslyn431.csproj", "{BAC41EE8-5516-4D6C-ABBC-1F66CB7ABEC3}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenApi.Client", "src\OpenApi.Client\OpenApi.Client.csproj", "{3FBC6663-B59A-4A68-A129-10A97ABE66BC}"
EndProject
-Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "OpenApi.Client.SourceGenerators", "src\OpenApi.Client.SourceGenerators\OpenApi.Client.SourceGenerators.shproj", "{5E7F1212-A54B-40CA-98C5-1FF5CD1A1638}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenApi.Client.Cli", "src\OpenApi.Client.Cli\OpenApi.Client.Cli.csproj", "{4D8AFE01-AD96-4954-8959-1002A3E20774}"
EndProject
-Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{723E5DFE-E809-4C07-90CC-03F44C29E259}"
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenApi.Client.SourceGenerators", "src\OpenApi.Client.SourceGenerators\OpenApi.Client.SourceGenerators.csproj", "{D50490C8-488C-7AC3-5A43-9F8BEB6CD044}"
EndProject
-Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenApi.Client.SourceGenerators.Roslyn431.UnitTests", "tests\OpenApi.Client.SourceGenerators.Roslyn431.UnitTests\OpenApi.Client.SourceGenerators.Roslyn431.UnitTests.csproj", "{6F7B2036-2C02-4C10-A788-613B116BE246}"
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenApi.Client.SourceGenerators.UnitTests", "tests\OpenApi.Client.SourceGenerators.UnitTests\OpenApi.Client.SourceGenerators.UnitTests.csproj", "{07D95FF8-531B-5237-7018-C39645124B17}"
EndProject
-Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenApi.Client.Cli", "src\OpenApi.Client.Cli\OpenApi.Client.Cli.csproj", "{4D8AFE01-AD96-4954-8959-1002A3E20774}"
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenApi.Client.Cli.UnitTests", "tests\OpenApi.Client.Cli.UnitTests\OpenApi.Client.Cli.UnitTests.csproj", "{0C407F0F-BE50-4850-B695-FE1C0910E8BB}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -39,36 +37,34 @@ Global
{3FBC6663-B59A-4A68-A129-10A97ABE66BC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3FBC6663-B59A-4A68-A129-10A97ABE66BC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3FBC6663-B59A-4A68-A129-10A97ABE66BC}.Release|Any CPU.Build.0 = Release|Any CPU
- {7A1D6A44-DD20-4AD1-95DB-C98F1C0DEA60}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {7A1D6A44-DD20-4AD1-95DB-C98F1C0DEA60}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {7A1D6A44-DD20-4AD1-95DB-C98F1C0DEA60}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {7A1D6A44-DD20-4AD1-95DB-C98F1C0DEA60}.Release|Any CPU.Build.0 = Release|Any CPU
- {BAC41EE8-5516-4D6C-ABBC-1F66CB7ABEC3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {BAC41EE8-5516-4D6C-ABBC-1F66CB7ABEC3}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {BAC41EE8-5516-4D6C-ABBC-1F66CB7ABEC3}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {BAC41EE8-5516-4D6C-ABBC-1F66CB7ABEC3}.Release|Any CPU.Build.0 = Release|Any CPU
- {6F7B2036-2C02-4C10-A788-613B116BE246}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {6F7B2036-2C02-4C10-A788-613B116BE246}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {6F7B2036-2C02-4C10-A788-613B116BE246}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {6F7B2036-2C02-4C10-A788-613B116BE246}.Release|Any CPU.Build.0 = Release|Any CPU
{4D8AFE01-AD96-4954-8959-1002A3E20774}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4D8AFE01-AD96-4954-8959-1002A3E20774}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4D8AFE01-AD96-4954-8959-1002A3E20774}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4D8AFE01-AD96-4954-8959-1002A3E20774}.Release|Any CPU.Build.0 = Release|Any CPU
+ {D50490C8-488C-7AC3-5A43-9F8BEB6CD044}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {D50490C8-488C-7AC3-5A43-9F8BEB6CD044}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {D50490C8-488C-7AC3-5A43-9F8BEB6CD044}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {D50490C8-488C-7AC3-5A43-9F8BEB6CD044}.Release|Any CPU.Build.0 = Release|Any CPU
+ {07D95FF8-531B-5237-7018-C39645124B17}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {07D95FF8-531B-5237-7018-C39645124B17}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {07D95FF8-531B-5237-7018-C39645124B17}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {07D95FF8-531B-5237-7018-C39645124B17}.Release|Any CPU.Build.0 = Release|Any CPU
+ {0C407F0F-BE50-4850-B695-FE1C0910E8BB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {0C407F0F-BE50-4850-B695-FE1C0910E8BB}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {0C407F0F-BE50-4850-B695-FE1C0910E8BB}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {0C407F0F-BE50-4850-B695-FE1C0910E8BB}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
- {6F7B2036-2C02-4C10-A788-613B116BE246} = {723E5DFE-E809-4C07-90CC-03F44C29E259}
+ {07D95FF8-531B-5237-7018-C39645124B17} = {723E5DFE-E809-4C07-90CC-03F44C29E259}
+ {0C407F0F-BE50-4850-B695-FE1C0910E8BB} = {723E5DFE-E809-4C07-90CC-03F44C29E259}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {5A90450F-432E-450C-9FE7-4C820639466E}
EndGlobalSection
GlobalSection(SharedMSBuildProjectFiles) = preSolution
src\OpenApi.Client.SourceGenerators\OpenApi.Client.SourceGenerators.projitems*{4d8afe01-ad96-4954-8959-1002a3e20774}*SharedItemsImports = 5
- src\OpenApi.Client.SourceGenerators\OpenApi.Client.SourceGenerators.projitems*{5e7f1212-a54b-40ca-98c5-1ff5cd1a1638}*SharedItemsImports = 13
- src\OpenApi.Client.SourceGenerators\OpenApi.Client.SourceGenerators.projitems*{7a1d6a44-dd20-4ad1-95db-c98f1c0dea60}*SharedItemsImports = 5
- src\OpenApi.Client.SourceGenerators\OpenApi.Client.SourceGenerators.projitems*{bac41ee8-5516-4d6c-abbc-1f66cb7abec3}*SharedItemsImports = 5
EndGlobalSection
EndGlobal
diff --git a/README.md b/README.md
index 1cd8035..fe62dfd 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,6 @@
# ☄️ OpenAPI Client
-[Created with ❤ in Poland by lepo.co](https://dev.lepo.co/)
+[Created with ❤ in Poland by lepo.co](https://lepo.co/) and [wonderful open-source community](https://github.com/lepoco/openapi.client/graphs/contributors)
OpenAPI Client is a toolkit that helps you create HTTP clients for external APIs based on their OpenAPI specifications. It simplifies the process of consuming and interacting with various web services. The project is developed and maintained by lepo.co and other community contributors.
## 👀 What does this repo contain?
@@ -10,7 +10,7 @@ The repository contains NuGet package source code, which uses C# code generators
## Gettings started
OpenApiClient is available as NuGet package on NuGet.org:
-https://www.nuget.org/packages/OpenApiClient
+
You can add it to your project using .NET CLI:
@@ -30,7 +30,7 @@ NuGet\Install-Package OpenApiClient
dotnet tool install --global OpenApiClient.Cli
```
-Define an Open API file as content in your **.csproj** file.
+Define an Open API file as content in your **.csproj** file.
```xml
@@ -80,12 +80,12 @@ We found the use of nullable essential, so C# 8.0 is required.
## OpenAPI
OpenAPI specification is available at:
-https://github.com/OAI/OpenAPI-Specification
+
## Community Toolkit
The OpenAPI Client is inspired by the MVVM Community Toolkit:
-https://github.com/CommunityToolkit/dotnet
+
## Compilation
diff --git a/documentation/OAPIC007.md b/documentation/OAPIC007.md
new file mode 100644
index 0000000..cbd4cca
--- /dev/null
+++ b/documentation/OAPIC007.md
@@ -0,0 +1,7 @@
+# OAPIC006
+
+OpenApi.Client.SourceGenerators.MissingPaths
+
+## Cause
+
+Source generation from Open API document failed because there is no known paths to generate.
diff --git a/nuget.config b/nuget.config
index 6eca12a..97513c8 100644
--- a/nuget.config
+++ b/nuget.config
@@ -4,11 +4,9 @@
-
-
diff --git a/src/OpenApi.Client.Cli/Commands/GenerateCommand.cs b/src/OpenApi.Client.Cli/Commands/GenerateCommand.cs
index bdd551b..0cda1c9 100644
--- a/src/OpenApi.Client.Cli/Commands/GenerateCommand.cs
+++ b/src/OpenApi.Client.Cli/Commands/GenerateCommand.cs
@@ -3,12 +3,8 @@
// Copyright (C) Leszek Pomianowski and OpenAPI Client Contributors.
// All Rights Reserved.
-using Microsoft.CodeAnalysis;
using OpenApi.Client.Cli.Settings;
-using OpenApi.Client.SourceGenerators.Contracts;
-using OpenApi.Client.SourceGenerators.Generation;
-using OpenApi.Client.SourceGenerators.Schema;
-using OpenApi.Client.SourceGenerators.Serialization;
+using OpenApi.Client.SourceGenerators.Client;
namespace OpenApi.Client.Cli.Commands;
@@ -24,100 +20,69 @@ public sealed class GenerateCommand : AsyncCommand
{
private static readonly Regex PathNormalizer = new(@"(\\\\|//)", RegexOptions.Compiled);
- private static readonly Regex NamespaceValidator =
- new(@"^[_a-zA-Z][_a-zA-Z0-9]*(\.[_a-zA-Z][_a-zA-Z0-9]*)*$", RegexOptions.Compiled);
+ private static readonly Regex NamespaceValidator = new(
+ @"^[_a-zA-Z][_a-zA-Z0-9]*(\.[_a-zA-Z][_a-zA-Z0-9]*)*$",
+ RegexOptions.Compiled
+ );
- private static readonly Regex ClassNameValidator =
- new(@"^[_a-zA-Z][_a-zA-Z0-9]*$", RegexOptions.Compiled);
+ private static readonly Regex ClassNameValidator = new(
+ @"^[_a-zA-Z][_a-zA-Z0-9]*$",
+ RegexOptions.Compiled
+ );
///
- public override async Task ExecuteAsync(
- CommandContext context,
- GenerateCommandSettings settings
- )
+ public override async Task ExecuteAsync(CommandContext context, GenerateCommandSettings settings)
{
using CancellationTokenSource cancellationTokenSource = new();
- string contents = await File.ReadAllTextAsync(settings.File);
- SerializationResult? serializationResult =
- new OpenApiSerializer().Deserialize(settings.File, contents);
+ await using FileStream fileStream = new(settings.File, FileMode.Open, FileAccess.Read);
- if (serializationResult.HasErrors)
- {
- foreach (
- SerializationResultError serializationResultError in serializationResult.Errors
- )
+ ClientGenerator generator = new(
+ new GeneratorData
{
- AnsiConsole.MarkupLine($"[red]Error: {serializationResultError.Message}[/]");
+ NamespaceName = settings.Namespace,
+ ClassName = settings.ClassName,
+ Access = Accessibility.Public,
+ SerializationTool = SerializationTool.SystemTextJson,
+ Source = fileStream,
+ Templates = null,
}
-
- return -1;
- }
-
- if (serializationResult.Result is null)
- {
- AnsiConsole.MarkupLine($"[red]Error: Serialized JSON returned empty API.[/]");
-
- return -2;
- }
-
- string? generatedSource = null;
-
- OpenApiContract contract = OpenApiContractParser.Parse(
- settings.Namespace,
- settings.ClassName,
- Accessibility.Public,
- serializationResult.Result
);
- ClientGenerator generator =
- new(
- contract,
- settings.Serializer switch
- {
- JsonSerializerType.NewtonsoftJson => ClientGeneratorSerializer.NewtonsoftJson,
- _ => ClientGeneratorSerializer.SystemTextJson
- }
- );
- GenerationResult generatorResult = generator.Generate();
+ GenerationResult generatorResult = await generator.GenerateAsync(cancellationTokenSource.Token);
if (generatorResult.HasErrors)
{
- foreach (GenerationResultError generatorResultError in generatorResult.Errors)
+ foreach (GenerationError generatorResultError in generatorResult.Errors)
{
- AnsiConsole.MarkupLine($"[red]Error: {generatorResultError.Message}[/]");
+ AnsiConsole.MarkupLine($"[red]Error:[/] {generatorResultError.Message}");
}
return -3;
}
- generatedSource = generatorResult.Result;
-
try
{
await File.WriteAllTextAsync(
settings.Output,
- generatedSource,
+ generatorResult.GeneratedClient,
cancellationTokenSource.Token
);
}
catch (Exception e)
{
- AnsiConsole.MarkupLine($"[red]Error: {e.Message}[/]");
+ AnsiConsole.MarkupLine($"[red]Error:[/] {e.Message}");
return -4;
}
- AnsiConsole.MarkupLine($"[green]Success: File was properly saved to {settings.Output}.[/]");
+ AnsiConsole.MarkupLine($"[green]Success:[/] File was properly saved to {settings.Output}.");
return 0;
}
///
- public override ValidationResult Validate(
- CommandContext context,
- GenerateCommandSettings settings
- )
+ public override ValidationResult Validate(CommandContext context, GenerateCommandSettings settings)
{
if (string.IsNullOrEmpty(settings.ClassName))
{
@@ -128,18 +93,14 @@ GenerateCommandSettings settings
if (!ClassNameValidator.IsMatch(settings.ClassName))
{
- return ValidationResult.Error(
- $"The name '{settings.ClassName}' is not valid C# type name."
- );
+ return ValidationResult.Error($"The name '{settings.ClassName}' is not valid C# type name.");
}
settings.Namespace = settings.Namespace.Trim();
if (!NamespaceValidator.IsMatch(settings.Namespace))
{
- return ValidationResult.Error(
- $"The namespace '{settings.Namespace}' is not valid C# namespace."
- );
+ return ValidationResult.Error($"The namespace '{settings.Namespace}' is not valid C# namespace.");
}
settings.File = PathNormalizer.Replace(settings.File, "/");
diff --git a/src/OpenApi.Client.Cli/DependencyInjection/DependencyInjectionRegistrar.cs b/src/OpenApi.Client.Cli/DependencyInjection/DependencyInjectionRegistrar.cs
deleted file mode 100644
index 016fd21..0000000
--- a/src/OpenApi.Client.Cli/DependencyInjection/DependencyInjectionRegistrar.cs
+++ /dev/null
@@ -1,34 +0,0 @@
-// This Source Code Form is subject to the terms of the MIT License.
-// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT.
-// Copyright (C) Leszek Pomianowski and OpenAPI Client Contributors.
-// All Rights Reserved.
-
-namespace OpenApi.Client.Cli.DependencyInjection;
-
-internal sealed class DependencyInjectionRegistrar(IHostBuilder builder) : ITypeRegistrar
-{
- public ITypeResolver Build()
- {
- return new DependencyInjectionResolver(builder.Build());
- }
-
- public void Register(Type service, Type implementation)
- {
- builder.ConfigureServices((_, services) => services.AddSingleton(service, implementation));
- }
-
- public void RegisterInstance(Type service, object implementation)
- {
- builder.ConfigureServices((_, services) => services.AddSingleton(service, implementation));
- }
-
- public void RegisterLazy(Type service, Func