'How to include members of base entity in Swagger API Documentation?

I have something like these:

BaseDTO

    public record BaseDTO
    {
        public virtual int Id { get; protected init; }
        public DateTime Timestamp { get; protected init; }
    }

NotificationDTO

    public record NotificationDTO(string Code, string Name, string Description, NotificationType Type) : BaseDTO;

NotificationsController

        [HttpPost]
        [ProducesResponseType((int)HttpStatusCode.OK)]
        public async Task<IActionResult> Post([FromBody] NotificationDTO notificationDTO)
        {
            await _notificationsService.AddNotification(notificationDTO);
            return Ok();
        }

When I open SwaggerURL only members of NotificationsDTO can be set in "Try it out" section, members of BaseDTO are missing. Even if I add them by hand like setting the Id to 1 in Swagger, if I put a breakpoint in controller, Id it's 0, so Swagger doesn't modify it.

How can I see the base entity members in Swagger?

Edit: It seems the object binding is not done properly, I have tried to send this in the request body with Postman:

{
    "type": 0,
    "id": 1,
    "timestamp": "2022-05-13T09:22:18.429Z",
    "code": "string",
    "name": "string",
    "description": "string"
  }

And in the controller I've got this:

{
   "NotificationDTO"{
      Id = 0,
      "Timestamp = 1/1/0001 12":"00":00 AM,
      "Code = string",
      "Name = string",
      "Description = string",
      "Type = Email"
   }
}

If I change the access modifiers of the properties of base entity from public virtual int Id { get; protected init; } to public virtual int Id { get; init; } then the objects are binded properly and I can see the members of the base entity in Swagger.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source