UNPKG

@rjsf/utils

Version:
26 lines 1.46 kB
import isEqual from 'lodash-es/isEqual.js'; import omit from 'lodash-es/omit.js'; import { REF_KEY, RJSF_REF_KEY } from './constants.js'; /** Helper to check whether a JSON schema object is the root schema. The schema is a root schema with root `properties` * key or a root `$ref` key. If the `schemaToCompare` has a root `oneOf` property, the function will * return false. Else if `schemaToCompare` and `rootSchema` are the same object or equal, the function will return * `true`. Else if the `rootSchema` has a $ref, it will be resolved using `schemaUtils.resolveSchema` utility. If the * resolved schema matches the `schemaToCompare` the function will return `true`. Otherwise, it will return false. * * @param registry - The `Registry` used to get the `rootSchema` and `schemaUtils` * @param schemaToCompare - The JSON schema object to check. If `schemaToCompare` is an root schema, the * function will return true. * @returns - Flag indicating whether the `schemaToCompare` is the root schema */ export default function isRootSchema(registry, schemaToCompare) { const { rootSchema, schemaUtils } = registry; if (isEqual(schemaToCompare, rootSchema)) { return true; } if (REF_KEY in rootSchema) { const resolvedSchema = schemaUtils.retrieveSchema(rootSchema); return isEqual(schemaToCompare, omit(resolvedSchema, RJSF_REF_KEY)); } return false; } //# sourceMappingURL=isRootSchema.js.map