I am building an API and using swagger to test the endpoints. I have a ProductDTO:
public string ProductName { get; set; }
.
.
.
public Price Price { get; set; }
in this DTO I want to use Price class which is used throughout my code. Price class looks like this:
public class Price
{
public Price(decimal amount, string currency)
{
Amount = amount;
Currency = currency;
}
public decimal Amount { get; private set; }
public string Currency { get; private set; }
}
But since private setters are used in Price class I cannot set these values using swagger (it has readonly attribute on those). I really like this approach of having private setters and setting values with constructor, which by the way is public. Is there any way I could set values for Price class using swagger and still use private setters on properties?