Skip to content

Commit 58bc79d

Browse files
authored
Try fix object types comfort feature to not cause issues with other s… (#853)
* Try fix object types comfort feature to not cause issues with other schema features and enable it by default * apply formatting changes --------- Co-authored-by: Logende <[email protected]>
1 parent 98160e1 commit 58bc79d

3 files changed

Lines changed: 76 additions & 15 deletions

File tree

meta_configurator/src/schema/metaSchemaBuilder.ts

Lines changed: 74 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -63,18 +63,8 @@ export function buildMetaSchema(metaSchemaSettings: SettingsInterfaceMetaSchema)
6363

6464
if (metaSchemaSettings.objectTypesComfort) {
6565
metaSchema.$defs.enumProperty.allOf = ALL_OF_ENUM_PROPERTY;
66+
metaSchema.$defs.constProperty.allOf = ALL_OF_CONST_PROPERTY;
6667
metaSchema.$defs['meta-data'].allOf = ALL_OF_META_DATA;
67-
68-
// delete properties that are not compatible with this option
69-
delete metaSchema.$defs.schemaComposition.properties.not;
70-
metaSchema.$defs.conditionalSchema = {};
71-
delete metaSchema.$defs.objectProperty.properties.additionalProperties;
72-
delete metaSchema.$defs.objectProperty.properties.propertyNames;
73-
delete metaSchema.$defs.objectProperty.properties.dependentRequired;
74-
delete metaSchema.$defs.objectProperty.properties.dependentSchemas;
75-
delete metaSchema.$defs.objectProperty.properties.unevaluatedProperties;
76-
delete metaSchema.$defs.arrayProperty.properties.unevaluatedItems;
77-
delete metaSchema.$defs.arrayProperty.properties.items;
7868
}
7969

8070
if (metaSchemaSettings.showJsonLdFields) {
@@ -124,6 +114,79 @@ const DEF_TYPE_DEFINITION_WITHOUT_MULTIPLE_TYPES = {
124114
};
125115

126116
const ALL_OF_ENUM_PROPERTY = [
117+
{
118+
if: {
119+
$ref: '#/$defs/hasTypeArray',
120+
},
121+
then: {
122+
properties: {
123+
enum: {
124+
items: {
125+
type: 'array',
126+
},
127+
},
128+
},
129+
},
130+
},
131+
{
132+
if: {
133+
$ref: '#/$defs/hasTypeObject',
134+
},
135+
then: {
136+
properties: {
137+
enum: {
138+
items: {
139+
type: 'object',
140+
},
141+
},
142+
},
143+
},
144+
},
145+
{
146+
if: {
147+
$ref: '#/$defs/hasTypeString',
148+
},
149+
then: {
150+
properties: {
151+
enum: {
152+
items: {
153+
type: 'string',
154+
},
155+
},
156+
},
157+
},
158+
},
159+
{
160+
if: {
161+
$ref: '#/$defs/hasTypeNumberOrInteger',
162+
},
163+
then: {
164+
properties: {
165+
enum: {
166+
items: {
167+
type: 'number',
168+
},
169+
},
170+
},
171+
},
172+
},
173+
{
174+
if: {
175+
$ref: '#/$defs/hasTypeBoolean',
176+
},
177+
then: {
178+
properties: {
179+
enum: {
180+
items: {
181+
type: 'boolean',
182+
},
183+
},
184+
},
185+
},
186+
},
187+
];
188+
189+
const ALL_OF_CONST_PROPERTY = [
127190
{
128191
if: {
129192
$ref: '#/$defs/hasTypeArray',

meta_configurator/src/settings/defaultSettingsData.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export const SETTINGS_DATA_DEFAULT = {
5252
metaSchema: {
5353
allowBooleanSchema: false,
5454
allowMultipleTypes: false,
55-
objectTypesComfort: false,
55+
objectTypesComfort: true,
5656
markMoreFieldsAsAdvanced: true,
5757
showAdditionalPropertiesButton: false,
5858
showJsonLdFields: false,

meta_configurator/src/settings/settingsSchema.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -326,11 +326,9 @@ export const SETTINGS_SCHEMA: TopLevelSchema = {
326326
},
327327
objectTypesComfort: {
328328
type: 'boolean',
329-
$comment:
330-
"Warning: due to incompatibility, this option will disable schema editor support for defining the items of an array, as well as support for many advanced keywords, such as conditionals and 'not'.",
331329
description:
332330
'This is a comfort feature: the original JSON Meta Schema allows properties of a particular type to have example values, constant values, default values or enum values of different types. For example, a field for numbers could have a string as a default value. This meta schema option forces the same type for all these values. This enables the tool to auto-select the corresponding type in the schema editor, avoiding the need for the user to manually select the types. ',
333-
default: false,
331+
default: true,
334332
metaConfigurator: {
335333
advanced: true,
336334
},

0 commit comments

Comments
 (0)