last ...
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
using System.Linq;
|
||||
using Microsoft.OpenApi.Any;
|
||||
using Microsoft.OpenApi.Models;
|
||||
using Swashbuckle.AspNetCore.SwaggerGen;
|
||||
using xCommons.Configurations;
|
||||
using xCommons.Extensions;
|
||||
|
||||
namespace xCommons.Filters
|
||||
{
|
||||
public class SwaggerDefaultValuesOperationFilter : IOperationFilter
|
||||
{
|
||||
private readonly XSwaggerConfiguration config;
|
||||
|
||||
public SwaggerDefaultValuesOperationFilter(
|
||||
XSwaggerConfiguration config
|
||||
)
|
||||
{
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
public void Apply(
|
||||
OpenApiOperation operation,
|
||||
OperationFilterContext context
|
||||
)
|
||||
{
|
||||
//
|
||||
// Validate Configuration ...
|
||||
if (
|
||||
!config.IsNull() &&
|
||||
!config.DefaultValues.IsNull() &&
|
||||
config.DefaultValues.HasChild()
|
||||
)
|
||||
{
|
||||
//
|
||||
foreach (var prv in config.DefaultValues)
|
||||
{
|
||||
//
|
||||
// Detect Parameter ...
|
||||
var swaggerParam = operation.Parameters.FirstOrDefault(p => p.Name == prv.Key);
|
||||
if (!swaggerParam.IsNull())
|
||||
{
|
||||
swaggerParam.Schema.Default = new OpenApiString(prv.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user