OpenAPI schema transformers are not called for base types
- Dominant language
- C#
- Stars
- 38.4k
- Forks
- 10.9k
- Avg merge
- 2d 6h
- Merged PRs (30d)
- 290
Description
### Is there an existing issue for this?
- [x] I have searched the existing issues
### Describe the bug
Create a program like this
```
[JsonDerivedType(typeof(B), "b")]
[JsonDerivedType(typeof(C), "c")]
public class A
{
public int I { get; set; }
}
public class B : A
{
public int J { get; set; }
}
public class C : A
{
public int K { get; set; }
}
class MySchemaTransformer : IOpenApiSchemaTransformer
{
public async Task TransformAsync(OpenApiSchema schema, OpenApiSchemaTransformerContext context, CancellationToken cancellationToken)
{
...
}
}
app.MapGet("/api/x", () =>TypedResults.Ok(new A());
builder.Services.AddOpenApi(options =>
{
options.AddSchemaTransformer();
}
```
The generated OpenAPI spec will contain 4 types: ABase (properites `i`), AB (properies `$type`, `i` and `j`), AC (properties `$type`, `i` and `k`) and A (`anyof(AB, AC, ABase)`)
The transformer is called for the types `A`, `AB` and `AC`, but *not* for `ABase`
### Expected Behavior
The schema transformer should be called for the (implicitly created) type `ABase`.
### Steps To Reproduce
_No response_
### Exceptions (if any)
_No response_
### .NET Version
10
### Anything else?
_No response_
Contributor guide
Assessment
This issue has not been assessed yet.