Skip to content

Commit

Permalink
fix: Fixed missing xml docs for clients.
Browse files Browse the repository at this point in the history
  • Loading branch information
HavenDV committed May 25, 2024
1 parent 5b7324c commit f7c95c6
Show file tree
Hide file tree
Showing 149 changed files with 777 additions and 136 deletions.
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.8.0</Version>
<Version>0.8.1</Version>
<MinVerMinimumMajorMinor>0.1</MinVerMinimumMajorMinor>
<MinVerTagPrefix>v</MinVerTagPrefix>
<MinVerDefaultPreReleaseIdentifiers>dev</MinVerDefaultPreReleaseIdentifiers>
Expand Down
15 changes: 9 additions & 6 deletions src/libs/OpenApiGenerator.Core/Extensions/StringExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,22 +136,25 @@ public static string AsArray(this string type)

public static string ToXmlDocumentationSummary(
this string text,
int level = 4)
int level = 4,
bool addSummary = true)
{
text = text ?? throw new ArgumentNullException(nameof(text));

var lines = text.Split(NewLine, StringSplitOptions.RemoveEmptyEntries);
if (lines.Length == 0)
{
lines = new[] { string.Empty };
lines = [string.Empty];
}

var spaces = new string(' ', level);
var value = string.Join("\n", lines
.Select(line => $"{spaces}/// {line}"));

return $@"/// <summary>
{string.Join("\n", lines
.Select(line => $"{spaces}/// {line}"))}
{spaces}/// </summary>";
return addSummary
? $@"/// <summary>
{value}
{spaces}/// </summary>" : value;
}

public static string UseWordSeparator(
Expand Down
6 changes: 3 additions & 3 deletions src/libs/OpenApiGenerator.Core/Generation/Data.Methods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,15 @@ .. includedTags.Select(x => PropertyData.Default with
{
CSharpType = $"{x.Name.ToClassName()}Client",
},
Summary = x.Description,
Summary = x.Description ?? string.Empty,
})
]
: [],
TargetFramework: settings.TargetFramework,
JsonSerializerType: settings.JsonSerializerType,
JsonSerializerContext: settings.JsonSerializerContext,
HttpMethod: OperationType.Get,
Summary: string.Empty,
Summary: openApiDocument.Info?.Description?.ClearForXml() ?? string.Empty,
RequestType: string.Empty,
ResponseType: string.Empty)] : [];
if (settings.GroupByTags && (settings.GenerateSdk || settings.GenerateConstructors))
Expand All @@ -130,7 +130,7 @@ .. includedTags.Select(x => PropertyData.Default with
JsonSerializerType: settings.JsonSerializerType,
JsonSerializerContext: settings.JsonSerializerContext,
HttpMethod: OperationType.Get,
Summary: string.Empty,
Summary: x.Description?.ClearForXml() ?? string.Empty,
RequestType: string.Empty,
ResponseType: string.Empty)))
.ToArray();
Expand Down
79 changes: 79 additions & 0 deletions src/libs/OpenApiGenerator.Core/Generation/Sources.Clients.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
using OpenApiGenerator.Core.Extensions;
using OpenApiGenerator.Core.Models;

namespace OpenApiGenerator.Core.Generation;

public static partial class Sources
{
public static string GenerateConstructors(
EndPoint endPoint)
{
return $@"
#nullable enable
namespace {endPoint.Namespace}
{{
/// <summary>
/// {endPoint.Summary}
/// If no httpClient is provided, a new one will be created.
/// If no baseUri is provided, the default baseUri from OpenAPI spec will be used.
/// </summary>
public sealed partial class {endPoint.ClassName} : global::System.IDisposable
{{
private readonly global::System.Net.Http.HttpClient _httpClient;
{(endPoint.Properties.Length != 0 ? "\n" + endPoint.Properties.Select(x => $@"
{x.Summary.ToXmlDocumentationSummary(level: 8)}
public {x.Type.CSharpType} {x.Name} => new {x.Type.CSharpType}(_httpClient);
").Inject() : " ")}
/// <summary>
/// Creates a new instance of the {endPoint.ClassName}.
/// If no httpClient is provided, a new one will be created.
/// If no baseUri is provided, the default baseUri from OpenAPI spec will be used.
/// </summary>
/// <param name=""httpClient""></param>
/// <param name=""baseUri""></param>
public {endPoint.ClassName}(
global::System.Net.Http.HttpClient? httpClient = null,
global::System.Uri? baseUri = null)
{{
_httpClient = httpClient ?? new global::System.Net.Http.HttpClient();
_httpClient.BaseAddress ??= baseUri ?? new global::System.Uri(""{endPoint.BaseUrl}"");
}}
/// <inheritdoc/>
public void Dispose()
{{
_httpClient.Dispose();
}}
}}
}}".RemoveBlankLinesWhereOnlyWhitespaces();
}

public static string GenerateAuthorizationMethod(
EndPoint endPoint)
{
return $@"
#nullable enable
namespace {endPoint.Namespace}
{{
public sealed partial class {endPoint.ClassName}
{{
/// <summary>
///
/// </summary>
/// <param name=""apiKey""></param>
public void {endPoint.NotAsyncMethodName}(
string apiKey)
{{
apiKey = apiKey ?? throw new global::System.ArgumentNullException(nameof(apiKey));
_httpClient.DefaultRequestHeaders.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue(
scheme: ""{endPoint.AuthorizationScheme.ToPropertyName()}"",
parameter: apiKey);
}}
}}
}}".RemoveBlankLinesWhereOnlyWhitespaces();
}
}
69 changes: 0 additions & 69 deletions src/libs/OpenApiGenerator.Core/Generation/Sources.Methods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,75 +36,6 @@ public partial class {endPoint.ClassName}
}}
}}".RemoveBlankLinesWhereOnlyWhitespaces();
}

