Skip to content

Commit

Permalink
Add explicit HttpMethod bindings for Swagger/OpenAPI 3.0, Close #181
Browse files Browse the repository at this point in the history
  • Loading branch information
VahidN committed Aug 19, 2024
1 parent 317c476 commit 3082ba4
Show file tree
Hide file tree
Showing 13 changed files with 17 additions and 8 deletions.
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "8.0.204",
"version": "8.0.400",
"rollForward": "latestMajor",
"allowPrerelease": false
}
Expand Down
8 changes: 4 additions & 4 deletions src/DNTCaptcha.Core/DNTCaptcha.Core.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Description>DNTCaptcha.Core is a captcha generator and validator for ASP.NET Core applications.</Description>
<VersionPrefix>5.2.4</VersionPrefix>
<VersionPrefix>5.2.5</VersionPrefix>
<Authors>Vahid Nasiri</Authors>
<TargetFrameworks>net8.0;net7.0;net6.0;</TargetFrameworks>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
Expand Down Expand Up @@ -42,11 +42,11 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Meziantou.Analyzer" Version="2.0.150">
<PackageReference Include="Meziantou.Analyzer" Version="2.0.163">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.10.48">
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.11.20">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand All @@ -58,7 +58,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="SonarAnalyzer.CSharp" Version="9.25.0.90414">
<PackageReference Include="SonarAnalyzer.CSharp" Version="9.32.0.97167">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
3 changes: 3 additions & 0 deletions src/DNTCaptcha.Core/DNTCaptchaImageController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ namespace DNTCaptcha.Core;
/// DNTCaptcha Image Controller
/// </summary>
[AllowAnonymous]
[Route("[controller]")]
#if NET7_0 || NET8_0
[EnableRateLimiting(DNTCaptchaRateLimiterPolicy.Name)]
#endif
Expand Down Expand Up @@ -86,6 +87,7 @@ public DNTCaptchaImageController(ICaptchaImageProvider captchaImageProvider,
/// Refresh the captcha
/// </summary>
[ResponseCache(Location = ResponseCacheLocation.None, NoStore = true, Duration = 0)]
[Route("[action]"), HttpGet("[action]"), HttpPost("[action]")]
public IActionResult Refresh(string data)
{
try
Expand Down Expand Up @@ -180,6 +182,7 @@ private void invalidateToken(DNTCaptchaTagHelperHtmlAttributes model)
/// Creates the captcha image.
/// </summary>
[ResponseCache(Location = ResponseCacheLocation.None, NoStore = true, Duration = 0)]
[Route("[action]"), HttpGet("[action]"), HttpPost("[action]")]
public IActionResult Show(string data)
{
try
Expand Down
3 changes: 3 additions & 0 deletions src/DNTCaptcha.TestApiApp/DNTCaptcha.TestApiApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@
<ItemGroup>
<ProjectReference Include="..\DNTCaptcha.Core\DNTCaptcha.Core.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.7.1" />
</ItemGroup>
</Project>
5 changes: 4 additions & 1 deletion src/DNTCaptcha.TestApiApp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

void ConfigureServices(IServiceCollection services, IWebHostEnvironment env)
{
services.AddSwaggerGen();
services.AddDNTCaptcha(options =>
{
// options.UseSessionStorageProvider(); // -> It doesn't rely on the server or client's times. Also it's the safest one.
Expand All @@ -30,7 +31,7 @@ void ConfigureServices(IServiceCollection services, IWebHostEnvironment env)
// Don't set this line (remove it) to use the installed system's fonts (FontName = "Tahoma").
// Or if you want to use a custom font, make sure that font is present in the wwwroot/fonts folder and also use a good and complete font!
.UseCustomFont(Path.Combine(env.WebRootPath, "fonts", "IRANSans(FaNum)_Bold.ttf")).AbsoluteExpiration(7)
.UseCustomFont(Path.Combine(env.WebRootPath, "fonts", "tahoma.ttf")).AbsoluteExpiration(7)
.RateLimiterPermitLimit(
10) // for .NET 7x, Also you need to call app.UseRateLimiter() after calling app.UseRouting().
.ShowExceptionsInResponse(env.IsDevelopment()).ShowThousandsSeparators(false)
Expand Down Expand Up @@ -72,6 +73,8 @@ void ConfigureMiddlewares(IApplicationBuilder app, IHostEnvironment env)
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseSwagger();
app.UseSwaggerUI(); // The Swagger UI can be found at https://localhost:<port>/swagger
}

app.UseHttpsRedirection();
Expand Down
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion src/DNTCaptcha.TestRazorPages/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ void ConfigureServices(IServiceCollection services, IWebHostEnvironment env)
// Don't set this line (remove it) to use the installed system's fonts (FontName = "Tahoma").
// Or if you want to use a custom font, make sure that font is present in the wwwroot/fonts folder and also use a good and complete font!
.UseCustomFont(Path.Combine(env.WebRootPath, "fonts", "IRANSans(FaNum)_Bold.ttf")).AbsoluteExpiration(7)
.UseCustomFont(Path.Combine(env.WebRootPath, "fonts", "tahoma.ttf")).AbsoluteExpiration(7)
.RateLimiterPermitLimit(
10) // for .NET 7x, Also you need to call app.UseRateLimiter() after calling app.UseRouting().
.ShowExceptionsInResponse(env.IsDevelopment()).ShowThousandsSeparators(false)
Expand Down
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion src/DNTCaptcha.TestWebApp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ void ConfigureServices(IServiceCollection services, IWebHostEnvironment env)
// Don't set this line (remove it) to use the installed system's fonts (FontName = "Tahoma").
// Or if you want to use a custom font, make sure that font is present in the wwwroot/fonts folder and also use a good and complete font!
.UseCustomFont(Path.Combine(env.WebRootPath, "fonts", "IRANSans(FaNum)_Bold.ttf"))
.UseCustomFont(Path.Combine(env.WebRootPath, "fonts", "tahoma.ttf"))
.ShowExceptionsInResponse(env.IsDevelopment()).AbsoluteExpiration(1)
.RateLimiterPermitLimit(
10) // for .NET 7x, Also you need to call app.UseRateLimiter() after calling app.UseRouting().
Expand Down
Binary file not shown.
Binary file not shown.

0 comments on commit 3082ba4

Please sign in to comment.