openapi_parameters 0.1.0 → 0.2.1
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/CHANGELOG.md +9 -1
- data/Gemfile +1 -0
- data/Gemfile.lock +30 -20
- data/README.md +4 -4
- 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 +4 -5
- metadata +8 -28
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8483c9c6b0071290af337487bdec6ae34c94904497c7dce5abb120c497eef94e
|
|
4
|
+
data.tar.gz: 78a862041af3c393e242185021eb52314f8d47e81c03160c41b46a2437379db7
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8234ded58769039d9366d94d0482be0ea0ba1ed22385ebb8d9f42ec9c1d93e3b3d5b295bc09cc049ba75613886dc7a1e8b7b6d83af953061591bb21d4c4ae80f
|
|
7
|
+
data.tar.gz: 1f0cac157a4601b405199bbddce07cb6bb41f701cb69570ef8e8ecd92ad610a504c066a834f9aad9da157ede3987bd27356e59dd5ecdd29ce3ac2074d6f7ffbc
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
## [Unreleased]
|
|
2
2
|
|
|
3
|
-
## [0.1
|
|
3
|
+
## [0.2.1] - 2023-03-31
|
|
4
|
+
|
|
5
|
+
- Fix links in gemspec
|
|
6
|
+
|
|
7
|
+
## [0.2.0] - 2023-03-30
|
|
8
|
+
|
|
9
|
+
- 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.
|
|
10
|
+
|
|
11
|
+
## [0.1.0] - 2023-03-25
|
|
4
12
|
|
|
5
13
|
- Initial release
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
|
@@ -1,55 +1,64 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
openapi_parameters (0.1
|
|
4
|
+
openapi_parameters (0.2.1)
|
|
5
5
|
rack (>= 2.2)
|
|
6
|
-
uri_template (>= 0.7, < 2.0)
|
|
7
6
|
zeitwerk (~> 2.6)
|
|
8
7
|
|
|
9
8
|
GEM
|
|
10
9
|
remote: https://rubygems.org/
|
|
11
10
|
specs:
|
|
12
11
|
ast (2.4.2)
|
|
12
|
+
benchmark-malloc (0.2.0)
|
|
13
|
+
benchmark-perf (0.6.0)
|
|
14
|
+
benchmark-trend (0.4.0)
|
|
13
15
|
diff-lcs (1.5.0)
|
|
14
|
-
json (2.6.
|
|
16
|
+
json (2.6.3)
|
|
15
17
|
parallel (1.22.1)
|
|
16
|
-
parser (3.
|
|
18
|
+
parser (3.2.1.1)
|
|
17
19
|
ast (~> 2.4.1)
|
|
18
|
-
rack (3.0.
|
|
20
|
+
rack (3.0.7)
|
|
19
21
|
rainbow (3.1.1)
|
|
20
22
|
rake (13.0.6)
|
|
21
|
-
regexp_parser (2.
|
|
23
|
+
regexp_parser (2.7.0)
|
|
22
24
|
rexml (3.2.5)
|
|
23
25
|
rspec (3.12.0)
|
|
24
26
|
rspec-core (~> 3.12.0)
|
|
25
27
|
rspec-expectations (~> 3.12.0)
|
|
26
28
|
rspec-mocks (~> 3.12.0)
|
|
27
|
-
rspec-
|
|
29
|
+
rspec-benchmark (0.6.0)
|
|
30
|
+
benchmark-malloc (~> 0.2)
|
|
31
|
+
benchmark-perf (~> 0.6)
|
|
32
|
+
benchmark-trend (~> 0.4)
|
|
33
|
+
rspec (>= 3.0)
|
|
34
|
+
rspec-core (3.12.1)
|
|
28
35
|
rspec-support (~> 3.12.0)
|
|
29
|
-
rspec-expectations (3.12.
|
|
36
|
+
rspec-expectations (3.12.2)
|
|
30
37
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
31
38
|
rspec-support (~> 3.12.0)
|
|
32
|
-
rspec-mocks (3.12.
|
|
39
|
+
rspec-mocks (3.12.5)
|
|
33
40
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
34
41
|
rspec-support (~> 3.12.0)
|
|
35
42
|
rspec-support (3.12.0)
|
|
36
|
-
rubocop (1.
|
|
43
|
+
rubocop (1.48.1)
|
|
37
44
|
json (~> 2.3)
|
|
38
45
|
parallel (~> 1.10)
|
|
39
|
-
parser (>= 3.
|
|
46
|
+
parser (>= 3.2.0.0)
|
|
40
47
|
rainbow (>= 2.2.2, < 4.0)
|
|
41
48
|
regexp_parser (>= 1.8, < 3.0)
|
|
42
49
|
rexml (>= 3.2.5, < 4.0)
|
|
43
|
-
rubocop-ast (>= 1.
|
|
50
|
+
rubocop-ast (>= 1.26.0, < 2.0)
|
|
44
51
|
ruby-progressbar (~> 1.7)
|
|
45
|
-
unicode-display_width (>=
|
|
46
|
-
rubocop-ast (1.
|
|
47
|
-
parser (>= 3.
|
|
48
|
-
rubocop-
|
|
49
|
-
rubocop (~> 1.
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
52
|
+
unicode-display_width (>= 2.4.0, < 3.0)
|
|
53
|
+
rubocop-ast (1.28.0)
|
|
54
|
+
parser (>= 3.2.1.0)
|
|
55
|
+
rubocop-capybara (2.17.1)
|
|
56
|
+
rubocop (~> 1.41)
|
|
57
|
+
rubocop-rspec (2.19.0)
|
|
58
|
+
rubocop (~> 1.33)
|
|
59
|
+
rubocop-capybara (~> 2.17)
|
|
60
|
+
ruby-progressbar (1.13.0)
|
|
61
|
+
unicode-display_width (2.4.2)
|
|
53
62
|
zeitwerk (2.6.7)
|
|
54
63
|
|
|
55
64
|
PLATFORMS
|
|
@@ -62,6 +71,7 @@ DEPENDENCIES
|
|
|
62
71
|
openapi_parameters!
|
|
63
72
|
rake (~> 13.0)
|
|
64
73
|
rspec (~> 3.0)
|
|
74
|
+
rspec-benchmark
|
|
65
75
|
rubocop
|
|
66
76
|
rubocop-rspec
|
|
67
77
|
|
data/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
OpenapiParameters is an an [OpenAPI](https://www.openapis.org/) aware parameter parser.
|
|
4
4
|
|
|
5
|
-
OpenapiParameters unpacks HTTP/Rack (query / header / cookie) parameters exactly as described in an [OpenAPI](https://www.openapis.org/) definition. It supports `style`, `explode` and `schema` definitions according to OpenAPI 3.1 (or 3.0).
|
|
5
|
+
OpenapiParameters unpacks HTTP/Rack (query / header / cookie) parameters exactly as described in an [OpenAPI](https://www.openapis.org/) definition. It supports `style`, `explode` and `schema` definitions according to OpenAPI 3.1 (or 3.0). The gem is mainly build to be used inside of other OpenAPI tooling.
|
|
6
6
|
|
|
7
7
|
## Synopsis
|
|
8
8
|
|
|
@@ -28,9 +28,9 @@ 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(
|
|
31
|
+
path_parameters = OpenapiParameters::Path.new(parameters)
|
|
32
|
+
route_params = env['route.params'] # This depends on the webframework you are using
|
|
33
|
+
path_parameters.unpack(route_params) # => { 'ids' => [1, 2, 3] }
|
|
34
34
|
|
|
35
35
|
header_parameters = OpenapiParameters::Header.new(parameters)
|
|
36
36
|
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
|
@@ -8,15 +8,15 @@ Gem::Specification.new do |spec|
|
|
|
8
8
|
spec.authors = ['Andreas Haller']
|
|
9
9
|
spec.email = ['andreas.haller@posteo.de']
|
|
10
10
|
|
|
11
|
-
spec.summary = '
|
|
11
|
+
spec.summary = 'openapi_parameters is an OpenAPI aware parameter parser'
|
|
12
12
|
spec.description =
|
|
13
|
-
'
|
|
14
|
-
spec.homepage = 'https://github.com/ahx/
|
|
13
|
+
'This parses HTTP query/path/header/cookie parameters exactly as described in an OpenAPI API description.'
|
|
14
|
+
spec.homepage = 'https://github.com/ahx/openapi_parameters'
|
|
15
15
|
spec.required_ruby_version = '>= 3.1.0'
|
|
16
16
|
spec.licenses = ['MIT']
|
|
17
17
|
|
|
18
18
|
spec.metadata['homepage_uri'] = spec.homepage
|
|
19
|
-
spec.metadata['source_code_uri'] = 'https://github.com/ahx/
|
|
19
|
+
spec.metadata['source_code_uri'] = 'https://github.com/ahx/openapi_parameters'
|
|
20
20
|
spec.metadata[
|
|
21
21
|
'changelog_uri'
|
|
22
22
|
] = 'https://github.com/ahx/openapi_parameters/blob/main/CHANGELOG.md'
|
|
@@ -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.1
|
|
4
|
+
version: 0.2.1
|
|
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-31 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
|
|
@@ -58,8 +38,8 @@ dependencies:
|
|
|
58
38
|
- - "~>"
|
|
59
39
|
- !ruby/object:Gem::Version
|
|
60
40
|
version: '2.6'
|
|
61
|
-
description:
|
|
62
|
-
an OpenAPI API description.
|
|
41
|
+
description: This parses HTTP query/path/header/cookie parameters exactly as described
|
|
42
|
+
in an OpenAPI API description.
|
|
63
43
|
email:
|
|
64
44
|
- andreas.haller@posteo.de
|
|
65
45
|
executables: []
|
|
@@ -87,12 +67,12 @@ files:
|
|
|
87
67
|
- lib/openapi_parameters/version.rb
|
|
88
68
|
- openapi_parameters.gemspec
|
|
89
69
|
- sig/openapi_parameters.rbs
|
|
90
|
-
homepage: https://github.com/ahx/
|
|
70
|
+
homepage: https://github.com/ahx/openapi_parameters
|
|
91
71
|
licenses:
|
|
92
72
|
- MIT
|
|
93
73
|
metadata:
|
|
94
|
-
homepage_uri: https://github.com/ahx/
|
|
95
|
-
source_code_uri: https://github.com/ahx/
|
|
74
|
+
homepage_uri: https://github.com/ahx/openapi_parameters
|
|
75
|
+
source_code_uri: https://github.com/ahx/openapi_parameters
|
|
96
76
|
changelog_uri: https://github.com/ahx/openapi_parameters/blob/main/CHANGELOG.md
|
|
97
77
|
rubygems_mfa_required: 'true'
|
|
98
78
|
post_install_message:
|
|
@@ -113,5 +93,5 @@ requirements: []
|
|
|
113
93
|
rubygems_version: 3.4.6
|
|
114
94
|
signing_key:
|
|
115
95
|
specification_version: 4
|
|
116
|
-
summary:
|
|
96
|
+
summary: openapi_parameters is an OpenAPI aware parameter parser
|
|
117
97
|
test_files: []
|