openapi_parameters 0.3.3 → 0.3.4
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/README.md +4 -6
- data/lib/openapi_parameters/converter.rb +6 -4
- data/lib/openapi_parameters/cookie.rb +1 -2
- data/lib/openapi_parameters/header.rb +1 -2
- data/lib/openapi_parameters/path.rb +2 -3
- data/lib/openapi_parameters/query.rb +1 -2
- 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: fa336f02dcfc58d656659606710c5fed70335b7a5e101f42228a24913e12325b
|
4
|
+
data.tar.gz: e81f400174546397953abe62d23c26f07fbf14f594ca2297ad129118847a4709
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b30a7b111b652c9dbc12e0c19ef5f9dc74a5ba9b6eebc0a7392ba0d5070d7c19578017a64e8948e8dd235b57e8784202e37765c62be015c5520940278def939f
|
7
|
+
data.tar.gz: 1e91216f5bff01be794c5eec6a469cea42162472568c2d881afa3267aa036257d0afab0e97534edd57f074217122c96abac08e3e6d4a14c139348bb0ae81fd8e
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -13,22 +13,20 @@ Note that OpenAPI supportes parameter definition on path and operation objects.
|
|
13
13
|
### Unpack query/path/header/cookie parameters from HTTP requests according to their OpenAPI definition
|
14
14
|
|
15
15
|
```ruby
|
16
|
-
|
16
|
+
|
17
|
+
query_parameters = OpenapiParameters::Query.new([{
|
17
18
|
'name' => 'ids',
|
18
19
|
'required' => true,
|
19
|
-
'in' => 'query', #
|
20
|
+
'in' => 'query', # Note that we only pass query parameters here
|
20
21
|
'schema' => {
|
21
22
|
'type' => 'array',
|
22
23
|
'items' => {
|
23
24
|
'type' => 'integer'
|
24
25
|
}
|
25
26
|
}
|
26
|
-
}]
|
27
|
-
|
28
|
-
query_parameters = OpenapiParameters::Query.new(parameters)
|
27
|
+
}])
|
29
28
|
query_string = env['QUERY_STRING'] # => 'ids=1&ids=2'
|
30
29
|
query_parameters.unpack(query_string) # => { 'ids' => [1, 2] }
|
31
|
-
query_parameters.unpack(query_string, convert: false) # => { 'ids' => ['1', '2'] }
|
32
30
|
|
33
31
|
path_parameters = OpenapiParameters::Path.new(parameters)
|
34
32
|
route_params = env['route.params'] # This depends on the webframework you are using
|
@@ -5,7 +5,7 @@ module OpenapiParameters
|
|
5
5
|
module Converter
|
6
6
|
class << self
|
7
7
|
##
|
8
|
-
# @param
|
8
|
+
# @param value [String, Hash, Array] the value to convert
|
9
9
|
# @param schema [Hash] the schema to use for conversion.
|
10
10
|
def convert(value, schema) # rubocop:disable Metrics
|
11
11
|
return if value.nil?
|
@@ -43,9 +43,11 @@ module OpenapiParameters
|
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
46
|
-
def convert_object(
|
47
|
-
|
48
|
-
|
46
|
+
def convert_object(value, schema)
|
47
|
+
return value unless value.is_a?(Hash)
|
48
|
+
|
49
|
+
value.each_with_object({}) do |(key, val), hsh|
|
50
|
+
hsh[key] = convert(val, schema['properties']&.fetch(key, nil))
|
49
51
|
end
|
50
52
|
end
|
51
53
|
|
@@ -6,7 +6,7 @@ module OpenapiParameters
|
|
6
6
|
# @param parameters [Array<Hash>] The OpenAPI parameter definitions.
|
7
7
|
# @param convert [Boolean] Whether to convert the values to the correct type.
|
8
8
|
def initialize(parameters, convert: true)
|
9
|
-
@parameters = parameters
|
9
|
+
@parameters = parameters.map { Parameter.new(_1) }
|
10
10
|
@convert = convert
|
11
11
|
end
|
12
12
|
|
@@ -14,7 +14,6 @@ module OpenapiParameters
|
|
14
14
|
def unpack(cookie_string)
|
15
15
|
cookies = Rack::Utils.parse_cookies_header(cookie_string)
|
16
16
|
parameters.each_with_object({}) do |parameter, result|
|
17
|
-
parameter = Parameter.new(parameter)
|
18
17
|
next unless cookies.key?(parameter.name)
|
19
18
|
|
20
19
|
result[parameter.name] = catch :skip do
|
@@ -6,14 +6,13 @@ module OpenapiParameters
|
|
6
6
|
# @param parameters [Array<Hash>] The OpenAPI parameters
|
7
7
|
# @param convert [Boolean] Whether to convert the values to the correct type.
|
8
8
|
def initialize(parameters, convert: true)
|
9
|
-
@parameters = parameters
|
9
|
+
@parameters = parameters.map { Parameter.new(_1) }
|
10
10
|
@convert = convert
|
11
11
|
end
|
12
12
|
|
13
13
|
# @param headers [Hash] The headers from the request. Use HeadersHash to convert a Rack env to a Hash.
|
14
14
|
def unpack(headers)
|
15
15
|
parameters.each_with_object({}) do |parameter, result|
|
16
|
-
parameter = Parameter.new(parameter)
|
17
16
|
next unless headers.key?(parameter.name)
|
18
17
|
|
19
18
|
result[parameter.name] = catch :skip do
|
@@ -8,7 +8,7 @@ module OpenapiParameters
|
|
8
8
|
# @param parameters [Array<Hash>] The OpenAPI path parameters.
|
9
9
|
# @param convert [Boolean] Whether to convert the values to the correct type.
|
10
10
|
def initialize(parameters, convert: true)
|
11
|
-
@parameters = parameters
|
11
|
+
@parameters = parameters.map { Parameter.new(_1) }
|
12
12
|
@convert = convert
|
13
13
|
end
|
14
14
|
|
@@ -16,8 +16,7 @@ module OpenapiParameters
|
|
16
16
|
|
17
17
|
# @param path_params [Hash] The path parameters from the Rack request. The keys are strings.
|
18
18
|
def unpack(path_params)
|
19
|
-
parameters.each_with_object({}) do |
|
20
|
-
parameter = Parameter.new(param)
|
19
|
+
parameters.each_with_object({}) do |parameter, result|
|
21
20
|
next unless path_params.key?(parameter.name)
|
22
21
|
|
23
22
|
result[parameter.name] = catch :skip do
|
@@ -8,14 +8,13 @@ module OpenapiParameters
|
|
8
8
|
# @param parameters [Array<Hash>] The OpenAPI query parameter definitions.
|
9
9
|
# @param convert [Boolean] Whether to convert the values to the correct type.
|
10
10
|
def initialize(parameters, convert: true)
|
11
|
-
@parameters = parameters
|
11
|
+
@parameters = parameters.map { Parameter.new(_1) }
|
12
12
|
@convert = convert
|
13
13
|
end
|
14
14
|
|
15
15
|
def unpack(query_string) # rubocop:disable Metrics/AbcSize
|
16
16
|
parsed_query = Rack::Utils.parse_query(query_string)
|
17
17
|
parameters.each_with_object({}) do |parameter, result|
|
18
|
-
parameter = Parameter.new(parameter)
|
19
18
|
if parameter.deep_object?
|
20
19
|
parsed_nested_query = Rack::Utils.parse_nested_query(query_string)
|
21
20
|
next unless parsed_nested_query.key?(parameter.name)
|
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.3.
|
4
|
+
version: 0.3.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andreas Haller
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-06-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|