From a29f84caf894dc288d9e0e7bc1e77288b358c971 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roberto=20Fern=C3=A1ndez=20Salinas?= Date: Fri, 13 Jun 2025 13:05:32 +0200 Subject: [PATCH 01/16] Remove .NET Framework 4.8.1 tests --- .github/workflows/github_build_and_publish.yml | 8 +++++--- build.cake | 2 +- build.sh | 2 +- .../MicroElements.NSwag.FluentValidation.csproj | 1 + .../MicroElements.Swashbuckle.FluentValidation.csproj | 1 + ...icroElements.Swashbuckle.FluentValidation.Tests.csproj | 2 +- .../SchemaGenerationTests.cs | 2 +- 7 files changed, 11 insertions(+), 7 deletions(-) diff --git a/.github/workflows/github_build_and_publish.yml b/.github/workflows/github_build_and_publish.yml index 64efc6d..1b9a0e1 100644 --- a/.github/workflows/github_build_and_publish.yml +++ b/.github/workflows/github_build_and_publish.yml @@ -9,7 +9,11 @@ on: jobs: build: - runs-on: ubuntu-latest + runs-on: ${{ matrix.os }} + + strategy: + matrix: + os: [ubuntu-latest, windows-latest] steps: # Шаг 1: Клонируем репозиторий @@ -31,5 +35,3 @@ jobs: run: | chmod a+x ./build.sh ./build.sh --target=Travis --verbosity=normal --ForceUploadPackages=true - - diff --git a/build.cake b/build.cake index 6a6cf6b..fb63049 100644 --- a/build.cake +++ b/build.cake @@ -68,4 +68,4 @@ Task("AppVeyor") .IsDependentOn("UploadTestResultsToAppVeyor") ; -RunTarget(args.Target); +RunTarget(args.Target); \ No newline at end of file diff --git a/build.sh b/build.sh index eb69310..0f91738 100644 --- a/build.sh +++ b/build.sh @@ -80,4 +80,4 @@ dotnet tool restore echo "Running build script..." CMD="dotnet cake $SCRIPT ${CAKE_ARGUMENTS[@]}" echo $CMD -exec $CMD +exec $CMD \ No newline at end of file diff --git a/src/MicroElements.NSwag.FluentValidation/MicroElements.NSwag.FluentValidation.csproj b/src/MicroElements.NSwag.FluentValidation/MicroElements.NSwag.FluentValidation.csproj index 0714ff6..cad1dba 100644 --- a/src/MicroElements.NSwag.FluentValidation/MicroElements.NSwag.FluentValidation.csproj +++ b/src/MicroElements.NSwag.FluentValidation/MicroElements.NSwag.FluentValidation.csproj @@ -13,6 +13,7 @@ + diff --git a/src/MicroElements.Swashbuckle.FluentValidation/MicroElements.Swashbuckle.FluentValidation.csproj b/src/MicroElements.Swashbuckle.FluentValidation/MicroElements.Swashbuckle.FluentValidation.csproj index 6ea7d7f..4696e1f 100644 --- a/src/MicroElements.Swashbuckle.FluentValidation/MicroElements.Swashbuckle.FluentValidation.csproj +++ b/src/MicroElements.Swashbuckle.FluentValidation/MicroElements.Swashbuckle.FluentValidation.csproj @@ -13,6 +13,7 @@ + diff --git a/test/MicroElements.Swashbuckle.FluentValidation.Tests/MicroElements.Swashbuckle.FluentValidation.Tests.csproj b/test/MicroElements.Swashbuckle.FluentValidation.Tests/MicroElements.Swashbuckle.FluentValidation.Tests.csproj index 7116aac..78e6d28 100644 --- a/test/MicroElements.Swashbuckle.FluentValidation.Tests/MicroElements.Swashbuckle.FluentValidation.Tests.csproj +++ b/test/MicroElements.Swashbuckle.FluentValidation.Tests/MicroElements.Swashbuckle.FluentValidation.Tests.csproj @@ -1,7 +1,7 @@  - net481;net8.0;net9.0 + net8.0;net9.0 enable latest false diff --git a/test/MicroElements.Swashbuckle.FluentValidation.Tests/SchemaGenerationTests.cs b/test/MicroElements.Swashbuckle.FluentValidation.Tests/SchemaGenerationTests.cs index 59c76cb..b7d2a1b 100644 --- a/test/MicroElements.Swashbuckle.FluentValidation.Tests/SchemaGenerationTests.cs +++ b/test/MicroElements.Swashbuckle.FluentValidation.Tests/SchemaGenerationTests.cs @@ -97,7 +97,7 @@ public void MaximumLength_ShouldNot_Override_NotNull() public void SampleValidator_FromSampleApi_Test() { var schemaRepository = new SchemaRepository(); - var referenceSchema = SchemaGenerator(new RuleHistoryCacheTest.SampleValidator()).GenerateSchema(typeof(RuleHistoryCacheTest.Sample), schemaRepository); + var referenceSchema = SchemaGenerator(new SampleValidator()).GenerateSchema(typeof(Sample), schemaRepository); var schema = schemaRepository.Schemas[referenceSchema.Reference.Id]; schema.Type.Should().Be("object"); From e93abfddb6e9d3c41b1bf5274c98e401e41a2bff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roberto=20Fern=C3=A1ndez=20Salinas?= Date: Fri, 13 Jun 2025 13:05:32 +0200 Subject: [PATCH 02/16] Remove .NET Framework 4.8.1 tests --- .../workflows/github_build_and_publish.yml | 8 +++--- build.cake | 27 ++++++++++++++++--- build.sh | 2 +- ...icroElements.NSwag.FluentValidation.csproj | 1 + ...ements.Swashbuckle.FluentValidation.csproj | 1 + .../SchemaGenerationTests.cs | 2 +- 6 files changed, 32 insertions(+), 9 deletions(-) diff --git a/.github/workflows/github_build_and_publish.yml b/.github/workflows/github_build_and_publish.yml index 64efc6d..1b9a0e1 100644 --- a/.github/workflows/github_build_and_publish.yml +++ b/.github/workflows/github_build_and_publish.yml @@ -9,7 +9,11 @@ on: jobs: build: - runs-on: ubuntu-latest + runs-on: ${{ matrix.os }} + + strategy: + matrix: + os: [ubuntu-latest, windows-latest] steps: # Шаг 1: Клонируем репозиторий @@ -31,5 +35,3 @@ jobs: run: | chmod a+x ./build.sh ./build.sh --target=Travis --verbosity=normal --ForceUploadPackages=true - - diff --git a/build.cake b/build.cake index 6a6cf6b..9897993 100644 --- a/build.cake +++ b/build.cake @@ -21,9 +21,28 @@ ScriptArgs args = new ScriptArgs(Context) Task("Build") .Does(() => args.Build().BuildSamples()); -Task("Test") - .WithCriteria(()=>args.RunTests) - .Does(() => RunTests(args)); +var isWindows = Environment.Platform.Family == PlatformFamily.Windows; +Task("Tests") + .Does(() => + { + var solution = "MicroElements.Swashbuckle.FluentValidation.sln"; + + if (isWindows) + { + Information("Executing tests net481, net8.0, net9.0 on Windows"); + + DotNetTest(solution, new DotNetTestSettings { Framework = "net481" }); + DotNetTest(solution, new DotNetTestSettings { Framework = "net8.0" }); + DotNetTest(solution, new DotNetTestSettings { Framework = "net9.0" }); + } + else + { + Information("Executing tests net8.0 y net9.0 on Linux/macOS"); + + DotNetTest(solution, new DotNetTestSettings { Framework = "net8.0" }); + DotNetTest(solution, new DotNetTestSettings { Framework = "net9.0" }); + } + }); Task("UploadTestResultsToAppVeyor") .WithCriteria(()=>args.RunTests) @@ -68,4 +87,4 @@ Task("AppVeyor") .IsDependentOn("UploadTestResultsToAppVeyor") ; -RunTarget(args.Target); +RunTarget(args.Target); \ No newline at end of file diff --git a/build.sh b/build.sh index eb69310..0f91738 100644 --- a/build.sh +++ b/build.sh @@ -80,4 +80,4 @@ dotnet tool restore echo "Running build script..." CMD="dotnet cake $SCRIPT ${CAKE_ARGUMENTS[@]}" echo $CMD -exec $CMD +exec $CMD \ No newline at end of file diff --git a/src/MicroElements.NSwag.FluentValidation/MicroElements.NSwag.FluentValidation.csproj b/src/MicroElements.NSwag.FluentValidation/MicroElements.NSwag.FluentValidation.csproj index 0714ff6..cad1dba 100644 --- a/src/MicroElements.NSwag.FluentValidation/MicroElements.NSwag.FluentValidation.csproj +++ b/src/MicroElements.NSwag.FluentValidation/MicroElements.NSwag.FluentValidation.csproj @@ -13,6 +13,7 @@ + diff --git a/src/MicroElements.Swashbuckle.FluentValidation/MicroElements.Swashbuckle.FluentValidation.csproj b/src/MicroElements.Swashbuckle.FluentValidation/MicroElements.Swashbuckle.FluentValidation.csproj index 6ea7d7f..4696e1f 100644 --- a/src/MicroElements.Swashbuckle.FluentValidation/MicroElements.Swashbuckle.FluentValidation.csproj +++ b/src/MicroElements.Swashbuckle.FluentValidation/MicroElements.Swashbuckle.FluentValidation.csproj @@ -13,6 +13,7 @@ + diff --git a/test/MicroElements.Swashbuckle.FluentValidation.Tests/SchemaGenerationTests.cs b/test/MicroElements.Swashbuckle.FluentValidation.Tests/SchemaGenerationTests.cs index 59c76cb..b7d2a1b 100644 --- a/test/MicroElements.Swashbuckle.FluentValidation.Tests/SchemaGenerationTests.cs +++ b/test/MicroElements.Swashbuckle.FluentValidation.Tests/SchemaGenerationTests.cs @@ -97,7 +97,7 @@ public void MaximumLength_ShouldNot_Override_NotNull() public void SampleValidator_FromSampleApi_Test() { var schemaRepository = new SchemaRepository(); - var referenceSchema = SchemaGenerator(new RuleHistoryCacheTest.SampleValidator()).GenerateSchema(typeof(RuleHistoryCacheTest.Sample), schemaRepository); + var referenceSchema = SchemaGenerator(new SampleValidator()).GenerateSchema(typeof(Sample), schemaRepository); var schema = schemaRepository.Schemas[referenceSchema.Reference.Id]; schema.Type.Should().Be("object"); From eba3ad48247de2b486e9c5643f42508cb645536a Mon Sep 17 00:00:00 2001 From: avgalex <35622249+avgalex@users.noreply.github.com> Date: Tue, 26 Nov 2024 02:21:40 +0300 Subject: [PATCH 03/16] Update github_build_and_publish.yml --- .../workflows/github_build_and_publish.yml | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/.github/workflows/github_build_and_publish.yml b/.github/workflows/github_build_and_publish.yml index 3da252a..7695781 100644 --- a/.github/workflows/github_build_and_publish.yml +++ b/.github/workflows/github_build_and_publish.yml @@ -1,23 +1,29 @@ name: Build and publish on: + workflow_dispatch: # Ручной запуск push: - branches: [ master ] + branches: [ master ] # Запуск при пуше в master pull_request: - branches: [ master ] + branches: [ master ] # Запуск для pull_request в master jobs: build: runs-on: ubuntu-latest steps: + # Шаг 1: Клонируем репозиторий - uses: actions/checkout@v3 + + # Шаг 2: Устанавливаем .NET SDK - name: Setup .NET SDK uses: actions/setup-dotnet@v3 with: dotnet-version: | 8.0.x 9.0.x + + # Шаг 3: Сборка проекта - name: Build env: UPLOAD_NUGET: ${{ secrets.UPLOAD_NUGET }} @@ -25,3 +31,15 @@ jobs: run: | chmod a+x ./build.sh ./build.sh --target=Travis --verbosity=normal --ForceUploadPackages=false + + # Шаг 4: Публикация пакета на NuGet + - name: Publish to NuGet + if: success() # Публиковать только при успешной сборке + run: | + if ls ./bin/Release/*.nupkg 1> /dev/null 2>&1; then + dotnet nuget push ./bin/Release/*.nupkg \ + -s https://api.nuget.org/v3/index.json \ + -k ${{ secrets.UPLOAD_NUGET_API_KEY }} + else + echo "No .nupkg files found for publishing." + fi From 9d6d10f14df20ca60ada54b31badf60ba50d916a Mon Sep 17 00:00:00 2001 From: avgalex <35622249+avgalex@users.noreply.github.com> Date: Tue, 26 Nov 2024 02:28:38 +0300 Subject: [PATCH 04/16] Update github_build_and_publish.yml --- .github/workflows/github_build_and_publish.yml | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/.github/workflows/github_build_and_publish.yml b/.github/workflows/github_build_and_publish.yml index 7695781..64efc6d 100644 --- a/.github/workflows/github_build_and_publish.yml +++ b/.github/workflows/github_build_and_publish.yml @@ -30,16 +30,6 @@ jobs: UPLOAD_NUGET_API_KEY: ${{ secrets.UPLOAD_NUGET_API_KEY }} run: | chmod a+x ./build.sh - ./build.sh --target=Travis --verbosity=normal --ForceUploadPackages=false + ./build.sh --target=Travis --verbosity=normal --ForceUploadPackages=true - # Шаг 4: Публикация пакета на NuGet - - name: Publish to NuGet - if: success() # Публиковать только при успешной сборке - run: | - if ls ./bin/Release/*.nupkg 1> /dev/null 2>&1; then - dotnet nuget push ./bin/Release/*.nupkg \ - -s https://api.nuget.org/v3/index.json \ - -k ${{ secrets.UPLOAD_NUGET_API_KEY }} - else - echo "No .nupkg files found for publishing." - fi + From adc51eb78a615275f0c978e8a402ff36f01d3830 Mon Sep 17 00:00:00 2001 From: Tom Longhurst <30480171+thomhurst@users.noreply.github.com> Date: Sun, 6 Oct 2024 10:32:07 +0100 Subject: [PATCH 05/16] Ensure we do not throw when some types can't be loaded --- ...ReflectionDependencyInjectionExtensions.cs | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/MicroElements.Swashbuckle.FluentValidation/AspNetCore/ReflectionDependencyInjectionExtensions.cs b/src/MicroElements.Swashbuckle.FluentValidation/AspNetCore/ReflectionDependencyInjectionExtensions.cs index 74ae599..39b9c48 100644 --- a/src/MicroElements.Swashbuckle.FluentValidation/AspNetCore/ReflectionDependencyInjectionExtensions.cs +++ b/src/MicroElements.Swashbuckle.FluentValidation/AspNetCore/ReflectionDependencyInjectionExtensions.cs @@ -2,6 +2,7 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. using System; +using System.Collections.Generic; using System.Linq; using System.Reflection; using System.Text.Json; @@ -17,16 +18,31 @@ internal static class ReflectionDependencyInjectionExtensions { private static Type? GetByFullName(string typeName) { - Type type = AppDomain + Type? type = AppDomain .CurrentDomain .GetAssemblies() .Where(assembly => assembly.FullName.Contains("Microsoft")) - .SelectMany(assembly => assembly.GetTypes()) + .SelectMany(GetLoadableTypes) .FirstOrDefault(type => type.FullName == typeName); return type; } + /// + /// Gets loadable Types from an Assembly, not throwing when some Types can't be loaded. + /// + private static IEnumerable GetLoadableTypes(Assembly assembly) + { + try + { + return assembly.GetTypes(); + } + catch (ReflectionTypeLoadException e) + { + return e.Types.Where(t => t != null); + } + } + /// /// Calls through reflection: services.Configure<JsonOptions>(options => configureJson(options));. /// Can be used from netstandard. From 19cd23c90d5b5788c1c7dd5ccff51cc847386776 Mon Sep 17 00:00:00 2001 From: kkytaiev Date: Thu, 27 Feb 2025 14:14:07 +0200 Subject: [PATCH 06/16] Fix duplicate regular expression patterns in a generated schema Add unit test --- .../FluentValidation/RuleHistoryCache.cs | 76 ++++++++++++++++++- .../RuleHistoryCacheTest.cs | 45 +++++++++++ 2 files changed, 120 insertions(+), 1 deletion(-) create mode 100644 test/MicroElements.Swashbuckle.FluentValidation.Tests/RuleHistoryCacheTest.cs diff --git a/src/MicroElements.OpenApi.FluentValidation/FluentValidation/RuleHistoryCache.cs b/src/MicroElements.OpenApi.FluentValidation/FluentValidation/RuleHistoryCache.cs index 3644cc5..4567321 100644 --- a/src/MicroElements.OpenApi.FluentValidation/FluentValidation/RuleHistoryCache.cs +++ b/src/MicroElements.OpenApi.FluentValidation/FluentValidation/RuleHistoryCache.cs @@ -1,6 +1,7 @@ // Copyright (c) MicroElements. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. +using System; using System.Collections.Generic; using System.Linq; using System.Runtime.CompilerServices; @@ -16,7 +17,30 @@ internal record RuleCacheItem( string SchemaTypeName, string SchemaPropertyName, IPropertyValidator PropertyValidator, - string RuleName); + string RuleName) + { + public virtual bool Equals(RuleCacheItem? other) + { + return !(other is null) && + SchemaTypeName == other.SchemaTypeName && + SchemaPropertyName == other.SchemaPropertyName && + PropertyValidatorComparer.Instance.Equals(PropertyValidator, other.PropertyValidator) + && RuleName == other.RuleName; + } + + public override int GetHashCode() + { + unchecked + { + PropertyValidator.Equals(PropertyValidator); + var hashCode = SchemaTypeName.GetHashCode(); + hashCode = (hashCode * 397) ^ SchemaPropertyName.GetHashCode(); + hashCode = (hashCode * 397) ^ PropertyValidator.Name.GetHashCode(); + hashCode = (hashCode * 397) ^ RuleName.GetHashCode(); + return hashCode; + } + } + } internal static void AddRuleHistoryItem(this object schema, RuleCacheItem historyItem) { @@ -29,5 +53,55 @@ internal static bool ContainsRuleHistoryItem(this object schema, RuleCacheItem h List historyItems = SchemaRuleHistory.GetOrCreateValue(schema); return historyItems.FirstOrDefault(item => Equals(item, historyItem)) != null; } + + internal class PropertyValidatorComparer : IEqualityComparer + { + public static readonly PropertyValidatorComparer Instance = new PropertyValidatorComparer(); + + /// + public bool Equals(IPropertyValidator? x, IPropertyValidator? y) + { + if (ReferenceEquals(x, y)) + return true; + + if (x == null || y == null) + return false; + + if (x.GetType() != y.GetType()) + return false; + + // stateless validators + if (x is INotNullValidator || x is INotEmptyValidator || x is IEmailValidator) + return true; + + if (x is IRegularExpressionValidator expressionValidator1 && + y is IRegularExpressionValidator expressionValidator2) + return Equals(expressionValidator1.Expression, expressionValidator2.Expression); + + if (x is ILengthValidator lengthValidator1 && + y is ILengthValidator lengthValidator2) + return lengthValidator1.Min == lengthValidator2.Min && lengthValidator1.Max == lengthValidator2.Max; + + if (x is IComparisonValidator comparisonValidator1 && + y is IComparisonValidator comparisonValidator2) + { + return comparisonValidator1.Comparison == comparisonValidator2.Comparison && + Equals(comparisonValidator1.MemberToCompare, comparisonValidator2.MemberToCompare) && + Equals(comparisonValidator1.ValueToCompare, comparisonValidator2.ValueToCompare); + } + + if (x is IBetweenValidator betweenValidator1 && + y is IBetweenValidator betweenValidator2) + return Equals(betweenValidator1.From, betweenValidator2.From) && Equals(betweenValidator1.To, betweenValidator2.To); + + return false; + } + + /// + public int GetHashCode(IPropertyValidator? obj) + { + return obj?.GetHashCode() ?? 0; + } + } } } \ No newline at end of file diff --git a/test/MicroElements.Swashbuckle.FluentValidation.Tests/RuleHistoryCacheTest.cs b/test/MicroElements.Swashbuckle.FluentValidation.Tests/RuleHistoryCacheTest.cs new file mode 100644 index 0000000..f0c2519 --- /dev/null +++ b/test/MicroElements.Swashbuckle.FluentValidation.Tests/RuleHistoryCacheTest.cs @@ -0,0 +1,45 @@ +using FluentValidation; +using FluentValidation.Validators; +using MicroElements.OpenApi.FluentValidation; +using System.Linq; +using Xunit; + +namespace MicroElements.Swashbuckle.FluentValidation.Tests +{ + public class RuleHistoryCacheTest + { + public class Sample + { + public string? Name { get; set;} + } + + public class SampleValidator : AbstractValidator + { + public SampleValidator() + { + RuleFor(p => p.Name) + .Matches("^[a-zA-Z0-9 ]+$"); + } + } + + [Fact] + // Issue 143 https://github.com/micro-elements/MicroElements.Swashbuckle.FluentValidation/issues/143 + public void DuplicateCachItem() + { + var key = new object(); + var cacheItem1 = CreateCacheItem(); + var cacheItem2 = CreateCacheItem(); + + key.AddRuleHistoryItem(cacheItem1); + + Assert.True(key.ContainsRuleHistoryItem(cacheItem2)); + } + + private RuleHistoryCache.RuleCacheItem CreateCacheItem() + { + var sampleValidator = new SampleValidator(); + var propertyValidator = sampleValidator.CreateDescriptor().GetRulesForMember("Name").First().Components.First().Validator; + return new RuleHistoryCache.RuleCacheItem("MySchema", "MyProperty", propertyValidator, "Pattern"); + } + } +} From d9315971550e8decf59157364718194353f45b06 Mon Sep 17 00:00:00 2001 From: kkytaiev Date: Thu, 27 Feb 2025 15:07:44 +0200 Subject: [PATCH 07/16] Add looking for properties through AllOf, AnyOf, OneOf Add unit test --- .../Swashbuckle/FluentValidationRules.cs | 60 +++++++++++++------ .../SchemaGenerationTests.cs | 51 ++++++++++++++++ .../UnitTestBase.cs | 2 +- 3 files changed, 95 insertions(+), 18 deletions(-) diff --git a/src/MicroElements.Swashbuckle.FluentValidation/Swashbuckle/FluentValidationRules.cs b/src/MicroElements.Swashbuckle.FluentValidation/Swashbuckle/FluentValidationRules.cs index 078a294..1b586b4 100644 --- a/src/MicroElements.Swashbuckle.FluentValidation/Swashbuckle/FluentValidationRules.cs +++ b/src/MicroElements.Swashbuckle.FluentValidation/Swashbuckle/FluentValidationRules.cs @@ -80,26 +80,32 @@ public void Apply(OpenApiSchema? schema, SchemaFilterContext context) if (validators == null) return; + var allSchemas = new List(); + ProcessAllSchemas(schema, allSchemas); + foreach (var validator in validators) { - var validatorContext = new ValidatorContext(typeContext, validator); - var schemaContext = new SchemaGenerationContext( - schemaRepository: context.SchemaRepository, - schemaGenerator: context.SchemaGenerator, - schemaType: context.Type, - schema: schema, - rules: _rules, - schemaGenerationOptions: _schemaGenerationOptions); - - ApplyRulesToSchema(schemaContext, validator); - - try - { - AddRulesFromIncludedValidators(schemaContext, validatorContext); - } - catch (Exception e) + foreach (var oneOfSchemas in allSchemas) { - _logger.LogWarning(0, e, "Applying IncludeRules for type '{ModelType}' failed", context.Type); + var validatorContext = new ValidatorContext(typeContext, validator); + var schemaContext = new SchemaGenerationContext( + schemaRepository: context.SchemaRepository, + schemaGenerator: context.SchemaGenerator, + schemaType: context.Type, + schema: oneOfSchemas, + rules: _rules, + schemaGenerationOptions: _schemaGenerationOptions); + + ApplyRulesToSchema(schemaContext, validator); + + try + { + AddRulesFromIncludedValidators(schemaContext, validatorContext); + } + catch (Exception e) + { + _logger.LogWarning(0, e, "Applying IncludeRules for type '{ModelType}' failed", context.Type); + } } } } @@ -121,5 +127,25 @@ private void AddRulesFromIncludedValidators(SchemaGenerationContext schemaGenera logger: _logger, schemaGenerationContext: schemaGenerationContext); } + + private void ProcessAllSchemas(OpenApiSchema schema, List schemas) + { + schemas.Add(schema); + + var collectionsOfSchemas = new IList[] { schema.AllOf, schema.OneOf, schema.AnyOf }; + + foreach (var collectionOfSchemas in collectionsOfSchemas) + { + foreach (var embededSchema in collectionOfSchemas) + { + if (!embededSchema.Properties.Any()) + { + continue; + } + + schemas.Add(embededSchema); + } + } + } } } \ No newline at end of file diff --git a/test/MicroElements.Swashbuckle.FluentValidation.Tests/SchemaGenerationTests.cs b/test/MicroElements.Swashbuckle.FluentValidation.Tests/SchemaGenerationTests.cs index 6e639e9..4bebc3d 100644 --- a/test/MicroElements.Swashbuckle.FluentValidation.Tests/SchemaGenerationTests.cs +++ b/test/MicroElements.Swashbuckle.FluentValidation.Tests/SchemaGenerationTests.cs @@ -1,5 +1,6 @@ using System.Collections; using System.Collections.Generic; +using System.Linq; using System.Text.Json.Serialization; using FluentAssertions; using FluentValidation; @@ -431,6 +432,56 @@ public void ILengthValidator_ProperlyAppliesMinMax_ToArrays(int min, int max) else schema.Properties[nameof(MinMaxLength.Qualities)].MaxItems.Should().BeNull(); } + + [Fact] + // See the issue https://github.com/micro-elements/MicroElements.Swashbuckle.FluentValidation/issues/156 + public void DerivedSample_ShouldHave_ValidationRulesApplied() + { + var schemaRepository = new SchemaRepository(); + var schemaGenerator = SchemaGenerator(options => + { + options.UseAllOfForInheritance = true; + ConfigureGenerator(options, [new DervidedSampleValidator()]); + }); + + schemaGenerator.GenerateSchema(typeof(BaseSample), schemaRepository); + var referenceSchema = schemaGenerator.GenerateSchema(typeof(DerivedSample), schemaRepository); + var schema = schemaRepository.Schemas[referenceSchema.Reference.Id]; + + // Should be empty after the change made because of the issue https://github.com/domaindrivendev/Swashbuckle.AspNetCore/issues/3021 + schema.Properties.Should().BeEmpty(); + schema.AllOf.Should().HaveCount(2); + + var derivedSampleSchema = schema.AllOf.FirstOrDefault(s => s.Type == "object"); + + Assert.NotNull(derivedSampleSchema); + + derivedSampleSchema.Properties.Should().HaveCount(1); + var propertySchema = derivedSampleSchema.Properties.First().Value; + propertySchema.MaxLength.Should().Be(255); + propertySchema.MinLength.Should().Be(1); + + derivedSampleSchema.Required.Should().HaveCount(1); + derivedSampleSchema.Required.First().Should().Be("Name"); + } + } + + public class BaseSample + { + public int Id { get; set; } + } + + public class DerivedSample : BaseSample + { + public string? Name { get; set; } + } + + public class DervidedSampleValidator : AbstractValidator + { + public DervidedSampleValidator() + { + RuleFor(p => p.Name).NotEmpty().MaximumLength(255); + } } public static class ValidatorExtensions diff --git a/test/MicroElements.Swashbuckle.FluentValidation.Tests/UnitTestBase.cs b/test/MicroElements.Swashbuckle.FluentValidation.Tests/UnitTestBase.cs index 7d8d031..b90f597 100644 --- a/test/MicroElements.Swashbuckle.FluentValidation.Tests/UnitTestBase.cs +++ b/test/MicroElements.Swashbuckle.FluentValidation.Tests/UnitTestBase.cs @@ -57,7 +57,7 @@ public SchemaGenerator SchemaGenerator( return new SchemaGenerator(generatorOptions, new JsonSerializerDataContractResolver(serializerOptions)); } - private void ConfigureGenerator(SchemaGeneratorOptions swaggerOptions, IValidator[] validators) + protected void ConfigureGenerator(SchemaGeneratorOptions swaggerOptions, IValidator[] validators) { SchemaGenerationOptions generationOptions = new SchemaGenerationOptions { From 643b28b27b7c6a8a5deba68d19be1f630dc9b28a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roberto=20Fern=C3=A1ndez=20Salinas?= Date: Thu, 12 Jun 2025 15:50:05 +0200 Subject: [PATCH 08/16] Migrate project to .NET 8 and 9 with dynamic versions and multi-targeting netstandard2.0, net8.0, and net9.0 --- samples/MinimalApi/MinimalApi.csproj | 28 ++++++------ .../SampleNSwagWebApi.csproj | 33 +++++++------- samples/SampleNSwagWebApi/Startup.cs | 6 +-- samples/SampleWebApi/Controllers/Issue100.cs | 2 +- samples/SampleWebApi/SampleWebApi.csproj | 14 +++--- samples/SampleWebApi/Startup.cs | 4 +- ...icroElements.NSwag.FluentValidation.csproj | 39 ++++++++--------- .../NSwagRuleContext.cs | 2 +- .../NSwagSchemaProcessorContext.cs | 3 +- ...roElements.OpenApi.FluentValidation.csproj | 43 ++++++++++--------- ...hbuckle.FluentValidation.AspNetCore.csproj | 19 ++++---- ...ements.Swashbuckle.FluentValidation.csproj | 10 ++--- ....Swashbuckle.FluentValidation.Tests.csproj | 15 ++++--- .../Samples/Customer.cs | 10 +++++ .../Samples/CustomerAddressValidator.cs | 25 +++++++++++ .../Samples/CustomerValidator.cs | 34 +++++++++++++++ .../Samples/Sample.cs | 25 +++++++++++ .../Samples/SampleValidator.cs | 29 +++++++++++++ .../SchemaGenerationTests.cs | 12 +++--- .../SwaggerTestHost.cs | 8 +++- 20 files changed, 244 insertions(+), 117 deletions(-) create mode 100644 test/MicroElements.Swashbuckle.FluentValidation.Tests/Samples/Customer.cs create mode 100644 test/MicroElements.Swashbuckle.FluentValidation.Tests/Samples/CustomerAddressValidator.cs create mode 100644 test/MicroElements.Swashbuckle.FluentValidation.Tests/Samples/CustomerValidator.cs create mode 100644 test/MicroElements.Swashbuckle.FluentValidation.Tests/Samples/Sample.cs create mode 100644 test/MicroElements.Swashbuckle.FluentValidation.Tests/Samples/SampleValidator.cs diff --git a/samples/MinimalApi/MinimalApi.csproj b/samples/MinimalApi/MinimalApi.csproj index fa11ff0..e8fba71 100644 --- a/samples/MinimalApi/MinimalApi.csproj +++ b/samples/MinimalApi/MinimalApi.csproj @@ -1,16 +1,20 @@ - + - - net9.0 - enable - enable - + + net9.0 + enable + latest + enable + - - - - - - + + + + + + + + + diff --git a/samples/SampleNSwagWebApi/SampleNSwagWebApi.csproj b/samples/SampleNSwagWebApi/SampleNSwagWebApi.csproj index e9eca62..b827cce 100644 --- a/samples/SampleNSwagWebApi/SampleNSwagWebApi.csproj +++ b/samples/SampleNSwagWebApi/SampleNSwagWebApi.csproj @@ -1,23 +1,20 @@ - + - - net9.0 - enable - 9 - + + net9.0 + enable + latest + - - - - - - - + + + + + + - - - - - + + + \ No newline at end of file diff --git a/samples/SampleNSwagWebApi/Startup.cs b/samples/SampleNSwagWebApi/Startup.cs index 4f71e2f..029b6b8 100644 --- a/samples/SampleNSwagWebApi/Startup.cs +++ b/samples/SampleNSwagWebApi/Startup.cs @@ -28,11 +28,11 @@ public void ConfigureServices(IServiceCollection services) var fluentValidationSchemaProcessor = serviceProvider.CreateScope().ServiceProvider.GetService(); // Add the fluent validations schema processor - settings.SchemaProcessors.Add(fluentValidationSchemaProcessor); + settings.SchemaSettings.SchemaProcessors.Add(fluentValidationSchemaProcessor); }); // Register FV validators - services.AddValidatorsFromAssemblyContaining(lifetime: ServiceLifetime.Scoped); + services.AddValidatorsFromAssemblyContaining(); // Adds FV rules to NSwag services.AddFluentValidationRulesToSwagger(); @@ -49,7 +49,7 @@ public void Configure(IApplicationBuilder app) }); app.UseOpenApi(); // serve OpenAPI/Swagger documents - app.UseSwaggerUi3(); // serve Swagger UI + app.UseSwaggerUi(); // serve Swagger UI } } } diff --git a/samples/SampleWebApi/Controllers/Issue100.cs b/samples/SampleWebApi/Controllers/Issue100.cs index b6dd6a0..92a0cb2 100644 --- a/samples/SampleWebApi/Controllers/Issue100.cs +++ b/samples/SampleWebApi/Controllers/Issue100.cs @@ -68,7 +68,7 @@ public Person100Validator() [SwaggerDiscriminator("discriminator")] [SwaggerSubType(typeof(Person100A), DiscriminatorValue = Person100A.DiscriminatorValue)] [SwaggerSubType(typeof(Person100B), DiscriminatorValue = Person100B.DiscriminatorValue)] - [JsonConverter(typeof(JsonInheritanceConverter), "discriminator")] + [JsonConverter(typeof(JsonInheritanceConverter), "discriminator")] [JsonInheritance(Person100A.DiscriminatorValue, typeof(Person100A))] [JsonInheritance(Person100B.DiscriminatorValue, typeof(Person100B))] public abstract class BasePerson100 diff --git a/samples/SampleWebApi/SampleWebApi.csproj b/samples/SampleWebApi/SampleWebApi.csproj index 5660591..4958832 100644 --- a/samples/SampleWebApi/SampleWebApi.csproj +++ b/samples/SampleWebApi/SampleWebApi.csproj @@ -7,15 +7,13 @@ - + - - - - - - - + + + + + diff --git a/samples/SampleWebApi/Startup.cs b/samples/SampleWebApi/Startup.cs index c8532bb..7d90dec 100644 --- a/samples/SampleWebApi/Startup.cs +++ b/samples/SampleWebApi/Startup.cs @@ -38,7 +38,7 @@ public void ConfigureServices(IServiceCollection services) services.AddHttpContextAccessor(); // Register FV validators - services.AddValidatorsFromAssemblyContaining(lifetime: ServiceLifetime.Scoped); + services.AddValidatorsFromAssemblyContaining(); // Add FV to Asp.net services.AddFluentValidationAutoValidation(); @@ -53,7 +53,7 @@ public void ConfigureServices(IServiceCollection services) // Add swagger services.AddSwaggerGen(c => { - c.SwaggerDoc("v1", new OpenApiInfo(){ Title = "My API", Version = "v1" }); + c.SwaggerDoc("v1", new OpenApiInfo() { Title = "My API", Version = "v1" }); c.EnableAnnotations(enableAnnotationsForInheritance: true, enableAnnotationsForPolymorphism: true); }); diff --git a/src/MicroElements.NSwag.FluentValidation/MicroElements.NSwag.FluentValidation.csproj b/src/MicroElements.NSwag.FluentValidation/MicroElements.NSwag.FluentValidation.csproj index a43100e..0714ff6 100644 --- a/src/MicroElements.NSwag.FluentValidation/MicroElements.NSwag.FluentValidation.csproj +++ b/src/MicroElements.NSwag.FluentValidation/MicroElements.NSwag.FluentValidation.csproj @@ -1,24 +1,23 @@ - - - - netstandard2.0 - enable - latest - true - false - Adds FluentValidation rules to swagger schema. - Swagger NSwag OpenApi FluentValidation - - - + - - - - + + netstandard2.0;net8.0;net9.0 + enable + latest + true + false + Adds FluentValidation rules to swagger schema. + Swagger NSwag OpenApi FluentValidation + - - - + + + + + + + + + \ No newline at end of file diff --git a/src/MicroElements.NSwag.FluentValidation/NSwagRuleContext.cs b/src/MicroElements.NSwag.FluentValidation/NSwagRuleContext.cs index 5635f25..9e0084e 100644 --- a/src/MicroElements.NSwag.FluentValidation/NSwagRuleContext.cs +++ b/src/MicroElements.NSwag.FluentValidation/NSwagRuleContext.cs @@ -27,7 +27,7 @@ public SchemaProcessorContext Property get { return new SchemaProcessorContext( - Schema.Type, + Schema.ContextualType, Schema.Schema.Properties[PropertyKey], Schema.Resolver, Schema.Generator, diff --git a/src/MicroElements.NSwag.FluentValidation/NSwagSchemaProcessorContext.cs b/src/MicroElements.NSwag.FluentValidation/NSwagSchemaProcessorContext.cs index 49c1c9f..a995b7e 100644 --- a/src/MicroElements.NSwag.FluentValidation/NSwagSchemaProcessorContext.cs +++ b/src/MicroElements.NSwag.FluentValidation/NSwagSchemaProcessorContext.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using FluentValidation.Validators; using MicroElements.OpenApi.FluentValidation; +using Namotion.Reflection; using NJsonSchema.Generation; namespace MicroElements.NSwag.FluentValidation @@ -77,7 +78,7 @@ public SchemaProcessorContext GetSchemaForType(Type type) { var schemaForType = _processorContext.Resolver.GetSchema(type, isIntegerEnumeration: false); return new SchemaProcessorContext( - type, + type.ToContextualType(), schemaForType, _processorContext.Resolver, _processorContext.Generator, diff --git a/src/MicroElements.OpenApi.FluentValidation/MicroElements.OpenApi.FluentValidation.csproj b/src/MicroElements.OpenApi.FluentValidation/MicroElements.OpenApi.FluentValidation.csproj index 15a40e4..ed2e2a7 100644 --- a/src/MicroElements.OpenApi.FluentValidation/MicroElements.OpenApi.FluentValidation.csproj +++ b/src/MicroElements.OpenApi.FluentValidation/MicroElements.OpenApi.FluentValidation.csproj @@ -1,22 +1,23 @@ - - - - netstandard2.0 - enable - latest - true - MicroElements.OpenApi - - - - - - - - - - - - - + + + + netstandard2.0;net8.0;net9.0 + enable + latest + true + MicroElements.OpenApi + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/MicroElements.Swashbuckle.FluentValidation.AspNetCore/MicroElements.Swashbuckle.FluentValidation.AspNetCore.csproj b/src/MicroElements.Swashbuckle.FluentValidation.AspNetCore/MicroElements.Swashbuckle.FluentValidation.AspNetCore.csproj index 1b86d3d..80bd0dd 100644 --- a/src/MicroElements.Swashbuckle.FluentValidation.AspNetCore/MicroElements.Swashbuckle.FluentValidation.AspNetCore.csproj +++ b/src/MicroElements.Swashbuckle.FluentValidation.AspNetCore/MicroElements.Swashbuckle.FluentValidation.AspNetCore.csproj @@ -1,13 +1,14 @@ - + - - net8.0;net9.0 - enable - enable - + + netstandard2.0;net8.0;net9.0 + enable + enable + latest + - - - + + + diff --git a/src/MicroElements.Swashbuckle.FluentValidation/MicroElements.Swashbuckle.FluentValidation.csproj b/src/MicroElements.Swashbuckle.FluentValidation/MicroElements.Swashbuckle.FluentValidation.csproj index 96f265b..6ea7d7f 100644 --- a/src/MicroElements.Swashbuckle.FluentValidation/MicroElements.Swashbuckle.FluentValidation.csproj +++ b/src/MicroElements.Swashbuckle.FluentValidation/MicroElements.Swashbuckle.FluentValidation.csproj @@ -1,7 +1,7 @@  - + - netstandard2.0 + netstandard2.0;net8.0;net9.0 enable latest true @@ -9,13 +9,11 @@ Swagger ISchemaFilter that uses FluentValidation validators instead System.ComponentModel based attributes. swagger swashbuckle FluentValidation aspnetcore - + - - - + diff --git a/test/MicroElements.Swashbuckle.FluentValidation.Tests/MicroElements.Swashbuckle.FluentValidation.Tests.csproj b/test/MicroElements.Swashbuckle.FluentValidation.Tests/MicroElements.Swashbuckle.FluentValidation.Tests.csproj index dca1dfa..7116aac 100644 --- a/test/MicroElements.Swashbuckle.FluentValidation.Tests/MicroElements.Swashbuckle.FluentValidation.Tests.csproj +++ b/test/MicroElements.Swashbuckle.FluentValidation.Tests/MicroElements.Swashbuckle.FluentValidation.Tests.csproj @@ -1,21 +1,22 @@  - net9.0 + net481;net8.0;net9.0 enable + latest false - - - - - + + + + + + - diff --git a/test/MicroElements.Swashbuckle.FluentValidation.Tests/Samples/Customer.cs b/test/MicroElements.Swashbuckle.FluentValidation.Tests/Samples/Customer.cs new file mode 100644 index 0000000..701cb47 --- /dev/null +++ b/test/MicroElements.Swashbuckle.FluentValidation.Tests/Samples/Customer.cs @@ -0,0 +1,10 @@ +namespace MicroElements.Swashbuckle.FluentValidation.Tests.Samples; + +public class Customer +{ + public int Id { get; set; } + public string Surname { get; set; } + public string Forename { get; set; } + public decimal Discount { get; set; } + public string Address { get; set; } +} \ No newline at end of file diff --git a/test/MicroElements.Swashbuckle.FluentValidation.Tests/Samples/CustomerAddressValidator.cs b/test/MicroElements.Swashbuckle.FluentValidation.Tests/Samples/CustomerAddressValidator.cs new file mode 100644 index 0000000..ae78b76 --- /dev/null +++ b/test/MicroElements.Swashbuckle.FluentValidation.Tests/Samples/CustomerAddressValidator.cs @@ -0,0 +1,25 @@ +using FluentValidation; +using System.Threading.Tasks; + +namespace MicroElements.Swashbuckle.FluentValidation.Tests.Samples; + +internal class CustomerAddressValidator : AbstractValidator +{ + public CustomerAddressValidator() + { + UnlessAsync((customer, _) => Task.FromResult(customer.Surname == "Test"), () => + { + RuleFor(customer => customer.Discount) + .NotEmpty() + .WithMessage("This WILL NOT be in the OpenAPI spec."); + }); + + RuleFor(customer => customer.Discount) + .NotEmpty() + .Unless(customer => customer.Surname == "Test") + .WithMessage("This WILL NOT be in the OpenAPI spec."); + + RuleFor(customer => customer.Address) + .Length(20, 250); + } +} diff --git a/test/MicroElements.Swashbuckle.FluentValidation.Tests/Samples/CustomerValidator.cs b/test/MicroElements.Swashbuckle.FluentValidation.Tests/Samples/CustomerValidator.cs new file mode 100644 index 0000000..7e88957 --- /dev/null +++ b/test/MicroElements.Swashbuckle.FluentValidation.Tests/Samples/CustomerValidator.cs @@ -0,0 +1,34 @@ +using System.Threading.Tasks; +using FluentValidation; + +namespace MicroElements.Swashbuckle.FluentValidation.Tests.Samples; + +public class CustomerValidator : AbstractValidator +{ + public CustomerValidator() + { + When(customer => customer.Id == 1, () => + { + RuleFor(customer => customer.Discount) + .NotEmpty() + .WithMessage("This WILL NOT be in the OpenAPI spec."); + }); + + RuleFor(customer => customer.Discount) + .ExclusiveBetween(4, 5) + .WithMessage("This WILL be in the OpenAPI spec."); + RuleFor(customer => customer.Discount) + .NotEmpty() + .WhenAsync((customer, _) => Task.FromResult(customer.Id == 1)) + .WithMessage("This WILL NOT be in the OpenAPI spec."); + + RuleFor(customer => customer.Surname) + .NotEmpty(); + + RuleFor(customer => customer.Forename) + .NotEmpty() + .WithMessage("Please specify a first name"); + + Include(new CustomerAddressValidator()); + } +} \ No newline at end of file diff --git a/test/MicroElements.Swashbuckle.FluentValidation.Tests/Samples/Sample.cs b/test/MicroElements.Swashbuckle.FluentValidation.Tests/Samples/Sample.cs new file mode 100644 index 0000000..365064c --- /dev/null +++ b/test/MicroElements.Swashbuckle.FluentValidation.Tests/Samples/Sample.cs @@ -0,0 +1,25 @@ +namespace MicroElements.Swashbuckle.FluentValidation.Tests.Samples; + +public class Sample +{ + public string PropertyWithNoRules { get; set; } + + public string NotNull { get; set; } + public string NotEmpty { get; set; } + public string EmailAddressRegex { get; set; } + public string EmailAddress { get; set; } + public string RegexField { get; set; } + + public int ValueInRange { get; set; } + public int ValueInRangeExclusive { get; set; } + + public float ValueInRangeFloat { get; set; } + public double ValueInRangeDouble { get; set; } + public decimal DecimalValue { get; set; } + + public string NotEmptyWithMaxLength { get; set; } + + // ReSharper disable once InconsistentNaming + // https://github.com/micro-elements/MicroElements.Swashbuckle.FluentValidation/issues/10 + public string javaStyleProperty { get; set; } +} diff --git a/test/MicroElements.Swashbuckle.FluentValidation.Tests/Samples/SampleValidator.cs b/test/MicroElements.Swashbuckle.FluentValidation.Tests/Samples/SampleValidator.cs new file mode 100644 index 0000000..2b8d65e --- /dev/null +++ b/test/MicroElements.Swashbuckle.FluentValidation.Tests/Samples/SampleValidator.cs @@ -0,0 +1,29 @@ +using FluentValidation; +using FluentValidation.Validators; +using JetBrains.Annotations; + +namespace MicroElements.Swashbuckle.FluentValidation.Tests.Samples; + +[UsedImplicitly] +public class SampleValidator : AbstractValidator +{ + public SampleValidator() + { + RuleFor(sample => sample.NotNull).NotNull(); + RuleFor(sample => sample.NotEmpty).NotEmpty(); + RuleFor(sample => sample.EmailAddressRegex).EmailAddress(EmailValidationMode.Net4xRegex); + RuleFor(sample => sample.EmailAddress).EmailAddress(); + RuleFor(sample => sample.RegexField).Matches(@"(\d{4})-(\d{2})-(\d{2})"); + + RuleFor(sample => sample.ValueInRange).GreaterThanOrEqualTo(5).LessThanOrEqualTo(10); + RuleFor(sample => sample.ValueInRangeExclusive).GreaterThan(5).LessThan(10); + + RuleFor(sample => sample.ValueInRangeFloat).InclusiveBetween(5.1f, 10.2f); + RuleFor(sample => sample.ValueInRangeDouble).ExclusiveBetween(5.1, 10.2); + RuleFor(sample => sample.DecimalValue).InclusiveBetween(1.333m, 200.333m); + + RuleFor(sample => sample.javaStyleProperty).MaximumLength(6); + + RuleFor(sample => sample.NotEmptyWithMaxLength).NotEmpty().MaximumLength(50); + } +} diff --git a/test/MicroElements.Swashbuckle.FluentValidation.Tests/SchemaGenerationTests.cs b/test/MicroElements.Swashbuckle.FluentValidation.Tests/SchemaGenerationTests.cs index 4bebc3d..59c76cb 100644 --- a/test/MicroElements.Swashbuckle.FluentValidation.Tests/SchemaGenerationTests.cs +++ b/test/MicroElements.Swashbuckle.FluentValidation.Tests/SchemaGenerationTests.cs @@ -1,14 +1,14 @@ -using System.Collections; -using System.Collections.Generic; -using System.Linq; -using System.Text.Json.Serialization; using FluentAssertions; using FluentValidation; using FluentValidation.Validators; using MicroElements.OpenApi; +using MicroElements.Swashbuckle.FluentValidation.Tests.Samples; using Microsoft.OpenApi.Models; -using SampleWebApi.Controllers; using Swashbuckle.AspNetCore.SwaggerGen; +using System.Collections; +using System.Collections.Generic; +using System.Linq; +using System.Text.Json.Serialization; using Xunit; namespace MicroElements.Swashbuckle.FluentValidation.Tests @@ -97,7 +97,7 @@ public void MaximumLength_ShouldNot_Override_NotNull() public void SampleValidator_FromSampleApi_Test() { var schemaRepository = new SchemaRepository(); - var referenceSchema = SchemaGenerator(new SampleValidator()).GenerateSchema(typeof(Sample), schemaRepository); + var referenceSchema = SchemaGenerator(new RuleHistoryCacheTest.SampleValidator()).GenerateSchema(typeof(RuleHistoryCacheTest.Sample), schemaRepository); var schema = schemaRepository.Schemas[referenceSchema.Reference.Id]; schema.Type.Should().Be("object"); diff --git a/test/MicroElements.Swashbuckle.FluentValidation.Tests/SwaggerTestHost.cs b/test/MicroElements.Swashbuckle.FluentValidation.Tests/SwaggerTestHost.cs index eaf9027..9bf3354 100644 --- a/test/MicroElements.Swashbuckle.FluentValidation.Tests/SwaggerTestHost.cs +++ b/test/MicroElements.Swashbuckle.FluentValidation.Tests/SwaggerTestHost.cs @@ -1,9 +1,11 @@ using System; using FluentValidation; +#if NET8_0_OR_GREATER using FluentValidation.AspNetCore; +using Microsoft.AspNetCore.Mvc; +#endif using MicroElements.OpenApi.FluentValidation; using MicroElements.Swashbuckle.FluentValidation.AspNetCore; -using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.DependencyInjection; using Microsoft.OpenApi.Models; using Swashbuckle.AspNetCore.SwaggerGen; @@ -30,16 +32,18 @@ public SwaggerTestHost Configure( Action? configureSchemaGenerationOptions = null, Action? configureRegistration = null) { +#if NET8_0_OR_GREATER // Add FV Services.AddFluentValidation(); // Json options by default no name policy. Services.Configure(options => options.JsonSerializerOptions.PropertyNamingPolicy = null); +#endif // Add Swagger Services.AddSwaggerGen(c => { - c.SwaggerDoc("v1", new OpenApiInfo{ Title = "API", Version = "v1" }); + c.SwaggerDoc("v1", new OpenApiInfo { Title = "API", Version = "v1" }); c.EnableAnnotations(enableAnnotationsForInheritance: true, enableAnnotationsForPolymorphism: true); }); From 73bf3a6a46c69374fea6b0441d66aba34d562831 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roberto=20Fern=C3=A1ndez=20Salinas?= Date: Fri, 13 Jun 2025 13:05:32 +0200 Subject: [PATCH 09/16] Remove .NET Framework 4.8.1 tests --- .../workflows/github_build_and_publish.yml | 8 +++--- build.cake | 27 ++++++++++++++++--- build.sh | 2 +- ...icroElements.NSwag.FluentValidation.csproj | 1 + ...ements.Swashbuckle.FluentValidation.csproj | 1 + .../SchemaGenerationTests.cs | 2 +- 6 files changed, 32 insertions(+), 9 deletions(-) diff --git a/.github/workflows/github_build_and_publish.yml b/.github/workflows/github_build_and_publish.yml index 64efc6d..1b9a0e1 100644 --- a/.github/workflows/github_build_and_publish.yml +++ b/.github/workflows/github_build_and_publish.yml @@ -9,7 +9,11 @@ on: jobs: build: - runs-on: ubuntu-latest + runs-on: ${{ matrix.os }} + + strategy: + matrix: + os: [ubuntu-latest, windows-latest] steps: # Шаг 1: Клонируем репозиторий @@ -31,5 +35,3 @@ jobs: run: | chmod a+x ./build.sh ./build.sh --target=Travis --verbosity=normal --ForceUploadPackages=true - - diff --git a/build.cake b/build.cake index 6a6cf6b..9897993 100644 --- a/build.cake +++ b/build.cake @@ -21,9 +21,28 @@ ScriptArgs args = new ScriptArgs(Context) Task("Build") .Does(() => args.Build().BuildSamples()); -Task("Test") - .WithCriteria(()=>args.RunTests) - .Does(() => RunTests(args)); +var isWindows = Environment.Platform.Family == PlatformFamily.Windows; +Task("Tests") + .Does(() => + { + var solution = "MicroElements.Swashbuckle.FluentValidation.sln"; + + if (isWindows) + { + Information("Executing tests net481, net8.0, net9.0 on Windows"); + + DotNetTest(solution, new DotNetTestSettings { Framework = "net481" }); + DotNetTest(solution, new DotNetTestSettings { Framework = "net8.0" }); + DotNetTest(solution, new DotNetTestSettings { Framework = "net9.0" }); + } + else + { + Information("Executing tests net8.0 y net9.0 on Linux/macOS"); + + DotNetTest(solution, new DotNetTestSettings { Framework = "net8.0" }); + DotNetTest(solution, new DotNetTestSettings { Framework = "net9.0" }); + } + }); Task("UploadTestResultsToAppVeyor") .WithCriteria(()=>args.RunTests) @@ -68,4 +87,4 @@ Task("AppVeyor") .IsDependentOn("UploadTestResultsToAppVeyor") ; -RunTarget(args.Target); +RunTarget(args.Target); \ No newline at end of file diff --git a/build.sh b/build.sh index eb69310..0f91738 100644 --- a/build.sh +++ b/build.sh @@ -80,4 +80,4 @@ dotnet tool restore echo "Running build script..." CMD="dotnet cake $SCRIPT ${CAKE_ARGUMENTS[@]}" echo $CMD -exec $CMD +exec $CMD \ No newline at end of file diff --git a/src/MicroElements.NSwag.FluentValidation/MicroElements.NSwag.FluentValidation.csproj b/src/MicroElements.NSwag.FluentValidation/MicroElements.NSwag.FluentValidation.csproj index 0714ff6..cad1dba 100644 --- a/src/MicroElements.NSwag.FluentValidation/MicroElements.NSwag.FluentValidation.csproj +++ b/src/MicroElements.NSwag.FluentValidation/MicroElements.NSwag.FluentValidation.csproj @@ -13,6 +13,7 @@ + diff --git a/src/MicroElements.Swashbuckle.FluentValidation/MicroElements.Swashbuckle.FluentValidation.csproj b/src/MicroElements.Swashbuckle.FluentValidation/MicroElements.Swashbuckle.FluentValidation.csproj index 6ea7d7f..4696e1f 100644 --- a/src/MicroElements.Swashbuckle.FluentValidation/MicroElements.Swashbuckle.FluentValidation.csproj +++ b/src/MicroElements.Swashbuckle.FluentValidation/MicroElements.Swashbuckle.FluentValidation.csproj @@ -13,6 +13,7 @@ + diff --git a/test/MicroElements.Swashbuckle.FluentValidation.Tests/SchemaGenerationTests.cs b/test/MicroElements.Swashbuckle.FluentValidation.Tests/SchemaGenerationTests.cs index 59c76cb..b7d2a1b 100644 --- a/test/MicroElements.Swashbuckle.FluentValidation.Tests/SchemaGenerationTests.cs +++ b/test/MicroElements.Swashbuckle.FluentValidation.Tests/SchemaGenerationTests.cs @@ -97,7 +97,7 @@ public void MaximumLength_ShouldNot_Override_NotNull() public void SampleValidator_FromSampleApi_Test() { var schemaRepository = new SchemaRepository(); - var referenceSchema = SchemaGenerator(new RuleHistoryCacheTest.SampleValidator()).GenerateSchema(typeof(RuleHistoryCacheTest.Sample), schemaRepository); + var referenceSchema = SchemaGenerator(new SampleValidator()).GenerateSchema(typeof(Sample), schemaRepository); var schema = schemaRepository.Schemas[referenceSchema.Reference.Id]; schema.Type.Should().Be("object"); From d18d99e4007b2c729861b1b6ace09ddda2fe5e1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roberto=20Fern=C3=A1ndez=20Salinas?= Date: Fri, 13 Jun 2025 13:05:32 +0200 Subject: [PATCH 10/16] Remove .NET Framework 4.8.1 tests --- .../MicroElements.Swashbuckle.FluentValidation.Tests.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/MicroElements.Swashbuckle.FluentValidation.Tests/MicroElements.Swashbuckle.FluentValidation.Tests.csproj b/test/MicroElements.Swashbuckle.FluentValidation.Tests/MicroElements.Swashbuckle.FluentValidation.Tests.csproj index 7116aac..78e6d28 100644 --- a/test/MicroElements.Swashbuckle.FluentValidation.Tests/MicroElements.Swashbuckle.FluentValidation.Tests.csproj +++ b/test/MicroElements.Swashbuckle.FluentValidation.Tests/MicroElements.Swashbuckle.FluentValidation.Tests.csproj @@ -1,7 +1,7 @@  - net481;net8.0;net9.0 + net8.0;net9.0 enable latest false From b08d6c20303c104221b7bda53b1704c5acf292c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roberto=20Fern=C3=A1ndez=20Salinas?= Date: Fri, 13 Jun 2025 16:31:27 +0200 Subject: [PATCH 11/16] Fix --- .github/workflows/github_build_and_publish.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/workflows/github_build_and_publish.yml b/.github/workflows/github_build_and_publish.yml index 380bb11..e7d58c7 100644 --- a/.github/workflows/github_build_and_publish.yml +++ b/.github/workflows/github_build_and_publish.yml @@ -11,10 +11,6 @@ jobs: build: runs-on: ${{ matrix.os }} - strategy: - matrix: - os: [ubuntu-latest, windows-latest] - strategy: matrix: os: [ubuntu-latest, windows-latest] From ca481b073f8cfdb7b6bc96ccbb85b18d2289ac5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roberto=20Fern=C3=A1ndez=20Salinas?= Date: Fri, 13 Jun 2025 16:38:40 +0200 Subject: [PATCH 12/16] Change github action --- .github/workflows/github_build_and_publish.yml | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/.github/workflows/github_build_and_publish.yml b/.github/workflows/github_build_and_publish.yml index e7d58c7..fd3d19b 100644 --- a/.github/workflows/github_build_and_publish.yml +++ b/.github/workflows/github_build_and_publish.yml @@ -41,4 +41,18 @@ jobs: UPLOAD_NUGET_API_KEY: ${{ secrets.UPLOAD_NUGET_API_KEY }} run: | chmod a+x ./build.sh - ./build.sh --target=Travis --verbosity=normal --ForceUploadPackages=true + ./build.sh --target=Travis --verbosity=normal --ForceUploadPackages=false + + # Шаг 3: Сборка проекта + + # Шаг 4: Публикация пакета на NuGet + - name: Publish to NuGet + if: success() && runner.os == 'Windows' # Публиковать только при успешной сборке + run: | + if ls ./bin/Release/*.nupkg 1> /dev/null 2>&1; then + dotnet nuget push ./bin/Release/*.nupkg \ + -s https://api.nuget.org/v3/index.json \ + -k ${{ secrets.UPLOAD_NUGET_API_KEY }} + else + echo "No .nupkg files found for publishing." + fi From e458af476b5034baf0c8a20cc2359ec0d5428d40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roberto=20Fern=C3=A1ndez=20Salinas?= Date: Mon, 16 Jun 2025 09:47:43 +0200 Subject: [PATCH 13/16] Change github workflow. --- .github/workflows/github_build_and_publish.yml | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/.github/workflows/github_build_and_publish.yml b/.github/workflows/github_build_and_publish.yml index fd3d19b..e7d58c7 100644 --- a/.github/workflows/github_build_and_publish.yml +++ b/.github/workflows/github_build_and_publish.yml @@ -41,18 +41,4 @@ jobs: UPLOAD_NUGET_API_KEY: ${{ secrets.UPLOAD_NUGET_API_KEY }} run: | chmod a+x ./build.sh - ./build.sh --target=Travis --verbosity=normal --ForceUploadPackages=false - - # Шаг 3: Сборка проекта - - # Шаг 4: Публикация пакета на NuGet - - name: Publish to NuGet - if: success() && runner.os == 'Windows' # Публиковать только при успешной сборке - run: | - if ls ./bin/Release/*.nupkg 1> /dev/null 2>&1; then - dotnet nuget push ./bin/Release/*.nupkg \ - -s https://api.nuget.org/v3/index.json \ - -k ${{ secrets.UPLOAD_NUGET_API_KEY }} - else - echo "No .nupkg files found for publishing." - fi + ./build.sh --target=Travis --verbosity=normal --ForceUploadPackages=true From 388fca24f73e6dd2b4a153b9bf9a722e414e1ce6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roberto=20Fern=C3=A1ndez=20Salinas?= Date: Wed, 9 Jul 2025 10:59:49 +0200 Subject: [PATCH 14/16] update-packages --- build.cake | 2 +- build.ps1 | 3 ++- build.sh | 3 ++- samples/MinimalApi/MinimalApi.csproj | 4 ++-- samples/SampleNSwagWebApi/SampleNSwagWebApi.csproj | 2 +- samples/SampleWebApi/SampleWebApi.csproj | 4 ++-- src/Directory.Build.props | 2 +- .../MicroElements.OpenApi.FluentValidation.csproj | 4 ++-- .../MicroElements.Swashbuckle.FluentValidation.csproj | 3 ++- .../Swashbuckle/ScopedSwaggerMiddleware.cs | 4 ++-- .../MicroElements.Swashbuckle.FluentValidation.Tests.csproj | 4 ++-- 11 files changed, 19 insertions(+), 16 deletions(-) diff --git a/build.cake b/build.cake index 9897993..38eb29d 100644 --- a/build.cake +++ b/build.cake @@ -2,7 +2,7 @@ // IMPORTS /////////////////////////////////////////////////////////////////////////////// -#load tools/microelements.devops/1.9.1/scripts/imports.cake +#load tools/microelements.devops/1.11.0/scripts/imports.cake /////////////////////////////////////////////////////////////////////////////// // SCRIPT ARGS AND CONVENTIONS diff --git a/build.ps1 b/build.ps1 index edd41c5..47dca38 100644 --- a/build.ps1 +++ b/build.ps1 @@ -20,7 +20,7 @@ if(!$PSScriptRoot){ $PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent } -$CAKE_VERSION = "0.38.0" +$CAKE_VERSION = "1.3.0" $DEVOPS_VERSION = "1.11.0" $NUGET_URL = "https://api.nuget.org/v3/index.json" $NUGET_BETA_URL = "https://www.myget.org/F/micro-elements/api/v3/index.json" @@ -63,6 +63,7 @@ if ($Verbosity) { $cakeArguments += "-verbosity=$Verbosity" } $cakeArguments += ("--rootDir="+@("$PSScriptRoot")); $cakeArguments += ("--devOpsVersion=$DEVOPS_VERSION"); $cakeArguments += ("--devOpsRoot=""$TOOLS_DIR/microelements.devops/$DEVOPS_VERSION"""); +$cakeArguments += ("--ForceUploadPackages=false") $cakeArguments += $ScriptArgs # Start Cake diff --git a/build.sh b/build.sh index 0f91738..7b69b20 100644 --- a/build.sh +++ b/build.sh @@ -18,7 +18,7 @@ TOOLS_DIR=$SCRIPT_DIR/tools SCRIPT=$TOOLS_DIR/microelements.devops/$DEVOPS_VERSION/scripts/main.cake CAKE_PROPS_PATH=$TOOLS_DIR/cake.props -CAKE_VERSION="0.38.0" +CAKE_VERSION="1.3.0" CAKE_ARGUMENTS=() # Parse arguments. @@ -35,6 +35,7 @@ done CAKE_ARGUMENTS+=("--rootDir=$SCRIPT_DIR"); CAKE_ARGUMENTS+=("--devOpsVersion=$DEVOPS_VERSION"); CAKE_ARGUMENTS+=("--devOpsRoot=$TOOLS_DIR/microelements.devops/$DEVOPS_VERSION"); +CAKE_ARGUMENTS+=("--ForceUploadPackages=false") echo "===========VARIABLES============" echo "SCRIPT_DIR: $SCRIPT_DIR" diff --git a/samples/MinimalApi/MinimalApi.csproj b/samples/MinimalApi/MinimalApi.csproj index e8fba71..de332ee 100644 --- a/samples/MinimalApi/MinimalApi.csproj +++ b/samples/MinimalApi/MinimalApi.csproj @@ -9,8 +9,8 @@ - - + + diff --git a/samples/SampleNSwagWebApi/SampleNSwagWebApi.csproj b/samples/SampleNSwagWebApi/SampleNSwagWebApi.csproj index b827cce..ef6d5a8 100644 --- a/samples/SampleNSwagWebApi/SampleNSwagWebApi.csproj +++ b/samples/SampleNSwagWebApi/SampleNSwagWebApi.csproj @@ -9,7 +9,7 @@ - + diff --git a/samples/SampleWebApi/SampleWebApi.csproj b/samples/SampleWebApi/SampleWebApi.csproj index 4958832..f6b0688 100644 --- a/samples/SampleWebApi/SampleWebApi.csproj +++ b/samples/SampleWebApi/SampleWebApi.csproj @@ -12,8 +12,8 @@ - - + + diff --git a/src/Directory.Build.props b/src/Directory.Build.props index 9ea8743..312d3a8 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -1,7 +1,7 @@ - + diff --git a/src/MicroElements.OpenApi.FluentValidation/MicroElements.OpenApi.FluentValidation.csproj b/src/MicroElements.OpenApi.FluentValidation/MicroElements.OpenApi.FluentValidation.csproj index ed2e2a7..1acf69b 100644 --- a/src/MicroElements.OpenApi.FluentValidation/MicroElements.OpenApi.FluentValidation.csproj +++ b/src/MicroElements.OpenApi.FluentValidation/MicroElements.OpenApi.FluentValidation.csproj @@ -16,8 +16,8 @@ - - + + \ No newline at end of file diff --git a/src/MicroElements.Swashbuckle.FluentValidation/MicroElements.Swashbuckle.FluentValidation.csproj b/src/MicroElements.Swashbuckle.FluentValidation/MicroElements.Swashbuckle.FluentValidation.csproj index 4696e1f..08934ac 100644 --- a/src/MicroElements.Swashbuckle.FluentValidation/MicroElements.Swashbuckle.FluentValidation.csproj +++ b/src/MicroElements.Swashbuckle.FluentValidation/MicroElements.Swashbuckle.FluentValidation.csproj @@ -14,7 +14,8 @@ - + + diff --git a/src/MicroElements.Swashbuckle.FluentValidation/Swashbuckle/ScopedSwaggerMiddleware.cs b/src/MicroElements.Swashbuckle.FluentValidation/Swashbuckle/ScopedSwaggerMiddleware.cs index 13edcd9..635121d 100644 --- a/src/MicroElements.Swashbuckle.FluentValidation/Swashbuckle/ScopedSwaggerMiddleware.cs +++ b/src/MicroElements.Swashbuckle.FluentValidation/Swashbuckle/ScopedSwaggerMiddleware.cs @@ -1,11 +1,11 @@ // Copyright (c) MicroElements. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -using System; -using System.Threading.Tasks; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Http; using Swashbuckle.AspNetCore.Swagger; +using System; +using System.Threading.Tasks; namespace MicroElements.Swashbuckle.FluentValidation { diff --git a/test/MicroElements.Swashbuckle.FluentValidation.Tests/MicroElements.Swashbuckle.FluentValidation.Tests.csproj b/test/MicroElements.Swashbuckle.FluentValidation.Tests/MicroElements.Swashbuckle.FluentValidation.Tests.csproj index 78e6d28..41d41e1 100644 --- a/test/MicroElements.Swashbuckle.FluentValidation.Tests/MicroElements.Swashbuckle.FluentValidation.Tests.csproj +++ b/test/MicroElements.Swashbuckle.FluentValidation.Tests/MicroElements.Swashbuckle.FluentValidation.Tests.csproj @@ -8,10 +8,10 @@ - + - + From dc9ce984ac807da95e76e49ae4653d2b453cfc2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roberto=20Fern=C3=A1ndez=20Salinas?= Date: Wed, 9 Jul 2025 10:59:49 +0200 Subject: [PATCH 15/16] Fix Multiple arguments with the same name (ForceUploadPackages)update-packages --- build.cake | 2 +- build.ps1 | 3 ++- build.sh | 4 +++- samples/MinimalApi/MinimalApi.csproj | 4 ++-- samples/SampleNSwagWebApi/SampleNSwagWebApi.csproj | 2 +- samples/SampleWebApi/SampleWebApi.csproj | 4 ++-- src/Directory.Build.props | 2 +- .../MicroElements.OpenApi.FluentValidation.csproj | 4 ++-- .../MicroElements.Swashbuckle.FluentValidation.csproj | 3 ++- .../Swashbuckle/ScopedSwaggerMiddleware.cs | 4 ++-- .../MicroElements.Swashbuckle.FluentValidation.Tests.csproj | 4 ++-- 11 files changed, 20 insertions(+), 16 deletions(-) diff --git a/build.cake b/build.cake index 9897993..38eb29d 100644 --- a/build.cake +++ b/build.cake @@ -2,7 +2,7 @@ // IMPORTS /////////////////////////////////////////////////////////////////////////////// -#load tools/microelements.devops/1.9.1/scripts/imports.cake +#load tools/microelements.devops/1.11.0/scripts/imports.cake /////////////////////////////////////////////////////////////////////////////// // SCRIPT ARGS AND CONVENTIONS diff --git a/build.ps1 b/build.ps1 index edd41c5..47dca38 100644 --- a/build.ps1 +++ b/build.ps1 @@ -20,7 +20,7 @@ if(!$PSScriptRoot){ $PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent } -$CAKE_VERSION = "0.38.0" +$CAKE_VERSION = "1.3.0" $DEVOPS_VERSION = "1.11.0" $NUGET_URL = "https://api.nuget.org/v3/index.json" $NUGET_BETA_URL = "https://www.myget.org/F/micro-elements/api/v3/index.json" @@ -63,6 +63,7 @@ if ($Verbosity) { $cakeArguments += "-verbosity=$Verbosity" } $cakeArguments += ("--rootDir="+@("$PSScriptRoot")); $cakeArguments += ("--devOpsVersion=$DEVOPS_VERSION"); $cakeArguments += ("--devOpsRoot=""$TOOLS_DIR/microelements.devops/$DEVOPS_VERSION"""); +$cakeArguments += ("--ForceUploadPackages=false") $cakeArguments += $ScriptArgs # Start Cake diff --git a/build.sh b/build.sh index 0f91738..7282e69 100644 --- a/build.sh +++ b/build.sh @@ -18,7 +18,7 @@ TOOLS_DIR=$SCRIPT_DIR/tools SCRIPT=$TOOLS_DIR/microelements.devops/$DEVOPS_VERSION/scripts/main.cake CAKE_PROPS_PATH=$TOOLS_DIR/cake.props -CAKE_VERSION="0.38.0" +CAKE_VERSION="1.3.0" CAKE_ARGUMENTS=() # Parse arguments. @@ -26,6 +26,7 @@ for i in "$@"; do case $1 in -s|--script) SCRIPT="$2"; shift ;; --cake-version) CAKE_VERSION="--version=$2"; shift ;; + --ForceUploadPackages=*|--ForceUploadPackages) ;; --) shift; CAKE_ARGUMENTS+=("$@"); break ;; *) CAKE_ARGUMENTS+=("$1") ;; esac @@ -35,6 +36,7 @@ done CAKE_ARGUMENTS+=("--rootDir=$SCRIPT_DIR"); CAKE_ARGUMENTS+=("--devOpsVersion=$DEVOPS_VERSION"); CAKE_ARGUMENTS+=("--devOpsRoot=$TOOLS_DIR/microelements.devops/$DEVOPS_VERSION"); +CAKE_ARGUMENTS+=("--ForceUploadPackages=false") echo "===========VARIABLES============" echo "SCRIPT_DIR: $SCRIPT_DIR" diff --git a/samples/MinimalApi/MinimalApi.csproj b/samples/MinimalApi/MinimalApi.csproj index e8fba71..de332ee 100644 --- a/samples/MinimalApi/MinimalApi.csproj +++ b/samples/MinimalApi/MinimalApi.csproj @@ -9,8 +9,8 @@ - - + + diff --git a/samples/SampleNSwagWebApi/SampleNSwagWebApi.csproj b/samples/SampleNSwagWebApi/SampleNSwagWebApi.csproj index b827cce..ef6d5a8 100644 --- a/samples/SampleNSwagWebApi/SampleNSwagWebApi.csproj +++ b/samples/SampleNSwagWebApi/SampleNSwagWebApi.csproj @@ -9,7 +9,7 @@ - + diff --git a/samples/SampleWebApi/SampleWebApi.csproj b/samples/SampleWebApi/SampleWebApi.csproj index 4958832..f6b0688 100644 --- a/samples/SampleWebApi/SampleWebApi.csproj +++ b/samples/SampleWebApi/SampleWebApi.csproj @@ -12,8 +12,8 @@ - - + + diff --git a/src/Directory.Build.props b/src/Directory.Build.props index 9ea8743..312d3a8 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -1,7 +1,7 @@ - + diff --git a/src/MicroElements.OpenApi.FluentValidation/MicroElements.OpenApi.FluentValidation.csproj b/src/MicroElements.OpenApi.FluentValidation/MicroElements.OpenApi.FluentValidation.csproj index ed2e2a7..1acf69b 100644 --- a/src/MicroElements.OpenApi.FluentValidation/MicroElements.OpenApi.FluentValidation.csproj +++ b/src/MicroElements.OpenApi.FluentValidation/MicroElements.OpenApi.FluentValidation.csproj @@ -16,8 +16,8 @@ - - + + \ No newline at end of file diff --git a/src/MicroElements.Swashbuckle.FluentValidation/MicroElements.Swashbuckle.FluentValidation.csproj b/src/MicroElements.Swashbuckle.FluentValidation/MicroElements.Swashbuckle.FluentValidation.csproj index 4696e1f..08934ac 100644 --- a/src/MicroElements.Swashbuckle.FluentValidation/MicroElements.Swashbuckle.FluentValidation.csproj +++ b/src/MicroElements.Swashbuckle.FluentValidation/MicroElements.Swashbuckle.FluentValidation.csproj @@ -14,7 +14,8 @@ - + + diff --git a/src/MicroElements.Swashbuckle.FluentValidation/Swashbuckle/ScopedSwaggerMiddleware.cs b/src/MicroElements.Swashbuckle.FluentValidation/Swashbuckle/ScopedSwaggerMiddleware.cs index 13edcd9..635121d 100644 --- a/src/MicroElements.Swashbuckle.FluentValidation/Swashbuckle/ScopedSwaggerMiddleware.cs +++ b/src/MicroElements.Swashbuckle.FluentValidation/Swashbuckle/ScopedSwaggerMiddleware.cs @@ -1,11 +1,11 @@ // Copyright (c) MicroElements. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -using System; -using System.Threading.Tasks; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Http; using Swashbuckle.AspNetCore.Swagger; +using System; +using System.Threading.Tasks; namespace MicroElements.Swashbuckle.FluentValidation { diff --git a/test/MicroElements.Swashbuckle.FluentValidation.Tests/MicroElements.Swashbuckle.FluentValidation.Tests.csproj b/test/MicroElements.Swashbuckle.FluentValidation.Tests/MicroElements.Swashbuckle.FluentValidation.Tests.csproj index 78e6d28..41d41e1 100644 --- a/test/MicroElements.Swashbuckle.FluentValidation.Tests/MicroElements.Swashbuckle.FluentValidation.Tests.csproj +++ b/test/MicroElements.Swashbuckle.FluentValidation.Tests/MicroElements.Swashbuckle.FluentValidation.Tests.csproj @@ -8,10 +8,10 @@ - + - + From 0fd6675154daebaf79f893176039f7e611c7779a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roberto=20Fern=C3=A1ndez=20Salinas?= Date: Wed, 9 Jul 2025 11:03:09 +0200 Subject: [PATCH 16/16] Comment UseScopedSwagger --- .../Swashbuckle/ScopedSwaggerMiddleware.cs | 92 +++++++++---------- 1 file changed, 46 insertions(+), 46 deletions(-) diff --git a/src/MicroElements.Swashbuckle.FluentValidation/Swashbuckle/ScopedSwaggerMiddleware.cs b/src/MicroElements.Swashbuckle.FluentValidation/Swashbuckle/ScopedSwaggerMiddleware.cs index 635121d..86a9a8d 100644 --- a/src/MicroElements.Swashbuckle.FluentValidation/Swashbuckle/ScopedSwaggerMiddleware.cs +++ b/src/MicroElements.Swashbuckle.FluentValidation/Swashbuckle/ScopedSwaggerMiddleware.cs @@ -1,51 +1,51 @@ -// Copyright (c) MicroElements. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. +//// Copyright (c) MicroElements. All rights reserved. +//// Licensed under the MIT license. See LICENSE file in the project root for full license information. -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Http; -using Swashbuckle.AspNetCore.Swagger; -using System; -using System.Threading.Tasks; +//using Microsoft.AspNetCore.Builder; +//using Microsoft.AspNetCore.Http; +//using Swashbuckle.AspNetCore.Swagger; +//using System; +//using System.Threading.Tasks; -namespace MicroElements.Swashbuckle.FluentValidation -{ - /// - /// SwaggerMiddleware that resolves on scope. - /// Resolves problems with validators with dependency on scoped services. - /// - public class ScopedSwaggerMiddleware - { - private readonly RequestDelegate _next; - private readonly SwaggerOptions _options; +//namespace MicroElements.Swashbuckle.FluentValidation +//{ +// /// +// /// SwaggerMiddleware that resolves on scope. +// /// Resolves problems with validators with dependency on scoped services. +// /// +// public class ScopedSwaggerMiddleware +// { +// private readonly RequestDelegate _next; +// private readonly SwaggerOptions _options; - /// - /// ctor. - /// - /// - /// - public ScopedSwaggerMiddleware(RequestDelegate next, SwaggerOptions options) - { - _next = next; - _options = options; - } +// /// +// /// ctor. +// /// +// /// +// /// +// public ScopedSwaggerMiddleware(RequestDelegate next, SwaggerOptions options) +// { +// _next = next; +// _options = options; +// } - public async Task Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider) - { - await new SwaggerMiddleware(_next, _options).Invoke(httpContext, swaggerProvider); - } - } +// public async Task Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider) +// { +// await new SwaggerMiddleware(_next, _options).Invoke(httpContext, swaggerProvider); +// } +// } - public static class SwaggerBuilderExtensions - { - /// - /// Replaces standard with . - /// Use instead of if you have services with scoped services like DbContext. - /// - public static IApplicationBuilder UseScopedSwagger(this IApplicationBuilder app, Action setupAction = null) - { - SwaggerOptions swaggerOptions = new SwaggerOptions(); - setupAction?.Invoke(swaggerOptions); - return app.UseMiddleware(swaggerOptions); - } - } -} \ No newline at end of file +// public static class SwaggerBuilderExtensions +// { +// /// +// /// Replaces standard with . +// /// Use instead of if you have services with scoped services like DbContext. +// /// +// public static IApplicationBuilder UseScopedSwagger(this IApplicationBuilder app, Action setupAction = null) +// { +// SwaggerOptions swaggerOptions = new SwaggerOptions(); +// setupAction?.Invoke(swaggerOptions); +// return app.UseMiddleware(swaggerOptions); +// } +// } +//} \ No newline at end of file