diff --git a/src/Http/Wolverine.Http.FluentValidation/Internals/HttpChainFluentValidationPolicy.cs b/src/Http/Wolverine.Http.FluentValidation/Internals/HttpChainFluentValidationPolicy.cs index 4a73125ab..48b9bed30 100644 --- a/src/Http/Wolverine.Http.FluentValidation/Internals/HttpChainFluentValidationPolicy.cs +++ b/src/Http/Wolverine.Http.FluentValidation/Internals/HttpChainFluentValidationPolicy.cs @@ -25,7 +25,7 @@ public void Apply(HttpChain chain, IServiceContainer container) if (registered.Count() == 1) { - chain.Metadata.ProducesProblem(400); + chain.Metadata.ProducesValidationProblem(400); var method = typeof(FluentValidationHttpExecutor).GetMethod(nameof(FluentValidationHttpExecutor.ExecuteOne))! @@ -41,7 +41,7 @@ public void Apply(HttpChain chain, IServiceContainer container) } else if (registered.Count() > 1) { - chain.Metadata.ProducesProblem(400); + chain.Metadata.ProducesValidationProblem(400); var method = typeof(FluentValidationHttpExecutor).GetMethod(nameof(FluentValidationHttpExecutor.ExecuteMany))! diff --git a/src/Http/Wolverine.Http.Tests/fluent_validation_middleware.cs b/src/Http/Wolverine.Http.Tests/fluent_validation_middleware.cs index 74ac3816a..b16e5fd2e 100644 --- a/src/Http/Wolverine.Http.Tests/fluent_validation_middleware.cs +++ b/src/Http/Wolverine.Http.Tests/fluent_validation_middleware.cs @@ -1,5 +1,10 @@ using Alba; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Http.Metadata; using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Routing; +using Microsoft.Extensions.DependencyInjection; +using Shouldly; using Wolverine.Http.Tests.DifferentAssembly.Validation; using WolverineWebApi.Validation; @@ -11,6 +16,19 @@ public fluent_validation_middleware(AppFixture fixture) : base(fixture) { } + [Fact] + public void adds_problem_validation_to_open_api_metadata() + { + var endpoints = Host.Services.GetServices().SelectMany(x => x.Endpoints).OfType() + .ToList(); + + var endpoint = endpoints.Single(x => x.RoutePattern.RawText == "/validate/customer"); + + var produces = endpoint.Metadata.OfType().Single(x => x.Type == typeof(HttpValidationProblemDetails)); + produces.StatusCode.ShouldBe(400); + produces.ContentTypes.Single().ShouldBe("application/problem+json"); + } + [Fact] public async Task one_validator_happy_path() { @@ -36,9 +54,9 @@ public async Task one_validator_sad_path() x.StatusCodeShouldBe(400); }); - // Just proving that we have ProblemDetails content + // Just proving that we have HttpValidationProblemDetails content // in the request - var problems = results.ReadAsJson(); + var problems = results.ReadAsJson(); } [Fact] public async Task one_validator_sad_path_in_different_assembly() @@ -52,9 +70,9 @@ public async Task one_validator_sad_path_in_different_assembly() x.StatusCodeShouldBe(400); }); - // Just proving that we have ProblemDetails content + // Just proving that we have HttpValidationProblemDetails content // in the request - var problems = results.ReadAsJson(); + var problems = results.ReadAsJson(); } [Fact] @@ -82,7 +100,7 @@ public async Task two_validator_sad_path() x.StatusCodeShouldBe(400); }); - var problems = results.ReadAsJson(); + var problems = results.ReadAsJson(); } [Fact] @@ -97,6 +115,6 @@ public async Task when_using_compound_handler_validation_is_called_before_load() x.StatusCodeShouldBe(400); }); - var problems = results.ReadAsJson(); + var problems = results.ReadAsJson(); } } \ No newline at end of file