class Dry::Schema::OpenAPI::SchemaCompiler

@api private

Constants

UnknownConversionError

Public Instance Methods

to_hash() click to toggle source
# File lib/dry/schema/extensions/open_api/schema_compiler.rb, line 13
def to_hash
  transform_json_schema_hash!(super)
end

Private Instance Methods

deep_transform_values!(hash) { |value| ... } click to toggle source
# File lib/dry/schema/extensions/open_api/schema_compiler.rb, line 41
def deep_transform_values!(hash, &block)
  case hash
  when Hash
    hash.transform_values! { |value| deep_transform_values!(yield(value), &block) }
  when Array
    hash.map! { |e| deep_transform_values!(e, &block) }
  else
    yield(hash)
  end
end
transform_json_schema_hash!(hash) click to toggle source
# File lib/dry/schema/extensions/open_api/schema_compiler.rb, line 19
def transform_json_schema_hash!(hash)
  hash.delete(:$schema)
  transform_nullables!(hash)
end
transform_nullables!(hash) click to toggle source
# File lib/dry/schema/extensions/open_api/schema_compiler.rb, line 24
def transform_nullables!(hash)
  deep_transform_values!(hash) do |input|
    next input unless input.respond_to?(:key?)
    next input unless input[:type].respond_to?(:each)

    types = input[:type]
    input[:nullable] = true if types.delete("null")

    if types.length == 1
      input[:type] = types.first
      input
    else
      raise UnknownConversionError, "cannot map type #{types.inspect}"
    end
  end
end