Socket
Socket
Sign inDemoInstall

@rjsf/validator-ajv8

Package Overview
Dependencies
4
Maintainers
2
Versions
64
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @rjsf/validator-ajv8

The ajv-8 based validator for @rjsf/core


Version published
Weekly downloads
198K
increased by4.49%
Maintainers
2
Created
Weekly downloads
 

Changelog

Source

5.6.0

@rjsf/antd

  • Treat multiple as a boolean rather than comparing against undefined in the SelectWidget, fixing #3595

@rjsf/core

  • Switched Form to use the new validatorDataMerge() and toErrorList() functions instead of the now deprecated schemaUtils.mergeValidatorData() and schemaUtils.getValidator().toErrorList()
  • Added option to provide a callback function to focusOnFirstError (3590)
  • Updated MultiSchemaField to handle the OpenAPI discriminator extension on anyOf/oneOf fields by passing it into getClosestMatchingOption() if it exists, fixing #3512
  • Updated SchemaField function to use getSchemaType rather than schema.type to set the proper class name.

@rjsf/utils

  • Refactored the createErrorHandler(), toErrorList(), toErrorSchema() and unwrapErrorHandler() functions from the @rjsf/validator-ajv6 and @rjsf/validator-ajv8 implementations since they were identical
    • As a result, the mergeValidationData() function was deprecated in favor of the new validationDataMerge() function that uses the refactored toErrorList() function
    • Refactored the ROOT_SCHEMA_PREFIX constant as well
  • Updated ValidatorType and SchemaUtilsType to deprecate the toErrorList() and mergeValidationData() functions, respectively
  • Updated the getClosestMatchingOption() and getFirstMatchingOption() to pass the new discriminatorField to the getMatchingOption() function
  • Updated getMatchingOption() to use discriminatorField when it is present in the options object properties to drill into the object to detect if that one field is valid
  • Updated SchemaUtilsType and the associated forward functions in createSchemaUtils to add the new discriminatorField?: string optional parameter
  • Updated toIdSchema() function to use getSchemaType(schema) === 'object' rather than schema.type === 'object' to get the proper pathing for ids, fixing #2044

@rjsf/validator-ajv6

  • Removed the refactored functions and constant from the AJV6Validator in favor of using the new functions and constant from @rjsf/utils

@rjsf/validator-ajv8

  • Removed the refactored functions and constant from the AJV8Validator in favor of using the new functions and constant from @rjsf/utils

Dev / docs / playground

  • Updated the utility-functions documentation to describe the new refactored functions as well as deprecating the mergeValidationData() function
  • Updated the playground to properly restore liveSettings from shared links and added a switch for noHtml5Validation in the live settings rather than having it set to true always
    • Also added a new Blank example to help users easily paste their code

Readme

Source

Build Status npm npm downloads Contributors Apache 2.0 License


Logo

@rjsf/validator-ajv8

AJV-8 based validator plugin for react-jsonschema-form.
Explore the docs »

View Playground · Report Bug · Request Feature

Table of Contents

About The Project

Exports validator-ajv8 plugin for react-jsonschema-form.

Built With

Getting Started

Prerequisites

React JsonSchema Form Utils
  • @rjsf/utils >= 5.0.0
yarn add @rjsf/core

Installation

yarn add @rjsf/validator-ajv8

Usage

import { RJSFSchema } from 'packages/utils/dist/index';
import Form from 'packages/core/dist/index';
import validator from '@rjsf/validator-ajv8';

const schema: RJSFSchema = {
  type: 'string',
};

<Form schema={schema} validator={validator} />;

or, using a more complex example using custom validator with custom formats

import { RJSFSchema } from '@rjsf/utils';
import Form from '@rjsf/core';
import { customizeValidator } from '@rjsf/validator-ajv8';

const customFormats = {
  'phone-us': /\(?\d{3}\)?[\s-]?\d{3}[\s-]?\d{4}$/,
};

const validator = customizeValidator({
  customFormats,
});

const schema: RJSFSchema = {
  type: 'string',
  format: 'phone-us',
};

<Form schema={schema} validator={validator} />;

or, using a more complex example using a custom with additional meta schema

import { RJSFSchema } from '@rjsf/utils';
import Form from '@rjsf/core';
import { customizeValidator } from '@rjsf/validator-ajv8';

const metaSchemaDraft06 = require('ajv/lib/refs/json-schema-draft-06.json');

const validator = customizeValidator({
  additionalMetaSchemas: [metaSchemaDraft06],
});

const schema: RJSFSchema = {
  $schema: 'http://json-schema.org/draft-06/schema#',
  type: 'string',
};

<Form schema={schema} validator={validator} />;

or, using a more complex example using custom validator config override options

import { RJSFSchema } from '@rjsf/utils';
import Form from '@rjsf/core';
import { customizeValidator } from '@rjsf/validator-ajv8';

const validator = customizeValidator({
  ajvOptionsOverrides: {
    $data: true,
    verbose: true,
  },
});

const schema: RJSFSchema = {
  type: 'string',
};

<Form schema={schema} validator={validator} />;

or, using a more complex example using ajv-formats custom format options.

import { RJSFSchema } from '@rjsf/utils';
import Form from '@rjsf/core';
import { customizeValidator } from '@rjsf/validator-ajv8';

const validator = customizeValidator({
  ajvFormatOptions: {
    keywords: true,
    formats: ['date', 'time'],
  },
});

const schema: RJSFSchema = {
  type: 'string',
};

<Form schema={schema} validator={validator} />;

Finally, you can combine both additional meta schemas, custom formats, custom validator config override options and ajv-formats custom format options.

import { RJSFSchema } from '@rjsf/utils';
import Form from '@rjsf/core';
import { customizeValidator } from '@rjsf/validator-ajv8';

const metaSchemaDraft06 = require('ajv/lib/refs/json-schema-draft-06.json');

const customFormats = {
  'phone-us': /\(?\d{3}\)?[\s-]?\d{3}[\s-]?\d{4}$/,
};

const validator = customizeValidator({
  additionalMetaSchemas: [metaSchemaDraft06],
  customFormats,
  ajvOptionsOverrides: {
    $data: true,
    verbose: true,
  },
  ajvFormatOptions: {
    keywords: true,
    formats: ['date', 'time'],
  },
});

const schema: RJSFSchema = {
  $schema: 'http://json-schema.org/draft-06/schema#',
  type: 'string',
  format: 'phone-us',
};

<Form schema={schema} validator={validator} />;

Roadmap

See the open issues for a list of proposed features (and known issues).

Contributing

Read our contributors' guide to get started.

Contact

rjsf team: https://github.com/orgs/rjsf-team/people

GitHub repository: https://github.com/rjsf-team/react-jsonschema-form

Keywords

FAQs

Last updated on 13 Apr 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc