openapi_parameters 0.4.0 → 0.5.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c0d1127ef2e34d916ca293835143d6267d1baf9cfb6f51ca12384e712f57eef0
4
- data.tar.gz: ced0820dba10352ab2a460b4c621c5fcbd2f79400008aef3081d442027189113
3
+ metadata.gz: 778cfe7ccd40119158a3c158b5cf1dcf8000436a4c747a1ecfa349782ffa99d1
4
+ data.tar.gz: ebdb7a20b68b881e526e11fd30e05458ed8dd5dea34b16f94115e522dfa1801f
5
5
  SHA512:
6
- metadata.gz: 1d3bbef2747984f498d259cd838ff5e9acbfd8f5417ad8718f7ac9d8ea078a72af94b3835f6307c967803c447ff3e7be0eb6b4b1cae9bb3d2afd1138226e8091
7
- data.tar.gz: 6d17518118d5df6dc5376e8bed4b131f65077c5ed71293fe41425f788c0ecddc7fbbd476a1e93cf28e022d522fb8973b1afe0090be9ab71b3b2b08b036aa70a3
6
+ metadata.gz: 61c5e95989223be85f4965355aede74739ac71a3f07ebeba9b6486ef56acf45a64093ffa23b680d1ccad28f7abbbcc4d94a6135acf4575f87f7e67773ccdd97c
7
+ data.tar.gz: 82fe0b18f8a79e758b5b3a3a496a8de373cc7a47079a3944cd5a6843130c03c1ca6b5173d479a8c2c0a14697e106f2d1aa407d6181e1feac8e5b2cdd074bb4bd
data/CHANGELOG.md CHANGED
@@ -1,6 +1,17 @@
1
1
  ## [Unreleased]
2
2
 
3
- ## [0.3.4] - 2024-12-17
3
+ ## [0.5.0] - 2025-04-01
4
+
5
+ - Add option to remove "[]" from unpacked query openapi_parameters
6
+ ```ruby
7
+ OpenapiParameters::Query.new(
8
+ [parameter],
9
+ rack_array_compat: true
10
+ ).unpack('ids[]=2')
11
+ # => { 'ids' => ['2'] }
12
+ ```
13
+
14
+ ## [0.4.0] - 2024-12-17
4
15
 
5
16
  - Add Parameter#convert(value)
6
17
  - Slight performance optimization
@@ -3,4 +3,7 @@
3
3
  module OpenapiParameters
4
4
  class Error < StandardError
5
5
  end
6
+
7
+ class NotSupportetError < Error
8
+ end
6
9
  end
@@ -52,6 +52,13 @@ module OpenapiParameters
52
52
  type == 'array'
53
53
  end
54
54
 
55
+ EMPTY_BRACKETS = '[]'
56
+ private_constant :EMPTY_BRACKETS
57
+
58
+ def bracket_array?
59
+ @bracket_array ||= array? && name.end_with?(EMPTY_BRACKETS)
60
+ end
61
+
55
62
  def object?
56
63
  type == 'object' || style == 'deepObject' || schema&.key?('properties')
57
64
  end
@@ -7,9 +7,10 @@ module OpenapiParameters
7
7
  class Query
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
- def initialize(parameters, convert: true)
10
+ def initialize(parameters, convert: true, rack_array_compat: false)
11
11
  @parameters = parameters.map { Parameter.new(_1) }
12
12
  @convert = convert
13
+ @remove_array_brackets = rack_array_compat
13
14
  end
14
15
 
15
16
  def unpack(query_string) # rubocop:disable Metrics/AbcSize
@@ -25,11 +26,17 @@ module OpenapiParameters
25
26
 
26
27
  value = Unpacker.unpack_value(parameter, parsed_query[parameter.name])
27
28
  end
28
- result[parameter.name] = @convert ? parameter.convert(value) : value
29
+ key = if remove_array_brackets && parameter.bracket_array?
30
+ parameter.name.delete_suffix('[]')
31
+ else
32
+ parameter.name
33
+ end
34
+ result[key] = @convert ? parameter.convert(value) : value
29
35
  end
30
36
  end
31
37
 
32
38
  attr_reader :parameters
39
+ private attr_reader :remove_array_brackets
33
40
 
34
41
  private
35
42
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module OpenapiParameters
4
- VERSION = '0.4.0'
4
+ VERSION = '0.5.0'
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.4.0
4
+ version: 0.5.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-12-17 00:00:00.000000000 Z
11
+ date: 2025-04-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack