Skip to content

Fix missing ParameterDescriptor for form parameters in API descriptions#2587

Merged
jeremydmiller merged 2 commits intoJasperFx:mainfrom
rmasciarella:fix/form-parameters-missing-parameter-descriptor
Apr 26, 2026
Merged

Fix missing ParameterDescriptor for form parameters in API descriptions#2587
jeremydmiller merged 2 commits intoJasperFx:mainfrom
rmasciarella:fix/form-parameters-missing-parameter-descriptor

Conversation

@rmasciarella
Copy link
Copy Markdown
Contributor

Summary

HttpChain.fillFormParameters emits ApiParameterDescription instances without populating ParameterDescriptor. ASP.NET Core 10's OpenApiDocumentService.GetFormRequestBody groups form parameters by parameter.ParameterDescriptor.Name with no null guard, so any application that contains a Wolverine HTTP endpoint with a primitive [FromForm] parameter (e.g. [FromForm] string, [FromForm] int, [FromForm] DateTime) returns HTTP 500 from /openapi/v1.json. The 500 takes down the entire OpenAPI document, breaking generated-client tooling (Orval, NSwag, Kiota, etc).

The two sibling form-emit paths in the same file (the FileParameters loop and the IFromFormMetadata loop) already populate ParameterDescriptor with new ParameterDescriptor { Name, ParameterType }. This change extends fillFormParameters to do the same.

_formValueVariables is populated by TryFindOrCreateFormValue, called both directly from primitive [FromForm] parameters and indirectly from FormBindingFrame for the constructor parameters of complex [FromForm] POCOs, so the fix covers both shapes.

Why this scope

Narrow producer-side null-contract fix. ApiParameterDescription.ParameterDescriptor is declared non-nullable in Microsoft.AspNetCore.Mvc.Abstractions; producers should populate it. fillQuerystringParameters and fillKnownHeaderParameters also leave it null, but query/header parameters don't flow through GetFormRequestBody and don't trigger the bug, so they're not changed here.

Repro stack trace

System.NullReferenceException
   at Microsoft.AspNetCore.OpenApi.OpenApiDocumentService.<>c.<GetFormRequestBody>b__33_0(ApiParameterDescription parameter)
   at System.Linq.Lookup`2.Create(...)
   at Microsoft.AspNetCore.OpenApi.OpenApiDocumentService.GetFormRequestBody(...)
   at Microsoft.AspNetCore.OpenApi.OpenApiDocumentService.GetRequestBodyAsync(...)

Regression test

using_form_parameters.form_parameter_descriptions_have_a_parameter_descriptor exercises /form/explicit ([FromForm(Name = "name")] string value), which routes through _formValueVariablesfillFormParameters. Asserts ParameterDescriptor is non-null and carries the right Name + ParameterType.

Fails on main:

should not be null but was
Failed!  - Failed: 1, Passed: 0

Passes after the fix:

Passed!  - Failed: 0, Passed: 1

Test plan

  • New test fails on main
  • New test passes after fix
  • Full using_form_parameters class: 29 passed, 8 pre-existing skips
  • Full openapi / swashbuckle / open_api filter: 35 passed, 0 failed

Copilot AI review requested due to automatic review settings April 26, 2026 09:22
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a null-contract issue in Wolverine HTTP’s API description generation that can cause /openapi/v1.json to fail (HTTP 500) on ASP.NET Core 10 when endpoints use primitive [FromForm] parameters.

Changes:

  • Populate ApiParameterDescription.ParameterDescriptor for form parameters emitted via _formValueVariables in HttpChain.fillFormParameters.
  • Add a regression test asserting ParameterDescriptor is present (and correctly populated) for a primitive [FromForm(Name = ...)] parameter.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/Http/Wolverine.Http/HttpChain.ApiDescription.cs Ensures form ApiParameterDescription instances include a non-null ParameterDescriptor with Name and ParameterType.
src/Http/Wolverine.Http.Tests/using_form_parameters.cs Adds a regression test validating ParameterDescriptor is set for primitive [FromForm] parameters used by OpenAPI form request-body generation.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants