From 8000c30ada5a7e283f986341d23e55d74081d742 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20=C3=81vila?= Date: Thu, 16 May 2024 00:26:48 -0300 Subject: [PATCH] Json schema docs --- README.md | 49 ++++++++++++++++++++++++++++++++++++------------- 1 file changed, 36 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 0f292460..ddd837c5 100644 --- a/README.md +++ b/README.md @@ -90,6 +90,42 @@ Options: ## Extra Features +### Json Schema + +Generate flat JSON schema from types. + +Recursive types are not supported and become the equivalent of `any` in the second time they appear. + +Configure your `beff.json` + +```json +{ + "parser": "./src/parser.ts", + "outputDir": "./src/generated" +} +``` + +Import the generated code and configure types that will be exported. + +```ts +import s from "./generated/schema"; + +type ProfileData = { + name: string; +}; + +type User = { + profile: ProfileData; + age: number; +}; + +export const Schemas = s.buildSchemas<{ + User: User; +}>(); + +console.log(Schemas.User); // JSON Schema without references +``` + ### Custom String Formats Configure your `beff.json` @@ -156,19 +192,6 @@ const AdHocList = b.Array(AdHocItem); const ls = AdHocList.parse([]); ``` -### Json Schema - -Validator have a `.jsonSchema` property with a flattened JSON Schema. - -Recursive types are not supported and become the equivalent of `any` in the second time they appear. - -```ts -import { Parsers } from "./parser.ts"; -import { z } from "zod"; - -const userSchema = Parsers.User.jsonSchema; -``` - ### Zod Compatibility Call `.zod()` on a parser to create a `zod` type.