koumoul-dev / vuetify-jsonschema-form

Create beautiful and low-effort forms that output valid data. Published on npm as @koumoul/vjsf.
https://koumoul-dev.github.io/vuetify-jsonschema-form/latest/
MIT License
538 stars 154 forks source link

Console error in `initFromSchema` #427

Closed mvandenburgh closed 4 months ago

mvandenburgh commented 4 months ago

Given the following JSON Schema -

JSON Schema ``` { "properties": { "Disorder": { "description": "Biolink, SNOMED, or other identifier for disorder studied", "properties": { "id": { "default": null, "description": "Uniform resource identifier", "readOnly": true, "title": "ID", "type": "string" }, "schemaKey": { "const": "Disorder", "default": "Disorder", "title": "Schema Key" }, "identifier": { "default": null, "description": "The identifier can be any url or a compact URI, preferably supported by identifiers.org.", "format": "uri", "maxLength": 1000, "minLength": 1, "nskey": "schema", "title": "Identifier", "type": "string" }, "name": { "default": null, "description": "The name of the item.", "maxLength": 150, "nskey": "schema", "title": "Name", "type": "string" }, "dxdate": { "default": null, "description": "Dates of diagnosis", "items": { "anyOf": [ { "format": "date", "type": "string" }, { "format": "date-time", "type": "string" } ] }, "nskey": "dandi", "rangeIncludes": "schema:Date", "title": "Dates of diagnosis", "type": "array" } }, "required": [ "schemaKey" ], "title": "Disorder", "type": "object" } } } ```

Feeding that schema into the latest version of VJSF (2.23.2 as of this issue filing) results in this console error on rendering:

"[Vue warn]: Error in callback for watcher 'fullSchema': 'TypeError: Cannot read properties of null (reading 'filter')'

Here is a codepen reproducing the error (check the console view): https://codepen.io/mvandenburgh/pen/WNmVWZz

To provide some context regarding this breakage - the JSON Schema we use with VJSF is generated by Pydantic. Previously, we were using a schema generated by Pydantic 1 and it worked with VJSF without any issues. We recently upgraded to Pydantic 2, and VJSF is throwing this error with the new schema generated by it. While the schema outputted by Pydantic has changed some properties, it is still a valid JSON Schema and thus shouldn't cause any console errors in VJSF.

Here's the old, working Pydantic 1 schema for reference:

Pydantic v1 Schema ``` { "properties": { "Disorder": { "title": "Disorder", "description": "Biolink, SNOMED, or other identifier for disorder studied", "type": "object", "properties": { "id": { "title": "ID", "description": "Uniform resource identifier", "readOnly": true, "type": "string" }, "schemaKey": { "title": "Schema Key", "default": "Disorder", "type": "string", "const": "Disorder" }, "identifier": { "title": "Identifier", "description": "The identifier can be any url or a compact URI, preferably supported by identifiers.org.", "nskey": "schema", "type": "string", "minLength": 1, "maxLength": 1000, "format": "uri" }, "name": { "title": "Name", "description": "The name of the item.", "maxLength": 150, "nskey": "schema", "type": "string" }, "dxdate": { "title": "Dates of diagnosis", "description": "Dates of diagnosis", "nskey": "dandi", "rangeIncludes": "schema:Date", "type": "array", "items": { "anyOf": [ { "type": "string", "format": "date" }, { "type": "string", "format": "date-time" } ] } } }, "required": [ "schemaKey" ] } } } ```