dry-rb/dry-validation

JSON schema contract failing to recognise valid input

Open

#720 aperta il 15 nov 2022

Vedi su GitHub
 (2 commenti) (0 reazioni) (0 assegnatari)Ruby (193 fork)github user discovery
bughelp wanted

Metriche repository

Star
 (1421 star)
Metriche merge PR
 (Metriche PR in attesa)

Descrizione

Describe the bug

A json schema that is not picking up on valid input.

To Reproduce

class TestContract < Dry::Validation::Contract
  json do
    required(:mykey?).value(:bool)
  end
end

input = JSON.parse('{"mykey?": true }')

result = TestContract.new.call(input)
# #<Dry::Validation::Result{} errors={:mykey?=>["is missing"]}>

result.to_h
# {}

result.errors
# #<Dry::Validation::MessageSet messages=[#<Dry::Schema::Message text="is missing" path=[:mykey?] predicate=:key? input={}>] options={}>

Expected behavior

It should have picked up the input since it was conforming to the schema.

My environment

  • Affects my production application: NO
  • Ruby version: 2.6.10
  • OS: macOS 12.6

Guida contributor