Repository navigation
GH-5099 Wolverine.HTTP: an omitted query, header or form value binds the parameter's declared default - #5101
Merged
Merged
Conversation
…the parameter's declared default `int limit = 100` bound 0 and `string name = "all"` bound null when the request omitted the value, because the generated code initialized the variable to `default` and never read ParameterInfo.DefaultValue. ASP.NET Core Minimal APIs bind the declared default. - ReadHttpFrame takes the declared default of the parameter it binds and emits it as a C# literal (DeclaredDefaultValue: strings and chars escaped, numeric suffixes, enums cast from their number). - A parsed value with a declared default parses into a temporary, like a nullable already did. A failed TryParse writes the type default into its out argument, and bool/enum parsing runs even on a missing value, so parsing straight into the variable would clobber the default. - A string value becomes `(string?)raw ?? "default"`. - Applied wherever a method parameter binds: query string, form, header (including postprocessor headers), optional route values, and [AsParameters] constructor parameters. - The OpenAPI description carries the default on query and form parameters. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DCggXgxnG3EBXoR9rrq37U
This was referenced Oct 21, 2026
This was referenced Oct 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
A Wolverine.HTTP parameter bound from the query string ignored its declared C# default when the request omitted the value.
int limit = 100bound0andstring name = "all"boundnull. The generated code initialized the variable todefault, and nothing readParameterInfo.DefaultValue. ASP.NET Core Minimal APIs bind the declared default. CritterWatch's audit-log endpoint returned[]for every request without?limitbecause of this.Fix
ReadHttpFrametakes the declared default of the parameter it binds and emits it as a C# literal through the newDeclaredDefaultValuehelper. It escapes strings and chars, adds numeric suffixes, and casts enums from their underlying number.TryParsewrites the type's default into itsoutargument, and bool and enum parsing run even on a missing value. Parsing straight into the variable would wipe out the default.(string?)raw ?? "default".[FromQuery(Name = ...)][AsParameters]constructor parametersTests
New
declared_default_values_5099in Wolverine.Http.Tests, with endpoints in WolverineWebApi:int?.[AsParameters].Results:
dotnet build wolverine.slnx -c Release -f net9.0has 0 errors.F# code generation is unchanged.
Closes #5099
🤖 Generated with Claude Code
https://claude.ai/code/session_01DCggXgxnG3EBXoR9rrq37U