-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Bug: AJV $data reference in const property in schema treated as default/const value. #4431
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
fbb53e9
Validator to support AJV $data reference and saving validator state i…
abdalla-rko 54ed4ed
Fix for AJV $data reference in const property in schema treated as de…
abdalla-rko efe76cf
written a test for consIsAjvDataReference.
abdalla-rko 84846ba
Merge branch 'main' into ajv-data-reference
abdalla-rko 253ed95
Merge branch 'main' into ajv-data-reference
abdalla-rko fcdd22f
Merge remote-tracking branch 'origin/main' into ajv-data-reference
abdalla-rko 94f09c6
Update CHANGELOG.md
heath-freenome File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -227,6 +227,49 @@ describe('ObjectField', () => { | |
}); | ||
}); | ||
|
||
it('should validate AJV $data reference ', () => { | ||
const schema = { | ||
type: 'object', | ||
properties: { | ||
email: { | ||
type: 'string', | ||
title: 'E-mail', | ||
format: 'email', | ||
}, | ||
emailConfirm: { | ||
type: 'string', | ||
const: { | ||
$data: '/email', | ||
}, | ||
title: 'Confirm e-mail', | ||
format: 'email', | ||
}, | ||
}, | ||
}; | ||
const { node, rerender } = createFormComponent({ | ||
schema, | ||
formData: { | ||
email: '[email protected]', | ||
emailConfirm: '[email protected]', | ||
}, | ||
liveValidate: true, | ||
}); | ||
|
||
const errorMessages = node.querySelectorAll('#root_emailConfirm__error'); | ||
expect(errorMessages).to.have.length(1); | ||
|
||
rerender({ | ||
schema, | ||
formData: { | ||
email: '[email protected]', | ||
emailConfirm: '[email protected]', | ||
}, | ||
liveValidate: true, | ||
}); | ||
|
||
expect(node.querySelectorAll('#root_foo__error')).to.have.length(0); | ||
}); | ||
|
||
it('Check that when formData changes, the form should re-validate', () => { | ||
const { node, rerender } = createFormComponent({ | ||
schema, | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
import { FormProps } from '@rjsf/core'; | ||
|
||
export type Sample = Omit<FormProps, 'validator'>; | ||
export interface Sample extends Omit<FormProps, 'validator'> { | ||
validator: string; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { CONST_KEY, getSchemaType, isObject } from './'; | ||
import { RJSFSchema, StrictRJSFSchema } from './types'; | ||
import { JSONSchema7Type } from 'json-schema'; | ||
import isString from 'lodash/isString'; | ||
|
||
/** | ||
* Checks if the schema const property value is an AJV $data reference | ||
* and the current schema is not an object or array | ||
* | ||
* @param schema - The schema to check if the const is an AJV $data reference | ||
* @returns - true if the schema const property value is an AJV $data reference otherwise false. | ||
*/ | ||
export default function constIsAjvDataReference<S extends StrictRJSFSchema = RJSFSchema>(schema: S): boolean { | ||
const schemaConst = schema[CONST_KEY] as JSONSchema7Type & { $data: string }; | ||
const schemaType = getSchemaType<S>(schema); | ||
return isObject(schemaConst) && isString(schemaConst?.$data) && schemaType !== 'object' && schemaType !== 'array'; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.