Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Info exension omits optional parameters with no predicates #347

Open
taylorthurlow opened this issue Mar 22, 2021 · 0 comments
Open

Info exension omits optional parameters with no predicates #347

taylorthurlow opened this issue Mar 22, 2021 · 0 comments

Comments

@taylorthurlow
Copy link

taylorthurlow commented Mar 22, 2021

Describe the bug

Using the info extension, I expected to be able to fetch a concise list of provided schema keys and whether or not they are required by using #info. This works great, but I'm finding that defining an optional schema key which has no predicates attached is completely omitted from this result. (See reproduction script below)

I'm not sure if this is an intentional thing or not, because I do see that, in my provided example, optional(:age) is sort of a "nothing burger". As far as the schema is concerned it doesn't end up really meaning anything. In my use case, a user is using dry-schema to build a definition for object attributes. optional(:age) has meaning to them/me because it signals the intent to create a getter/setter for :age, even if the value will just pass through the schema validator.

To Reproduce

require 'dry/schema'

Dry::Schema.load_extensions(:info)

Dry::Schema.Params {
  required(:email).filled(:string)
  optional(:age)
}.info # => {:keys=>{:email=>{:required=>true, :type=>"string"}}}

puts Dry::Schema.Params {
  required(:email).filled(:string)
  optional(:age).filled(:integer)
}.info # => {:keys=>{:email=>{:required=>true, :type=>"string"}, :age=>{:required=>false, :type=>"integer"}}}

Expected behavior

require 'dry/schema'

Dry::Schema.load_extensions(:info)

Dry::Schema.Params {
  required(:email).filled(:string)
  optional(:age)
}.info # => {:keys=>{:email=>{:required=>true, :type=>"string"}, :age=>{:required=>false}}}

puts Dry::Schema.Params {
  required(:email).filled(:string)
  optional(:age).filled(:integer)
}.info # => {:keys=>{:email=>{:required=>true, :type=>"string"}, :age=>{:required=>false, :type=>"integer"}}}

My environment

  • Affects my production application: No
  • Ruby version: 2.5 to 2.7
  • OS: macOS Catalina
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant