ruby-linstor-client 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.
Files changed (193) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +9 -0
  3. data/Gemfile.lock +86 -0
  4. data/LICENSE +21 -0
  5. data/README.md +21 -0
  6. data/Rakefile +10 -0
  7. data/codegen.sh +22 -0
  8. data/generator/custom/one_of_drbd_resource_definition_layer.rb +7 -0
  9. data/generator/custom/one_of_drbd_volume_definition.rb +7 -0
  10. data/generator/custom/one_of_drbd_volume_luks_volume_storage_nvme_volme_writecache_volume.rb +11 -0
  11. data/generator/openapi-generator.yaml +11 -0
  12. data/generator/template/Gemfile.mustache +9 -0
  13. data/generator/template/README.mustache +148 -0
  14. data/generator/template/Rakefile.mustache +10 -0
  15. data/generator/template/api.mustache +209 -0
  16. data/generator/template/api_client.mustache +264 -0
  17. data/generator/template/api_client_faraday_partial.mustache +136 -0
  18. data/generator/template/api_client_spec.mustache +220 -0
  19. data/generator/template/api_client_typhoeus_partial.mustache +153 -0
  20. data/generator/template/api_doc.mustache +118 -0
  21. data/generator/template/api_error.mustache +49 -0
  22. data/generator/template/api_info.mustache +12 -0
  23. data/generator/template/api_test.mustache +47 -0
  24. data/generator/template/base_object.mustache +120 -0
  25. data/generator/template/configuration.mustache +385 -0
  26. data/generator/template/configuration_spec.mustache +34 -0
  27. data/generator/template/configuration_tls_faraday_partial.mustache +29 -0
  28. data/generator/template/configuration_tls_typhoeus_partial.mustache +34 -0
  29. data/generator/template/gem.mustache +53 -0
  30. data/generator/template/gemspec.mustache +35 -0
  31. data/generator/template/git_push.sh.mustache +57 -0
  32. data/generator/template/gitignore.mustache +39 -0
  33. data/generator/template/model.mustache +26 -0
  34. data/generator/template/model_doc.mustache +12 -0
  35. data/generator/template/model_test.mustache +77 -0
  36. data/generator/template/partial_model_enum_class.mustache +20 -0
  37. data/generator/template/partial_model_generic.mustache +371 -0
  38. data/generator/template/partial_model_generic_doc.mustache +28 -0
  39. data/generator/template/partial_oneof_module.mustache +137 -0
  40. data/generator/template/partial_oneof_module_doc.mustache +92 -0
  41. data/generator/template/rspec.mustache +2 -0
  42. data/generator/template/rubocop.mustache +148 -0
  43. data/generator/template/spec_helper.mustache +103 -0
  44. data/generator/template/travis.mustache +14 -0
  45. data/generator/template/version.mustache +7 -0
  46. data/lib/ruby-linstor-client/api/developers_api.rb +5856 -0
  47. data/lib/ruby-linstor-client/api_client.rb +393 -0
  48. data/lib/ruby-linstor-client/api_error.rb +57 -0
  49. data/lib/ruby-linstor-client/configuration.rb +298 -0
  50. data/lib/ruby-linstor-client/models/api_call_rc.rb +293 -0
  51. data/lib/ruby-linstor-client/models/auto_place_request.rb +245 -0
  52. data/lib/ruby-linstor-client/models/auto_select_filter.rb +305 -0
  53. data/lib/ruby-linstor-client/models/candidate.rb +248 -0
  54. data/lib/ruby-linstor-client/models/controller_props_modify.rb +243 -0
  55. data/lib/ruby-linstor-client/models/controller_version.rb +245 -0
  56. data/lib/ruby-linstor-client/models/drbd_proxy_enable.rb +219 -0
  57. data/lib/ruby-linstor-client/models/drbd_proxy_modify.rb +288 -0
  58. data/lib/ruby-linstor-client/models/drbd_resource.rb +276 -0
  59. data/lib/ruby-linstor-client/models/drbd_resource_definition_layer.rb +283 -0
  60. data/lib/ruby-linstor-client/models/drbd_volume.rb +285 -0
  61. data/lib/ruby-linstor-client/models/drbd_volume_definition.rb +236 -0
  62. data/lib/ruby-linstor-client/models/error_report.rb +252 -0
  63. data/lib/ruby-linstor-client/models/key_value_store.rb +231 -0
  64. data/lib/ruby-linstor-client/models/key_value_store_modify.rb +243 -0
  65. data/lib/ruby-linstor-client/models/layer_type.rb +40 -0
  66. data/lib/ruby-linstor-client/models/luks_resource.rb +220 -0
  67. data/lib/ruby-linstor-client/models/luks_volume.rb +275 -0
  68. data/lib/ruby-linstor-client/models/max_volume_sizes.rb +229 -0
  69. data/lib/ruby-linstor-client/models/net_interface.rb +309 -0
  70. data/lib/ruby-linstor-client/models/node.rb +381 -0
  71. data/lib/ruby-linstor-client/models/node_modify.rb +252 -0
  72. data/lib/ruby-linstor-client/models/nvme_resource.rb +220 -0
  73. data/lib/ruby-linstor-client/models/nvme_volume.rb +266 -0
  74. data/lib/ruby-linstor-client/models/one_of_drbd_resource_definition_layer.rb +7 -0
  75. data/lib/ruby-linstor-client/models/one_of_drbd_volume_definition.rb +7 -0
  76. data/lib/ruby-linstor-client/models/one_of_drbd_volume_luks_volume_storage_nvme_volme_writecache_volume.rb +11 -0
  77. data/lib/ruby-linstor-client/models/pass_phrase_create.rb +227 -0
  78. data/lib/ruby-linstor-client/models/physical_storage.rb +238 -0
  79. data/lib/ruby-linstor-client/models/physical_storage_create.rb +337 -0
  80. data/lib/ruby-linstor-client/models/physical_storage_device.rb +245 -0
  81. data/lib/ruby-linstor-client/models/physical_storage_storage_pool_create.rb +232 -0
  82. data/lib/ruby-linstor-client/models/provider_kind.rb +43 -0
  83. data/lib/ruby-linstor-client/models/resource.rb +278 -0
  84. data/lib/ruby-linstor-client/models/resource_connection.rb +261 -0
  85. data/lib/ruby-linstor-client/models/resource_connection_modify.rb +243 -0
  86. data/lib/ruby-linstor-client/models/resource_create.rb +238 -0
  87. data/lib/ruby-linstor-client/models/resource_definition.rb +295 -0
  88. data/lib/ruby-linstor-client/models/resource_definition_create.rb +262 -0
  89. data/lib/ruby-linstor-client/models/resource_definition_layer.rb +228 -0
  90. data/lib/ruby-linstor-client/models/resource_definition_modify.rb +274 -0
  91. data/lib/ruby-linstor-client/models/resource_group.rb +262 -0
  92. data/lib/ruby-linstor-client/models/resource_group_modify.rb +261 -0
  93. data/lib/ruby-linstor-client/models/resource_group_spawn.rb +255 -0
  94. data/lib/ruby-linstor-client/models/resource_layer.rb +283 -0
  95. data/lib/ruby-linstor-client/models/resource_modify.rb +243 -0
  96. data/lib/ruby-linstor-client/models/resource_state.rb +218 -0
  97. data/lib/ruby-linstor-client/models/resource_with_volumes.rb +297 -0
  98. data/lib/ruby-linstor-client/models/resource_with_volumes_all_of.rb +220 -0
  99. data/lib/ruby-linstor-client/models/snapshot.rb +282 -0
  100. data/lib/ruby-linstor-client/models/snapshot_restore.rb +236 -0
  101. data/lib/ruby-linstor-client/models/snapshot_volume_definition.rb +228 -0
  102. data/lib/ruby-linstor-client/models/storage_pool.rb +333 -0
  103. data/lib/ruby-linstor-client/models/storage_pool_definition.rb +230 -0
  104. data/lib/ruby-linstor-client/models/storage_pool_definition_modify.rb +243 -0
  105. data/lib/ruby-linstor-client/models/storage_resource.rb +220 -0
  106. data/lib/ruby-linstor-client/models/storage_volume.rb +256 -0
  107. data/lib/ruby-linstor-client/models/volume.rb +327 -0
  108. data/lib/ruby-linstor-client/models/volume_definition.rb +277 -0
  109. data/lib/ruby-linstor-client/models/volume_definition_create.rb +232 -0
  110. data/lib/ruby-linstor-client/models/volume_definition_layer.rb +233 -0
  111. data/lib/ruby-linstor-client/models/volume_definition_modify.rb +264 -0
  112. data/lib/ruby-linstor-client/models/volume_group.rb +251 -0
  113. data/lib/ruby-linstor-client/models/volume_group_modify.rb +255 -0
  114. data/lib/ruby-linstor-client/models/volume_layer.rb +228 -0
  115. data/lib/ruby-linstor-client/models/volume_modify.rb +243 -0
  116. data/lib/ruby-linstor-client/models/volume_state.rb +218 -0
  117. data/lib/ruby-linstor-client/models/writecache_resource.rb +220 -0
  118. data/lib/ruby-linstor-client/models/writecache_volume.rb +266 -0
  119. data/lib/ruby-linstor-client/version.rb +15 -0
  120. data/lib/ruby-linstor-client.rb +109 -0
  121. data/pkg/ruby-linstor-client-1.0.0.gem +0 -0
  122. data/ruby-linstor-client.gemspec +39 -0
  123. data/spec/api/developers_api_spec.rb +1116 -0
  124. data/spec/api_client_spec.rb +188 -0
  125. data/spec/configuration_spec.rb +42 -0
  126. data/spec/models/api_call_rc_spec.rb +70 -0
  127. data/spec/models/auto_place_request_spec.rb +46 -0
  128. data/spec/models/auto_select_filter_spec.rb +82 -0
  129. data/spec/models/candidate_spec.rb +52 -0
  130. data/spec/models/controller_props_modify_spec.rb +46 -0
  131. data/spec/models/controller_version_spec.rb +52 -0
  132. data/spec/models/drbd_proxy_enable_spec.rb +34 -0
  133. data/spec/models/drbd_proxy_modify_spec.rb +56 -0
  134. data/spec/models/drbd_resource_definition_layer_spec.rb +76 -0
  135. data/spec/models/drbd_resource_spec.rb +70 -0
  136. data/spec/models/drbd_volume_definition_spec.rb +46 -0
  137. data/spec/models/drbd_volume_spec.rb +76 -0
  138. data/spec/models/error_report_spec.rb +52 -0
  139. data/spec/models/key_value_store_modify_spec.rb +46 -0
  140. data/spec/models/key_value_store_spec.rb +40 -0
  141. data/spec/models/layer_type_spec.rb +28 -0
  142. data/spec/models/luks_resource_spec.rb +34 -0
  143. data/spec/models/luks_volume_spec.rb +70 -0
  144. data/spec/models/max_volume_sizes_spec.rb +40 -0
  145. data/spec/models/net_interface_spec.rb +68 -0
  146. data/spec/models/node_modify_spec.rb +52 -0
  147. data/spec/models/node_spec.rb +102 -0
  148. data/spec/models/nvme_resource_spec.rb +34 -0
  149. data/spec/models/nvme_volume_spec.rb +64 -0
  150. data/spec/models/pass_phrase_create_spec.rb +40 -0
  151. data/spec/models/physical_storage_create_spec.rb +80 -0
  152. data/spec/models/physical_storage_device_spec.rb +52 -0
  153. data/spec/models/physical_storage_spec.rb +46 -0
  154. data/spec/models/physical_storage_storage_pool_create_spec.rb +40 -0
  155. data/spec/models/provider_kind_spec.rb +28 -0
  156. data/spec/models/resource_connection_modify_spec.rb +46 -0
  157. data/spec/models/resource_connection_spec.rb +58 -0
  158. data/spec/models/resource_create_spec.rb +46 -0
  159. data/spec/models/resource_definition_create_spec.rb +58 -0
  160. data/spec/models/resource_definition_layer_spec.rb +40 -0
  161. data/spec/models/resource_definition_modify_spec.rb +64 -0
  162. data/spec/models/resource_definition_spec.rb +76 -0
  163. data/spec/models/resource_group_modify_spec.rb +58 -0
  164. data/spec/models/resource_group_spawn_spec.rb +52 -0
  165. data/spec/models/resource_group_spec.rb +58 -0
  166. data/spec/models/resource_layer_spec.rb +76 -0
  167. data/spec/models/resource_modify_spec.rb +46 -0
  168. data/spec/models/resource_spec.rb +70 -0
  169. data/spec/models/resource_state_spec.rb +34 -0
  170. data/spec/models/resource_with_volumes_all_of_spec.rb +34 -0
  171. data/spec/models/resource_with_volumes_spec.rb +76 -0
  172. data/spec/models/snapshot_restore_spec.rb +40 -0
  173. data/spec/models/snapshot_spec.rb +70 -0
  174. data/spec/models/snapshot_volume_definition_spec.rb +40 -0
  175. data/spec/models/storage_pool_definition_modify_spec.rb +46 -0
  176. data/spec/models/storage_pool_definition_spec.rb +40 -0
  177. data/spec/models/storage_pool_spec.rb +94 -0
  178. data/spec/models/storage_resource_spec.rb +34 -0
  179. data/spec/models/storage_volume_spec.rb +58 -0
  180. data/spec/models/volume_definition_create_spec.rb +40 -0
  181. data/spec/models/volume_definition_layer_spec.rb +40 -0
  182. data/spec/models/volume_definition_modify_spec.rb +58 -0
  183. data/spec/models/volume_definition_spec.rb +64 -0
  184. data/spec/models/volume_group_modify_spec.rb +52 -0
  185. data/spec/models/volume_group_spec.rb +52 -0
  186. data/spec/models/volume_layer_spec.rb +40 -0
  187. data/spec/models/volume_modify_spec.rb +46 -0
  188. data/spec/models/volume_spec.rb +100 -0
  189. data/spec/models/volume_state_spec.rb +34 -0
  190. data/spec/models/writecache_resource_spec.rb +34 -0
  191. data/spec/models/writecache_volume_spec.rb +64 -0
  192. data/spec/spec_helper.rb +111 -0
  193. metadata +344 -0
