Describe the bug
I have a model class with a dictionary property. At request time, I want to require the dictionary be non-empty. MVC supports doing that via the [MinLength] attribute:
[Required]
[MinLength(1)]
public IReadOnlyDictionary<string, string?> Values { get; }
However, Swashbuckle then applies "minLength": 1 to the schema definition instead of "minProperties": 1.
Expected behavior
The generated OpenAPI document includes "minProperties": 1 for the Values schema.
Actual behavior
The generated OpenAPI document includes "minLength": 1 for the Values schema.
Steps to reproduce
public class MyModel
{
[Required]
[MinLength(1)]
public IReadOnlyDictionary<string, string?> Values { get; init; }
}
[ApiController]
public class MyController
{
[HttpPost]
public void MyAction([FromBody] MyModel model)
{
}
}
Exception(s) (if any)
No response
Swashbuckle.AspNetCore version
10.1.7
.NET Version
10.0.202
Anything else?
This was found by running the vacuum linter against the generated OpenAPI document.
Describe the bug
I have a model class with a dictionary property. At request time, I want to require the dictionary be non-empty. MVC supports doing that via the
[MinLength]attribute:However, Swashbuckle then applies
"minLength": 1to the schema definition instead of"minProperties": 1.Expected behavior
The generated OpenAPI document includes
"minProperties": 1for theValuesschema.Actual behavior
The generated OpenAPI document includes
"minLength": 1for theValuesschema.Steps to reproduce
Exception(s) (if any)
No response
Swashbuckle.AspNetCore version
10.1.7
.NET Version
10.0.202
Anything else?
This was found by running the
vacuumlinter against the generated OpenAPI document.