Skip to content

Commit 71391dd

Browse files
- Responded to self-review feedback
1 parent d71d435 commit 71391dd

6 files changed

+75
-760
lines changed

packages/validator-ajv8/src/compileSchemaValidators.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,12 @@ export default function compileSchemaValidators<S extends StrictRJSFSchema = RJS
2626
const schemas = Object.values(schemaMaps);
2727

2828
const { additionalMetaSchemas, customFormats, ajvOptionsOverrides = {}, ajvFormatOptions, AjvClass } = options;
29-
const compileOptions = { ...ajvOptionsOverrides, code: { source: true, lines: true }, schemas };
29+
// Allow users to turn off the `lines: true` feature in their own overrides, but NOT the `source: true`
30+
const compileOptions = {
31+
...ajvOptionsOverrides,
32+
code: { lines: true, ...ajvOptionsOverrides.code, source: true },
33+
schemas,
34+
};
3035
const ajv = createAjvInstance(additionalMetaSchemas, customFormats, compileOptions, ajvFormatOptions, AjvClass);
3136

3237
const moduleCode = standaloneCode(ajv);

packages/validator-ajv8/src/precompiledValidator.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ export default class AJV8PrecompiledValidator<
100100
* @throws - Error when the schema provided does not match the base schema of the precompiled validator
101101
*/
102102
rawValidation<Result = any>(schema: S, formData?: T): RawValidationErrorsType<Result> {
103-
const validationError: Error | undefined = undefined;
104103
if (!isEqual(schema, this.rootSchema)) {
105104
throw new Error(
106105
'The schema associated with the precompiled schema differs from the schema provided for validation'
@@ -116,10 +115,7 @@ export default class AJV8PrecompiledValidator<
116115
// Clear errors to prevent persistent errors, see #1104
117116
this.mainValidator.errors = null;
118117

119-
return {
120-
errors: errors as unknown as Result[],
121-
validationError,
122-
};
118+
return { errors: errors as unknown as Result[] };
123119
}
124120

125121
/** This function processes the `formData` with an optional user contributed `customValidate` function, which receives

packages/validator-ajv8/test/compileSchemaValidators.test.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,10 @@ describe('compileSchemaValidators()', () => {
5959
beforeAll(() => {
6060
schemas = Object.values(schemaParser(superSchema as RJSFSchema));
6161
expectedCode = readFileSync('./test/harness/superSchemaOptions.js').toString();
62-
compileSchemaValidators(superSchema as RJSFSchema, OUTPUT_FILE, CUSTOM_OPTIONS);
62+
compileSchemaValidators(superSchema as RJSFSchema, OUTPUT_FILE, {
63+
...CUSTOM_OPTIONS,
64+
ajvOptionsOverrides: { ...CUSTOM_OPTIONS.ajvOptionsOverrides, code: { lines: false } },
65+
});
6366
});
6467
afterAll(() => {
6568
consoleLogSpy.mockClear();
@@ -82,7 +85,7 @@ describe('compileSchemaValidators()', () => {
8285
ajvFormatOptions,
8386
AjvClass,
8487
} = CUSTOM_OPTIONS;
85-
const expectedCompileOpts = { ...ajvOptionsOverrides, code: { source: true, lines: true }, schemas };
88+
const expectedCompileOpts = { ...ajvOptionsOverrides, code: { source: true, lines: false }, schemas };
8689
expect(createAjvInstance).toHaveBeenCalledWith(
8790
additionalMetaSchemas,
8891
customFormats,

packages/validator-ajv8/test/harness/compileTestSchema.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@ const superSchema = require('./superSchema.json');
1616
const options = {
1717
additionalMetaSchemas: [require('ajv/lib/refs/json-schema-draft-06.json')],
1818
customFormats: { 'phone-us': /\(?\d{3}\)?[\s-]?\d{3}[\s-]?\d{4}$/, 'area-code': /\d{3}/ },
19-
ajvOptionsOverrides: {
20-
$data: true,
21-
verbose: true,
22-
},
19+
ajvOptionsOverrides: { $data: true, verbose: true, code: { lines: false } },
2320
ajvFormatOptions: {
2421
mode: 'fast',
2522
},

0 commit comments

Comments
 (0)