feat: expose FluentValidation rules in API definitions - #26112
Merged
Merged
Conversation
Contributor
Author
The RangeAttribute supports exclusive bounds since .NET 8, but they were lost in the api definition. The bounds are also written with the invariant culture now, so the api definition does not depend on the culture of the request.
IPropertyApiDescriptionModelContributor lets a package enrich the properties of a type after they are created from the attributes. The contributors are applied by AspNetCoreApiDescriptionModelProvider, so TypeApiDescriptionModel stays a plain model.
It reflects the statically evaluable FluentValidation rules of a DTO into the api definition, so the client proxy generators see the same constraints the attributes already provide. A rule is only published when it applies to every instance of the type, which leaves out the conditional rules, the rules of a non-default rule set and the rules of a RuleForEach. Volo.Abp.FluentValidation keeps its own dependencies, it does not depend on Volo.Abp.Http.
maliming
self-requested a review
August 29, 2026 09:52
Member
|
Hi, Thanks for the PR. I pushed some changes to your branch:
There is a test project and a documentation section listing what the mapping can not express. Please take a look. Thanks |
Contributor
Author
|
Hi @maliming, Thanks for improving the implementation and adding the tests and documentation.
|
maliming
approved these changes
Aug 30, 2026
Range(Type, string, string) keeps its limits as strings until the first validation, so a numeric limit was reported in the culture that declared it and could not be merged with a FluentValidation bound.
A magnitude below the decimal range, like 1e-30, parses to a zero, so a round trip through decimal turned it into a bound the server does not accept.
Range(Type, string, string) keeps its limits as strings until the first validation. They are converted the way the attribute converts them, so the reported limit is the one the server validates against whatever the culture of the request is, and a magnitude outside the decimal range survives it.
The contribution context carries the property now, so a rule on another type, the ordinal comparison of two strings for example, no longer publishes a numeric bound. Two bounds are compared as decimals, which are exact for every integral type, and only fall back to double for the magnitudes decimal can not hold.
A native integer is a number in the api type system too, and a between rule that carries its own comparer is skipped when its bounds no longer read as an interval, because the comparer itself is not on the descriptor.
1 task done
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.
Description
Resolves #26083
Adds an extension point for contributing property metadata during API description model generation and provides a FluentValidation implementation.
Changes:
IPropertyApiDescriptionModelContributortoVolo.Abp.Http.Modeling.AspNetCoreApiDescriptionModelProviderto resolve and execute registered property API description model contributors.FluentValidationApiDescriptionModelContributor.This is not a breaking change.
Checklist
How to test it?
/api/abp/api-definition.