-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
C# Code Generation doesn't validate patterns #3145
Comments
What code generation are you talking about? Controller code generation or client-side validation? For controllers generation, I think that DataAnnotations are enough to validate such entries? doesn't that work? Could you send an example ? |
I'm referring to client-side code generation. I'd expect the client to validate URL parameters before sending the request. Even if the validation happens on the server, we can avoid this unnecessary network roundtrip. |
Example: /api/test/{version}:
get:
parameters:
name: version
in: path
schema:
type: string
pattern: "^\\d+(\\.\\d+)?(\\.\\d+)?$"
responses:
"200":
description: Success
content:
text/plain:
schema:
type: string generates the following client code: public async System.Threading.Tasks.Task<string> TestAsync(string version, System.Threading.CancellationToken cancellationToken)
{
var urlBuilder_ = new System.Text.StringBuilder();
urlBuilder_.Append(BaseUrl != null ? BaseUrl.TrimEnd('/') : "").Append("/api/test/{version}");
urlBuilder_.Replace("{version}", System.Uri.EscapeDataString(ConvertToString(version, System.Globalization.CultureInfo.InvariantCulture)));
var client_ = _httpClient;
var disposeClient_ = false;
try
{
using (var request_ = new System.Net.Http.HttpRequestMessage())
... I would expect to see a few lines like: if (!Regex.IsMatch(version, @"^\d+(\.\d+)?(\.\d+)?$"))
{
throw new ApiException($"Query parameter 'version' doesn't match the specified pattern.")
} |
This feature is currently not implemented. |
@RicoSuter Hello! Is this feature still not implemented? If so, I would be happy to try to implement it. |
@RicoSuter @davidorbelian any updates on this? We're making wrappers at the moment to do simple validation on the client-side Example:
The generated csharp client does not create any validation here. Or is there any options to enforce this? Thanks |
Hi, is there a plan to prioritise this? None of the |
Hi everyone,
I noticed that the C# code generation doesn't validate patterns (on the client side). If I annotate a parameter of type string with a pattern (e.g. "^v[1-9]$"), I expect the Api method to throw an ApiException when the supplied string doesn't match the pattern.
I'd be happy to open a PR. Is that something this project could use?
The text was updated successfully, but these errors were encountered: