import { lazy } from "https://deno.land/x/fun@v2.0.0-alpha.6/json_schema.ts";
Creates a lazy JsonBuilder, which is useful for creating recursive JSON Schemas, mutual or otherwise. A limitation of typescript means that the type must be defined outside of the JsonBuilder and manually annotated
Examples
Example 1
Example 1
import * as J from "./json_schema.ts";
import { pipe } from "./fn.ts";
// {
// "$ref": "#/definitions/Person",
// "definitions": {
// "Person": {
// "type": "object",
// "properties": {
// "age": {
// "type": "number"
// },
// "children": {
// "type": "array",
// "items": {
// "$ref": "#/definitions/Person"
// }
// },
// "name": {
// "type": "string"
// }
// },
// "required": [
// "age",
// "children",
// "name"
// ]
// }
// }
// }
type Person = {
readonly name: string;
readonly age: number;
readonly children: ReadonlyArray<Person>;
};
const Person: J.JsonBuilder<Person> = J.lazy("Person", () =>
J.struct({
name: J.string(),
age: J.number(),
children: J.array(Person),
}));
const schema = J.print(Person);
Parameters
fn: () => JsonBuilder<A>