2

I'm currently using NSwag Studio to generate my C# Client. I have the setting "generate data annotation attributes" turned on and seems to work well for data annotations such as [Required], [Range] etc...

I've noticed, however, that not all annotations are generated though. Annotations such as [Display] is missing from the generated client, even though they've been added to the model class. For example:

[Required]
[Range(1.9, 3.9)]
[Display(Name = "Total Price")]
public decimal? TotalPrice { get; set; }

Generates the following:

[Newtonsoft.Json.JsonProperty("totalPrice", Required = Newtonsoft.Json.Required.Always)]
[System.ComponentModel.DataAnnotations.Range(1.9D, 3.9D)]
public decimal TotalPrice { get; set; }

The [Display] annotation is missing. Is this by design, or am I perhaps missing something or implemented my class incorrectly? Thanks

Andrew
  • 238
  • 1
  • 9
  • Have you found a solution or workaround to this issue? – Javi Kroonenburg Dec 04 '19 at 12:36
  • 1
    I managed to find the root cause yes but I have not had time to conduct a pull request. Basically, the Title property is missing from the PropertyModel.cs that maps these attributes. See more here: https://github.com/RicoSuter/NSwag/issues/2297#issuecomment-524640331 It shows an example of how the [Description] attribute is being mapped, and if you look inside the PropertyModel.cs class, you'll see it's missing the Title. Not sure if you have any bandwidth to conduct the pull request or not? It shouldn't take long I would have thought though. Just pretty slammed right now. – Andrew Dec 04 '19 at 12:56

0 Answers0