Closed riedgar-ms closed 3 months ago
Thanks for getting this started! Just a few comments for you as you're working on this...
pattern
as it will be difficult to enforce that a user's regex is properly escaped and will lead to something that is JSON loads-able... Although maybe all we have to do is document that using this functionality is "at your own risk"select
call inside _gen_json_string and just use a regex (optionally adding {min,max})... Take a look at the regex I sent on the related issue -- may be helpfulThanks for getting this started! Just a few comments for you as you're working on this...
- I'm a little bit wary about exposing direct regex generation via
pattern
as it will be difficult to enforce that a user's regex is properly escaped and will lead to something that is JSON loads-able... Although maybe all we have to do is document that using this functionality is "at your own risk"- In the same vein, it may be impossible to enforce both a pattern and min/max length...
- I think you can do away with the direct
select
call inside _gen_json_string and just use a regex (optionally adding {min,max})... Take a look at the regex I sent on the related issue -- may be helpful
For (1), I'd absolutely say that it's "at your own risk" functionality.
For (2), I'm quite confident that we cannot simultaneously enforce both a pattern and a min/maxLength. Imagine something like "pattern": "aaaa", "maxLength": 2
which is impossible to satisfy.
Of more immediate concern is that my negative test cases are failing really weirdly :-/
Ah, the {b'"'} != {b'"'}
isn't as weird as it looks -- it's a repr problem. Annoyingly valid_next_bytes
doesn't actually return a set of bytes; it returns a set of Byte
s and ByteRange
s (which look like bytes in their reprs).
Ah, the
{b'"'} != {b'"'}
isn't as weird as it looks -- it's a repr problem. Annoyinglyvalid_next_bytes
doesn't actually return a set of bytes; it returns a set ofByte
s andByteRange
s (which look like bytes in their reprs).
That was on my "to investigate" list; was suspecting something like that.
Of more immediate concern: if you look closely at the failing tests, I believe you'll find that they ought to be passing.
Attention: Patch coverage is 98.30508%
with 1 line
in your changes missing coverage. Please review.
Project coverage is 59.18%. Comparing base (
ba86754
) to head (bd30725
).
Files | Patch % | Lines |
---|---|---|
guidance/library/_json.py | 96.00% | 1 Missing :warning: |
:exclamation: Your organization needs to install the Codecov GitHub app to enable full functionality.
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
Looking good! One ask -- could you maybe reuse the sequence
code inside of _regex.py
so we don't have two implementations of it?
Looking to add support for
pattern
,minLength
andmaxLength
to strings in JSON schema. This should address half of #925This has lead to the creation of a few new library functions to help out, and consolidation into a new
_sequences.py
library file. It is also hooked into_regex.py
.