public static string GenerateConstructors(
EndPoint endPoint)
{
return $@"
#nullable enable
namespace {endPoint.Namespace}
{{
/// <summary>
/// If no httpClient is provided, a new one will be created.
/// If no baseUri is provided, the default baseUri from OpenAPI spec will be used.
/// </summary>
public sealed partial class {endPoint.ClassName} : global::System.IDisposable
{{
private readonly global::System.Net.Http.HttpClient _httpClient;
{(endPoint.Properties.Length != 0 ? "\n" + endPoint.Properties.Select(x => $@"
public {x.Type.CSharpType} {x.Name} => new {x.Type.CSharpType}(_httpClient);").Inject() : " ")}
/// <summary>
/// Creates a new instance of the {endPoint.ClassName}.
/// If no httpClient is provided, a new one will be created.
/// If no baseUri is provided, the default baseUri from OpenAPI spec will be used.
/// </summary>
/// <param name=""httpClient""></param>
/// <param name=""baseUri""></param>
public {endPoint.ClassName}(
global::System.Net.Http.HttpClient? httpClient = null,
global::System.Uri? baseUri = null)
{{
_httpClient = httpClient ?? new global::System.Net.Http.HttpClient();
_httpClient.BaseAddress ??= baseUri ?? new global::System.Uri(""{endPoint.BaseUrl}"");
}}
/// <inheritdoc/>
public void Dispose()
{{
_httpClient.Dispose();
}}
}}
}}".RemoveBlankLinesWhereOnlyWhitespaces();
}

public static string GenerateAuthorizationMethod(
EndPoint endPoint)
{
return $@"
#nullable enable
namespace {endPoint.Namespace}
{{
public sealed partial class {endPoint.ClassName}
{{
/// <summary>
///
/// </summary>
/// <param name=""apiKey""></param>
public void {endPoint.NotAsyncMethodName}(
string apiKey)
{{
apiKey = apiKey ?? throw new global::System.ArgumentNullException(nameof(apiKey));
_httpClient.DefaultRequestHeaders.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue(
scheme: ""{endPoint.AuthorizationScheme.ToPropertyName()}"",
parameter: apiKey);
}}
}}
}}".RemoveBlankLinesWhereOnlyWhitespaces();
}

public static string GetHttpMethod(string targetFramework, OperationType operationType)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@
namespace G
{
/// <summary>
/// GitHub's v3 REST API.
/// If no httpClient is provided, a new one will be created.
/// If no baseUri is provided, the default baseUri from OpenAPI spec will be used.
/// </summary>
public sealed partial class Api : global::System.IDisposable
{
private readonly global::System.Net.Http.HttpClient _httpClient;

/// <summary>
/// Move projects to or from GitHub.
/// </summary>
public MigrationsClient Migrations => new MigrationsClient(_httpClient);

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace G
{
/// <summary>
/// Move projects to or from GitHub.
/// If no httpClient is provided, a new one will be created.
/// If no baseUri is provided, the default baseUri from OpenAPI spec will be used.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@
namespace G
{
/// <summary>
/// GitHub's v3 REST API.
/// If no httpClient is provided, a new one will be created.
/// If no baseUri is provided, the default baseUri from OpenAPI spec will be used.
/// </summary>
public sealed partial class Api : global::System.IDisposable
{
private readonly global::System.Net.Http.HttpClient _httpClient;

/// <summary>
/// Move projects to or from GitHub.
/// </summary>
public MigrationsClient Migrations => new MigrationsClient(_httpClient);

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace G
{
/// <summary>
/// Move projects to or from GitHub.
/// If no httpClient is provided, a new one will be created.
/// If no baseUri is provided, the default baseUri from OpenAPI spec will be used.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace G
{
/// <summary>
/// Endpoints to manage GitHub Actions using the REST API.
/// If no httpClient is provided, a new one will be created.
/// If no baseUri is provided, the default baseUri from OpenAPI spec will be used.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace G
{
/// <summary>
/// Activity APIs provide access to notifications, subscriptions, and timelines.
/// If no httpClient is provided, a new one will be created.
/// If no baseUri is provided, the default baseUri from OpenAPI spec will be used.
/// </summary>
Expand Down
Loading

0 comments on commit f7c95c6

Please sign in to comment.