Description
Is there an existing issue for this?
- I have searched the existing issues
Describe the bug
When an endpoint returns a type containing a Dictionary
containing another type, the schema of this last type is not processed by schema transformers (see the missing "a": "b"
in Bar2
below, causing a new schema to be created).
{
"schemas": {
"Bar": {
"type": "object",
"properties": {
"value": {
"type": "integer",
"format": "int32",
"a": "b"
}
},
"a": "b"
},
"Bar2": {
"type": "object",
"properties": {
"value": {
"type": "integer",
"format": "int32"
}
}
},
"Foo": {
"type": "object",
"properties": {
"bar": {
"$ref": "#/components/schemas/Bar"
},
"bars": {
"type": "object",
"additionalProperties": {
"$ref": "#/components/schemas/Bar2"
},
"a": "b"
}
},
"a": "b"
}
}
}
My guess is that additionalProperties
should be processed somewhere here:
aspnetcore/src/OpenApi/src/Services/Schemas/OpenApiSchemaService.cs
Lines 172 to 215 in a6ce940
Expected Behavior
I expected to see
{
"schemas": {
"Bar": {
"type": "object",
"properties": {
"value": {
"type": "integer",
"format": "int32",
"a": "b"
}
},
"a": "b"
},
"Foo": {
"type": "object",
"properties": {
"bar": {
"$ref": "#/components/schemas/Bar"
},
"bars": {
"type": "object",
"additionalProperties": {
"$ref": "#/components/schemas/Bar"
},
"a": "b"
}
},
"a": "b"
}
}
}
Steps To Reproduce
Add a schema transformer like so:
options.AddSchemaTransformer((schema, _, _)
=>
{
schema.Extensions.Add("a", new OpenApiString("b"));
return Task.CompletedTask;
});
And add an endpoint that returns a type (Foo
) which contains a dictionary with another type (Bar
).
app.MapGet("/", () => new Foo());
class Foo
{
public Bar Bar { get; set; }
public Dictionary<string, Bar> Bars { get; set; }
}
class Bar
{
public int Value { get; set; }
}
Exceptions (if any)
No response
.NET Version
9.0.200-preview.0.24575.35
Anything else?
No response