Skip to content

Commit

Permalink
Json schema docs
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasavila00 committed May 16, 2024
1 parent 357bdf9 commit 8000c30
Showing 1 changed file with 36 additions and 13 deletions.
49 changes: 36 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 8000c30

Please sign in to comment.