-
Notifications
You must be signed in to change notification settings - Fork 15
feature/dependabot-groups #211
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
0676f9c
chore(deps): bump Swashbuckle.AspNetCore from 8.1.0 to 8.1.1
nanotaboada fd6be45
chore(ci): adjust Dependabot groups
nanotaboada 1dc5a42
refactor(controllers)!: adjust routes to match public identifier
nanotaboada 1bc5e2c
feat: extract Swagger options into dedicated SwaggerGenDefaults class
nanotaboada de96a21
fix(controllers): adjust log messages to match routes
nanotaboada File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or 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
Binary file not shown.
47 changes: 47 additions & 0 deletions
47
src/Dotnet.Samples.AspNetCore.WebApi/Configurations/AuthorizeCheckOperationFilter.cs
This file contains hidden or 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,47 @@ | ||
| using System.Linq; | ||
| using Microsoft.AspNetCore.Authorization; | ||
| using Microsoft.OpenApi.Models; | ||
| using Swashbuckle.AspNetCore.SwaggerGen; | ||
|
|
||
| namespace Dotnet.Samples.AspNetCore.WebApi.Configurations | ||
| { | ||
| /// <summary> | ||
| /// Adds the Bearer security requirement only to operations that have [Authorize] attributes. | ||
| /// </summary> | ||
| public class AuthorizeCheckOperationFilter : IOperationFilter | ||
| { | ||
| public void Apply(OpenApiOperation operation, OperationFilterContext context) | ||
| { | ||
| // Check if [Authorize] is applied at the method or class level | ||
| var hasAuthorize = | ||
| context.MethodInfo.GetCustomAttributes(true).OfType<AuthorizeAttribute>().Any() | ||
| || context | ||
| .MethodInfo.DeclaringType?.GetCustomAttributes(true) | ||
| .OfType<AuthorizeAttribute>() | ||
| .Any() == true; | ||
|
|
||
| // If there's no [Authorize] attribute, skip adding the security requirement | ||
| if (!hasAuthorize) | ||
| return; | ||
|
|
||
| // Add security requirement (shows the lock icon) | ||
| operation.Security ??= new List<OpenApiSecurityRequirement>(); | ||
| operation.Security.Add( | ||
| new OpenApiSecurityRequirement | ||
| { | ||
| { | ||
| new OpenApiSecurityScheme | ||
| { | ||
| Reference = new OpenApiReference | ||
| { | ||
| Id = "Bearer", | ||
| Type = ReferenceType.SecurityScheme | ||
| } | ||
| }, | ||
| Array.Empty<string>() | ||
| } | ||
| } | ||
| ); | ||
| } | ||
| } | ||
| } |
68 changes: 68 additions & 0 deletions
68
src/Dotnet.Samples.AspNetCore.WebApi/Configurations/SwaggerDocOptions.cs
This file contains hidden or 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,68 @@ | ||
| using System.Reflection; | ||
| using Microsoft.OpenApi.Models; | ||
|
|
||
| namespace Dotnet.Samples.AspNetCore.WebApi.Configurations; | ||
|
|
||
| /// <summary> | ||
| /// Provides centralized configuration methods for Swagger/OpenAPI docs. | ||
| /// Includes XML comments path resolution and security (JWT Bearer) setup. | ||
| /// </summary> | ||
| public static class SwaggerGenDefaults | ||
| { | ||
| /// <summary> | ||
| /// Resolves the path to the XML comments file generated from code | ||
| /// documentation. | ||
| /// This is used to enrich the Swagger UI with method summaries and remarks. | ||
| /// </summary> | ||
| /// <returns>Full file path to the XML documentation file.</returns> | ||
| public static string ConfigureXmlCommentsFilePath() | ||
| { | ||
| return Path.Combine( | ||
| AppContext.BaseDirectory, | ||
| $"{Assembly.GetExecutingAssembly().GetName().Name}.xml" | ||
| ); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Configures the OpenAPI security definition for JWT Bearer authentication. | ||
| /// This will show the padlock icon in Swagger UI and allow users to | ||
| /// authenticate. | ||
| /// </summary> | ||
| /// <returns>An <see cref="OpenApiSecurityScheme"/> describing the Bearer token format.</returns> | ||
| public static OpenApiSecurityScheme ConfigureSecurityDefinition() | ||
| { | ||
| return new OpenApiSecurityScheme | ||
| { | ||
| Name = "Authorization", | ||
| Type = SecuritySchemeType.Http, | ||
| Scheme = "bearer", | ||
| BearerFormat = "JWT", | ||
| In = ParameterLocation.Header, | ||
| Description = "Enter your JWT token below. Example: Bearer {token}" | ||
| }; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Adds a global security requirement to the Swagger spec that applies | ||
| /// the Bearer definition. | ||
| /// Routes decorated with [Authorize] will be marked as protected in the UI. | ||
| /// </summary> | ||
| /// <returns>An <see cref="OpenApiSecurityRequirement"/> referencing the Bearer definition.</returns> | ||
| public static OpenApiSecurityRequirement ConfigureSecurityRequirement() | ||
| { | ||
| return new OpenApiSecurityRequirement | ||
| { | ||
| { | ||
| new OpenApiSecurityScheme | ||
| { | ||
| Reference = new OpenApiReference | ||
| { | ||
| Id = "Bearer", | ||
| Type = ReferenceType.SecurityScheme | ||
| } | ||
| }, | ||
| Array.Empty<string>() | ||
| } | ||
| }; | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.