openapi_parameters 0.1.0 → 0.2.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 +5 -1
- data/Gemfile.lock +21 -20
- data/README.md +2 -3
- data/lib/openapi_parameters/converter.rb +2 -4
- data/lib/openapi_parameters/parameter.rb +1 -2
- data/lib/openapi_parameters/path.rb +39 -37
- data/lib/openapi_parameters/version.rb +1 -1
- data/openapi_parameters.gemspec +0 -1
- metadata +2 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ef334fe7ee42e62490cabedbb2d5172c710299e736db3154450d23db23dc4247
|
4
|
+
data.tar.gz: faa2d9c99a2a4f59ebe38b2ff797bcaae165277cc606075168e8cf3191a3722e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6bfe90c227761100d238dec3c51d7f680ce20d39a834b149cdf1426163685e99209b0a4f5b131ff58a9362419d50f5fec966b86747d176609de524d94e17421d
|
7
|
+
data.tar.gz: ec587259898ef7c0004b97a0ab849fb97624de1dd464159dcbd5eeff549e2877465195d94b67cba3fbc5a2f6f245fb0a5863198048a9ba6c04a09324bb1b420e
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
-
## [0.
|
3
|
+
## [0.2.0] - 2023-03-30
|
4
|
+
|
5
|
+
- Breaking: Path parameters are unpacked from a hash, which is usually available from the used Rack web framework. This is much simpler and more performant.
|
6
|
+
|
7
|
+
## [0.1.0] - 2023-03-25
|
4
8
|
|
5
9
|
- Initial release
|
data/Gemfile.lock
CHANGED
@@ -1,9 +1,8 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
openapi_parameters (0.
|
4
|
+
openapi_parameters (0.2.0)
|
5
5
|
rack (>= 2.2)
|
6
|
-
uri_template (>= 0.7, < 2.0)
|
7
6
|
zeitwerk (~> 2.6)
|
8
7
|
|
9
8
|
GEM
|
@@ -11,45 +10,47 @@ GEM
|
|
11
10
|
specs:
|
12
11
|
ast (2.4.2)
|
13
12
|
diff-lcs (1.5.0)
|
14
|
-
json (2.6.
|
13
|
+
json (2.6.3)
|
15
14
|
parallel (1.22.1)
|
16
|
-
parser (3.
|
15
|
+
parser (3.2.1.1)
|
17
16
|
ast (~> 2.4.1)
|
18
|
-
rack (3.0.
|
17
|
+
rack (3.0.7)
|
19
18
|
rainbow (3.1.1)
|
20
19
|
rake (13.0.6)
|
21
|
-
regexp_parser (2.
|
20
|
+
regexp_parser (2.7.0)
|
22
21
|
rexml (3.2.5)
|
23
22
|
rspec (3.12.0)
|
24
23
|
rspec-core (~> 3.12.0)
|
25
24
|
rspec-expectations (~> 3.12.0)
|
26
25
|
rspec-mocks (~> 3.12.0)
|
27
|
-
rspec-core (3.12.
|
26
|
+
rspec-core (3.12.1)
|
28
27
|
rspec-support (~> 3.12.0)
|
29
|
-
rspec-expectations (3.12.
|
28
|
+
rspec-expectations (3.12.2)
|
30
29
|
diff-lcs (>= 1.2.0, < 2.0)
|
31
30
|
rspec-support (~> 3.12.0)
|
32
|
-
rspec-mocks (3.12.
|
31
|
+
rspec-mocks (3.12.5)
|
33
32
|
diff-lcs (>= 1.2.0, < 2.0)
|
34
33
|
rspec-support (~> 3.12.0)
|
35
34
|
rspec-support (3.12.0)
|
36
|
-
rubocop (1.
|
35
|
+
rubocop (1.48.1)
|
37
36
|
json (~> 2.3)
|
38
37
|
parallel (~> 1.10)
|
39
|
-
parser (>= 3.
|
38
|
+
parser (>= 3.2.0.0)
|
40
39
|
rainbow (>= 2.2.2, < 4.0)
|
41
40
|
regexp_parser (>= 1.8, < 3.0)
|
42
41
|
rexml (>= 3.2.5, < 4.0)
|
43
|
-
rubocop-ast (>= 1.
|
42
|
+
rubocop-ast (>= 1.26.0, < 2.0)
|
44
43
|
ruby-progressbar (~> 1.7)
|
45
|
-
unicode-display_width (>=
|
46
|
-
rubocop-ast (1.
|
47
|
-
parser (>= 3.
|
48
|
-
rubocop-
|
49
|
-
rubocop (~> 1.
|
50
|
-
|
51
|
-
|
52
|
-
|
44
|
+
unicode-display_width (>= 2.4.0, < 3.0)
|
45
|
+
rubocop-ast (1.28.0)
|
46
|
+
parser (>= 3.2.1.0)
|
47
|
+
rubocop-capybara (2.17.1)
|
48
|
+
rubocop (~> 1.41)
|
49
|
+
rubocop-rspec (2.19.0)
|
50
|
+
rubocop (~> 1.33)
|
51
|
+
rubocop-capybara (~> 2.17)
|
52
|
+
ruby-progressbar (1.13.0)
|
53
|
+
unicode-display_width (2.4.2)
|
53
54
|
zeitwerk (2.6.7)
|
54
55
|
|
55
56
|
PLATFORMS
|
data/README.md
CHANGED
@@ -28,9 +28,8 @@ query_string = env['QUERY_STRING'] # => 'ids=1&ids=2'
|
|
28
28
|
query_parameters.unpack(query_string) # => { 'ids' => [1, 2] }
|
29
29
|
query_parameters.unpack(query_string, convert: false) # => { 'ids' => ['1', '2'] }
|
30
30
|
|
31
|
-
path_parameters = OpenapiParameters::Path.new(parameters
|
32
|
-
|
33
|
-
path_parameters.unpack(path_info) # => { 'ids' => [1, 2, 3] }
|
31
|
+
path_parameters = OpenapiParameters::Path.new(parameters)
|
32
|
+
path_parameters.unpack(route_params) # => { 'ids' => [1, 2, 3] }
|
34
33
|
|
35
34
|
header_parameters = OpenapiParameters::Header.new(parameters)
|
36
35
|
header_parameters.unpack_env(env)
|
@@ -22,9 +22,7 @@ module OpenapiParameters
|
|
22
22
|
|
23
23
|
private
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
def convert(value, schema)
|
25
|
+
def convert(value, schema) # rubocop:disable Metrics/*
|
28
26
|
check_supported!(schema)
|
29
27
|
return if value.nil?
|
30
28
|
return value if schema.nil?
|
@@ -57,7 +55,7 @@ module OpenapiParameters
|
|
57
55
|
end
|
58
56
|
end
|
59
57
|
|
60
|
-
REF = '$ref'
|
58
|
+
REF = '$ref'
|
61
59
|
private_constant :REF
|
62
60
|
|
63
61
|
def check_supported!(schema)
|
@@ -86,11 +86,10 @@ module OpenapiParameters
|
|
86
86
|
}.freeze
|
87
87
|
private_constant :DEFAULT_STYLE
|
88
88
|
|
89
|
-
|
90
89
|
VALID_LOCATIONS = Set.new(%w[query header path cookie]).freeze
|
91
90
|
private_constant :VALID_LOCATIONS
|
92
91
|
|
93
|
-
REF = '$ref'
|
92
|
+
REF = '$ref'
|
94
93
|
private_constant :REF
|
95
94
|
|
96
95
|
def check_supported!(definition)
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require '
|
3
|
+
require 'rack'
|
4
4
|
|
5
5
|
module OpenapiParameters
|
6
6
|
# Parses OpenAPI path parameters from path template strings and the request path.
|
@@ -8,65 +8,67 @@ module OpenapiParameters
|
|
8
8
|
# @param parameters [Array<Hash>] The OpenAPI path parameters.
|
9
9
|
# @param path [String] The OpenAPI path template string.
|
10
10
|
# @param convert [Boolean] Whether to convert the values to the correct type.
|
11
|
-
def initialize(parameters,
|
11
|
+
def initialize(parameters, convert: true)
|
12
12
|
@parameters = parameters
|
13
|
-
@path = path
|
14
13
|
@convert = convert
|
15
14
|
end
|
16
15
|
|
17
16
|
attr_reader :parameters, :path
|
18
17
|
|
19
|
-
def unpack(
|
20
|
-
|
21
|
-
parameters.each_with_object(parsed_path) do |param, result|
|
18
|
+
def unpack(path_params)
|
19
|
+
parameters.each_with_object({}) do |param, result|
|
22
20
|
parameter = Parameter.new(param)
|
23
|
-
next unless
|
21
|
+
next unless path_params.key?(parameter.name)
|
24
22
|
|
25
23
|
result[parameter.name] = catch :skip do
|
26
|
-
value = unpack_parameter(parameter,
|
24
|
+
value = unpack_parameter(parameter, path_params)
|
27
25
|
@convert ? Converter.call(value, parameter.schema) : value
|
28
26
|
end
|
29
27
|
end
|
30
28
|
end
|
31
29
|
|
30
|
+
private
|
31
|
+
|
32
32
|
def unpack_parameter(parameter, parsed_path)
|
33
33
|
value = parsed_path[parameter.name]
|
34
|
-
if parameter.
|
35
|
-
|
36
|
-
|
37
|
-
end
|
38
|
-
value
|
34
|
+
return value if parameter.primitive? || value.nil?
|
35
|
+
return unpack_array(parameter, value) if parameter.array?
|
36
|
+
return unpack_object(parameter, value) if parameter.object?
|
39
37
|
end
|
40
38
|
|
41
|
-
def
|
42
|
-
|
43
|
-
|
44
|
-
path = @path.dup
|
45
|
-
parameters.each do |p|
|
46
|
-
param = Parameter.new(p)
|
47
|
-
next unless param.array? || param.object?
|
48
|
-
|
49
|
-
path.gsub!(
|
50
|
-
"{#{param.name}}",
|
51
|
-
"{#{operator(param)}#{param.name}#{modifier(param)}}"
|
52
|
-
)
|
53
|
-
end
|
54
|
-
path
|
55
|
-
end
|
56
|
-
end
|
39
|
+
def unpack_array(parameter, value)
|
40
|
+
return value if value.empty?
|
41
|
+
return unpack_matrix(parameter, value) if parameter.style == 'matrix'
|
57
42
|
|
58
|
-
|
43
|
+
value = value[1..] if PREFIXED.key?(parameter.style)
|
44
|
+
value.split(ARRAY_DELIMITER[parameter.style])
|
45
|
+
end
|
59
46
|
|
60
|
-
|
61
|
-
|
47
|
+
def unpack_matrix(parameter, value)
|
48
|
+
result = Rack::Utils.parse_query(value, ';')[parameter.name]
|
49
|
+
return result if parameter.explode?
|
62
50
|
|
63
|
-
|
64
|
-
LIST_OPS[param.style]
|
51
|
+
result.split(',')
|
65
52
|
end
|
66
53
|
|
67
|
-
def
|
68
|
-
return '
|
69
|
-
|
54
|
+
def unpack_object(parameter, value)
|
55
|
+
return Rack::Utils.parse_query(value, ',') if parameter.explode?
|
56
|
+
|
57
|
+
array = unpack_array(parameter, value)
|
58
|
+
throw :skip, value if array.length.odd?
|
59
|
+
|
60
|
+
Hash[*array]
|
70
61
|
end
|
62
|
+
|
63
|
+
PREFIXED = {
|
64
|
+
'label' => '.',
|
65
|
+
'matrix' => ';'
|
66
|
+
}.freeze
|
67
|
+
|
68
|
+
ARRAY_DELIMITER = {
|
69
|
+
'label' => '.',
|
70
|
+
'simple' => ','
|
71
|
+
}.freeze
|
72
|
+
private_constant :ARRAY_DELIMITER
|
71
73
|
end
|
72
74
|
end
|
data/openapi_parameters.gemspec
CHANGED
@@ -38,7 +38,6 @@ Gem::Specification.new do |spec|
|
|
38
38
|
spec.require_paths = ['lib']
|
39
39
|
|
40
40
|
spec.add_dependency 'rack', '>= 2.2'
|
41
|
-
spec.add_dependency 'uri_template', '>= 0.7', '< 2.0'
|
42
41
|
spec.add_dependency 'zeitwerk', '~> 2.6'
|
43
42
|
|
44
43
|
# For more information and examples about making a new gem, check out our
|
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.2.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-03-
|
11
|
+
date: 2023-03-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -24,26 +24,6 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '2.2'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: uri_template
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - ">="
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '0.7'
|
34
|
-
- - "<"
|
35
|
-
- !ruby/object:Gem::Version
|
36
|
-
version: '2.0'
|
37
|
-
type: :runtime
|
38
|
-
prerelease: false
|
39
|
-
version_requirements: !ruby/object:Gem::Requirement
|
40
|
-
requirements:
|
41
|
-
- - ">="
|
42
|
-
- !ruby/object:Gem::Version
|
43
|
-
version: '0.7'
|
44
|
-
- - "<"
|
45
|
-
- !ruby/object:Gem::Version
|
46
|
-
version: '2.0'
|
47
27
|
- !ruby/object:Gem::Dependency
|
48
28
|
name: zeitwerk
|
49
29
|
requirement: !ruby/object:Gem::Requirement
|