Sha256: 1dd78fce5d82161311ccb0431207b9a84cb461c659595e158a515821cf8c8960

Contents?: true

Size: 683 Bytes

Versions: 21

Compression:

Stored size: 683 Bytes

Contents

# frozen_string_literal: true

require "dry/schema/extensions/json_schema/schema_compiler"

module Dry
  module Schema
    # JSONSchema extension
    #
    # @api public
    module JSONSchema
      module SchemaMethods
        # Convert the schema into a JSON schema hash
        #
        # @param [Symbol] loose Compile the schema in "loose" mode
        #
        # @return [Hash<Symbol=>Hash>]
        #
        # @api public
        def json_schema(loose: false)
          compiler = SchemaCompiler.new(root: true, loose: loose)
          compiler.call(to_ast)
          compiler.to_hash
        end
      end
    end

    Processor.include(JSONSchema::SchemaMethods)
  end
end

Version data entries

21 entries across 21 versions & 2 rubygems

Version Path
dry-schema-extensions-1.0.0 lib/dry/schema/extensions/json_schema.rb