forked from loafle/openapi-generator-original
Validate model property against allowed values (enum)
when present with attribute setters
This commit is contained in:
parent
fafddbf040
commit
108b2241c0
@ -29,11 +29,20 @@ module {{moduleName}}
|
||||
{{#vars}}
|
||||
if attributes[:'{{{baseName}}}']
|
||||
{{#isContainer}}if (value = attributes[:'{{{baseName}}}']).is_a?(Array)
|
||||
@{{{name}}} = value
|
||||
end{{/isContainer}}{{^isContainer}}@{{{name}}} = attributes[:'{{{baseName}}}']{{/isContainer}}
|
||||
self.{{{name}}} = value
|
||||
end{{/isContainer}}{{^isContainer}}self.{{{name}}} = attributes[:'{{{baseName}}}']{{/isContainer}}
|
||||
end
|
||||
{{/vars}}
|
||||
end
|
||||
{{#vars}}{{#isEnum}}
|
||||
def {{{name}}}=({{{name}}})
|
||||
allowed_values = [{{#allowableValues}}{{#values}}"{{{this}}}"{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}}]
|
||||
if {{{name}}} && !allowed_values.include?({{{name}}})
|
||||
fail "invalid value for '{{{name}}}', must be one of #{allowed_values}"
|
||||
end
|
||||
@{{{name}}} = {{{name}}}
|
||||
end
|
||||
{{/isEnum}}{{/vars}}
|
||||
end
|
||||
{{/model}}
|
||||
{{/models}}
|
||||
|
@ -32,13 +32,14 @@ module Petstore
|
||||
|
||||
|
||||
if attributes[:'id']
|
||||
@id = attributes[:'id']
|
||||
self.id = attributes[:'id']
|
||||
end
|
||||
|
||||
if attributes[:'name']
|
||||
@name = attributes[:'name']
|
||||
self.name = attributes[:'name']
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
@ -48,29 +48,38 @@ module Petstore
|
||||
|
||||
|
||||
if attributes[:'id']
|
||||
@id = attributes[:'id']
|
||||
self.id = attributes[:'id']
|
||||
end
|
||||
|
||||
if attributes[:'petId']
|
||||
@pet_id = attributes[:'petId']
|
||||
self.pet_id = attributes[:'petId']
|
||||
end
|
||||
|
||||
if attributes[:'quantity']
|
||||
@quantity = attributes[:'quantity']
|
||||
self.quantity = attributes[:'quantity']
|
||||
end
|
||||
|
||||
if attributes[:'shipDate']
|
||||
@ship_date = attributes[:'shipDate']
|
||||
self.ship_date = attributes[:'shipDate']
|
||||
end
|
||||
|
||||
if attributes[:'status']
|
||||
@status = attributes[:'status']
|
||||
self.status = attributes[:'status']
|
||||
end
|
||||
|
||||
if attributes[:'complete']
|
||||
@complete = attributes[:'complete']
|
||||
self.complete = attributes[:'complete']
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
def status=(status)
|
||||
allowed_values = ["placed", "approved", "delivered"]
|
||||
if status && !allowed_values.include?(status)
|
||||
fail "invalid value for 'status', must be one of #{allowed_values}"
|
||||
end
|
||||
@status = status
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
@ -48,33 +48,42 @@ module Petstore
|
||||
|
||||
|
||||
if attributes[:'id']
|
||||
@id = attributes[:'id']
|
||||
self.id = attributes[:'id']
|
||||
end
|
||||
|
||||
if attributes[:'category']
|
||||
@category = attributes[:'category']
|
||||
self.category = attributes[:'category']
|
||||
end
|
||||
|
||||
if attributes[:'name']
|
||||
@name = attributes[:'name']
|
||||
self.name = attributes[:'name']
|
||||
end
|
||||
|
||||
if attributes[:'photoUrls']
|
||||
if (value = attributes[:'photoUrls']).is_a?(Array)
|
||||
@photo_urls = value
|
||||
self.photo_urls = value
|
||||
end
|
||||
end
|
||||
|
||||
if attributes[:'tags']
|
||||
if (value = attributes[:'tags']).is_a?(Array)
|
||||
@tags = value
|
||||
self.tags = value
|
||||
end
|
||||
end
|
||||
|
||||
if attributes[:'status']
|
||||
@status = attributes[:'status']
|
||||
self.status = attributes[:'status']
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
def status=(status)
|
||||
allowed_values = ["available", "pending", "sold"]
|
||||
if status && !allowed_values.include?(status)
|
||||
fail "invalid value for 'status', must be one of #{allowed_values}"
|
||||
end
|
||||
@status = status
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
@ -32,13 +32,14 @@ module Petstore
|
||||
|
||||
|
||||
if attributes[:'id']
|
||||
@id = attributes[:'id']
|
||||
self.id = attributes[:'id']
|
||||
end
|
||||
|
||||
if attributes[:'name']
|
||||
@name = attributes[:'name']
|
||||
self.name = attributes[:'name']
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
@ -56,37 +56,38 @@ module Petstore
|
||||
|
||||
|
||||
if attributes[:'id']
|
||||
@id = attributes[:'id']
|
||||
self.id = attributes[:'id']
|
||||
end
|
||||
|
||||
if attributes[:'username']
|
||||
@username = attributes[:'username']
|
||||
self.username = attributes[:'username']
|
||||
end
|
||||
|
||||
if attributes[:'firstName']
|
||||
@first_name = attributes[:'firstName']
|
||||
self.first_name = attributes[:'firstName']
|
||||
end
|
||||
|
||||
if attributes[:'lastName']
|
||||
@last_name = attributes[:'lastName']
|
||||
self.last_name = attributes[:'lastName']
|
||||
end
|
||||
|
||||
if attributes[:'email']
|
||||
@email = attributes[:'email']
|
||||
self.email = attributes[:'email']
|
||||
end
|
||||
|
||||
if attributes[:'password']
|
||||
@password = attributes[:'password']
|
||||
self.password = attributes[:'password']
|
||||
end
|
||||
|
||||
if attributes[:'phone']
|
||||
@phone = attributes[:'phone']
|
||||
self.phone = attributes[:'phone']
|
||||
end
|
||||
|
||||
if attributes[:'userStatus']
|
||||
@user_status = attributes[:'userStatus']
|
||||
self.user_status = attributes[:'userStatus']
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user