sinatra-schema 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a34c267cb9a3dafd8ddf39079c29d49097587b6a
4
- data.tar.gz: 0b004738e02c95aa6162f2a9a72cf308f4245c79
3
+ metadata.gz: 603462c6a4aa1a4d10f74c16f6f06572a41e7b20
4
+ data.tar.gz: 2dba7d6115b90f6bf2b9fc2b3da650b582aea859
5
5
  SHA512:
6
- metadata.gz: 3321031aea9981da9d327b73d6cd474e099a6bf513158d5864975af2acf52b6f6a7b40fd1fe858604b20fbd87bd31cccd32122544a1a51124f39c2c3d8b0316f
7
- data.tar.gz: 75b6bf7740d69bc5eaebb2a98bd2ced7e8e8fb491caba601ffa73e6fc0774f12a1fdebe692bad7f5996c0749c1c5444af772c72f8dccdbb64792d08525be7a8d
6
+ metadata.gz: 8defef282e9e5912c0ca54d19e94acaca55f426a0dcb8168f97cbc93be76326bdccf420bdfdabd2b5c75b078ac8b9aa9194b28c3487ce660c47017d2f6f13fbd
7
+ data.tar.gz: 7acf6b4143b1d239bb29ef7df0dc035037b95694e6fb07efd295c94a0db0893166558664a593cebcbb6a09b02862b0e1ddb32df528bb41e59c30c3637274be25
@@ -2,7 +2,12 @@ module Sinatra
2
2
  module Schema
3
3
  module ParamValidation
4
4
  def validate_params!(params, properties)
5
- missing = properties.keys.map(&:to_s).sort - params.keys.map(&:to_s).sort
5
+ required_properties = properties.map do |k, prop|
6
+ # ignore nested properties for now, we'll cover these next
7
+ k unless prop.is_a?(Hash) || prop.optional
8
+ end.compact
9
+
10
+ missing = required_properties.map(&:to_s).sort - params.keys.map(&:to_s).sort
6
11
  unless missing.empty?
7
12
  raise BadParams.new("Missing expected params: #{missing.join(',')}")
8
13
  end
@@ -1,5 +1,5 @@
1
1
  module Sinatra
2
2
  module Schema
3
- VERSION = "0.1.1"
3
+ VERSION = "0.1.2"
4
4
  end
5
5
  end
@@ -39,6 +39,12 @@ describe Sinatra::Schema::ParamValidation do
39
39
  assert_equal 200, last_response.status
40
40
  end
41
41
 
42
+ it "allows optional params not set" do
43
+ $properties = { foo: Sinatra::Schema::Definition.new(type: "string", optional: true) }
44
+ post "/", "{}"
45
+ assert_equal 200, last_response.status
46
+ end
47
+
42
48
  it "errors out on wrong format" do
43
49
  $properties = { bool: Sinatra::Schema::Definition.new(type: "boolean") }
44
50
  assert_raises(Sinatra::Schema::BadParams) do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sinatra-schema
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pedro Belo