-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
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
[aspnetcore] Added support for patterns on model properties #2948
Conversation
Thanks for the contribution! I've tested with a petstore simple spec and a pattern added to the
Generating code on this branch creates the expected attribute:
Putting an invalid name via swagger ui:
It responds with the error object:
I do wonder if here are any concerns with this response object, since it exposes the regex value to the client. Do you know if it's possible to make the error message generic? |
To me, it's ok as the error message should be informative so not a bad idea for the client to know why the validation fails. |
I agree with William, if somebody has access to the service he should be
able to see how to consume it. And this is the same information in the
specification so I can't see why this should be a secret.
It's possible specify custom error message if that is needed:
[RegularExpression(@"^[a-zA-Z''-'\s]{1,40}$", ErrorMessage = "Characters
are not allowed.")]
See here for details:
https://docs.microsoft.com/en-us/dotnet/api/system.componentmodel.dataannotations.regularexpressionattribute?view=netframework-4.8
…On Sun, 26 May 2019, 09:05 William Cheng, ***@***.***> wrote:
I do wonder if here are any concerns with this response object, since it
exposes the regex value to the client. Do you know if it's possible to make
the error message generic?
To me, it's ok as the error message should be informative so not a bad
idea for the client to know why the validation fails.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#2948?email_source=notifications&email_token=AADT5YA77FF7MYUWBUDNKI3PXJHEJA5CNFSM4HODXUOKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODWIBNFA#issuecomment-495982228>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AADT5YFQBIHXFBFN46QN4WDPXJHEJANCNFSM4HODXUOA>
.
|
Let's go with this implementation and see if we've more feedback from the users on this. |
@ingvirafn thanks again for your contribution, which has been included in the v4.0.1 release (https://twitter.com/oas_generator/status/1135534738658062336) |
* 4.1.x: (56 commits) sync master Update compatibility table Ruby client: escape path parameters (OpenAPITools#3039) [gradle plugin] Release 4.0.1 fixes (OpenAPITools#3051) Update version to 4.0.2-SNAPSHOT (OpenAPITools#3047) Map number to double time since float is also parsed as double in Qt5 C++ (OpenAPITools#3046) Prepare 4.0.1 release (OpenAPITools#3041) [gradle] Reworking publishing pipeline (OpenAPITools#2886) [typescript-fetch] Fix uploading files (OpenAPITools#2900) Resolves OpenAPITools#2962 - Add properties config to Maven parameters (OpenAPITools#2963) fix(golang): Check error of xml Encode (OpenAPITools#3027) [C++][Restbed] Add handler callback methods (OpenAPITools#2911) Remove null checks for C# value types (OpenAPITools#2933) [python-server] Support python 3.7 for all server-generators (OpenAPITools#2884) Use golang's provided method names (gin) (OpenAPITools#2983) [python] Adding constructor parameters to Configuration and improving documentation (OpenAPITools#3002) Add new option to maven plugin's readme (OpenAPITools#3025) Engine param in maven plugin. (OpenAPITools#2881) Added support for patterns on model properties (OpenAPITools#2948) [csharp] Make API response headers dictionary case insensitive (OpenAPITools#2998) ...
ASPNET Core uses the attribute RegularExpression to validate the model state. This is supported in OpenAPI spec with the 'pattern' property.
This PR adds the reg-ex attribute to the model codegen.