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

Validating JSON document when schema has bytes #101

Open
itamarst opened this issue Oct 6, 2021 · 1 comment
Open

Validating JSON document when schema has bytes #101

itamarst opened this issue Oct 6, 2021 · 1 comment
Assignees
Labels
enhancement New feature or request help wanted Extra attention is needed validation
Milestone

Comments

@itamarst
Copy link
Contributor

itamarst commented Oct 6, 2021

Hi,

Continuing investigation of cddl—support for same schema with both JSON and CBOR is great, but there's the problem of bytes. The CDDL RFC says "don't support bytes in schema language", which OK, that's an approach. But another alternative is to say "if schema says bytes, expectation is that in JSON document this will be base64-encoded bytes in a string." And then you could validate JSON documents even with a schema that had bytes, by converting to bytes as part of validation.

I imagine this would have to be a two-step process:

  1. Notice it's supposed to be bytes, check if it's string and convert to bytes.
  2. Then after deserialization to bytes apply any additional controls/constraints, e.g. .size.

Since this not quite compatible with the RFC (arguably it is compatible, in that RFC says "don't use bstr in schema" so this is a superset), might want such a mode hidden behind an option. Some questions:

  1. Would you be amenable to such a feature, if I provided it? Or some other alternative?
  2. Any sense of how difficult it would be to implement?

(Still investigating if this is an actual requirement for the project, or just a nice to have; if this takes more than 60 seconds to answer "not sure" is a fine answer for both questions.)

@anweiss
Copy link
Owner

anweiss commented Oct 7, 2021

Thanks for the feedback @itamarst. While the JSON validator already supports CDDL byte values, to your point, it does not support CDDL byte data types (e.g. bstr and bytes). Also IMHO tool implementors can loosely interpret the following statement from Appendix E of the RFC:

Roughly speaking, this means leaving out byte strings ...

This would be easy to implement. Will mark this as a feature request and if you feel that this is more than just a nice-to-have, let me know and I'll work on it.

@anweiss anweiss added the enhancement New feature or request label Oct 7, 2021
@anweiss anweiss added this to the v1.0.0 milestone Oct 7, 2021
@anweiss anweiss self-assigned this Oct 7, 2021
@anweiss anweiss modified the milestones: v1.0.0, v2.0.0 Mar 23, 2022
@anweiss anweiss added the help wanted Extra attention is needed label Oct 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed validation
Projects
None yet
Development

No branches or pull requests

2 participants