MEV analyzers: warn on polymorphic derived types registered via IJsonTypeInfoResolver
- Dominant language
- C#
- Stars
- 38.4k
- Forks
- 10.9k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 281
Description
### Is there an existing issue for this?
- [x] I have searched the existing issues
### Is your feature request related to a problem? Please describe the problem.
```csharp
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddValidation();
builder.Services.ConfigureHttpJsonOptions(options =>
{
var resolver = new DefaultJsonTypeInfoResolver();
resolver.Modifiers.Add(typeInfo =>
{
if (typeInfo.Type == typeof(MyBaseType))
{
typeInfo.PolymorphismOptions = new JsonPolymorphismOptions
{
TypeDiscriminatorPropertyName = "$type"
};
typeInfo.PolymorphismOptions.DerivedTypes.Add(
new JsonDerivedType(typeof(MyDerivedType1), "type1"));
typeInfo.PolymorphismOptions.DerivedTypes.Add(
new JsonDerivedType(typeof(MyDerivedType2), "type2"));
}
});
options.SerializerOptions.TypeInfoResolver = resolver;
});
```
If `MyDerivedType1` and `MyDerivedType2` don't have `[ValidatableType]` attribute and also didn't appear in the type graph that is statically known at compile-time, a warning should suggest adding the attribute to them. Otherwise, validation for them will be skipped if any endpoint encounters `MyBaseType`.
### Describe the solution you'd like
Analyzer warning to help with this case where validation is silently skipped.
### Additional context
_No response_
Contributor guide
Research direction
Locate the MEV analyzer implementation and its existing ValidatableType diagnostics and tests; begin by tracing how statically known types are discovered and how IJsonTypeInfoResolver registrations are represented. Done means the analyzer warns when resolver-registered derived types lack [ValidatableType] and are absent from the compile-time type graph, covering the shown polymorphic scenario.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100