Remove incorrect documentation about combining values and allow_blank - #2631
Remove incorrect documentation about combining values and allow_blank#2631eriklovmo wants to merge 1 commit into
values and allow_blank#2631Conversation
The example is incorrect: you can, in fact, not supply a blank value to `state` with that `params` block.
|
I did not update the changelog because it seemed like an insignificant patch. Is that OK? |
|
@eriklovmo I do confirm the behavior # frozen_string_literal: true
require 'bundler/inline'
gemfile(true) do
source 'https://rubygems.org'
gem 'grape'
gem 'rack'
gem 'minitest'
gem 'rack-test'
end
require 'minitest/autorun'
require 'rack/test'
require 'grape'
class GrapeAPIBugTest < Minitest::Test
include Rack::Test::Methods
def setup
@api = Class.new(Grape::API) do
prefix :api
version 'v1', using: :path
params do
requires :state, type: Symbol, values: [:active, :inactive]
end
post '/' do
'hello'
end
end.new
end
def test_v1_users_via_api
options = {
method: Rack::POST,
params: {
state: nil
}
}
env = Rack::MockRequest.env_for('/api/v1', options)
response = Rack::MockResponse[*@api.call(env)]
assert_equal 'hello', response.body
assert_equal 201, response.status
end
endIt fails |
|
But #2185, is mentionning something about |
Thanks!
OK, this might warrant a clarifying note in the docs. When using |
|
@eriklovmo Verified — your removal is correct. Behavior matrix from a runnable repro:
To your question — "ambiguity around blankness, or conflating optional keys with optional values?" — it's the latter. return if val.nil? && !required_for_root_scope?This runs before The To reject blank values from an I rolled this into #2700 (the README/docs cleanup PR) with the deletion you proposed plus a clarifying replacement note covering |
…l + values Spelling and grammar: - "given on an `configuration`" → "based on a `configuration`" - "Accept` head" → "Accept` header" - "won't affects" → "won't affect" - "with' blocks" → "with` blocks" (mismatched quote) - `required :beer` / `:wine` / `:blah` → `requires` (the DSL method is `requires`; the samples as written would raise NoMethodError) - "the the [grape-entity]" → "the [grape-entity]" Accuracy: - §"Accept-Version Header": the strict-mode sentence said the 406 was raised when no correct `Accept` header was supplied; the middleware checks `HTTP_ACCEPT_VERSION`, so corrected to "Accept-Version". - "Rack::Etag" → "Rack::ETag" (correct class name). - Removed the "Integer/Fixnum and Coercions" section comparing Ruby 2.4 vs. earlier — `grape.gemspec` requires Ruby >= 3.2, where `Fixnum` no longer exists. Replaces an incorrect note about `requires + values + allow_blank` (closes #2631) with a correct note covering `optional + values`. The deleted note claimed `:allow_blank` defaults to `true` and that absence of `:allow_blank` does not prevent `:state` from receiving blank values — both wrong: `@allow_blank` defaults to `nil`, and `requires` already rejects `nil` via the values validator. The real quirk is `optional + values`: `ValuesValidator#validate_param!` short-circuits on `nil` whenever the param is optional at the root scope, so missing/`nil`/`""`-coerced-to-`nil` all pass. The new note documents that and shows `allow_blank: false` as the way to opt out while still allowing the key to be absent. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
Superseded by #2700, which incorporates this deletion plus a corrected clarifying note about |
…l + values (#2700) Spelling and grammar: - "given on an `configuration`" → "based on a `configuration`" - "Accept` head" → "Accept` header" - "won't affects" → "won't affect" - "with' blocks" → "with` blocks" (mismatched quote) - `required :beer` / `:wine` / `:blah` → `requires` (the DSL method is `requires`; the samples as written would raise NoMethodError) - "the the [grape-entity]" → "the [grape-entity]" Accuracy: - §"Accept-Version Header": the strict-mode sentence said the 406 was raised when no correct `Accept` header was supplied; the middleware checks `HTTP_ACCEPT_VERSION`, so corrected to "Accept-Version". - "Rack::Etag" → "Rack::ETag" (correct class name). - Removed the "Integer/Fixnum and Coercions" section comparing Ruby 2.4 vs. earlier — `grape.gemspec` requires Ruby >= 3.2, where `Fixnum` no longer exists. Replaces an incorrect note about `requires + values + allow_blank` (closes #2631) with a correct note covering `optional + values`. The deleted note claimed `:allow_blank` defaults to `true` and that absence of `:allow_blank` does not prevent `:state` from receiving blank values — both wrong: `@allow_blank` defaults to `nil`, and `requires` already rejects `nil` via the values validator. The real quirk is `optional + values`: `ValuesValidator#validate_param!` short-circuits on `nil` whenever the param is optional at the root scope, so missing/`nil`/`""`-coerced-to-`nil` all pass. The new note documents that and shows `allow_blank: false` as the way to opt out while still allowing the key to be absent. Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The deleted example was incorrect: you can, in fact, not supply a blank value to the
stateparameter with such aparamsblock. I don't know the background, maybe it was correct at one point in time.