forked from loafle/openapi-generator-original
use original value of pattern (#5554)
This commit is contained in:
parent
fd17955685
commit
1e9fe51175
@ -1 +1 @@
|
||||
|{{paramName}} |{{description}} |{{^required}}(x){{/required}}{{#required}}(/){{/required}} |{{defaultValue}} | {{pattern}} |
|
||||
|{{paramName}} |{{description}} |{{^required}}(x){{/required}}{{#required}}(/){{/required}} |{{defaultValue}} | {{{pattern}}} |
|
||||
|
@ -203,38 +203,52 @@ this.{{name}} = {{name}};
|
||||
/// <param name="validationContext">Validation context</param>
|
||||
/// <returns>Validation Result</returns>
|
||||
IEnumerable<System.ComponentModel.DataAnnotations.ValidationResult> IValidatableObject.Validate(ValidationContext validationContext)
|
||||
{ {{#vars}}{{#hasValidation}}{{#maxLength}}
|
||||
{
|
||||
{{#vars}}
|
||||
{{#hasValidation}}
|
||||
{{#maxLength}}
|
||||
// {{{name}}} ({{{datatype}}}) maxLength
|
||||
if(this.{{{name}}} != null && this.{{{name}}}.Length > {{maxLength}})
|
||||
{
|
||||
yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for {{{name}}}, length must be less than {{maxLength}}.", new [] { "{{{name}}}" });
|
||||
}
|
||||
{{/maxLength}}{{#minLength}}
|
||||
|
||||
{{/maxLength}}
|
||||
{{#minLength}}
|
||||
// {{{name}}} ({{{datatype}}}) minLength
|
||||
if(this.{{{name}}} != null && this.{{{name}}}.Length < {{minLength}})
|
||||
{
|
||||
yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for {{{name}}}, length must be greater than {{minLength}}.", new [] { "{{{name}}}" });
|
||||
}
|
||||
{{/minLength}}{{#maximum}}
|
||||
|
||||
{{/minLength}}
|
||||
{{#maximum}}
|
||||
// {{{name}}} ({{{datatype}}}) maximum
|
||||
if(this.{{{name}}} > ({{{datatype}}}){{maximum}})
|
||||
{
|
||||
yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for {{{name}}}, must be a value less than or equal to {{maximum}}.", new [] { "{{{name}}}" });
|
||||
}
|
||||
{{/maximum}}{{#minimum}}
|
||||
|
||||
{{/maximum}}
|
||||
{{#minimum}}
|
||||
// {{{name}}} ({{{datatype}}}) minimum
|
||||
if(this.{{{name}}} < ({{{datatype}}}){{minimum}})
|
||||
{
|
||||
yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for {{{name}}}, must be a value greater than or equal to {{minimum}}.", new [] { "{{{name}}}" });
|
||||
}
|
||||
{{/minimum}}{{#pattern}}
|
||||
|
||||
{{/minimum}}
|
||||
{{#pattern}}
|
||||
// {{{name}}} ({{{datatype}}}) pattern
|
||||
Regex regex{{{name}}} = new Regex(@"{{vendorExtensions.x-regex}}"{{#vendorExtensions.x-modifiers}}{{#-first}}, {{/-first}}RegexOptions.{{.}}{{^-last}} | {{/-last}}{{/vendorExtensions.x-modifiers}});
|
||||
Regex regex{{{name}}} = new Regex(@"{{{vendorExtensions.x-regex}}}"{{#vendorExtensions.x-modifiers}}{{#-first}}, {{/-first}}RegexOptions.{{{.}}}{{^-last}} | {{/-last}}{{/vendorExtensions.x-modifiers}});
|
||||
if (false == regex{{{name}}}.Match(this.{{{name}}}).Success)
|
||||
{
|
||||
yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for {{{name}}}, must match a pattern of {{pattern}}.", new [] { "{{{name}}}" });
|
||||
yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for {{{name}}}, must match a pattern of {{{pattern}}}.", new [] { "{{{name}}}" });
|
||||
}
|
||||
{{/pattern}}{{/hasValidation}}{{/vars}}
|
||||
|
||||
{{/pattern}}
|
||||
{{/hasValidation}}
|
||||
{{/vars}}
|
||||
yield break;
|
||||
}
|
||||
{{/validatable}}
|
||||
|
@ -70,7 +70,7 @@ request_param_info('{{operationId}}', {{^isBodyParam}}'{{baseName}}'{{/isBodyPar
|
||||
{exclusive_min, {{exclusiveMinimum}} },{{/exclusiveMinimum}}{{#maxLength}}
|
||||
{max_length, {{maxLength}} },{{/maxLength}}{{#minLength}}
|
||||
{min_length, {{minLength}} },{{/minLength}}{{#pattern}}
|
||||
{pattern, "{{pattern}}" },{{/pattern}}{{#isBodyParam}}
|
||||
{pattern, "{{{pattern}}}" },{{/pattern}}{{#isBodyParam}}
|
||||
schema,{{/isBodyParam}}{{#required}}
|
||||
required{{/required}}{{^required}}
|
||||
not_required{{/required}}
|
||||
|
@ -120,7 +120,7 @@ class {{classname}}
|
||||
* @DTA\Validator(name="LessThan", options={"max":{{maximum}}{{^exclusiveMaximum}}, "inclusive":true{{/exclusiveMaximum}}})
|
||||
{{/maximum}}
|
||||
{{#pattern}}
|
||||
* @DTA\Validator(name="Regex", options={"pattern":"{{pattern}}})
|
||||
* @DTA\Validator(name="Regex", options={"pattern":"{{{pattern}}}"})
|
||||
{{/pattern}}
|
||||
{{/hasValidation}}
|
||||
* @var {{datatype}}
|
||||
|
Loading…
x
Reference in New Issue
Block a user