generated from codebeltnet/dotnet-new-classlib
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🔀 migrated code from Cuemon.Extensions.Swashbuckle.AspNetCore incl. …
…unit-test
- Loading branch information
1 parent
e18b20c
commit 675bec7
Showing
29 changed files
with
1,443 additions
and
116 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,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 |
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
18 changes: 18 additions & 0 deletions
18
...ebelt.Extensions.Swashbuckle.AspNetCore/Codebelt.Extensions.Swashbuckle.AspNetCore.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,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> |
57 changes: 57 additions & 0 deletions
57
src/Codebelt.Extensions.Swashbuckle.AspNetCore/ConfigureSwaggerGenOptions.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,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); | ||
} | ||
} | ||
} | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
src/Codebelt.Extensions.Swashbuckle.AspNetCore/ConfigureSwaggerUIOptions.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,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
53
src/Codebelt.Extensions.Swashbuckle.AspNetCore/DocumentFilter.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,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; } | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/Codebelt.Extensions.Swashbuckle.AspNetCore/GlobalSuppressions.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,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}")] |
43 changes: 43 additions & 0 deletions
43
src/Codebelt.Extensions.Swashbuckle.AspNetCore/OpenApiInfoOptions.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,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>(); | ||
} | ||
} |
Oops, something went wrong.