build: add support .net 10
All checks were successful
Build and Deploy Docker Container / build-and-deploy (push) Successful in 4m33s
All checks were successful
Build and Deploy Docker Container / build-and-deploy (push) Successful in 4m33s
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -1,81 +0,0 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.OpenApi.Models;
|
||||
using Swashbuckle.AspNetCore.SwaggerGen;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Mirea.Api.Endpoint.Configuration.SwaggerOptions;
|
||||
|
||||
public class ActionResultSchemaFilter : IOperationFilter
|
||||
{
|
||||
public void Apply(OpenApiOperation operation, OperationFilterContext context)
|
||||
{
|
||||
var returnType = context.MethodInfo.ReturnType;
|
||||
if (!returnType.IsEquivalentTo(typeof(ActionResult)) &&
|
||||
!returnType.IsEquivalentTo(typeof(ContentResult)) &&
|
||||
!returnType.IsEquivalentTo(typeof(FileStreamResult)) &&
|
||||
!returnType.IsGenericType)
|
||||
return;
|
||||
|
||||
if (returnType.IsGenericType &&
|
||||
!returnType.GetGenericTypeDefinition().IsEquivalentTo(typeof(ActionResult<>)) &&
|
||||
!returnType.GetGenericTypeDefinition().IsEquivalentTo(typeof(Task<>)))
|
||||
return;
|
||||
|
||||
var genericType = returnType.IsGenericType ? returnType.GetGenericArguments().FirstOrDefault() : returnType;
|
||||
if (genericType == null)
|
||||
return;
|
||||
|
||||
var responseTypeAttributes = context.MethodInfo.GetCustomAttributes(typeof(ProducesResponseTypeAttribute), false)
|
||||
.Cast<ProducesResponseTypeAttribute>()
|
||||
.Where(attr => attr.StatusCode == 200)
|
||||
.ToList();
|
||||
|
||||
var contentType = "application/json";
|
||||
|
||||
if (context.MethodInfo.GetCustomAttributes(typeof(ProducesAttribute), false)
|
||||
.FirstOrDefault() is ProducesAttribute producesAttribute)
|
||||
contentType = producesAttribute.ContentTypes.FirstOrDefault() ?? "application/json";
|
||||
|
||||
if (responseTypeAttributes.Count != 0)
|
||||
{
|
||||
var responseType = responseTypeAttributes.First().Type;
|
||||
genericType = responseType;
|
||||
}
|
||||
|
||||
if (genericType.IsEquivalentTo(typeof(ContentResult)) || genericType.IsEquivalentTo(typeof(FileStreamResult)))
|
||||
{
|
||||
operation.Responses["200"] = new OpenApiResponse
|
||||
{
|
||||
Description = "OK",
|
||||
Content = new Dictionary<string, OpenApiMediaType>
|
||||
{
|
||||
[contentType] = new()
|
||||
}
|
||||
};
|
||||
}
|
||||
else if (genericType == typeof(ActionResult))
|
||||
{
|
||||
operation.Responses["200"] = new OpenApiResponse { Description = "OK" };
|
||||
}
|
||||
else
|
||||
{
|
||||
OpenApiSchema schema;
|
||||
if (genericType.IsGenericType && genericType.GetGenericTypeDefinition() == typeof(ActionResult<>))
|
||||
schema = context.SchemaGenerator.GenerateSchema(genericType.GetGenericArguments().FirstOrDefault(),
|
||||
context.SchemaRepository);
|
||||
else
|
||||
schema = context.SchemaGenerator.GenerateSchema(genericType, context.SchemaRepository);
|
||||
|
||||
operation.Responses["200"] = new OpenApiResponse
|
||||
{
|
||||
Description = "OK",
|
||||
Content = new Dictionary<string, OpenApiMediaType>
|
||||
{
|
||||
[contentType] = new() { Schema = schema }
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -1,51 +0,0 @@
|
||||
using Microsoft.AspNetCore.Mvc.ApiExplorer;
|
||||
using Microsoft.AspNetCore.Mvc.ModelBinding;
|
||||
using Microsoft.OpenApi.Models;
|
||||
using Swashbuckle.AspNetCore.SwaggerGen;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace Mirea.Api.Endpoint.Configuration.SwaggerOptions;
|
||||
|
||||
public class DefaultValues : IOperationFilter
|
||||
{
|
||||
public void Apply(OpenApiOperation operation, OperationFilterContext context)
|
||||
{
|
||||
var apiDescription = context.ApiDescription;
|
||||
operation.Deprecated |= apiDescription.IsDeprecated();
|
||||
|
||||
foreach (var responseType in context.ApiDescription.SupportedResponseTypes)
|
||||
{
|
||||
var responseKey = responseType.IsDefaultResponse ? "default" : responseType.StatusCode.ToString();
|
||||
var response = operation.Responses[responseKey];
|
||||
|
||||
foreach (var contentType in response.Content.Keys)
|
||||
{
|
||||
if (responseType.ApiResponseFormats.All(x => x.MediaType != contentType))
|
||||
response.Content.Remove(contentType);
|
||||
}
|
||||
}
|
||||
|
||||
if (operation.Parameters == null)
|
||||
return;
|
||||
|
||||
foreach (var parameter in operation.Parameters)
|
||||
{
|
||||
var description = apiDescription.ParameterDescriptions.First(p => p.Name == parameter.Name);
|
||||
|
||||
parameter.Description ??= description.ModelMetadata.Description;
|
||||
|
||||
if (parameter.Schema.Default == null &&
|
||||
description.DefaultValue != null &&
|
||||
description.DefaultValue is not DBNull &&
|
||||
description.ModelMetadata is ModelMetadata modelMetadata)
|
||||
{
|
||||
var json = JsonSerializer.Serialize(description.DefaultValue, modelMetadata.ModelType);
|
||||
parameter.Schema.Default = OpenApiAnyFactory.CreateFromJson(json);
|
||||
}
|
||||
|
||||
parameter.Required |= description.IsRequired;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
using Microsoft.OpenApi.Any;
|
||||
using Microsoft.OpenApi.Models;
|
||||
using Swashbuckle.AspNetCore.SwaggerGen;
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace Mirea.Api.Endpoint.Configuration.SwaggerOptions;
|
||||
|
||||
public class EnumSchemaFilter : ISchemaFilter
|
||||
{
|
||||
public void Apply(OpenApiSchema schema, SchemaFilterContext context)
|
||||
{
|
||||
if (!context.Type.IsEnum)
|
||||
return;
|
||||
|
||||
schema.Enum.Clear();
|
||||
|
||||
var enumValues = Enum.GetNames(context.Type)
|
||||
.Select(name => new OpenApiString(name))
|
||||
.ToList();
|
||||
|
||||
foreach (var value in enumValues)
|
||||
schema.Enum.Add(value);
|
||||
|
||||
schema.Type = "string";
|
||||
schema.Format = null;
|
||||
}
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
using Microsoft.OpenApi.Models;
|
||||
using Mirea.Api.Endpoint.Common.Attributes;
|
||||
using Swashbuckle.AspNetCore.SwaggerGen;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Mirea.Api.Endpoint.Configuration.SwaggerOptions;
|
||||
|
||||
public class ExampleFilter : ISchemaFilter
|
||||
{
|
||||
public void Apply(OpenApiSchema schema, SchemaFilterContext context)
|
||||
{
|
||||
var att = context.ParameterInfo?.GetCustomAttribute<SwaggerDefaultAttribute>();
|
||||
if (att != null)
|
||||
schema.Example = new Microsoft.OpenApi.Any.OpenApiString(att.Value);
|
||||
}
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc.Controllers;
|
||||
using Microsoft.OpenApi.Models;
|
||||
using Swashbuckle.AspNetCore.SwaggerGen;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Mirea.Api.Endpoint.Configuration.SwaggerOptions;
|
||||
|
||||
public class TagSchemeFilter : IOperationFilter
|
||||
{
|
||||
public void Apply(OpenApiOperation operation, OperationFilterContext context)
|
||||
{
|
||||
if (context.ApiDescription.ActionDescriptor is not ControllerActionDescriptor controllerActionDescriptor)
|
||||
return;
|
||||
|
||||
var controllerType = controllerActionDescriptor.ControllerTypeInfo;
|
||||
|
||||
var tagsAttribute = controllerType.GetCustomAttributes<TagsAttribute>(inherit: true).FirstOrDefault();
|
||||
|
||||
if (tagsAttribute == null)
|
||||
{
|
||||
var baseType = controllerType.BaseType;
|
||||
while (baseType != null)
|
||||
{
|
||||
tagsAttribute = baseType.GetCustomAttributes<TagsAttribute>(inherit: true).FirstOrDefault();
|
||||
if (tagsAttribute != null)
|
||||
break;
|
||||
|
||||
baseType = baseType.BaseType;
|
||||
}
|
||||
}
|
||||
|
||||
if (tagsAttribute == null)
|
||||
return;
|
||||
|
||||
operation.Tags ??= [];
|
||||
operation.Tags.Add(new OpenApiTag { Name = tagsAttribute.Tags[0] });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user