petstore-test-sdk 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENSE +28 -0
- data/README.md +90 -0
- data/lib/swagger_petstore_open_api30/api_helper.rb +10 -0
- data/lib/swagger_petstore_open_api30/client.rb +72 -0
- data/lib/swagger_petstore_open_api30/configuration.rb +125 -0
- data/lib/swagger_petstore_open_api30/controllers/base_controller.rb +66 -0
- data/lib/swagger_petstore_open_api30/controllers/pet_controller.rb +226 -0
- data/lib/swagger_petstore_open_api30/controllers/store_controller.rb +107 -0
- data/lib/swagger_petstore_open_api30/controllers/user_controller.rb +189 -0
- data/lib/swagger_petstore_open_api30/exceptions/api_exception.rb +10 -0
- data/lib/swagger_petstore_open_api30/http/auth/custom_header_authentication.rb +42 -0
- data/lib/swagger_petstore_open_api30/http/http_call_back.rb +10 -0
- data/lib/swagger_petstore_open_api30/http/http_method_enum.rb +10 -0
- data/lib/swagger_petstore_open_api30/http/http_request.rb +10 -0
- data/lib/swagger_petstore_open_api30/http/http_response.rb +10 -0
- data/lib/swagger_petstore_open_api30/models/address.rb +77 -0
- data/lib/swagger_petstore_open_api30/models/base_model.rb +62 -0
- data/lib/swagger_petstore_open_api30/models/category.rb +59 -0
- data/lib/swagger_petstore_open_api30/models/customer.rb +77 -0
- data/lib/swagger_petstore_open_api30/models/order.rb +105 -0
- data/lib/swagger_petstore_open_api30/models/order_status_enum.rb +26 -0
- data/lib/swagger_petstore_open_api30/models/pet.rb +103 -0
- data/lib/swagger_petstore_open_api30/models/pet_image.rb +68 -0
- data/lib/swagger_petstore_open_api30/models/pet_status_enum.rb +26 -0
- data/lib/swagger_petstore_open_api30/models/status_enum.rb +26 -0
- data/lib/swagger_petstore_open_api30/models/tag.rb +59 -0
- data/lib/swagger_petstore_open_api30/models/user.rb +115 -0
- data/lib/swagger_petstore_open_api30/utilities/date_time_helper.rb +11 -0
- data/lib/swagger_petstore_open_api30/utilities/file_wrapper.rb +16 -0
- data/lib/swagger_petstore_open_api30.rb +53 -0
- data/test/controllers/controller_test_base.rb +29 -0
- data/test/controllers/test_pet_controller.rb +76 -0
- data/test/controllers/test_store_controller.rb +58 -0
- data/test/controllers/test_user_controller.rb +55 -0
- data/test/http_response_catcher.rb +19 -0
- metadata +154 -0
@@ -0,0 +1,107 @@
|
|
1
|
+
# swagger_petstore_open_api30
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0
|
4
|
+
# ( https://apimatic.io ).
|
5
|
+
|
6
|
+
module SwaggerPetstoreOpenApi30
|
7
|
+
# StoreController
|
8
|
+
class StoreController < BaseController
|
9
|
+
# Returns a map of status codes to quantities
|
10
|
+
# @return [Hash[String, Integer]] response from the API call
|
11
|
+
def get_inventory
|
12
|
+
new_api_call_builder
|
13
|
+
.request(new_request_builder(HttpMethodEnum::GET,
|
14
|
+
'/store/inventory',
|
15
|
+
Server::DEFAULT)
|
16
|
+
.auth(Single.new('api_key')))
|
17
|
+
.response(new_response_handler
|
18
|
+
.deserializer(APIHelper.method(:deserialize_primitive_types))
|
19
|
+
.deserialize_into(proc do |response| response.to_i end)
|
20
|
+
.is_primitive_response(true))
|
21
|
+
.execute
|
22
|
+
end
|
23
|
+
|
24
|
+
# Place a new order in the store
|
25
|
+
# @param [Integer] id Optional parameter: Example:
|
26
|
+
# @param [Integer] pet_id Optional parameter: Example:
|
27
|
+
# @param [Integer] quantity Optional parameter: Example:
|
28
|
+
# @param [DateTime] ship_date Optional parameter: Example:
|
29
|
+
# @param [OrderStatusEnum] order_status Optional parameter: Order Status
|
30
|
+
# @param [TrueClass | FalseClass] complete Optional parameter: Example:
|
31
|
+
# @return [Order] response from the API call
|
32
|
+
def place_order(id: nil,
|
33
|
+
pet_id: nil,
|
34
|
+
quantity: nil,
|
35
|
+
ship_date: nil,
|
36
|
+
order_status: OrderStatusEnum::APPROVED,
|
37
|
+
complete: nil)
|
38
|
+
new_api_call_builder
|
39
|
+
.request(new_request_builder(HttpMethodEnum::POST,
|
40
|
+
'/store/order',
|
41
|
+
Server::DEFAULT)
|
42
|
+
.form_param(new_parameter(id, key: 'id'))
|
43
|
+
.form_param(new_parameter(pet_id, key: 'petId'))
|
44
|
+
.form_param(new_parameter(quantity, key: 'quantity'))
|
45
|
+
.form_param(new_parameter(ship_date, key: 'shipDate'))
|
46
|
+
.form_param(new_parameter(order_status, key: 'orderStatus'))
|
47
|
+
.form_param(new_parameter(complete, key: 'complete'))
|
48
|
+
.header_param(new_parameter('application/x-www-form-urlencoded', key: 'content-type'))
|
49
|
+
.header_param(new_parameter('application/json', key: 'accept')))
|
50
|
+
.response(new_response_handler
|
51
|
+
.deserializer(APIHelper.method(:custom_type_deserializer))
|
52
|
+
.deserialize_into(Order.method(:from_hash))
|
53
|
+
.local_error('405',
|
54
|
+
'Invalid input',
|
55
|
+
APIException))
|
56
|
+
.execute
|
57
|
+
end
|
58
|
+
|
59
|
+
# For valid response try integer IDs with value <= 5 or > 10. Other values
|
60
|
+
# will generate exceptions.
|
61
|
+
# @param [Integer] order_id Required parameter: ID of order that needs to be
|
62
|
+
# fetched
|
63
|
+
# @return [Order] response from the API call
|
64
|
+
def get_order_by_id(order_id)
|
65
|
+
new_api_call_builder
|
66
|
+
.request(new_request_builder(HttpMethodEnum::GET,
|
67
|
+
'/store/order/{orderId}',
|
68
|
+
Server::DEFAULT)
|
69
|
+
.template_param(new_parameter(order_id, key: 'orderId')
|
70
|
+
.should_encode(true))
|
71
|
+
.header_param(new_parameter('application/json', key: 'accept')))
|
72
|
+
.response(new_response_handler
|
73
|
+
.deserializer(APIHelper.method(:custom_type_deserializer))
|
74
|
+
.deserialize_into(Order.method(:from_hash))
|
75
|
+
.local_error('400',
|
76
|
+
'Invalid ID supplied',
|
77
|
+
APIException)
|
78
|
+
.local_error('404',
|
79
|
+
'Order not found',
|
80
|
+
APIException))
|
81
|
+
.execute
|
82
|
+
end
|
83
|
+
|
84
|
+
# For valid response try integer IDs with value < 1000. Anything above 1000
|
85
|
+
# or nonintegers will generate API errors
|
86
|
+
# @param [Integer] order_id Required parameter: ID of the order that needs
|
87
|
+
# to be deleted
|
88
|
+
# @return [void] response from the API call
|
89
|
+
def delete_order(order_id)
|
90
|
+
new_api_call_builder
|
91
|
+
.request(new_request_builder(HttpMethodEnum::DELETE,
|
92
|
+
'/store/order/{orderId}',
|
93
|
+
Server::DEFAULT)
|
94
|
+
.template_param(new_parameter(order_id, key: 'orderId')
|
95
|
+
.should_encode(true)))
|
96
|
+
.response(new_response_handler
|
97
|
+
.is_response_void(true)
|
98
|
+
.local_error('400',
|
99
|
+
'Invalid ID supplied',
|
100
|
+
APIException)
|
101
|
+
.local_error('404',
|
102
|
+
'Order not found',
|
103
|
+
APIException))
|
104
|
+
.execute
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
@@ -0,0 +1,189 @@
|
|
1
|
+
# swagger_petstore_open_api30
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0
|
4
|
+
# ( https://apimatic.io ).
|
5
|
+
|
6
|
+
module SwaggerPetstoreOpenApi30
|
7
|
+
# UserController
|
8
|
+
class UserController < BaseController
|
9
|
+
# TODO: type endpoint description here
|
10
|
+
# @return [void] response from the API call
|
11
|
+
def logout_user
|
12
|
+
new_api_call_builder
|
13
|
+
.request(new_request_builder(HttpMethodEnum::GET,
|
14
|
+
'/user/logout',
|
15
|
+
Server::DEFAULT))
|
16
|
+
.response(new_response_handler
|
17
|
+
.is_response_void(true))
|
18
|
+
.execute
|
19
|
+
end
|
20
|
+
|
21
|
+
# Creates list of users with given input array
|
22
|
+
# @param [Array[User]] body Optional parameter: Example:
|
23
|
+
# @return [User] response from the API call
|
24
|
+
def create_users_with_list_input(body: nil)
|
25
|
+
new_api_call_builder
|
26
|
+
.request(new_request_builder(HttpMethodEnum::POST,
|
27
|
+
'/user/createWithList',
|
28
|
+
Server::DEFAULT)
|
29
|
+
.header_param(new_parameter('application/json', key: 'Content-Type'))
|
30
|
+
.body_param(new_parameter(body))
|
31
|
+
.header_param(new_parameter('application/json', key: 'accept'))
|
32
|
+
.body_serializer(proc do |param| param.to_json unless param.nil? end))
|
33
|
+
.response(new_response_handler
|
34
|
+
.deserializer(APIHelper.method(:custom_type_deserializer))
|
35
|
+
.deserialize_into(User.method(:from_hash))
|
36
|
+
.local_error('default',
|
37
|
+
'successful operation',
|
38
|
+
APIException))
|
39
|
+
.execute
|
40
|
+
end
|
41
|
+
|
42
|
+
# This can only be done by the logged in user.
|
43
|
+
# @param [Integer] id Optional parameter: Example:
|
44
|
+
# @param [String] username Optional parameter: Example:
|
45
|
+
# @param [String] first_name Optional parameter: Example:
|
46
|
+
# @param [String] last_name Optional parameter: Example:
|
47
|
+
# @param [String] email Optional parameter: Example:
|
48
|
+
# @param [String] password Optional parameter: Example:
|
49
|
+
# @param [String] phone Optional parameter: Example:
|
50
|
+
# @param [Integer] user_status Optional parameter: User Status
|
51
|
+
# @return [User] response from the API call
|
52
|
+
def create_user(id: nil,
|
53
|
+
username: nil,
|
54
|
+
first_name: nil,
|
55
|
+
last_name: nil,
|
56
|
+
email: nil,
|
57
|
+
password: nil,
|
58
|
+
phone: nil,
|
59
|
+
user_status: nil)
|
60
|
+
new_api_call_builder
|
61
|
+
.request(new_request_builder(HttpMethodEnum::POST,
|
62
|
+
'/user',
|
63
|
+
Server::DEFAULT)
|
64
|
+
.form_param(new_parameter(id, key: 'id'))
|
65
|
+
.form_param(new_parameter(username, key: 'username'))
|
66
|
+
.form_param(new_parameter(first_name, key: 'firstName'))
|
67
|
+
.form_param(new_parameter(last_name, key: 'lastName'))
|
68
|
+
.form_param(new_parameter(email, key: 'email'))
|
69
|
+
.form_param(new_parameter(password, key: 'password'))
|
70
|
+
.form_param(new_parameter(phone, key: 'phone'))
|
71
|
+
.form_param(new_parameter(user_status, key: 'userStatus'))
|
72
|
+
.header_param(new_parameter('application/x-www-form-urlencoded', key: 'content-type'))
|
73
|
+
.header_param(new_parameter('application/json', key: 'accept')))
|
74
|
+
.response(new_response_handler
|
75
|
+
.deserializer(APIHelper.method(:custom_type_deserializer))
|
76
|
+
.deserialize_into(User.method(:from_hash)))
|
77
|
+
.execute
|
78
|
+
end
|
79
|
+
|
80
|
+
# TODO: type endpoint description here
|
81
|
+
# @param [String] username Optional parameter: The user name for login
|
82
|
+
# @param [String] password Optional parameter: The password for login in
|
83
|
+
# clear text
|
84
|
+
# @return [String] response from the API call
|
85
|
+
def login_user(username: nil,
|
86
|
+
password: nil)
|
87
|
+
new_api_call_builder
|
88
|
+
.request(new_request_builder(HttpMethodEnum::GET,
|
89
|
+
'/user/login',
|
90
|
+
Server::DEFAULT)
|
91
|
+
.query_param(new_parameter(username, key: 'username'))
|
92
|
+
.query_param(new_parameter(password, key: 'password')))
|
93
|
+
.response(new_response_handler
|
94
|
+
.deserializer(APIHelper.method(:deserialize_primitive_types))
|
95
|
+
.deserialize_into(proc do |response| response.to_s end)
|
96
|
+
.is_primitive_response(true)
|
97
|
+
.local_error('400',
|
98
|
+
'Invalid username/password supplied',
|
99
|
+
APIException))
|
100
|
+
.execute
|
101
|
+
end
|
102
|
+
|
103
|
+
# TODO: type endpoint description here
|
104
|
+
# @param [String] name Required parameter: The name that needs to be
|
105
|
+
# fetched. Use user1 for testing.
|
106
|
+
# @return [User] response from the API call
|
107
|
+
def get_user_by_name(name)
|
108
|
+
new_api_call_builder
|
109
|
+
.request(new_request_builder(HttpMethodEnum::GET,
|
110
|
+
'/user/{name}',
|
111
|
+
Server::DEFAULT)
|
112
|
+
.template_param(new_parameter(name, key: 'name')
|
113
|
+
.should_encode(true))
|
114
|
+
.header_param(new_parameter('application/json', key: 'accept')))
|
115
|
+
.response(new_response_handler
|
116
|
+
.deserializer(APIHelper.method(:custom_type_deserializer))
|
117
|
+
.deserialize_into(User.method(:from_hash))
|
118
|
+
.local_error('400',
|
119
|
+
'Invalid username supplied',
|
120
|
+
APIException)
|
121
|
+
.local_error('404',
|
122
|
+
'User not found',
|
123
|
+
APIException))
|
124
|
+
.execute
|
125
|
+
end
|
126
|
+
|
127
|
+
# This can only be done by the logged in user.
|
128
|
+
# @param [String] name Required parameter: name that need to be deleted
|
129
|
+
# @param [Integer] id Optional parameter: Example:
|
130
|
+
# @param [String] username Optional parameter: Example:
|
131
|
+
# @param [String] first_name Optional parameter: Example:
|
132
|
+
# @param [String] last_name Optional parameter: Example:
|
133
|
+
# @param [String] email Optional parameter: Example:
|
134
|
+
# @param [String] password Optional parameter: Example:
|
135
|
+
# @param [String] phone Optional parameter: Example:
|
136
|
+
# @param [Integer] user_status Optional parameter: User Status
|
137
|
+
# @return [void] response from the API call
|
138
|
+
def update_user(name,
|
139
|
+
id: nil,
|
140
|
+
username: nil,
|
141
|
+
first_name: nil,
|
142
|
+
last_name: nil,
|
143
|
+
email: nil,
|
144
|
+
password: nil,
|
145
|
+
phone: nil,
|
146
|
+
user_status: nil)
|
147
|
+
new_api_call_builder
|
148
|
+
.request(new_request_builder(HttpMethodEnum::PUT,
|
149
|
+
'/user/{name}',
|
150
|
+
Server::DEFAULT)
|
151
|
+
.template_param(new_parameter(name, key: 'name')
|
152
|
+
.should_encode(true))
|
153
|
+
.form_param(new_parameter(id, key: 'id'))
|
154
|
+
.form_param(new_parameter(username, key: 'username'))
|
155
|
+
.form_param(new_parameter(first_name, key: 'firstName'))
|
156
|
+
.form_param(new_parameter(last_name, key: 'lastName'))
|
157
|
+
.form_param(new_parameter(email, key: 'email'))
|
158
|
+
.form_param(new_parameter(password, key: 'password'))
|
159
|
+
.form_param(new_parameter(phone, key: 'phone'))
|
160
|
+
.form_param(new_parameter(user_status, key: 'userStatus'))
|
161
|
+
.header_param(new_parameter('application/x-www-form-urlencoded', key: 'content-type')))
|
162
|
+
.response(new_response_handler
|
163
|
+
.is_response_void(true))
|
164
|
+
.execute
|
165
|
+
end
|
166
|
+
|
167
|
+
# This can only be done by the logged in user.
|
168
|
+
# @param [String] name Required parameter: The name that needs to be
|
169
|
+
# deleted
|
170
|
+
# @return [void] response from the API call
|
171
|
+
def delete_user(name)
|
172
|
+
new_api_call_builder
|
173
|
+
.request(new_request_builder(HttpMethodEnum::DELETE,
|
174
|
+
'/user/{name}',
|
175
|
+
Server::DEFAULT)
|
176
|
+
.template_param(new_parameter(name, key: 'name')
|
177
|
+
.should_encode(true)))
|
178
|
+
.response(new_response_handler
|
179
|
+
.is_response_void(true)
|
180
|
+
.local_error('400',
|
181
|
+
'Invalid username supplied',
|
182
|
+
APIException)
|
183
|
+
.local_error('404',
|
184
|
+
'User not found',
|
185
|
+
APIException))
|
186
|
+
.execute
|
187
|
+
end
|
188
|
+
end
|
189
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# swagger_petstore_open_api30
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0
|
4
|
+
# ( https://apimatic.io ).
|
5
|
+
|
6
|
+
module SwaggerPetstoreOpenApi30
|
7
|
+
# Class for exceptions when there is a network error, status code error, etc.
|
8
|
+
class APIException < CoreLibrary::ApiException
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# swagger_petstore_open_api30
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0
|
4
|
+
# ( https://apimatic.io ).
|
5
|
+
|
6
|
+
module SwaggerPetstoreOpenApi30
|
7
|
+
# Utility class for custom header authorization.
|
8
|
+
class CustomHeaderAuthentication < CoreLibrary::HeaderAuth
|
9
|
+
# Display error message on occurrence of authentication failure.
|
10
|
+
# @returns [String] The oAuth error message.
|
11
|
+
def error_message
|
12
|
+
'CustomHeaderAuthentication: api_key is undefined.'
|
13
|
+
end
|
14
|
+
|
15
|
+
# Initialization constructor.
|
16
|
+
def initialize(custom_header_authentication_credentials)
|
17
|
+
auth_params = {}
|
18
|
+
auth_params['api_key'] = custom_header_authentication_credentials.api_key unless
|
19
|
+
custom_header_authentication_credentials.nil? || custom_header_authentication_credentials.api_key.nil?
|
20
|
+
|
21
|
+
super auth_params
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
# Data class for CustomHeaderAuthenticationCredentials.
|
26
|
+
# Data class for CustomHeaderAuthenticationCredentials.
|
27
|
+
class CustomHeaderAuthenticationCredentials
|
28
|
+
attr_reader :api_key
|
29
|
+
|
30
|
+
def initialize(api_key:)
|
31
|
+
raise ArgumentError, 'api_key cannot be nil' if api_key.nil?
|
32
|
+
|
33
|
+
@api_key = api_key
|
34
|
+
end
|
35
|
+
|
36
|
+
def clone_with(api_key: nil)
|
37
|
+
api_key ||= self.api_key
|
38
|
+
|
39
|
+
CustomHeaderAuthenticationCredentials.new(api_key: api_key)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# swagger_petstore_open_api30
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0
|
4
|
+
# ( https://apimatic.io ).
|
5
|
+
|
6
|
+
module SwaggerPetstoreOpenApi30
|
7
|
+
# HttpCallBack allows defining callables for pre and post API calls.
|
8
|
+
class HttpCallBack < CoreLibrary::HttpCallback
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
# swagger_petstore_open_api30
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0
|
4
|
+
# ( https://apimatic.io ).
|
5
|
+
|
6
|
+
module SwaggerPetstoreOpenApi30
|
7
|
+
# Address Model.
|
8
|
+
class Address < BaseModel
|
9
|
+
SKIP = Object.new
|
10
|
+
private_constant :SKIP
|
11
|
+
|
12
|
+
# TODO: Write general description for this method
|
13
|
+
# @return [String]
|
14
|
+
attr_accessor :street
|
15
|
+
|
16
|
+
# TODO: Write general description for this method
|
17
|
+
# @return [String]
|
18
|
+
attr_accessor :city
|
19
|
+
|
20
|
+
# TODO: Write general description for this method
|
21
|
+
# @return [String]
|
22
|
+
attr_accessor :state
|
23
|
+
|
24
|
+
# TODO: Write general description for this method
|
25
|
+
# @return [String]
|
26
|
+
attr_accessor :zip
|
27
|
+
|
28
|
+
# A mapping from model property names to API property names.
|
29
|
+
def self.names
|
30
|
+
@_hash = {} if @_hash.nil?
|
31
|
+
@_hash['street'] = 'street'
|
32
|
+
@_hash['city'] = 'city'
|
33
|
+
@_hash['state'] = 'state'
|
34
|
+
@_hash['zip'] = 'zip'
|
35
|
+
@_hash
|
36
|
+
end
|
37
|
+
|
38
|
+
# An array for optional fields
|
39
|
+
def self.optionals
|
40
|
+
%w[
|
41
|
+
street
|
42
|
+
city
|
43
|
+
state
|
44
|
+
zip
|
45
|
+
]
|
46
|
+
end
|
47
|
+
|
48
|
+
# An array for nullable fields
|
49
|
+
def self.nullables
|
50
|
+
[]
|
51
|
+
end
|
52
|
+
|
53
|
+
def initialize(street = SKIP, city = SKIP, state = SKIP, zip = SKIP)
|
54
|
+
@street = street unless street == SKIP
|
55
|
+
@city = city unless city == SKIP
|
56
|
+
@state = state unless state == SKIP
|
57
|
+
@zip = zip unless zip == SKIP
|
58
|
+
end
|
59
|
+
|
60
|
+
# Creates an instance of the object from a hash.
|
61
|
+
def self.from_hash(hash)
|
62
|
+
return nil unless hash
|
63
|
+
|
64
|
+
# Extract variables from the hash.
|
65
|
+
street = hash.key?('street') ? hash['street'] : SKIP
|
66
|
+
city = hash.key?('city') ? hash['city'] : SKIP
|
67
|
+
state = hash.key?('state') ? hash['state'] : SKIP
|
68
|
+
zip = hash.key?('zip') ? hash['zip'] : SKIP
|
69
|
+
|
70
|
+
# Create object from extracted values.
|
71
|
+
Address.new(street,
|
72
|
+
city,
|
73
|
+
state,
|
74
|
+
zip)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# swagger_petstore_open_api30
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0
|
4
|
+
# ( https://apimatic.io ).
|
5
|
+
|
6
|
+
module SwaggerPetstoreOpenApi30
|
7
|
+
# Base model.
|
8
|
+
class BaseModel < CoreLibrary::BaseModel
|
9
|
+
# Returns a Hash representation of the current object.
|
10
|
+
def to_hash
|
11
|
+
# validating the model being serialized
|
12
|
+
self.class.validate(self) if self.class.respond_to?(:validate)
|
13
|
+
|
14
|
+
hash = {}
|
15
|
+
instance_variables.each do |name|
|
16
|
+
value = instance_variable_get(name)
|
17
|
+
name = name[1..]
|
18
|
+
key = self.class.names.key?(name) ? self.class.names[name] : name
|
19
|
+
optional_fields = self.class.optionals
|
20
|
+
nullable_fields = self.class.nullables
|
21
|
+
if value.nil?
|
22
|
+
next unless nullable_fields.include?(name)
|
23
|
+
|
24
|
+
if !optional_fields.include?(name) && !nullable_fields.include?(name)
|
25
|
+
raise ArgumentError,
|
26
|
+
"`#{name}` cannot be nil in `#{self.class}`. Please specify a valid value."
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
hash[key] = nil
|
31
|
+
unless value.nil?
|
32
|
+
if respond_to?("to_custom_#{name}")
|
33
|
+
if (value.instance_of? Array) || (value.instance_of? Hash)
|
34
|
+
params = [hash, key]
|
35
|
+
hash[key] = send("to_custom_#{name}", *params)
|
36
|
+
else
|
37
|
+
hash[key] = send("to_custom_#{name}")
|
38
|
+
end
|
39
|
+
elsif respond_to?("to_union_type_#{name}")
|
40
|
+
hash[key] = send("to_union_type_#{name}")
|
41
|
+
elsif value.instance_of? Array
|
42
|
+
hash[key] = value.map { |v| v.is_a?(BaseModel) ? v.to_hash : v }
|
43
|
+
elsif value.instance_of? Hash
|
44
|
+
hash[key] = {}
|
45
|
+
value.each do |k, v|
|
46
|
+
hash[key][k] = v.is_a?(BaseModel) ? v.to_hash : v
|
47
|
+
end
|
48
|
+
else
|
49
|
+
hash[key] = value.is_a?(BaseModel) ? value.to_hash : value
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
hash
|
54
|
+
end
|
55
|
+
|
56
|
+
# Returns a JSON representation of the curent object.
|
57
|
+
def to_json(options = {})
|
58
|
+
hash = to_hash
|
59
|
+
hash.to_json(options)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# swagger_petstore_open_api30
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0
|
4
|
+
# ( https://apimatic.io ).
|
5
|
+
|
6
|
+
module SwaggerPetstoreOpenApi30
|
7
|
+
# Category Model.
|
8
|
+
class Category < BaseModel
|
9
|
+
SKIP = Object.new
|
10
|
+
private_constant :SKIP
|
11
|
+
|
12
|
+
# TODO: Write general description for this method
|
13
|
+
# @return [Integer]
|
14
|
+
attr_accessor :id
|
15
|
+
|
16
|
+
# TODO: Write general description for this method
|
17
|
+
# @return [String]
|
18
|
+
attr_accessor :name
|
19
|
+
|
20
|
+
# A mapping from model property names to API property names.
|
21
|
+
def self.names
|
22
|
+
@_hash = {} if @_hash.nil?
|
23
|
+
@_hash['id'] = 'id'
|
24
|
+
@_hash['name'] = 'name'
|
25
|
+
@_hash
|
26
|
+
end
|
27
|
+
|
28
|
+
# An array for optional fields
|
29
|
+
def self.optionals
|
30
|
+
%w[
|
31
|
+
id
|
32
|
+
name
|
33
|
+
]
|
34
|
+
end
|
35
|
+
|
36
|
+
# An array for nullable fields
|
37
|
+
def self.nullables
|
38
|
+
[]
|
39
|
+
end
|
40
|
+
|
41
|
+
def initialize(id = SKIP, name = SKIP)
|
42
|
+
@id = id unless id == SKIP
|
43
|
+
@name = name unless name == SKIP
|
44
|
+
end
|
45
|
+
|
46
|
+
# Creates an instance of the object from a hash.
|
47
|
+
def self.from_hash(hash)
|
48
|
+
return nil unless hash
|
49
|
+
|
50
|
+
# Extract variables from the hash.
|
51
|
+
id = hash.key?('id') ? hash['id'] : SKIP
|
52
|
+
name = hash.key?('name') ? hash['name'] : SKIP
|
53
|
+
|
54
|
+
# Create object from extracted values.
|
55
|
+
Category.new(id,
|
56
|
+
name)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
# swagger_petstore_open_api30
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0
|
4
|
+
# ( https://apimatic.io ).
|
5
|
+
|
6
|
+
module SwaggerPetstoreOpenApi30
|
7
|
+
# Customer Model.
|
8
|
+
class Customer < BaseModel
|
9
|
+
SKIP = Object.new
|
10
|
+
private_constant :SKIP
|
11
|
+
|
12
|
+
# TODO: Write general description for this method
|
13
|
+
# @return [Integer]
|
14
|
+
attr_accessor :id
|
15
|
+
|
16
|
+
# TODO: Write general description for this method
|
17
|
+
# @return [String]
|
18
|
+
attr_accessor :username
|
19
|
+
|
20
|
+
# TODO: Write general description for this method
|
21
|
+
# @return [Array[Address]]
|
22
|
+
attr_accessor :address
|
23
|
+
|
24
|
+
# A mapping from model property names to API property names.
|
25
|
+
def self.names
|
26
|
+
@_hash = {} if @_hash.nil?
|
27
|
+
@_hash['id'] = 'id'
|
28
|
+
@_hash['username'] = 'username'
|
29
|
+
@_hash['address'] = 'address'
|
30
|
+
@_hash
|
31
|
+
end
|
32
|
+
|
33
|
+
# An array for optional fields
|
34
|
+
def self.optionals
|
35
|
+
%w[
|
36
|
+
id
|
37
|
+
username
|
38
|
+
address
|
39
|
+
]
|
40
|
+
end
|
41
|
+
|
42
|
+
# An array for nullable fields
|
43
|
+
def self.nullables
|
44
|
+
[]
|
45
|
+
end
|
46
|
+
|
47
|
+
def initialize(id = SKIP, username = SKIP, address = SKIP)
|
48
|
+
@id = id unless id == SKIP
|
49
|
+
@username = username unless username == SKIP
|
50
|
+
@address = address unless address == SKIP
|
51
|
+
end
|
52
|
+
|
53
|
+
# Creates an instance of the object from a hash.
|
54
|
+
def self.from_hash(hash)
|
55
|
+
return nil unless hash
|
56
|
+
|
57
|
+
# Extract variables from the hash.
|
58
|
+
id = hash.key?('id') ? hash['id'] : SKIP
|
59
|
+
username = hash.key?('username') ? hash['username'] : SKIP
|
60
|
+
# Parameter is an array, so we need to iterate through it
|
61
|
+
address = nil
|
62
|
+
unless hash['address'].nil?
|
63
|
+
address = []
|
64
|
+
hash['address'].each do |structure|
|
65
|
+
address << (Address.from_hash(structure) if structure)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
address = SKIP unless hash.key?('address')
|
70
|
+
|
71
|
+
# Create object from extracted values.
|
72
|
+
Customer.new(id,
|
73
|
+
username,
|
74
|
+
address)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|