Module: Modern::Descriptor::Converters::Output

Defined in:
lib/modern/descriptor/converters/output/base.rb,
lib/modern/descriptor/converters/output/json.rb,
lib/modern/descriptor/converters/output/yaml.rb

Defined Under Namespace

Classes: Base

Constant Summary collapse

JSON =
Base.new(
  media_type: "application/json",
  converter: proc do |_type, retval, _output_converter|
    retval =
      if retval.is_a?(Hash)
        retval.compact
      elsif retval.is_a?(Dry::Struct)
        retval.to_h.compact
      else
        retval
      end

    if retval.respond_to?(:as_json)
      ::JSON.generate(retval.as_json)
    else
      ::JSON.generate(retval)
    end
  end
)
JSONBypass =

We use this because we pre-bake the OpenAPI3 spec JSON and want the content type. However, our route invokes Response#bypass!, so this will never be called.

Base.new(
  media_type: "application/json",
  converter: proc { raise "this should never be called!" }
)
YAMLBypass =

We use this because we pre-bake the OpenAPI3 spec JSON and want the content type. However, our route invokes Response#bypass!, so this will never be called.

Base.new(
  media_type: "application/yaml",
  converter: proc { raise "this should never be called!" }
)