module Grape::DSL::Desc

def desc(description, options = nil, &config_block)

Other tags:
    Yield: - a block yielding an instance context with methods mapping to

Options Hash: (**options)
  • :tags (Array[String]) -- a list of tags
  • :security (Array[Hash]) -- a list of security schemes
  • :consumes (Array[String]) -- a list of MIME types the endpoint consume
  • :produces (Array[String]) -- a list of MIME types the endpoint produce
  • :nickname (String) -- nickname of the endpoint
  • :is_array (Boolean) -- response entity is array or not
  • :deprecated (Boolean) -- deprecate the endpoint or not
  • :hidden (Boolean) -- hide the endpoint or not
  • :headers (Hash) -- HTTP headers this method can accept
  • :body_name (String) -- override the autogenerated body name param
  • :named (String) -- a specific name to help find this route
  • :http_codes (Array[Array]) -- possible HTTP codes this
  • :entity (Grape::Entity) -- the entity returned upon a
  • :params (Hash) -- param types and info. normally, you set
  • :summary (String) -- summary for this endpoint
  • :detail (String) -- additional detail about this endpoint

Parameters:
  • options (Hash) -- other properties you can set to describe the
  • description (String) -- descriptive string for this endpoint
def desc(description, options = nil, &config_block)
  opts =
    if config_block
      desc_container(endpoint_configuration).then do |config_class|
        config_class.configure do
          description(description)
        end
        config_class.configure(&config_block)
        config_class.settings
      end
    else
      options&.merge(description: description) || { description: description }
    end
  namespace_setting :description, opts
  route_setting :description, opts
end

def desc_container(endpoint_configuration)

Returns an object which configures itself via an instance-context DSL.
def desc_container(endpoint_configuration)
  Module.new do
    include Grape::Util::StrictHashConfiguration.module(*ROUTE_ATTRIBUTES)
    config_context.define_singleton_method(:configuration) do
      endpoint_configuration
    end
    def config_context.success(*args)
      entity(*args)
    end
    def config_context.failure(*args)
      http_codes(*args)
    end
  end
end

def endpoint_configuration

def endpoint_configuration
  return {} unless defined?(configuration)
  if configuration.respond_to?(:evaluate)
    configuration.evaluate
    # Within `given` or `mounted blocks` the configuration is already evaluated
  elsif configuration.is_a?(Hash)
    configuration
  end
end