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

JSON schema contract failing to recognise valid input #720

Open
RajatPawar opened this issue Nov 15, 2022 · 2 comments
Open

JSON schema contract failing to recognise valid input #720

RajatPawar opened this issue Nov 15, 2022 · 2 comments

Comments

@RajatPawar
Copy link

RajatPawar commented Nov 15, 2022

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
@RajatPawar RajatPawar changed the title Schema failing to recognise valid input JSON schema contract failing to recognise valid input Nov 15, 2022
@flash-gordon
Copy link
Member

?-ending keys are not supported because they have special meaning in dry-types. It was a trade-off I made. We could have an option for schemas to avoid this in dry-schema, I think. I'll give it a try.

@RajatPawar
Copy link
Author

RajatPawar commented Nov 16, 2022

Ah, okay. I didn't see it in the documentation. Could you please add it along with any other key constraints? It would make things easier to have this functionality. Appreciate the work behind this library, thanks!

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

2 participants