diff --git a/src/Refitter.Core/XmlDocumentationGenerator.cs b/src/Refitter.Core/XmlDocumentationGenerator.cs index 9f798000a..73fc620d5 100644 --- a/src/Refitter.Core/XmlDocumentationGenerator.cs +++ b/src/Refitter.Core/XmlDocumentationGenerator.cs @@ -46,11 +46,11 @@ public void AppendInterfaceDocumentationByTag(OpenApiDocument document, string t return; } - var controllerTag = document.Tags.FirstOrDefault(t => t.Name.SanitizeControllerTag() == tag); + var controllerTag = document.Tags?.FirstOrDefault(t => t.Name.SanitizeControllerTag() == tag); var controllerDescription = controllerTag?.Description; if (!string.IsNullOrEmpty(controllerDescription)) { - this.AppendXmlCommentBlock(SummaryTag, EscapeSymbols(controllerDescription), code, indent: Separator); + this.AppendXmlCommentBlock(SummaryTag, EscapeSymbols(controllerDescription!), code, indent: Separator); } } @@ -88,7 +88,7 @@ public void AppendSingleInterfaceDocumentation(OpenApiDocument document, StringB var title = document.Info?.Title; if (!string.IsNullOrEmpty(title)) { - this.AppendXmlCommentBlock(SummaryTag, EscapeSymbols(title), code, indent: Separator); + this.AppendXmlCommentBlock(SummaryTag, EscapeSymbols(title!), code, indent: Separator); } } @@ -334,6 +334,7 @@ private string BuildResponseDescription(string text, IEnumerable", ">"); } diff --git a/src/Refitter.SourceGenerator.Tests/AdditionalFiles/Generated/SwaggerPetstoreMultipleInterfaces.g.cs b/src/Refitter.SourceGenerator.Tests/AdditionalFiles/Generated/SwaggerPetstoreMultipleInterfaces.g.cs index cae33f5ad..f9aba24c0 100644 --- a/src/Refitter.SourceGenerator.Tests/AdditionalFiles/Generated/SwaggerPetstoreMultipleInterfaces.g.cs +++ b/src/Refitter.SourceGenerator.Tests/AdditionalFiles/Generated/SwaggerPetstoreMultipleInterfaces.g.cs @@ -191,6 +191,7 @@ public partial interface IUpdatePetWithFormEndpoint public partial interface IDeletePetEndpoint { /// Deletes a pet + /// api_key parameter /// Pet id to delete /// The cancellation token to cancel the request. /// A that completes when the request is finished. @@ -218,6 +219,7 @@ public partial interface IUploadFileEndpoint /// uploads an image /// ID of pet to update /// Additional Metadata + /// body parameter /// The cancellation token to cancel the request. /// /// A representing the instance containing the result: @@ -256,6 +258,7 @@ public partial interface IPlaceOrderEndpoint { /// Place an order for a pet /// Place a new order in the store + /// body parameter /// The cancellation token to cancel the request. /// successful operation /// @@ -357,6 +360,7 @@ public partial interface ICreateUsersWithListInputEndpoint { /// Creates list of users with given input array /// Creates list of users with given input array + /// body parameter /// The cancellation token to cancel the request. /// Successful operation /// Thrown when the request returns a non-success status code. diff --git a/src/Refitter.Tests/Examples/NumericFormatWithPatternTests.cs b/src/Refitter.Tests/Examples/NumericFormatWithPatternTests.cs index fa9edddfd..5e7337100 100644 --- a/src/Refitter.Tests/Examples/NumericFormatWithPatternTests.cs +++ b/src/Refitter.Tests/Examples/NumericFormatWithPatternTests.cs @@ -1,4 +1,4 @@ -using FluentAssertions; +using FluentAssertions; using Refitter.Core; using Refitter.Tests.Build; using Refitter.Tests.TestUtilities; diff --git a/src/Refitter.Tests/XmlDocumentationGeneratorTests.cs b/src/Refitter.Tests/XmlDocumentationGeneratorTests.cs index 2c3550321..47a9548ae 100644 --- a/src/Refitter.Tests/XmlDocumentationGeneratorTests.cs +++ b/src/Refitter.Tests/XmlDocumentationGeneratorTests.cs @@ -41,14 +41,46 @@ public void Can_Generate_Interface_Doc_With_Linebreaks() public void Can_Generate_Interface_Doc_From_Controller_Tag() { var docs = new StringBuilder(); - var controllerTag = new OpenApiTag { Name = "TestController", Description = "TestControllerDescription" }; - var document = new OpenApiDocument { Tags = [controllerTag] }; + var controllerTag = new OpenApiTag { Name = "TestController", Description = "TestControllerDescription" }; + var document = new OpenApiDocument { Tags = [controllerTag] }; this._generator.AppendInterfaceDocumentationByTag(document, "TestController", docs); docs.ToString().Trim().Should().Be("/// TestControllerDescription"); } + [Test] + public void Can_Handle_Null_Document_Tags() + { + var docs = new StringBuilder(); + var document = new OpenApiDocument { Tags = null }; + + this._generator.AppendInterfaceDocumentationByTag(document, "TestController", docs); + + docs.ToString().Trim().Should().BeEmpty(); + } + + [Test] + public void Can_Escape_Xml_Special_Characters_In_Interface_Doc() + { + var docs = new StringBuilder(); + var controllerTag = new OpenApiTag { Name = "TestController", Description = "Test & content" }; + var document = new OpenApiDocument { Tags = [controllerTag] }; + + this._generator.AppendInterfaceDocumentationByTag(document, "TestController", docs); + + docs.ToString().Trim().Should().Be("/// Test <tag> & content"); + } + + [Test] + public void Can_Escape_Xml_Special_Characters_In_Method_Summary() + { + var docs = new StringBuilder(); + var method = CreateOperationModel(new OpenApiOperation { Summary = "Test & content", }); + this._generator.AppendMethodDocumentation(method, false, false, false, false, docs); + docs.ToString().Trim().Should().StartWith("/// Test <tag> & content"); + } + [Test] public void Can_Generate_Method_Summary() {