c# client. OneOf on request types with derived abstract base class generates a method but not with the base class as parameter but the first of the derived classes #4824
public abstract class BaseClass
{
[Required]
public string BaseProp { get; set; }
}
public class DerivedA : BaseClass
{
[Required]
public string DerivedAProp { get; set; }
}
public class DerivedB : BaseClass
{
[Required]
public string DerivedBProp { get; set; }
}
and a controller taking the BaseClass as a param
[HttpPost("doSomething", Name = "DoSomething")]
[ProducesResponseType<string>(StatusCodes.Status200OK)]
public IActionResult DoSomething(BaseClass request)
{
return Ok();
}
The generated c# client does not take the BaseClass as a param but instead the first of the derived types / oneOf´s and hence cannot be called with all possible derived request types.
public virtual System.Threading.Tasks.Task<string> DoSomethingAsync(DerivedA body)
{
return DoSomethingAsync(body, System.Threading.CancellationToken.None);
}
Is it not suppose to figure out that it should pick the base type, so the operation can be called with either DerivedA or DerivedB?
It has figured out the both DerivedA and DerivedB derives from BaseClass and hence the base class should be the method argumenT?
[System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.0.3.0 (NJsonSchema v11.0.0.0 (Newtonsoft.Json v13.0.0.0))")]
public partial class DerivedA : BaseClass
{
[Newtonsoft.Json.JsonProperty("derivedAProp", Required = Newtonsoft.Json.Required.Always)]
[System.ComponentModel.DataAnnotations.Required]
public string DerivedAProp { get; set; }
}
[System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.0.3.0 (NJsonSchema v11.0.0.0 (Newtonsoft.Json v13.0.0.0))")]
public partial class DerivedB : BaseClass
{
[Newtonsoft.Json.JsonProperty("derivedAProp", Required = Newtonsoft.Json.Required.Always)]
[System.ComponentModel.DataAnnotations.Required]
public string DerivedAProp { get; set; }
}
When having a request class defined by
and a controller taking the BaseClass as a param
with configuration
The schema gets to be
The generated c# client does not take the BaseClass as a param but instead the first of the derived types / oneOf´s and hence cannot be called with all possible derived request types.
Is it not suppose to figure out that it should pick the base type, so the operation can be called with either DerivedA or DerivedB?
It has figured out the both DerivedA and DerivedB derives from BaseClass and hence the base class should be the method argumenT?