Sha256: 7cde19ca17d4272a40aacf2155efecc32db74cac2d611c97c623a54fa72568fd

Contents?: true

Size: 695 Bytes

Versions: 2

Compression:

Stored size: 695 Bytes

Contents

require 'json-schema'

module Rswag3
  module Specs
    class ExtendedSchema < JSON::Schema::Draft4
      
      def initialize
        super
        @attributes['type'] = ExtendedTypeAttribute
        @uri = URI.parse('http://tempuri.org/rswag/specs/extended_schema')
        @names = ['http://tempuri.org/rswag/specs/extended_schema']
      end
    end

    class ExtendedTypeAttribute < JSON::Schema::TypeV4Attribute
      
      def self.validate(current_schema, data, fragments, processor, validator, options={})
        return if data.nil? && current_schema.schema['x-nullable'] == true
        super
      end
    end

    JSON::Validator.register_validator(ExtendedSchema.new)
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rswag3-specs-0.0.2 lib/rswag3/specs/extended_schema.rb
rswag3-specs-0.0.1 lib/rswag3/specs/extended_schema.rb