Sha256: b7fd63fa2e28fa8d22f8cd264ff03fbd892bd4a3dd2637d6d2b8de6d57ba96b4
Contents?: true
Size: 1.63 KB
Versions: 1
Compression:
Stored size: 1.63 KB
Contents
# frozen_string_literal: true require_relative 'ref_schema_builder' require_relative 'dynamic_schema_builder' require_relative 'array_schema_builder' require_relative 'object_schema_builder' module Meta module JsonSchema class SchemaBuilderTool class << self SCHEMA_BUILDER_OPTIONS = Utils::KeywordArgs::Builder.build do permit_extras true key :ref, alias_names: [:using] key :dynamic_ref, alias_names: [:dynamic_using], normalizer: ->(value) { value.is_a?(Proc) ? { resolve: value } : value } end def build(options = {}, &block) options = SCHEMA_BUILDER_OPTIONS.check(options) if apply_array_schema?(options, block) ArraySchemaBuilder.new(options, &block).to_schema elsif apply_ref_schema?(options, block) RefSchemaBuilder.new(options).to_schema elsif apply_dynamic_schema?(options, block) DynamicSchemaBuilder.new(options).to_schema elsif apply_object_schema?(options, block) ObjectSchemaBuilder.new(options, &block).to_schema else BaseSchema.new(options) end end private def apply_array_schema?(options, block) options[:type] == 'array' end def apply_object_schema?(options, block) (options[:type] == 'object' || options[:type].nil?) && (options[:properties] || block) end def apply_ref_schema?(options, block) options[:ref] != nil end def apply_dynamic_schema?(options, block) options[:dynamic_ref] != nil end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
meta-api-0.0.6 | lib/meta/json_schema/builders/schema_builder_tool.rb |