verquest 0.8.0 → 0.10.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: 4445e1ed3a032827a00b4805bb1eb3bcb57eb11cf3a261e334d4bb5362df953d
4
- data.tar.gz: 14a3b0eb7fc630f6d227f4efc439eabfde307ed0e8d3c133a68b96120e6b588e
3
+ metadata.gz: ba6bc529dbf828ec473edcf82a1cedefe5d3b1ac4b581a159e5421ab3dc9f751
4
+ data.tar.gz: 7a1e7463fcd6987fcaaed5fab9b757acff2e7176f7a5a490e6de5c6197e84b8b
5
5
  SHA512:
6
- metadata.gz: 6605a7c2d01d8a1d89388340592f5f9ac7e61220f705ce06eecdc50b39b0b01771c70afa0311f4ca4ebd21f72c0ca61732ca2ab27e9fc332d5761f357f909e4a
7
- data.tar.gz: c8dacd48fec778f398971dcf1f797fb639edd771069070c64c2f5ee3a9eb3c1389483f5dbb6348eb4607c579624ba3fb74a94fe64c05f9a7bd7cbe79112d9fd8
6
+ metadata.gz: 67030d45303503d3e2ea2a8258c7c74081c66582458e228a965cd0335431a1a713ad6617d5dd6a7242ce84ff0e79c9890a7d27f8b704a4e295e857ae9414cdc7
7
+ data.tar.gz: 5f503d96382ca5c77ba193cfd5cabf2e494fa3273b770b1f73a38b07e6e96151983b571cb35def51378278060a1874104c67d9efa91dd6f379a99c55ba2eb8db
data/CHANGELOG.md CHANGED
@@ -1,5 +1,26 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.10.0] - 2026-11-09
4
+
5
+ ### Added
6
+ - `config.lenient_through = "2025-06"` makes query and path requests for that version or an earlier one lenient; `process(..., lenient: true/false)` overrides it per call. A lenient request corrects values instead of rejecting them: blank root values are removed where strict validation would reject them (not for required properties, arrays, properties that accept null, or strings without constraints, also as an anyOf or oneOf variant), enum values match case-insensitively when one value matches, numbers above `maximum` are capped, date-times (with at most 9 fraction digits) without an offset get `Z` and `+HHMM` offsets a colon, with `T` between the date and the time, and root properties that still fail validation are removed, except filters and properties required by `required`, `dependentRequired` or a condition. A value gets at most one correction. `process` yields a `Verquest::Correction` (`path` as the JSON pointer of the corrected value, `rule`, `from` as sent, `to`, and `name` of the root property) for each, also before raising for a validation failure.
7
+ - `property_names(version:)` lists the root property names a version declares, inherited ones included, in declaration order.
8
+
9
+ ### Changed
10
+ - The private `Query::Coercer` type hooks `coerce_integer`, `coerce_number` and `coerce_string` take `(value, value_schema, path)`. A subclass overriding them must accept the new arguments.
11
+
12
+ ## [0.9.0] - 2026-11-09
13
+
14
+ ### Added
15
+ - `filter` declares a property with `field`, `array` or `enum` (`as:`) and the block that filters by its value; `apply_filters(target, params, version:)` runs a version's filters in declaration order, skipping nil and empty values, and `filter_names(version:)` lists them. Filters are inherited, excluded and replaced with their properties. A filter with `map:`, another `as:`, no block, or outside a version's root raises `Verquest::DefinitionError`.
16
+ - `process(..., reject_other_version_keys: true)` (or `config.reject_other_version_keys`) reports root keys that only another version declares as validation errors of type `other_version`, when params are validated.
17
+
18
+ ### Changed
19
+ - Validation skips json_schemer's default insertion when the schema declares no `default`, which makes `process` about 15% faster for such schemas.
20
+
21
+ ### Fixed
22
+ - `process` no longer inserts defaults into the caller's nested hashes, and no longer raises `FrozenError` for frozen nested params when it inserts defaults.
23
+
3
24
  ## [0.8.0] - 2026-11-06
