Skip to content
18 changes: 14 additions & 4 deletions src/Refitter.Core/RefitInterfaceGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,11 @@ private string GenerateInterfaceBody(out string? dynamicQuerystringParameters)
var parametersString = string.Join(", ", parameters);
var hasApizrRequestOptionsParameter = settings.ApizrSettings?.WithRequestOptions == true;

this.docGenerator.AppendMethodDocumentation(operationModel, IsApiResponseType(returnType), hasDynamicQuerystringParameter, hasApizrRequestOptionsParameter, code);
if (settings.GenerateXmlDocCodeComments)
{
this.docGenerator.AppendMethodDocumentation(operationModel, IsApiResponseType(returnType), hasDynamicQuerystringParameter, hasApizrRequestOptionsParameter, code);
}

GenerateObsoleteAttribute(operation, code);
GenerateForMultipartFormData(operationModel, code);
GenerateHeaders(operations, operation, operationModel, code);
Expand All @@ -82,7 +86,10 @@ private string GenerateInterfaceBody(out string? dynamicQuerystringParameters)

if (parametersString.Contains("?") && settings is {OptionalParameters: true, ApizrSettings: not null})
{
this.docGenerator.AppendMethodDocumentation(operationModel, IsApiResponseType(returnType), false, hasApizrRequestOptionsParameter, code);
if (settings.GenerateXmlDocCodeComments)
{
this.docGenerator.AppendMethodDocumentation(operationModel, IsApiResponseType(returnType), false, hasApizrRequestOptionsParameter, code);
}
GenerateObsoleteAttribute(operation, code);
GenerateForMultipartFormData(operationModel, code);
GenerateHeaders(operations, operation, operationModel, code);
Expand Down Expand Up @@ -290,10 +297,13 @@ private string GenerateInterfaceDeclaration(out string interfaceName)
: null;

var modifier = settings.TypeAccessibility.ToString().ToLowerInvariant();
return $"""
var code = new StringBuilder();
docGenerator.AppendInterfaceDocumentation(document, code);
code.Append($"""
{Separator}{GetGeneratedCodeAttribute()}
{Separator}{modifier} partial interface {interfaceName}{inheritance}
""";
""");
return code.ToString();
Comment thread
christianhelle marked this conversation as resolved.
}

protected string GetGeneratedCodeAttribute() =>
Expand Down
21 changes: 21 additions & 0 deletions src/Refitter.Core/XmlDocumentationGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,38 @@ internal XmlDocumentationGenerator(RefitGeneratorSettings settings)

/// <summary>
/// Appends XML docs for the given interface definition to the given code builder.
/// This uses the OpenAPI operation info to generate the summary and remarks.
/// </summary>
/// <param name="group">The OpenAPI definition of the interface.</param>
/// <param name="code">The builder to append the documentation to.</param>
public void AppendInterfaceDocumentation(OpenApiOperation group, StringBuilder code)
{
if (!_settings.GenerateXmlDocCodeComments || string.IsNullOrWhiteSpace(group.Summary))
{
this.AppendXmlCommentBlock("summary", "Refit interface - no description available", code, indent: Separator);
return;
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.

this.AppendXmlCommentBlock("summary", group.Summary, code, indent: Separator);
}

/// <summary>
/// Appends XML docs for the given interface definition to the given code builder.
/// This uses the OpenAPI document's info description as the summary.
/// </summary>
/// <param name="document">The OpenAPI definition of the interface.</param>
/// <param name="code">The builder to append the documentation to.</param>
public void AppendInterfaceDocumentation(OpenApiDocument document, StringBuilder code)
{
if (!_settings.GenerateXmlDocCodeComments || string.IsNullOrWhiteSpace(document.Info?.Title))
{
this.AppendXmlCommentBlock("summary", "Refit interface - no description available", code, indent: Separator);
return;
}

this.AppendXmlCommentBlock("summary", document.Info!.Title, code, indent: Separator);
}

/// <summary>
/// Appends XML docs for the given method to the given code builder.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

namespace Refitter.Tests.AdditionalFiles.NoFilename
{
/// <summary>Swagger Petstore - OpenAPI 3.0</summary>
[System.CodeDom.Compiler.GeneratedCode("Refitter", "1.0.0.0")]
public partial interface ISwaggerPetstore
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

namespace Refitter.Tests.AdditionalFiles.OptionalParameters
{
/// <summary>Swagger Petstore - OpenAPI 3.0</summary>
[System.CodeDom.Compiler.GeneratedCode("Refitter", "1.0.0.0")]
public partial interface ISwaggerPetstoreWithOptionalParameters
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

namespace Refitter.Tests.AdditionalFiles.SingeInterfaceWithHttpResilience
{
/// <summary>Swagger Petstore - OpenAPI 3.0</summary>
[System.CodeDom.Compiler.GeneratedCode("Refitter", "1.0.0.0")]
public partial interface ISwaggerPetstoreInterfaceWithHttpResilience
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

namespace Refitter.Tests.AdditionalFiles.SingeInterface
{
/// <summary>Swagger Petstore - OpenAPI 3.0</summary>
[System.CodeDom.Compiler.GeneratedCode("Refitter", "1.0.0.0")]
public partial interface ISwaggerPetstoreInterface
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

namespace Refitter.Tests.UseJsonInheritanceConverter
{
/// <summary>Refit interface - no description available</summary>
[System.CodeDom.Compiler.GeneratedCode("Refitter", "1.0.0.0")]
public partial interface IApiClient
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

namespace Refitter.Tests.UsePolymorphicSerialization
{
/// <summary>Refit interface - no description available</summary>
[System.CodeDom.Compiler.GeneratedCode("Refitter", "1.0.0.0")]
public partial interface IApiClient
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

namespace Refitter.Tests.CustomGenerated
{
/// <summary>Swagger Petstore - OpenAPI 3.0</summary>
[System.CodeDom.Compiler.GeneratedCode("Refitter", "1.0.0.0")]
public partial interface IApiInCustomGeneratedFolder
{
Expand Down
3 changes: 2 additions & 1 deletion src/Refitter/GenerateCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,8 @@ private static RefitGeneratorSettings CreateRefitGeneratorSettings(Settings sett
ContractsNamespace = settings.ContractsNamespace,
UsePolymorphicSerialization = settings.UsePolymorphicSerialization,
GenerateDisposableClients = settings.GenerateDisposableClients,
CollectionFormat = settings.CollectionFormat
CollectionFormat = settings.CollectionFormat,
GenerateXmlDocCodeComments = !settings.NoXmlDocCodeComments
};
}
private static async Task WriteSingleFile(
Expand Down
7 changes: 6 additions & 1 deletion src/Refitter/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,12 @@ public sealed class Settings : CommandSettings
[Description("Don't add <auto-generated> header to output file")]
[CommandOption("--no-auto-generated-header")]
[DefaultValue(false)]
public bool NoAutoGeneratedHeader { get; set; }
public bool NoAutoGeneratedHeader { get; set; }

[Description("Don't generate XML doc comments for interfaces and operations")]
[CommandOption("--no-xml-doc-comments")]
[DefaultValue(false)]
public bool NoXmlDocCodeComments { get; set; }

[Description("Don't add <Accept> header to output file")]
[CommandOption("--no-accept-headers")]
Expand Down
Loading