|
| 1 | +# Migrating to JSON Forms 3.0 for React users |
| 2 | + |
| 3 | +With version 3.0 of JSON Forms, we removed the `json-schema-ref-parser` dependency within the core package. |
| 4 | +This change only affects users of the React variant (Vue and Angular are not affected) and even for React only a few users will need to adjust their code. |
| 5 | +Problematic cases are mostly complex `$ref` setups, often in combination with `anyOf`, `allOf` or `oneOf`. |
| 6 | +To restore the previous behavior, you can use `json-schema-ref-parser` or `json-refs` to resolve references on your own before passing the schema to JSON Forms. |
| 7 | +Here is an example, how to use these libraries to resolve your refs before handing the schema to JSON Forms: |
| 8 | + |
| 9 | +```ts |
| 10 | +import React, { useState } from 'react'; |
| 11 | +import { JsonForms } from '@jsonforms/react'; |
| 12 | +import { materialCells, materialRenderers } from '@jsonforms/material-renderers'; |
| 13 | +import $RefParser from '@apidevtools/json-schema-ref-parser'; |
| 14 | +import JsonRefs from 'JsonRefs'; |
| 15 | + |
| 16 | +const schema = { |
| 17 | + $defs: { |
| 18 | + Base: { |
| 19 | + type: 'object', |
| 20 | + properties: { |
| 21 | + width: { |
| 22 | + type: 'integer' |
| 23 | + } |
| 24 | + } |
| 25 | + }, |
| 26 | + Child: { |
| 27 | + type: 'object', |
| 28 | + allOf: [ |
| 29 | + { $ref: '#/$defs/Base' }, |
| 30 | + { |
| 31 | + properties: { |
| 32 | + geometry: { |
| 33 | + type: 'string' |
| 34 | + } |
| 35 | + } |
| 36 | + } |
| 37 | + ] |
| 38 | + } |
| 39 | + }, |
| 40 | + type: 'object', |
| 41 | + properties: { |
| 42 | + element: { |
| 43 | + $ref: '#/$defs/Child' |
| 44 | + } |
| 45 | + } |
| 46 | +}; |
| 47 | + |
| 48 | +const resolvedSchema = $RefParser.dereference(schema) |
| 49 | +// or |
| 50 | +const resolvedSchema = JsonRefs.resolveRefs(schema) |
| 51 | + |
| 52 | +function App() { |
| 53 | + const [data, setData] = useState(initialData); |
| 54 | + |
| 55 | + return ( |
| 56 | + <JsonForms |
| 57 | + schema={resolvedSchema} |
| 58 | + uischema={uischema} |
| 59 | + data={data} |
| 60 | + renderers={materialRenderers} |
| 61 | + cells={materialCells} |
| 62 | + onChange={({ data, _errors }) => setData(data)} |
| 63 | + /> |
| 64 | + ); |
| 65 | +} |
| 66 | +``` |
| 67 | + |
| 68 | +For more information have a look at our [ref-resolving](https://jsonforms.io/docs/ref-resolving) docs page. |
| 69 | + |
1 | 70 | # Migrating to JSON Forms 2.5 for Angular users
|
2 | 71 | The JsonFormsAngularService is not provided in the root anymore.
|
3 | 72 | To keep the old behavior, you need to provide it manually in the module.
|
|
0 commit comments