protoc-gen-jsonschema icon indicating copy to clipboard operation
protoc-gen-jsonschema copied to clipboard

Update to a more actively maintained JSONSchema library

Open chrusty opened this issue 3 years ago • 10 comments

Currently we're using https://github.com/alecthomas/jsonschema to build JSONSchemas, but this project seems to have stopped at draft-04. It might be time to consider an alternative such as https://github.com/santhosh-tekuri/jsonschema,

chrusty avatar Nov 06 '21 20:11 chrusty

Thanks for link! I was searching for a library which supports JSON Schema Draft 07

atreya2011 avatar Nov 16 '21 02:11 atreya2011

Upon further inspection it looks like this library https://github.com/santhosh-tekuri/jsonschema doesn't support conversion but rather just validation?

atreya2011 avatar Nov 16 '21 02:11 atreya2011

Hi @atreya2011. I've not done any testing against this library, but at first glance it did seem to support the new JSONSchema features that I'd like to use here.

protoc-gen-jsonschema wouldn't make use of any conversion capabilities anyway - these behaviours are so tighltly bound to the options we offer and the desired layouts. I'd really just be looking to use the structure and marshalling capabilities instead.

In any case, I've opened a PR with our existing dependency lib to introduce some of the stuff I want to use, so it might take the pressure off for a bit.

chrusty avatar Nov 16 '21 03:11 chrusty

Thanks for your kind reply 🙏🏼 In then end I have decided to go down this path

  • Maintain the JSON Schema as a YAML file
  • Convert it to JSON, Go and TypeScript definitions using codegen libraries

A example of how I went about it is here if you are interested https://github.com/atreya2011/go-kratos-test/blob/32328056c8f2764b5f0fadeaf8e1d7a817b630d8/Makefile#L4

atreya2011 avatar Nov 18 '21 02:11 atreya2011

Hey @chrusty - https://github.com/pnwcode/protoc-gen-jsonschema/commit/86b60afd2c7d3db39b20125c5602650369d27a49 gets a compiling version of this. As the commit says, the tests are of course broken...but i needed schema 07 and this got me close enough.

parsnips avatar Apr 16 '22 19:04 parsnips

Hey @parsnips, the invopop fork looks like the right choice - almost a drop-in replacement!

I can pick this up at some point, get it fully integrated and make sure the tests pass. Should we be concerned about any other schema-07 features that need to be brought along?

chrusty avatar Apr 17 '22 20:04 chrusty

Should we be concerned about any other schema-07 features that need to be brought along?

I'm not sure, the thing I needed was the newer enumeration format and just by flipping versions it produced the correct json schema.

parsnips avatar Apr 19 '22 16:04 parsnips

jsonschema by @alecthomas was discontinued. Maintenance has moved to invopop/jsonschema.

franchb avatar Apr 22 '22 16:04 franchb

Are there still plans to update to a newer draft?

timofurrer avatar Feb 07 '24 15:02 timofurrer

Following the publication of https://buf.build/community/chrusty-jsonschema, we received several questions and support requests for updated JSON Schema drafts.

We've started an initiative to publish a collection of Protobuf plugins, including jsonschema (Draft 2020-12), that generate various schemas from protobuf files.

Anyone interested can find the open-source repository here: bufbuild/protoschema-plugins and a protoc-gen-jsonschema is also available as a Remote Plugin here.

We'll continue to publish @chrusty's plugin as new tags become available. ✌️

mfridman avatar Mar 13 '24 20:03 mfridman