Live data from Hacker News

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

typeschema.org

11–20 of 52 posts

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

#11
post #10
post #8

Earlier quoted context omitted.

Feels much weaker/naive than JSON Schema, as TypeSchema barely has any constraints. The TypeSchema spec is hard to comprehend as it doesn't delve into any details and looks like just a bunch of random examples with comments than a proper definitive document (e.g. they don't ever seem to define what "date-time" string format is). I don't see a way to say, e.g., that a string must be an UUIDv7, or that an integer must…

"What is the difference to JSON Schema? 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." They have more details on the History page.

Yeah, I've edited my comment above and added the last paragraph with a note about it. Must be a really weird use case when you need to write a bunch of code in different languages (probably writing libraries for some API or JSON-based data interchange format?), and is also not concerned about validation and language - because if you need validation, you're writing code by hand either way, so code generation becomes a curse rather than a blessing.

I would've understood if it would do the inverse - read source code in any of the supported languages, and check if the structures it define it conforms to the schema. That would make sense for testing that those structs aren't too diverging between codebases (have the same-shaped fields). Even then I'm not sure I see the point because various languages tend to use different language-specific things (like an UUID type or enums/symbols/atoms, etc.) to make developer feel at home rather than in a barren JSONland.

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

#12
I find it interesting that the Go serialization just duplicates the props rather than using composition: https://typeschema.org/example/go

Seems a bit naively implemented.

Ideally, the duplicated props in Student would just be a single line of `Human`.

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

#13
post #10
post #8

Earlier quoted context omitted.

Feels much weaker/naive than JSON Schema, as TypeSchema barely has any constraints. The TypeSchema spec is hard to comprehend as it doesn't delve into any details and looks like just a bunch of random examples with comments than a proper definitive document (e.g. they don't ever seem to define what "date-time" string format is). I don't see a way to say, e.g., that a string must be an UUIDv7, or that an integer must…

"What is the difference to JSON Schema? 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." They have more details on the History page.

Those are certainly words, but since the words they use to describe what differentiates them form JSON Schema is just asserting that their thing is for exactly what has always motivated schema languages including, but not limited to, JSON Schema, and since JSON Schema supports that purpose far better, I am left confused

At best, I can guess that maybe they are trying to get at the fact that JSON schema supports some structures that can be awkward or unidiomatic for data models in some languages (a lot of what you can do via allOf or oneOf fits this) and they want to narrow down to something where what can be defined in the schema language is also simple idiomatic structures nearly everywhere, but a restricted profile of JSON Schema would get you there much faster than starting from the ground up.

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

#14
post #10

Earlier quoted context omitted.

"What is the difference to JSON Schema? 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." They have more details on the History page.

Those are certainly words, but since the words they use to describe what differentiates them form JSON Schema is just asserting that their thing is for exactly what has always motivated schema languages including, but not limited to, JSON Schema, and since JSON Schema supports that purpose far better, I am left confused At best, I can guess that maybe they are trying to get at the fact that JSON schema supports some…

> narrow down to something where what can be defined in the schema language is also simple idiomatic structures nearly everywhere

It feels more like a lowest common denominator to me, which is frequently (in presence of anything non-trivial) the opposite of idiomatic.

For example, JSON does not have monetary/decimal type, best option available is a string. It would be very opposite of idiomatic to have a C# or Python code use a string in the record/dataclass, instead of a decimal, if the actual JSON document field has the "monetary value" semantic.

And TypeSchema seem to ignore aspects like nullability and presence requirements, making assumptions that everything can be null (which can be wrong and even harmful, as if Java haven't taught us anything).

Maybe I'm thinking wrong about it and the idea is to have separate wire and public API formats, though, where the wire format is minimal JSON (TypeSchema can work, I guess, although I still have concerns about nulls - and distinguishing between nulls and absence of the field) and then that intermediate almost-over-the-wire-but-deserialized-from-JSON-blob object representation is adapted into a language-specific idiomatic structure. I always felt that such approach is way too verbose and adds a lot of boilerplate without a good reason, but I could be wrong about it.

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

#15
The rust generator seems not to place generic parameters on the type itself?

use serde::{Serialize, Deserialize}; #[derive(Serialize, Deserialize)] pub struct Map { #[serde(rename = "totalResults")] total_results: Option,

    #[serde(rename = "entries")]
    entries: Option>,

}

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

#16

Earlier quoted context omitted.

Those are certainly words, but since the words they use to describe what differentiates them form JSON Schema is just asserting that their thing is for exactly what has always motivated schema languages including, but not limited to, JSON Schema, and since JSON Schema supports that purpose far better, I am left confused At best, I can guess that maybe they are trying to get at the fact that JSON schema supports some…

> narrow down to something where what can be defined in the schema language is also simple idiomatic structures nearly everywhere It feels more like a lowest common denominator to me, which is frequently (in presence of anything non-trivial) the opposite of idiomatic. For example, JSON does not have monetary/decimal type, best option available is a string. It would be very opposite of idiomatic to have a C# or Python…

Yeah, “idiomatic” may have been a poor word choice, I really meant closer to “simply representable”. oneOf, for instance, lets you very easily define flexible, concise structures in JSON Schema that OO languages without union types may not express naturally if at all, and which may not be natural to work with even if they cna be expressed in many languages.

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

#18
post #3

What's the benefit over existing variants like Swagger/OpenAPI/JsonSchema ?

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.

[dead]

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

#19

Earlier quoted context omitted.

> narrow down to something where what can be defined in the schema language is also simple idiomatic structures nearly everywhere It feels more like a lowest common denominator to me, which is frequently (in presence of anything non-trivial) the opposite of idiomatic. For example, JSON does not have monetary/decimal type, best option available is a string. It would be very opposite of idiomatic to have a C# or Python…

Yeah, “idiomatic” may have been a poor word choice, I really meant closer to “simply representable”. oneOf, for instance, lets you very easily define flexible, concise structures in JSON Schema that OO languages without union types may not express naturally if at all, and which may not be natural to work with even if they cna be expressed in many languages.

This makes sense, but I think it's even a better reason to not use a code generator (which forces certain patterns on your code), but rather think about the best language-native way to express a certain concept you want to express.

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

#20
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.

This tool can convert to JSON Schema, so it can be used with validator libraries. Either way, validation and static duck typing based on schema are two separate concerns, and the latter is impossible without something like a Typescript compiler (or checker if using jsdoc-style Typescript).
Post reply on HN