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

Generate JSON Schema from Protobuf definitions and use it to enforce fields? #67

Closed
woodruffw opened this issue Feb 8, 2023 · 3 comments · Fixed by #112
Closed

Generate JSON Schema from Protobuf definitions and use it to enforce fields? #67

woodruffw opened this issue Feb 8, 2023 · 3 comments · Fixed by #112

Comments

@woodruffw
Copy link
Member

Breakout from #64 (comment): I think one possible solution to our "required" field woes is as follows:

  1. Keep the current Protobuf definitions, and mark fields we expect/need as required;
  2. Use a Protobuf to JSON Schema generator to generate a corresponding JSON Schema, including actual field enforcement (meaning that the generator will need to respect/handle the relevant annotations)
  3. Use the generated JSON Schema to actually enforce the validity of JSON marshaled messages

This shouldn't be too difficult to do, and it looks like there's already some tooling out there that does it (https://github.com/chrusty/protoc-gen-jsonschema).

OTOH, it adds yet another layer of schematization, and only applies to JSON-marshaled messages.

cc @znewman01

@kommendorkapten
Copy link
Member

An alternative approach: the protobuf files are not expected to change that frequently. How about we hand code validate functions for each ecosystem, as part of the language bindings in this repo?
Wire up conformance testing to the automation. It will be "expensive" upfront, but I think will simplify our lives down the road with much less complexity.

@znewman01
Copy link
Contributor

znewman01 commented Feb 9, 2023 via email

@jleightcap
Copy link
Contributor

Noting that the using language binding generated from JSON schema seem to have a corner cases around variable naming conventions when trying to share artifacts from bindings generated from protobuf.

Concretely, the camelCase sigstore-python artifacts break Rust bindings (#118), as the JSON schema names are all normalized to snake_case.

See: Marwes/schemafy#73

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

Successfully merging a pull request may close this issue.

4 participants