openapi_parameters 0.2.2 → 0.3.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: d08c51fd9da86ddf6ef26a0e0778031b33224475091f21bf212cbdda65dd0b80
4
- data.tar.gz: b8c2d56ad760c556cb51996e694d7bb8dbfe3d6188f4407702f698e8ca49b720
3
+ metadata.gz: aa586602013f736682059c6e4615dbd4eb7e57daaa4633e6fb35982261a39e11
4
+ data.tar.gz: 772345d845efdf6d191c362176deac63036cf064fbd4145c8b375f9bf500faaf
5
5
  SHA512:
6
- metadata.gz: fdb3cf5fd14b1decad231f881229d9344020a59722c07086e5a79c0ee6f58bbad335f982a8847d60e64fb9e62c066636a142f514239ca78a7ec5de0916663abd
7
- data.tar.gz: affa943a27552eb4a9a1495272d80d5d8cb2f591145b79758056c2d2eb93949d61e63524733a0474a3596d1a7d0bc4c77c5187e0a7d4bd9cd02e41cbd88e6706
6
+ metadata.gz: 8d21a6c44fc2a1d6d72a3b4cd2bab4804ee4ddfd62d5cf73d3407bf913583b0733b61e9b567da45dca13f9bf2007d58ac6b45fb71299ffa509385aaa1f05b18a
7
+ data.tar.gz: d7cc40c0551910ba432955e7008762950d8c65df0b06e45d094dca0f8b601c6bacc68e6ef8d223471d9f59c112f7a872fd2a5903a7f78de2d70f0580ccfc9115
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.3.0] - 2023-10-27
4
+
5
+ - Query parameters: Don't attempt to convert arras within deepObject objects. Behaviour is not defined in OpenApi 3.1.
6
+
3
7
  ## [0.2.2] - 2023-06-01
4
8
 
5
9
  - Remove superflous validation of "in" property
data/Gemfile CHANGED
@@ -5,8 +5,8 @@ source 'https://rubygems.org'
5
5
  # Specify your gem's dependencies in OpenapiParameters.gemspec
6
6
  gemspec
7
7
 
8
+ gem 'rack-test'
8
9
  gem 'rake', '~> 13.0'
9
-
10
10
  gem 'rspec', '~> 3.0'
11
11
  gem 'rspec-benchmark'
12
12
  gem 'rubocop'
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- openapi_parameters (0.2.2)
4
+ openapi_parameters (0.3.0)
5
5
  rack (>= 2.2)
6
6
  zeitwerk (~> 2.6)
7
7
 
@@ -14,14 +14,19 @@ GEM
14
14
  benchmark-trend (0.4.0)
15
15
  diff-lcs (1.5.0)
16
16
  json (2.6.3)
17
+ language_server-protocol (3.17.0.3)
17
18
  parallel (1.23.0)
18
- parser (3.2.2.1)
19
+ parser (3.2.2.4)
19
20
  ast (~> 2.4.1)
20
- rack (3.0.7)
21
+ racc
22
+ racc (1.7.1)
23
+ rack (3.0.8)
24
+ rack-test (2.1.0)
25
+ rack (>= 1.3)
21
26
  rainbow (3.1.1)
22
27
  rake (13.0.6)
23
- regexp_parser (2.8.0)
24
- rexml (3.2.5)
28
+ regexp_parser (2.8.2)
29
+ rexml (3.2.6)
25
30
  rspec (3.12.0)
26
31
  rspec-core (~> 3.12.0)
27
32
  rspec-expectations (~> 3.12.0)
@@ -36,33 +41,34 @@ GEM
36
41
  rspec-expectations (3.12.3)
37
42
  diff-lcs (>= 1.2.0, < 2.0)
38
43
  rspec-support (~> 3.12.0)
39
- rspec-mocks (3.12.5)
44
+ rspec-mocks (3.12.6)
40
45
  diff-lcs (>= 1.2.0, < 2.0)
41
46
  rspec-support (~> 3.12.0)
42
- rspec-support (3.12.0)
43
- rubocop (1.51.0)
47
+ rspec-support (3.12.1)
48
+ rubocop (1.57.2)
44
49
  json (~> 2.3)
50
+ language_server-protocol (>= 3.17.0)
45
51
  parallel (~> 1.10)
