News for hackers. Stuff that matters.
Re:JSON with Commas and Comments by nly on Tuesday February 23, 2021 @04:33AM (#26235409)
Imho, statically typed languages are the ones that benefit most from schema. The current schema version is 12 but the implementations for Go, Rust, C++ and Java are all listed as draft 7. None of them support codegen either, just validation, so not exactly compelling.
Re:JSON with Commas and Comments by dragonwriter on Tuesday February 23, 2021 @05:31AM (#26235703)
> The current schema version is 12 but the implementations for Go, Rust, C++ and Java are all listed as draft 7

It's actually 2020-12, which is two versions after Draft 7 (they shifted from Draft n to YYYY-MM after Draft 7, and since then have had 2019-09 and 2020-12.)

And that's true of most languages, though there is some 2019-09 support. (It really doesn't help that there is also OpenAPI which baked in a variant—“extended subset”—of Draft 5 JSON Schema.)

Re:JSON with Commas and Comments by devj on Tuesday February 23, 2021 @08:45AM (#26237135)
OpenAPI 3.1 which was released recently, uses JSONSchema 2020-12 as the primary schema format. As a result, we can expect further consolidation of tooling, etc in the community.
Re:JSON with Commas and Comments by lloeki on Tuesday February 23, 2021 @04:46AM (#26235474)
I benefit greatly from schema validation in Ruby, ensuring that ingress-processing code does not receive e.g a String or Hash instead of an Array which would have things blow up way after the ingress edge when a call to an Array method fails, or worse, produce silently broken behaviour that may or may not blow up even farther down the road because both String and Hash respond to e.g #[](Integer).
Re:JSON with Commas and Comments by nly on Tuesday February 23, 2021 @07:02AM (#26236310)
Yeah but Ruby is a dynamically typed language. There's not much benefit to codegen since nothing is checked at compile time anyway.
Re:JSON with Commas and Comments by lloeki on Tuesday February 23, 2021 @11:01AM (#26238812)
I found code generation to be useful in Ruby with protobuf. This:

https://github.com/lloeki/ruby-skyjam/blob/master/defs/skyja...

gives that:

https://github.com/lloeki/ruby-skyjam/blob/master/lib/skyjam...

I would certainly enjoy having a DSL to write descriptive code to validate using JSON schema, but it would be even better if the Ruby definitions could be generated and persisted in Ruby files using that DSL.

Also, storing things in basic hash/array types works, but having dedicated types is useful, so that one can ensure not shoving one kind of hash in place of another unrelated kind of hash.

As for types themselves in general, there's RBS and Sorbet. One could have type definition generation as well for even deeper static and runtime checks.

Re:JSON with Commas and Comments by speedgoose on Tuesday February 23, 2021 @05:06AM (#26235572)
Do you really want generated code to manipulate JSON? I'm not sure there is a demand for that.
Re:JSON with Commas and Comments by nly on Tuesday February 23, 2021 @05:29AM (#26235690)
Manipulating anything dynamic in a statically typed language is generally tedious and not type safe, so yes.
Re:JSON with Commas and Comments by johannes1234321 on Tuesday February 23, 2021 @08:37AM (#26237057)
In any language I eventually need to validate. Whether I do it early, using a validator, or during processing the data at later is a choice depending on the problem.

Existence of a schema definition file and checking responses against is signalling that I can trust an API vendor to be at least aware of the requirements for clients. (Whether they randomly change the schema definition or ignore it is a second question, but at least somebody once thought about formalising and it's not an complete adhoc dump of today's internal data representation)