Earlier quoted context omitted.
Neither binary nor decimal floating point types exist in the JSON spec. The JSON spec does not give an explicit internal representation for floating points, implementations are free to use decimal types internally, if they wish to do so. The JSON spec merely specifies what a "number" is at the grammar level. Having said that most implementations don't use decimal floating points to represent these.
It is a scandal that JSON does not support the BigInt type.
Ask HN: Do you use JSON Schema? Help us shape its future stability guarantees
151–160 of 179 posts
Re: Ask HN: Do you use JSON Schema? Help us shape its future stability guarantees
#152JSON Schema is awesome. I wish Typescript had better support for it though, having to do stuff in Zod and JSON Scheme sucks. I have a system I built that compiles TS types to JSON schema, which then validates data coming into my endpoints, this way I am typesafe at compile time (Typescript API) but if someone hits my REST endpoint w/o using my library, I still get runtime goodness. The number of different ways that J…
Maybe a better solution (not necessarily for your exact your use case) would be to generate the Typescript types from JSON schema? The schema feels more like it should be the real source of truth. That's how protobuf (for example) works - there's a language-independent schema and you can generate types for any languages you wish (but don't have to depend on any particular language if you don't need it).
1. Fancy combo of build and compile time generics generated all of our libraries 2. Tooling ran over return values from the generic definitions and created the schema
I rewrote it and now everything is defined in JSON files and those JSON files are ran through a code generator that creates our exported libraries, and we still generate the schema based on the TS exports.
Having everything defined in JSON then allowed us to write tooling on top of the JSON to make changes to our libraries.
Protobuf v3 is horrible, had to start using it recently. The type system is so anemic, it is a joke how hard it is to model things in it.
JSON schema is more powerful than TS, and TS is orders of magnitude more powerful than what can be expressed in PB.
The original generics code was super cool, and obscenely succinct, but it wasn't amenable to being auto generated.
Re: Ask HN: Do you use JSON Schema? Help us shape its future stability guarantees
#153JSON Schema is awesome. I wish Typescript had better support for it though, having to do stuff in Zod and JSON Scheme sucks. I have a system I built that compiles TS types to JSON schema, which then validates data coming into my endpoints, this way I am typesafe at compile time (Typescript API) but if someone hits my REST endpoint w/o using my library, I still get runtime goodness. The number of different ways that J…
What tool do you use to generate json schema from typescript?
Re: Ask HN: Do you use JSON Schema? Help us shape its future stability guarantees
#154Earlier quoted context omitted.
> Also lack of inheritance support. (For example I want a way to specify that my json object should be deserialized as Dog not as Animal.) Use Typescript, then so long as it barks, you can treat it like a dog! And if it knows how to bark and meow, you can treat it as a dog or a cat at your leisure. :-D
The issue is when JSON has to be parsed on the server using Java/C#. How do you know whether to parse it as a Dog or as a Cat (both of which inherits from Animal)? Here's Microsoft's workaround: https://devblogs.microsoft.com/dotnet/system-text-json-in-do...
I mean how MS does it, yeah, you have a tagged union, look at the tag to determine what it is.
Heck even networking packets work this way, UDP or TCP, look at the Protocol Field on the IP packet to see which it is.
Re: Ask HN: Do you use JSON Schema? Help us shape its future stability guarantees
#155Earlier quoted context omitted.
The issue is when JSON has to be parsed on the server using Java/C#. How do you know whether to parse it as a Dog or as a Cat (both of which inherits from Animal)? Here's Microsoft's workaround: https://devblogs.microsoft.com/dotnet/system-text-json-in-do...
I must admit I'm a noob in this world so maybe I'm going about it the wrong way, but I used JSON Schema's oneOf[1] along with required[2] for this: "properties": { "cat": { "$ref": "#/$defs/catType" } "dog": { "$ref": "#/$defs/dogType" } }, "oneOf": [ { "required": ["cat"] }, { "required": ["dog"] }, ] Usage would then look like: { "dog": { "name": "Charlie" } } At least it's explicit and can be easily checked for va…
Re: Ask HN: Do you use JSON Schema? Help us shape its future stability guarantees
#156Earlier quoted context omitted.
A good json schema validator will usually reject excess fields.
Actually, currently, this is not the case. The specification explicitly allows for additional fields for the purposes of extensions. We are considering changing that, and only allowing pre-defined fields, or having a way to mark specific fields as limited extensions.
Re: Ask HN: Do you use JSON Schema? Help us shape its future stability guarantees
#157Re: Ask HN: Do you use JSON Schema? Help us shape its future stability guarantees
#158Earlier quoted context omitted.
What are you trying to do in regard to your API? I just developed an extensive API definition using OpenAPI, which (as of version 3.1) is compliant with JSON Schema. I used Stoplight Studio on Mac OS, although it still doesn't fully support OAS 3.1 two years after it became the current OpenAPI standard. The support from tools and generators is terrible; there's still no apparent toolchain that supports version 3.1 fr…
I am planning to autogenerate a set of Java libs from OpenAPI 3.1 definitions in an upcoming project, and so far have assumed it would Just Work. Am I going to have a bad time?
The OpenAPI Generator uses Mustache templates and a plug-in-style design to handle all the different languages and outputs targeting different packages. I was never able to find a succinct document explaining exactly how the processing steps worked or even a catalog of data elements that the generator extracted from your OpenAPI spec document (YAML or JSON). So while there's a lot of talk about creating a custom template, or, if that's not enough, a custom generator... the documentation to do so is very incomplete. The only example I found all discussed making a generator for documentation and not code. Again, not to sound unappreciative, but... that's lame.
Re: Ask HN: Do you use JSON Schema? Help us shape its future stability guarantees
#159Earlier quoted context omitted.
What are you trying to do in regard to your API? I just developed an extensive API definition using OpenAPI, which (as of version 3.1) is compliant with JSON Schema. I used Stoplight Studio on Mac OS, although it still doesn't fully support OAS 3.1 two years after it became the current OpenAPI standard. The support from tools and generators is terrible; there's still no apparent toolchain that supports version 3.1 fr…
I spent the last year and half working on a project where we planned to use OpenApi/AsyncApi to generate typed api clients and validate api requests between all our services and applications (written in typescript & C#). Going into it, I thought we'd be on a well traveled path, but that was far from the case... Typescript has some decent code generation packages (although fragmented) and request validation can be hac…
Using OpenAPI and Stoplight was very useful for thinking the API through and how the whole thing could work, but the code-generation aspect was a total bust. And talking to some new colleagues later who had some knowledge of it, I found that I wasn't alone in my opinion that the tooling is trash.
Even worse, the prevailing opinion on the ecosystem is so poor that it might even be a professional liability to propose (or admit to) using it. The implication was that it (or at least the code-generation facilities for it) is by and for people who don't know what they're doing. Oof.
Re: Ask HN: Do you use JSON Schema? Help us shape its future stability guarantees
#160Earlier quoted context omitted.
What are you trying to do in regard to your API? I just developed an extensive API definition using OpenAPI, which (as of version 3.1) is compliant with JSON Schema. I used Stoplight Studio on Mac OS, although it still doesn't fully support OAS 3.1 two years after it became the current OpenAPI standard. The support from tools and generators is terrible; there's still no apparent toolchain that supports version 3.1 fr…
It's kind of insane how stoplight and swagger/smartbear still don't support OpenAPI 3.1 Half tempted to just start building out OA3.1 stuff to replace those services
And I don't even know Python. I figured it'd be easier to learn it and use it for text processing than wasting any more time trying to make the sprawling Java "tools" work.