Recommended way of avoiding base class on DTO

Hi,

I’m trying to avoid using a base class BaseStepTypeDto on the JobStepDto.StepParameters for the summarised structure below. The client is the TypeScript JsonServiceClient. A job can contain multiple steps and each step can have different parameters based on the step type. I could just stringify the step parameters but would like to get the type info if possible. Suggestions appreciated.

Thanks,
John

public class JobDto
{
    public List<JobStepDto> JobSteps { get; set; } = new List<JobStepDto>();
}

public class JobStepDto
{
    public JobStepType StepType { get; set; }

    public BaseStepTypeDto StepParameters { get; set; }
}
    
public abstract class BaseStepTypeDto
{
    public string Name { get; set; }
}

public class SomeOtherStepTypeDto : BaseStepTypeDto
{
    //Lots of different config parameters
    public string Config1 { get; set; }
}

DTOs are used to define your services contract which I’d avoid trying to hide behind their inheritance, apart from making it harder for anyone trying to reason the inputs/outputs of each of your Services, it’s a common source of serialization issues.

You can avoid inheritance by flattening the hierarchy into a single generic type (you could classify with a Name/Type/Kind property) or by having your Request DTO contain a different explicit typed property per job (i.e. has vs is).