Sha256: 3f8212e45c2b8e3931fc25e3e21aa27ae62fd9b370488d844e571132ae2fdd32

Contents?: true

Size: 750 Bytes

Versions: 5

Compression:

Stored size: 750 Bytes

Contents

require 'json_schema'
require 'json_schema/parser'
require 'json_schema/schema'

module JsonSchema
  module ExampleParsing
    def parse_schema(data, parent, fragment)
      schema = super(data, parent, fragment)
      schema.example = schema.data['example']
      schema
    end
  end

  class Parser
    prepend ExampleParsing
  end

  class Schema
    attr_schema :example

    def make_example
      if example
        return example
      end
      if items
        ex = items.make_example and return Array(ex)
      end
      unless any_of.empty?
        any_of.each {|s| ex = s.make_example and return ex }
      end
      unless all_of.empty?
        any_of.each {|s| ex = s.make_example and return ex }
      end
      nil
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
acter-0.2.0 lib/json_schema-example_parsing.rb
acter-0.1.3 lib/json_schema-example_parsing.rb
acter-0.1.2 lib/json_schema-example_parsing.rb
acter-0.1.1 lib/json_schema-example_parsing.rb
acter-0.1.0 lib/json_schema-example_parsing.rb