diff --git a/src/Http/Wolverine.Http.Tests/using_form_parameters.cs b/src/Http/Wolverine.Http.Tests/using_form_parameters.cs index e9dddb437..c672d1b3d 100644 --- a/src/Http/Wolverine.Http.Tests/using_form_parameters.cs +++ b/src/Http/Wolverine.Http.Tests/using_form_parameters.cs @@ -6,6 +6,7 @@ using Wolverine.Runtime; using WolverineWebApi; using WolverineWebApi.Forms; +using MvcBindingSource = Microsoft.AspNetCore.Mvc.ModelBinding.BindingSource; namespace Wolverine.Http.Tests; @@ -537,6 +538,26 @@ public void trouble_shoot_form_matching() variable!.Creator.ShouldBeOfType(); } + [Fact] + public void form_parameter_descriptions_have_a_parameter_descriptor() + { + // Regression: ApiParameterDescription instances emitted for [FromForm] + // primitive parameters used to leave ParameterDescriptor null. ASP.NET + // Core's OpenApiDocumentService.GetFormRequestBody groups form + // parameters by ParameterDescriptor.Name and NREs when it is missing, + // taking down the entire /openapi/v1.json response for any endpoint + // that has at least one such parameter. + var chain = HttpChains.ChainFor("POST", "/form/explicit"); + var apiDescription = chain!.CreateApiDescription("POST"); + + var formParameter = apiDescription.ParameterDescriptions.Single(p => p.Name == "name"); + formParameter.Source.ShouldBe(MvcBindingSource.Form); + formParameter.Type.ShouldBe(typeof(string)); + formParameter.ParameterDescriptor.ShouldNotBeNull(); + formParameter.ParameterDescriptor.Name.ShouldBe("name"); + formParameter.ParameterDescriptor.ParameterType.ShouldBe(typeof(string)); + } + [Fact] public void form_endpoints_honor_consumes_metadata_for_supported_request_formats() { diff --git a/src/Http/Wolverine.Http/HttpChain.ApiDescription.cs b/src/Http/Wolverine.Http/HttpChain.ApiDescription.cs index 55f7d0b84..226a2d4a3 100644 --- a/src/Http/Wolverine.Http/HttpChain.ApiDescription.cs +++ b/src/Http/Wolverine.Http/HttpChain.ApiDescription.cs @@ -411,6 +411,11 @@ private void fillFormParameters(ApiDescription apiDescription) Name = formVariable.Name, ModelMetadata = new EndpointModelMetadata(formVariable.VariableType), Source = BindingSource.Form, + ParameterDescriptor = new ParameterDescriptor + { + Name = formVariable.Name, + ParameterType = formVariable.VariableType + }, Type = formVariable.VariableType, IsRequired = false };