Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/cicd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
id: tag
- uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x
dotnet-version: 10.0.x
- run: echo "::remove-matcher owner=csc::"
- uses: reviewdog/action-setup@v1
- run: dotnet --info
Expand Down
Original file line number Diff line number Diff line change
@@ -1,47 +1,42 @@
using Microsoft.Extensions.DependencyInjection;
using System.Collections.Generic;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi;
using Swashbuckle.AspNetCore.Filters;
using Swashbuckle.AspNetCore.SwaggerGen;

namespace Samhammer.Swagger.Authentication.Guest
{
public class ConfigureSwaggerGenGuest : IConfigureOptions<SwaggerGenOptions>
public class ConfigureSwaggerGenGuest(IOptions<SwaggerGuestOptions> options) : IConfigureOptions<SwaggerGenOptions>
{
private SwaggerGuestOptions Options { get; }
private SwaggerGuestOptions Options { get; } = options.Value;

private const string HeaderKey = "GuestID";

public ConfigureSwaggerGenGuest(IOptions<SwaggerGuestOptions> options)
{
Options = options.Value;
}

public void Configure(SwaggerGenOptions swaggerGen)
{
if (!Options.Enabled)
{
return;
}

var apiKeyRef = new OpenApiReference
{
Id = "Guest",
Type = ReferenceType.SecurityScheme,
};
const string schemeId = "Guest";

var apiKeyScheme = new OpenApiSecurityScheme
{
Reference = apiKeyRef,
Type = SecuritySchemeType.ApiKey,
In = ParameterLocation.Header,
Name = HeaderKey,
};

swaggerGen.AddSecurityDefinition(apiKeyRef.Id, apiKeyScheme);
swaggerGen.AddSecurityRequirement(new OpenApiSecurityRequirement { { apiKeyScheme, new string[] { } } });
swaggerGen.AddSecurityDefinition(schemeId, apiKeyScheme);

swaggerGen.AddSecurityRequirement(document => new OpenApiSecurityRequirement
{
[new OpenApiSecuritySchemeReference(schemeId, document)] = new List<string>(),
});

swaggerGen.OperationFilter<SecurityRequirementsOperationFilter>(true, apiKeyScheme.Reference.Id);
swaggerGen.OperationFilter<SecurityRequirementsOperationFilter>(true, schemeId);

if (!swaggerGen.OperationFilterDescriptors.Exists(f => f.Type == typeof(AppendAuthorizeToSummaryOperationFilter)))
{
Expand Down
11 changes: 3 additions & 8 deletions src/Samhammer.Swagger.Authentication/Jwt/ConfigureSwaggerGen.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
using System;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi;
using Swashbuckle.AspNetCore.Filters;
using Swashbuckle.AspNetCore.SwaggerGen;

namespace Samhammer.Swagger.Authentication.Jwt
{
public class ConfigureSwaggerGen : IConfigureOptions<SwaggerGenOptions>
public class ConfigureSwaggerGen(IOptions<SwaggerAuthOptions> options) : IConfigureOptions<SwaggerGenOptions>
{
private SwaggerAuthOptions Options { get; }

public ConfigureSwaggerGen(IOptions<SwaggerAuthOptions> options)
{
Options = options.Value;
}
private SwaggerAuthOptions Options { get; } = options.Value;

public void Configure(SwaggerGenOptions swaggerGen)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<CodeAnalysisRuleSet>..\stylecop.ruleset</CodeAnalysisRuleSet>
<Authors>Samhammer AG</Authors>
<Company>Samhammer AG</Company>
Expand All @@ -17,11 +17,11 @@
<None Include="..\..\README.md" Pack="true" PackagePath="\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.376">
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.556">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
<PackageReference Include="Swashbuckle.AspNetCore.Filters" Version="8.0.1" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="10.1.0" />
<PackageReference Include="Swashbuckle.AspNetCore.Filters" Version="10.0.1" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion src/Samhammer.Swagger.Default/ConfigureSwaggerGen.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi;
using Swashbuckle.AspNetCore.SwaggerGen;

namespace Samhammer.Swagger.Default
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<CodeAnalysisRuleSet>..\stylecop.ruleset</CodeAnalysisRuleSet>
<Authors>Samhammer AG</Authors>
<Company>Samhammer AG</Company>
Expand All @@ -17,10 +17,10 @@
<None Include="..\..\README.md" Pack="true" PackagePath="\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.376">
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.556">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="10.1.0" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<CodeAnalysisRuleSet>..\stylecop.ruleset</CodeAnalysisRuleSet>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
Expand All @@ -12,11 +12,11 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.376">
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.556">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="10.1.0" />
</ItemGroup>

<ItemGroup>
Expand Down
14 changes: 4 additions & 10 deletions src/Samhammer.Swagger.Versioning/ConfigureSwaggerGen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,16 @@
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi;
using Swashbuckle.AspNetCore.SwaggerGen;

namespace Samhammer.Swagger.Versioning
{
public class ConfigureSwaggerGen : IConfigureOptions<SwaggerGenOptions>
public class ConfigureSwaggerGen(IApiVersionDescriptionProvider provider, IWebHostEnvironment hostingEnv) : IConfigureOptions<SwaggerGenOptions>
{
private IApiVersionDescriptionProvider Provider { get; }
private IApiVersionDescriptionProvider Provider { get; } = provider;

private IWebHostEnvironment HostingEnv { get; }

public ConfigureSwaggerGen(IApiVersionDescriptionProvider provider, IWebHostEnvironment hostingEnv)
{
Provider = provider;
HostingEnv = hostingEnv;
}
private IWebHostEnvironment HostingEnv { get; } = hostingEnv;

public void Configure(SwaggerGenOptions options)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<CodeAnalysisRuleSet>..\stylecop.ruleset</CodeAnalysisRuleSet>
<Authors>Samhammer AG</Authors>
<Company>Samhammer AG</Company>
Expand All @@ -17,11 +17,11 @@
<None Include="..\..\README.md" Pack="true" PackagePath="\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Asp.Versioning.Mvc.ApiExplorer" Version="8.0.0" />
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.376">
<PackageReference Include="Asp.Versioning.Mvc.ApiExplorer" Version="8.1.1" />
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.556">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="10.1.0" />
</ItemGroup>
</Project>