46
- parser (>= 3.2.0.0)
52
+ parser (>= 3.2.2.4)
47
53
  rainbow (>= 2.2.2, < 4.0)
48
54
  regexp_parser (>= 1.8, < 3.0)
49
55
  rexml (>= 3.2.5, < 4.0)
50
- rubocop-ast (>= 1.28.0, < 2.0)
56
+ rubocop-ast (>= 1.28.1, < 2.0)
51
57
  ruby-progressbar (~> 1.7)
52
58
  unicode-display_width (>= 2.4.0, < 3.0)
53
- rubocop-ast (1.28.1)
59
+ rubocop-ast (1.30.0)
54
60
  parser (>= 3.2.1.0)
55
- rubocop-capybara (2.18.0)
61
+ rubocop-capybara (2.19.0)
56
62
  rubocop (~> 1.41)
57
- rubocop-factory_bot (2.23.1)
58
- rubocop (~> 1.33)
59
- rubocop-rspec (2.22.0)
63
+ rubocop-factory_bot (2.24.0)
60
64
  rubocop (~> 1.33)
65
+ rubocop-rspec (2.25.0)
66
+ rubocop (~> 1.40)
61
67
  rubocop-capybara (~> 2.17)
62
68
  rubocop-factory_bot (~> 2.22)
63
69
  ruby-progressbar (1.13.0)
64
- unicode-display_width (2.4.2)
65
- zeitwerk (2.6.8)
70
+ unicode-display_width (2.5.0)
71
+ zeitwerk (2.6.12)
66
72
 
67
73
  PLATFORMS
68
74
  arm64-darwin-21
@@ -72,6 +78,7 @@ PLATFORMS
72
78
 
73
79
  DEPENDENCIES
74
80
  openapi_parameters!
81
+ rack-test
75
82
  rake (~> 13.0)
76
83
  rspec (~> 3.0)
77
84
  rspec-benchmark
@@ -3,87 +3,77 @@
3
3
  module OpenapiParameters
4
4
  ##
5
5
  # Tries to convert a request parameter value (string) to the type specified in the JSON Schema.
6
- class Converter
7
- ##
8
- # @param input [String, Hash, Array] the value to convert
9
- # @param schema [Hash] the schema to use for conversion.
10
- def self.call(input, schema)
11
- new(input, schema).call
12
- end
13
-
14
- def initialize(input, schema)
15
- @input = input
16
- @root_schema = schema
17
- end
18
-
19
- def call
20
- convert(@input, @root_schema)
21
- end
22
-
23
- private
6
+ module Converter
7
+ class << self
8
+ ##
9
+ # @param input [String, Hash, Array] the value to convert
10
+ # @param schema [Hash] the schema to use for conversion.
11
+ def convert(value, schema) # rubocop:disable Metrics
12
+ return if value.nil?
13
+ return value if schema.nil?
24
14
 
25
- def convert(value, schema) # rubocop:disable Metrics/*
26
- # check_supported!(schema)
27
- return if value.nil?
28
- return value if schema.nil?
29
-
30
- case type(schema)
31
- when 'integer'
32
- begin
33
- Integer(value, 10)
34
- rescue StandardError
35
- value
36
- end
37
- when 'number'
38
- begin
39
- Float(value)
40
- rescue StandardError
41
- value
42
- end
43
- when 'boolean'
44
- if value == 'true'
45
- true
15
+ case type(schema)
16
+ when 'integer'
17
+ begin
18
+ Integer(value, 10)
19
+ rescue StandardError
20
+ value
21
+ end
22
+ when 'number'
23
+ begin
24
+ Float(value)
25
+ rescue StandardError
26
+ value
27
+ end
28
+ when 'boolean'
29
+ if value == 'true'
30
+ true
31
+ else
32
+ value == 'false' ? false : value
33
+ end
34
+ when 'object'
35
+ convert_object(value, schema)
36
+ when 'array'
37
+ convert_array(value, schema)
46
38
  else
47
- value == 'false' ? false : value
39
+ value
48
40
  end
49
- when 'object'
50
- convert_object(value, schema)
51
- when 'array'
52
- convert_array(value, schema)
53
- else
54
- value
55
41
  end
56
- end
57
42
 
