mirror of
https://github.com/valitydev/openapi-generator.git
synced 2024-11-07 19:08:52 +00:00
use instance variable in validation rule
This commit is contained in:
parent
e17a620506
commit
0e58265eb5
@ -62,36 +62,36 @@ module {{moduleName}}{{#models}}{{#model}}{{#description}}
|
||||
invalid_properties = Array.new
|
||||
{{#isEnum}}
|
||||
allowed_values = [{{#allowableValues}}{{#values}}"{{{this}}}"{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}}]
|
||||
if {{{name}}} && !allowed_values.include?({{{name}}})
|
||||
if @{{{name}}} && !allowed_values.include?(@{{{name}}})
|
||||
invalid_properties.push("invalid value for '{{{name}}}', must be one of #{allowed_values}.")
|
||||
end
|
||||
|
||||
{{/isEnum}}
|
||||
{{#hasValidation}}
|
||||
if {{{name}}}.nil?
|
||||
if @{{{name}}}.nil?
|
||||
fail ArgumentError, "{{{name}}} cannot be nil"
|
||||
end
|
||||
|
||||
{{#minLength}}
|
||||
if {{{name}}}.to_s.length > {{{maxLength}}}
|
||||
if @{{{name}}}.to_s.length > {{{maxLength}}}
|
||||
invalid_properties.push("invalid value for '{{{name}}}', the character length must be smaller than or equal to {{{maxLength}}}.")
|
||||
end
|
||||
|
||||
{{/minLength}}
|
||||
{{#maxLength}}
|
||||
if {{{name}}}.to_s.length < {{{minLength}}}
|
||||
if @{{{name}}}.to_s.length < {{{minLength}}}
|
||||
invalid_properties.push("invalid value for '{{{name}}}', the character length must be great than or equal to {{{minLength}}}.")
|
||||
end
|
||||
|
||||
{{/maxLength}}
|
||||
{{#maximum}}
|
||||
if {{{name}}} > {{{maximum}}}
|
||||
if @{{{name}}} > {{{maximum}}}
|
||||
invalid_properties.push("invalid value for '{{{name}}}', must be smaller than or equal to {{{maximum}}}.")
|
||||
end
|
||||
|
||||
{{/maximum}}
|
||||
{{#minimum}}
|
||||
if {{{name}}} < {{{minimum}}}
|
||||
if @{{{name}}} < {{{minimum}}}
|
||||
invalid_properties.push("invalid value for '{{{name}}}', must be greater than or equal to {{{minimum}}}.")
|
||||
end
|
||||
|
||||
@ -112,31 +112,31 @@ module {{moduleName}}{{#models}}{{#model}}{{#description}}
|
||||
{{/required}}
|
||||
{{#isEnum}}
|
||||
allowed_values = [{{#allowableValues}}{{#values}}"{{{this}}}"{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}}]
|
||||
if {{{name}}} && !allowed_values.include?({{{name}}})
|
||||
if @{{{name}}} && !allowed_values.include?(@{{{name}}})
|
||||
return false
|
||||
end
|
||||
{{/isEnum}}
|
||||
{{#hasValidation}}
|
||||
{{#minLength}}
|
||||
if {{{name}}}.to_s.length > {{{maxLength}}}
|
||||
if @{{{name}}}.to_s.length > {{{maxLength}}}
|
||||
return false
|
||||
end
|
||||
|
||||
{{/minLength}}
|
||||
{{#maxLength}}
|
||||
if {{{name}}}.to_s.length < {{{minLength}}}
|
||||
if @{{{name}}}.to_s.length < {{{minLength}}}
|
||||
return false
|
||||
end
|
||||
|
||||
{{/maxLength}}
|
||||
{{#maximum}}
|
||||
if {{{name}}} > {{{maximum}}}
|
||||
if @{{{name}}} > {{{maximum}}}
|
||||
return false
|
||||
end
|
||||
|
||||
{{/maximum}}
|
||||
{{#minimum}}
|
||||
if {{{name}}} < {{{minimum}}}
|
||||
if @{{{name}}} < {{{minimum}}}
|
||||
return false
|
||||
end
|
||||
|
||||
@ -151,7 +151,7 @@ module {{moduleName}}{{#models}}{{#model}}{{#description}}
|
||||
# @param [Object] {{{name}}} Object to be assigned
|
||||
def {{{name}}}=({{{name}}})
|
||||
allowed_values = [{{#allowableValues}}{{#values}}"{{{this}}}"{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}}]
|
||||
if {{{name}}} && !allowed_values.include?({{{name}}})
|
||||
if {{{name}}} && !allowed_values.include?(@{{{name}}})
|
||||
fail ArgumentError, "invalid value for '{{{name}}}', must be one of #{allowed_values}."
|
||||
end
|
||||
@{{{name}}} = {{{name}}}
|
||||
|
@ -8,7 +8,7 @@ This SDK is automatically generated by the [Swagger Codegen](https://github.com/
|
||||
|
||||
- API version: 1.0.0
|
||||
- Package version: 1.0.0
|
||||
- Build date: 2016-04-25T19:16:37.992+08:00
|
||||
- Build date: 2016-04-25T21:47:45.004+08:00
|
||||
- Build package: class io.swagger.codegen.languages.RubyClientCodegen
|
||||
|
||||
## Installation
|
||||
|
@ -146,19 +146,19 @@ module Petstore
|
||||
# Check to see if the all the properties in the model are valid
|
||||
# @return true if the model is valid
|
||||
def valid?
|
||||
if integer > 100.0
|
||||
if @integer > 100.0
|
||||
return false
|
||||
end
|
||||
|
||||
if integer < 10.0
|
||||
if @integer < 10.0
|
||||
return false
|
||||
end
|
||||
|
||||
if int32 > 200.0
|
||||
if @int32 > 200.0
|
||||
return false
|
||||
end
|
||||
|
||||
if int32 < 20.0
|
||||
if @int32 < 20.0
|
||||
return false
|
||||
end
|
||||
|
||||
@ -166,27 +166,27 @@ module Petstore
|
||||
return false
|
||||
end
|
||||
|
||||
if number > 543.2
|
||||
if @number > 543.2
|
||||
return false
|
||||
end
|
||||
|
||||
if number < 32.1
|
||||
if @number < 32.1
|
||||
return false
|
||||
end
|
||||
|
||||
if float > 987.6
|
||||
if @float > 987.6
|
||||
return false
|
||||
end
|
||||
|
||||
if float < 54.3
|
||||
if @float < 54.3
|
||||
return false
|
||||
end
|
||||
|
||||
if double > 123.4
|
||||
if @double > 123.4
|
||||
return false
|
||||
end
|
||||
|
||||
if double < 67.8
|
||||
if @double < 67.8
|
||||
return false
|
||||
end
|
||||
|
||||
@ -202,11 +202,11 @@ module Petstore
|
||||
return false
|
||||
end
|
||||
|
||||
if password.to_s.length > 64
|
||||
if @password.to_s.length > 64
|
||||
return false
|
||||
end
|
||||
|
||||
if password.to_s.length < 10
|
||||
if @password.to_s.length < 10
|
||||
return false
|
||||
end
|
||||
|
||||
|
@ -102,7 +102,7 @@ module Petstore
|
||||
# @return true if the model is valid
|
||||
def valid?
|
||||
allowed_values = ["placed", "approved", "delivered"]
|
||||
if status && !allowed_values.include?(status)
|
||||
if @status && !allowed_values.include?(status)
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
@ -112,7 +112,7 @@ module Petstore
|
||||
end
|
||||
|
||||
allowed_values = ["available", "pending", "sold"]
|
||||
if status && !allowed_values.include?(status)
|
||||
if @status && !allowed_values.include?(status)
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user