aboutsummaryrefslogtreecommitdiffstats
path: root/server/src/Utilities/SwaggerDefaultValues.cs
diff options
context:
space:
mode:
authorivarlovlie <git@ivarlovlie.no>2022-10-05 14:45:21 +0200
committerivarlovlie <git@ivarlovlie.no>2022-10-05 14:45:21 +0200
commitb7e39b59fd0fc7b5610ebff29035bf622079e0d8 (patch)
tree64be84ebbdac9f7ceced983390c53b10d575af5c /server/src/Utilities/SwaggerDefaultValues.cs
parent2001c035fbb417ab0a3d42cfb04d17420bde4086 (diff)
downloadgreatoffice-b7e39b59fd0fc7b5610ebff29035bf622079e0d8.tar.xz
greatoffice-b7e39b59fd0fc7b5610ebff29035bf622079e0d8.zip
refactor: Change file structure
Diffstat (limited to 'server/src/Utilities/SwaggerDefaultValues.cs')
-rw-r--r--server/src/Utilities/SwaggerDefaultValues.cs58
1 files changed, 0 insertions, 58 deletions
diff --git a/server/src/Utilities/SwaggerDefaultValues.cs b/server/src/Utilities/SwaggerDefaultValues.cs
deleted file mode 100644
index 4b5c764..0000000
--- a/server/src/Utilities/SwaggerDefaultValues.cs
+++ /dev/null
@@ -1,58 +0,0 @@
-using Microsoft.AspNetCore.Mvc.ApiExplorer;
-using Swashbuckle.AspNetCore.SwaggerGen;
-
-namespace IOL.GreatOffice.Api.Utilities;
-
-/// <summary>
-/// Represents the Swagger/Swashbuckle operation filter used to document the implicit API version parameter.
-/// </summary>
-/// <remarks>This <see cref="IOperationFilter"/> is only required due to bugs in the <see cref="SwaggerGenerator"/>.
-/// Once they are fixed and published, this class can be removed.</remarks>
-public class SwaggerDefaultValues : IOperationFilter
-{
- /// <summary>
- /// Applies the filter to the specified operation using the given context.
- /// </summary>
- /// <param name="operation">The operation to apply the filter to.</param>
- /// <param name="context">The current operation filter context.</param>
- public void Apply(OpenApiOperation operation, OperationFilterContext context) {
- var apiDescription = context.ApiDescription;
-
- operation.Deprecated |= apiDescription.IsDeprecated();
-
- // REF: https://github.com/domaindrivendev/Swashbuckle.AspNetCore/issues/1752#issue-663991077
- foreach (var responseType in context.ApiDescription.SupportedResponseTypes) {
- // REF: https://github.com/domaindrivendev/Swashbuckle.AspNetCore/blob/b7cf75e7905050305b115dd96640ddd6e74c7ac9/src/Swashbuckle.AspNetCore.SwaggerGen/SwaggerGenerator/SwaggerGenerator.cs#L383-L387
- var responseKey = responseType.IsDefaultResponse ? "default" : responseType.StatusCode.ToString();
- var response = operation.Responses[responseKey];
-
- foreach (var contentType in response.Content.Keys) {
- if (!responseType.ApiResponseFormats.Any(x => x.MediaType == contentType)) {
- response.Content.Remove(contentType);
- }
- }
- }
-
- if (operation.Parameters == null) {
- return;
- }
-
- // REF: https://github.com/domaindrivendev/Swashbuckle.AspNetCore/issues/412
- // REF: https://github.com/domaindrivendev/Swashbuckle.AspNetCore/pull/413
- foreach (var parameter in operation.Parameters) {
- var description = apiDescription.ParameterDescriptions.First(p => p.Name == parameter.Name);
-
- if (parameter.Description == null) {
- parameter.Description = description.ModelMetadata.Description;
- }
-
- if (parameter.Schema.Default == null && description.DefaultValue != null) {
- // REF: https://github.com/Microsoft/aspnet-api-versioning/issues/429#issuecomment-605402330
- var json = JsonSerializer.Serialize(description.DefaultValue, description.ModelMetadata.ModelType);
- parameter.Schema.Default = OpenApiAnyFactory.CreateFromJson(json);
- }
-
- parameter.Required |= description.IsRequired;
- }
- }
-}