fastify / fluent-json-schema

A fluent API to generate JSON schemas
MIT License
495 stars 58 forks source link

Add Support for custom format input #250

Open shivamkj opened 3 months ago

shivamkj commented 3 months ago

Prerequisites

🚀 Feature Proposal

Currently, if I call S.string().format('myformat'), it throws following error:

throw new FluentSchemaError(
FluentSchemaError: 'format' must be one of relative-json-pointer, json-pointer, uuid, regex, ipv6, ipv4, hostname, email, url, uri-template, uri-reference, uri, time, date, date-time

This makes it difficult to use any custom format with this library. We should provide option to customize this behavior to support custom formats.

Motivation

I am using ajv for validation, ajv supports adding custom user defined format - Format validation, which takes validate function in which one write any js code to validate the input. Now since this library only takes well defined formats, it's difficult to use this library with ajv.

Example

S.string().format('myformat')