Sha256: 1e942c4995a4fc34a1a1c709dfe3cf60b96d1f7d1407b7aebe71eab56c5c98ff

Contents?: true

Size: 1.76 KB

Versions: 124

Compression:

Stored size: 1.76 KB

Contents

# frozen_string_literal: true

module Aws
  module Plugins

    # Converts input value to JSON Syntax for members with jsonvalue trait
    class JsonvalueConverter < Seahorse::Client::Plugin

      # @api private
      class Handler < Seahorse::Client::Handler

        def call(context)
          context.operation.input.shape.members.each do |m, ref|
            convert_jsonvalue(m, ref, context.params, 'params')
          end
          @handler.call(context)
        end

        def convert_jsonvalue(m, ref, params, context)
          return if params.nil? || !params.key?(m)

          if ref['jsonvalue']
            params[m] = serialize_jsonvalue(params[m], "#{context}[#{m}]")
          else
            case ref.shape
            when Seahorse::Model::Shapes::StructureShape
              ref.shape.members.each do |member_m, ref|
                convert_jsonvalue(member_m, ref, params[m], "#{context}[#{m}]")
              end
            when Seahorse::Model::Shapes::ListShape
              if ref.shape.member['jsonvalue']
                params[m] = params[m].each_with_index.map do |v, i|
                  serialize_jsonvalue(v, "#{context}[#{m}][#{i}]")
                end
              end
            when Seahorse::Model::Shapes::MapShape
              if ref.shape.value['jsonvalue']
                params[m].each do |k, v|
                  params[m][k] = serialize_jsonvalue(v, "#{context}[#{m}][#{k}]")
                end
              end
            end
          end
        end

        def serialize_jsonvalue(v, context)
          unless v.respond_to?(:to_json)
            raise ArgumentError, "The value of #{context} is not JSON serializable."
          end
          v.to_json
        end

      end

      handler(Handler, step: :initialize)
    end

  end
end

Version data entries

124 entries across 124 versions & 1 rubygems

Version Path
aws-sdk-core-3.180.1 lib/aws-sdk-core/plugins/jsonvalue_converter.rb
aws-sdk-core-3.180.0 lib/aws-sdk-core/plugins/jsonvalue_converter.rb
aws-sdk-core-3.179.0 lib/aws-sdk-core/plugins/jsonvalue_converter.rb
aws-sdk-core-3.178.0 lib/aws-sdk-core/plugins/jsonvalue_converter.rb
aws-sdk-core-3.177.0 lib/aws-sdk-core/plugins/jsonvalue_converter.rb
aws-sdk-core-3.176.1 lib/aws-sdk-core/plugins/jsonvalue_converter.rb
aws-sdk-core-3.176.0 lib/aws-sdk-core/plugins/jsonvalue_converter.rb
aws-sdk-core-3.175.0 lib/aws-sdk-core/plugins/jsonvalue_converter.rb
aws-sdk-core-3.174.0 lib/aws-sdk-core/plugins/jsonvalue_converter.rb
aws-sdk-core-3.173.1 lib/aws-sdk-core/plugins/jsonvalue_converter.rb
aws-sdk-core-3.173.0 lib/aws-sdk-core/plugins/jsonvalue_converter.rb
aws-sdk-core-3.172.0 lib/aws-sdk-core/plugins/jsonvalue_converter.rb
aws-sdk-core-3.171.1 lib/aws-sdk-core/plugins/jsonvalue_converter.rb
aws-sdk-core-3.171.0 lib/aws-sdk-core/plugins/jsonvalue_converter.rb
aws-sdk-core-3.170.1 lib/aws-sdk-core/plugins/jsonvalue_converter.rb
aws-sdk-core-3.170.0 lib/aws-sdk-core/plugins/jsonvalue_converter.rb
aws-sdk-core-3.169.0 lib/aws-sdk-core/plugins/jsonvalue_converter.rb
aws-sdk-core-3.168.4 lib/aws-sdk-core/plugins/jsonvalue_converter.rb
aws-sdk-core-3.168.3 lib/aws-sdk-core/plugins/jsonvalue_converter.rb
aws-sdk-core-3.168.2 lib/aws-sdk-core/plugins/jsonvalue_converter.rb