4
25
 
5
26
  ### Changed
data/README.md CHANGED
@@ -20,7 +20,7 @@ Sponsored by [Stora](https://stora.co)
20
20
 
21
21
  - [Installation](#installation)
22
22
  - [Quick Start](#quick-start)
23
- - [Core Features](#core-features): [schema definition](#schema-definition-and-validation), [oneOf](#oneof), [conditional schemas](#conditional-schemas), [custom field types](#custom-field-types), [versioning](#versioning), [mapping](#mapping-request-structure), [query parameters](#query-parameters), [path parameters](#path-parameters), [OpenAPI components](#component-generation-for-openapi)
23
+ - [Core Features](#core-features): [schema definition](#schema-definition-and-validation), [oneOf](#oneof), [conditional schemas](#conditional-schemas), [custom field types](#custom-field-types), [versioning](#versioning), [mapping](#mapping-request-structure), [query parameters](#query-parameters), [filters](#filters), [path parameters](#path-parameters), [OpenAPI components](#component-generation-for-openapi)
24
24
  - [Rails and rswag](docs/rails.md)
25
25
  - [Configuration](#configuration)
26
26
 
@@ -29,7 +29,7 @@ Sponsored by [Stora](https://stora.co)
29
29
  Add this line to your application's Gemfile:
30
30
 
31
31
  ```ruby
32
- gem "verquest", "~> 0.7"
32
+ gem "verquest", "~> 0.9"
33
33
  ```
34
34
 
35
35
  And then execute:
@@ -134,7 +134,8 @@ error.errors
134
134
  Set `config.current_version` to drop the `version:` argument, or `config.validation_error_handling = :result` to get a `Verquest::Result` instead of an exception (see [Configuration](#configuration)). For query and path parameters in controllers, see [Rails and rswag](docs/rails.md).
135
135
 
136
136
  ### JSON schema for OpenAPI
137
- You can generate JSON Schema for your versioned requests, which can be used for API documentation:
137
+
138
+ `to_schema` returns the JSON Schema of a version for your API documentation. References stay `$ref`s:
138
139
 
139
140
  ```ruby
140
141
  UserCreateRequest.to_schema(version: "2025-06")
@@ -161,7 +162,8 @@ Output:
161
162
  "name" => {"type" => "string", "description" => "Name of the permission"},
162
163
  "read" => {"type" => "boolean", "description" => "Permission to read"},
163
164
  "write" => {"type" => "boolean", "description" => "Permission to write"}
164
- }
165
+ },
166
+ "additionalProperties" => false
165
167
  },
166
168
  "description" => "Permissions associated with the user"
167
169
  },
@@ -182,9 +184,11 @@ Output:
182
184
  "github" => {"type" => "string", "format" => "uri", "description" => "GitHub profile URL"},
183
185
  "mastodon" => {"type" => "string", "format" => "uri", "description" => "Mastodon profile URL"}
184
186
  },
187
+ "additionalProperties" => false,
185
188
  "description" => "Some social networks"
186
189
  }
187
- }
190
+ },
191
+ "additionalProperties" => false
188
192
  },
189
193
  "company" => {"const" => "Awesome Inc."}
190
194
  },
@@ -194,7 +198,7 @@ Output:
194
198
 
195
199
  ### JSON schema for validation
196
200
 
197
- You can check the validation JSON schema for a specific version of your request:
201
+ `to_validation_schema` returns the schema that `process` validates against, with references inlined:
198
202
 
199
203
  ```ruby
200
204
  UserCreateRequest.to_validation_schema(version: "2025-06")
@@ -210,7 +214,7 @@ Output:
210
214
  "first_name" => {"type" => "string", "description" => "The first name of the user", "maxLength" => 50},
211
215
  "last_name" => {"type" => "string", "description" => "The last name of the user", "maxLength" => 50},
212
216
  "email" => {"type" => "string", "format" => "email", "description" => "The email address of the user"},
213
- "birth_date" => {"type" => "string", "format" => "date", "description" => "The birth date of the user"},
217
+ "birth_date" => {"type" => ["string", "null"], "format" => "date", "description" => "The birth date of the user"},
214
218
  "address" => { # from the AddressCreateRequest
215
219
  "type" => "object",
216
220
  "description" => "Address Create Request",
@@ -231,7 +235,8 @@ Output:
231
235
  "name" => {"type" => "string", "description" => "Name of the permission"},
232
236
  "read" => {"type" => "boolean", "description" => "Permission to read"},
233
237
  "write" => {"type" => "boolean", "description" => "Permission to write"}
234
- }
238
+ },
239
+ "additionalProperties" => false
235
240
  },
236
241
  "description" => "Permissions associated with the user"
237
242
  },
@@ -241,26 +246,30 @@ Output:
241
246
  "default" => "member",
242
247
  "description" => "Role of the user"
243
248
  },
244
- "profile_details" => {"type" => "object",
249
+ "profile_details" => {
250
+ "type" => "object",
245
251
  "properties" => {
246
252
  "bio" => {"type" => "string", "description" => "Short biography of the user"},
247
253
  "hobbies" => {"type" => "array", "items" => {"type" => "string"}, "description" => "Tags associated with the user"},
248
254
  "social_links" => {
249
- "type" => "object",
255
+ "type" => "object",
250
256
  "properties" => {
251
- "github" => {"type" => "string", "format" => "uri", "description" => "GitHub profile URL"},
257
+ "github" => {"type" => "string", "format" => "uri", "description" => "GitHub profile URL"},
252
258
  "mastodon" => {"type" => "string", "format" => "uri", "description" => "Mastodon profile URL"}
253
- },
254
- "description" => "Some social networks"}
259
+ },
260
+ "additionalProperties" => false,
261
+ "description" => "Some social networks"
262
+ }
255
263
  },
256
- "company" => {"const" => "Awesome Inc."}
257
- }
264
+ "additionalProperties" => false
265
+ },
266
+ "company" => {"const" => "Awesome Inc."}
258
267
  },
259
268
  "additionalProperties" => false
260
269
  }
261
270
  ```
262
271
 
263
- You can also validate it to ensure it meets the JSON Schema standards. Under `:openapi30` this checks the document from `to_schema` against the OpenAPI 3.0 meta-schema, since validation schemas keep JSON Schema forms OpenAPI 3.0 forbids:
272
+ `valid_schema?` and `validate_schema` check the validation schema against the meta-schema of `config.json_schema_version`. Under `:openapi30`, they check the `to_schema` document instead, because validation schemas keep JSON Schema forms that OpenAPI 3.0 forbids:
264
273
 
265
274
  ```ruby
266
275
  UserCreateRequest.valid_schema?(version: "2025-06") # => true/false
@@ -615,7 +624,6 @@ end
615
624
  {
616
625
  "type" => "object",
617
626
  "description" => "User Create Request",
618
- "required" => ["email"],
619
627
  "properties" => {
620
628
  "email" => {
621
629
  "type" => "string",
@@ -678,9 +686,8 @@ class UserCreateRequest < Verquest::Base
678
686
  end
679
687
  ```
680
688
 
681
- Internal `Verquest::VersionResolver` is then used to resolve the right version for the one specified in the call. It implements a "downgrading" strategy - when an exact version match isn't found, it returns the closest earlier version.
689
+ `Verquest::VersionResolver` picks the version block for the requested version. When no block matches exactly, it picks the closest earlier one:
682
690
 
683
- Example:
684
691
  ```ruby
685
692
  UserCreateRequest.process(params, version: "2025-05") # => use the defined version "2025-04"
686
693
  UserCreateRequest.process(params, version: "2025-06") # => use the defined version "2025-06"
@@ -689,9 +696,9 @@ UserCreateRequest.process(params, version: "2025-08") # => use the defined versi
689
696
  UserCreateRequest.process(params, version: "2025-10") # => use the closest earlier version "2025-08"
690
697
  ```
691
698
 
692
- This is used across all referenced requests, so if you have a `UserRequest` that references an `AddressCreateRequest`, it will also resolve the correct version of the `AddressCreateRequest` based on the initial requested version (as the `AddressCreateRequest` can have different versions defined).
699
+ References resolve the same way. When `UserCreateRequest` references `AddressCreateRequest`, the requested version also picks the `AddressCreateRequest` block, so the two classes can declare different versions.
693
700
 
694
- The goal here is to avoid redefining the same request structure in multiple versions when there are no changes, and to facilitate the easy evolution of API requests over time. When a new API version is created and there are no changes to the requests, you don't need to update anything.
701
+ A new API version that doesn't change a request needs no new `version` block in it.
695
702
 
696
703
  #### Supported versions
697
704
 
@@ -721,13 +728,11 @@ OverlockRequest.process(params, version: "2026-06") # => raises Verquest::Versio
721
728
 
722
729
  ### Mapping request structure
723
730
 
724
- Verquest's mapping system allows transforming external API request structures into your internal application data structures.
725
-
726
- Here’s a short example: we store the address in the same table as the user internally, but the API request structure is different.
731
+ `map:` turns the public request structure into the structure your app uses. In this example, the app stores the address in the users table, so the address fields move to the root:
727
732
 
728
733
  ```ruby
729
734
  class UserCreateRequest < Verquest::Base
730
- version "2025-06", exclude_properties: %i[street city] do
735
+ version "2025-06" do
731
736
  field :full_name, type: :string, map: "name"
732
737
  field :email, type: :string, format: "email", required: true
733
738
  field :phone, type: :string
@@ -741,40 +746,43 @@ class UserCreateRequest < Verquest::Base
741
746
  end
742
747
  ```
743
748
 
744
- When called with `UserCreateRequest.process(params)`, the `address` object will be mapped to the internal structure with keys `address_street`, `address_city`, and `address_zip`.
749
+ `UserCreateRequest.process` turns these params:
745
750
 
746
- Example request params
747
751
  ```ruby
748
752
  {
749
- "full_name": "John Doe",
750
- "email": "john@doe.com",
751
- "phone": "1234567890",
752
- "address": {
753
- "street": "123 Main St",
754
- "city": "Springfield",
755
- "postal_code": "12345"
753
+ "full_name" => "John Doe",
754
+ "email" => "john@doe.com",
755
+ "phone" => "1234567890",
756
+ "address" => {
757
+ "street" => "123 Main St",
758
+ "city" => "Springfield",
759
+ "postal_code" => "12345"
756
760
  }
757
761
  }
758
762
  ```
759
763
 
760
- Will be transformed to:
764
+ into:
765
+
761
766
  ```ruby
762
767
  {
763
- "name": "John Doe",
764
- "email": "john@doe.com",
765
- "phone": "1234567890",
766
- "address_street": "123 Main St",
767
- "address_city": "Springfield",
768
- "address_zip": "12345"
768
+ "name" => "John Doe",
769
+ "email" => "john@doe.com",
770
+ "phone" => "1234567890",
771
+ "address_street" => "123 Main St",
772
+ "address_city" => "Springfield",
773
+ "address_zip" => "12345"
769
774
  }
770
775
  ```
771
776
 
772
- What you can use:
773
- - `/` to reference the root of the request structure
774
- - `nested/structure` use slash notation to reference nested structures
775
- - if the `map` is not set, the field name will be used as the key in the internal structure
777
+ `map:` takes one of these forms:
778
+
779
+ - `"name"`: a key at the same level;
780
+ - `"/name"`: a key at the root;
781
+ - `"nested/structure"`: a key inside nested objects.
776
782
 
777
- To get the mapping to map the request structure back to the external API structure, you can use the `external_mapping` method:
783
+ Without `map:`, the property name is the key.
784
+
785
+ `external_mapping` returns the mapping back, from internal keys to external paths:
778
786
 
779
787
  ```ruby
780
788
  UserCreateRequest.external_mapping(version: "2025-06")
@@ -807,12 +815,20 @@ class DealsIndexQuery < Verquest::Base
807
815
  field :page, type: :integer, minimum: 1, default: 1
808
816
  field :archived, type: :boolean
809
817
  enum :sort_direction, values: %w[ASC DESC], default: "DESC"
810
- array :status, type: :string, explode: false, item_schema_options: {enum: %w[open won lost]}
818
+ filter :status, as: :array, type: :string, explode: false, item_schema_options: {enum: %w[open won lost]} do |deals, value|
819
+ deals.where(status: value)
820
+ end
811
821
 
812
822
  object :created do # sent as created[after]=...
813
823
  field :after, type: :string, format: "date-time", map: "/created_after"
814
824
  end
815
825
  end
826
+
827
+ version "2025-08" do # inherits the 2025-06 properties and filters
828
+ filter :site_id, type: :string do |deals, value|
829
+ deals.where(site_id: value)
830
+ end
831
+ end
816
832
  end
817
833
 
818
834
  DealsIndexQuery.process(request.query_parameters, version: "2025-06")
@@ -820,6 +836,8 @@ DealsIndexQuery.process(request.query_parameters, version: "2025-06")
820
836
  # => {"page" => 2, "archived" => true, "sort_direction" => "DESC", "status" => ["open", "won"], "created_after" => "2025-01-01T00:00:00Z"}
821
837
  ```
822
838
 
839
+ `filter :status, as: :array` declares the same property as `array :status`, plus a block that [Filters](#filters) describes.
840
+
823
841
  Conversion follows the validation schema:
824
842
  - `integer` and `number` from digits (`"2"`, `"-1.5"`), `boolean` from `"true"` and `"false"`, `null` from an empty string when the schema allows it (a string outside an enum's values tries the next type, so `""` is `nil` in a nullable string enum);
825
843
  - arrays split on commas with `explode: false` (`status=open,won`), or come from repeated keys with `explode: true` (`status[]=open&status[]=won`; Rails keeps only the last value of a plain repeated key). `config.query_array_explode` sets the default (`true`);
@@ -845,6 +863,63 @@ array :status, type: :string, explode: false, item_schema_options: {enum: %w[ope
845
863
 
846
864
  A property reference to another query class reuses its definition, e.g. a shared `expand` parameter: `reference :expand, from: ExpandQuery, property: :expand`.
847
865
 
866
+ #### Lenient requests
867
+
868
+ Tightening validation can break clients of a released version. `config.lenient_through` makes query and path requests for that version, or an earlier one, correct values instead of rejecting them. Later versions and body requests stay strict, and `process(..., lenient: true/false)` overrides the setting per call.
869
+
870
+ ```ruby
871
+ Verquest.configure do |config|
872
+ config.lenient_through = "2025-06"
873
+ end
874
+ ```
875
+
876
+ | Rule | Value sent | Correction |
877
+ |------|------------|------------|
878
+ | `blank` | `page=` | Removed, where strict validation would reject it (not for required properties, arrays, properties that accept null, or strings without constraints, also as an anyOf or oneOf variant) |
879
+ | `enum_case` | `sort_direction=desc` | `"DESC"`, when exactly one enum value matches case-insensitively |
880
+ | `maximum` | `limit=200` | Capped at the `maximum`, `100` |
881
+ | `datetime_offset` | `2025-01-12 15:30:00`, `...+0100` | `T` between the date and the time, and `Z` added or a colon added to the offset (`+01:00`) |
882
+ | `invalid` | `page=0` | Removed when it still fails validation, except a filter or a required property, which is still rejected |
883
+
884
+ A value gets at most one correction: a value that is still invalid after a correction is removed, except a filter or a property required by `required`, `dependentRequired` or a condition, which fails validation with its own error, as in strict requests. This is conservative: a property any `dependentRequired` or condition can require is kept even when the trigger is absent or the condition doesn't apply. `process` yields a `Verquest::Correction` for each, also before it raises for a validation failure: `path` is the JSON pointer of the corrected value (`/status/0`, `/created/gte`, or the removed root property), `name` its root property, `rule`, `from` as sent and `to`:
885
+
886
+ ```ruby
887
+ params = ListQuery.process(request.query_parameters) do |correction|
888
+ logger.info(correction.to_h.except(:from)) # `from` is what the client sent
889
+ end
890
+ ```
891
+
892
+ ### Filters
893
+
894
+ `filter` declares a property and the block that filters by its value. The property is a `field` by default, an `array` with `as: :array`, or an `enum` with `as: :enum`, in a body or a query request. `apply_filters` passes the target through the version's filters in declaration order, and skips a filter when its value is nil or empty. `DealsIndexQuery` from [Query parameters](#query-parameters) filters by `status` from `2025-06`, and also by `site_id` from `2025-08`:
895
+
896
+ ```ruby
897
+ params = DealsIndexQuery.process(request.query_parameters, version: "2025-08")
898
+ DealsIndexQuery.apply_filters(Deal.all, params, version: "2025-08")
899
+ DealsIndexQuery.filter_names(version: "2025-08") # => ["status", "site_id"]
900
+ DealsIndexQuery.property_names(version: "2025-08") # => ["page", "archived", "sort_direction", "status", "created", "site_id"]
901
+ ```
902
+
903
+ - Filters follow the rules of properties. A later version inherits them, `exclude_properties` removes one, and redeclaring a filter replaces its block. Redeclaring it as a plain property, such as `field :status`, stops it filtering.
904
+ - `reference` copies the property without its filter.
905
+ - The block runs only from `apply_filters`, with `self` set to the request class.
906
+ - `apply_filters` reads the params by their String names, as `process` returns them. With `validation_error_handling = :result`, pass the result's `value`.
907
+ - A filter must be at the root of a version, and it can't use `map:`. Otherwise defining the version raises `Verquest::DefinitionError`.
908
+
909
+ [`test/support/examples/deals_index_query.rb`](test/support/examples/deals_index_query.rb) runs the same query against an Array of Hashes.
910
+
911
+ #### Reject keys from other versions
912
+
913
+ `process` drops root keys that the version doesn't declare. A client that sends `site_id` to `2025-06` gets an unfiltered list and no error. With `reject_other_version_keys: true`, `process` reports a root key that only another version declares as a validation error:
914
+
915
+ ```ruby
916
+ DealsIndexQuery.process({"site_id" => "site_1"}, version: "2025-06", reject_other_version_keys: true)
917
+ # raises Verquest::InvalidParamsError with
918
+ # [{pointer: "/site_id", type: "other_version", message: "`site_id` isn't available in version 2025-06", details: nil}]
919
+ ```
920
+
921
+ `remove_extra_root_keys` still drops keys that no version declares, such as `utm_source`. The check works for body requests too, and runs only when `process` validates the params. `config.reject_other_version_keys` sets the default (`false`).
922
+
848
923
  ### Path parameters
849
924
 
850
925
  `location :path` works like `location :query`, but documents `in: :path` parameters. Path parameters must be required scalars; arrays, objects, one_of and optional properties raise `Verquest::DefinitionError`.
@@ -899,6 +974,9 @@ Verquest.configure do |config|
899
974
 
900
975
  # Remove extra root keys from provided params
901
976
  config.remove_extra_root_keys = true # default
977
+
978
+ # Report root keys that only another version declares, see Filters
979
+ config.reject_other_version_keys = false # default
902
980
 
903
981
  # Set custom version resolver
904
982
  config.version_resolver = CustomVersionResolver # default is `Verquest::VersionResolver`
@@ -909,6 +987,9 @@ Verquest.configure do |config|
909
987
  # Default explode value of query arrays (true: status[]=a&status[]=b, false: status=a,b)
910
988
  config.query_array_explode = true # default
911
989
 
990
+ # Last version whose query and path requests are corrected instead of rejected, see Lenient requests
991
+ config.lenient_through = nil # default
992
+
912
993
  # Reusable field types, see Custom Field Types
913
994
  config.custom_field_types = {} # default
914
995
  end
data/Rakefile CHANGED
@@ -32,9 +32,10 @@ task :yard do
32
32
  puts "\nYARD documentation: 100% documented"
33
33
  end
34
34
 
35
- desc "Benchmark the transformer (objects allocated and calls per second)"
35
+ desc "Benchmark the transformer and process (objects allocated and calls per second)"
36
36
  task :bench do
37
37
  ruby "-Ilib", "bench/transformer.rb"
38
+ ruby "-Ilib", "bench/process.rb"
38
39
  end
39
40
 
40
41
  task default: %i[test rubocop yard]
data/docs/rails.md CHANGED
@@ -25,6 +25,8 @@ end
25
25
  # config/initializers/verquest.rb
26
26
  Verquest.configure do |config|
27
27
  config.current_version = -> { Current.api_version }
28
+ # Released versions keep tolerating what they accepted before validation
29
+ config.lenient_through = "2025-06"
28
30
  end
29
31
  ```
30
32
 
@@ -62,8 +64,12 @@ module VerquestParams
62
64
 
63
65
  # Every path class applies, so /deals/:deal_id/notes/:id can check both IDs
64
66
  @path_params = by_location.fetch(:path, []).to_h { |declaration| process_path_param(declaration) }
65
- # Unknown query keys (cache busters, tracking) are dropped instead of rejected
66
- @query_params = by_location[:query]&.first&.dig(:class)&.process(request.query_parameters, remove_extra_root_keys: true)
67
+ # Unknown query keys (cache busters, tracking) are dropped instead of rejected. Add
68
+ # `reject_other_version_keys: true` to reject keys from another version, such as a newer filter.
69
+ # A lenient request (config.lenient_through) yields each value it corrected instead of rejecting.
70
+ @query_params = by_location[:query]&.first&.dig(:class)&.process(request.query_parameters, remove_extra_root_keys: true) do |correction|
71
+ Rails.logger.info("Corrected query param: #{correction.to_h.except(:from)}")
72
+ end
67
73
  @body_params = by_location[:body]&.first&.dig(:class)&.process(request.request_parameters)
68
74
  end
69
75
 
@@ -115,6 +121,10 @@ class DealsController < ApplicationController
115
121
  verquest_params DealsIndexQuery, only: :index
116
122
  verquest_params DealUpdateRequest, only: :update
117
123
 
124
+ def index
125
+ render json: DealsIndexQuery.apply_filters(Deal.all, query_params)
126
+ end
127
+
118
128
  def show
119
129
  render json: Deal.find_by!(public_id: path_params["id"])
120
130
  end
@@ -127,6 +137,8 @@ end
127
137
 
128
138
  `GET /deals/con_123` then returns 422 with `{"pointer" => "/id", ...}`, and `POST /deals/con_123/win` with `{"pointer" => "/deal_id", ...}`.
129
139
 
140
+ `DealsIndexQuery` declares its filters with `filter` (see [Filters](../README.md#filters)). `apply_filters` takes the version from `config.current_version`, like `process`. `GET /2025-06/deals?site_id=site_1` lists every deal, because `site_id` is a `2025-08` filter and `process` drops it. With `reject_other_version_keys: true`, the same request returns 422 with `{"pointer" => "/site_id", "type" => "other_version", ...}`.
141
+
130
142
  ## rswag
131
143
 
132
144
  A shared context documents a query or path class with `to_parameters`. `name:` renames a path class's parameter to the route key, and `description:` replaces its description: