Skip to content

Commit

Permalink
🔀 migrated code from Cuemon.Extensions.Swashbuckle.AspNetCore incl. …
Browse files Browse the repository at this point in the history
…unit-test
  • Loading branch information
gimlichael committed Sep 21, 2024
1 parent e18b20c commit 675bec7
Show file tree
Hide file tree
Showing 29 changed files with 1,443 additions and 116 deletions.
46 changes: 0 additions & 46 deletions ClassLibrary1.sln

This file was deleted.

39 changes: 39 additions & 0 deletions Codebelt..Extensions.Swashbuckle.AspNetCore.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.9.34728.123
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{0070E83B-2DDD-4537-A83F-1CF8644F2880}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{A3C56B2E-55EE-44EC-876E-B03B8DDA3317}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Codebelt.Extensions.Swashbuckle.AspNetCore", "src\Codebelt.Extensions.Swashbuckle.AspNetCore\Codebelt.Extensions.Swashbuckle.AspNetCore.csproj", "{AA0ADF91-E7C7-4CB4-A39D-E1A5374C5602}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Codebelt.Extensions.Swashbuckle.AspNetCore.Tests", "test\Codebelt.Extensions.Swashbuckle.AspNetCore.Tests\Codebelt.Extensions.Swashbuckle.AspNetCore.Tests.csproj", "{F529CFC3-9892-4F7A-BB8D-5D32181C319A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{AA0ADF91-E7C7-4CB4-A39D-E1A5374C5602}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AA0ADF91-E7C7-4CB4-A39D-E1A5374C5602}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AA0ADF91-E7C7-4CB4-A39D-E1A5374C5602}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AA0ADF91-E7C7-4CB4-A39D-E1A5374C5602}.Release|Any CPU.Build.0 = Release|Any CPU
{F529CFC3-9892-4F7A-BB8D-5D32181C319A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F529CFC3-9892-4F7A-BB8D-5D32181C319A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F529CFC3-9892-4F7A-BB8D-5D32181C319A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F529CFC3-9892-4F7A-BB8D-5D32181C319A}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{AA0ADF91-E7C7-4CB4-A39D-E1A5374C5602} = {0070E83B-2DDD-4537-A83F-1CF8644F2880}
{F529CFC3-9892-4F7A-BB8D-5D32181C319A} = {A3C56B2E-55EE-44EC-876E-B03B8DDA3317}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {0CBE2805-F0FF-4D0F-902C-8B9277A5D3F2}
EndGlobalSection
EndGlobal
26 changes: 13 additions & 13 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<IsTestProject>$(MSBuildProjectName.EndsWith('Tests'))</IsTestProject>
<IsLinux>$([MSBuild]::IsOSPlatform('Linux'))</IsLinux>
<IsWindows>$([MSBuild]::IsOSPlatform('Windows'))</IsWindows>
<IsMainAuthor Condition="'$(EMAIL)' == 'classlibrary1@dot.net'">true</IsMainAuthor>
<IsMainAuthor Condition="'$(EMAIL)' == 'michael@geekle.io'">true</IsMainAuthor>
<SkipSignAssembly>false</SkipSignAssembly>
<LangVersion>latest</LangVersion>
</PropertyGroup>
Expand All @@ -15,16 +15,16 @@
</PropertyGroup>

<PropertyGroup Condition="'$(IsTestProject)' == 'false'">
<TargetFrameworks>net8.0</TargetFrameworks>
<Copyright>Copyright © ClassLibrary1 2024. All rights reserved.</Copyright>
<Authors>ClassLibrary1</Authors>
<Company>ClassLibrary1</Company>
<Product>ClassLibrary1</Product>
<TargetFrameworks>net8.0;net6.0</TargetFrameworks>
<Copyright>Copyright © Geekle 2024. All rights reserved.</Copyright>
<Authors>gimlichael</Authors>
<Company>Geekle</Company>
<Product>Extensions for Swashbuckle.AspNetCore API by Codebelt</Product>
<PackageIcon>icon.png</PackageIcon>
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageProjectUrl>https://www.classlibrary1.net/</PackageProjectUrl>
<PackageProjectUrl>https://swashbuckle.codebelt.net/</PackageProjectUrl>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<RepositoryUrl>https://github.com/classlibrary1/ClassLibrary1</RepositoryUrl>
<RepositoryUrl>https://github.com/codebeltnet/swashbuckle-aspnetcore</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<NeutralLanguage>en-US</NeutralLanguage>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
Expand All @@ -33,27 +33,27 @@
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<SignAssembly Condition="('$(CI)' == 'true' OR '$(IsMainAuthor)' == 'true') AND '$(SkipSignAssembly)' == 'false'">true</SignAssembly>
<AssemblyOriginatorKeyFile>$(MSBuildThisFileDirectory)ClassLibrary1.snk</AssemblyOriginatorKeyFile>
<AssemblyOriginatorKeyFile>$(MSBuildThisFileDirectory)swashbuckle.snk</AssemblyOriginatorKeyFile>
<NoWarn>7035,CA2260</NoWarn>
</PropertyGroup>

<ItemGroup Condition="'$(NuGetPackageRoot)' != ''">
<SourceRoot Include="$(NuGetPackageRoot)" RepositoryUrl="https://github.com/classlibrary1/ClassLibrary1" />
<SourceRoot Include="$(NuGetPackageRoot)" RepositoryUrl="https://github.com/codebeltnet/swashbuckle-aspnetcore" />
</ItemGroup>

<ItemGroup Condition="'$(IsTestProject)' == 'false'">
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="all" />
<PackageReference Include="MinVer" Version="6.0.0" PrivateAssets="all" />
<None Include="..\..\.nuget\$(MSBuildProjectName)\icon.png" Pack="true" Visible="false" PackagePath="\" />
<None Include="..\..\.nuget\icon.png" Pack="true" Visible="false" PackagePath="\" />
<None Include="..\..\.nuget\$(MSBuildProjectName)\README.md" Pack="true" PackagePath="\" />
</ItemGroup>

<PropertyGroup Condition="'$(IsTestProject)' == 'true' AND '$(IsLinux)' == 'true'">
<TargetFrameworks>net8.0</TargetFrameworks>
<TargetFrameworks>net8.0;net6.0</TargetFrameworks>
</PropertyGroup>

<PropertyGroup Condition="'$(IsTestProject)' == 'true' AND '$(IsWindows)' == 'true'">
<TargetFrameworks>net8.0</TargetFrameworks>
<TargetFrameworks>net8.0;net6.0</TargetFrameworks>
</PropertyGroup>

<PropertyGroup Condition="'$(IsTestProject)' == 'true'">
Expand Down
7 changes: 0 additions & 7 deletions src/ClassLibrary1/Class1.cs

This file was deleted.

5 changes: 0 additions & 5 deletions src/ClassLibrary1/ClassLibrary1.csproj

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<ProjectGuid>9f667892-7018-4d30-9b07-ec75a4bc32b3</ProjectGuid>
<OpenApiGenerateDocuments>false</OpenApiGenerateDocuments>
</PropertyGroup>

<PropertyGroup>
<Description>The Codebelt.Extensions.Swashbuckle.AspNetCore namespace contains types and extension methods that complements the Swashbuckle.AspNetCore namespace by adding new ways of working with Swagger 2.0 and OpenAPI 3.0.</Description>
<PackageTags>extension-methods extensions document-filter operation-filter restful user-agent x-api-key jwt-bearer restful-swagger</PackageTags>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Codebelt.Extensions.Asp.Versioning" Version="8.4.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.7.3" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using Asp.Versioning.ApiExplorer;
using Cuemon.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using Microsoft.OpenApi.Models;
using Swashbuckle.AspNetCore.SwaggerGen;

