Skip to content

Commit e586672

Browse files
TheZokersdirix
andauthored
Add migration guide for version 3.0
Co-authored-by: Stefan Dirix <sdirix@eclipsesource.com>
1 parent 5ccb67e commit e586672

File tree

2 files changed

+107
-16
lines changed

2 files changed

+107
-16
lines changed

MIGRATION.md

Lines changed: 101 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,71 @@
1-
# Migrating to JSON Forms 2.5 for Angular users
2-
The JsonFormsAngularService is not provided in the root anymore.
1+
# Migration guide
2+
3+
## Migrating to JSON Forms 3.0 for React users
4+
5+
With version 3.0 of JSON Forms, we removed the `json-schema-ref-parser` dependency within the core package.
6+
This change only affects users of the React variant, Vue and Angular users are not affected.
7+
8+
`json-schema-ref-parser` was used to resolve external JSON Schema references.
9+
As a side effect it also resolved 'internal' references and therefore simplified the JSON Schema for JSON Forms' processing.
10+
However that resolving was quite slow, the JSON Schema was mutated in place and `json-schema-ref-parser` brought in Node-only dependencies which needed to be polyfilled.
11+
Also all users of JSON Forms React had to pay the resolving effort, whether they needed it or not.
12+
13+
Most React users should be unaffected by this change and don't need to spend any migration efforts.
14+
However when you relied on the resolving of external JSON Schema references via the `refParserOptions` or use complicated references setups which can't yet be handled by JSON Forms' internal processing, you can resolve the JSON Schema before handing it over to JSON Forms.
15+
16+
Note that we're aware of some regressions caused by removing `json-schema-ref-parser` which occur when not handing over a resolved JSON Schema to JSON Forms.
17+
We're working on removing these edge cases during the JSON Forms 3.0 alpha period.
18+
You can always restore the old behavior when following the approach described below.
19+
20+
To restore the old behavior, you can use `json-schema-ref-parser` or other libraries like `json-refs` to resolve references on your own before passing the schema to JSON Forms.
21+
22+
```ts
23+
import React, { useState } from 'react';
24+
import { JsonForms } from '@jsonforms/react';
25+
import { materialCells, materialRenderers } from '@jsonforms/material-renderers';
26+
import $RefParser from '@apidevtools/json-schema-ref-parser';
27+
import JsonRefs from 'json-refs';
28+
29+
import mySchemaWithReferences from 'myschema.json';
30+
31+
const refParserOptions = {
32+
dereference: {
33+
circular: false
34+
}
35+
}
36+
37+
function App() {
38+
const [data, setData] = useState(initialData);
39+
const [resolvedSchema, setSchema] = useState();
40+
41+
useEffect(() => {
42+
$RefParser.dereference(mySchemaWithReferences).then(res => setSchema(res.$schema));
43+
// or
44+
JsonRefs.resolveRefs(mySchemaWithReferences).then(res => setSchema(res.resolved));
45+
},[]);
46+
47+
if(resolvedSchema === undefined) {
48+
return <div> Loading... </div>
49+
}
50+
51+
return (
52+
<JsonForms
53+
schema={resolvedSchema}
54+
uischema={uischema}
55+
data={data}
56+
renderers={materialRenderers}
57+
cells={materialCells}
58+
onChange={({ data, _errors }) => setData(data)}
59+
/>
60+
);
61+
}
62+
```
63+
64+
For more information have a look at our [ref-resolving](https://jsonforms.io/docs/ref-resolving) docs page.
65+
66+
## Migrating to JSON Forms 2.5 for Angular users
67+
68+
The JsonFormsAngularService is not provided in the root anymore.
369
To keep the old behavior, you need to provide it manually in the module.
470

571
The preferred way is using the new JsonForms Component though.
@@ -42,7 +108,7 @@ export class AppComponent {
42108
}
43109
```
44110

45-
# Migrating to JSON Forms 2.5 for React users
111+
## Migrating to JSON Forms 2.5 for React users
46112

47113
In version 2.5 we made the `redux` dependency within the `react` package optional.
48114
Users of the JSON Forms React standalone version (i.e. without Redux) don't need to change anything.
@@ -51,6 +117,7 @@ In contrary you no longer need to install 'redux' and 'react-redux' to use JSON
51117
Users of the JSON Forms Redux variant need to perform some changes.
52118

53119
Basically there are two different approaches:
120+
54121
1. Migrate your app to the standalone variant
55122
2. Keep using the Redux variant of JSON Forms
56123

@@ -60,14 +127,16 @@ In any case, users of the vanilla renderers need to migrate style definitions.
60127
Providing style classes via the redux context is no longer supported even when using the redux fallback.
61128
For more information see the [vanilla renderer style guide](./packages/vanilla/Styles.md).
62129

63-
## Case 1: Migrate to the standalone variant (recommended)
130+
### Case 1: Migrate to the standalone variant (recommended)
64131

65132
The standalone JSON Forms variant is the new default and the main focus for new features and bug fixes.
66133
We definitely recommend migrating to this version as soon as possible.
67134
All current Redux functionally can also be achieved with the standalone version.
68135

69-
### Example 1: Init action
136+
#### Example 1: Init action
137+
70138
Previously the store was initialized like this:
139+
71140
```ts
72141
const store = createStore(
73142
combineReducers({ jsonforms: jsonformsReducer() }),
@@ -89,6 +158,7 @@ return (
89158
```
90159

91160
Instead of creating a store and passing the required information to that store, we rather pass it directly to the `<JsonForms .../>` component:
161+
92162
```ts
93163
return (
94164
<JsonForms
@@ -101,15 +171,18 @@ return (
101171
);
102172
```
103173

104-
### Example 2: Register a custom renderer
174+
#### Example 2: Register a custom renderer
175+
105176
Another commonly used action is the 'register renderer' action.
106177

107178
With Redux this could look like this:
179+
108180
```ts
109181
store.dispatch(Actions.registerRenderer(customControlTester, CustomControl));
110182
```
111183

112184
Within the standalone version, the renderer can just be provided to the `<JsonForms .../>` element like this:
185+
113186
```ts
114187
const renderers = [
115188
...materialRenderers,
@@ -125,7 +198,9 @@ const MyApp = () => (
125198
);
126199

127200
```
128-
### Example 3: Listen to data and validation changes
201+
202+
#### Example 3: Listen to data and validation changes
203+
129204
The `JsonForms` component offers to register a listener which is notified whenever `data` and `errors` changes:
130205

131206
```ts
@@ -141,7 +216,7 @@ const MyApp = () => {
141216
};
142217
```
143218

144-
## Case 2: Use the Redux fallback
219+
### Case 2: Use the Redux fallback
145220

146221
If you want to keep using the Redux variant of JSON Forms for now (which is not recommended), you have to change a few import paths.
147222

@@ -151,22 +226,26 @@ The new imports are available at `@jsonforms/react/lib/redux`, i.e.
151226
import { jsonformsReducer, JsonFormsReduxProvider } from '@jsonforms/react/lib/redux';
152227
```
153228

154-
# Migrating from JSON Forms 1.x (AngularJS 1.x)
229+
## Migrating from JSON Forms 1.x (AngularJS 1.x)
230+
155231
The complexity of the migration of an existing JSON Forms 1.x application, which is based on AngularJS, to JSON Forms 2.x depends on the feature set you use.
156232

157-
## Architectural changes in JSON Forms 2.x
233+
### Architectural changes in JSON Forms 2.x
234+
158235
There are two big changes between JSON Forms 1 and JSON Forms 2 you need to understand when migrating your existing application.
159236

160237
1. JSON Forms 2.x does not rely on any specific UI framework [or library]. The `2.0.0` initial release featured renderers based on [React](https://reactjs.org). An [Angular](https://angular.io) based renderer set was released with `2.1.0`.
161238

162239
2. Since JSON Forms 2.x maintains its internal state via [redux](https://redux.js.org/), you will need to add it as a dependency to your application.
163240

164-
## Steps for upgrading your application to JSON Forms 2.x
241+
### Steps for upgrading your application to JSON Forms 2.x
242+
243+
#### Step 1: Update your UI schemata
165244

166-
### Step 1: Update your UI schemata
167245
There is only one minor change in the UI schemata. The UI Schema for controls was simplified and the bulky `ref` object inside `scope` was removed.
168246

169247
Instead of:
248+
170249
```ts
171250
const uischema = {
172251
type: 'Control',
@@ -175,20 +254,26 @@ const uischema = {
175254
}
176255
}
177256
```
257+
178258
simply write:
259+
179260
```ts
180261
const uischema = {
181262
type: 'Control',
182263
scope: '#/properties/name'
183264
}
184265
```
266+
185267
Otherwise the UI schema remains unchanged and works like in JSON Forms 1.x.
186268

187-
### Step 2: Use JSON Forms 2.x in your application
269+
#### Step 2: Use JSON Forms 2.x in your application
270+
188271
As JSON Forms 2 does not rely on any specific UI framework or library you can choose which renderer set you want to use. The React Material renderer set is the most polished one at the moment, followed by Angular Material and the Vanilla renderer sets.
189272

190-
#### Use with React
191-
Please refer to the React [Tutorial](http://jsonforms.io/docs/tutorial).
273+
##### Use with React
274+
275+
Please refer to the React [tutorial](http://jsonforms.io/docs/tutorial).
276+
277+
#### Step 3: Migrate Custom Renderers
192278

193-
### Step 3: Migrate Custom Renderers
194279
Any custom renderer needs to be re-factored to conform to the new custom renderer style in JSON Forms 2.x. You can find instructions how to implement Custom controls based on React [here](http://jsonforms.io/docs/custom-renderers). While you need to change a lot except for the template, the good news it that writing custom renderers became much simpler in JSON Forms 2 since the framework will trigger rendering and re-rendering in case of changes to the data or other state. In many cases this means you will be able to streamline your code for custom renderers significantly.

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ Please see the official JSON Forms website, [jsonforms.io](https://jsonforms.io)
1515
For more info about the seed app, please see the corresponding README file of the [seed repo](https://github.com/eclipsesource/jsonforms-react-seed).
1616
For a more detailed tutorial about the usage of JSON Forms, please see [this tutorial](http://jsonforms.io/docs/tutorial).
1717

18+
## Upgrading to JSON Forms 3.0 Alpha
19+
20+
With version 3.0 of JSON Forms we removed `json-schema-ref-parser` from the core package.
21+
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.
22+
To avoid issues and for more information, please have a look at our [migration guide](https://github.com/eclipsesource/jsonforms/blob/master/MIGRATION.md).
23+
1824
## Feedback, Help and Support
1925

2026
If you encounter any problems feel free to [open an issue](https://github.com/eclipsesource/jsonforms/issues/new/choose) on the repo.

0 commit comments

Comments
 (0)