Swashbuckle.AspNetCore.Filters
Swashbuckle.AspNetCore.Filters copied to clipboard
ExamplesProvider does not apply to sub objects
The examples provider doesn't seem to respect if the example provided is a sub class of another object.
If I have a nested object within the request object, the example is not picked up in Swagger. For example:
public class ControllerExample
{
public IActionResult Post(TestClass testClass)
{
//... Etc
}
public class TestClass
{
public TestSubClass TestSubClass { get; set; }
}
public class TestSubClass
{
public string Id { get; set; }
}
}
public class TestSubClassExamplesProvider : IExamplesProvider<ControllerExample.TestSubClass>
{
public ControllerExample.TestSubClass GetExamples()
{
return new ControllerExample.TestSubClass
{
Id = "Hello"
};
}
}
In this example, I'd expect that the TestSubClass
in the swagger example would have a value of "Hello" in swagger, however it is not picked up and falls back to the default value for a string.
I'm going to copy/paste this advisory to any open issues that are for ExamplesOperationFilter.
https://github.com/mattfrear/Swashbuckle.AspNetCore.Filters#do-not-use-this-filter-unless-you-have-to
Swashbuckle.AspNetCore supports adding examples from XML documentation, which might already cover your use case, in which case you can stop using this package and close your issue.
If examples from XML documentation doesn't work for you, then feel free to leave your issue open.