Is there an existing issue for this?
Describe the bug
OpenApiSchemaService emits the type discriminator of a polymorphic derived type as a one-value string constant, which is correct. When it hands that node to an IOpenApiSchemaTransformer, it populates OpenApiSchemaTransformerContext.JsonPropertyInfo (and therefore JsonTypeInfo) by matching the discriminator's name against the type's JSON metadata. That match can land on a property the emitter itself excluded from the schema because it carries [JsonIgnore].
context.JsonTypeInfo.Type then reports the CLR type of an ignored property instead of the type of the node the framework actually built. A transformer that keys on the node's type rewrites the discriminator and silently corrupts it.
The same component already handles the exclusion correctly elsewhere. An ignored property on a non-polymorphic type produces no schema node and no transformer callback. Only the discriminator lookup reaches back into the excluded metadata.
Expected Behavior
The transformer should not receive an ignored property's metadata for the discriminator node. Either no JsonPropertyInfo is supplied for a synthesized discriminator, or the lookup skips the properties the emitter excluded, so context.JsonTypeInfo.Type describes the node the framework built.
The control output is the correct document, and it is what a transformer has to be able to leave intact.
Steps To Reproduce
aspnetcore-openapi-discriminator-repro
Exceptions (if any)
No response
.NET Version
10.0.400
Anything else?
This block is byte-identical on release/9.0, release/10.0 and main, so the .NET 11 preview line — Microsoft.AspNetCore.OpenApi 11.0.0-preview.7, which takes Microsoft.OpenApi [3.9.0, 4.0.0) — carries it unchanged. I read that from source rather than running it: 3.x is consumed only by the net11.0 packages and I have no .NET 11 SDK to hand.
Suggested fix
Skip, in that loop, the candidates the emitter itself skipped. A JsonPropertyInfo with no accessors is exactly an ignored one:
foreach (var propertyInfo in jsonTypeInfo.Properties)
{
// the schema carries no node for an ignored property, so its metadata describes no node here
if (propertyInfo is { Get: null, Set: null })
{
continue;
}
...
}
Is there an existing issue for this?
Describe the bug
OpenApiSchemaServiceemits the type discriminator of a polymorphic derived type as a one-value string constant, which is correct. When it hands that node to anIOpenApiSchemaTransformer, it populatesOpenApiSchemaTransformerContext.JsonPropertyInfo(and thereforeJsonTypeInfo) by matching the discriminator's name against the type's JSON metadata. That match can land on a property the emitter itself excluded from the schema because it carries[JsonIgnore].context.JsonTypeInfo.Typethen reports the CLR type of an ignored property instead of the type of the node the framework actually built. A transformer that keys on the node's type rewrites the discriminator and silently corrupts it.The same component already handles the exclusion correctly elsewhere. An ignored property on a non-polymorphic type produces no schema node and no transformer callback. Only the discriminator lookup reaches back into the excluded metadata.
Expected Behavior
The transformer should not receive an ignored property's metadata for the discriminator node. Either no
JsonPropertyInfois supplied for a synthesized discriminator, or the lookup skips the properties the emitter excluded, socontext.JsonTypeInfo.Typedescribes the node the framework built.The control output is the correct document, and it is what a transformer has to be able to leave intact.
Steps To Reproduce
aspnetcore-openapi-discriminator-repro
Exceptions (if any)
No response
.NET Version
10.0.400
Anything else?
This block is byte-identical on
release/9.0,release/10.0andmain, so the .NET 11 preview line —Microsoft.AspNetCore.OpenApi 11.0.0-preview.7, which takesMicrosoft.OpenApi [3.9.0, 4.0.0)— carries it unchanged. I read that from source rather than running it: 3.x is consumed only by the net11.0 packages and I have no .NET 11 SDK to hand.Suggested fix
Skip, in that loop, the candidates the emitter itself skipped. A JsonPropertyInfo with no accessors is exactly an ignored one: