From 0b04d94a932f442405d9088ffad4a702c159ed56 Mon Sep 17 00:00:00 2001 From: r7kamura Date: Wed, 5 Jul 2023 08:01:25 +0900 Subject: [PATCH 1/3] Rename `parameter_overwite_by_rails_rule` to `parameter_overwrite_by_rails_rule` --- README.md | 2 +- lib/committee/schema_validator/open_api_3.rb | 2 +- lib/committee/schema_validator/option.rb | 4 ++-- test/middleware/request_validation_open_api_3_test.rb | 6 +++--- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 68855ddc..a4adddbd 100644 --- a/README.md +++ b/README.md @@ -355,7 +355,7 @@ Important changes are also described below. Committee 5.* has few breaking changes so we recommend upgrading to the latest release on 4.* and fixing any deprecation errors you see before upgrading. - set `parse_response_by_content_type=true` by default (old versions set `false`) -- set `parameter_overwite_by_rails_rule=true` by default (old version set `false`) +- set `parameter_overwrite_by_rails_rule=true` by default (old version set `false`) #### Future Updates (5.*~) OpenAPI3 Schema Users: Newly-added `strict_reference_validation` option defaults to `false` if not set. diff --git a/lib/committee/schema_validator/open_api_3.rb b/lib/committee/schema_validator/open_api_3.rb index 26c4f0b1..8ee6abd5 100644 --- a/lib/committee/schema_validator/open_api_3.rb +++ b/lib/committee/schema_validator/open_api_3.rb @@ -97,7 +97,7 @@ def request_unpack(request) end def copy_coerced_data_to_params(request) - order = if validator_option.parameter_overwite_by_rails_rule + order = if validator_option.parameter_overwrite_by_rails_rule # (high priority) path_hash_key -> query_param -> request_body_hash [validator_option.request_body_hash_key, validator_option.query_hash_key, validator_option.path_hash_key] else diff --git a/lib/committee/schema_validator/option.rb b/lib/committee/schema_validator/option.rb index 72c773d9..c309ffa6 100644 --- a/lib/committee/schema_validator/option.rb +++ b/lib/committee/schema_validator/option.rb @@ -17,7 +17,7 @@ class Option :optimistic_json, :validate_success_only, :parse_response_by_content_type, - :parameter_overwite_by_rails_rule + :parameter_overwrite_by_rails_rule # Non-boolean options: attr_reader :headers_key, @@ -45,7 +45,7 @@ def initialize(options, schema, schema_type) @coerce_recursive = options.fetch(:coerce_recursive, true) @optimistic_json = options.fetch(:optimistic_json, false) @parse_response_by_content_type = options.fetch(:parse_response_by_content_type, true) - @parameter_overwite_by_rails_rule = options.fetch(:parameter_overwite_by_rails_rule, true) + @parameter_overwrite_by_rails_rule = options.fetch(:parameter_overwrite_by_rails_rule, true) # Boolean options and have a different value by default @allow_get_body = options.fetch(:allow_get_body, schema.driver.default_allow_get_body) diff --git a/test/middleware/request_validation_open_api_3_test.rb b/test/middleware/request_validation_open_api_3_test.rb index b9a8b5cb..1a941d1e 100644 --- a/test/middleware/request_validation_open_api_3_test.rb +++ b/test/middleware/request_validation_open_api_3_test.rb @@ -419,7 +419,7 @@ def app assert_equal env['committee.query_hash']['integer'], 42 #assert_equal env['rack.request.query_hash'][:integer], 42 # this isn't hash indifferent hash because we use rack.request.query_hash [204, {}, []] - end, schema: open_api_3_schema, parameter_overwite_by_rails_rule: false) + end, schema: open_api_3_schema, parameter_overwrite_by_rails_rule: false) header "Content-Type", "application/json" post '/overwrite_same_parameter?integer=42' @@ -434,7 +434,7 @@ def app assert_equal env['committee.request_body_hash'][:integer], 21 assert_equal env['committee.query_hash']['integer'], 42 [204, {}, []] - end, schema: open_api_3_schema, parameter_overwite_by_rails_rule: false) + end, schema: open_api_3_schema, parameter_overwrite_by_rails_rule: false) params = {integer: 21} @@ -454,7 +454,7 @@ def app assert_equal env['committee.query_hash']['integer'], 84 # we can't use query_parameter :( #assert_equal env['rack.request.query_hash'][:integer], 21 # this isn't hash indifferent hash because we use rack.request.query_hash [204, {}, []] - end, schema: open_api_3_schema, parameter_overwite_by_rails_rule: false) + end, schema: open_api_3_schema, parameter_overwrite_by_rails_rule: false) params = {integer: 21} From b165473598f097a34604bf39d917c26e7018e915 Mon Sep 17 00:00:00 2001 From: r7kamura Date: Mon, 13 May 2024 15:31:03 +0900 Subject: [PATCH 2/3] Support the overwite version for backward compatibility --- lib/committee/schema_validator/option.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/committee/schema_validator/option.rb b/lib/committee/schema_validator/option.rb index c309ffa6..fddfeba6 100644 --- a/lib/committee/schema_validator/option.rb +++ b/lib/committee/schema_validator/option.rb @@ -45,7 +45,14 @@ def initialize(options, schema, schema_type) @coerce_recursive = options.fetch(:coerce_recursive, true) @optimistic_json = options.fetch(:optimistic_json, false) @parse_response_by_content_type = options.fetch(:parse_response_by_content_type, true) - @parameter_overwrite_by_rails_rule = options.fetch(:parameter_overwrite_by_rails_rule, true) + + @parameter_overwrite_by_rails_rule = + if options.key?(:parameter_overwite_by_rails_rule) + Committee.warn_deprecated_until_6(true, "The option `parameter_overwite_by_rails_rule` is deprecated. Use `parameter_overwrite_by_rails_rule` instead.") + options[:parameter_overwite_by_rails_rule] + else + options.fetch(:parameter_overwrite_by_rails_rule, true) + end # Boolean options and have a different value by default @allow_get_body = options.fetch(:allow_get_body, schema.driver.default_allow_get_body) From 9e1e9f13a6330b045bc161e671c16d9a787d970d Mon Sep 17 00:00:00 2001 From: r7kamura Date: Mon, 13 May 2024 18:01:09 +0900 Subject: [PATCH 3/3] Add changelog entry about #396 --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7178ca8a..3a5e0df4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +- Rename `parameter_overwite_by_rails_rule` to `parameter_overwrite_by_rails_rule` #396 ## [5.2.0] - 2024-05-04 - Error explicitly that OpenAPI 3.1+ isn't supported #418