From 194d47ba88338140da43a359eab888d0746f4133 Mon Sep 17 00:00:00 2001 From: activitysmith-bot Date: Tue, 15 Sep 2026 13:11:24 +0000 Subject: [PATCH] chore: regenerate SDK --- generated/activitysmith_openapi.rb | 3 + .../activitysmith_openapi/configuration.rb | 7 + .../app_icon_badge_count_update_error.rb | 386 ++++++++++++++++++ .../app_icon_badge_count_update_response.rb | 44 +- .../models/live_activity_end_request.rb | 64 ++- .../models/live_activity_limit_error.rb | 30 +- .../models/live_activity_start_request.rb | 33 +- .../live_activity_stream_delete_request.rb | 45 +- .../models/live_activity_stream_request.rb | 33 +- .../models/live_activity_update_request.rb | 64 ++- .../models/metadata_value.rb | 106 +++++ .../models/push_notification_action.rb | 2 +- .../models/push_notification_request.rb | 50 ++- ...update_app_icon_badge_count422_response.rb | 105 +++++ generated/openapi-source.json | 6 + 15 files changed, 951 insertions(+), 27 deletions(-) create mode 100644 generated/activitysmith_openapi/models/app_icon_badge_count_update_error.rb create mode 100644 generated/activitysmith_openapi/models/metadata_value.rb create mode 100644 generated/activitysmith_openapi/models/update_app_icon_badge_count422_response.rb create mode 100644 generated/openapi-source.json diff --git a/generated/activitysmith_openapi.rb b/generated/activitysmith_openapi.rb index 9928336..87bdaa3 100644 --- a/generated/activitysmith_openapi.rb +++ b/generated/activitysmith_openapi.rb @@ -20,6 +20,7 @@ require 'activitysmith_openapi/models/activity_metric' require 'activitysmith_openapi/models/activity_metric_value' require 'activitysmith_openapi/models/alert_payload' +require 'activitysmith_openapi/models/app_icon_badge_count_update_error' require 'activitysmith_openapi/models/app_icon_badge_count_update_request' require 'activitysmith_openapi/models/app_icon_badge_count_update_response' require 'activitysmith_openapi/models/bad_request_error' @@ -45,6 +46,7 @@ require 'activitysmith_openapi/models/live_activity_update_request' require 'activitysmith_openapi/models/live_activity_update_response' require 'activitysmith_openapi/models/live_activity_webhook_method' +require 'activitysmith_openapi/models/metadata_value' require 'activitysmith_openapi/models/metric_error' require 'activitysmith_openapi/models/metric_value_update_request' require 'activitysmith_openapi/models/metric_value_update_request_value' @@ -59,6 +61,7 @@ require 'activitysmith_openapi/models/rate_limit_error' require 'activitysmith_openapi/models/send_push_notification429_response' require 'activitysmith_openapi/models/stream_content_state' +require 'activitysmith_openapi/models/update_app_icon_badge_count422_response' # APIs require 'activitysmith_openapi/api/app_icon_badges_api' diff --git a/generated/activitysmith_openapi/configuration.rb b/generated/activitysmith_openapi/configuration.rb index da0dc73..4333dc1 100644 --- a/generated/activitysmith_openapi/configuration.rb +++ b/generated/activitysmith_openapi/configuration.rb @@ -252,6 +252,13 @@ def auth_settings key: 'Authorization', value: "Bearer #{access_token_with_refresh}" }, + 'mcpOAuth' => + { + type: 'oauth2', + in: 'header', + key: 'Authorization', + value: "Bearer #{access_token_with_refresh}" + }, } end diff --git a/generated/activitysmith_openapi/models/app_icon_badge_count_update_error.rb b/generated/activitysmith_openapi/models/app_icon_badge_count_update_error.rb new file mode 100644 index 0000000..5cc0896 --- /dev/null +++ b/generated/activitysmith_openapi/models/app_icon_badge_count_update_error.rb @@ -0,0 +1,386 @@ +=begin +#ActivitySmith API + +#Send push notifications and Live Activities to your own devices via a single API key. + +The version of the OpenAPI document: 1.0.0 + +Generated by: https://openapi-generator.tech +Generator version: 7.7.0 + +=end + +require 'date' +require 'time' + +module OpenapiClient + class AppIconBadgeCountUpdateError + attr_accessor :error + + attr_accessor :code + + attr_accessor :message + + attr_accessor :badge + + attr_accessor :devices_targeted + + attr_accessor :devices_updated + + attr_accessor :users_updated + + # Deprecated compatibility alias for devices_updated. + attr_accessor :devices_notified + + attr_accessor :effective_channel_slugs + + class EnumAttributeValidator + attr_reader :datatype + attr_reader :allowable_values + + def initialize(datatype, allowable_values) + @allowable_values = allowable_values.map do |value| + case datatype.to_s + when /Integer/i + value.to_i + when /Float/i + value.to_f + else + value + end + end + end + + def valid?(value) + !value || allowable_values.include?(value) + end + end + + # Attribute mapping from ruby-style variable name to JSON key. + def self.attribute_map + { + :'error' => :'error', + :'code' => :'code', + :'message' => :'message', + :'badge' => :'badge', + :'devices_targeted' => :'devices_targeted', + :'devices_updated' => :'devices_updated', + :'users_updated' => :'users_updated', + :'devices_notified' => :'devices_notified', + :'effective_channel_slugs' => :'effective_channel_slugs' + } + end + + # Returns all the JSON keys this model knows about + def self.acceptable_attributes + attribute_map.values + end + + # Attribute type mapping. + def self.openapi_types + { + :'error' => :'String', + :'code' => :'String', + :'message' => :'String', + :'badge' => :'Integer', + :'devices_targeted' => :'Integer', + :'devices_updated' => :'Integer', + :'users_updated' => :'Integer', + :'devices_notified' => :'Integer', + :'effective_channel_slugs' => :'Array' + } + end + + # List of attributes with nullable: true + def self.openapi_nullable + Set.new([ + ]) + end + + # Initializes the object + # @param [Hash] attributes Model attributes in the form of hash + def initialize(attributes = {}) + if (!attributes.is_a?(Hash)) + fail ArgumentError, "The input argument (attributes) must be a hash in `OpenapiClient::AppIconBadgeCountUpdateError` initialize method" + end + + # check to see if the attribute exists and convert string to symbol for hash key + attributes = attributes.each_with_object({}) { |(k, v), h| + if (!self.class.attribute_map.key?(k.to_sym)) + fail ArgumentError, "`#{k}` is not a valid attribute in `OpenapiClient::AppIconBadgeCountUpdateError`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect + end + h[k.to_sym] = v + } + + if attributes.key?(:'error') + self.error = attributes[:'error'] + else + self.error = nil + end + + if attributes.key?(:'code') + self.code = attributes[:'code'] + else + self.code = nil + end + + if attributes.key?(:'message') + self.message = attributes[:'message'] + else + self.message = nil + end + + if attributes.key?(:'badge') + self.badge = attributes[:'badge'] + else + self.badge = nil + end + + if attributes.key?(:'devices_targeted') + self.devices_targeted = attributes[:'devices_targeted'] + end + + if attributes.key?(:'devices_updated') + self.devices_updated = attributes[:'devices_updated'] + else + self.devices_updated = nil + end + + if attributes.key?(:'users_updated') + self.users_updated = attributes[:'users_updated'] + end + + if attributes.key?(:'devices_notified') + self.devices_notified = attributes[:'devices_notified'] + end + + if attributes.key?(:'effective_channel_slugs') + if (value = attributes[:'effective_channel_slugs']).is_a?(Array) + self.effective_channel_slugs = value + end + end + end + + # Show invalid properties with the reasons. Usually used together with valid? + # @return Array for valid properties with the reasons + def list_invalid_properties + warn '[DEPRECATED] the `list_invalid_properties` method is obsolete' + invalid_properties = Array.new + if @error.nil? + invalid_properties.push('invalid value for "error", error cannot be nil.') + end + + if @code.nil? + invalid_properties.push('invalid value for "code", code cannot be nil.') + end + + if @message.nil? + invalid_properties.push('invalid value for "message", message cannot be nil.') + end + + if @badge.nil? + invalid_properties.push('invalid value for "badge", badge cannot be nil.') + end + + if @badge > 2147483647 + invalid_properties.push('invalid value for "badge", must be smaller than or equal to 2147483647.') + end + + if @badge < 0 + invalid_properties.push('invalid value for "badge", must be greater than or equal to 0.') + end + + if @devices_updated.nil? + invalid_properties.push('invalid value for "devices_updated", devices_updated cannot be nil.') + end + + invalid_properties + end + + # Check to see if the all the properties in the model are valid + # @return true if the model is valid + def valid? + warn '[DEPRECATED] the `valid?` method is obsolete' + return false if @error.nil? + return false if @code.nil? + code_validator = EnumAttributeValidator.new('String', ["badge_device_disconnected", "badge_update_failed"]) + return false unless code_validator.valid?(@code) + return false if @message.nil? + return false if @badge.nil? + return false if @badge > 2147483647 + return false if @badge < 0 + return false if @devices_updated.nil? + true + end + + # Custom attribute writer method checking allowed values (enum). + # @param [Object] code Object to be assigned + def code=(code) + validator = EnumAttributeValidator.new('String', ["badge_device_disconnected", "badge_update_failed"]) + unless validator.valid?(code) + fail ArgumentError, "invalid value for \"code\", must be one of #{validator.allowable_values}." + end + @code = code + end + + # Custom attribute writer method with validation + # @param [Object] badge Value to be assigned + def badge=(badge) + if badge.nil? + fail ArgumentError, 'badge cannot be nil' + end + + if badge > 2147483647 + fail ArgumentError, 'invalid value for "badge", must be smaller than or equal to 2147483647.' + end + + if badge < 0 + fail ArgumentError, 'invalid value for "badge", must be greater than or equal to 0.' + end + + @badge = badge + end + + # Checks equality by comparing each attribute. + # @param [Object] Object to be compared + def ==(o) + return true if self.equal?(o) + self.class == o.class && + error == o.error && + code == o.code && + message == o.message && + badge == o.badge && + devices_targeted == o.devices_targeted && + devices_updated == o.devices_updated && + users_updated == o.users_updated && + devices_notified == o.devices_notified && + effective_channel_slugs == o.effective_channel_slugs + end + + # @see the `==` method + # @param [Object] Object to be compared + def eql?(o) + self == o + end + + # Calculates hash code according to all attributes. + # @return [Integer] Hash code + def hash + [error, code, message, badge, devices_targeted, devices_updated, users_updated, devices_notified, effective_channel_slugs].hash + end + + # Builds the object from hash + # @param [Hash] attributes Model attributes in the form of hash + # @return [Object] Returns the model itself + def self.build_from_hash(attributes) + return nil unless attributes.is_a?(Hash) + attributes = attributes.transform_keys(&:to_sym) + transformed_hash = {} + openapi_types.each_pair do |key, type| + if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + transformed_hash["#{key}"] = nil + elsif type =~ /\AArray<(.*)>/i + # check to ensure the input is an array given that the attribute + # is documented as an array but the input is not + if attributes[attribute_map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + end + elsif !attributes[attribute_map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + end + end + new(transformed_hash) + end + + # Deserializes the data based on type + # @param string type Data type + # @param string value Value to be deserialized + # @return [Object] Deserialized data + def self._deserialize(type, value) + case type.to_sym + when :Time + Time.parse(value) + when :Date + Date.parse(value) + when :String + value.to_s + when :Integer + value.to_i + when :Float + value.to_f + when :Boolean + if value.to_s =~ /\A(true|t|yes|y|1)\z/i + true + else + false + end + when :Object + # generic object (usually a Hash), return directly + value + when /\AArray<(?.+)>\z/ + inner_type = Regexp.last_match[:inner_type] + value.map { |v| _deserialize(inner_type, v) } + when /\AHash<(?.+?), (?.+)>\z/ + k_type = Regexp.last_match[:k_type] + v_type = Regexp.last_match[:v_type] + {}.tap do |hash| + value.each do |k, v| + hash[_deserialize(k_type, k)] = _deserialize(v_type, v) + end + end + else # model + # models (e.g. Pet) or oneOf + klass = OpenapiClient.const_get(type) + klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value) + end + end + + # Returns the string representation of the object + # @return [String] String presentation of the object + def to_s + to_hash.to_s + end + + # to_body is an alias to to_hash (backward compatibility) + # @return [Hash] Returns the object in the form of hash + def to_body + to_hash + end + + # Returns the object in the form of hash + # @return [Hash] Returns the object in the form of hash + def to_hash + hash = {} + self.class.attribute_map.each_pair do |attr, param| + value = self.send(attr) + if value.nil? + is_nullable = self.class.openapi_nullable.include?(attr) + next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) + end + + hash[param] = _to_hash(value) + end + hash + end + + # Outputs non-array value in the form of hash + # For object, use to_hash. Otherwise, just return the value + # @param [Object] value Any valid value + # @return [Hash] Returns the value in the form of hash + def _to_hash(value) + if value.is_a?(Array) + value.compact.map { |v| _to_hash(v) } + elsif value.is_a?(Hash) + {}.tap do |hash| + value.each { |k, v| hash[k] = _to_hash(v) } + end + elsif value.respond_to? :to_hash + value.to_hash + else + value + end + end + + end + +end diff --git a/generated/activitysmith_openapi/models/app_icon_badge_count_update_response.rb b/generated/activitysmith_openapi/models/app_icon_badge_count_update_response.rb index 9faa31c..4482afc 100644 --- a/generated/activitysmith_openapi/models/app_icon_badge_count_update_response.rb +++ b/generated/activitysmith_openapi/models/app_icon_badge_count_update_response.rb @@ -19,8 +19,16 @@ class AppIconBadgeCountUpdateResponse attr_accessor :badge + # Number of devices whose App Icon Badge Count was updated. + attr_accessor :devices_updated + + # Number of account users with at least one updated device. + attr_accessor :users_updated + + # Deprecated compatibility alias for devices_updated. attr_accessor :devices_notified + # Deprecated compatibility alias for users_updated. attr_accessor :users_notified attr_accessor :effective_channel_slugs @@ -32,6 +40,8 @@ def self.attribute_map { :'success' => :'success', :'badge' => :'badge', + :'devices_updated' => :'devices_updated', + :'users_updated' => :'users_updated', :'devices_notified' => :'devices_notified', :'users_notified' => :'users_notified', :'effective_channel_slugs' => :'effective_channel_slugs', @@ -49,6 +59,8 @@ def self.openapi_types { :'success' => :'Boolean', :'badge' => :'Integer', + :'devices_updated' => :'Integer', + :'users_updated' => :'Integer', :'devices_notified' => :'Integer', :'users_notified' => :'Integer', :'effective_channel_slugs' => :'Array', @@ -89,16 +101,24 @@ def initialize(attributes = {}) self.badge = nil end + if attributes.key?(:'devices_updated') + self.devices_updated = attributes[:'devices_updated'] + else + self.devices_updated = nil + end + + if attributes.key?(:'users_updated') + self.users_updated = attributes[:'users_updated'] + else + self.users_updated = nil + end + if attributes.key?(:'devices_notified') self.devices_notified = attributes[:'devices_notified'] - else - self.devices_notified = nil end if attributes.key?(:'users_notified') self.users_notified = attributes[:'users_notified'] - else - self.users_notified = nil end if attributes.key?(:'effective_channel_slugs') @@ -137,12 +157,12 @@ def list_invalid_properties invalid_properties.push('invalid value for "badge", must be greater than or equal to 0.') end - if @devices_notified.nil? - invalid_properties.push('invalid value for "devices_notified", devices_notified cannot be nil.') + if @devices_updated.nil? + invalid_properties.push('invalid value for "devices_updated", devices_updated cannot be nil.') end - if @users_notified.nil? - invalid_properties.push('invalid value for "users_notified", users_notified cannot be nil.') + if @users_updated.nil? + invalid_properties.push('invalid value for "users_updated", users_updated cannot be nil.') end if @effective_channel_slugs.nil? @@ -164,8 +184,8 @@ def valid? return false if @badge.nil? return false if @badge > 2147483647 return false if @badge < 0 - return false if @devices_notified.nil? - return false if @users_notified.nil? + return false if @devices_updated.nil? + return false if @users_updated.nil? return false if @effective_channel_slugs.nil? return false if @timestamp.nil? true @@ -196,6 +216,8 @@ def ==(o) self.class == o.class && success == o.success && badge == o.badge && + devices_updated == o.devices_updated && + users_updated == o.users_updated && devices_notified == o.devices_notified && users_notified == o.users_notified && effective_channel_slugs == o.effective_channel_slugs && @@ -211,7 +233,7 @@ def eql?(o) # Calculates hash code according to all attributes. # @return [Integer] Hash code def hash - [success, badge, devices_notified, users_notified, effective_channel_slugs, timestamp].hash + [success, badge, devices_updated, users_updated, devices_notified, users_notified, effective_channel_slugs, timestamp].hash end # Builds the object from hash diff --git a/generated/activitysmith_openapi/models/live_activity_end_request.rb b/generated/activitysmith_openapi/models/live_activity_end_request.rb index 40b43c2..d8877d0 100644 --- a/generated/activitysmith_openapi/models/live_activity_end_request.rb +++ b/generated/activitysmith_openapi/models/live_activity_end_request.rb @@ -16,8 +16,14 @@ module OpenapiClient # End an existing Live Activity by activity_id. class LiveActivityEndRequest + # Additional information shown in notification and Live Activity details in ActivitySmith. Not displayed in the Push Notification or Live Activity on the device. Values must be strings, finite numbers, or booleans. At most 50 entries and 16 KB of serialized UTF-8 JSON. Omit on updates to preserve existing Metadata; send {} to clear it. + attr_accessor :metadata + attr_accessor :activity_id + # Tags for notification history. Omit to keep existing Tags, supply an array to replace them, or send an empty array to clear them. + attr_accessor :tags + attr_accessor :content_state attr_accessor :action @@ -28,7 +34,9 @@ class LiveActivityEndRequest # Attribute mapping from ruby-style variable name to JSON key. def self.attribute_map { + :'metadata' => :'metadata', :'activity_id' => :'activity_id', + :'tags' => :'tags', :'content_state' => :'content_state', :'action' => :'action', :'secondary_action' => :'secondary_action' @@ -43,7 +51,9 @@ def self.acceptable_attributes # Attribute type mapping. def self.openapi_types { + :'metadata' => :'Hash', :'activity_id' => :'String', + :'tags' => :'Array', :'content_state' => :'ContentStateEnd', :'action' => :'LiveActivityAction', :'secondary_action' => :'LiveActivityAction' @@ -71,12 +81,24 @@ def initialize(attributes = {}) h[k.to_sym] = v } + if attributes.key?(:'metadata') + if (value = attributes[:'metadata']).is_a?(Hash) + self.metadata = value + end + end + if attributes.key?(:'activity_id') self.activity_id = attributes[:'activity_id'] else self.activity_id = nil end + if attributes.key?(:'tags') + if (value = attributes[:'tags']).is_a?(Array) + self.tags = value + end + end + if attributes.key?(:'content_state') self.content_state = attributes[:'content_state'] else @@ -97,10 +119,18 @@ def initialize(attributes = {}) def list_invalid_properties warn '[DEPRECATED] the `list_invalid_properties` method is obsolete' invalid_properties = Array.new + if !@metadata.nil? && @metadata.length > 50 + invalid_properties.push('invalid value for "metadata", number of items must be less than or equal to 50.') + end + if @activity_id.nil? invalid_properties.push('invalid value for "activity_id", activity_id cannot be nil.') end + if !@tags.nil? && @tags.length > 20 + invalid_properties.push('invalid value for "tags", number of items must be less than or equal to 20.') + end + if @content_state.nil? invalid_properties.push('invalid value for "content_state", content_state cannot be nil.') end @@ -112,17 +142,49 @@ def list_invalid_properties # @return true if the model is valid def valid? warn '[DEPRECATED] the `valid?` method is obsolete' + return false if !@metadata.nil? && @metadata.length > 50 return false if @activity_id.nil? + return false if !@tags.nil? && @tags.length > 20 return false if @content_state.nil? true end + # Custom attribute writer method with validation + # @param [Object] metadata Value to be assigned + def metadata=(metadata) + if metadata.nil? + fail ArgumentError, 'metadata cannot be nil' + end + + if metadata.length > 50 + fail ArgumentError, 'invalid value for "metadata", number of items must be less than or equal to 50.' + end + + @metadata = metadata + end + + # Custom attribute writer method with validation + # @param [Object] tags Value to be assigned + def tags=(tags) + if tags.nil? + fail ArgumentError, 'tags cannot be nil' + end + + if tags.length > 20 + fail ArgumentError, 'invalid value for "tags", number of items must be less than or equal to 20.' + end + + @tags = tags + end + # Checks equality by comparing each attribute. # @param [Object] Object to be compared def ==(o) return true if self.equal?(o) self.class == o.class && + metadata == o.metadata && activity_id == o.activity_id && + tags == o.tags && content_state == o.content_state && action == o.action && secondary_action == o.secondary_action @@ -137,7 +199,7 @@ def eql?(o) # Calculates hash code according to all attributes. # @return [Integer] Hash code def hash - [activity_id, content_state, action, secondary_action].hash + [metadata, activity_id, tags, content_state, action, secondary_action].hash end # Builds the object from hash diff --git a/generated/activitysmith_openapi/models/live_activity_limit_error.rb b/generated/activitysmith_openapi/models/live_activity_limit_error.rb index c10f24d..52f964c 100644 --- a/generated/activitysmith_openapi/models/live_activity_limit_error.rb +++ b/generated/activitysmith_openapi/models/live_activity_limit_error.rb @@ -21,16 +21,24 @@ class LiveActivityLimitError attr_accessor :limit - # Current number of active Live Activities. + # Highest number of active Live Activities among the targeted devices. attr_accessor :active + # Number of targeted devices that have reached the enforced iOS Live Activity concurrency threshold. Included only when targeted devices have mixed capacity. + attr_accessor :blocked_devices + + # Total number of targeted devices. Included only when targeted devices have mixed capacity. + attr_accessor :targeted_devices + # Attribute mapping from ruby-style variable name to JSON key. def self.attribute_map { :'error' => :'error', :'message' => :'message', :'limit' => :'limit', - :'active' => :'active' + :'active' => :'active', + :'blocked_devices' => :'blocked_devices', + :'targeted_devices' => :'targeted_devices' } end @@ -45,7 +53,9 @@ def self.openapi_types :'error' => :'String', :'message' => :'String', :'limit' => :'Integer', - :'active' => :'Integer' + :'active' => :'Integer', + :'blocked_devices' => :'Integer', + :'targeted_devices' => :'Integer' } end @@ -93,6 +103,14 @@ def initialize(attributes = {}) else self.active = nil end + + if attributes.key?(:'blocked_devices') + self.blocked_devices = attributes[:'blocked_devices'] + end + + if attributes.key?(:'targeted_devices') + self.targeted_devices = attributes[:'targeted_devices'] + end end # Show invalid properties with the reasons. Usually used together with valid? @@ -138,7 +156,9 @@ def ==(o) error == o.error && message == o.message && limit == o.limit && - active == o.active + active == o.active && + blocked_devices == o.blocked_devices && + targeted_devices == o.targeted_devices end # @see the `==` method @@ -150,7 +170,7 @@ def eql?(o) # Calculates hash code according to all attributes. # @return [Integer] Hash code def hash - [error, message, limit, active].hash + [error, message, limit, active, blocked_devices, targeted_devices].hash end # Builds the object from hash diff --git a/generated/activitysmith_openapi/models/live_activity_start_request.rb b/generated/activitysmith_openapi/models/live_activity_start_request.rb index 7297a28..135006f 100644 --- a/generated/activitysmith_openapi/models/live_activity_start_request.rb +++ b/generated/activitysmith_openapi/models/live_activity_start_request.rb @@ -16,6 +16,9 @@ module OpenapiClient # Start a new Live Activity. The response includes activity_id for later update and end calls. class LiveActivityStartRequest + # Additional information shown in notification and Live Activity details in ActivitySmith. Not displayed in the Push Notification or Live Activity on the device. Values must be strings, finite numbers, or booleans. At most 50 entries and 16 KB of serialized UTF-8 JSON. Omit on updates to preserve existing Metadata; send {} to clear it. + attr_accessor :metadata + attr_accessor :content_state attr_accessor :action @@ -33,6 +36,7 @@ class LiveActivityStartRequest # Attribute mapping from ruby-style variable name to JSON key. def self.attribute_map { + :'metadata' => :'metadata', :'content_state' => :'content_state', :'action' => :'action', :'secondary_action' => :'secondary_action', @@ -50,6 +54,7 @@ def self.acceptable_attributes # Attribute type mapping. def self.openapi_types { + :'metadata' => :'Hash', :'content_state' => :'ContentStateStart', :'action' => :'LiveActivityAction', :'secondary_action' => :'LiveActivityAction', @@ -80,6 +85,12 @@ def initialize(attributes = {}) h[k.to_sym] = v } + if attributes.key?(:'metadata') + if (value = attributes[:'metadata']).is_a?(Hash) + self.metadata = value + end + end + if attributes.key?(:'content_state') self.content_state = attributes[:'content_state'] else @@ -114,6 +125,10 @@ def initialize(attributes = {}) def list_invalid_properties warn '[DEPRECATED] the `list_invalid_properties` method is obsolete' invalid_properties = Array.new + if !@metadata.nil? && @metadata.length > 50 + invalid_properties.push('invalid value for "metadata", number of items must be less than or equal to 50.') + end + if @content_state.nil? invalid_properties.push('invalid value for "content_state", content_state cannot be nil.') end @@ -125,15 +140,31 @@ def list_invalid_properties # @return true if the model is valid def valid? warn '[DEPRECATED] the `valid?` method is obsolete' + return false if !@metadata.nil? && @metadata.length > 50 return false if @content_state.nil? true end + # Custom attribute writer method with validation + # @param [Object] metadata Value to be assigned + def metadata=(metadata) + if metadata.nil? + fail ArgumentError, 'metadata cannot be nil' + end + + if metadata.length > 50 + fail ArgumentError, 'invalid value for "metadata", number of items must be less than or equal to 50.' + end + + @metadata = metadata + end + # Checks equality by comparing each attribute. # @param [Object] Object to be compared def ==(o) return true if self.equal?(o) self.class == o.class && + metadata == o.metadata && content_state == o.content_state && action == o.action && secondary_action == o.secondary_action && @@ -151,7 +182,7 @@ def eql?(o) # Calculates hash code according to all attributes. # @return [Integer] Hash code def hash - [content_state, action, secondary_action, alert, target, tags].hash + [metadata, content_state, action, secondary_action, alert, target, tags].hash end # Builds the object from hash diff --git a/generated/activitysmith_openapi/models/live_activity_stream_delete_request.rb b/generated/activitysmith_openapi/models/live_activity_stream_delete_request.rb index 97f1dd2..0cb5d09 100644 --- a/generated/activitysmith_openapi/models/live_activity_stream_delete_request.rb +++ b/generated/activitysmith_openapi/models/live_activity_stream_delete_request.rb @@ -16,6 +16,12 @@ module OpenapiClient # Optional payload for ending a managed stream. When omitted, ActivitySmith ends the stream using the latest known state when possible. class LiveActivityStreamDeleteRequest + # Additional information shown in notification and Live Activity details in ActivitySmith. Not displayed in the Push Notification or Live Activity on the device. Values must be strings, finite numbers, or booleans. At most 50 entries and 16 KB of serialized UTF-8 JSON. Omit on updates to preserve existing Metadata; send {} to clear it. + attr_accessor :metadata + + # Optional tags to organize and filter notification history. + attr_accessor :tags + attr_accessor :content_state attr_accessor :action @@ -28,6 +34,8 @@ class LiveActivityStreamDeleteRequest # Attribute mapping from ruby-style variable name to JSON key. def self.attribute_map { + :'metadata' => :'metadata', + :'tags' => :'tags', :'content_state' => :'content_state', :'action' => :'action', :'secondary_action' => :'secondary_action', @@ -43,6 +51,8 @@ def self.acceptable_attributes # Attribute type mapping. def self.openapi_types { + :'metadata' => :'Hash', + :'tags' => :'Array', :'content_state' => :'StreamContentState', :'action' => :'LiveActivityAction', :'secondary_action' => :'LiveActivityAction', @@ -71,6 +81,18 @@ def initialize(attributes = {}) h[k.to_sym] = v } + if attributes.key?(:'metadata') + if (value = attributes[:'metadata']).is_a?(Hash) + self.metadata = value + end + end + + if attributes.key?(:'tags') + if (value = attributes[:'tags']).is_a?(Array) + self.tags = value + end + end + if attributes.key?(:'content_state') self.content_state = attributes[:'content_state'] end @@ -93,6 +115,10 @@ def initialize(attributes = {}) def list_invalid_properties warn '[DEPRECATED] the `list_invalid_properties` method is obsolete' invalid_properties = Array.new + if !@metadata.nil? && @metadata.length > 50 + invalid_properties.push('invalid value for "metadata", number of items must be less than or equal to 50.') + end + invalid_properties end @@ -100,14 +126,31 @@ def list_invalid_properties # @return true if the model is valid def valid? warn '[DEPRECATED] the `valid?` method is obsolete' + return false if !@metadata.nil? && @metadata.length > 50 true end + # Custom attribute writer method with validation + # @param [Object] metadata Value to be assigned + def metadata=(metadata) + if metadata.nil? + fail ArgumentError, 'metadata cannot be nil' + end + + if metadata.length > 50 + fail ArgumentError, 'invalid value for "metadata", number of items must be less than or equal to 50.' + end + + @metadata = metadata + end + # Checks equality by comparing each attribute. # @param [Object] Object to be compared def ==(o) return true if self.equal?(o) self.class == o.class && + metadata == o.metadata && + tags == o.tags && content_state == o.content_state && action == o.action && secondary_action == o.secondary_action && @@ -123,7 +166,7 @@ def eql?(o) # Calculates hash code according to all attributes. # @return [Integer] Hash code def hash - [content_state, action, secondary_action, alert].hash + [metadata, tags, content_state, action, secondary_action, alert].hash end # Builds the object from hash diff --git a/generated/activitysmith_openapi/models/live_activity_stream_request.rb b/generated/activitysmith_openapi/models/live_activity_stream_request.rb index d2581d7..0253e2b 100644 --- a/generated/activitysmith_openapi/models/live_activity_stream_request.rb +++ b/generated/activitysmith_openapi/models/live_activity_stream_request.rb @@ -16,6 +16,9 @@ module OpenapiClient # Send the latest state for a managed Live Activity stream. channels is the streamlined form for stream targeting. target.channels is also accepted for compatibility. If both are provided, they must match. class LiveActivityStreamRequest + # Additional information shown in notification and Live Activity details in ActivitySmith. Not displayed in the Push Notification or Live Activity on the device. Values must be strings, finite numbers, or booleans. At most 50 entries and 16 KB of serialized UTF-8 JSON. Omit on updates to preserve existing Metadata; send {} to clear it. + attr_accessor :metadata + attr_accessor :content_state attr_accessor :action @@ -36,6 +39,7 @@ class LiveActivityStreamRequest # Attribute mapping from ruby-style variable name to JSON key. def self.attribute_map { + :'metadata' => :'metadata', :'content_state' => :'content_state', :'action' => :'action', :'secondary_action' => :'secondary_action', @@ -54,6 +58,7 @@ def self.acceptable_attributes # Attribute type mapping. def self.openapi_types { + :'metadata' => :'Hash', :'content_state' => :'StreamContentState', :'action' => :'LiveActivityAction', :'secondary_action' => :'LiveActivityAction', @@ -85,6 +90,12 @@ def initialize(attributes = {}) h[k.to_sym] = v } + if attributes.key?(:'metadata') + if (value = attributes[:'metadata']).is_a?(Hash) + self.metadata = value + end + end + if attributes.key?(:'content_state') self.content_state = attributes[:'content_state'] else @@ -125,6 +136,10 @@ def initialize(attributes = {}) def list_invalid_properties warn '[DEPRECATED] the `list_invalid_properties` method is obsolete' invalid_properties = Array.new + if !@metadata.nil? && @metadata.length > 50 + invalid_properties.push('invalid value for "metadata", number of items must be less than or equal to 50.') + end + if @content_state.nil? invalid_properties.push('invalid value for "content_state", content_state cannot be nil.') end @@ -140,11 +155,26 @@ def list_invalid_properties # @return true if the model is valid def valid? warn '[DEPRECATED] the `valid?` method is obsolete' + return false if !@metadata.nil? && @metadata.length > 50 return false if @content_state.nil? return false if !@channels.nil? && @channels.length < 1 true end + # Custom attribute writer method with validation + # @param [Object] metadata Value to be assigned + def metadata=(metadata) + if metadata.nil? + fail ArgumentError, 'metadata cannot be nil' + end + + if metadata.length > 50 + fail ArgumentError, 'invalid value for "metadata", number of items must be less than or equal to 50.' + end + + @metadata = metadata + end + # Custom attribute writer method with validation # @param [Object] channels Value to be assigned def channels=(channels) @@ -164,6 +194,7 @@ def channels=(channels) def ==(o) return true if self.equal?(o) self.class == o.class && + metadata == o.metadata && content_state == o.content_state && action == o.action && secondary_action == o.secondary_action && @@ -182,7 +213,7 @@ def eql?(o) # Calculates hash code according to all attributes. # @return [Integer] Hash code def hash - [content_state, action, secondary_action, alert, channels, target, tags].hash + [metadata, content_state, action, secondary_action, alert, channels, target, tags].hash end # Builds the object from hash diff --git a/generated/activitysmith_openapi/models/live_activity_update_request.rb b/generated/activitysmith_openapi/models/live_activity_update_request.rb index b952430..ae174e2 100644 --- a/generated/activitysmith_openapi/models/live_activity_update_request.rb +++ b/generated/activitysmith_openapi/models/live_activity_update_request.rb @@ -16,8 +16,14 @@ module OpenapiClient # Update an existing Live Activity by activity_id. class LiveActivityUpdateRequest + # Additional information shown in notification and Live Activity details in ActivitySmith. Not displayed in the Push Notification or Live Activity on the device. Values must be strings, finite numbers, or booleans. At most 50 entries and 16 KB of serialized UTF-8 JSON. Omit on updates to preserve existing Metadata; send {} to clear it. + attr_accessor :metadata + attr_accessor :activity_id + # Tags for notification history. Omit to keep existing Tags, supply an array to replace them, or send an empty array to clear them. + attr_accessor :tags + attr_accessor :content_state attr_accessor :action @@ -28,7 +34,9 @@ class LiveActivityUpdateRequest # Attribute mapping from ruby-style variable name to JSON key. def self.attribute_map { + :'metadata' => :'metadata', :'activity_id' => :'activity_id', + :'tags' => :'tags', :'content_state' => :'content_state', :'action' => :'action', :'secondary_action' => :'secondary_action' @@ -43,7 +51,9 @@ def self.acceptable_attributes # Attribute type mapping. def self.openapi_types { + :'metadata' => :'Hash', :'activity_id' => :'String', + :'tags' => :'Array', :'content_state' => :'ContentStateUpdate', :'action' => :'LiveActivityAction', :'secondary_action' => :'LiveActivityAction' @@ -71,12 +81,24 @@ def initialize(attributes = {}) h[k.to_sym] = v } + if attributes.key?(:'metadata') + if (value = attributes[:'metadata']).is_a?(Hash) + self.metadata = value + end + end + if attributes.key?(:'activity_id') self.activity_id = attributes[:'activity_id'] else self.activity_id = nil end + if attributes.key?(:'tags') + if (value = attributes[:'tags']).is_a?(Array) + self.tags = value + end + end + if attributes.key?(:'content_state') self.content_state = attributes[:'content_state'] else @@ -97,10 +119,18 @@ def initialize(attributes = {}) def list_invalid_properties warn '[DEPRECATED] the `list_invalid_properties` method is obsolete' invalid_properties = Array.new + if !@metadata.nil? && @metadata.length > 50 + invalid_properties.push('invalid value for "metadata", number of items must be less than or equal to 50.') + end + if @activity_id.nil? invalid_properties.push('invalid value for "activity_id", activity_id cannot be nil.') end + if !@tags.nil? && @tags.length > 20 + invalid_properties.push('invalid value for "tags", number of items must be less than or equal to 20.') + end + if @content_state.nil? invalid_properties.push('invalid value for "content_state", content_state cannot be nil.') end @@ -112,17 +142,49 @@ def list_invalid_properties # @return true if the model is valid def valid? warn '[DEPRECATED] the `valid?` method is obsolete' + return false if !@metadata.nil? && @metadata.length > 50 return false if @activity_id.nil? + return false if !@tags.nil? && @tags.length > 20 return false if @content_state.nil? true end + # Custom attribute writer method with validation + # @param [Object] metadata Value to be assigned + def metadata=(metadata) + if metadata.nil? + fail ArgumentError, 'metadata cannot be nil' + end + + if metadata.length > 50 + fail ArgumentError, 'invalid value for "metadata", number of items must be less than or equal to 50.' + end + + @metadata = metadata + end + + # Custom attribute writer method with validation + # @param [Object] tags Value to be assigned + def tags=(tags) + if tags.nil? + fail ArgumentError, 'tags cannot be nil' + end + + if tags.length > 20 + fail ArgumentError, 'invalid value for "tags", number of items must be less than or equal to 20.' + end + + @tags = tags + end + # Checks equality by comparing each attribute. # @param [Object] Object to be compared def ==(o) return true if self.equal?(o) self.class == o.class && + metadata == o.metadata && activity_id == o.activity_id && + tags == o.tags && content_state == o.content_state && action == o.action && secondary_action == o.secondary_action @@ -137,7 +199,7 @@ def eql?(o) # Calculates hash code according to all attributes. # @return [Integer] Hash code def hash - [activity_id, content_state, action, secondary_action].hash + [metadata, activity_id, tags, content_state, action, secondary_action].hash end # Builds the object from hash diff --git a/generated/activitysmith_openapi/models/metadata_value.rb b/generated/activitysmith_openapi/models/metadata_value.rb new file mode 100644 index 0000000..289024c --- /dev/null +++ b/generated/activitysmith_openapi/models/metadata_value.rb @@ -0,0 +1,106 @@ +=begin +#ActivitySmith API + +#Send push notifications and Live Activities to your own devices via a single API key. + +The version of the OpenAPI document: 1.0.0 + +Generated by: https://openapi-generator.tech +Generator version: 7.7.0 + +=end + +require 'date' +require 'time' + +module OpenapiClient + module MetadataValue + class << self + # List of class defined in oneOf (OpenAPI v3) + def openapi_one_of + [ + :'Boolean', + :'Float', + :'String' + ] + end + + # Builds the object + # @param [Mixed] Data to be matched against the list of oneOf items + # @return [Object] Returns the model or the data itself + def build(data) + # Go through the list of oneOf items and attempt to identify the appropriate one. + # Note: + # - We do not attempt to check whether exactly one item matches. + # - No advanced validation of types in some cases (e.g. "x: { type: string }" will happily match { x: 123 }) + # due to the way the deserialization is made in the base_object template (it just casts without verifying). + # - TODO: scalar values are de facto behaving as if they were nullable. + # - TODO: logging when debugging is set. + openapi_one_of.each do |klass| + begin + next if klass == :AnyType # "nullable: true" + typed_data = find_and_cast_into_type(klass, data) + return typed_data if typed_data + rescue # rescue all errors so we keep iterating even if the current item lookup raises + end + end + + openapi_one_of.include?(:AnyType) ? data : nil + end + + private + + SchemaMismatchError = Class.new(StandardError) + + # Note: 'File' is missing here because in the regular case we get the data _after_ a call to JSON.parse. + def find_and_cast_into_type(klass, data) + return if data.nil? + + case klass.to_s + when 'Boolean' + return data if data.instance_of?(TrueClass) || data.instance_of?(FalseClass) + when 'Float' + return data if data.instance_of?(Float) + when 'Integer' + return data if data.instance_of?(Integer) + when 'Time' + return Time.parse(data) + when 'Date' + return Date.parse(data) + when 'String' + return data if data.instance_of?(String) + when 'Object' # "type: object" + return data if data.instance_of?(Hash) + when /\AArray<(?.+)>\z/ # "type: array" + if data.instance_of?(Array) + sub_type = Regexp.last_match[:sub_type] + return data.map { |item| find_and_cast_into_type(sub_type, item) } + end + when /\AHash.+)>\z/ # "type: object" with "additionalProperties: { ... }" + if data.instance_of?(Hash) && data.keys.all? { |k| k.instance_of?(Symbol) || k.instance_of?(String) } + sub_type = Regexp.last_match[:sub_type] + return data.each_with_object({}) { |(k, v), hsh| hsh[k] = find_and_cast_into_type(sub_type, v) } + end + else # model + const = OpenapiClient.const_get(klass) + if const + if const.respond_to?(:openapi_one_of) # nested oneOf model + model = const.build(data) + return model if model + else + # raise if data contains keys that are not known to the model + raise if const.respond_to?(:acceptable_attributes) && !(data.keys - const.acceptable_attributes).empty? + model = const.build_from_hash(data) + return model if model + end + end + end + + raise # if no match by now, raise + rescue + raise SchemaMismatchError, "#{data} doesn't match the #{klass} type" + end + end + end + +end diff --git a/generated/activitysmith_openapi/models/push_notification_action.rb b/generated/activitysmith_openapi/models/push_notification_action.rb index d29eb66..a3dd68d 100644 --- a/generated/activitysmith_openapi/models/push_notification_action.rb +++ b/generated/activitysmith_openapi/models/push_notification_action.rb @@ -20,7 +20,7 @@ class PushNotificationAction attr_accessor :type - # Action URL. For open_url, use an HTTP or HTTPS URL or a shortcuts://run-shortcut?name=... URL that runs a specific iPhone Shortcut. For webhook, use an HTTPS URL called by the ActivitySmith backend. + # Action URL. For open_url, use HTTP, HTTPS, Shortcuts, or an installed app’s custom URL scheme, such as spotify:// or spotify:track:123. Custom app schemes require iOS 1.13.4 build 2 or later; no web fallback is provided. Internal and executable schemes are blocked. For webhook, use an HTTPS URL called by the ActivitySmith backend. attr_accessor :url # Webhook HTTP method. Used only when type=webhook. diff --git a/generated/activitysmith_openapi/models/push_notification_request.rb b/generated/activitysmith_openapi/models/push_notification_request.rb index cfba9e2..e500e93 100644 --- a/generated/activitysmith_openapi/models/push_notification_request.rb +++ b/generated/activitysmith_openapi/models/push_notification_request.rb @@ -15,6 +15,9 @@ module OpenapiClient class PushNotificationRequest + # Additional information shown in notification and Live Activity details in ActivitySmith. Not displayed in the Push Notification or Live Activity on the device. Values must be strings, finite numbers, or booleans. At most 50 entries and 16 KB of serialized UTF-8 JSON. Omit on updates to preserve existing Metadata; send {} to clear it. + attr_accessor :metadata + attr_accessor :title attr_accessor :message @@ -24,7 +27,7 @@ class PushNotificationRequest # Optional HTTPS URL for an image, audio file, or video that users can preview or play when they expand the notification. If `redirection` is omitted, tapping the notification opens this URL. Cannot be combined with `actions`. attr_accessor :media - # Optional HTTP URL, HTTPS URL, or shortcuts://run-shortcut?name=... URL opened when the user taps the notification body. Use shortcuts://run-shortcut?name=... to run a specific iPhone Shortcut that already exists on the user's device. Overrides the default tap target from `media` when both are provided. + # Optional HTTP, HTTPS, Shortcuts, or installed app URL opened when the user taps the notification body. Custom schemes such as spotify:// and spotify:track:123 require iOS 1.13.4 build 2 or later and an installed handler; no web fallback is provided. Internal and executable schemes are blocked. Overrides the default tap target from media. attr_accessor :redirection # Optional interactive actions shown when users expand the notification. Cannot be combined with `media`. @@ -44,6 +47,7 @@ class PushNotificationRequest # Attribute mapping from ruby-style variable name to JSON key. def self.attribute_map { + :'metadata' => :'metadata', :'title' => :'title', :'message' => :'message', :'subtitle' => :'subtitle', @@ -66,6 +70,7 @@ def self.acceptable_attributes # Attribute type mapping. def self.openapi_types { + :'metadata' => :'Hash', :'title' => :'String', :'message' => :'String', :'subtitle' => :'String', @@ -101,6 +106,12 @@ def initialize(attributes = {}) h[k.to_sym] = v } + if attributes.key?(:'metadata') + if (value = attributes[:'metadata']).is_a?(Hash) + self.metadata = value + end + end + if attributes.key?(:'title') self.title = attributes[:'title'] else @@ -157,6 +168,10 @@ def initialize(attributes = {}) def list_invalid_properties warn '[DEPRECATED] the `list_invalid_properties` method is obsolete' invalid_properties = Array.new + if !@metadata.nil? && @metadata.length > 50 + invalid_properties.push('invalid value for "metadata", number of items must be less than or equal to 50.') + end + if @title.nil? invalid_properties.push('invalid value for "title", title cannot be nil.') end @@ -166,7 +181,11 @@ def list_invalid_properties invalid_properties.push("invalid value for \"media\", must conform to the pattern #{pattern}.") end - pattern = Regexp.new(/^(http|https|shortcuts):\/\//) + if !@redirection.nil? && @redirection.to_s.length > 2048 + invalid_properties.push('invalid value for "redirection", the character length must be smaller than or equal to 2048.') + end + + pattern = Regexp.new(/^[A-Za-z][A-Za-z0-9+.-]*:/) if !@redirection.nil? && @redirection !~ pattern invalid_properties.push("invalid value for \"redirection\", must conform to the pattern #{pattern}.") end @@ -182,13 +201,29 @@ def list_invalid_properties # @return true if the model is valid def valid? warn '[DEPRECATED] the `valid?` method is obsolete' + return false if !@metadata.nil? && @metadata.length > 50 return false if @title.nil? return false if !@media.nil? && @media !~ Regexp.new(/^https:\/\//) - return false if !@redirection.nil? && @redirection !~ Regexp.new(/^(http|https|shortcuts):\/\//) + return false if !@redirection.nil? && @redirection.to_s.length > 2048 + return false if !@redirection.nil? && @redirection !~ Regexp.new(/^[A-Za-z][A-Za-z0-9+.-]*:/) return false if !@actions.nil? && @actions.length > 4 true end + # Custom attribute writer method with validation + # @param [Object] metadata Value to be assigned + def metadata=(metadata) + if metadata.nil? + fail ArgumentError, 'metadata cannot be nil' + end + + if metadata.length > 50 + fail ArgumentError, 'invalid value for "metadata", number of items must be less than or equal to 50.' + end + + @metadata = metadata + end + # Custom attribute writer method with validation # @param [Object] media Value to be assigned def media=(media) @@ -211,7 +246,11 @@ def redirection=(redirection) fail ArgumentError, 'redirection cannot be nil' end - pattern = Regexp.new(/^(http|https|shortcuts):\/\//) + if redirection.to_s.length > 2048 + fail ArgumentError, 'invalid value for "redirection", the character length must be smaller than or equal to 2048.' + end + + pattern = Regexp.new(/^[A-Za-z][A-Za-z0-9+.-]*:/) if redirection !~ pattern fail ArgumentError, "invalid value for \"redirection\", must conform to the pattern #{pattern}." end @@ -238,6 +277,7 @@ def actions=(actions) def ==(o) return true if self.equal?(o) self.class == o.class && + metadata == o.metadata && title == o.title && message == o.message && subtitle == o.subtitle && @@ -260,7 +300,7 @@ def eql?(o) # Calculates hash code according to all attributes. # @return [Integer] Hash code def hash - [title, message, subtitle, media, redirection, actions, payload, badge, sound, target, tags].hash + [metadata, title, message, subtitle, media, redirection, actions, payload, badge, sound, target, tags].hash end # Builds the object from hash diff --git a/generated/activitysmith_openapi/models/update_app_icon_badge_count422_response.rb b/generated/activitysmith_openapi/models/update_app_icon_badge_count422_response.rb new file mode 100644 index 0000000..3cba603 --- /dev/null +++ b/generated/activitysmith_openapi/models/update_app_icon_badge_count422_response.rb @@ -0,0 +1,105 @@ +=begin +#ActivitySmith API + +#Send push notifications and Live Activities to your own devices via a single API key. + +The version of the OpenAPI document: 1.0.0 + +Generated by: https://openapi-generator.tech +Generator version: 7.7.0 + +=end + +require 'date' +require 'time' + +module OpenapiClient + module UpdateAppIconBadgeCount422Response + class << self + # List of class defined in oneOf (OpenAPI v3) + def openapi_one_of + [ + :'AppIconBadgeCountUpdateError', + :'NoRecipientsError' + ] + end + + # Builds the object + # @param [Mixed] Data to be matched against the list of oneOf items + # @return [Object] Returns the model or the data itself + def build(data) + # Go through the list of oneOf items and attempt to identify the appropriate one. + # Note: + # - We do not attempt to check whether exactly one item matches. + # - No advanced validation of types in some cases (e.g. "x: { type: string }" will happily match { x: 123 }) + # due to the way the deserialization is made in the base_object template (it just casts without verifying). + # - TODO: scalar values are de facto behaving as if they were nullable. + # - TODO: logging when debugging is set. + openapi_one_of.each do |klass| + begin + next if klass == :AnyType # "nullable: true" + typed_data = find_and_cast_into_type(klass, data) + return typed_data if typed_data + rescue # rescue all errors so we keep iterating even if the current item lookup raises + end + end + + openapi_one_of.include?(:AnyType) ? data : nil + end + + private + + SchemaMismatchError = Class.new(StandardError) + + # Note: 'File' is missing here because in the regular case we get the data _after_ a call to JSON.parse. + def find_and_cast_into_type(klass, data) + return if data.nil? + + case klass.to_s + when 'Boolean' + return data if data.instance_of?(TrueClass) || data.instance_of?(FalseClass) + when 'Float' + return data if data.instance_of?(Float) + when 'Integer' + return data if data.instance_of?(Integer) + when 'Time' + return Time.parse(data) + when 'Date' + return Date.parse(data) + when 'String' + return data if data.instance_of?(String) + when 'Object' # "type: object" + return data if data.instance_of?(Hash) + when /\AArray<(?.+)>\z/ # "type: array" + if data.instance_of?(Array) + sub_type = Regexp.last_match[:sub_type] + return data.map { |item| find_and_cast_into_type(sub_type, item) } + end + when /\AHash.+)>\z/ # "type: object" with "additionalProperties: { ... }" + if data.instance_of?(Hash) && data.keys.all? { |k| k.instance_of?(Symbol) || k.instance_of?(String) } + sub_type = Regexp.last_match[:sub_type] + return data.each_with_object({}) { |(k, v), hsh| hsh[k] = find_and_cast_into_type(sub_type, v) } + end + else # model + const = OpenapiClient.const_get(klass) + if const + if const.respond_to?(:openapi_one_of) # nested oneOf model + model = const.build(data) + return model if model + else + # raise if data contains keys that are not known to the model + raise if const.respond_to?(:acceptable_attributes) && !(data.keys - const.acceptable_attributes).empty? + model = const.build_from_hash(data) + return model if model + end + end + end + + raise # if no match by now, raise + rescue + raise SchemaMismatchError, "#{data} doesn't match the #{klass} type" + end + end + end + +end diff --git a/generated/openapi-source.json b/generated/openapi-source.json new file mode 100644 index 0000000..dc05717 --- /dev/null +++ b/generated/openapi-source.json @@ -0,0 +1,6 @@ +{ + "repository": "ActivitySmithHQ/activitysmith-backend", + "commit": "49ad7b083b50f53bc3d81edb77ca6597845160a2", + "path": "openapi.json", + "sha256": "b7e33cd485df8ddc5d7fb7b57b61106fd6f8ff3ffa7cc7bef4ac1ccbbb0cede7" +}