namespace Codebelt.Extensions.Swashbuckle.AspNetCore
{
/// <summary>
/// Represents something that configures the <see cref="SwaggerGenOptions"/> type.
/// Note: These are run before all <see cref="IPostConfigureOptions{TOptions}"/>.
/// </summary>
/// <seealso cref="IConfigureOptions{SwaggerUIOptions}" />
public class ConfigureSwaggerGenOptions : Configurable<RestfulSwaggerOptions>, IConfigureOptions<SwaggerGenOptions>
{
private readonly IApiVersionDescriptionProvider _provider;

/// <summary>
/// Initializes a new instance of the <see cref="ConfigureSwaggerGenOptions"/> class.
/// </summary>
/// <param name="provider">The behavior of a provider that discovers and describes API version information within an application.</param>
/// <param name="restfulSwaggerOptions">The options for configuring the <see cref="SwaggerGenOptions"/>.</param>
public ConfigureSwaggerGenOptions(IApiVersionDescriptionProvider provider, IOptions<RestfulSwaggerOptions> restfulSwaggerOptions) : base(restfulSwaggerOptions.Value)
{
_provider = provider;
}

/// <summary>
/// Invoked to configure a <see cref="SwaggerGenOptions"/> instance.
/// </summary>
/// <param name="options">The options instance to configure.</param>
public void Configure(SwaggerGenOptions options)
{
foreach (var description in _provider.ApiVersionDescriptions)
{
options.SwaggerDoc(
description.GroupName,
new OpenApiInfo()
{
Title = Options.OpenApiInfo.Title ?? $"API {description.ApiVersion}",
Description = Options.OpenApiInfo.Description,
Contact = Options.OpenApiInfo.Contact,
License = Options.OpenApiInfo.License,
TermsOfService = Options.OpenApiInfo.TermsOfService,
Version = description.ApiVersion.ToString(),
Extensions = Options.OpenApiInfo.Extensions
});

foreach (var xmldoc in Options.XmlDocumentations)
{
options.IncludeXmlComments(() => xmldoc, Options.IncludeControllerXmlComments);
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System.Linq;
using Asp.Versioning.ApiExplorer;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.Options;
using Swashbuckle.AspNetCore.SwaggerUI;

namespace Codebelt.Extensions.Swashbuckle.AspNetCore
{
/// <summary>
/// Represents something that configures the <see cref="SwaggerUIOptions"/> type.
/// Note: These are run before all <see cref="IPostConfigureOptions{TOptions}"/>.
/// </summary>
/// <seealso cref="IConfigureOptions{SwaggerUIOptions}" />
public class ConfigureSwaggerUIOptions : IConfigureOptions<SwaggerUIOptions>
{
private readonly IApiVersionDescriptionProvider _provider;

/// <summary>
/// Initializes a new instance of the <see cref="ConfigureSwaggerUIOptions"/> class.
/// </summary>
/// <param name="provider">The behavior of a provider that discovers and describes API version information within an application.</param>
public ConfigureSwaggerUIOptions(IApiVersionDescriptionProvider provider)
{
_provider = provider;
}

/// <summary>
/// Invoked to configure a <see cref="SwaggerUIOptions"/> instance.
/// </summary>
/// <param name="options">The options instance to configure.</param>
public void Configure(SwaggerUIOptions options)
{
foreach (var groupName in _provider.ApiVersionDescriptions.Select(description => description.GroupName))
{
options.SwaggerEndpoint($"/swagger/{groupName}/swagger.json", groupName.ToUpperInvariant());
}
}
}
}
53 changes: 53 additions & 0 deletions src/Codebelt.Extensions.Swashbuckle.AspNetCore/DocumentFilter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using Cuemon;
using Cuemon.Configuration;
using Microsoft.OpenApi.Models;
using Swashbuckle.AspNetCore.SwaggerGen;

namespace Codebelt.Extensions.Swashbuckle.AspNetCore
{
/// <summary>
/// Represents the base class of an <see cref="IDocumentFilter"/> implementation.
/// </summary>
/// <seealso cref="IDocumentFilter" />
/// <remarks>https://github.com/domaindrivendev/Swashbuckle.AspNetCore#document-filters</remarks>
public abstract class DocumentFilter : IDocumentFilter
{
/// <summary>
/// Initializes a new instance of the <see cref="DocumentFilter"/> class.
/// </summary>
protected DocumentFilter()
{
}

/// <summary>
/// Applies post-processing to the <paramref name="swaggerDoc"/>.
/// </summary>
/// <param name="swaggerDoc">The <see cref="OpenApiDocument"/> to modify.</param>
/// <param name="context">The <see cref="DocumentFilterContext"/> that provides additional context.</param>
/// <remarks>Once an <seealso cref="OpenApiDocument"/> has been generated you have full control to modify the document however you see fit.</remarks>
public abstract void Apply(OpenApiDocument swaggerDoc, DocumentFilterContext context);
}

/// <summary>
/// Represents a configurable base class of an <see cref="IDocumentFilter"/> implementation.
/// </summary>
/// <seealso cref="DocumentFilter"/>
public abstract class DocumentFilter<T> : DocumentFilter, IConfigurable<T> where T : class, IParameterObject, new()
{
/// <summary>
/// Initializes a new instance of the <see cref="DocumentFilter{T}"/> class.
/// </summary>
/// <param name="options">The configured options of this instance.</param>
protected DocumentFilter(T options)
{
Validator.ThrowIfNull(options);
Options = options;
}

/// <summary>
/// Gets the configured options of this instance.
/// </summary>
/// <value>The configured options of this instance.</value>
public T Options { get; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// This file is used by Code Analysis to maintain SuppressMessage
// attributes that are applied to this project.
// Project-level suppressions either have no target or are given
// a specific target and scoped to a namespace, type, member, etc.

using System.Diagnostics.CodeAnalysis;

[assembly: SuppressMessage("Security", "CA5372:Use XmlReader for XPathDocument constructor", Justification = "Does not apply to XML documentation files.", Scope = "member", Target = "~M:Cuemon.Extensions.Swashbuckle.AspNetCore.XPathDocumentExtensions.AddByFilename(System.Collections.Generic.IList{System.Xml.XPath.XPathDocument},System.String)~System.Collections.Generic.IList{System.Xml.XPath.XPathDocument}")]
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using System;
using System.Collections.Generic;
using Microsoft.OpenApi.Interfaces;
using Microsoft.OpenApi.Models;

namespace Codebelt.Extensions.Swashbuckle.AspNetCore
{
/// <summary>
/// Represents a proxy for configuring an Open API Info Object that provides metadata about an Open API endpoint.
/// </summary>
public class OpenApiInfoOptions
{
/// <summary>
/// The title of the application.
/// </summary>
public string Title { get; set; }

/// <summary>
/// A short description of the application.
/// </summary>
public string Description { get; set; }

/// <summary>
/// A URL to the Terms of Service for the API.
/// </summary>
public Uri TermsOfService { get; set; }

/// <summary>
/// The contact information for the exposed API.
/// </summary>
public OpenApiContact Contact { get; set; }

/// <summary>
/// The license information for the exposed API.
/// </summary>
public OpenApiLicense License { get; set; }

/// <summary>
/// This object MAY be extended with Specification Extensions.
/// </summary>
public IDictionary<string, IOpenApiExtension> Extensions { get; set; } = new Dictionary<string, IOpenApiExtension>();
}
}
Loading

0 comments on commit 675bec7

Please sign in to comment.