Skip to content

Commit

Permalink
Merge branch 'main' into add-v6-to-ci
Browse files Browse the repository at this point in the history
  • Loading branch information
heath-freenome authored Dec 8, 2023
2 parents aa71815 + 2061ce6 commit d48f16f
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 17 deletions.
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,24 @@ it according to semantic versioning. For example, if your PR adds a breaking cha
should change the heading of the (upcoming) version to include a major version bump.
-->
# 5.15.1

## @rjsf/core

- fix `getFieldNames`. Now correctly defines an array of primitives.

## @rjsf/validator-ajv6

- Updated the `AJV6Validator` class to expose the internal `ajv` object, allowing access to support a fix related to [#3972](https://github.com/rjsf-team/react-jsonschema-form/issues/3972)

## @rjsf/validator-ajv8

- Updated the `AJV8Validator` class to expose the internal `ajv` object, allowing access to support a fix related to [#3972](https://github.com/rjsf-team/react-jsonschema-form/issues/3972)

## Dev / docs / playground

- Updated the documentation to describe how to use the newly exposed `ajv` variable

# 5.15.0

## @rjsf/mui
Expand Down
6 changes: 5 additions & 1 deletion packages/core/src/components/Form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,11 @@ export default class Form<
const formValue = _get(formData, path);
// adds path to fieldNames if it points to a value
// or an empty object/array
if (typeof formValue !== 'object' || _isEmpty(formValue)) {
if (
typeof formValue !== 'object' ||
_isEmpty(formValue) ||
(Array.isArray(formValue) && formValue.every((val) => typeof val !== 'object'))
) {
acc.push(path);
}
});
Expand Down
5 changes: 5 additions & 0 deletions packages/core/test/Form.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3463,6 +3463,7 @@ describe('Form omitExtraData and liveOmit', () => {
extra: 'asdf',
anotherThingNested2: 0,
},
stringArray: ['scobochka'],
},
level1a: 1.23,
};
Expand All @@ -3488,6 +3489,9 @@ describe('Form omitExtraData and liveOmit', () => {
$name: 'level1.anotherThing.anotherThingNested2',
},
},
stringArray: {
$name: 'level1.stringArray',
},
},
level1a: {
$name: 'level1a',
Expand All @@ -3500,6 +3504,7 @@ describe('Form omitExtraData and liveOmit', () => {
['level1', 'anotherThing', 'anotherThingNested'],
['level1', 'anotherThing', 'anotherThingNested2'],
['level1', 'level2'],
['level1', 'stringArray'],
['level1a'],
].sort()
);
Expand Down
2 changes: 1 addition & 1 deletion packages/docs/docs/api-reference/validator-ajv8.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ If a `localizer` is provided, it is used to translate the messages generated by

#### Returns

- ValidatorType&lt;T, S, F>: The custom validator implementation resulting from the set of parameters provided
- AJV8Validator&lt;T, S, F>: The custom validator implementation resulting from the set of parameters provided

### compileSchemaValidators&lt;S extends StrictRJSFSchema = RJSFSchema>()

Expand Down
15 changes: 15 additions & 0 deletions packages/docs/docs/usage/validation.md
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,21 @@ const validator = customizeValidator({ ajvOptionsOverrides });
render(<Form schema={schema} validator={validator} />, document.getElementById('app'));
```

## Using the raw Ajv instance

The `customizeValidator()` function returns the `AJV8Validator` (or `AJV6Validator` depending on the library you use) implementation class, which has an internal raw `ajv` instance within it.
If you need to do some deep customization of the instance using any of the `ajv` libraries (like `ajv-keywords`), you can do so using this raw instance as follows:

```ts
import { customizeValidator } from '@rjsf/validator-ajv6';
import ajvKeywords from 'ajv-keywords';

const validator = customizeValidator();
ajvKeywords(validator.ajv, ['your-keyword']);

// use your update validator with a `Form`
```

## Ajv8 validator differences

There are a few differences in configuring the Ajv 8 validator.
Expand Down
4 changes: 2 additions & 2 deletions packages/validator-ajv6/src/customizeValidator.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FormContextType, RJSFSchema, StrictRJSFSchema, ValidatorType } from '@rjsf/utils';
import { FormContextType, RJSFSchema, StrictRJSFSchema } from '@rjsf/utils';

import { CustomValidatorOptionsType } from './types';
import AJV6Validator from './validator';
Expand All @@ -13,6 +13,6 @@ export default function customizeValidator<
T = any,
S extends StrictRJSFSchema = RJSFSchema,
F extends FormContextType = any
>(options: CustomValidatorOptionsType = {}): ValidatorType<T, S, F> {
>(options: CustomValidatorOptionsType = {}) {
return new AJV6Validator<T, S, F>(options);
}
4 changes: 1 addition & 3 deletions packages/validator-ajv6/src/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,8 @@ export default class AJV6Validator<T = any, S extends StrictRJSFSchema = RJSFSch
implements ValidatorType<T, S, F>
{
/** The AJV instance to use for all validations
*
* @private
*/
private ajv: Ajv;
ajv: Ajv;

/** Constructs an `AJV6Validator` instance using the `options`
*
Expand Down
4 changes: 2 additions & 2 deletions packages/validator-ajv8/src/customizeValidator.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FormContextType, RJSFSchema, StrictRJSFSchema, ValidatorType } from '@rjsf/utils';
import { FormContextType, RJSFSchema, StrictRJSFSchema } from '@rjsf/utils';

import { CustomValidatorOptionsType, Localizer } from './types';
import AJV8Validator from './validator';
Expand All @@ -15,6 +15,6 @@ export default function customizeValidator<
T = any,
S extends StrictRJSFSchema = RJSFSchema,
F extends FormContextType = any
>(options: CustomValidatorOptionsType = {}, localizer?: Localizer): ValidatorType<T, S, F> {
>(options: CustomValidatorOptionsType = {}, localizer?: Localizer) {
return new AJV8Validator<T, S, F>(options, localizer);
}
2 changes: 1 addition & 1 deletion packages/validator-ajv8/src/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default class AJV8Validator<T = any, S extends StrictRJSFSchema = RJSFSch
*
* @private
*/
private ajv: Ajv;
ajv: Ajv;

/** The Localizer function to use for localizing Ajv errors
*
Expand Down
7 changes: 0 additions & 7 deletions packages/validator-ajv8/test/validator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ describe('AJV8Validator', () => {
name: 'John Doe',
};

// @ts-expect-error - accessing private Ajv instance to verify compilation happens once
const addSchemaSpy = jest.spyOn(validator.ajv, 'addSchema');

// Call isValid twice with the same schema
Expand Down Expand Up @@ -123,7 +122,6 @@ describe('AJV8Validator', () => {
name: 'John Doe',
};

// @ts-expect-error - accessing private Ajv instance to verify compilation happens once
const ajvInstance = validator.ajv;
const originalGetSchema = ajvInstance.getSchema.bind(ajvInstance);
const getSchemaSpy = jest.spyOn(ajvInstance, 'getSchema');
Expand Down Expand Up @@ -345,7 +343,6 @@ describe('AJV8Validator', () => {
},
};

// @ts-expect-error - accessing private Ajv instance to verify compilation happens once
const compileSpy = jest.spyOn(validator.ajv, 'compile');
compileSpy.mockClear();

Expand Down Expand Up @@ -589,7 +586,6 @@ describe('AJV8Validator', () => {
name: 'John Doe',
};

// @ts-expect-error - accessing private Ajv instance to verify compilation happens once
const addSchemaSpy = jest.spyOn(validator.ajv, 'addSchema');
addSchemaSpy.mockClear();

Expand Down Expand Up @@ -803,7 +799,6 @@ describe('AJV8Validator', () => {
},
};

// @ts-expect-error - accessing private Ajv instance to verify compilation happens once
const compileSpy = jest.spyOn(validator.ajv, 'compile');
compileSpy.mockClear();

Expand Down Expand Up @@ -1047,7 +1042,6 @@ describe('AJV8Validator', () => {
name: 'John Doe',
};

// @ts-expect-error - accessing private Ajv instance to verify compilation happens once
const addSchemaSpy = jest.spyOn(validator.ajv, 'addSchema');
addSchemaSpy.mockClear();

Expand Down Expand Up @@ -1449,7 +1443,6 @@ describe('AJV8Validator', () => {
},
};

// @ts-expect-error - accessing private Ajv instance to verify compilation happens once
const compileSpy = jest.spyOn(validator.ajv, 'compile');
compileSpy.mockClear();

Expand Down

0 comments on commit d48f16f

Please sign in to comment.