Sha256: d16baf73db04958693bc5d7c51ce124a20804dd3140d27544dea9c3ce47e1f5d

Contents?: true

Size: 1.32 KB

Versions: 1

Compression:

Stored size: 1.32 KB

Contents

module Lina
  class Schema
    def self.argument
      {
        type: "object",
        required: ['name', 'params', 'return'],
        properties: {
          name: {
            type: "string",
            description: "api name"
          },
          description: {
            type: 'string',
          },
          params: {
            type: "object",
          },
          return: {
            type: "object",
          }
        }
      }
    end

    def self.params_validator(params)
      {
        type: 'object',
        properties: params
      }
    end
  end

  class Validator
    def self.params_check(schema, data)
      return unless Lina.params_check
      begin
        JSON::Validator.validate!(schema, data)
      rescue JSON::Schema::ValidationError => e
        raise Lina::ParamsCheckError, e.message
      end
    end

    def self.return_check(schema, data)
      return unless Lina.return_check
      begin
        JSON::Validator.validate!(schema, data)
      rescue JSON::Schema::ValidationError => e
        raise Lina::ReturnCheckError, e.message
      end
    end

    def self.api_spec_check(schema, data)
      begin
        JSON::Validator.validate!(schema, data)
      rescue JSON::Schema::ValidationError => e
        raise Lina::ApiSpecError, e.message
      end
    end
  end # end of class Validator

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
lina-0.0.1 lib/lina/schema.rb