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

Should generators respect validations on schemas, and schema instances created from transformOrFail? #439

Open
beem812 opened this issue Nov 21, 2022 · 1 comment

Comments

@beem812
Copy link
Contributor

beem812 commented Nov 21, 2022

Current behavior:

  1. Create a schema with a validation, then derive a generator for that schema.
    running that generator produces values that do not meet the schemas validation.

  2. Create a schema via the .transformOrFail function, then derive a generator from that schema
    running the generator potentially produces no values, despite the condition for successful creation being something simple like strings longer than 5 characters

Potential solutions:

  1. filter the generator over the validation to produce valid instances (It is dangerous to allow someone to create a filter that may never return a value, so this option seems bad)
  2. Similar to one, for transformOrFail instances, keep creating until an instance is actually generated. Again dangerous if all cases fail.
@err0r500
Copy link

I've been surprised by the current behaviour, actually.
Don't know if it's possible but a solution might be to provide a generator for each validation and combine them.
It looks like it's what refined-scalacheck does (and it's not just filters)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants