-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add default response handling and update OpenAPI config (#229)
- Loading branch information
Showing
8 changed files
with
50 additions
and
16 deletions.
There are no files selected for viewing
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 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 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 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 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
38 changes: 38 additions & 0 deletions
38
src/TinyHelpers.AspNetCore/OpenApi/DefaultResponseOperationTransformer.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,38 @@ | ||
#if NET9_0_OR_GREATER | ||
|
||
using System.Net.Mime; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.AspNetCore.OpenApi; | ||
using Microsoft.OpenApi.Models; | ||
|
||
namespace TinyHelpers.AspNetCore.OpenApi; | ||
|
||
internal class DefaultResponseOperationTransformer : IOpenApiOperationTransformer | ||
{ | ||
public Task TransformAsync(OpenApiOperation operation, OpenApiOperationTransformerContext context, CancellationToken cancellationToken) | ||
{ | ||
var defaultResponse = new OpenApiResponse() | ||
{ | ||
Description = "Error", | ||
Content = new Dictionary<string, OpenApiMediaType> | ||
{ | ||
[MediaTypeNames.Application.ProblemJson] = new() | ||
{ | ||
Schema = new() | ||
{ | ||
Reference = new() | ||
{ | ||
Id = nameof(ProblemDetails), | ||
Type = ReferenceType.Schema | ||
} | ||
} | ||
} | ||
} | ||
}; | ||
|
||
operation.Responses.TryAdd("default", defaultResponse); | ||
return Task.CompletedTask; | ||
} | ||
} | ||
|
||
#endif |
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 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