From 0501df91c75ddbfa71f2dc6bdb52e201acad27a4 Mon Sep 17 00:00:00 2001
From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com>
Date: Sun, 3 Dec 2023 20:13:56 +0000
Subject: [PATCH 1/2] Update dependency
MicroElements.Swashbuckle.FluentValidation to v6
---
Directory.Packages.props | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/Directory.Packages.props b/Directory.Packages.props
index c45e9839d..af9cc369d 100644
--- a/Directory.Packages.props
+++ b/Directory.Packages.props
@@ -74,7 +74,7 @@
-
+
From 616c7d5886c9b389e27bbf7a98da18363bf05cba Mon Sep 17 00:00:00 2001
From: David Driscoll
Date: Sun, 31 Dec 2023 00:14:02 -0500
Subject: [PATCH 2/2] private properties are weird
---
.../Conventions/FluentValidationConvention.cs | 27 +++++++++++++++----
1 file changed, 22 insertions(+), 5 deletions(-)
diff --git a/src/AspNetCore/Conventions/FluentValidationConvention.cs b/src/AspNetCore/Conventions/FluentValidationConvention.cs
index be518f5a2..dc56e7b14 100644
--- a/src/AspNetCore/Conventions/FluentValidationConvention.cs
+++ b/src/AspNetCore/Conventions/FluentValidationConvention.cs
@@ -1,6 +1,7 @@
using System.Reflection;
using FluentValidation.AspNetCore;
using FluentValidation.Validators;
+using MicroElements.OpenApi.FluentValidation;
using MicroElements.Swashbuckle.FluentValidation;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
@@ -33,7 +34,13 @@ private static void AddFluentValidationRules(IServiceCollection services)
.WithApply(
context =>
{
- var propertyType = context.ReflectionContext.PropertyInfo?.DeclaringType ?? context.ReflectionContext.ParameterInfo?.ParameterType;
+ var ruleContext = ((ValidationRuleContext)context
+ .GetType()
+ .GetProperties(BindingFlags.Instance | BindingFlags.NonPublic)
+ .First(z => z.PropertyType == typeof(ValidationRuleContext))
+ .GetValue(context))
+ .GetReflectionContext();
+ var propertyType = ruleContext?.PropertyInfo?.DeclaringType;
if (propertyType == typeof(string))
{
context.Schema.Properties[context.PropertyKey].MinLength = 1;
@@ -47,7 +54,13 @@ private static void AddFluentValidationRules(IServiceCollection services)
.WithApply(
context =>
{
- var propertyType = context.ReflectionContext.PropertyInfo?.DeclaringType ?? context.ReflectionContext.ParameterInfo?.ParameterType;
+ var ruleContext = ((ValidationRuleContext)context
+ .GetType()
+ .GetProperties(BindingFlags.Instance | BindingFlags.NonPublic)
+ .First(z => z.PropertyType == typeof(ValidationRuleContext))
+ .GetValue(context))
+ .GetReflectionContext();
+ var propertyType = ruleContext?.PropertyInfo?.DeclaringType;
if (propertyType != null &&
( ( propertyType.IsValueType && Nullable.GetUnderlyingType(propertyType) == null ) ||
propertyType.IsEnum ))
@@ -64,11 +77,15 @@ private static void AddFluentValidationRules(IServiceCollection services)
.WithApply(
context =>
{
+ var ruleContext = ((ValidationRuleContext)context
+ .GetType()
+ .GetProperties(BindingFlags.Instance | BindingFlags.NonPublic)
+ .First(z => z.PropertyType == typeof(ValidationRuleContext))
+ .GetValue(context))
+ .GetReflectionContext();
context.Schema.Properties[context.PropertyKey].Nullable =
context.PropertyValidator is not (INotNullValidator or INotEmptyValidator)
- || ( context.ReflectionContext.ParameterInfo is { } pai && getNullableValue(pai.GetNullability(), pai.ParameterType) )
- || ( context.ReflectionContext.PropertyInfo is PropertyInfo pi && getNullableValue(pi.GetNullability(), pi.PropertyType) )
- || ( context.ReflectionContext.PropertyInfo is FieldInfo fi && getNullableValue(fi.GetNullability(), fi.FieldType) )
+ || ( ruleContext.PropertyInfo is FieldInfo fi && getNullableValue(fi.GetNullability(), fi.FieldType) )
;
static bool getNullableValue(Nullability nullability, Type propertyType)