committee 3.0.0.beta2 → 3.0.0.beta3
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/committee/drivers/open_api_2.rb +20 -0
- data/lib/committee/schema_validator/open_api_3.rb +10 -2
- data/lib/committee/schema_validator/open_api_3/operation_wrapper.rb +0 -7
- data/test/drivers/open_api_2_test.rb +81 -0
- data/test/middleware/request_validation_open_api_3_test.rb +14 -0
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4af30e34beff4126b7d69135a887fd8e984741f0700be148eaad1109b7b96511
|
4
|
+
data.tar.gz: 98075cfbcf0207f6d4278eaef4d6fb9d13681648748d768a35e637c45e96be5b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3f8c7471aaba3b7df58bb4c5e2f5b6311dfd91d2e6d8fd28848b715f4f2d59a418c275a76ecdbce34c1aa5222c1a2c18198ffcd815588f81f6d319ff09e1e1f5
|
7
|
+
data.tar.gz: dbc206cf90277dad16b2611fd489889c229d27616c0eecbdcf9ed59e494c588b1d0e3eba31e98e8da44417c13d15c6566fe28d9cb2e1df11cc552a0553c1dca5
|
@@ -181,6 +181,26 @@ module Committee::Drivers
|
|
181
181
|
# therefore this should map over quite well.
|
182
182
|
param_schema.type = [param_data["type"]]
|
183
183
|
|
184
|
+
param_schema.enum = param_data["enum"] unless param_data["enum"].nil?
|
185
|
+
|
186
|
+
# validation: string
|
187
|
+
param_schema.format = param_data["format"] unless param_data["format"].nil?
|
188
|
+
param_schema.pattern = Regexp.new(param_data["pattern"]) unless param_data["pattern"].nil?
|
189
|
+
param_schema.min_length = param_data["minLength"] unless param_data["minLength"].nil?
|
190
|
+
param_schema.max_length = param_data["maxLength"] unless param_data["maxLength"].nil?
|
191
|
+
|
192
|
+
# validation: array
|
193
|
+
param_schema.min_items = param_data["minItems"] unless param_data["minItems"].nil?
|
194
|
+
param_schema.max_items = param_data["maxItems"] unless param_data["maxItems"].nil?
|
195
|
+
param_schema.unique_items = param_data["uniqueItems"] unless param_data["uniqueItems"].nil?
|
196
|
+
|
197
|
+
# validation: number/integer
|
198
|
+
param_schema.min = param_data["minimum"] unless param_data["minimum"].nil?
|
199
|
+
param_schema.min_exclusive = param_data["exclusiveMinimum"] unless param_data["exclusiveMinimum"].nil?
|
200
|
+
param_schema.max = param_data["maximum"] unless param_data["maximum"].nil?
|
201
|
+
param_schema.max_exclusive = param_data["exclusiveMaximum"] unless param_data["exclusiveMaximum"].nil?
|
202
|
+
param_schema.multiple_of = param_data["multipleOf"] unless param_data["multipleOf"].nil?
|
203
|
+
|
184
204
|
# And same idea: despite parameters not being schemas, the items
|
185
205
|
# key (if preset) is actually a schema that defines each item of an
|
186
206
|
# array type, so we can just reflect that directly onto our
|
@@ -17,7 +17,7 @@ class Committee::SchemaValidator
|
|
17
17
|
|
18
18
|
request_schema_validation(request)
|
19
19
|
|
20
|
-
|
20
|
+
copy_coerced_data_to_query_hash(request)
|
21
21
|
end
|
22
22
|
|
23
23
|
def response_validate(status, headers, response, test_method = false)
|
@@ -71,5 +71,13 @@ class Committee::SchemaValidator
|
|
71
71
|
schema_validator: self
|
72
72
|
).call
|
73
73
|
end
|
74
|
+
|
75
|
+
def copy_coerced_data_to_query_hash(request)
|
76
|
+
return if request.env["rack.request.query_hash"].nil? || request.env["rack.request.query_hash"].empty?
|
77
|
+
|
78
|
+
request.env["rack.request.query_hash"].keys.each do |k|
|
79
|
+
request.env["rack.request.query_hash"][k] = request.env[validator_option.params_key][k]
|
80
|
+
end
|
81
|
+
end
|
74
82
|
end
|
75
|
-
end
|
83
|
+
end
|
@@ -20,13 +20,6 @@ module Committee
|
|
20
20
|
request_operation.validate_path_params(options)
|
21
21
|
end
|
22
22
|
|
23
|
-
def coerce_request_parameter(params, headers, validator_option)
|
24
|
-
options = build_openapi_parser_get_option(validator_option)
|
25
|
-
return unless options.coerce_value
|
26
|
-
|
27
|
-
request_operation.validate_request_parameter(params, headers, options)
|
28
|
-
end
|
29
|
-
|
30
23
|
# @param [Boolean] strict when not content_type or status code definition, raise error
|
31
24
|
def validate_response_params(status_code, headers, response_data, strict, check_header)
|
32
25
|
request_body = OpenAPIParser::RequestOperation::ValidatableResponseBody.new(status_code, response_data, headers)
|
@@ -219,6 +219,19 @@ describe Committee::Drivers::OpenAPI2::ParameterSchemaBuilder do
|
|
219
219
|
assert_equal ["limit"], schema.properties.keys
|
220
220
|
assert_equal [], schema.required
|
221
221
|
assert_equal ["integer"], schema.properties["limit"].type
|
222
|
+
assert_nil schema.properties["limit"].enum
|
223
|
+
assert_nil schema.properties["limit"].format
|
224
|
+
assert_nil schema.properties["limit"].pattern
|
225
|
+
assert_nil schema.properties["limit"].min_length
|
226
|
+
assert_nil schema.properties["limit"].max_length
|
227
|
+
assert_nil schema.properties["limit"].min_items
|
228
|
+
assert_nil schema.properties["limit"].max_items
|
229
|
+
assert_nil schema.properties["limit"].unique_items
|
230
|
+
assert_nil schema.properties["limit"].min
|
231
|
+
assert_nil schema.properties["limit"].min_exclusive
|
232
|
+
assert_nil schema.properties["limit"].max
|
233
|
+
assert_nil schema.properties["limit"].max_exclusive
|
234
|
+
assert_nil schema.properties["limit"].multiple_of
|
222
235
|
end
|
223
236
|
|
224
237
|
it "reflects a required property into a schema" do
|
@@ -242,6 +255,9 @@ describe Committee::Drivers::OpenAPI2::ParameterSchemaBuilder do
|
|
242
255
|
{
|
243
256
|
"name" => "tags",
|
244
257
|
"type" => "array",
|
258
|
+
"minItems" => 1,
|
259
|
+
"maxItems" => 10,
|
260
|
+
"uniqueItems" => true,
|
245
261
|
"items" => {
|
246
262
|
"type" => "string"
|
247
263
|
}
|
@@ -252,9 +268,74 @@ describe Committee::Drivers::OpenAPI2::ParameterSchemaBuilder do
|
|
252
268
|
|
253
269
|
assert_nil schema_data
|
254
270
|
assert_equal ["array"], schema.properties["tags"].type
|
271
|
+
assert_equal 1, schema.properties["tags"].min_items
|
272
|
+
assert_equal 10, schema.properties["tags"].max_items
|
273
|
+
assert_equal true, schema.properties["tags"].unique_items
|
255
274
|
assert_equal({ "type" => "string" }, schema.properties["tags"].items)
|
256
275
|
end
|
257
276
|
|
277
|
+
it "reflects a enum property into a schema" do
|
278
|
+
data = {
|
279
|
+
"parameters" => [
|
280
|
+
{
|
281
|
+
"name" => "type",
|
282
|
+
"type" => "string",
|
283
|
+
"enum" => ["hoge", "fuga"]
|
284
|
+
}
|
285
|
+
]
|
286
|
+
}
|
287
|
+
schema, schema_data = call(data)
|
288
|
+
|
289
|
+
assert_nil schema_data
|
290
|
+
assert_equal ["hoge", "fuga"], schema.properties["type"].enum
|
291
|
+
end
|
292
|
+
|
293
|
+
it "reflects string properties into a schema" do
|
294
|
+
data = {
|
295
|
+
"parameters" => [
|
296
|
+
{
|
297
|
+
"name" => "password",
|
298
|
+
"type" => "string",
|
299
|
+
"format" => "password",
|
300
|
+
"pattern" => "[a-zA-Z0-9]+",
|
301
|
+
"minLength" => 6,
|
302
|
+
"maxLength" => 30
|
303
|
+
}
|
304
|
+
]
|
305
|
+
}
|
306
|
+
schema, schema_data = call(data)
|
307
|
+
|
308
|
+
assert_nil schema_data
|
309
|
+
assert_equal "password", schema.properties["password"].format
|
310
|
+
assert_equal Regexp.new("[a-zA-Z0-9]+"), schema.properties["password"].pattern
|
311
|
+
assert_equal 6, schema.properties["password"].min_length
|
312
|
+
assert_equal 30, schema.properties["password"].max_length
|
313
|
+
end
|
314
|
+
|
315
|
+
it "reflects number properties into a schema" do
|
316
|
+
data = {
|
317
|
+
"parameters" => [
|
318
|
+
{
|
319
|
+
"name" => "limit",
|
320
|
+
"type" => "integer",
|
321
|
+
"minimum" => 20,
|
322
|
+
"exclusiveMinimum" => true,
|
323
|
+
"maximum" => 100,
|
324
|
+
"exclusiveMaximum" => false,
|
325
|
+
"multipleOf" => 10
|
326
|
+
}
|
327
|
+
]
|
328
|
+
}
|
329
|
+
schema, schema_data = call(data)
|
330
|
+
|
331
|
+
assert_nil schema_data
|
332
|
+
assert_equal 20, schema.properties["limit"].min
|
333
|
+
assert_equal true, schema.properties["limit"].min_exclusive
|
334
|
+
assert_equal 100, schema.properties["limit"].max
|
335
|
+
assert_equal false, schema.properties["limit"].max_exclusive
|
336
|
+
assert_equal 10, schema.properties["limit"].multiple_of
|
337
|
+
end
|
338
|
+
|
258
339
|
it "returns schema data for a body parameter" do
|
259
340
|
data = {
|
260
341
|
"parameters" => [
|
@@ -42,6 +42,20 @@ describe Committee::Middleware::RequestValidation do
|
|
42
42
|
assert_equal 200, last_response.status
|
43
43
|
end
|
44
44
|
|
45
|
+
it "passes given a datetime and with coerce_date_times enabled on GET endpoint with request body(old behavior)" do
|
46
|
+
params = { "datetime_string" => "2016-04-01T16:00:00.000+09:00" }
|
47
|
+
|
48
|
+
check_parameter = lambda { |env|
|
49
|
+
assert_equal DateTime, env['committee.params']["datetime_string"].class
|
50
|
+
[200, {}, []]
|
51
|
+
}
|
52
|
+
|
53
|
+
@app = new_rack_app_with_lambda(check_parameter, schema: open_api_3_schema, coerce_date_times: true)
|
54
|
+
|
55
|
+
get "/get_body_test", { no_problem: true }, { input: params.to_json }
|
56
|
+
assert_equal 200, last_response.status
|
57
|
+
end
|
58
|
+
|
45
59
|
it "passes given a datetime and with coerce_date_times enabled on POST endpoint" do
|
46
60
|
params = {
|
47
61
|
"nested_array" => [
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: committee
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.0.
|
4
|
+
version: 3.0.0.beta3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brandur
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2019-01-
|
12
|
+
date: 2019-01-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: json_schema
|
@@ -241,8 +241,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
241
241
|
- !ruby/object:Gem::Version
|
242
242
|
version: 1.3.1
|
243
243
|
requirements: []
|
244
|
-
|
245
|
-
rubygems_version: 2.7.7
|
244
|
+
rubygems_version: 3.0.1
|
246
245
|
signing_key:
|
247
246
|
specification_version: 4
|
248
247
|
summary: A collection of Rack middleware to support JSON Schema.
|