fix(#222): emit numeric bounds for short/byte/ushort/uint/ulong-typed rules#225
Merged
Conversation
…ds are emitted Validation bounds whose value was a small integer type (short/byte/ushort/uint/ ulong/sbyte) were silently dropped: the Between/Comparison rules matched, but the apply action skipped the bound because IsNumeric() did not recognize the boxed value, so minimum/maximum never reached the schema — even though the generator emits "type": "integer" for the property. This could not be worked around at the validator definition site, since e.g. InclusiveBetween on a short property only accepts short bounds. Fix: IsNumeric (shared core, MicroElements.OpenApi.FluentValidation) now recognizes all integer primitives (sbyte/byte/short/ushort/int/uint/long/ulong) alongside the floating/decimal/BigInteger types. NumericToDecimal already converted them all, so this single change fixes all three providers at once (Swashbuckle, NSwag, and the native Microsoft.AspNetCore.OpenApi transformer). Adds regression tests for InclusiveBetween/ExclusiveBetween and the comparison rules across the small integer types (verified red without the fix, green with it). Bumps version 7.1.8 -> 7.1.9 and updates CHANGELOG. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Member
Author
|
@claude review this pr |
|
Claude finished @avgalex's task in 59s —— View job Claude's ReviewTasks
Solid, well-scoped fix. Summary of what I checked: Core fix —
Tests —
CHANGELOG / version bump
Minor, non-blocking observations
Note: I could not run Looks good to merge from my read. |
avgalex
pushed a commit
that referenced
this pull request
Jul 9, 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.
Fixes #222.
Problem
Validation bounds whose value is a small integer type (
short/byte/ushort/uint/ulong/sbyte) were silently dropped:Between/Comparisonrules matched, but the apply action skipped the bound, sominimum/maximumnever reached the schema — even though the generator emits"type": "integer"for the property.Before:
"quantity": { "type": "integer", "format": "int16" }After:
"quantity": { "type": "integer", "format": "int16", "minimum": 1, "maximum": 99 }This could not be worked around at the validator definition site — for a
shortproperty,InclusiveBetween/GreaterThanOrEqualToonly acceptshortbounds, so the boxed value is always ashort.Root cause
IsNumericin the shared core (MicroElements.OpenApi.FluentValidation/Core/Extensions.cs) only recognizedint/long/float/double/decimal/BigInteger.short/byte/ushort/uint/ulong/sbytefall through tofalse, so theBetween/Comparisonapply actions skipped the bound.NumericToDecimalalready converts all of them viaConvert.ToDecimal.Fix
IsNumericnow recognizes all integer primitives:Because the check lives in the shared core, this single change fixes all three providers at once — Swashbuckle, NSwag, and the native
Microsoft.AspNetCore.OpenApitransformer (IsNumeric()gates the numeric bounds in each provider'sComparison/Betweenrules). No overflow risk:decimalcoversulong.MaxValue, andBigIntegerkeeps its dedicated branch. Thanks to @send0xx for the precise report and the proposed fix.Tests
Adds
Issue222SmallIntegerBoundsTestcoveringInclusiveBetween/ExclusiveBetweenand the comparison rules (GreaterThanOrEqualTo/LessThanOrEqualTo/GreaterThan) acrosssbyte/byte/short/ushort/uint/ulong, assertingminimum/maximumend-to-end. Verified red without the fix (10/10 fail), green with it.Full suite: net8.0 128/128, net9.0 128/128, net10.0 96/96.
Release
Bumps
version.props7.1.8 → 7.1.9 (patch) and adds a CHANGELOG entry.7.1.9is the canonical SemVer patch over the published7.1.8— preferred over a 4-part7.1.8.1for NuGet (all tags in this repo are 3-part, and SemVer 2.0 tooling normalizes trailing revisions).🤖 Generated with Claude Code