-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Closed as not planned
Description
Describe the bug
From v.6.6.1 an implementation of ISchemaFilter will not return any properties for subclasses:
int propertiesCount = schema.Properties.Count; // 0
This is a regression bug. It works as expected in v6.5.0.
Full implementatoin code of SchemaFilter:
public class MyFilter : ISchemaFilter
{
public void Apply(OpenApiSchema schema, SchemaFilterContext context)
{
var typeName = context.Type.Name;
Debug.WriteLine($"SchemaFilter called with: {typeName}");
if (typeName == nameof(CoffeeMachine))
{
int propertiesCount = schema.Properties.Count;
Debug.WriteLine($"Properties count of CoffeeMachine: {propertiesCount}");
// 0 in Swashbuckle.AspNetCore 6.6.1 - Incorrect
// 1 in Swashbuckle.AspNetCore 6.5.0 - Correct
}
}
}
Expected behavior
Should return 1
for my example:
public class CoffeeMachine : Machine
{
public string BeanType { get; set; }
}
Actual behavior
Returns 0
for my example:
public class CoffeeMachine : Machine
{
public string BeanType { get; set; }
}
Steps to reproduce
- Clone repro repo https://github.com/coder925/swashbuckle-propertiescount
- Debug project. Add breakpoint in MyFilter.cs.
Exception(s) (if any)
No response
Swashbuckle.AspNetCore version
6.6.1
.NET Version
8.0.303
Anything else?
I have a MarkAllAsRequiredFilter. I detected this issue since all properties of subclasses got optional from v6.6.1.
This was my original code:
public void Apply(OpenApiSchema model, SchemaFilterContext context)
{
var additionalRequiredProps = model.Properties
.Where(x => !model.Required.Contains(x.Key))
.Select(x => x.Key);
foreach (var propKey in additionalRequiredProps)
{
model.Required.Add(propKey);
}
}
Metadata
Metadata
Assignees
Labels
No labels