Sha256: 333de9c144e93a89156b49b3bd14ae1aad00cdf75d6bc0aa4d2c677cea4296f0

Contents?: true

Size: 1.5 KB

Versions: 25

Compression:

Stored size: 1.5 KB

Contents

# frozen_string_literal: true
require 'json-schema'

module Hyrax
  module Arkivo
    ITEM_SCHEMA = {
      type: 'object',
      properties: {
        token: { type: 'string', required: true },
        metadata: {
          type: 'object',
          required: true,
          properties: {
            title: { type: 'string', required: true },
            license: { type: 'string', required: true },
            resourceType: { type: 'string' },
            description: { type: 'string' },
            publisher: { type: 'string' },
            dateCreated: { type: 'string' },
            basedNear: { type: 'string' },
            identifier: { type: 'string' },
            url: { type: 'string' },
            language: { type: 'string' }
          }
        },
        file: {
          type: 'object',
          required: true,
          properties: {
            base64: { type: 'string', required: true },
            md5: { type: 'string', required: true },
            filename: { type: 'string', required: true },
            contentType: { type: 'string', required: true }
          }
        }
      }
    }.freeze

    class InvalidItem < RuntimeError
    end

    class SchemaValidator
      attr_reader :item

      def initialize(item)
        @item = item
      end

      def call
        JSON::Validator.validate!(Hyrax::Arkivo::ITEM_SCHEMA, item, version: :draft3)
      rescue JSON::Schema::ValidationError => exception
        raise Hyrax::Arkivo::InvalidItem, exception.message
      end
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
hyrax-5.0.1 lib/hyrax/arkivo/schema_validator.rb
hyrax-5.0.0 lib/hyrax/arkivo/schema_validator.rb
hyrax-5.0.0.rc3 lib/hyrax/arkivo/schema_validator.rb
hyrax-5.0.0.rc2 lib/hyrax/arkivo/schema_validator.rb
hyrax-5.0.0.rc1 lib/hyrax/arkivo/schema_validator.rb
hyrax-3.6.0 lib/hyrax/arkivo/schema_validator.rb
hyrax-4.0.0 lib/hyrax/arkivo/schema_validator.rb
hyrax-4.0.0.rc3 lib/hyrax/arkivo/schema_validator.rb
hyrax-4.0.0.rc2 lib/hyrax/arkivo/schema_validator.rb
hyrax-4.0.0.rc1 lib/hyrax/arkivo/schema_validator.rb
hyrax-3.5.0 lib/hyrax/arkivo/schema_validator.rb
hyrax-4.0.0.beta2 lib/hyrax/arkivo/schema_validator.rb
hyrax-3.4.2 lib/hyrax/arkivo/schema_validator.rb
hyrax-4.0.0.beta1 lib/hyrax/arkivo/schema_validator.rb
hyrax-3.4.1 lib/hyrax/arkivo/schema_validator.rb
hyrax-3.4.0 lib/hyrax/arkivo/schema_validator.rb
hyrax-3.3.0 lib/hyrax/arkivo/schema_validator.rb
hyrax-3.2.0 lib/hyrax/arkivo/schema_validator.rb
hyrax-3.1.0 lib/hyrax/arkivo/schema_validator.rb
hyrax-3.0.2 lib/hyrax/arkivo/schema_validator.rb