class HttpStub::Server::Stub::Match::Rule::SchemaBody

Constants

MANDATORY_ELEMENT_NAMES

Public Class Methods

create(schema) click to toggle source
# File lib/http_stub/server/stub/match/rule/schema_body.rb, line 15
def create(schema)
  validate(schema)
  begin
    body_class = HttpStub::Server::Stub::Match::Rule.const_get("#{schema[:type].capitalize}SchemaBody")
    body_class.new(schema[:definition])
  rescue NameError
    raise "Stub request body schema #{schema} is invalid: #{schema[:type]} schema is not supported"
  end
end
validate(schema) click to toggle source
# File lib/http_stub/server/stub/match/rule/schema_body.rb, line 25
def validate(schema)
  MANDATORY_ELEMENT_NAMES.each do |name|
    raise "Stub request body schema #{schema} is invalid: #{name} expected" unless schema[name]
  end
end