Let's say I have a class I would like to be returned by API:
public class MyClass
{
...
public object someObject { get; set; }
...
public MyClass(object someObject)
{
this.someObject = someObject;
}
}
And as someObject property in this class I would like to return one or another class:
public class CustomClass1
{
...
}
public class CustomClass2
{
...
}
My API method in controller looks something like this:
[HttpGet()]
[Produces("application/json")]
[ProducesResponseType(typeof(MyClass), 200)]
public async Task<IActionResult> ApiMethod([Required] string input)
{
if (...)
return new OkObjectResult(new MyClass(new class CustomClass1());
else
return new OkObjectResult(new MyClass(new class CustomClass2());
}
But in Swagger models CustomClass1 and CustomClass2 are not specified and MyClass's property someObject is empty and looks like this: {}. Is there any way to tell OpenApi to "index" those classes as models and specify that one or another type will be returned? Possibly some alternative solution?
