sinatra-schema 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/sinatra/schema/param_validation.rb +6 -1
- data/lib/sinatra/schema/version.rb +1 -1
- data/spec/param_validation_spec.rb +6 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 603462c6a4aa1a4d10f74c16f6f06572a41e7b20
|
4
|
+
data.tar.gz: 2dba7d6115b90f6bf2b9fc2b3da650b582aea859
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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
|
@@ -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
|