Skip to content

Commit

Permalink
style: braces
Browse files Browse the repository at this point in the history
  • Loading branch information
Alxandr committed Mar 10, 2025
1 parent 5e89cc0 commit caa6f73
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,40 +24,54 @@ public XmlDocOperationFilter(IXmlDocProvider documentationProvider)
/// <inheritdoc />
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);
}

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);
}

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);
Expand All @@ -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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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))
{
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,20 @@ public class XmlAnnotatedTypeWithoutExample
/// <summary>
/// Summary for Nullable StringPropertyWithNullExample
/// </summary>
public string StringPropertyWithNullExample { get; set; }
public string? StringPropertyWithNullExample { get; set; }

/// <summary>
/// Summary for StringProperty
/// </summary>
public string StringProperty { get; set; }
public string? StringProperty { get; set; }

/// <summary>
/// Summary for StringPropertyWithUri
/// </summary>
public string StringPropertyWithUri { get; set; }
public string? StringPropertyWithUri { get; set; }

/// <summary>
/// Summary for ObjectProperty
/// </summary>
public object ObjectProperty { get; set; }
public object? ObjectProperty { get; set; }
}

0 comments on commit caa6f73

Please sign in to comment.