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 +4 -4
- data/CHANGELOG.md +4 -0
- data/Gemfile +1 -1
- data/Gemfile.lock +24 -17
- data/lib/openapi_parameters/converter.rb +61 -71
- data/lib/openapi_parameters/cookie.rb +1 -1
- data/lib/openapi_parameters/header.rb +1 -1
- data/lib/openapi_parameters/path.rb +1 -1
- data/lib/openapi_parameters/query.rb +8 -1
- data/lib/openapi_parameters/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aa586602013f736682059c6e4615dbd4eb7e57daaa4633e6fb35982261a39e11
|
4
|
+
data.tar.gz: 772345d845efdf6d191c362176deac63036cf064fbd4145c8b375f9bf500faaf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8d21a6c44fc2a1d6d72a3b4cd2bab4804ee4ddfd62d5cf73d3407bf913583b0733b61e9b567da45dca13f9bf2007d58ac6b45fb71299ffa509385aaa1f05b18a
|
7
|
+
data.tar.gz: d7cc40c0551910ba432955e7008762950d8c65df0b06e45d094dca0f8b601c6bacc68e6ef8d223471d9f59c112f7a872fd2a5903a7f78de2d70f0580ccfc9115
|
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
openapi_parameters (0.
|
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.
|
19
|
+
parser (3.2.2.4)
|
19
20
|
ast (~> 2.4.1)
|
20
|
-
|
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.
|
24
|
-
rexml (3.2.
|
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.
|
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.
|
43
|
-
rubocop (1.
|
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.
|
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.
|
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.
|
59
|
+
rubocop-ast (1.30.0)
|
54
60
|
parser (>= 3.2.1.0)
|
55
|
-
rubocop-capybara (2.
|
61
|
+
rubocop-capybara (2.19.0)
|
56
62
|
rubocop (~> 1.41)
|
57
|
-
rubocop-factory_bot (2.
|
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.
|
65
|
-
zeitwerk (2.6.
|
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
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
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
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
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
|
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
|
-
|
59
|
-
schema && schema['type']
|
60
|
-
end
|
43
|
+
private
|
61
44
|
|
62
|
-
|
63
|
-
|
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
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
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
|
-
|
74
|
-
|
55
|
+
def convert_array(array, schema)
|
56
|
+
return array unless array.is_a?(Array)
|
75
57
|
|
76
|
-
|
77
|
-
|
78
|
-
array
|
79
|
-
|
80
|
-
.
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
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.
|
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.
|
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.
|
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.
|
48
|
+
Converter.convert(value, parameter.schema)
|
42
49
|
end
|
43
50
|
end
|
44
51
|
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.
|
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-
|
11
|
+
date: 2023-10-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|