openapi_parameters 0.3.4 → 0.4.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 -0
- data/lib/openapi_parameters/converter.rb +1 -0
- data/lib/openapi_parameters/converters.rb +43 -0
- data/lib/openapi_parameters/cookie.rb +1 -1
- data/lib/openapi_parameters/header.rb +1 -1
- data/lib/openapi_parameters/parameter.rb +5 -0
- data/lib/openapi_parameters/path.rb +1 -1
- data/lib/openapi_parameters/query.rb +2 -2
- data/lib/openapi_parameters/version.rb +1 -1
- data/lib/openapi_parameters.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c0d1127ef2e34d916ca293835143d6267d1baf9cfb6f51ca12384e712f57eef0
|
4
|
+
data.tar.gz: ced0820dba10352ab2a460b4c621c5fcbd2f79400008aef3081d442027189113
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1d3bbef2747984f498d259cd838ff5e9acbfd8f5417ad8718f7ac9d8ea078a72af94b3835f6307c967803c447ff3e7be0eb6b4b1cae9bb3d2afd1138226e8091
|
7
|
+
data.tar.gz: 6d17518118d5df6dc5376e8bed4b131f65077c5ed71293fe41425f788c0ecddc7fbbd476a1e93cf28e022d522fb8973b1afe0090be9ab71b3b2b08b036aa70a3
|
data/CHANGELOG.md
CHANGED
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OpenapiParameters
|
4
|
+
# Home for all converters
|
5
|
+
module Converters
|
6
|
+
@converters = {}
|
7
|
+
|
8
|
+
class << self
|
9
|
+
attr_reader :converters
|
10
|
+
|
11
|
+
def register(type, converter)
|
12
|
+
converters[type] = converter
|
13
|
+
end
|
14
|
+
|
15
|
+
def [](schema)
|
16
|
+
type = schema && schema['type']
|
17
|
+
converters.fetch(type) do
|
18
|
+
->(value) { Converter.convert(value, schema) }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
register('integer', lambda do |value|
|
24
|
+
Integer(value, 10)
|
25
|
+
rescue StandardError
|
26
|
+
value
|
27
|
+
end)
|
28
|
+
|
29
|
+
register('number', lambda do |value|
|
30
|
+
Float(value)
|
31
|
+
rescue StandardError
|
32
|
+
value
|
33
|
+
end)
|
34
|
+
|
35
|
+
register('boolean', lambda do |value|
|
36
|
+
if value == 'true'
|
37
|
+
true
|
38
|
+
else
|
39
|
+
value == 'false' ? false : value
|
40
|
+
end
|
41
|
+
end)
|
42
|
+
end
|
43
|
+
end
|
@@ -18,7 +18,7 @@ module OpenapiParameters
|
|
18
18
|
|
19
19
|
result[parameter.name] = catch :skip do
|
20
20
|
value = Unpacker.unpack_value(parameter, cookies[parameter.name])
|
21
|
-
@convert ?
|
21
|
+
@convert ? parameter.convert(value) : value
|
22
22
|
end
|
23
23
|
end
|
24
24
|
end
|
@@ -17,7 +17,7 @@ module OpenapiParameters
|
|
17
17
|
|
18
18
|
result[parameter.name] = catch :skip do
|
19
19
|
value = Unpacker.unpack_value(parameter, headers[parameter.name])
|
20
|
-
@convert ?
|
20
|
+
@convert ? parameter.convert(value) : value
|
21
21
|
end
|
22
22
|
end
|
23
23
|
end
|
@@ -9,11 +9,16 @@ module OpenapiParameters
|
|
9
9
|
@definition = definition
|
10
10
|
@name = definition['name']
|
11
11
|
@is_deep_object = style == 'deepObject'
|
12
|
+
@converter = Converters[schema]
|
12
13
|
check_supported!
|
13
14
|
end
|
14
15
|
|
15
16
|
attr_reader :definition, :name
|
16
17
|
|
18
|
+
def convert(value)
|
19
|
+
@converter.call(value)
|
20
|
+
end
|
21
|
+
|
17
22
|
def deep_object?
|
18
23
|
@is_deep_object
|
19
24
|
end
|
@@ -21,7 +21,7 @@ module OpenapiParameters
|
|
21
21
|
|
22
22
|
result[parameter.name] = catch :skip do
|
23
23
|
value = Unpacker.unpack_value(parameter, path_params[parameter.name])
|
24
|
-
@convert ?
|
24
|
+
@convert ? parameter.convert(value) : value
|
25
25
|
end
|
26
26
|
end
|
27
27
|
end
|
@@ -19,13 +19,13 @@ module OpenapiParameters
|
|
19
19
|
parsed_nested_query = Rack::Utils.parse_nested_query(query_string)
|
20
20
|
next unless parsed_nested_query.key?(parameter.name)
|
21
21
|
|
22
|
-
|
22
|
+
value = parsed_nested_query[parameter.name]
|
23
23
|
else
|
24
24
|
next unless parsed_query.key?(parameter.name)
|
25
25
|
|
26
26
|
value = Unpacker.unpack_value(parameter, parsed_query[parameter.name])
|
27
|
-
result[parameter.name] = convert(value, parameter)
|
28
27
|
end
|
28
|
+
result[parameter.name] = @convert ? parameter.convert(value) : value
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
data/lib/openapi_parameters.rb
CHANGED
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.4.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: 2024-
|
11
|
+
date: 2024-12-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -36,6 +36,7 @@ files:
|
|
36
36
|
- README.md
|
37
37
|
- lib/openapi_parameters.rb
|
38
38
|
- lib/openapi_parameters/converter.rb
|
39
|
+
- lib/openapi_parameters/converters.rb
|
39
40
|
- lib/openapi_parameters/cookie.rb
|
40
41
|
- lib/openapi_parameters/error.rb
|
41
42
|
- lib/openapi_parameters/header.rb
|