RicoSuter / NSwag

The Swagger/OpenAPI toolchain for .NET, ASP.NET Core and TypeScript.
http://NSwag.org
MIT License
6.7k stars 1.24k forks source link

Property for data annotations missing when generating client using NSwag #3581

Open tilenzalar opened 3 years ago

tilenzalar commented 3 years ago

I have a project (C# API and Blazor WebAssembly client side). I have this data annotation on one of my property.

[Required(ErrorMessage = "My custom error message")]
public string Client { get; set; }

I'm using NSwag to generate my client side. NSwag generates this:

[Newtonsoft.Json.JsonProperty("client", Required = Newtonsoft.Json.Required.Always)]
[System.ComponentModel.DataAnnotations.Required(AllowEmptyStrings = true)]
public string Client { get; set; }

So property "ErrorMessage" was not generated. It should generate:

[System.ComponentModel.DataAnnotations.Required(AllowEmptyStrings = true, ErrorMessage = "My custom error message")]

I can add this manually, but I would like that NSwag generates this. Is this not possible or am I missing something?

*I've found this similar topic https://github.com/RicoSuter/NSwag/issues/2297#issuecomment-524640331 but I can't help myself with it.

RicoSuter commented 3 years ago

Is this not possible or am I missing something?

Open API does not have a way to describe this - ie its not possible ATM. However with custom properties and custom templates it would be possible...