Skip to content

retrieveSchema() throws for schema with JSON pointers #4529

@caillou

Description

@caillou

Prerequisites

What theme are you using?

core

Version

5.24.7

Current Behavior

The following code throws an error:

import { getDefaultFormState, RJSFSchema } from '@rjsf/utils';
import validator from '@rjsf/validator-ajv8';

const schema: RJSFSchema = {
  definitions: {
    address: {
      type: 'object',
      properties: {
        street_address: { type: 'string' },
        city: { type: 'string' },
        state: { type: 'string' },
      },
      required: ['street_address', 'city', 'state'],
    },
  },
  type: 'object',
  properties: {
    billing_address: { $ref: '#/definitions/address' },
    shipping_address: { $ref: '#/definitions/address' },
  },
};

try {
  getDefaultFormState(validator, schema, {});
} catch (e) {
  console.log('Error calling retrieveSchema:', e);
}

This is the error thrown:

Error: Could not find a definition for #/definitions/address.
    at findSchemaDefinitionRecursive (chunk-IEJR3CZA.js?v=69f3d9b8:8602:11)
    at findSchemaDefinition (chunk-IEJR3CZA.js?v=69f3d9b8:8625:10)
    at resolveAllReferences (chunk-IEJR3CZA.js?v=69f3d9b8:9545:23)
    at chunk-IEJR3CZA.js?v=69f3d9b8:9552:21
    at chunk-IEJR3CZA.js?v=69f3d9b8:9108:12
    at chunk-IEJR3CZA.js?v=69f3d9b8:8694:11
    at baseForOwn (chunk-IEJR3CZA.js?v=69f3d9b8:8709:20)
    at transform (chunk-IEJR3CZA.js?v=69f3d9b8:9107:55)
    at resolveAllReferences (chunk-IEJR3CZA.js?v=69f3d9b8:9550:26)
    at resolveReference (chunk-IEJR3CZA.js?v=69f3d9b8:9528:25)

Expected Behavior

getDefaultFormState() should return the default form data.

Steps To Reproduce

  1. Visit https://stackblitz.com/edit/vitejs-vite-mw8zql5w?file=src%2Fmain.ts&terminal=dev
  2. Open developer tools to see the logged error.

Environment

- OS: MacOS
- Node: v20.13.1
- npm: 10.5.2

Anything else?

  • The same error is thrown when calling retrieveSchema(validator, schema);
  • Using this schema directly with a @rjsf/core Form does not throw.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions