Reputation: 373
I am looking for a way to change the display Name of a property in Model so that the same would be reflect in the response body in swagger.
I tried using DisplayName
attribute for the field but it doesn't seem to be working.
[DisplayName("Fucntion ID")]
public string FunctionId { get; set; }
[DisplayName("Function Description")]
public string FunctionDEscription { get; set; }
Is there any other way to achieve this? Thanks in advance.
Upvotes: 2
Views: 2111
Reputation: 373
I got the answer-
Used [JsonPropertyName("Fucntion ID")]
instead of [DisplayName("Fucntion ID")]
Upvotes: 0
Reputation: 36685
If you use asp.net core 3.x and asp.net 5,you could use [JsonPropertyName("Fucntion ID")]
which is in System.Text.Json
.
If you use asp.net core 2.x,you could use [JsonProperty("Fucntion ID")]
which is in Json.NET
.
Reference:
https://www.newtonsoft.com/json/help/html/JsonPropertyName.htm
Upvotes: 3