Show HN: JSONSchema to TypeScript compiler
github.com
github.com
In case you need to do the reverse, for example model-first in typescript and want to generate JSONSchema:
Typescript Code to JSONSchema: https://github.com/YousefED/typescript-json-schema - started this long ago but some great contributors are leading it since!
[0] https://github.com/bcherny/json-schema-to-typescript/issues/...
$refs are used in JSONSchema, but are described in the separate JSONPointer spec [0].
See unit tests for examples:
- In-file $ref: https://github.com/bcherny/json-schema-to-typescript/blob/ma...
- Local $ref: https://github.com/bcherny/json-schema-to-typescript/blob/ma...
- Remote $ref: https://github.com/bcherny/json-schema-to-typescript/blob/ma...
- Cyclical $ref: https://github.com/bcherny/json-schema-to-typescript/blob/ma...
Hope that helps!
Now that TypeScript is gaining traction it might be a great moment to start documenting your REST payloads with it instead of eg JSON Schema or just some JSON example blobs. It's very readable even for non TypeScript programmers.
Planning on adding TypeScript soon, and may do JSONSchema too!
It’s written in Elm, whose strict compiler really helps with avoiding bugs. https://github.com/RoyalIcing/lofi-schema-elm
I'm considering taking a crack at a Julia output module for your project. Those output adapters look pretty straightforward.
Ok will consider JSON Schema support. Thanks!
We've gotten to a point where a human-readable, human-editable text format for structured data has become a complex nightmare where somebody can safely say "As many threads on xml-dev have shown, text-based processing of XML is hazardous at best" and be perfectly valid in saying it. -- Tom Bradford
For any use case where there is a set of servers and a set of clients that interact with those servers, you often end up having to hard-code API contracts and response shapes on each client and each server.
If your client and server are written in the same language, you might be able to write an interface/class once and share the code between both builds. But what if (as is more often the case) they are written in different languages? What if you introduce a 3rd client, written in a 3rd language (say C# on the server, Swift on iOS, and Java on Android)?
This is what Google uses Protobuf for [0]. A competing solution is JSONSchema, which gives a slightly different set of functionality than Protobuf.
You describe your interface once with JSONSchema, and compile it into interfaces/classes for your various clients/servers to consume. This gives you compile time safety, and eliminates the need to manually author these classes and manually keep them in sync between platforms.
As you scale up the number of services/clients/servers you're running, a system like this becomes not just helpful, but necessary to ensure that they can all talk to one another.
Alone, you're right, this project doesn't make much sense, but it's part of a larger community of tools for creating cross-language model definitions based on a common schema language.
https://docs.oracle.com/javase/7/docs/technotes/tools/share/...