Libraries
    Preparing search index...

    Function withStandardJsonSchema

    • Wraps a @cleverbrush/schema builder with the Standard JSON Schema v1 interface.

      The returned schema object's ~standard property is enriched with a jsonSchema converter. Because @cleverbrush/schema does not distinguish between input and output types, both input() and output() produce the same JSON Schema document.

      Note: this mutates the schema instance by overriding the ~standard property. The returned reference is the same schema object.

      Type Parameters

      Parameters

      • schema: T

        Any @cleverbrush/schema builder instance.

      Returns T & StandardJSONSchemaV1<unknown, unknown>

      The same schema instance, now also conforming to StandardJSONSchemaV1.

      import { object, string, number } from '@cleverbrush/schema';
      import { withStandardJsonSchema } from '@cleverbrush/schema-json';

      const schema = object({ name: string(), age: number().optional() });
      const wrapped = withStandardJsonSchema(schema);

      // Access standard JSON Schema properties
      wrapped['~standard'].jsonSchema.input({ target: 'draft-2020-12' });
      wrapped['~standard'].jsonSchema.output({ target: 'draft-07' });