-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
105 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using Microsoft.AspNetCore.Mvc; | ||
|
||
namespace SimpleEndpoints.Swashbuckle | ||
{ | ||
public static class MvcOptionsExtensions | ||
{ | ||
public static void AddSwashbuckleCompatibilityForSimpleEndpoints(this MvcOptions options) | ||
{ | ||
options.Conventions.Add(new SwashbuckleCompatibilityConvention()); | ||
} | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/SimpleEndpoints.Swashbuckle/SimpleEndpoints.Swashbuckle.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netcoreapp3.1</TargetFramework> | ||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild> | ||
<Description>Swashbuckle support for SimpleEndpoints. | ||
A simple, convention-based, endpoint per action pattern implementation for AspNetCore 3.0+</Description> | ||
<Copyright>2020 Dasith Wijesiriwardena</Copyright> | ||
<PackageProjectUrl>https://github.com/dasiths/SimpleEndpoints</PackageProjectUrl> | ||
<RepositoryUrl>https://github.com/dasiths/SimpleEndpoints</RepositoryUrl> | ||
<RepositoryType>Git</RepositoryType> | ||
<PackageTags>aspnetcore api controller endpoints swashbuckle</PackageTags> | ||
<Version>1.2.0</Version> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.2.0" /> | ||
</ItemGroup> | ||
|
||
</Project> |
29 changes: 29 additions & 0 deletions
29
src/SimpleEndpoints.Swashbuckle/SwashbuckleCompatibilityConvention.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using System.Linq; | ||
using Microsoft.AspNetCore.Mvc.ActionConstraints; | ||
using Microsoft.AspNetCore.Mvc.ApplicationModels; | ||
using Microsoft.AspNetCore.Mvc.Routing; | ||
|
||
namespace SimpleEndpoints.Swashbuckle | ||
{ | ||
public class SwashbuckleCompatibilityConvention : IApplicationModelConvention | ||
{ | ||
public void Apply(ApplicationModel application) | ||
{ | ||
foreach (var action in application.Controllers.SelectMany(c => c.Actions)) | ||
{ | ||
if (action.Selectors.Any() && | ||
action.Selectors[0].ActionConstraints.Count == 0 && | ||
action.ApiExplorer.IsVisible.GetValueOrDefault(false)) | ||
{ | ||
var attribute = action.Attributes.FirstOrDefault(a => a is HttpMethodAttribute); | ||
|
||
if (attribute is HttpMethodAttribute item) | ||
{ | ||
var o = new HttpMethodActionConstraint(item.HttpMethods); | ||
action.Selectors[0].ActionConstraints.Add(o); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters