committee 2.4.0 → 2.5.0

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
  SHA256:
3
- metadata.gz: eac1e86868d4ca6f8b7ef27f62ec87131ba1399985f48b0e7846a5ceda6d81cc
4
- data.tar.gz: a0e76eea124800b0d8d328657ffb30efc3c683bbfd47707ce9c148500fc79307
3
+ metadata.gz: 80e547ab72368f1c052c9ca8617977a0291855b598465baf2021a2e6724ba27e
4
+ data.tar.gz: cf618eb555e631ef4a6dc51b0b8bcc856b58102193eaffb84d5cd6e68f2852da
5
5
  SHA512:
6
- metadata.gz: dcaa28428558ae7b9f6ce8679e826e62bdc0640228e35fb41a0998a1ccbbab4d505bc6e23ad052b907a45be6d2003152ab9803e132907a3c68b1a2fbf7fc5292
7
- data.tar.gz: 0a1d640b9305e12a2ac6b7436b2971a8a1568322aa1d75a25f8ec4a25aed50229c5bd5c99e317c9c243d22099c1855ea93fbf17cc0692488a35a8f1ee03f8959
6
+ metadata.gz: 2db3579f4329429aac202ff34c111b0f92609de39ab6f1d1e4264910d42612d1b8c20fcdf464881f148012086e57bd0fedd3730dec76d500235764a599e0676d
7
+ data.tar.gz: d680e5a57f7393a64336e17a593a862bab689992d032b8ef5fabfa735d80815ee6739801602c277b851d930f296b511b19bda412555e1a8c96b4150a9f92f783
@@ -173,6 +173,26 @@ module Committee::Drivers
173
173
  # therefore this should map over quite well.
174
174
  param_schema.type = [param_data["type"]]
175
175
 
176
+ param_schema.enum = param_data["enum"] unless param_data["enum"].nil?
177
+
178
+ # validation: string
179
+ param_schema.format = param_data["format"] unless param_data["format"].nil?
180
+ param_schema.pattern = param_data["pattern"] unless param_data["pattern"].nil?
181
+ param_schema.min_length = param_data["minLength"] unless param_data["minLength"].nil?
182
+ param_schema.max_length = param_data["maxLength"] unless param_data["maxLength"].nil?
183
+
184
+ # validation: array
185
+ param_schema.min_items = param_data["minItems"] unless param_data["minItems"].nil?
186
+ param_schema.max_items = param_data["maxItems"] unless param_data["maxItems"].nil?
187
+ param_schema.unique_items = param_data["uniqueItems"] unless param_data["uniqueItems"].nil?
188
+
189
+ # validation: number/integer
190
+ param_schema.min = param_data["minimum"] unless param_data["minimum"].nil?
191
+ param_schema.min_exclusive = param_data["exclusiveMinimum"] unless param_data["exclusiveMinimum"].nil?
192
+ param_schema.max = param_data["maximum"] unless param_data["maximum"].nil?
193
+ param_schema.max_exclusive = param_data["exclusiveMaximum"] unless param_data["exclusiveMaximum"].nil?
194
+ param_schema.multiple_of = param_data["multipleOf"] unless param_data["multipleOf"].nil?
195
+
176
196
  # And same idea: despite parameters not being schemas, the items
177
197
  # key (if preset) is actually a schema that defines each item of an
178
198
  # array type, so we can just reflect that directly onto our
@@ -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 "[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" => [
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: 2.4.0
4
+ version: 2.5.0
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-20 00:00:00.000000000 Z
12
+ date: 2019-01-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json_schema
@@ -213,7 +213,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
213
213
  version: '0'
214
214
  requirements: []
215
215
  rubyforge_project:
216
- rubygems_version: 2.7.3
216
+ rubygems_version: 2.7.7
217
217
  signing_key:
218
218
  specification_version: 4
219
219
  summary: A collection of Rack middleware to support JSON Schema.