Skip to content

Commit 0f62433

Browse files
committed
Merge pull request #2954 from wing328/add_test_array
Add new test model to array properties
2 parents fefd507 + 105b4b9 commit 0f62433

File tree

6 files changed

+264
-1
lines changed

6 files changed

+264
-1
lines changed

modules/swagger-codegen/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -971,6 +971,25 @@ definitions:
971971
readOnly: true
972972
baz:
973973
type: string
974+
ArrayTest:
975+
type: object
976+
array_of_string:
977+
type: array
978+
items:
979+
type: string
980+
array_array_of_integer:
981+
type: array
982+
items:
983+
type: array
984+
items:
985+
type: integer
986+
format: int64
987+
array_array_of_model:
988+
type: array
989+
items:
990+
type: array
991+
items:
992+
$ref: '#/definitions/ReadOnlyFirst'
974993
externalDocs:
975994
description: Find out more about Swagger
976995
url: 'http://swagger.io'

samples/client/petstore/ruby/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ This SDK is automatically generated by the [Swagger Codegen](https://github.com/
88

99
- API version: 1.0.0
1010
- Package version: 1.0.0
11-
- Build date: 2016-05-24T23:13:57.542+08:00
11+
- Build date: 2016-05-25T01:17:54.676+08:00
1212
- Build package: class io.swagger.codegen.languages.RubyClientCodegen
1313

1414
## Installation
@@ -120,6 +120,7 @@ Class | Method | HTTP request | Description
120120
- [Petstore::Animal](docs/Animal.md)
121121
- [Petstore::AnimalFarm](docs/AnimalFarm.md)
122122
- [Petstore::ApiResponse](docs/ApiResponse.md)
123+
- [Petstore::ArrayTest](docs/ArrayTest.md)
123124
- [Petstore::Cat](docs/Cat.md)
124125
- [Petstore::Category](docs/Category.md)
125126
- [Petstore::Dog](docs/Dog.md)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Petstore::ArrayTest
2+
3+
## Properties
4+
Name | Type | Description | Notes
5+
------------ | ------------- | ------------- | -------------
6+
7+

samples/client/petstore/ruby/lib/petstore.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
require 'petstore/models/animal'
3333
require 'petstore/models/animal_farm'
3434
require 'petstore/models/api_response'
35+
require 'petstore/models/array_test'
3536
require 'petstore/models/cat'
3637
require 'petstore/models/category'
3738
require 'petstore/models/dog'
Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
=begin
2+
Swagger Petstore
3+
4+
This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
5+
6+
OpenAPI spec version: 1.0.0
7+
Contact: apiteam@swagger.io
8+
Generated by: https://github.com/swagger-api/swagger-codegen.git
9+
10+
Licensed under the Apache License, Version 2.0 (the "License");
11+
you may not use this file except in compliance with the License.
12+
You may obtain a copy of the License at
13+
14+
http://www.apache.org/licenses/LICENSE-2.0
15+
16+
Unless required by applicable law or agreed to in writing, software
17+
distributed under the License is distributed on an "AS IS" BASIS,
18+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19+
See the License for the specific language governing permissions and
20+
limitations under the License.
21+
22+
=end
23+
24+
require 'date'
25+
26+
module Petstore
27+
28+
class ArrayTest
29+
# Attribute mapping from ruby-style variable name to JSON key.
30+
def self.attribute_map
31+
{
32+
}
33+
end
34+
35+
# Attribute type mapping.
36+
def self.swagger_types
37+
{
38+
}
39+
end
40+
41+
# Initializes the object
42+
# @param [Hash] attributes Model attributes in the form of hash
43+
def initialize(attributes = {})
44+
return unless attributes.is_a?(Hash)
45+
46+
# convert string to symbol for hash key
47+
attributes = attributes.each_with_object({}){|(k,v), h| h[k.to_sym] = v}
48+
49+
end
50+
51+
# Show invalid properties with the reasons. Usually used together with valid?
52+
# @return Array for valid properies with the reasons
53+
def list_invalid_properties
54+
invalid_properties = Array.new
55+
return invalid_properties
56+
end
57+
58+
# Check to see if the all the properties in the model are valid
59+
# @return true if the model is valid
60+
def valid?
61+
end
62+
63+
# Checks equality by comparing each attribute.
64+
# @param [Object] Object to be compared
65+
def ==(o)
66+
return true if self.equal?(o)
67+
self.class == o.class
68+
end
69+
70+
# @see the `==` method
71+
# @param [Object] Object to be compared
72+
def eql?(o)
73+
self == o
74+
end
75+
76+
# Calculates hash code according to all attributes.
77+
# @return [Fixnum] Hash code
78+
def hash
79+
[].hash
80+
end
81+
82+
# Builds the object from hash
83+
# @param [Hash] attributes Model attributes in the form of hash
84+
# @return [Object] Returns the model itself
85+
def build_from_hash(attributes)
86+
return nil unless attributes.is_a?(Hash)
87+
self.class.swagger_types.each_pair do |key, type|
88+
if type =~ /^Array<(.*)>/i
89+
# check to ensure the input is an array given that the the attribute
90+
# is documented as an array but the input is not
91+
if attributes[self.class.attribute_map[key]].is_a?(Array)
92+
self.send("#{key}=", attributes[self.class.attribute_map[key]].map{ |v| _deserialize($1, v) } )
93+
end
94+
elsif !attributes[self.class.attribute_map[key]].nil?
95+
self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
96+
end # or else data not found in attributes(hash), not an issue as the data can be optional
97+
end
98+
99+
self
100+
end
101+
102+
# Deserializes the data based on type
103+
# @param string type Data type
104+
# @param string value Value to be deserialized
105+
# @return [Object] Deserialized data
106+
def _deserialize(type, value)
107+
case type.to_sym
108+
when :DateTime
109+
DateTime.parse(value)
110+
when :Date
111+
Date.parse(value)
112+
when :String
113+
value.to_s
114+
when :Integer
115+
value.to_i
116+
when :Float
117+
value.to_f
118+
when :BOOLEAN
119+
if value.to_s =~ /^(true|t|yes|y|1)$/i
120+
true
121+
else
122+
false
123+
end
124+
when :Object
125+
# generic object (usually a Hash), return directly
126+
value
127+
when /\AArray<(?<inner_type>.+)>\z/
128+
inner_type = Regexp.last_match[:inner_type]
129+
value.map { |v| _deserialize(inner_type, v) }
130+
when /\AHash<(?<k_type>.+), (?<v_type>.+)>\z/
131+
k_type = Regexp.last_match[:k_type]
132+
v_type = Regexp.last_match[:v_type]
133+
{}.tap do |hash|
134+
value.each do |k, v|
135+
hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
136+
end
137+
end
138+
else # model
139+
temp_model = Petstore.const_get(type).new
140+
temp_model.build_from_hash(value)
141+
end
142+
end
143+
144+
# Returns the string representation of the object
145+
# @return [String] String presentation of the object
146+
def to_s
147+
to_hash.to_s
148+
end
149+
150+
# to_body is an alias to to_hash (backward compatibility)
151+
# @return [Hash] Returns the object in the form of hash
152+
def to_body
153+
to_hash
154+
end
155+
156+
# Returns the object in the form of hash
157+
# @return [Hash] Returns the object in the form of hash
158+
def to_hash
159+
hash = {}
160+
self.class.attribute_map.each_pair do |attr, param|
161+
value = self.send(attr)
162+
next if value.nil?
163+
hash[param] = _to_hash(value)
164+
end
165+
hash
166+
end
167+
168+
# Outputs non-array value in the form of hash
169+
# For object, use to_hash. Otherwise, just return the value
170+
# @param [Object] value Any valid value
171+
# @return [Hash] Returns the value in the form of hash
172+
def _to_hash(value)
173+
if value.is_a?(Array)
174+
value.compact.map{ |v| _to_hash(v) }
175+
elsif value.is_a?(Hash)
176+
{}.tap do |hash|
177+
value.each { |k, v| hash[k] = _to_hash(v) }
178+
end
179+
elsif value.respond_to? :to_hash
180+
value.to_hash
181+
else
182+
value
183+
end
184+
end
185+
186+
end
187+
188+
end
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
=begin
2+
Swagger Petstore
3+
4+
This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
5+
6+
OpenAPI spec version: 1.0.0
7+
Contact: apiteam@swagger.io
8+
Generated by: https://github.com/swagger-api/swagger-codegen.git
9+
10+
Licensed under the Apache License, Version 2.0 (the "License");
11+
you may not use this file except in compliance with the License.
12+
You may obtain a copy of the License at
13+
14+
http://www.apache.org/licenses/LICENSE-2.0
15+
16+
Unless required by applicable law or agreed to in writing, software
17+
distributed under the License is distributed on an "AS IS" BASIS,
18+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19+
See the License for the specific language governing permissions and
20+
limitations under the License.
21+
22+
=end
23+
24+
require 'spec_helper'
25+
require 'json'
26+
require 'date'
27+
28+
# Unit tests for Petstore::ArrayTest
29+
# Automatically generated by swagger-codegen (github.com/swagger-api/swagger-codegen)
30+
# Please update as you see appropriate
31+
describe 'ArrayTest' do
32+
before do
33+
# run before each test
34+
@instance = Petstore::ArrayTest.new
35+
end
36+
37+
after do
38+
# run after each test
39+
end
40+
41+
describe 'test an instance of ArrayTest' do
42+
it 'should create an instact of ArrayTest' do
43+
expect(@instance).to be_instance_of(Petstore::ArrayTest)
44+
end
45+
end
46+
end
47+

0 commit comments

Comments
 (0)