How do I make a property read-only in a DTO? #4300
Unanswered
Peter-Svahn
asked this question in
Q&A
Replies: 1 comment
-
Hello, I have the same issue, could someone provide an update ? Thanks in advance |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I'm using Nswag to generate a client API for a UserController, where UserDTO objects are defined as:
public class UserDTO
{
public int Id { get; set; }
public DateTime CreatedTime { get; private set; }
public DateTime UpdatedTime { get; private set; }
public string? UserName { get; set; }
public string? DisplayName { get; set; }
public string? EncodedPassword { get; set; }
public string? Email { get; set; }
public bool Active { get; set; }
public List? Roles { get; set; }
}
I would like to disallow clients to set created and update time by making the setters private. But the generated UserDTO on the client side still has a public setter. Are there any attributes to control the OpenAPI document generation in this respect?
Beta Was this translation helpful? Give feedback.
All reactions