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>
|
/// <param name="validationContext">Validation context</param>
|
||||||
/// <returns>Validation Result</returns>
|
/// <returns>Validation Result</returns>
|
||||||
IEnumerable<System.ComponentModel.DataAnnotations.ValidationResult> IValidatableObject.Validate(ValidationContext validationContext)
|
IEnumerable<System.ComponentModel.DataAnnotations.ValidationResult> IValidatableObject.Validate(ValidationContext validationContext)
|
||||||
{ {{#vars}}{{#hasValidation}}{{#maxLength}}
|
{
|
||||||
|
{{#vars}}
|
||||||
|
{{#hasValidation}}
|
||||||
|
{{#maxLength}}
|
||||||
// {{{name}}} ({{{datatype}}}) maxLength
|
// {{{name}}} ({{{datatype}}}) maxLength
|
||||||
if(this.{{{name}}} != null && this.{{{name}}}.Length > {{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}}}" });
|
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
|
// {{{name}}} ({{{datatype}}}) minLength
|
||||||
if(this.{{{name}}} != null && this.{{{name}}}.Length < {{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}}}" });
|
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
|
// {{{name}}} ({{{datatype}}}) maximum
|
||||||
if(this.{{{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}}}" });
|
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
|
// {{{name}}} ({{{datatype}}}) minimum
|
||||||
if(this.{{{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}}}" });
|
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
|
// {{{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)
|
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;
|
yield break;
|
||||||
}
|
}
|
||||||
{{/validatable}}
|
{{/validatable}}
|
||||||
|
@ -70,7 +70,7 @@ request_param_info('{{operationId}}', {{^isBodyParam}}'{{baseName}}'{{/isBodyPar
|
|||||||
{exclusive_min, {{exclusiveMinimum}} },{{/exclusiveMinimum}}{{#maxLength}}
|
{exclusive_min, {{exclusiveMinimum}} },{{/exclusiveMinimum}}{{#maxLength}}
|
||||||
{max_length, {{maxLength}} },{{/maxLength}}{{#minLength}}
|
{max_length, {{maxLength}} },{{/maxLength}}{{#minLength}}
|
||||||
{min_length, {{minLength}} },{{/minLength}}{{#pattern}}
|
{min_length, {{minLength}} },{{/minLength}}{{#pattern}}
|
||||||
{pattern, "{{pattern}}" },{{/pattern}}{{#isBodyParam}}
|
{pattern, "{{{pattern}}}" },{{/pattern}}{{#isBodyParam}}
|
||||||
schema,{{/isBodyParam}}{{#required}}
|
schema,{{/isBodyParam}}{{#required}}
|
||||||
required{{/required}}{{^required}}
|
required{{/required}}{{^required}}
|
||||||
not_required{{/required}}
|
not_required{{/required}}
|
||||||
|
@ -120,7 +120,7 @@ class {{classname}}
|
|||||||
* @DTA\Validator(name="LessThan", options={"max":{{maximum}}{{^exclusiveMaximum}}, "inclusive":true{{/exclusiveMaximum}}})
|
* @DTA\Validator(name="LessThan", options={"max":{{maximum}}{{^exclusiveMaximum}}, "inclusive":true{{/exclusiveMaximum}}})
|
||||||
{{/maximum}}
|
{{/maximum}}
|
||||||
{{#pattern}}
|
{{#pattern}}
|
||||||
* @DTA\Validator(name="Regex", options={"pattern":"{{pattern}}})
|
* @DTA\Validator(name="Regex", options={"pattern":"{{{pattern}}}"})
|
||||||
{{/pattern}}
|
{{/pattern}}
|
||||||
{{/hasValidation}}
|
{{/hasValidation}}
|
||||||
* @var {{datatype}}
|
* @var {{datatype}}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user