diff --git a/src/Altinn.Swashbuckle/src/Altinn.Swashbuckle/XmlDoc/XmlDocOperationFilter.cs b/src/Altinn.Swashbuckle/src/Altinn.Swashbuckle/XmlDoc/XmlDocOperationFilter.cs index 1c20fd4..983e930 100644 --- a/src/Altinn.Swashbuckle/src/Altinn.Swashbuckle/XmlDoc/XmlDocOperationFilter.cs +++ b/src/Altinn.Swashbuckle/src/Altinn.Swashbuckle/XmlDoc/XmlDocOperationFilter.cs @@ -24,14 +24,20 @@ public XmlDocOperationFilter(IXmlDocProvider documentationProvider) /// public void Apply(OpenApiOperation operation, OperationFilterContext context) { - if (context.MethodInfo == null) return; + if (context.MethodInfo is null) + { + return; + } // If method is from a constructed generic type, look for comments from the generic type method var targetMethod = context.MethodInfo.DeclaringType is not null && context.MethodInfo.DeclaringType.IsConstructedGenericType ? context.MethodInfo.GetUnderlyingGenericTypeMethod() : context.MethodInfo; - if (targetMethod == null) return; + if (targetMethod is null) + { + return; + } ApplyControllerTags(operation, targetMethod.DeclaringType!); ApplyMethodTags(operation, targetMethod); @@ -39,7 +45,10 @@ public void Apply(OpenApiOperation operation, OperationFilterContext context) private void ApplyControllerTags(OpenApiOperation operation, Type controllerType) { - if (!_documentationProvider.TryGetXmlDoc(controllerType, out var methodNode)) return; + if (!_documentationProvider.TryGetXmlDoc(controllerType, out var methodNode)) + { + return; + } var responseNodes = methodNode.SelectChildren("response"); ApplyResponseTags(operation, responseNodes); @@ -47,17 +56,22 @@ private void ApplyControllerTags(OpenApiOperation operation, Type controllerType private void ApplyMethodTags(OpenApiOperation operation, MethodInfo methodInfo) { - var methodMemberName = XmlCommentsNodeNameHelper.GetMemberNameForMethod(methodInfo); - - if (!_documentationProvider.TryGetXmlDoc(methodInfo, out var methodNode)) return; + if (!_documentationProvider.TryGetXmlDoc(methodInfo, out var methodNode)) + { + return; + } var summaryNode = methodNode.SelectFirstChild("summary"); if (summaryNode != null) + { operation.Summary = XmlCommentsTextHelper.Humanize(summaryNode.InnerXml); + } var remarksNode = methodNode.SelectFirstChild("remarks"); if (remarksNode != null) + { operation.Description = XmlCommentsTextHelper.Humanize(remarksNode.InnerXml); + } var responseNodes = methodNode.SelectChildren("response"); ApplyResponseTags(operation, responseNodes); @@ -79,7 +93,7 @@ private void ApplyResponseTags(OpenApiOperation operation, XPathNodeIterator res operation.Responses[code] = response; } - response.Description = XmlCommentsTextHelper.Humanize(responseNodes.Current.InnerXml); + response.Description = XmlCommentsTextHelper.Humanize(responseNodes.Current!.InnerXml); } } } diff --git a/src/Altinn.Swashbuckle/src/Altinn.Swashbuckle/XmlDoc/XmlDocParameterFilter.cs b/src/Altinn.Swashbuckle/src/Altinn.Swashbuckle/XmlDoc/XmlDocParameterFilter.cs index 0509e9b..12d71a1 100644 --- a/src/Altinn.Swashbuckle/src/Altinn.Swashbuckle/XmlDoc/XmlDocParameterFilter.cs +++ b/src/Altinn.Swashbuckle/src/Altinn.Swashbuckle/XmlDoc/XmlDocParameterFilter.cs @@ -49,21 +49,30 @@ private void ApplyPropertyTags(OpenApiParameter parameter, ParameterFilterContex } var exampleNode = propertyNode.SelectFirstChild("example"); - if (exampleNode == null) return; + if (exampleNode == null) + { + return; + } parameter.Example = XmlCommentsExampleHelper.Create(context.SchemaRepository, parameter.Schema, exampleNode.ToString()); } private void ApplyParamTags(OpenApiParameter parameter, ParameterFilterContext context) { - if (!(context.ParameterInfo.Member is MethodInfo methodInfo)) return; + if (context.ParameterInfo.Member is not MethodInfo methodInfo) + { + return; + } // If method is from a constructed generic type, look for comments from the generic type method - var targetMethod = methodInfo.DeclaringType.IsConstructedGenericType + var targetMethod = methodInfo.DeclaringType!.IsConstructedGenericType ? methodInfo.GetUnderlyingGenericTypeMethod() : methodInfo; - if (targetMethod == null) return; + if (targetMethod == null) + { + return; + } if (!_documentationProvider.TryGetXmlDoc(targetMethod, out var propertyNode)) { @@ -77,7 +86,10 @@ private void ApplyParamTags(OpenApiParameter parameter, ParameterFilterContext c parameter.Description = XmlCommentsTextHelper.Humanize(paramNode.InnerXml); var example = paramNode.GetAttribute("example"); - if (string.IsNullOrEmpty(example)) return; + if (string.IsNullOrEmpty(example)) + { + return; + } parameter.Example = XmlCommentsExampleHelper.Create(context.SchemaRepository, parameter.Schema, example); } diff --git a/src/Altinn.Swashbuckle/test/Altinn.Swashbuckle.Tests/Fixtures/XmlAnnotatedTypeWithoutExample.cs b/src/Altinn.Swashbuckle/test/Altinn.Swashbuckle.Tests/Fixtures/XmlAnnotatedTypeWithoutExample.cs index e763d27..dedecc1 100644 --- a/src/Altinn.Swashbuckle/test/Altinn.Swashbuckle.Tests/Fixtures/XmlAnnotatedTypeWithoutExample.cs +++ b/src/Altinn.Swashbuckle/test/Altinn.Swashbuckle.Tests/Fixtures/XmlAnnotatedTypeWithoutExample.cs @@ -48,20 +48,20 @@ public class XmlAnnotatedTypeWithoutExample /// /// Summary for Nullable StringPropertyWithNullExample /// - public string StringPropertyWithNullExample { get; set; } + public string? StringPropertyWithNullExample { get; set; } /// /// Summary for StringProperty /// - public string StringProperty { get; set; } + public string? StringProperty { get; set; } /// /// Summary for StringPropertyWithUri /// - public string StringPropertyWithUri { get; set; } + public string? StringPropertyWithUri { get; set; } /// /// Summary for ObjectProperty /// - public object ObjectProperty { get; set; } + public object? ObjectProperty { get; set; } }