mux_ruby 1.8.1 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (288) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +3 -1
  3. data/Gemfile.lock +26 -37
  4. data/README.md +37 -13
  5. data/docs/AbridgedVideoView.md +33 -13
  6. data/docs/Asset.md +59 -25
  7. data/docs/AssetErrors.md +15 -4
  8. data/docs/AssetMaster.md +15 -4
  9. data/docs/AssetNonStandardInputReasons.md +29 -11
  10. data/docs/AssetRecordingTimes.md +15 -4
  11. data/docs/AssetResponse.md +13 -3
  12. data/docs/AssetStaticRenditions.md +15 -4
  13. data/docs/AssetStaticRenditionsFiles.md +23 -8
  14. data/docs/AssetsApi.md +396 -161
  15. data/docs/BreakdownValue.md +21 -7
  16. data/docs/CreateAssetRequest.md +27 -10
  17. data/docs/CreateLiveStreamRequest.md +27 -9
  18. data/docs/CreatePlaybackIDRequest.md +13 -3
  19. data/docs/CreatePlaybackIDResponse.md +13 -3
  20. data/docs/CreateSimulcastTargetRequest.md +17 -5
  21. data/docs/CreateTrackRequest.md +25 -9
  22. data/docs/CreateTrackResponse.md +13 -3
  23. data/docs/CreateUploadRequest.md +19 -6
  24. data/docs/DeliveryReport.md +27 -9
  25. data/docs/DeliveryUsageApi.md +41 -23
  26. data/docs/DimensionValue.md +15 -4
  27. data/docs/DimensionsApi.md +72 -34
  28. data/docs/DirectUploadsApi.md +131 -56
  29. data/docs/DisableLiveStreamResponse.md +13 -3
  30. data/docs/EnableLiveStreamResponse.md +13 -3
  31. data/docs/Error.md +27 -10
  32. data/docs/ErrorsApi.md +38 -20
  33. data/docs/ExportDate.md +20 -0
  34. data/docs/ExportFile.md +22 -0
  35. data/docs/ExportsApi.md +99 -12
  36. data/docs/FilterValue.md +15 -4
  37. data/docs/FiltersApi.md +71 -33
  38. data/docs/GetAssetInputInfoResponse.md +13 -3
  39. data/docs/GetAssetOrLiveStreamIdResponse.md +18 -0
  40. data/docs/GetAssetOrLiveStreamIdResponseData.md +22 -0
  41. data/docs/GetAssetOrLiveStreamIdResponseDataObject.md +20 -0
  42. data/docs/GetAssetPlaybackIDResponse.md +13 -3
  43. data/docs/GetMetricTimeseriesDataResponse.md +17 -5
  44. data/docs/GetOverallValuesResponse.md +17 -5
  45. data/docs/GetRealTimeBreakdownResponse.md +17 -5
  46. data/docs/GetRealTimeHistogramTimeseriesResponse.md +19 -6
  47. data/docs/GetRealTimeHistogramTimeseriesResponseMeta.md +13 -3
  48. data/docs/GetRealTimeTimeseriesResponse.md +17 -5
  49. data/docs/Incident.md +53 -23
  50. data/docs/IncidentBreakdown.md +17 -5
  51. data/docs/IncidentNotification.md +17 -5
  52. data/docs/IncidentNotificationRule.md +21 -7
  53. data/docs/IncidentResponse.md +15 -4
  54. data/docs/IncidentsApi.md +118 -62
  55. data/docs/InputFile.md +15 -4
  56. data/docs/InputInfo.md +15 -4
  57. data/docs/InputSettings.md +31 -10
  58. data/docs/InputSettingsOverlaySettings.md +25 -9
  59. data/docs/InputTrack.md +29 -11
  60. data/docs/Insight.md +23 -8
  61. data/docs/ListAllMetricValuesResponse.md +17 -5
  62. data/docs/ListAssetsResponse.md +13 -3
  63. data/docs/ListBreakdownValuesResponse.md +17 -5
  64. data/docs/ListDeliveryUsageResponse.md +19 -6
  65. data/docs/ListDimensionValuesResponse.md +17 -5
  66. data/docs/ListDimensionsResponse.md +17 -5
  67. data/docs/ListErrorsResponse.md +17 -5
  68. data/docs/ListExportsResponse.md +17 -5
  69. data/docs/ListFilterValuesResponse.md +17 -5
  70. data/docs/ListFiltersResponse.md +17 -5
  71. data/docs/ListFiltersResponseData.md +15 -4
  72. data/docs/ListIncidentsResponse.md +17 -5
  73. data/docs/ListInsightsResponse.md +17 -5
  74. data/docs/ListLiveStreamsResponse.md +13 -3
  75. data/docs/ListRealTimeDimensionsResponse.md +17 -5
  76. data/docs/ListRealTimeDimensionsResponseData.md +15 -4
  77. data/docs/ListRealTimeMetricsResponse.md +17 -5
  78. data/docs/ListRelatedIncidentsResponse.md +17 -5
  79. data/docs/ListSigningKeysResponse.md +13 -3
  80. data/docs/ListUploadsResponse.md +13 -3
  81. data/docs/ListVideoViewExportsResponse.md +22 -0
  82. data/docs/ListVideoViewsResponse.md +17 -5
  83. data/docs/LiveStream.md +39 -15
  84. data/docs/LiveStreamResponse.md +13 -3
  85. data/docs/LiveStreamsApi.md +418 -170
  86. data/docs/Metric.md +21 -7
  87. data/docs/MetricsApi.md +211 -117
  88. data/docs/NotificationRule.md +17 -5
  89. data/docs/OverallValues.md +19 -6
  90. data/docs/PlaybackID.md +15 -4
  91. data/docs/PlaybackIDApi.md +78 -0
  92. data/docs/PlaybackPolicy.md +10 -2
  93. data/docs/RealTimeApi.md +177 -81
  94. data/docs/RealTimeBreakdownValue.md +21 -7
  95. data/docs/RealTimeHistogramTimeseriesBucket.md +15 -4
  96. data/docs/RealTimeHistogramTimeseriesBucketValues.md +15 -4
  97. data/docs/RealTimeHistogramTimeseriesDatapoint.md +25 -9
  98. data/docs/RealTimeTimeseriesDatapoint.md +17 -5
  99. data/docs/Score.md +23 -8
  100. data/docs/SignalLiveStreamCompleteResponse.md +13 -3
  101. data/docs/SigningKey.md +17 -5
  102. data/docs/SigningKeyResponse.md +13 -3
  103. data/docs/SimulcastTarget.md +21 -7
  104. data/docs/SimulcastTargetResponse.md +13 -3
  105. data/docs/Track.md +37 -15
  106. data/docs/URLSigningKeysApi.md +130 -54
  107. data/docs/UpdateAssetMP4SupportRequest.md +13 -3
  108. data/docs/UpdateAssetMasterAccessRequest.md +13 -3
  109. data/docs/Upload.md +29 -11
  110. data/docs/UploadError.md +15 -4
  111. data/docs/UploadResponse.md +13 -3
  112. data/docs/VideoView.md +251 -114
  113. data/docs/VideoViewEvent.md +19 -6
  114. data/docs/VideoViewResponse.md +15 -4
  115. data/docs/VideoViewsApi.md +78 -41
  116. data/examples/video/exercise-assets.rb +21 -0
  117. data/examples/video/exercise-live-streams.rb +8 -0
  118. data/gen/.gitignore +7 -0
  119. data/gen/Makefile +31 -0
  120. data/gen/generator-config.json +11 -0
  121. data/gen/openapitools.json +7 -0
  122. data/gen/package.json +17 -0
  123. data/gen/templates/Gemfile.mustache +11 -0
  124. data/gen/templates/README.mustache +158 -0
  125. data/gen/templates/Rakefile.mustache +10 -0
  126. data/gen/templates/api.mustache +206 -0
  127. data/gen/templates/api_client.mustache +264 -0
  128. data/gen/templates/api_client_faraday_partial.mustache +138 -0
  129. data/gen/templates/api_client_spec.mustache +220 -0
  130. data/gen/templates/api_client_typhoeus_partial.mustache +183 -0
  131. data/gen/templates/api_doc.mustache +118 -0
  132. data/gen/templates/api_error.mustache +67 -0
  133. data/gen/templates/api_info.mustache +12 -0
  134. data/gen/templates/api_test.mustache +47 -0
  135. data/gen/templates/base_object.mustache +120 -0
  136. data/gen/templates/configuration.mustache +349 -0
  137. data/gen/templates/configuration_spec.mustache +34 -0
  138. data/gen/templates/configuration_tls_faraday_partial.mustache +29 -0
  139. data/gen/templates/configuration_tls_typhoeus_partial.mustache +34 -0
  140. data/gen/templates/gem.mustache +40 -0
  141. data/gen/templates/gemspec.mustache +35 -0
  142. data/gen/templates/gitignore.mustache +39 -0
  143. data/gen/templates/model.mustache +26 -0
  144. data/gen/templates/model_doc.mustache +12 -0
  145. data/gen/templates/model_test.mustache +77 -0
  146. data/gen/templates/partial_model_enum_class.mustache +20 -0
  147. data/gen/templates/partial_model_generic.mustache +371 -0
  148. data/gen/templates/partial_model_generic_doc.mustache +28 -0
  149. data/gen/templates/partial_oneof_module.mustache +137 -0
  150. data/gen/templates/partial_oneof_module_doc.mustache +92 -0
  151. data/gen/templates/rspec.mustache +2 -0
  152. data/gen/templates/rubocop.mustache +148 -0
  153. data/gen/templates/spec_helper.mustache +103 -0
  154. data/gen/templates/version.mustache +7 -0
  155. data/gen/yarn.lock +1878 -0
  156. data/lib/mux_ruby.rb +16 -2
  157. data/lib/mux_ruby/api/assets_api.rb +291 -152
  158. data/lib/mux_ruby/api/delivery_usage_api.rb +32 -16
  159. data/lib/mux_ruby/api/dimensions_api.rb +55 -29
  160. data/lib/mux_ruby/api/direct_uploads_api.rb +90 -44
  161. data/lib/mux_ruby/api/errors_api.rb +34 -18
  162. data/lib/mux_ruby/api/exports_api.rb +86 -13
  163. data/lib/mux_ruby/api/filters_api.rb +53 -27
  164. data/lib/mux_ruby/api/incidents_api.rb +94 -52
  165. data/lib/mux_ruby/api/live_streams_api.rb +299 -157
  166. data/lib/mux_ruby/api/metrics_api.rb +193 -122
  167. data/lib/mux_ruby/api/playback_id_api.rb +85 -0
  168. data/lib/mux_ruby/api/real_time_api.rb +149 -87
  169. data/lib/mux_ruby/api/url_signing_keys_api.rb +95 -48
  170. data/lib/mux_ruby/api/video_views_api.rb +60 -33
  171. data/lib/mux_ruby/api_client.rb +106 -91
  172. data/lib/mux_ruby/api_error.rb +35 -7
  173. data/lib/mux_ruby/configuration.rb +50 -14
  174. data/lib/mux_ruby/models/abridged_video_view.rb +58 -24
  175. data/lib/mux_ruby/models/asset.rb +129 -58
  176. data/lib/mux_ruby/models/asset_errors.rb +52 -15
  177. data/lib/mux_ruby/models/asset_master.rb +85 -15
  178. data/lib/mux_ruby/models/asset_non_standard_input_reasons.rb +78 -43
  179. data/lib/mux_ruby/models/asset_recording_times.rb +52 -18
  180. data/lib/mux_ruby/models/asset_response.rb +48 -14
  181. data/lib/mux_ruby/models/asset_static_renditions.rb +55 -19
  182. data/lib/mux_ruby/models/asset_static_renditions_files.rb +60 -25
  183. data/lib/mux_ruby/models/breakdown_value.rb +52 -18
  184. data/lib/mux_ruby/models/create_asset_request.rb +70 -30
  185. data/lib/mux_ruby/models/create_live_stream_request.rb +68 -23
  186. data/lib/mux_ruby/models/create_playback_id_request.rb +48 -14
  187. data/lib/mux_ruby/models/create_playback_id_response.rb +48 -14
  188. data/lib/mux_ruby/models/create_simulcast_target_request.rb +50 -16
  189. data/lib/mux_ruby/models/create_track_request.rb +65 -27
  190. data/lib/mux_ruby/models/create_track_response.rb +48 -14
  191. data/lib/mux_ruby/models/create_upload_request.rb +52 -18
  192. data/lib/mux_ruby/models/delivery_report.rb +106 -21
  193. data/lib/mux_ruby/models/dimension_value.rb +49 -15
  194. data/lib/mux_ruby/models/disable_live_stream_response.rb +48 -14
  195. data/lib/mux_ruby/models/enable_live_stream_response.rb +48 -14
  196. data/lib/mux_ruby/models/error.rb +63 -21
  197. data/lib/mux_ruby/models/export_date.rb +229 -0
  198. data/lib/mux_ruby/models/export_file.rb +236 -0
  199. data/lib/mux_ruby/models/filter_value.rb +49 -15
  200. data/lib/mux_ruby/models/get_asset_input_info_response.rb +48 -14
  201. data/lib/mux_ruby/models/get_asset_or_live_stream_id_response.rb +218 -0
  202. data/lib/mux_ruby/models/get_asset_or_live_stream_id_response_data.rb +237 -0
  203. data/lib/mux_ruby/models/get_asset_or_live_stream_id_response_data_object.rb +264 -0
  204. data/lib/mux_ruby/models/get_asset_playback_id_response.rb +48 -14
  205. data/lib/mux_ruby/models/get_metric_timeseries_data_response.rb +50 -16
  206. data/lib/mux_ruby/models/get_overall_values_response.rb +50 -16
  207. data/lib/mux_ruby/models/get_real_time_breakdown_response.rb +50 -16
  208. data/lib/mux_ruby/models/get_real_time_histogram_timeseries_response.rb +51 -17
  209. data/lib/mux_ruby/models/get_real_time_histogram_timeseries_response_meta.rb +48 -14
  210. data/lib/mux_ruby/models/get_real_time_timeseries_response.rb +50 -16
  211. data/lib/mux_ruby/models/incident.rb +68 -34
  212. data/lib/mux_ruby/models/incident_breakdown.rb +50 -16
  213. data/lib/mux_ruby/models/incident_notification.rb +50 -16
  214. data/lib/mux_ruby/models/incident_notification_rule.rb +52 -18
  215. data/lib/mux_ruby/models/incident_response.rb +49 -15
  216. data/lib/mux_ruby/models/input_file.rb +49 -15
  217. data/lib/mux_ruby/models/input_info.rb +49 -15
  218. data/lib/mux_ruby/models/input_settings.rb +91 -30
  219. data/lib/mux_ruby/models/input_settings_overlay_settings.rb +68 -26
  220. data/lib/mux_ruby/models/input_track.rb +56 -22
  221. data/lib/mux_ruby/models/insight.rb +53 -19
  222. data/lib/mux_ruby/models/list_all_metric_values_response.rb +50 -16
  223. data/lib/mux_ruby/models/list_assets_response.rb +48 -14
  224. data/lib/mux_ruby/models/list_breakdown_values_response.rb +50 -16
  225. data/lib/mux_ruby/models/list_delivery_usage_response.rb +51 -17
  226. data/lib/mux_ruby/models/list_dimension_values_response.rb +50 -16
  227. data/lib/mux_ruby/models/list_dimensions_response.rb +50 -16
  228. data/lib/mux_ruby/models/list_errors_response.rb +50 -16
  229. data/lib/mux_ruby/models/list_exports_response.rb +50 -16
  230. data/lib/mux_ruby/models/list_filter_values_response.rb +50 -16
  231. data/lib/mux_ruby/models/list_filters_response.rb +50 -16
  232. data/lib/mux_ruby/models/list_filters_response_data.rb +49 -15
  233. data/lib/mux_ruby/models/list_incidents_response.rb +50 -16
  234. data/lib/mux_ruby/models/list_insights_response.rb +50 -16
  235. data/lib/mux_ruby/models/list_live_streams_response.rb +48 -14
  236. data/lib/mux_ruby/models/list_real_time_dimensions_response.rb +50 -16
  237. data/lib/mux_ruby/models/list_real_time_dimensions_response_data.rb +49 -15
  238. data/lib/mux_ruby/models/list_real_time_metrics_response.rb +50 -16
  239. data/lib/mux_ruby/models/list_related_incidents_response.rb +50 -16
  240. data/lib/mux_ruby/models/list_signing_keys_response.rb +48 -14
  241. data/lib/mux_ruby/models/list_uploads_response.rb +48 -14
  242. data/lib/mux_ruby/models/list_video_view_exports_response.rb +240 -0
  243. data/lib/mux_ruby/models/list_video_views_response.rb +50 -16
  244. data/lib/mux_ruby/models/live_stream.rb +121 -29
  245. data/lib/mux_ruby/models/live_stream_response.rb +48 -14
  246. data/lib/mux_ruby/models/metric.rb +52 -18
  247. data/lib/mux_ruby/models/notification_rule.rb +50 -16
  248. data/lib/mux_ruby/models/overall_values.rb +51 -17
  249. data/lib/mux_ruby/models/playback_id.rb +50 -15
  250. data/lib/mux_ruby/models/playback_policy.rb +12 -6
  251. data/lib/mux_ruby/models/real_time_breakdown_value.rb +52 -18
  252. data/lib/mux_ruby/models/real_time_histogram_timeseries_bucket.rb +50 -16
  253. data/lib/mux_ruby/models/real_time_histogram_timeseries_bucket_values.rb +49 -15
  254. data/lib/mux_ruby/models/real_time_histogram_timeseries_datapoint.rb +54 -20
  255. data/lib/mux_ruby/models/real_time_timeseries_datapoint.rb +50 -16
  256. data/lib/mux_ruby/models/score.rb +53 -19
  257. data/lib/mux_ruby/models/signal_live_stream_complete_response.rb +48 -14
  258. data/lib/mux_ruby/models/signing_key.rb +53 -16
  259. data/lib/mux_ruby/models/signing_key_response.rb +48 -14
  260. data/lib/mux_ruby/models/simulcast_target.rb +55 -21
  261. data/lib/mux_ruby/models/simulcast_target_response.rb +48 -14
  262. data/lib/mux_ruby/models/track.rb +92 -33
  263. data/lib/mux_ruby/models/update_asset_master_access_request.rb +51 -17
  264. data/lib/mux_ruby/models/update_asset_mp4_support_request.rb +51 -17
  265. data/lib/mux_ruby/models/upload.rb +62 -26
  266. data/lib/mux_ruby/models/upload_error.rb +51 -15
  267. data/lib/mux_ruby/models/upload_response.rb +48 -14
  268. data/lib/mux_ruby/models/video_view.rb +242 -136
  269. data/lib/mux_ruby/models/video_view_event.rb +51 -17
  270. data/lib/mux_ruby/models/video_view_response.rb +49 -15
  271. data/lib/mux_ruby/version.rb +10 -3
  272. data/mux_ruby.gemspec +15 -15
  273. data/spec/api/assets_api_spec.rb +2 -0
  274. data/spec/api/playback_id_api_spec.rb +40 -0
  275. data/spec/api_client_spec.rb +10 -3
  276. data/spec/configuration_spec.rb +9 -2
  277. data/spec/models/asset_master_spec.rb +4 -0
  278. data/spec/models/asset_spec.rb +10 -0
  279. data/spec/models/export_date_spec.rb +40 -0
  280. data/spec/models/export_file_spec.rb +46 -0
  281. data/spec/models/get_asset_or_live_stream_id_response_data_object_spec.rb +44 -0
  282. data/spec/models/get_asset_or_live_stream_id_response_data_spec.rb +46 -0
  283. data/spec/models/get_asset_or_live_stream_id_response_spec.rb +34 -0
  284. data/spec/models/input_settings_spec.rb +12 -0
  285. data/spec/models/list_video_view_exports_response_spec.rb +46 -0
  286. data/spec/models/track_spec.rb +4 -0
  287. data/spec/spec_helper.rb +9 -2
  288. metadata +161 -235
@@ -0,0 +1,28 @@
1
+ # {{moduleName}}::{{classname}}
2
+
3
+ ## Properties
4
+
5
+ | Name | Type | Description | Notes |
6
+ | ---- | ---- | ----------- | ----- |
7
+ {{#vars}}
8
+ | **{{name}}** | {{#isPrimitiveType}}**{{dataType}}**{{/isPrimitiveType}}{{^isPrimitiveType}}[**{{dataType}}**]({{complexType}}.md){{/isPrimitiveType}} | {{description}} | {{^required}}[optional]{{/required}}{{#isReadOnly}}[readonly]{{/isReadOnly}}{{#defaultValue}}[default to {{defaultValue}}]{{/defaultValue}} |
9
+ {{/vars}}
10
+
11
+ ## Example
12
+
13
+ ```ruby
14
+ require '{{{gemName}}}'
15
+
16
+ {{^vars}}
17
+ instance = {{moduleName}}::{{classname}}.new()
18
+ {{/vars}}
19
+ {{#vars}}
20
+ {{#-first}}
21
+ instance = {{moduleName}}::{{classname}}.new(
22
+ {{/-first}}
23
+ {{name}}: {{example}}{{^-last}},{{/-last}}
24
+ {{#-last}}
25
+ )
26
+ {{/-last}}
27
+ {{/vars}}
28
+ ```
@@ -0,0 +1,137 @@
1
+ {{#description}}
2
+ # {{{description}}}
3
+ {{/description}}
4
+ module {{classname}}
5
+ class << self
6
+ {{#oneOf}}
7
+ {{#-first}}
8
+ # List of class defined in oneOf (OpenAPI v3)
9
+ def openapi_one_of
10
+ [
11
+ {{/-first}}
12
+ :'{{{.}}}'{{^-last}},{{/-last}}
13
+ {{#-last}}
14
+ ]
15
+ end
16
+
17
+ {{/-last}}
18
+ {{/oneOf}}
19
+ {{#discriminator}}
20
+ {{#propertyName}}
21
+ # Discriminator's property name (OpenAPI v3)
22
+ def openapi_discriminator_name
23
+ :'{{{.}}}'
24
+ end
25
+
26
+ {{/propertyName}}
27
+ {{#mappedModels}}
28
+ {{#-first}}
29
+ # Discriminator's mapping (OpenAPI v3)
30
+ def openapi_discriminator_mapping
31
+ {
32
+ {{/-first}}
33
+ :'{{{mappingName}}}' => :'{{{modelName}}}'{{^-last}},{{/-last}}
34
+ {{#-last}}
35
+ }
36
+ end
37
+
38
+ {{/-last}}
39
+ {{/mappedModels}}
40
+ {{/discriminator}}
41
+ # Builds the object
42
+ # @param [Mixed] Data to be matched against the list of oneOf items
43
+ # @return [Object] Returns the model or the data itself
44
+ def build(data)
45
+ {{#discriminator}}
46
+ discriminator_value = data[openapi_discriminator_name]
47
+ return nil unless discriminator_value
48
+ {{#mappedModels}}
49
+ {{#-first}}
50
+
51
+ klass = openapi_discriminator_mapping[discriminator_value.to_sym]
52
+ return nil unless klass
53
+
54
+ {{moduleName}}.const_get(klass).build_from_hash(data)
55
+ {{/-first}}
56
+ {{/mappedModels}}
57
+ {{^mappedModels}}
58
+ {{moduleName}}.const_get(discriminator_value).build_from_hash(data)
59
+ {{/mappedModels}}
60
+ {{/discriminator}}
61
+ {{^discriminator}}
62
+ # Go through the list of oneOf items and attempt to identify the appropriate one.
63
+ # Note:
64
+ # - We do not attempt to check whether exactly one item matches.
65
+ # - No advanced validation of types in some cases (e.g. "x: { type: string }" will happily match { x: 123 })
66
+ # due to the way the deserialization is made in the base_object template (it just casts without verifying).
67
+ # - TODO: scalar values are defacto behaving as if they were nullable.
68
+ # - TODO: logging when debugging is set.
69
+ openapi_one_of.each do |klass|
70
+ begin
71
+ next if klass == :AnyType # "nullable: true"
72
+ typed_data = find_and_cast_into_type(klass, data)
73
+ return typed_data if typed_data
74
+ rescue # rescue all errors so we keep iterating even if the current item lookup raises
75
+ end
76
+ end
77
+
78
+ openapi_one_of.include?(:AnyType) ? data : nil
79
+ {{/discriminator}}
80
+ end
81
+ {{^discriminator}}
82
+
83
+ private
84
+
85
+ SchemaMismatchError = Class.new(StandardError)
86
+
87
+ # Note: 'File' is missing here because in the regular case we get the data _after_ a call to JSON.parse.
88
+ def find_and_cast_into_type(klass, data)
89
+ return if data.nil?
90
+
91
+ case klass.to_s
92
+ when 'Boolean'
93
+ return data if data.instance_of?(TrueClass) || data.instance_of?(FalseClass)
94
+ when 'Float'
95
+ return data if data.instance_of?(Float)
96
+ when 'Integer'
97
+ return data if data.instance_of?(Integer)
98
+ when 'Time'
99
+ return Time.parse(data)
100
+ when 'Date'
101
+ return Date.parse(data)
102
+ when 'String'
103
+ return data if data.instance_of?(String)
104
+ when 'Object' # "type: object"
105
+ return data if data.instance_of?(Hash)
106
+ when /\AArray<(?<sub_type>.+)>\z/ # "type: array"
107
+ if data.instance_of?(Array)
108
+ sub_type = Regexp.last_match[:sub_type]
109
+ return data.map { |item| find_and_cast_into_type(sub_type, item) }
110
+ end
111
+ when /\AHash<String, (?<sub_type>.+)>\z/ # "type: object" with "additionalProperties: { ... }"
112
+ if data.instance_of?(Hash) && data.keys.all? { |k| k.instance_of?(Symbol) || k.instance_of?(String) }
113
+ sub_type = Regexp.last_match[:sub_type]
114
+ return data.each_with_object({}) { |(k, v), hsh| hsh[k] = find_and_cast_into_type(sub_type, v) }
115
+ end
116
+ else # model
117
+ const = {{moduleName}}.const_get(klass)
118
+ if const
119
+ if const.respond_to?(:openapi_one_of) # nested oneOf model
120
+ model = const.build(data)
121
+ return model if model
122
+ else
123
+ # raise if data contains keys that are not known to the model
124
+ raise unless (data.keys - const.acceptable_attributes).empty?
125
+ model = const.build_from_hash(data)
126
+ return model if model && model.valid?
127
+ end
128
+ end
129
+ end
130
+
131
+ raise # if no match by now, raise
132
+ rescue
133
+ raise SchemaMismatchError, "#{data} doesn't match the #{klass} type"
134
+ end
135
+ {{/discriminator}}
136
+ end
137
+ end
@@ -0,0 +1,92 @@
1
+ # {{moduleName}}::{{classname}}
2
+
3
+ ## Class instance methods
4
+
5
+ ### `openapi_one_of`
6
+
7
+ Returns the list of classes defined in oneOf.
8
+
9
+ #### Example
10
+
11
+ ```ruby
12
+ require '{{{gemName}}}'
13
+
14
+ {{moduleName}}::{{classname}}.openapi_one_of
15
+ # =>
16
+ {{#oneOf}}
17
+ {{#-first}}
18
+ # [
19
+ {{/-first}}
20
+ # :'{{{.}}}'{{^-last}},{{/-last}}
21
+ {{#-last}}
22
+ # ]
23
+ {{/-last}}
24
+ {{/oneOf}}
25
+ ```
26
+ {{#discriminator}}
27
+ {{#propertyName}}
28
+
29
+ ### `openapi_discriminator_name`
30
+
31
+ Returns the discriminator's property name.
32
+
33
+ #### Example
34
+
35
+ ```ruby
36
+ require '{{{gemName}}}'
37
+
38
+ {{moduleName}}::{{classname}}.openapi_discriminator_name
39
+ # => :'{{{.}}}'
40
+ ```
41
+ {{/propertyName}}
42
+ {{#mappedModels}}
43
+ {{#-first}}
44
+
45
+ ### `openapi_discriminator_name`
46
+
47
+ Returns the discriminator's mapping.
48
+
49
+ #### Example
50
+
51
+ ```ruby
52
+ require '{{{gemName}}}'
53
+
54
+ {{moduleName}}::{{classname}}.openapi_discriminator_mapping
55
+ # =>
56
+ # {
57
+ {{/-first}}
58
+ # :'{{{mappingName}}}' => :'{{{modelName}}}'{{^-last}},{{/-last}}
59
+ {{#-last}}
60
+ # }
61
+ {{/-last}}
62
+ {{/mappedModels}}
63
+ {{/discriminator}}
64
+
65
+ ### build
66
+
67
+ Find the appropriate object from the `openapi_one_of` list and casts the data into it.
68
+
69
+ #### Example
70
+
71
+ ```ruby
72
+ require '{{{gemName}}}'
73
+
74
+ {{moduleName}}::{{classname}}.build(data)
75
+ # => {{#oneOf}}{{#-first}}#<{{{.}}}:0x00007fdd4aab02a0>{{/-first}}{{/oneOf}}
76
+
77
+ {{moduleName}}::{{classname}}.build(data_that_doesnt_match)
78
+ # => nil
79
+ ```
80
+
81
+ #### Parameters
82
+
83
+ | Name | Type | Description |
84
+ | ---- | ---- | ----------- |
85
+ | **data** | **Mixed** | data to be matched against the list of oneOf items |
86
+
87
+ #### Return type
88
+
89
+ {{#oneOf}}
90
+ - `{{{.}}}`
91
+ {{/oneOf}}
92
+ - `nil` (if no type matches)
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
@@ -0,0 +1,148 @@
1
+ # This file is based on https://github.com/rails/rails/blob/master/.rubocop.yml (MIT license)
2
+ # Automatically generated by OpenAPI Generator (https://openapi-generator.tech)
3
+ AllCops:
4
+ TargetRubyVersion: 2.4
5
+ # RuboCop has a bunch of cops enabled by default. This setting tells RuboCop
6
+ # to ignore them, so only the ones explicitly set in this file are enabled.
7
+ DisabledByDefault: true
8
+ Exclude:
9
+ - '**/templates/**/*'
10
+ - '**/vendor/**/*'
11
+ - 'actionpack/lib/action_dispatch/journey/parser.rb'
12
+
13
+ # Prefer &&/|| over and/or.
14
+ Style/AndOr:
15
+ Enabled: true
16
+
17
+ # Align `when` with `case`.
18
+ Layout/CaseIndentation:
19
+ Enabled: true
20
+
21
+ # Align comments with method definitions.
22
+ Layout/CommentIndentation:
23
+ Enabled: true
24
+
25
+ Layout/ElseAlignment:
26
+ Enabled: true
27
+
28
+ Layout/EmptyLineAfterMagicComment:
29
+ Enabled: true
30
+
31
+ # In a regular class definition, no empty lines around the body.
32
+ Layout/EmptyLinesAroundClassBody:
33
+ Enabled: true
34
+
35
+ # In a regular method definition, no empty lines around the body.
36
+ Layout/EmptyLinesAroundMethodBody:
37
+ Enabled: true
38
+
39
+ # In a regular module definition, no empty lines around the body.
40
+ Layout/EmptyLinesAroundModuleBody:
41
+ Enabled: true
42
+
43
+ Layout/FirstArgumentIndentation:
44
+ Enabled: true
45
+
46
+ # Use Ruby >= 1.9 syntax for hashes. Prefer { a: :b } over { :a => :b }.
47
+ Style/HashSyntax:
48
+ Enabled: false
49
+
50
+ # Method definitions after `private` or `protected` isolated calls need one
51
+ # extra level of indentation.
52
+ Layout/IndentationConsistency:
53
+ Enabled: true
54
+ EnforcedStyle: indented_internal_methods
55
+
56
+ # Two spaces, no tabs (for indentation).
57
+ Layout/IndentationWidth:
58
+ Enabled: true
59
+
60
+ Layout/LeadingCommentSpace:
61
+ Enabled: true
62
+
63
+ Layout/SpaceAfterColon:
64
+ Enabled: true
65
+
66
+ Layout/SpaceAfterComma:
67
+ Enabled: true
68
+
69
+ Layout/SpaceAroundEqualsInParameterDefault:
70
+ Enabled: true
71
+
72
+ Layout/SpaceAroundKeyword:
73
+ Enabled: true
74
+
75
+ Layout/SpaceAroundOperators:
76
+ Enabled: true
77
+
78
+ Layout/SpaceBeforeComma:
79
+ Enabled: true
80
+
81
+ Layout/SpaceBeforeFirstArg:
82
+ Enabled: true
83
+
84
+ Style/DefWithParentheses:
85
+ Enabled: true
86
+
87
+ # Defining a method with parameters needs parentheses.
88
+ Style/MethodDefParentheses:
89
+ Enabled: true
90
+
91
+ Style/FrozenStringLiteralComment:
92
+ Enabled: false
93
+ EnforcedStyle: always
94
+
95
+ # Use `foo {}` not `foo{}`.
96
+ Layout/SpaceBeforeBlockBraces:
97
+ Enabled: true
98
+
99
+ # Use `foo { bar }` not `foo {bar}`.
100
+ Layout/SpaceInsideBlockBraces:
101
+ Enabled: true
102
+
103
+ # Use `{ a: 1 }` not `{a:1}`.
104
+ Layout/SpaceInsideHashLiteralBraces:
105
+ Enabled: true
106
+
107
+ Layout/SpaceInsideParens:
108
+ Enabled: true
109
+
110
+ # Check quotes usage according to lint rule below.
111
+ #Style/StringLiterals:
112
+ # Enabled: true
113
+ # EnforcedStyle: single_quotes
114
+
115
+ # Detect hard tabs, no hard tabs.
116
+ Layout/IndentationStyle:
117
+ Enabled: true
118
+
119
+ # Blank lines should not have any spaces.
120
+ Layout/TrailingEmptyLines:
121
+ Enabled: true
122
+
123
+ # No trailing whitespace.
124
+ Layout/TrailingWhitespace:
125
+ Enabled: false
126
+
127
+ # Use quotes for string literals when they are enough.
128
+ Style/RedundantPercentQ:
129
+ Enabled: true
130
+
131
+ # Align `end` with the matching keyword or starting expression except for
132
+ # assignments, where it should be aligned with the LHS.
133
+ Layout/EndAlignment:
134
+ Enabled: true
135
+ EnforcedStyleAlignWith: variable
136
+ AutoCorrect: true
137
+
138
+ # Use my_method(my_arg) not my_method( my_arg ) or my_method my_arg.
139
+ Lint/RequireParentheses:
140
+ Enabled: true
141
+
142
+ Style/RedundantReturn:
143
+ Enabled: true
144
+ AllowMultipleReturnValues: true
145
+
146
+ Style/Semicolon:
147
+ Enabled: true
148
+ AllowAsExpressionSeparator: true
@@ -0,0 +1,103 @@
1
+ =begin
2
+ {{> api_info}}
3
+ =end
4
+
5
+ # load the gem
6
+ require '{{{gemName}}}'
7
+
8
+ # The following was generated by the `rspec --init` command. Conventionally, all
9
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
10
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
11
+ # this file to always be loaded, without a need to explicitly require it in any
12
+ # files.
13
+ #
14
+ # Given that it is always loaded, you are encouraged to keep this file as
15
+ # light-weight as possible. Requiring heavyweight dependencies from this file
16
+ # will add to the boot time of your test suite on EVERY test run, even for an
17
+ # individual file that may not need all of that loaded. Instead, consider making
18
+ # a separate helper file that requires the additional dependencies and performs
19
+ # the additional setup, and require it from the spec files that actually need
20
+ # it.
21
+ #
22
+ # The `.rspec` file also contains a few flags that are not defaults but that
23
+ # users commonly want.
24
+ #
25
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
26
+ RSpec.configure do |config|
27
+ # rspec-expectations config goes here. You can use an alternate
28
+ # assertion/expectation library such as wrong or the stdlib/minitest
29
+ # assertions if you prefer.
30
+ config.expect_with :rspec do |expectations|
31
+ # This option will default to `true` in RSpec 4. It makes the `description`
32
+ # and `failure_message` of custom matchers include text for helper methods
33
+ # defined using `chain`, e.g.:
34
+ # be_bigger_than(2).and_smaller_than(4).description
35
+ # # => "be bigger than 2 and smaller than 4"
36
+ # ...rather than:
37
+ # # => "be bigger than 2"
38
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
39
+ end
40
+
41
+ # rspec-mocks config goes here. You can use an alternate test double
42
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
43
+ config.mock_with :rspec do |mocks|
44
+ # Prevents you from mocking or stubbing a method that does not exist on
45
+ # a real object. This is generally recommended, and will default to
46
+ # `true` in RSpec 4.
47
+ mocks.verify_partial_doubles = true
48
+ end
49
+
50
+ # The settings below are suggested to provide a good initial experience
51
+ # with RSpec, but feel free to customize to your heart's content.
52
+ =begin
53
+ # These two settings work together to allow you to limit a spec run
54
+ # to individual examples or groups you care about by tagging them with
55
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
56
+ # get run.
57
+ config.filter_run :focus
58
+ config.run_all_when_everything_filtered = true
59
+
60
+ # Allows RSpec to persist some state between runs in order to support
61
+ # the `--only-failures` and `--next-failure` CLI options. We recommend
62
+ # you configure your source control system to ignore this file.
63
+ config.example_status_persistence_file_path = "spec/examples.txt"
64
+
65
+ # Limits the available syntax to the non-monkey patched syntax that is
66
+ # recommended. For more details, see:
67
+ # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
68
+ # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
69
+ # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
70
+ config.disable_monkey_patching!
71
+
72
+ # This setting enables warnings. It's recommended, but in some cases may
73
+ # be too noisy due to issues in dependencies.
74
+ config.warnings = true
75
+
76
+ # Many RSpec users commonly either run the entire suite or an individual
77
+ # file, and it's useful to allow more verbose output when running an
78
+ # individual spec file.
79
+ if config.files_to_run.one?
80
+ # Use the documentation formatter for detailed output,
81
+ # unless a formatter has already been configured
82
+ # (e.g. via a command-line flag).
83
+ config.default_formatter = 'doc'
84
+ end
85
+
86
+ # Print the 10 slowest examples and example groups at the
87
+ # end of the spec run, to help surface which specs are running
88
+ # particularly slow.
89
+ config.profile_examples = 10
90
+
91
+ # Run specs in random order to surface order dependencies. If you find an
92
+ # order dependency and want to debug it, you can fix the order by providing
93
+ # the seed, which is printed after each run.
94
+ # --seed 1234
95
+ config.order = :random
96
+
97
+ # Seed global randomization in this process using the `--seed` CLI option.
98
+ # Setting this allows you to use `--seed` to deterministically reproduce
99
+ # test failures related to randomization by passing the same `--seed` value
100
+ # as the one that triggered the failure.
101
+ Kernel.srand config.seed
102
+ =end
103
+ end