gopad 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +20 -0
- data/CONTRIBUTING.md +121 -0
- data/DCO +34 -0
- data/LICENSE +202 -0
- data/README.md +67 -0
- data/lib/gopad/api/auth_api.rb +154 -0
- data/lib/gopad/api/team_api.rb +671 -0
- data/lib/gopad/api/user_api.rb +671 -0
- data/lib/gopad/api_client.rb +429 -0
- data/lib/gopad/api_error.rb +56 -0
- data/lib/gopad/configuration.rb +390 -0
- data/lib/gopad/models/notification.rb +227 -0
- data/lib/gopad/models/team.rb +251 -0
- data/lib/gopad/models/team_user_params.rb +262 -0
- data/lib/gopad/models/team_users.rb +227 -0
- data/lib/gopad/models/teams.rb +220 -0
- data/lib/gopad/models/user.rb +299 -0
- data/lib/gopad/models/user_auth.rb +234 -0
- data/lib/gopad/models/user_team.rb +302 -0
- data/lib/gopad/models/user_team_params.rb +262 -0
- data/lib/gopad/models/user_teams.rb +227 -0
- data/lib/gopad/models/users.rb +220 -0
- data/lib/gopad/models/validation.rb +220 -0
- data/lib/gopad/version.rb +13 -0
- data/lib/gopad.rb +52 -0
- metadata +117 -0
@@ -0,0 +1,390 @@
|
|
1
|
+
# Gopad OpenAPI
|
2
|
+
#
|
3
|
+
# API definition for Gopad, Etherpad for markdown with go
|
4
|
+
#
|
5
|
+
# The version of the OpenAPI document: 1.0.0-alpha1
|
6
|
+
# Contact: gopad@webhippie.de
|
7
|
+
# Generated by: https://openapi-generator.tech
|
8
|
+
# Generator version: 7.6.0
|
9
|
+
#
|
10
|
+
|
11
|
+
module Gopad
|
12
|
+
class Configuration
|
13
|
+
# Defines url scheme
|
14
|
+
attr_accessor :scheme
|
15
|
+
|
16
|
+
# Defines url host
|
17
|
+
attr_accessor :host
|
18
|
+
|
19
|
+
# Defines url base path
|
20
|
+
attr_accessor :base_path
|
21
|
+
|
22
|
+
# Define server configuration index
|
23
|
+
attr_accessor :server_index
|
24
|
+
|
25
|
+
# Define server operation configuration index
|
26
|
+
attr_accessor :server_operation_index
|
27
|
+
|
28
|
+
# Default server variables
|
29
|
+
attr_accessor :server_variables
|
30
|
+
|
31
|
+
# Default server operation variables
|
32
|
+
attr_accessor :server_operation_variables
|
33
|
+
|
34
|
+
# Defines API keys used with API Key authentications.
|
35
|
+
#
|
36
|
+
# @return [Hash] key: parameter name, value: parameter value (API key)
|
37
|
+
#
|
38
|
+
# @example parameter name is "api_key", API key is "xxx" (e.g. "api_key=xxx" in query string)
|
39
|
+
# config.api_key['api_key'] = 'xxx'
|
40
|
+
attr_accessor :api_key
|
41
|
+
|
42
|
+
# Defines API key prefixes used with API Key authentications.
|
43
|
+
#
|
44
|
+
# @return [Hash] key: parameter name, value: API key prefix
|
45
|
+
#
|
46
|
+
# @example parameter name is "Authorization", API key prefix is "Token" (e.g. "Authorization: Token xxx" in headers)
|
47
|
+
# config.api_key_prefix['api_key'] = 'Token'
|
48
|
+
attr_accessor :api_key_prefix
|
49
|
+
|
50
|
+
# Defines the username used with HTTP basic authentication.
|
51
|
+
#
|
52
|
+
# @return [String]
|
53
|
+
attr_accessor :username
|
54
|
+
|
55
|
+
# Defines the password used with HTTP basic authentication.
|
56
|
+
#
|
57
|
+
# @return [String]
|
58
|
+
attr_accessor :password
|
59
|
+
|
60
|
+
# Defines the access token (Bearer) used with OAuth2.
|
61
|
+
attr_accessor :access_token
|
62
|
+
|
63
|
+
# Defines a Proc used to fetch or refresh access tokens (Bearer) used with OAuth2.
|
64
|
+
# Overrides the access_token if set
|
65
|
+
# @return [Proc]
|
66
|
+
attr_accessor :access_token_getter
|
67
|
+
|
68
|
+
# Set this to return data as binary instead of downloading a temp file. When enabled (set to true)
|
69
|
+
# HTTP responses with return type `File` will be returned as a stream of binary data.
|
70
|
+
# Default to false.
|
71
|
+
attr_accessor :return_binary_data
|
72
|
+
|
73
|
+
# Set this to enable/disable debugging. When enabled (set to true), HTTP request/response
|
74
|
+
# details will be logged with `logger.debug` (see the `logger` attribute).
|
75
|
+
# Default to false.
|
76
|
+
#
|
77
|
+
# @return [true, false]
|
78
|
+
attr_accessor :debugging
|
79
|
+
|
80
|
+
# Defines the logger used for debugging.
|
81
|
+
# Default to `Rails.logger` (when in Rails) or logging to STDOUT.
|
82
|
+
#
|
83
|
+
# @return [#debug]
|
84
|
+
attr_accessor :logger
|
85
|
+
|
86
|
+
# Defines the temporary folder to store downloaded files
|
87
|
+
# (for API endpoints that have file response).
|
88
|
+
# Default to use `Tempfile`.
|
89
|
+
#
|
90
|
+
# @return [String]
|
91
|
+
attr_accessor :temp_folder_path
|
92
|
+
|
93
|
+
# The time limit for HTTP request in seconds.
|
94
|
+
# Default to 0 (never times out).
|
95
|
+
attr_accessor :timeout
|
96
|
+
|
97
|
+
# Set this to false to skip client side validation in the operation.
|
98
|
+
# Default to true.
|
99
|
+
# @return [true, false]
|
100
|
+
attr_accessor :client_side_validation
|
101
|
+
|
102
|
+
### TLS/SSL setting
|
103
|
+
# Set this to false to skip verifying SSL certificate when calling API from https server.
|
104
|
+
# Default to true.
|
105
|
+
#
|
106
|
+
# @note Do NOT set it to false in production code, otherwise you would face multiple types of cryptographic attacks.
|
107
|
+
#
|
108
|
+
# @return [true, false]
|
109
|
+
attr_accessor :ssl_verify
|
110
|
+
|
111
|
+
### TLS/SSL setting
|
112
|
+
# Any `OpenSSL::SSL::` constant (see https://ruby-doc.org/stdlib-2.5.1/libdoc/openssl/rdoc/OpenSSL/SSL.html)
|
113
|
+
#
|
114
|
+
# @note Do NOT set it to false in production code, otherwise you would face multiple types of cryptographic attacks.
|
115
|
+
#
|
116
|
+
attr_accessor :ssl_verify_mode
|
117
|
+
|
118
|
+
### TLS/SSL setting
|
119
|
+
# Set this to customize the certificate file to verify the peer.
|
120
|
+
#
|
121
|
+
# @return [String] the path to the certificate file
|
122
|
+
attr_accessor :ssl_ca_file
|
123
|
+
|
124
|
+
### TLS/SSL setting
|
125
|
+
# Client certificate file (for client certificate)
|
126
|
+
attr_accessor :ssl_client_cert
|
127
|
+
|
128
|
+
### TLS/SSL setting
|
129
|
+
# Client private key file (for client certificate)
|
130
|
+
attr_accessor :ssl_client_key
|
131
|
+
|
132
|
+
### Proxy setting
|
133
|
+
# HTTP Proxy settings
|
134
|
+
attr_accessor :proxy
|
135
|
+
|
136
|
+
# Set this to customize parameters encoder of array parameter.
|
137
|
+
# Default to nil. Faraday uses NestedParamsEncoder when nil.
|
138
|
+
#
|
139
|
+
# @see The params_encoder option of Faraday. Related source code:
|
140
|
+
# https://github.com/lostisland/faraday/tree/main/lib/faraday/encoders
|
141
|
+
attr_accessor :params_encoder
|
142
|
+
|
143
|
+
attr_accessor :inject_format, :force_ending_format
|
144
|
+
|
145
|
+
def initialize
|
146
|
+
@scheme = 'https'
|
147
|
+
@host = 'try.gopad.eu'
|
148
|
+
@base_path = '/api/v1'
|
149
|
+
@server_index = nil
|
150
|
+
@server_operation_index = {}
|
151
|
+
@server_variables = {}
|
152
|
+
@server_operation_variables = {}
|
153
|
+
@api_key = {}
|
154
|
+
@api_key_prefix = {}
|
155
|
+
@client_side_validation = true
|
156
|
+
@ssl_verify = true
|
157
|
+
@ssl_verify_mode = nil
|
158
|
+
@ssl_ca_file = nil
|
159
|
+
@ssl_client_cert = nil
|
160
|
+
@ssl_client_key = nil
|
161
|
+
@middlewares = Hash.new { |h, k| h[k] = [] }
|
162
|
+
@configure_connection_blocks = []
|
163
|
+
@timeout = 60
|
164
|
+
# return data as binary instead of file
|
165
|
+
@return_binary_data = false
|
166
|
+
@params_encoder = nil
|
167
|
+
@debugging = false
|
168
|
+
@inject_format = false
|
169
|
+
@force_ending_format = false
|
170
|
+
@logger = defined?(Rails) ? Rails.logger : Logger.new($stdout)
|
171
|
+
|
172
|
+
yield(self) if block_given?
|
173
|
+
end
|
174
|
+
|
175
|
+
# The default Configuration object.
|
176
|
+
def self.default
|
177
|
+
@@default ||= Configuration.new
|
178
|
+
end
|
179
|
+
|
180
|
+
def configure
|
181
|
+
yield(self) if block_given?
|
182
|
+
end
|
183
|
+
|
184
|
+
def scheme=(scheme)
|
185
|
+
# remove :// from scheme
|
186
|
+
@scheme = scheme.sub('://', '')
|
187
|
+
end
|
188
|
+
|
189
|
+
def host=(host)
|
190
|
+
# remove http(s):// and anything after a slash
|
191
|
+
@host = host.sub(%r{https?://}, '').split('/').first
|
192
|
+
end
|
193
|
+
|
194
|
+
def base_path=(base_path)
|
195
|
+
# Add leading and trailing slashes to base_path
|
196
|
+
@base_path = "/#{base_path}".gsub(%r{/+}, '/')
|
197
|
+
@base_path = '' if @base_path == '/'
|
198
|
+
end
|
199
|
+
|
200
|
+
# Returns base URL for specified operation based on server settings
|
201
|
+
def base_url(operation = nil)
|
202
|
+
if operation_server_settings.key?(operation)
|
203
|
+
index = server_operation_index.fetch(operation, server_index)
|
204
|
+
server_url(index.nil? ? 0 : index, server_operation_variables.fetch(operation, server_variables), operation_server_settings[operation])
|
205
|
+
else
|
206
|
+
server_index.nil? ? "#{scheme}://#{[host, base_path].join('/').gsub(%r{/+}, '/')}".sub(%r{/+\z}, '') : server_url(server_index, server_variables, nil)
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
210
|
+
# Gets API key (with prefix if set).
|
211
|
+
# @param [String] param_name the parameter name of API key auth
|
212
|
+
def api_key_with_prefix(param_name, param_alias = nil)
|
213
|
+
key = @api_key[param_name]
|
214
|
+
key = @api_key.fetch(param_alias, key) unless param_alias.nil?
|
215
|
+
if @api_key_prefix[param_name]
|
216
|
+
"#{@api_key_prefix[param_name]} #{key}"
|
217
|
+
else
|
218
|
+
key
|
219
|
+
end
|
220
|
+
end
|
221
|
+
|
222
|
+
# Gets access_token using access_token_getter or uses the static access_token
|
223
|
+
def access_token_with_refresh
|
224
|
+
return access_token if access_token_getter.nil?
|
225
|
+
|
226
|
+
access_token_getter.call
|
227
|
+
end
|
228
|
+
|
229
|
+
# Gets Basic Auth token string
|
230
|
+
def basic_auth_token
|
231
|
+
'Basic ' + ["#{username}:#{password}"].pack('m').delete("\r\n")
|
232
|
+
end
|
233
|
+
|
234
|
+
# Returns Auth Settings hash for api client.
|
235
|
+
def auth_settings
|
236
|
+
{
|
237
|
+
'Cookie' =>
|
238
|
+
{
|
239
|
+
type: 'api_key',
|
240
|
+
in: 'header',
|
241
|
+
key: 'Cookie',
|
242
|
+
value: api_key_with_prefix('Cookie')
|
243
|
+
},
|
244
|
+
'Header' =>
|
245
|
+
{
|
246
|
+
type: 'api_key',
|
247
|
+
in: 'header',
|
248
|
+
key: 'X-API-Key',
|
249
|
+
value: api_key_with_prefix('Header')
|
250
|
+
},
|
251
|
+
'Basic' =>
|
252
|
+
{
|
253
|
+
type: 'basic',
|
254
|
+
in: 'header',
|
255
|
+
key: 'Authorization',
|
256
|
+
value: basic_auth_token
|
257
|
+
}
|
258
|
+
}
|
259
|
+
end
|
260
|
+
|
261
|
+
# Returns an array of Server setting
|
262
|
+
def server_settings
|
263
|
+
[
|
264
|
+
{
|
265
|
+
url: 'https://try.gopad.eu/api/v1',
|
266
|
+
description: 'No description provided'
|
267
|
+
}
|
268
|
+
]
|
269
|
+
end
|
270
|
+
|
271
|
+
def operation_server_settings
|
272
|
+
{}
|
273
|
+
end
|
274
|
+
|
275
|
+
# Returns URL based on server settings
|
276
|
+
#
|
277
|
+
# @param index array index of the server settings
|
278
|
+
# @param variables hash of variable and the corresponding value
|
279
|
+
def server_url(index, variables = {}, servers = nil)
|
280
|
+
servers = server_settings if servers.nil?
|
281
|
+
|
282
|
+
# check array index out of bound
|
283
|
+
if index.nil? || index.negative? || index >= servers.size
|
284
|
+
raise ArgumentError, "Invalid index #{index} when selecting the server. Must not be nil and must be less than #{servers.size}"
|
285
|
+
end
|
286
|
+
|
287
|
+
server = servers[index]
|
288
|
+
url = server[:url]
|
289
|
+
|
290
|
+
return url unless server.key? :variables
|
291
|
+
|
292
|
+
# go through variable and assign a value
|
293
|
+
server[:variables].each_key do |name|
|
294
|
+
if variables.key?(name)
|
295
|
+
if !server[:variables][name].key?(:enum_values) || server[:variables][name][:enum_values].include?(variables[name])
|
296
|
+
url.gsub! '{' + name.to_s + '}', variables[name]
|
297
|
+
else
|
298
|
+
raise ArgumentError, "The variable `#{name}` in the server URL has invalid value #{variables[name]}. Must be #{server[:variables][name][:enum_values]}."
|
299
|
+
end
|
300
|
+
else
|
301
|
+
# use default value
|
302
|
+
url.gsub! '{' + name.to_s + '}', server[:variables][name][:default_value]
|
303
|
+
end
|
304
|
+
end
|
305
|
+
|
306
|
+
url
|
307
|
+
end
|
308
|
+
|
309
|
+
# Configure Faraday connection directly.
|
310
|
+
#
|
311
|
+
# ```
|
312
|
+
# c.configure_faraday_connection do |conn|
|
313
|
+
# conn.use Faraday::HttpCache, shared_cache: false, logger: logger
|
314
|
+
# conn.response :logger, nil, headers: true, bodies: true, log_level: :debug do |logger|
|
315
|
+
# logger.filter(/(Authorization: )(.*)/, '\1[REDACTED]')
|
316
|
+
# end
|
317
|
+
# end
|
318
|
+
#
|
319
|
+
# c.configure_faraday_connection do |conn|
|
320
|
+
# conn.adapter :typhoeus
|
321
|
+
# end
|
322
|
+
# ```
|
323
|
+
#
|
324
|
+
# @param block [Proc] `#call`able object that takes one arg, the connection
|
325
|
+
def configure_faraday_connection(&block)
|
326
|
+
@configure_connection_blocks << block
|
327
|
+
end
|
328
|
+
|
329
|
+
def configure_connection(conn)
|
330
|
+
@configure_connection_blocks.each do |block|
|
331
|
+
block.call(conn)
|
332
|
+
end
|
333
|
+
end
|
334
|
+
|
335
|
+
# Adds middleware to the stack
|
336
|
+
def use(*middleware)
|
337
|
+
set_faraday_middleware(:use, *middleware)
|
338
|
+
end
|
339
|
+
|
340
|
+
# Adds request middleware to the stack
|
341
|
+
def request(*middleware)
|
342
|
+
set_faraday_middleware(:request, *middleware)
|
343
|
+
end
|
344
|
+
|
345
|
+
# Adds response middleware to the stack
|
346
|
+
def response(*middleware)
|
347
|
+
set_faraday_middleware(:response, *middleware)
|
348
|
+
end
|
349
|
+
|
350
|
+
# Adds Faraday middleware setting information to the stack
|
351
|
+
#
|
352
|
+
# @example Use the `set_faraday_middleware` method to set middleware information
|
353
|
+
# config.set_faraday_middleware(:request, :retry, max: 3, methods: [:get, :post], retry_statuses: [503])
|
354
|
+
# config.set_faraday_middleware(:response, :logger, nil, { bodies: true, log_level: :debug })
|
355
|
+
# config.set_faraday_middleware(:use, Faraday::HttpCache, store: Rails.cache, shared_cache: false)
|
356
|
+
# config.set_faraday_middleware(:insert, 0, FaradayMiddleware::FollowRedirects, { standards_compliant: true, limit: 1 })
|
357
|
+
# config.set_faraday_middleware(:swap, 0, Faraday::Response::Logger)
|
358
|
+
# config.set_faraday_middleware(:delete, Faraday::Multipart::Middleware)
|
359
|
+
#
|
360
|
+
# @see https://github.com/lostisland/faraday/blob/v2.3.0/lib/faraday/rack_builder.rb#L92-L143
|
361
|
+
def set_faraday_middleware(operation, key, *args, &block)
|
362
|
+
unless %i[request response use insert insert_before insert_after swap delete].include?(operation)
|
363
|
+
raise ArgumentError, "Invalid faraday middleware operation #{operation}. Must be " \
|
364
|
+
':request, :response, :use, :insert, :insert_before, :insert_after, :swap or :delete.'
|
365
|
+
end
|
366
|
+
|
367
|
+
@middlewares[operation] << [key, args, block]
|
368
|
+
end
|
369
|
+
ruby2_keywords(:set_faraday_middleware) if respond_to?(:ruby2_keywords, true)
|
370
|
+
|
371
|
+
# Set up middleware on the connection
|
372
|
+
def configure_middleware(connection)
|
373
|
+
return if @middlewares.empty?
|
374
|
+
|
375
|
+
%i[request response use insert insert_before insert_after swap].each do |operation|
|
376
|
+
next unless @middlewares.key?(operation)
|
377
|
+
|
378
|
+
@middlewares[operation].each do |key, args, block|
|
379
|
+
connection.builder.send(operation, key, *args, &block)
|
380
|
+
end
|
381
|
+
end
|
382
|
+
|
383
|
+
if @middlewares.key?(:delete)
|
384
|
+
@middlewares[:delete].each do |key, _args, _block|
|
385
|
+
connection.builder.delete(key)
|
386
|
+
end
|
387
|
+
end
|
388
|
+
end
|
389
|
+
end
|
390
|
+
end
|
@@ -0,0 +1,227 @@
|
|
1
|
+
# Gopad OpenAPI
|
2
|
+
#
|
3
|
+
# API definition for Gopad, Etherpad for markdown with go
|
4
|
+
#
|
5
|
+
# The version of the OpenAPI document: 1.0.0-alpha1
|
6
|
+
# Contact: gopad@webhippie.de
|
7
|
+
# Generated by: https://openapi-generator.tech
|
8
|
+
# Generator version: 7.6.0
|
9
|
+
#
|
10
|
+
|
11
|
+
require 'date'
|
12
|
+
require 'time'
|
13
|
+
|
14
|
+
module Gopad
|
15
|
+
# Generic response for errors and validations
|
16
|
+
class Notification
|
17
|
+
attr_accessor :status, :message, :errors
|
18
|
+
|
19
|
+
# Attribute mapping from ruby-style variable name to JSON key.
|
20
|
+
def self.attribute_map
|
21
|
+
{
|
22
|
+
status: :status,
|
23
|
+
message: :message,
|
24
|
+
errors: :errors
|
25
|
+
}
|
26
|
+
end
|
27
|
+
|
28
|
+
# Returns all the JSON keys this model knows about
|
29
|
+
def self.acceptable_attributes
|
30
|
+
attribute_map.values
|
31
|
+
end
|
32
|
+
|
33
|
+
# Attribute type mapping.
|
34
|
+
def self.openapi_types
|
35
|
+
{
|
36
|
+
status: :Integer,
|
37
|
+
message: :String,
|
38
|
+
errors: :'Array<Validation>'
|
39
|
+
}
|
40
|
+
end
|
41
|
+
|
42
|
+
# List of attributes with nullable: true
|
43
|
+
def self.openapi_nullable
|
44
|
+
Set.new([
|
45
|
+
])
|
46
|
+
end
|
47
|
+
|
48
|
+
# Initializes the object
|
49
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
50
|
+
def initialize(attributes = {})
|
51
|
+
unless attributes.is_a?(Hash)
|
52
|
+
raise ArgumentError, 'The input argument (attributes) must be a hash in `Gopad::Notification` initialize method'
|
53
|
+
end
|
54
|
+
|
55
|
+
# check to see if the attribute exists and convert string to symbol for hash key
|
56
|
+
attributes = attributes.each_with_object({}) do |(k, v), h|
|
57
|
+
unless self.class.attribute_map.key?(k.to_sym)
|
58
|
+
raise ArgumentError, "`#{k}` is not a valid attribute in `Gopad::Notification`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
|
59
|
+
end
|
60
|
+
|
61
|
+
h[k.to_sym] = v
|
62
|
+
end
|
63
|
+
|
64
|
+
if attributes.key?(:status)
|
65
|
+
self.status = attributes[:status]
|
66
|
+
end
|
67
|
+
|
68
|
+
if attributes.key?(:message)
|
69
|
+
self.message = attributes[:message]
|
70
|
+
end
|
71
|
+
|
72
|
+
if attributes.key?(:errors) && (value = attributes[:errors]).is_a?(Array)
|
73
|
+
self.errors = value
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
# Show invalid properties with the reasons. Usually used together with valid?
|
78
|
+
# @return Array for valid properties with the reasons
|
79
|
+
def list_invalid_properties
|
80
|
+
warn '[DEPRECATED] the `list_invalid_properties` method is obsolete'
|
81
|
+
[]
|
82
|
+
end
|
83
|
+
|
84
|
+
# Check to see if the all the properties in the model are valid
|
85
|
+
# @return true if the model is valid
|
86
|
+
def valid?
|
87
|
+
warn '[DEPRECATED] the `valid?` method is obsolete'
|
88
|
+
true
|
89
|
+
end
|
90
|
+
|
91
|
+
# Checks equality by comparing each attribute.
|
92
|
+
# @param [Object] Object to be compared
|
93
|
+
def ==(other)
|
94
|
+
return true if equal?(other)
|
95
|
+
|
96
|
+
self.class == other.class &&
|
97
|
+
status == other.status &&
|
98
|
+
message == other.message &&
|
99
|
+
errors == other.errors
|
100
|
+
end
|
101
|
+
|
102
|
+
# @see the `==` method
|
103
|
+
# @param [Object] Object to be compared
|
104
|
+
def eql?(other)
|
105
|
+
self == other
|
106
|
+
end
|
107
|
+
|
108
|
+
# Calculates hash code according to all attributes.
|
109
|
+
# @return [Integer] Hash code
|
110
|
+
def hash
|
111
|
+
[status, message, errors].hash
|
112
|
+
end
|
113
|
+
|
114
|
+
# Builds the object from hash
|
115
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
116
|
+
# @return [Object] Returns the model itself
|
117
|
+
def self.build_from_hash(attributes)
|
118
|
+
return nil unless attributes.is_a?(Hash)
|
119
|
+
|
120
|
+
attributes = attributes.transform_keys(&:to_sym)
|
121
|
+
transformed_hash = {}
|
122
|
+
openapi_types.each_pair do |key, type|
|
123
|
+
if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
|
124
|
+
transformed_hash[key.to_s] = nil
|
125
|
+
elsif type =~ /\AArray<(.*)>/i
|
126
|
+
# check to ensure the input is an array given that the attribute
|
127
|
+
# is documented as an array but the input is not
|
128
|
+
if attributes[attribute_map[key]].is_a?(Array)
|
129
|
+
transformed_hash[key.to_s] = attributes[attribute_map[key]].map { |v| _deserialize(::Regexp.last_match(1), v) }
|
130
|
+
end
|
131
|
+
elsif !attributes[attribute_map[key]].nil?
|
132
|
+
transformed_hash[key.to_s] = _deserialize(type, attributes[attribute_map[key]])
|
133
|
+
end
|
134
|
+
end
|
135
|
+
new(transformed_hash)
|
136
|
+
end
|
137
|
+
|
138
|
+
# Deserializes the data based on type
|
139
|
+
# @param string type Data type
|
140
|
+
# @param string value Value to be deserialized
|
141
|
+
# @return [Object] Deserialized data
|
142
|
+
def self._deserialize(type, value)
|
143
|
+
case type.to_sym
|
144
|
+
when :Time
|
145
|
+
Time.parse(value)
|
146
|
+
when :Date
|
147
|
+
Date.parse(value)
|
148
|
+
when :String
|
149
|
+
value.to_s
|
150
|
+
when :Integer
|
151
|
+
value.to_i
|
152
|
+
when :Float
|
153
|
+
value.to_f
|
154
|
+
when :Boolean
|
155
|
+
if value.to_s =~ /\A(true|t|yes|y|1)\z/i
|
156
|
+
true
|
157
|
+
else
|
158
|
+
false
|
159
|
+
end
|
160
|
+
when :Object
|
161
|
+
# generic object (usually a Hash), return directly
|
162
|
+
value
|
163
|
+
when /\AArray<(?<inner_type>.+)>\z/
|
164
|
+
inner_type = Regexp.last_match[:inner_type]
|
165
|
+
value.map { |v| _deserialize(inner_type, v) }
|
166
|
+
when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
|
167
|
+
k_type = Regexp.last_match[:k_type]
|
168
|
+
v_type = Regexp.last_match[:v_type]
|
169
|
+
{}.tap do |hash|
|
170
|
+
value.each do |k, v|
|
171
|
+
hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
|
172
|
+
end
|
173
|
+
end
|
174
|
+
else # model
|
175
|
+
# models (e.g. Pet) or oneOf
|
176
|
+
klass = Gopad.const_get(type)
|
177
|
+
klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
# Returns the string representation of the object
|
182
|
+
# @return [String] String presentation of the object
|
183
|
+
def to_s
|
184
|
+
to_hash.to_s
|
185
|
+
end
|
186
|
+
|
187
|
+
# to_body is an alias to to_hash (backward compatibility)
|
188
|
+
# @return [Hash] Returns the object in the form of hash
|
189
|
+
def to_body
|
190
|
+
to_hash
|
191
|
+
end
|
192
|
+
|
193
|
+
# Returns the object in the form of hash
|
194
|
+
# @return [Hash] Returns the object in the form of hash
|
195
|
+
def to_hash
|
196
|
+
hash = {}
|
197
|
+
self.class.attribute_map.each_pair do |attr, param|
|
198
|
+
value = send(attr)
|
199
|
+
if value.nil?
|
200
|
+
is_nullable = self.class.openapi_nullable.include?(attr)
|
201
|
+
next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
|
202
|
+
end
|
203
|
+
|
204
|
+
hash[param] = _to_hash(value)
|
205
|
+
end
|
206
|
+
hash
|
207
|
+
end
|
208
|
+
|
209
|
+
# Outputs non-array value in the form of hash
|
210
|
+
# For object, use to_hash. Otherwise, just return the value
|
211
|
+
# @param [Object] value Any valid value
|
212
|
+
# @return [Hash] Returns the value in the form of hash
|
213
|
+
def _to_hash(value)
|
214
|
+
if value.is_a?(Array)
|
215
|
+
value.compact.map { |v| _to_hash(v) }
|
216
|
+
elsif value.is_a?(Hash)
|
217
|
+
{}.tap do |hash|
|
218
|
+
value.each { |k, v| hash[k] = _to_hash(v) }
|
219
|
+
end
|
220
|
+
elsif value.respond_to? :to_hash
|
221
|
+
value.to_hash
|
222
|
+
else
|
223
|
+
value
|
224
|
+
end
|
225
|
+
end
|
226
|
+
end
|
227
|
+
end
|