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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e010a357f13e7452f8945d95e7c277fc35c87d1cc713e41dccae68a20d37db03
4
- data.tar.gz: 763b4eed6e0e11c4f0ff839afa366cadc6569c371a4ccd5490a7b3368f8849fc
3
+ metadata.gz: fa336f02dcfc58d656659606710c5fed70335b7a5e101f42228a24913e12325b
4
+ data.tar.gz: e81f400174546397953abe62d23c26f07fbf14f594ca2297ad129118847a4709
5
5
  SHA512:
6
- metadata.gz: 49a1e95d33f513346408826aa1954d9a8c58b7a656d23b1643f8f5664e3747ab04589586d8c6ffcd9392022ff85ad2f4722dd9e541f569399ff8a7bd2226ecb6
7
- data.tar.gz: 6bc8eadb1948050b12ab6561c8e412ab124d0bfd64d94414506f71d5c1549d963c2d765ce0e9ebea1908c258ef30d17b7f8c4db3bd9c81643897c0bac86ad487
6
+ metadata.gz: b30a7b111b652c9dbc12e0c19ef5f9dc74a5ba9b6eebc0a7392ba0d5070d7c19578017a64e8948e8dd235b57e8784202e37765c62be015c5520940278def939f
7
+ data.tar.gz: 1e91216f5bff01be794c5eec6a469cea42162472568c2d881afa3267aa036257d0afab0e97534edd57f074217122c96abac08e3e6d4a14c139348bb0ae81fd8e
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.3.4] - 2024-06-14
4
+
5
+ - Fix handling invalid object query parameters (String vs Hash)
6
+
3
7
  ## [0.3.3] - 2023-04-13
4
8
 
5
9
  - Remove zeitwerk. It's awesome, but not needed here
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
- parameters = [{
16
+
17
+ query_parameters = OpenapiParameters::Query.new([{
17
18
  'name' => 'ids',
18
19
  'required' => true,
19
- 'in' => 'query', # or 'path', 'header', 'cookie'
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 input [String, Hash, Array] the value to convert
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(object, schema)
47
- object.each_with_object({}) do |(key, value), hsh|
48
- hsh[key] = convert(value, schema['properties']&.fetch(key, nil))
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 |param, result|
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)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module OpenapiParameters
4
- VERSION = '0.3.3'
4
+ VERSION = '0.3.4'
5
5
  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.3.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-04-13 00:00:00.000000000 Z
11
+ date: 2024-06-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack