module Aws::Api::Customizations

def api(prefix, &block)

def api(prefix, &block)
  @apis[prefix] = block
end

def apply_api_customizations(api)

def apply_api_customizations(api)
  metadata = api['metadata'] || {}
  prefix = metadata['serviceFullName']
  # event stream is not supported at V2
  api = exclude_eventstream(api) if api['operations']
  @apis[prefix].call(api) if @apis[prefix]
end

def apply_doc_customizations(api, docs)

def apply_doc_customizations(api, docs)
  prefix = api.metadata['serviceFullName']
  @docs[prefix].call(docs) if @docs[prefix]
end

def apply_plugins(client_class)

def apply_plugins(client_class)
  prefix = client_class.api.metadata['serviceFullName']
  if @plugins[prefix]
    @plugins[prefix][:add].each { |p| client_class.add_plugin(p) }
    @plugins[prefix][:remove].each { |p| client_class.remove_plugin(p) }
  end
end

def doc(prefix, &block)

def doc(prefix, &block)
  @docs[prefix] = block
end

def exclude_eventstream(api)

def exclude_eventstream(api)
  api['operations'].each do |name, ref|
    inbound = ref['input'] && is_eventstream?(api, ref['input']['shape'])
    outbound = ref['output'] && is_eventstream?(api, ref['output']['shape'])
    api['operations'].delete(name) if !!inbound || !!outbound
  end
  api
end

def is_eventstream?(api, shape_name)

def is_eventstream?(api, shape_name)
  shape = api['shapes'][shape_name]
  if shape['type'] == 'structure'
    eventstream = false
    shape['members'].each do |_, m_ref|
      eventstream ||= api['shapes'][m_ref['shape']]['eventstream']
    end
    eventstream
  else
    # non structure request/response shape
    # check if it's eventstream itself
    shape['eventstream']
  end
end

def plugins(prefix, options)

def plugins(prefix, options)
  @plugins[prefix] = {
    add: options[:add] || [],
    remove: options[:remove] || [],
  }
end