petstore-pets 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 +96 -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 +21 -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 +90 -0
- data/lib/swagger_petstore_open_api30/models/base_model.rb +110 -0
- data/lib/swagger_petstore_open_api30/models/category.rb +71 -0
- data/lib/swagger_petstore_open_api30/models/customer.rb +90 -0
- data/lib/swagger_petstore_open_api30/models/order.rb +120 -0
- data/lib/swagger_petstore_open_api30/models/order_status_enum.rb +26 -0
- data/lib/swagger_petstore_open_api30/models/pet.rb +118 -0
- data/lib/swagger_petstore_open_api30/models/pet_image.rb +81 -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 +71 -0
- data/lib/swagger_petstore_open_api30/models/user.rb +132 -0
- data/lib/swagger_petstore_open_api30/utilities/date_time_helper.rb +11 -0
- data/lib/swagger_petstore_open_api30/utilities/file_wrapper.rb +28 -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 +50 -0
- data/test/controllers/test_store_controller.rb +56 -0
- data/test/controllers/test_user_controller.rb +53 -0
- data/test/http_response_catcher.rb +19 -0
- metadata +147 -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
|
+
# Place a new order in the store
|
10
|
+
# @param [Integer] id Optional parameter: Example:
|
11
|
+
# @param [Integer] pet_id Optional parameter: Example:
|
12
|
+
# @param [Integer] quantity Optional parameter: Example:
|
13
|
+
# @param [DateTime] ship_date Optional parameter: Example:
|
14
|
+
# @param [OrderStatusEnum] order_status Optional parameter: Order Status
|
15
|
+
# @param [TrueClass | FalseClass] complete Optional parameter: Example:
|
16
|
+
# @return [Order] response from the API call.
|
17
|
+
def place_order(id: nil,
|
18
|
+
pet_id: nil,
|
19
|
+
quantity: nil,
|
20
|
+
ship_date: nil,
|
21
|
+
order_status: OrderStatusEnum::APPROVED,
|
22
|
+
complete: nil)
|
23
|
+
new_api_call_builder
|
24
|
+
.request(new_request_builder(HttpMethodEnum::POST,
|
25
|
+
'/store/order',
|
26
|
+
Server::DEFAULT)
|
27
|
+
.form_param(new_parameter(id, key: 'id'))
|
28
|
+
.form_param(new_parameter(pet_id, key: 'petId'))
|
29
|
+
.form_param(new_parameter(quantity, key: 'quantity'))
|
30
|
+
.form_param(new_parameter(ship_date, key: 'shipDate'))
|
31
|
+
.form_param(new_parameter(order_status, key: 'orderStatus'))
|
32
|
+
.form_param(new_parameter(complete, key: 'complete'))
|
33
|
+
.header_param(new_parameter('application/x-www-form-urlencoded', key: 'content-type'))
|
34
|
+
.header_param(new_parameter('application/json', key: 'accept')))
|
35
|
+
.response(new_response_handler
|
36
|
+
.deserializer(APIHelper.method(:custom_type_deserializer))
|
37
|
+
.deserialize_into(Order.method(:from_hash))
|
38
|
+
.local_error('405',
|
39
|
+
'Invalid input',
|
40
|
+
APIException))
|
41
|
+
.execute
|
42
|
+
end
|
43
|
+
|
44
|
+
# For valid response try integer IDs with value <= 5 or > 10. Other values
|
45
|
+
# will generate exceptions.
|
46
|
+
# @param [Integer] order_id Required parameter: ID of order that needs to be
|
47
|
+
# fetched
|
48
|
+
# @return [Order] response from the API call.
|
49
|
+
def get_order_by_id(order_id)
|
50
|
+
new_api_call_builder
|
51
|
+
.request(new_request_builder(HttpMethodEnum::GET,
|
52
|
+
'/store/order/{orderId}',
|
53
|
+
Server::DEFAULT)
|
54
|
+
.template_param(new_parameter(order_id, key: 'orderId')
|
55
|
+
.should_encode(true))
|
56
|
+
.header_param(new_parameter('application/json', key: 'accept')))
|
57
|
+
.response(new_response_handler
|
58
|
+
.deserializer(APIHelper.method(:custom_type_deserializer))
|
59
|
+
.deserialize_into(Order.method(:from_hash))
|
60
|
+
.local_error('400',
|
61
|
+
'Invalid ID supplied',
|
62
|
+
APIException)
|
63
|
+
.local_error('404',
|
64
|
+
'Order not found',
|
65
|
+
APIException))
|
66
|
+
.execute
|
67
|
+
end
|
68
|
+
|
69
|
+
# For valid response try integer IDs with value < 1000. Anything above 1000
|
70
|
+
# or nonintegers will generate API errors
|
71
|
+
# @param [Integer] order_id Required parameter: ID of the order that needs
|
72
|
+
# to be deleted
|
73
|
+
# @return [void] response from the API call.
|
74
|
+
def delete_order(order_id)
|
75
|
+
new_api_call_builder
|
76
|
+
.request(new_request_builder(HttpMethodEnum::DELETE,
|
77
|
+
'/store/order/{orderId}',
|
78
|
+
Server::DEFAULT)
|
79
|
+
.template_param(new_parameter(order_id, key: 'orderId')
|
80
|
+
.should_encode(true)))
|
81
|
+
.response(new_response_handler
|
82
|
+
.is_response_void(true)
|
83
|
+
.local_error('400',
|
84
|
+
'Invalid ID supplied',
|
85
|
+
APIException)
|
86
|
+
.local_error('404',
|
87
|
+
'Order not found',
|
88
|
+
APIException))
|
89
|
+
.execute
|
90
|
+
end
|
91
|
+
|
92
|
+
# Returns a map of status codes to quantities
|
93
|
+
# @return [Hash[String, Integer]] response from the API call.
|
94
|
+
def get_inventory
|
95
|
+
new_api_call_builder
|
96
|
+
.request(new_request_builder(HttpMethodEnum::GET,
|
97
|
+
'/store/inventory',
|
98
|
+
Server::DEFAULT)
|
99
|
+
.auth(Single.new('api_key')))
|
100
|
+
.response(new_response_handler
|
101
|
+
.deserializer(APIHelper.method(:deserialize_primitive_types))
|
102
|
+
.deserialize_into(proc do |response| response.to_i end)
|
103
|
+
.is_primitive_response(true))
|
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
|
+
# Creates list of users with given input array
|
10
|
+
# @param [Array[User]] body Optional parameter: Example:
|
11
|
+
# @return [User] response from the API call.
|
12
|
+
def create_users_with_list_input(body: nil)
|
13
|
+
new_api_call_builder
|
14
|
+
.request(new_request_builder(HttpMethodEnum::POST,
|
15
|
+
'/user/createWithList',
|
16
|
+
Server::DEFAULT)
|
17
|
+
.header_param(new_parameter('application/json', key: 'Content-Type'))
|
18
|
+
.body_param(new_parameter(body))
|
19
|
+
.header_param(new_parameter('application/json', key: 'accept'))
|
20
|
+
.body_serializer(proc do |param| param.to_json unless param.nil? end))
|
21
|
+
.response(new_response_handler
|
22
|
+
.deserializer(APIHelper.method(:custom_type_deserializer))
|
23
|
+
.deserialize_into(User.method(:from_hash))
|
24
|
+
.local_error('default',
|
25
|
+
'successful operation',
|
26
|
+
APIException))
|
27
|
+
.execute
|
28
|
+
end
|
29
|
+
|
30
|
+
# TODO: type endpoint description here
|
31
|
+
# @param [String] username Optional parameter: The user name for login
|
32
|
+
# @param [String] password Optional parameter: The password for login in
|
33
|
+
# clear text
|
34
|
+
# @return [String] response from the API call.
|
35
|
+
def login_user(username: nil,
|
36
|
+
password: nil)
|
37
|
+
new_api_call_builder
|
38
|
+
.request(new_request_builder(HttpMethodEnum::GET,
|
39
|
+
'/user/login',
|
40
|
+
Server::DEFAULT)
|
41
|
+
.query_param(new_parameter(username, key: 'username'))
|
42
|
+
.query_param(new_parameter(password, key: 'password')))
|
43
|
+
.response(new_response_handler
|
44
|
+
.deserializer(APIHelper.method(:deserialize_primitive_types))
|
45
|
+
.deserialize_into(proc do |response| response.to_s end)
|
46
|
+
.is_primitive_response(true)
|
47
|
+
.local_error('400',
|
48
|
+
'Invalid username/password supplied',
|
49
|
+
APIException))
|
50
|
+
.execute
|
51
|
+
end
|
52
|
+
|
53
|
+
# This can only be done by the logged in user.
|
54
|
+
# @param [String] name Required parameter: name that need to be deleted
|
55
|
+
# @param [Integer] id Optional parameter: Example:
|
56
|
+
# @param [String] username Optional parameter: Example:
|
57
|
+
# @param [String] first_name Optional parameter: Example:
|
58
|
+
# @param [String] last_name Optional parameter: Example:
|
59
|
+
# @param [String] email Optional parameter: Example:
|
60
|
+
# @param [String] password Optional parameter: Example:
|
61
|
+
# @param [String] phone Optional parameter: Example:
|
62
|
+
# @param [Integer] user_status Optional parameter: User Status
|
63
|
+
# @return [void] response from the API call.
|
64
|
+
def update_user(name,
|
65
|
+
id: nil,
|
66
|
+
username: nil,
|
67
|
+
first_name: nil,
|
68
|
+
last_name: nil,
|
69
|
+
email: nil,
|
70
|
+
password: nil,
|
71
|
+
phone: nil,
|
72
|
+
user_status: nil)
|
73
|
+
new_api_call_builder
|
74
|
+
.request(new_request_builder(HttpMethodEnum::PUT,
|
75
|
+
'/user/{name}',
|
76
|
+
Server::DEFAULT)
|
77
|
+
.template_param(new_parameter(name, key: 'name')
|
78
|
+
.should_encode(true))
|
79
|
+
.form_param(new_parameter(id, key: 'id'))
|
80
|
+
.form_param(new_parameter(username, key: 'username'))
|
81
|
+
.form_param(new_parameter(first_name, key: 'firstName'))
|
82
|
+
.form_param(new_parameter(last_name, key: 'lastName'))
|
83
|
+
.form_param(new_parameter(email, key: 'email'))
|
84
|
+
.form_param(new_parameter(password, key: 'password'))
|
85
|
+
.form_param(new_parameter(phone, key: 'phone'))
|
86
|
+
.form_param(new_parameter(user_status, key: 'userStatus'))
|
87
|
+
.header_param(new_parameter('application/x-www-form-urlencoded', key: 'content-type')))
|
88
|
+
.response(new_response_handler
|
89
|
+
.is_response_void(true))
|
90
|
+
.execute
|
91
|
+
end
|
92
|
+
|
93
|
+
# This can only be done by the logged in user.
|
94
|
+
# @param [String] name Required parameter: The name that needs to be
|
95
|
+
# deleted
|
96
|
+
# @return [void] response from the API call.
|
97
|
+
def delete_user(name)
|
98
|
+
new_api_call_builder
|
99
|
+
.request(new_request_builder(HttpMethodEnum::DELETE,
|
100
|
+
'/user/{name}',
|
101
|
+
Server::DEFAULT)
|
102
|
+
.template_param(new_parameter(name, key: 'name')
|
103
|
+
.should_encode(true)))
|
104
|
+
.response(new_response_handler
|
105
|
+
.is_response_void(true)
|
106
|
+
.local_error('400',
|
107
|
+
'Invalid username supplied',
|
108
|
+
APIException)
|
109
|
+
.local_error('404',
|
110
|
+
'User not found',
|
111
|
+
APIException))
|
112
|
+
.execute
|
113
|
+
end
|
114
|
+
|
115
|
+
# TODO: type endpoint description here
|
116
|
+
# @param [String] name Required parameter: The name that needs to be
|
117
|
+
# fetched. Use user1 for testing.
|
118
|
+
# @return [User] response from the API call.
|
119
|
+
def get_user_by_name(name)
|
120
|
+
new_api_call_builder
|
121
|
+
.request(new_request_builder(HttpMethodEnum::GET,
|
122
|
+
'/user/{name}',
|
123
|
+
Server::DEFAULT)
|
124
|
+
.template_param(new_parameter(name, key: 'name')
|
125
|
+
.should_encode(true))
|
126
|
+
.header_param(new_parameter('application/json', key: 'accept')))
|
127
|
+
.response(new_response_handler
|
128
|
+
.deserializer(APIHelper.method(:custom_type_deserializer))
|
129
|
+
.deserialize_into(User.method(:from_hash))
|
130
|
+
.local_error('400',
|
131
|
+
'Invalid username supplied',
|
132
|
+
APIException)
|
133
|
+
.local_error('404',
|
134
|
+
'User not found',
|
135
|
+
APIException))
|
136
|
+
.execute
|
137
|
+
end
|
138
|
+
|
139
|
+
# TODO: type endpoint description here
|
140
|
+
# @return [void] response from the API call.
|
141
|
+
def logout_user
|
142
|
+
new_api_call_builder
|
143
|
+
.request(new_request_builder(HttpMethodEnum::GET,
|
144
|
+
'/user/logout',
|
145
|
+
Server::DEFAULT))
|
146
|
+
.response(new_response_handler
|
147
|
+
.is_response_void(true))
|
148
|
+
.execute
|
149
|
+
end
|
150
|
+
|
151
|
+
# This can only be done by the logged in user.
|
152
|
+
# @param [Integer] id Optional parameter: Example:
|
153
|
+
# @param [String] username Optional parameter: Example:
|
154
|
+
# @param [String] first_name Optional parameter: Example:
|
155
|
+
# @param [String] last_name Optional parameter: Example:
|
156
|
+
# @param [String] email Optional parameter: Example:
|
157
|
+
# @param [String] password Optional parameter: Example:
|
158
|
+
# @param [String] phone Optional parameter: Example:
|
159
|
+
# @param [Integer] user_status Optional parameter: User Status
|
160
|
+
# @return [User] response from the API call.
|
161
|
+
def create_user(id: nil,
|
162
|
+
username: nil,
|
163
|
+
first_name: nil,
|
164
|
+
last_name: nil,
|
165
|
+
email: nil,
|
166
|
+
password: nil,
|
167
|
+
phone: nil,
|
168
|
+
user_status: nil)
|
169
|
+
new_api_call_builder
|
170
|
+
.request(new_request_builder(HttpMethodEnum::POST,
|
171
|
+
'/user',
|
172
|
+
Server::DEFAULT)
|
173
|
+
.form_param(new_parameter(id, key: 'id'))
|
174
|
+
.form_param(new_parameter(username, key: 'username'))
|
175
|
+
.form_param(new_parameter(first_name, key: 'firstName'))
|
176
|
+
.form_param(new_parameter(last_name, key: 'lastName'))
|
177
|
+
.form_param(new_parameter(email, key: 'email'))
|
178
|
+
.form_param(new_parameter(password, key: 'password'))
|
179
|
+
.form_param(new_parameter(phone, key: 'phone'))
|
180
|
+
.form_param(new_parameter(user_status, key: 'userStatus'))
|
181
|
+
.header_param(new_parameter('application/x-www-form-urlencoded', key: 'content-type'))
|
182
|
+
.header_param(new_parameter('application/json', key: 'accept')))
|
183
|
+
.response(new_response_handler
|
184
|
+
.deserializer(APIHelper.method(:custom_type_deserializer))
|
185
|
+
.deserialize_into(User.method(:from_hash)))
|
186
|
+
.execute
|
187
|
+
end
|
188
|
+
end
|
189
|
+
end
|
@@ -0,0 +1,21 @@
|
|
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
|
+
# Provides a human-readable string representation of the object.
|
10
|
+
def to_s
|
11
|
+
class_name = self.class.name.split('::').last
|
12
|
+
"<#{class_name} status_code: #{@response_code}, reason: #{@reason}>"
|
13
|
+
end
|
14
|
+
|
15
|
+
# Provides a debugging-friendly string with detailed object information.
|
16
|
+
def inspect
|
17
|
+
class_name = self.class.name.split('::').last
|
18
|
+
"<#{class_name} status_code: #{@response_code.inspect}, reason: #{@reason.inspect}>"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
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,90 @@
|
|
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
|
+
|
77
|
+
# Provides a human-readable string representation of the object.
|
78
|
+
def to_s
|
79
|
+
class_name = self.class.name.split('::').last
|
80
|
+
"<#{class_name} street: #{@street}, city: #{@city}, state: #{@state}, zip: #{@zip}>"
|
81
|
+
end
|
82
|
+
|
83
|
+
# Provides a debugging-friendly string with detailed object information.
|
84
|
+
def inspect
|
85
|
+
class_name = self.class.name.split('::').last
|
86
|
+
"<#{class_name} street: #{@street.inspect}, city: #{@city.inspect}, state:"\
|
87
|
+
" #{@state.inspect}, zip: #{@zip.inspect}>"
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,110 @@
|
|
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
|
+
# rubocop:disable all
|
9
|
+
class BaseModel < CoreLibrary::BaseModel
|
10
|
+
# Returns a Hash representation of the current object.
|
11
|
+
def to_hash
|
12
|
+
# validating the model being serialized
|
13
|
+
self.class.validate(self) if self.class.respond_to?(:validate)
|
14
|
+
|
15
|
+
hash = {}
|
16
|
+
instance_variables.each do |name|
|
17
|
+
value = instance_variable_get(name)
|
18
|
+
name = name[1..]
|
19
|
+
if name == 'additional_properties'
|
20
|
+
additional_properties = process_additional_properties(value, self.class.names)
|
21
|
+
hash.merge!(additional_properties)
|
22
|
+
else
|
23
|
+
key = self.class.names.key?(name) ? self.class.names[name] : name
|
24
|
+
optional_fields = self.class.optionals
|
25
|
+
nullable_fields = self.class.nullables
|
26
|
+
if value.nil?
|
27
|
+
next unless nullable_fields.include?(name)
|
28
|
+
|
29
|
+
if !optional_fields.include?(name) && !nullable_fields.include?(name)
|
30
|
+
raise ArgumentError,
|
31
|
+
"`#{name}` cannot be nil in `#{self.class}`. Please specify a valid value."
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
hash[key] = nil
|
36
|
+
unless value.nil?
|
37
|
+
if respond_to?("to_custom_#{name}")
|
38
|
+
if (value.instance_of? Array) || (value.instance_of? Hash)
|
39
|
+
params = [hash, key]
|
40
|
+
hash[key] = send("to_custom_#{name}", *params)
|
41
|
+
else
|
42
|
+
hash[key] = send("to_custom_#{name}")
|
43
|
+
end
|
44
|
+
elsif respond_to?("to_union_type_#{name}")
|
45
|
+
hash[key] = send("to_union_type_#{name}")
|
46
|
+
elsif value.instance_of? Array
|
47
|
+
hash[key] = value.map { |v| v.is_a?(BaseModel) ? v.to_hash : v }
|
48
|
+
elsif value.instance_of? Hash
|
49
|
+
hash[key] = {}
|
50
|
+
value.each do |k, v|
|
51
|
+
hash[key][k] = v.is_a?(BaseModel) ? v.to_hash : v
|
52
|
+
end
|
53
|
+
else
|
54
|
+
hash[key] = value.is_a?(BaseModel) ? value.to_hash : value
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
hash
|
60
|
+
end
|
61
|
+
|
62
|
+
# Processes additional properties, ensuring no conflicts with existing properties.
|
63
|
+
def process_additional_properties(additional_properties, existing_prop_names)
|
64
|
+
hash = {}
|
65
|
+
additional_properties.each do |name, value|
|
66
|
+
check_for_conflict(name, existing_prop_names)
|
67
|
+
|
68
|
+
hash[name] = if value.is_a?(Array)
|
69
|
+
process_array(value)
|
70
|
+
elsif value.is_a?(Hash)
|
71
|
+
process_hash(value)
|
72
|
+
else
|
73
|
+
process_basic_value(value)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
hash
|
77
|
+
end
|
78
|
+
|
79
|
+
# Checks if an additional property conflicts with a model's existing property.
|
80
|
+
def check_for_conflict(name, existing_prop_names)
|
81
|
+
return unless existing_prop_names.key?(name)
|
82
|
+
|
83
|
+
raise ArgumentError, "An additional property key, '#{name}' conflicts with one of the model's properties"
|
84
|
+
end
|
85
|
+
|
86
|
+
# Processes an array of values, recursively calling `to_hash` on BaseModel objects.
|
87
|
+
def process_array(value)
|
88
|
+
value.map { |v| v.is_a?(BaseModel) ? v.to_hash : v }
|
89
|
+
end
|
90
|
+
|
91
|
+
# Processes a hash of values, recursively calling `to_hash` on BaseModel objects.
|
92
|
+
def process_hash(value)
|
93
|
+
value.transform_values do |v|
|
94
|
+
v.is_a?(BaseModel) ? v.to_hash : v
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
# Processes a basic value (non-array, non-hash).
|
99
|
+
def process_basic_value(value)
|
100
|
+
value.is_a?(BaseModel) ? value.to_hash : value
|
101
|
+
end
|
102
|
+
|
103
|
+
# Returns a JSON representation of the curent object.
|
104
|
+
def to_json(options = {})
|
105
|
+
hash = to_hash
|
106
|
+
hash.to_json(options)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
# rubocop:enable all
|
110
|
+
end
|
@@ -0,0 +1,71 @@
|
|
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
|
+
|
59
|
+
# Provides a human-readable string representation of the object.
|
60
|
+
def to_s
|
61
|
+
class_name = self.class.name.split('::').last
|
62
|
+
"<#{class_name} id: #{@id}, name: #{@name}>"
|
63
|
+
end
|
64
|
+
|
65
|
+
# Provides a debugging-friendly string with detailed object information.
|
66
|
+
def inspect
|
67
|
+
class_name = self.class.name.split('::').last
|
68
|
+
"<#{class_name} id: #{@id.inspect}, name: #{@name.inspect}>"
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|