Skip to content

Commit

Permalink
Minor clean-up/re-naming on the back of previous commit
Browse files Browse the repository at this point in the history
  • Loading branch information
domaindrivendev committed Sep 20, 2019
1 parent f37443a commit 2b52181
Showing 1 changed file with 8 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Microsoft.OpenApi.Models;
using Swashbuckle.AspNetCore.SwaggerGen;

Expand All @@ -13,11 +12,11 @@ public void Apply(OpenApiOperation operation, OperationFilterContext context)
{
if (context.MethodInfo == null) return;

// Action descriptions should take precedence over controller descriptions and
// the most derived controller descrption should take precedence over the least,
// so do not overwrite the description if there is a value already there.
var controllerAttributes = context.MethodInfo.DeclaringType.GetTypeInfo().GetCustomAttributes(true);
var controllerAttributes = context.MethodInfo.DeclaringType.GetCustomAttributes(true);
var actionAttributes = context.MethodInfo.GetCustomAttributes(true);

// NOTE: When controller and action attributes are applicable, action attributes should take precendence.
// Hence why they're at the end of the list (i.e. last one wins)
var controllerAndActionAttributes = controllerAttributes.Union(actionAttributes);

ApplySwaggerOperationAttribute(operation, actionAttributes);
Expand Down Expand Up @@ -55,9 +54,9 @@ public void Apply(OpenApiOperation operation, OperationFilterContext context)
public static void ApplySwaggerOperationFilterAttributes(
OpenApiOperation operation,
OperationFilterContext context,
IEnumerable<object> actionAndControllerAttributes)
IEnumerable<object> controllerAndActionAttributes)
{
var swaggerOperationFilterAttributes = actionAndControllerAttributes
var swaggerOperationFilterAttributes = controllerAndActionAttributes
.OfType<SwaggerOperationFilterAttribute>();

foreach (var swaggerOperationFilterAttribute in swaggerOperationFilterAttributes)
Expand All @@ -69,9 +68,9 @@ public void Apply(OpenApiOperation operation, OperationFilterContext context)

private void ApplySwaggerResponseAttributes(
OpenApiOperation operation,
IEnumerable<object> actionAndControllerAttributes)
IEnumerable<object> controllerAndActionAttributes)
{
var swaggerResponseAttributes = actionAndControllerAttributes
var swaggerResponseAttributes = controllerAndActionAttributes
.OfType<SwaggerResponseAttribute>();

foreach (var swaggerResponseAttribute in swaggerResponseAttributes)
Expand Down

0 comments on commit 2b52181

Please sign in to comment.