Skip to content

Commit 3a9c01f

Browse files
authored
docs: document JSON Schema deprecated support and UI options (#5061)
* docs: document JSON Schema deprecated support and UI options * docs: move deprecated keyword to json-schema docs and refine uiSchema formatting * docs: add note about JSON Schema Draft 2019-09 for deprecated keyword
1 parent 1772f68 commit 3a9c01f

2 files changed

Lines changed: 73 additions & 0 deletions

File tree

packages/docs/docs/api-reference/uiSchema.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,59 @@ const uiSchema: UiSchema = {
333333
};
334334
```
335335

336+
### deprecatedHandling
337+
338+
The `ui:deprecatedHandling` uiSchema directive controls how a field marked as `deprecated` in the JSON Schema is rendered.
339+
340+
Accepts one of three values:
341+
342+
- `'label'` (default): The field is rendered normally with `"(deprecated)"` appended to its label.
343+
- `'disable'`: The field is rendered but all its child widgets are disabled.
344+
- `'hide'`: The field is completely hidden from the form.
345+
346+
```tsx
347+
import { RJSFSchema, UiSchema } from '@rjsf/utils';
348+
349+
const schema: RJSFSchema = {
350+
type: 'object',
351+
properties: {
352+
legacyField: { type: 'string', deprecated: true },
353+
},
354+
};
355+
356+
const uiSchema: UiSchema = {
357+
legacyField: {
358+
'ui:options': {
359+
deprecatedHandling: 'disable',
360+
},
361+
},
362+
};
363+
```
364+
365+
It can also be set globally by specifying the `deprecatedHandling` option in the `ui:globalOptions` uiSchema directive, which applies the chosen behavior to every deprecated field in the form.
366+
367+
```tsx
368+
import { Form } from '@rjsf/core';
369+
import { RJSFSchema, UiSchema } from '@rjsf/utils';
370+
import validator from '@rjsf/validator-ajv8';
371+
372+
const schema: RJSFSchema = {
373+
type: 'object',
374+
properties: {
375+
legacyField: { type: 'string', deprecated: true },
376+
anotherOldField: { type: 'number', deprecated: true },
377+
},
378+
};
379+
380+
const uiSchema: UiSchema = {
381+
'ui:globalOptions': {
382+
deprecatedHandling: 'hide',
383+
},
384+
};
385+
386+
render(<Form schema={schema} uiSchema={uiSchema} validator={validator} />, document.getElementById('app'));
387+
```
388+
336389
### disabled
337390

338391
The `ui:disabled` uiSchema directive will disable all child widgets from a given field.

packages/docs/docs/json-schema/single.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,26 @@ const schema: RJSFSchema = {
4444
render(<Form schema={schema} validator={validator} />, document.getElementById('app'));
4545
```
4646

47+
## Deprecated fields
48+
49+
The JSON Schema `deprecated` keyword can be used to indicate that a field is no longer supported.
50+
51+
The `deprecated` keyword is a JSON Schema Draft 2019-09 feature. You may need to configure your schema validator to properly recognize it. See the [Validation](../usage/validation.md#ajvclass) documentation for more details.
52+
53+
```tsx
54+
import { RJSFSchema } from '@rjsf/utils';
55+
import validator from '@rjsf/validator-ajv8';
56+
57+
const schema: RJSFSchema = {
58+
type: 'string',
59+
deprecated: true,
60+
};
61+
62+
render(<Form schema={schema} validator={validator} />, document.getElementById('app'));
63+
```
64+
65+
By default, RJSF will append ` (deprecated)` to the field label. You can customize this behavior using the `deprecatedHandling` option in the uiSchema. See [deprecatedHandling](../api-reference/uiSchema.md#deprecatedhandling) for more details.
66+
4767
## Enumerated values
4868

4969
All base schema types support the `enum` attribute, which restricts the user to select among a list of options. For example:

0 commit comments

Comments
 (0)