From 5fa2cea60704c61c3519961b7c2b15db476cd29f Mon Sep 17 00:00:00 2001 From: avgalex <6c65787870@protonmail.ch> Date: Mon, 1 Sep 2025 10:11:58 +0300 Subject: [PATCH] Fix test project compilation errors - Remove orphaned #endif directive in SwaggerTestHost.cs - Add missing package references (FluentValidation.AspNetCore, Swashbuckle.AspNetCore.Annotations) - Add null check for ISchemaGenerator to prevent NullReferenceException --- .../MicroElements.Swashbuckle.FluentValidation.Tests.csproj | 2 ++ .../SwaggerTestHost.cs | 6 +++++- 2 files changed, 7 insertions(+), 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 4021561..2d1eec4 100644 --- a/test/MicroElements.Swashbuckle.FluentValidation.Tests/MicroElements.Swashbuckle.FluentValidation.Tests.csproj +++ b/test/MicroElements.Swashbuckle.FluentValidation.Tests/MicroElements.Swashbuckle.FluentValidation.Tests.csproj @@ -9,7 +9,9 @@ + + diff --git a/test/MicroElements.Swashbuckle.FluentValidation.Tests/SwaggerTestHost.cs b/test/MicroElements.Swashbuckle.FluentValidation.Tests/SwaggerTestHost.cs index 2c3c4fb..1e03d53 100644 --- a/test/MicroElements.Swashbuckle.FluentValidation.Tests/SwaggerTestHost.cs +++ b/test/MicroElements.Swashbuckle.FluentValidation.Tests/SwaggerTestHost.cs @@ -1,12 +1,13 @@ using System; using FluentValidation; + using Microsoft.AspNetCore.Mvc; -#endif using MicroElements.OpenApi.FluentValidation; using MicroElements.Swashbuckle.FluentValidation.AspNetCore; using Microsoft.Extensions.DependencyInjection; using Microsoft.OpenApi.Models; using Swashbuckle.AspNetCore.SwaggerGen; +using Swashbuckle.AspNetCore.Annotations; namespace MicroElements.Swashbuckle.FluentValidation.Tests; @@ -60,6 +61,9 @@ public SwaggerTestHost RegisterValidator() public SwaggerTestHost GenerateSchema(out OpenApiSchema schema) { var schemaGenerator = ServiceProvider.GetService(); + if (schemaGenerator == null) + throw new InvalidOperationException("ISchemaGenerator service not found. Make sure to call Configure() first."); + var openApiSchema = schemaGenerator.GenerateSchema(typeof(TModel), SchemaRepository); schema = SchemaRepository.Schemas[openApiSchema.Reference.Id]; return this;