Live data from Hacker News

Show HN: TypeSchema – A JSON specification to describe data models

typeschema.org

31–40 of 52 posts

Re: Show HN: TypeSchema – A JSON specification to describe data models

#31

Why reinvent https://json-schema.org ?? Pros/cons?

From my understanding, JSON schema describes the schema of JSON objects with JSON. This one describes a variety of types of schemas with JSON.

So it could be typescript, Go, GraphQL, etc. It seems to output to JSON schema as well. I guess its main purpose is to share the schema between different languages. Which I imagine works with JSON schema too, but this takes it a step further and handle all the mapping you'd need to do otherwise.

Re: Show HN: TypeSchema – A JSON specification to describe data models

#32
post #21

Earlier quoted context omitted.

Yeah, I'm not really following the line of reasoning presented on the "/history" page: https://typeschema.org/history It seems to me like a mischaracterization of JSON Schema to say you can't define a concrete type without actual data. I am a very stupid individual so I could be misunderstanding the argument.

I can't really follow those arguments either. For example the empty object example {}. Why is this bad? Types without properties are a real thing. Also an empty schema is a real thing. The thought I do get: JSON Schema primarily describes one main document (object/thing). And additionally defines named types (#/definitions/Student). But it's totally fine to just use the definitions for code generation. The reference…

Maybe it's just me, but I've never been able to get a complex type schema to work properly with JSON schema.

The moment you have types referencing other types in a way that can become recursive in ANY way, the whole thing seems to explode.

Re: Show HN: TypeSchema – A JSON specification to describe data models

#34
From the history page:

> JSON Schema is a constraint system which is designed to validate JSON data. Such a constraint system is not great for code generation, with TypeSchema our focus is to model data to be able to generate high quality code.

Well, types themselves are another type of constraint; specifying something like the type (number) of a property (Age) is a constraint on the possible values for that property.

> For code generators it is difficult to work with JSON Schema since it is designed to validate JSON data

There's lots of features in JSON Schema, but if you're writing a code generator, you don't actually to have support all of them. Some languages like C# don't have native lang support for AllOf, but do support OneOf or AnyOf.

> JSON Schema has many keywords which contain logic like dependencies, not, if/then/else which are basically not needed for code generators and really complicates building them.

So isn't the whole point of code generators for OpenAPI/JSON Schema is that they generate code to map foreign data sources in a target programming language so that the programmer doesn't have to write all this mapping code by hand? The vast majority of all programming languages support if/then/else and even modelling dependencies like what JSON Schema supports. So why is it a bad thing if a schema language like JSON Schema supports these constraints? Wouldn't having support for this in the schema language and a code generator mean less handwritten code and more time saved?

If a schema constrained Person.Age to be an integer always greater than 0, I would actually really love for that validation code to be generated for me. Chances are, if such constraints exist in the schema, then the vendor/original author probably has good reason to include them; having it code generated automatically means I don't have to worry about writing it myself.

I mean if you want to generate the code for only defining data structures & their properties, you can still do that, and just stop there. A whole new schema language in JSON seems wholly redundant. It seems like maybe the authors should've started with writing their own better code generator for JSON Schema rather than their whole new schema language and code generator.

Finally, reading the spec https://typeschema.org/specification, I can't see support for optional values or null/nullable types. I'm hoping it's just an oversight (seeing as how the spec itself is incredibly brief), but if it isn't, then bluntly, then this isn't ready for release.

Re: Show HN: TypeSchema – A JSON specification to describe data models

#36
post #17

TypeScript but no JavaScript is a tiny bit disappointing. I still like to be able to work on front-end code without needing to run separate build tooling.

It can actually generate the JavaScript type definitions for all possible inputs at once! Here, I'll copy and paste the result for you:

Hope that helps.

Re: Show HN: TypeSchema – A JSON specification to describe data models

#37

Why reinvent https://json-schema.org ?? Pros/cons?

json schema has nuanced and expressive constraints to validate information exchanged in json serialization.

typeschema in contrast seems to focus on describing just the structure of data with the goal to generate stubs in a wide variety of programming languages.

Re: Show HN: TypeSchema – A JSON specification to describe data models

#38

Looking at the Kotlin or TypeScript examples, it would be preferable to use one of them as source and parse it to output other formats. An LLM would probably be good at doing this too. Unless it can do more than generate boilerplate code I can't see needing this.

You don't need an LLM for that task.

Re: Show HN: TypeSchema – A JSON specification to describe data models

#39
Three big downturns for me:

1) They do not publish rationale of why the world needs yet another protocol / language / framework on the homepage. It is hidden in https://typeschema.org/history

2) In the history page, they confuse strongly typed and statically typed languages. I have a prejudice about people doing this.

3) The biggest challenge about data models is not auto-generated code (that many people would avoid in principle anyway), but compressed, optimized wire serialization. So you START with selecting this for your application (eg. AVRO, CapnProto, MessagePack etc) and then use the schema definition language coming with the serialization tool you've chosen.

Re: Show HN: TypeSchema – A JSON specification to describe data models

#40

Three big downturns for me: 1) They do not publish rationale of why the world needs yet another protocol / language / framework on the homepage. It is hidden in https://typeschema.org/history 2) In the history page, they confuse strongly typed and statically typed languages. I have a prejudice about people doing this. 3) The biggest challenge about data models is not auto-generated code (that many people would avoid…

also the output in markdown and php doesn't seem good
Post reply on HN