Skip to content
Matt Muller edited this page Oct 5, 2021 · 6 revisions

Params are modules that convert user provided input into rigid shapes used by middleware. Params have a 1:1 mapping to Smithy shapes.

Param modules will initialize Types and set members if they exist. Params will do lightweight validation (using Seahorse::Validator) for aggregate structures, such as Array, Hash, and Set, so that values can be iterated over.

module SampleService
  module Params
    module HighScoreParams
      def self.build(params, context: '')
        Seahorse::Validator.validate!(params, Hash, Types::HighScoreParams, context: context)
        type = Types::HighScoreParams.new
        type.game = params[:game]
        type.score = params[:score]
        type.simple_list = SimpleList.build(params[:simple_list], context: "#{context}[:simple_list]") if params[:simple_list]
        type
      end
    end

    module SimpleList
      def self.build(params, context: '')
        Seahorse::Validator.validate!(params, Array, context: context)

        params.each_with_index.map do |element, index|
          element
        end
      end
    end 
  end
end