@@ -0,0 +1,153 @@
1
+ # Call an API with given options.
2
+ #
3
+ # @return [Array<(Object, Integer, Hash)>] an array of 3 elements:
4
+ # the data deserialized from response body (could be nil), response status code and response headers.
5
+ def call_api(http_method, path, opts = {})
6
+ request = build_request(http_method, path, opts)
7
+ response = request.run
8
+
9
+ if @config.debugging
10
+ @config.logger.debug "HTTP response body ~BEGIN~\n#{response.body}\n~END~\n"
11
+ end
12
+
13
+ unless response.success?
14
+ if response.timed_out?
15
+ fail ApiError.new('Connection timed out')
16
+ elsif response.code == 0
17
+ # Errors from libcurl will be made visible here
18
+ fail ApiError.new(:code => 0,
19
+ :message => response.return_message)
20
+ else
21
+ fail ApiError.new(:code => response.code,
22
+ :response_headers => response.headers,
23
+ :response_body => response.body),
24
+ response.status_message
25
+ end
26
+ end
27
+
28
+ if opts[:return_type]
29
+ data = deserialize(response, opts[:return_type])
30
+ else
31
+ data = nil
32
+ end
33
+ return data, response.code, response.headers
34
+ end
35
+
36
+ # Builds the HTTP request
37
+ #
38
+ # @param [String] http_method HTTP method/verb (e.g. POST)
39
+ # @param [String] path URL path (e.g. /account/new)
40
+ # @option opts [Hash] :header_params Header parameters
41
+ # @option opts [Hash] :query_params Query parameters
42
+ # @option opts [Hash] :form_params Query parameters
43
+ # @option opts [Object] :body HTTP body (JSON/XML)
44
+ # @return [Typhoeus::Request] A Typhoeus Request
45
+ def build_request(http_method, path, opts = {})
46
+ url = build_request_url(path, opts)
47
+ http_method = http_method.to_sym.downcase
48
+
49
+ header_params = @default_headers.merge(opts[:header_params] || {})
50
+ query_params = opts[:query_params] || {}
51
+ form_params = opts[:form_params] || {}
52
+
53
+ {{#hasAuthMethods}}
54
+ update_params_for_auth! header_params, query_params, opts[:auth_names]
55
+ {{/hasAuthMethods}}
56
+
57
+ # set ssl_verifyhosts option based on @config.verify_ssl_host (true/false)
58
+ _verify_ssl_host = @config.verify_ssl_host ? 2 : 0
59
+
60
+ req_opts = {
61
+ :method => http_method,
62
+ :headers => header_params,
63
+ :params => query_params,
64
+ :params_encoding => @config.params_encoding,
65
+ :timeout => @config.timeout,
66
+ :ssl_verifypeer => @config.verify_ssl,
67
+ :ssl_verifyhost => _verify_ssl_host,
68
+ :sslcert => @config.cert_file,
69
+ :sslkey => @config.key_file,
70
+ :verbose => @config.debugging
71
+ }
72
+
73
+ # set custom cert, if provided
74
+ req_opts[:cainfo] = @config.ssl_ca_cert if @config.ssl_ca_cert
75
+
76
+ if [:post, :patch, :put, :delete].include?(http_method)
77
+ req_body = build_request_body(header_params, form_params, opts[:body])
78
+ req_opts.update :body => req_body
79
+ if @config.debugging
80
+ @config.logger.debug "HTTP request body param ~BEGIN~\n#{req_body}\n~END~\n"
81
+ end
82
+ end
83
+
84
+ request = Typhoeus::Request.new(url, req_opts)
85
+ download_file(request) if opts[:return_type] == 'File'
86
+ request
87
+ end
88
+
89
+ # Builds the HTTP request body
90
+ #
91
+ # @param [Hash] header_params Header parameters
92
+ # @param [Hash] form_params Query parameters
93
+ # @param [Object] body HTTP body (JSON/XML)
94
+ # @return [String] HTTP body data in the form of string
95
+ def build_request_body(header_params, form_params, body)
96
+ # http form
97
+ if header_params['Content-Type'] == 'application/x-www-form-urlencoded' ||
98
+ header_params['Content-Type'] == 'multipart/form-data'
99
+ data = {}
100
+ form_params.each do |key, value|
101
+ case value
102
+ when ::File, ::Array, nil
103
+ # let typhoeus handle File, Array and nil parameters
104
+ data[key] = value
105
+ else
106
+ data[key] = value.to_s
107
+ end
108
+ end
109
+ elsif body
110
+ data = body.is_a?(String) ? body : body.to_json
111
+ else
112
+ data = nil
113
+ end
114
+ data
115
+ end
116
+
117
+ # Save response body into a file in (the defined) temporary folder, using the filename
118
+ # from the "Content-Disposition" header if provided, otherwise a random filename.
119
+ # The response body is written to the file in chunks in order to handle files which
120
+ # size is larger than maximum Ruby String or even larger than the maximum memory a Ruby
121
+ # process can use.
122
+ #
123
+ # @see Configuration#temp_folder_path
124
+ def download_file(request)
125
+ tempfile = nil
126
+ encoding = nil
127
+ request.on_headers do |response|
128
+ content_disposition = response.headers['Content-Disposition']
129
+ if content_disposition && content_disposition =~ /filename=/i
130
+ filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1]
131
+ prefix = sanitize_filename(filename)
132
+ else
133
+ prefix = 'download-'
134
+ end
135
+ prefix = prefix + '-' unless prefix.end_with?('-')
136
+ encoding = response.body.encoding
137
+ tempfile = Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding)
138
+ @tempfile = tempfile
139
+ end
140
+ request.on_body do |chunk|
141
+ chunk.force_encoding(encoding)
142
+ tempfile.write(chunk)
143
+ end
144
+ request.on_complete do |response|
145
+ if tempfile
146
+ tempfile.close
147
+ @config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\
148
+ "with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\
149
+ "will be deleted automatically with GC. It's also recommended to delete the temp file "\
150
+ "explicitly with `tempfile.delete`"
151
+ end
152
+ end
153
+ end
@@ -0,0 +1,118 @@
1
+ # {{moduleName}}::{{classname}}{{#description}}
2
+
3
+ {{.}}{{/description}}
4
+
5
+ All URIs are relative to *{{basePath}}*
6
+
7
+ | Method | HTTP request | Description |
8
+ | ------ | ------------ | ----------- |
9
+ {{#operations}}
10
+ {{#operation}}
11
+ | [**{{operationId}}**]({{classname}}.md#{{operationId}}) | **{{httpMethod}}** {{path}} | {{summary}} |
12
+ {{/operation}}
13
+ {{/operations}}
14
+
15
+ {{#operations}}
16
+ {{#operation}}
17
+
18
+ ## {{operationId}}
19
+
20
+ > {{#returnType}}{{#returnTypeIsPrimitive}}{{returnType}}{{/returnTypeIsPrimitive}}{{^returnTypeIsPrimitive}}<{{{returnType}}}>{{/returnTypeIsPrimitive}} {{/returnType}}{{operationId}}{{#hasParams}}({{#requiredParams}}{{{paramName}}}{{^-last}}, {{/-last}}{{/requiredParams}}{{#optionalParams}}{{#-last}}{{#hasRequiredParams}}, {{/hasRequiredParams}}opts{{/-last}}{{/optionalParams}}){{/hasParams}}
21
+
22
+ {{{summary}}}{{#notes}}
23
+
24
+ {{{.}}}{{/notes}}
25
+
26
+ ### Examples
27
+
28
+ ```ruby
29
+ require 'time'
30
+ require '{{{gemName}}}'
31
+ {{#hasAuthMethods}}
32
+ # setup authorization
33
+ {{{moduleName}}}.configure do |config|{{#authMethods}}{{#isBasic}}{{#isBasicBasic}}
34
+ # Configure HTTP basic authorization: {{{name}}}
35
+ config.username = 'YOUR USERNAME'
36
+ config.password = 'YOUR PASSWORD'{{/isBasicBasic}}{{#isBasicBearer}}
37
+ # Configure Bearer authorization{{#bearerFormat}} ({{{.}}}){{/bearerFormat}}: {{{name}}}
38
+ config.access_token = 'YOUR_BEARER_TOKEN'{{/isBasicBearer}}{{/isBasic}}{{#isApiKey}}
39
+ # Configure API key authorization: {{{name}}}
40
+ config.api_key['{{{name}}}'] = 'YOUR API KEY'
41
+ # Uncomment the following line to set a prefix for the API key, e.g. 'Bearer' (defaults to nil)
42
+ # config.api_key_prefix['{{{name}}}'] = 'Bearer'{{/isApiKey}}{{#isOAuth}}
43
+ # Configure OAuth2 access token for authorization: {{{name}}}
44
+ config.access_token = 'YOUR ACCESS TOKEN'{{/isOAuth}}
45
+ {{/authMethods}}end
46
+ {{/hasAuthMethods}}
47
+
48
+ api_instance = {{{moduleName}}}::{{{classname}}}.new
49
+ {{#requiredParams}}
50
+ {{{paramName}}} = {{{vendorExtensions.x-ruby-example}}} # {{{dataType}}} | {{{description}}}
51
+ {{/requiredParams}}
52
+ {{#optionalParams}}
53
+ {{#-first}}
54
+ opts = {
55
+ {{/-first}}
56
+ {{{paramName}}}: {{{vendorExtensions.x-ruby-example}}}{{^-last}},{{/-last}} # {{{dataType}}} | {{{description}}}
57
+ {{#-last}}
58
+ }
59
+ {{/-last}}
60
+ {{/optionalParams}}
61
+
62
+ begin
63
+ {{#summary}}# {{{.}}}{{/summary}}
64
+ {{#returnType}}result = {{/returnType}}api_instance.{{{operationId}}}{{#hasParams}}({{#requiredParams}}{{{paramName}}}{{^-last}}, {{/-last}}{{/requiredParams}}{{#optionalParams}}{{#-last}}{{#hasRequiredParams}}, {{/hasRequiredParams}}opts{{/-last}}{{/optionalParams}}){{/hasParams}}
65
+ {{#returnType}}
66
+ p result
67
+ {{/returnType}}
68
+ rescue {{{moduleName}}}::ApiError => e
69
+ puts "Error when calling {{classname}}->{{{operationId}}}: #{e}"
70
+ end
71
+ ```
72
+
73
+ #### Using the {{operationId}}_with_http_info variant
74
+
75
+ This returns an Array which contains the response data{{^returnType}} (`nil` in this case){{/returnType}}, status code and headers.
76
+
77
+ > <Array({{#returnType}}{{#returnTypeIsPrimitive}}{{returnType}}{{/returnTypeIsPrimitive}}{{^returnTypeIsPrimitive}}<{{{returnType}}}>{{/returnTypeIsPrimitive}}{{/returnType}}{{^returnType}}nil{{/returnType}}, Integer, Hash)> {{operationId}}_with_http_info{{#hasParams}}({{#requiredParams}}{{{paramName}}}{{^-last}}, {{/-last}}{{/requiredParams}}{{#optionalParams}}{{#-last}}{{#hasRequiredParams}}, {{/hasRequiredParams}}opts{{/-last}}{{/optionalParams}}){{/hasParams}}
78
+
79
+ ```ruby
80
+ begin
81
+ {{#summary}}# {{{.}}}{{/summary}}
82
+ data, status_code, headers = api_instance.{{{operationId}}}_with_http_info{{#hasParams}}({{#requiredParams}}{{{paramName}}}{{^-last}}, {{/-last}}{{/requiredParams}}{{#optionalParams}}{{#-last}}{{#hasRequiredParams}}, {{/hasRequiredParams}}opts{{/-last}}{{/optionalParams}}){{/hasParams}}
83
+ p status_code # => 2xx
84
+ p headers # => { ... }
85
+ p data # => {{#returnType}}{{#returnTypeIsPrimitive}}{{returnType}}{{/returnTypeIsPrimitive}}{{^returnTypeIsPrimitive}}<{{{returnType}}}>{{/returnTypeIsPrimitive}}{{/returnType}}{{^returnType}}nil{{/returnType}}
86
+ rescue {{{moduleName}}}::ApiError => e
87
+ puts "Error when calling {{classname}}->{{{operationId}}}_with_http_info: #{e}"
88
+ end
89
+ ```
90
+
91
+ ### Parameters
92
+
93
+ {{^allParams}}
94
+ This endpoint does not need any parameter.
95
+ {{/allParams}}
96
+ {{#allParams}}
97
+ {{#-first}}
98
+ | Name | Type | Description | Notes |
99
+ | ---- | ---- | ----------- | ----- |
100
+ {{/-first}}
101
+ | **{{paramName}}** | {{#isPrimitiveType}}**{{dataType}}**{{/isPrimitiveType}}{{^isPrimitiveType}}{{#isFile}}**{{dataType}}**{{/isFile}}{{^isFile}}[**{{dataType}}**]({{baseType}}.md){{/isFile}}{{/isPrimitiveType}} | {{description}} | {{^required}}[optional]{{/required}}{{#defaultValue}}[default to {{.}}]{{/defaultValue}} |
102
+ {{/allParams}}
103
+
104
+ ### Return type
105
+
106
+ {{#returnType}}{{#returnTypeIsPrimitive}}**{{returnType}}**{{/returnTypeIsPrimitive}}{{^returnTypeIsPrimitive}}[**{{returnType}}**]({{returnBaseType}}.md){{/returnTypeIsPrimitive}}{{/returnType}}{{^returnType}}nil (empty response body){{/returnType}}
107
+
108
+ ### Authorization
109
+
110
+ {{^authMethods}}No authorization required{{/authMethods}}{{#authMethods}}[{{name}}](../README.md#{{name}}){{^-last}}, {{/-last}}{{/authMethods}}
111
+
112
+ ### HTTP request headers
113
+
114
+ - **Content-Type**: {{#consumes}}{{{mediaType}}}{{^-last}}, {{/-last}}{{/consumes}}{{^consumes}}Not defined{{/consumes}}
115
+ - **Accept**: {{#produces}}{{{mediaType}}}{{^-last}}, {{/-last}}{{/produces}}{{^produces}}Not defined{{/produces}}
116
+
117
+ {{/operation}}
118
+ {{/operations}}
@@ -0,0 +1,49 @@
1
+ =begin
2
+ {{> api_info}}
3
+ =end
4
+
5
+ module {{moduleName}}
6
+ class ApiError < StandardError
7
+ attr_reader :code, :response_headers, :response_body
8
+
9
+ # Usage examples:
10
+ # ApiError.new
11
+ # ApiError.new("message")
12
+ # ApiError.new(:code => 500, :response_headers => {}, :response_body => "")
13
+ # ApiError.new(:code => 404, :message => "Not Found")
14
+ def initialize(arg = nil)
15
+ if arg.is_a? Hash
16
+ if arg.key?(:message) || arg.key?('message')
17
+ super(arg[:message] || arg['message'])
18
+ else
19
+ super arg
20
+ end
21
+
22
+ arg.each do |k, v|
23
+ instance_variable_set "@#{k}", v
24
+ end
25
+ else
26
+ super arg
27
+ end
28
+ end
29
+
30
+ # Override to_s to display a friendly error message
31
+ def to_s
32
+ message
33
+ end
34
+
35
+ def message
36
+ if @message.nil?
37
+ msg = "Error message: the server returns an error"
38
+ else
39
+ msg = @message
40
+ end
41
+
42
+ msg += "\nHTTP status code: #{code}" if code
43
+ msg += "\nResponse headers: #{response_headers}" if response_headers
44
+ msg += "\nResponse body: #{response_body}" if response_body
45
+
46
+ msg
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,12 @@
1
+ {{#appName}}
2
+ #{{{.}}}
3
+
4
+ {{/appName}}
5
+ {{#appDescription}}
6
+ #{{{.}}}
7
+
8
+ {{/appDescription}}
9
+ {{#version}}The version of the OpenAPI document: {{.}}{{/version}}
10
+ {{#infoEmail}}Contact: {{{.}}}{{/infoEmail}}
11
+ Generated by: https://openapi-generator.tech
12
+ OpenAPI Generator version: {{{generatorVersion}}}
@@ -0,0 +1,47 @@
1
+ =begin
2
+ {{> api_info}}
3
+ =end
4
+
5
+ require 'spec_helper'
6
+ require 'json'
7
+
8
+ # Unit tests for {{moduleName}}::{{classname}}
9
+ # Automatically generated by openapi-generator (https://openapi-generator.tech)
10
+ # Please update as you see appropriate
11
+ {{#operations}}describe '{{classname}}' do
12
+ before do
13
+ # run before each test
14
+ @api_instance = {{moduleName}}::{{classname}}.new
15
+ end
16
+
17
+ after do
18
+ # run after each test
19
+ end
20
+
21
+ describe 'test an instance of {{classname}}' do
22
+ it 'should create an instance of {{classname}}' do
23
+ expect(@api_instance).to be_instance_of({{moduleName}}::{{classname}})
24
+ end
25
+ end
26
+
27
+ {{#operation}}
28
+ # unit tests for {{operationId}}
29
+ {{#summary}}
30
+ # {{.}}
31
+ {{/summary}}
32
+ {{#notes}}
33
+ # {{.}}
34
+ {{/notes}}
35
+ {{#allParams}}{{#required}} # @param {{paramName}} {{description}}
36
+ {{/required}}{{/allParams}} # @param [Hash] opts the optional parameters
37
+ {{#allParams}}{{^required}} # @option opts [{{{dataType}}}] :{{paramName}} {{description}}
38
+ {{/required}}{{/allParams}} # @return [{{{returnType}}}{{^returnType}}nil{{/returnType}}]
39
+ describe '{{operationId}} test' do
40
+ it 'should work' do
41
+ # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers
42
+ end
43
+ end
44
+
45
+ {{/operation}}
46
+ end
47
+ {{/operations}}
@@ -0,0 +1,120 @@
1
+ # Builds the object from hash
2
+ # @param [Hash] attributes Model attributes in the form of hash
3
+ # @return [Object] Returns the model itself
4
+ def self.build_from_hash(attributes)
5
+ new.build_from_hash(attributes)
6
+ end
7
+
8
+ # Builds the object from hash
9
+ # @param [Hash] attributes Model attributes in the form of hash
10
+ # @return [Object] Returns the model itself
11
+ def build_from_hash(attributes)
12
+ return nil unless attributes.is_a?(Hash)
13
+ {{#parent}}
14
+ super(attributes)
15
+ {{/parent}}
16
+ self.class.openapi_types.each_pair do |key, type|
17
+ if attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key)
18
+ self.send("#{key}=", nil)
19
+ elsif type =~ /\AArray<(.*)>/i
20
+ # check to ensure the input is an array given that the attribute
21
+ # is documented as an array but the input is not
22
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
23
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
24
+ end
25
+ elsif !attributes[self.class.attribute_map[key]].nil?
26
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
27
+ end
28
+ end
29
+
30
+ self
31
+ end
32
+
33
+ # Deserializes the data based on type
34
+ # @param string type Data type
35
+ # @param string value Value to be deserialized
36
+ # @return [Object] Deserialized data
37
+ def _deserialize(type, value)
38
+ case type.to_sym
39
+ when :Time
40
+ Time.parse(value)
41
+ when :Date
42
+ Date.parse(value)
43
+ when :String
44
+ value.to_s
45
+ when :Integer
46
+ value.to_i
47
+ when :Float
48
+ value.to_f
49
+ when :Boolean
50
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
51
+ true
52
+ else
53
+ false
54
+ end
55
+ when :Object
56
+ # generic object (usually a Hash), return directly
57
+ value
58
+ when /\AArray<(?<inner_type>.+)>\z/
59
+ inner_type = Regexp.last_match[:inner_type]
60
+ value.map { |v| _deserialize(inner_type, v) }
61
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
62
+ k_type = Regexp.last_match[:k_type]
63
+ v_type = Regexp.last_match[:v_type]
64
+ {}.tap do |hash|
65
+ value.each do |k, v|
66
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
67
+ end
68
+ end
69
+ else # model
70
+ # models (e.g. Pet) or oneOf
71
+ klass = {{moduleName}}.const_get(type)
72
+ klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
73
+ end
74
+ end
75
+
76
+ # Returns the string representation of the object
77
+ # @return [String] String presentation of the object
78
+ def to_s
79
+ to_hash.to_s
80
+ end
81
+
82
+ # to_body is an alias to to_hash (backward compatibility)
83
+ # @return [Hash] Returns the object in the form of hash
84
+ def to_body
85
+ to_hash
86
+ end
87
+
88
+ # Returns the object in the form of hash
89
+ # @return [Hash] Returns the object in the form of hash
90
+ def to_hash
91
+ hash = {{^parent}}{}{{/parent}}{{#parent}}super{{/parent}}
92
+ self.class.attribute_map.each_pair do |attr, param|
93
+ value = self.send(attr)
94
+ if value.nil?
95
+ is_nullable = self.class.openapi_nullable.include?(attr)
96
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
97
+ end
98
+
99
+ hash[param] = _to_hash(value)
100
+ end
101
+ hash
102
+ end
103
+
104
+ # Outputs non-array value in the form of hash
105
+ # For object, use to_hash. Otherwise, just return the value
106
+ # @param [Object] value Any valid value
107
+ # @return [Hash] Returns the value in the form of hash
108
+ def _to_hash(value)
109
+ if value.is_a?(Array)
110
+ value.compact.map { |v| _to_hash(v) }
111
+ elsif value.is_a?(Hash)
112
+ {}.tap do |hash|
113
+ value.each { |k, v| hash[k] = _to_hash(v) }
114
+ end
115
+ elsif value.respond_to? :to_hash
116
+ value.to_hash
117
+ else
118
+ value
119
+ end
120
+ end