public class InputModel
{
public string Thing { get; set; }
public DateTime AnotherThing { get; set; }
}
public ThingController : ControllerBase
{
public Task DoTheThing([FromQuery] int foo, [FromQuery] InputModel input)
{
// Elided.
}
}
The problem is that when the Swagger documentation is generated for this controller, the following inputs are listed for DoTheThing
:
foo: int
Thing: string
AnotherThing: DateTime
Note how the last two inputs start with uppercase, because that's how they are defined in their model. I want them to start with lowercase to be consistent with the non-complex parameters passed to the controller method (remember, ASP.NET model binding doesn't care about casing).
The easy way to do this is to either have those properties be named starting with lowercase on the model, or apply the FromQuery
and/or FromBody
attribute on them. I don't want to do either of these things because the former is just nasty, and the latter is applying behaviour to properties, when I need that behaviour to be applied on a case-by-case basis.
Ideally I'd like to be able to write something like the following (which currently doesn't work because Swashbuckle doesn't seem to know/care about the DisplayName
or Display
attributes):
public class InputModel
{
[DisplayName("thing")]
public string Thing { get; set; }
[DisplayName("anotherThing")]
public DateTime AnotherThing { get; set; }
}
However, I'd be happy with any solution that allows me to "rename" the model properties without changing their names.
I have looked at Swashbuckle.AspNetCore.Annotations but it doesn't appear to provide this functionality.