58
- def type(schema)
59
- schema && schema['type']
60
- end
43
+ private
61
44
 
62
- def convert_object(object, schema)
63
- object.each_with_object({}) do |(key, value), hsh|
64
- hsh[key] = convert(value, schema['properties']&.fetch(key))
45
+ def type(schema)
46
+ schema && schema['type']
65
47
  end
66
- end
67
48
 
68
- def convert_array(array, schema)
69
- item_schema = schema['items']
70
- prefix_schemas = schema['prefixItems']
71
- return convert_array_with_prefixes(array, prefix_schemas, item_schema) if prefix_schemas
49
+ def convert_object(object, schema)
50
+ object.each_with_object({}) do |(key, value), hsh|
51
+ hsh[key] = convert(value, schema['properties']&.fetch(key))
52
+ end
53
+ end
72
54
 
73
- array.map { |item| convert(item, item_schema) }
74
- end
55
+ def convert_array(array, schema)
56
+ return array unless array.is_a?(Array)
75
57
 
76
- def convert_array_with_prefixes(array, prefix_schemas, item_schema)
77
- prefixes =
78
- array
79
- .slice(0, prefix_schemas.size)
80
- .each_with_index
81
- .map { |item, index| convert(item, prefix_schemas[index]) }
82
- array =
83
- array[prefix_schemas.size..].map! do |item|
84
- convert(item, item_schema)
85
- end
86
- prefixes + array
58
+ item_schema = schema['items']
59
+ prefix_schemas = schema['prefixItems']
60
+ return convert_array_with_prefixes(array, prefix_schemas, item_schema) if prefix_schemas
61
+
62
+ array.map { |item| convert(item, item_schema) }
63
+ end
64
+
65
+ def convert_array_with_prefixes(array, prefix_schemas, item_schema)
66
+ prefixes =
67
+ array
68
+ .slice(0, prefix_schemas.size)
69
+ .each_with_index
70
+ .map { |item, index| convert(item, prefix_schemas[index]) }
71
+ array =
72
+ array[prefix_schemas.size..].map! do |item|
73
+ convert(item, item_schema)
74
+ end
75
+ prefixes + array
76
+ end
87
77
  end
88
78
  end
89
79
  end
@@ -21,7 +21,7 @@ module OpenapiParameters
21
21
 
22
22
  result[parameter.name] = catch :skip do
23
23
  value = Unpacker.unpack_value(parameter, cookies[parameter.name])
24
- @convert ? Converter.call(value, parameter.schema) : value
24
+ @convert ? Converter.convert(value, parameter.schema) : value
25
25
  end
26
26
  end
27
27
  end
@@ -18,7 +18,7 @@ module OpenapiParameters
18
18
 
19
19
  result[parameter.name] = catch :skip do
20
20
  value = Unpacker.unpack_value(parameter, headers[parameter.name])
21
- @convert ? Converter.call(value, parameter.schema) : value
21
+ @convert ? Converter.convert(value, parameter.schema) : value
22
22
  end
23
23
  end
24
24
  end
@@ -22,7 +22,7 @@ module OpenapiParameters
22
22
 
23
23
  result[parameter.name] = catch :skip do
24
24
  value = Unpacker.unpack_value(parameter, path_params[parameter.name])
25
- @convert ? Converter.call(value, parameter.schema) : value
25
+ @convert ? Converter.convert(value, parameter.schema) : value
26
26
  end
27
27
  end
28
28
  end
@@ -34,11 +34,18 @@ module OpenapiParameters
34
34
 
35
35
  private
36
36
 
37
+ def convert_primitive(value, parameter)
38
+ return value unless @convert
39
+ return value if value == ''
40
+
41
+ Converter.convert_primitive(value, parameter.schema)
42
+ end
43
+
37
44
  def convert(value, parameter)
38
45
  return value unless @convert
39
46
  return value if value == ''
40
47
 
41
- Converter.call(value, parameter.schema)
48
+ Converter.convert(value, parameter.schema)
42
49
  end
43
50
  end
44
51
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module OpenapiParameters
4
- VERSION = '0.2.2'
4
+ VERSION = '0.3.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openapi_parameters
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andreas Haller
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-06-01 00:00:00.000000000 Z
11
+ date: 2023-10-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack