@web2paper/vite-plugin-ts-schema
v0.0.2
Published
Vite plugin to generate a JSON schema from a typescript type.
Readme
This is a Vite plugin for Web2Paper. It allows you to design the data schema of the model in TypeScript instead of JSON
Schema. This is made possible by the legendary typescript-json-schema library.
Have a look at the resume example to see what is possible.
This package is part of the @web2paper/modeling-* ecosystem.
⚠️ Web2Paper and its ecosystem are under construction. Expect breaking change to API and bugs.
Usage
// vite.config.ts
import {defineConfig} from 'vite'
import {viteWeb2PaperTsSchema} from "@web2paper/vite-plugin-ts-schema";
export default defineConfig({
// [...]
plugins: [
// [...]
// Generate the JSON Schema for the model's data from a Typescript definition (you're welcome)
viteWeb2PaperTsSchema({
entrypoint: "schema/index.ts", // Path to the file containing the type to transform to a JSON Schema
type: "Resume", // Type to transform
schemaFile: "schema.json" // Name of the schema file (stay with `schema.json` for Web2Paper)
}),
// [...]
],
})Do I really need that ?
No. If you enjoy pain, you can simply write your JSON schema by hand and then reproduce your schema in types if you ever want to interact programmatically with the data injected in the model.
