Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
tilenzalar opened this issue Aug 3, 2021 · 1 comment

Comments

@tilenzalar
Copy link

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 #2297 (comment) but I can't help myself with it.

@RicoSuter
Copy link
Owner

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...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants