typebox
ts-json-schema-generator
typebox | ts-json-schema-generator | |
---|---|---|
57 | 12 | |
4,746 | 1,417 | |
- | 1.9% | |
8.4 | 9.2 | |
7 days ago | 2 days ago | |
TypeScript | TypeScript | |
GNU General Public License v3.0 or later | MIT License |
Stars - the number of stars that a project has on GitHub. Growth - month over month growth in stars.
Activity is a relative number indicating how actively a project is being developed. Recent commits have higher weight than older ones.
For example, an activity of 9.0 indicates that a project is amongst the top 10% of the most actively developed projects that we are tracking.
typebox
-
Popular Libraries For Building Type-safe Web Application APIs
The documentation can be found here.
-
I write HTTP services in Go after 13 years (Mat Ryer, 2024)
So far I like the commonly used approach in the Typescript community best:
1. Create your Schema using https://zod.dev or https://github.com/sinclairzx81/typebox
2. Generate your Types from the schema. It's very simple to create partial or composite types, e.g. UpdateModel, InsertModels, Arrays of them, etc.
3. Most modern Frameworks have first class support for validation, like is a great example Fastify (with typebox). Just reuse your schema definition.
That is very easy, obvious and effective.
- Where DRY Applies
-
Has anybody used Typia library?
There's a ton of schema validators out there and most devs have their personal favorite. Mine was zod and is now typebox + ajv.
- I'm looking to use my openapi spec to dyanamically create types
-
How can I generate typescript types?
If you're willing to document your API with an OpenAPI schema, then it should be possible to generate TypeScript types based on the OpenAPI schema with something like openapi-typescript. Also, Typebox can generate JSON schemas, maybe it can be used to generate something that the front-end can also use?
-
[AskTS] What do you think will be the future of runtime type checking?
Well, I do provide extensibility for those bullet points you've listed to varying degrees (both schema and type representation), as well as offering a reference implementation for expressing a entirely different schema specification under the type system (specifically RFC8927 / JSON Type Definition). Reference implementation here. As for JSDoc, It's supported in code hints.
- TypeBox: Runtime Type System Built on Industry Standards
- TypeBox: A Type System for JavaScript built on Industry Standard Specifications
-
Building a modern gRPC-powered microservice using Node.js, Typescript, and Connect
In setting out to build this service, we wanted to use gRPC for its APIs. We’ve been reaching for REST when building APIs so far, primarily out of necessity, i.e., our public APIs needed auto-generated client SDKs and docs for developers working with them. We built those APIs with Fastify and Typebox but felt burned by a code-first approach to generating an OpenAPI spec. I’ll spare you the details and save that experience/learning for another article. Suffice it to say we love gRPC’s schema-first approach. This blog post summarizes our feelings well
ts-json-schema-generator
-
TypeSpec: A New Language for API-Centric Development
This looks interesting but I already have TypeScript types for my APIs so I developed https://github.com/vega/ts-json-schema-generator which lets me generate JSON schema from the sources directly. Yes, it does have some oddities because the two languages have slightly different feature sets but it’s been working well for us for a few years. If I didn’t have TypeScript or a smaller API surface I’d be okay with typing again I would look at TypeSpec though. It definitely beats writing JSON schema by hand.
-
Automating API Documentation: A Journey from TypeScript to OpenAPI and Schema Governence with Optic
3. Generate JSON schemas with the ts-json-schema-generator package
-
Is using zod as the primary source of truth for Typescript types sensible/sustainable?
We user ts-json-schema-generator to create the schemas directly from TS types.
-
Validating JSON parser that uses TS as the spec format?
I’ve been using this one: https://github.com/vega/ts-json-schema-generator most recently and it’s been great
-
Transpiling Typescript into Rust
Maybe this vscode extension can work for you. It can turn Json samples into structs. this can help you turn typescript to Json. Maybe you can automate it.
-
Game engine in web - part 2 - data oriented system
Now we have to parse the JSON containing our scene and validate that this JSON is valid according to what we expect. For that we are going to use the JSON Schema along with ts-json-schema-generator to generate said schema automatically and ajv to validate JSON against the generated schema.
-
Is there a tool to visualize all of the value-types of a highly abstracted interface/type?
If the output format isn’t important you could use ts-json-schema-generator - it doesn’t work with everything but it’s pretty good at outputting a json schema structure for interfaces and types.
-
Anyone using decorators, or some other form of inline documentation, to generate an openapi spec file based on a typescript library?
https://github.com/grantila/typeconv/ https://github.com/airtasker/spot https://github.com/vega/ts-json-schema-generator
- TypeScript runtime type-checking - designed for simple use, through to enforcing API payload schema
-
Testing in production: using JSON Schema for 3rd party API response validation
Most people do not write JSON Schema by hand. Typescript is one of the popular tools: https://github.com/vega/ts-json-schema-generator
What are some alternatives?
zod - TypeScript-first schema validation with static type inference
zod-to-json-schema - Converts Zod schemas to Json schemas
ajv - The fastest JSON schema Validator. Supports JSON Schema draft-04/06/07/2019-09/2020-12 and JSON Type Definition (RFC8927)
typescript-json-validator - Automatically generate a validator using JSON Schema and AJV for any TypeScript type.
class-validator - Decorator-based property validation for classes.
typeconv - Convert between JSON Schema, TypeScript, GraphQL, Open API and SureType
openapi-typescript-validator - Generate typescript with ajv validation based on openapi schemas
spot - Spot is a concise, developer-friendly way to describe your API contract.
io-ts - Runtime type system for IO decoding/encoding
awesome-jsonschema - A curated list of awesome JSON Schema resources, tutorials, tools, and more