@gravitee/ui-particles-angular 17.4.0 → 17.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2976,7 +2976,8 @@ class GioFormlyJsonSchemaService {
2976
2976
  this.formlyJsonschema = formlyJsonschema;
2977
2977
  }
2978
2978
  toFormlyFieldConfig(jsonSchema, context) {
2979
- return this.formlyJsonschema.toFieldConfig(jsonSchema, {
2979
+ const preprocessed = this.preserveGioConfigOnRefs(jsonSchema);
2980
+ return this.formlyJsonschema.toFieldConfig(preprocessed, {
2980
2981
  map: (mappedField, mapSource) => {
2981
2982
  mappedField = this.uiTypeMap(mappedField, mapSource); // Keep first in order to correctly construct tree
2982
2983
  mappedField = this.displayIfMap(mappedField, mapSource, context);
@@ -3182,6 +3183,61 @@ class GioFormlyJsonSchemaService {
3182
3183
  }
3183
3184
  return mappedField;
3184
3185
  }
3186
+ /**
3187
+ * Formly's $ref resolution only preserves title, description, default and widget from sibling properties.
3188
+ * This method walks the schema and inlines $ref definitions when gioConfig is present alongside a $ref,
3189
+ * so that gioConfig is not lost during resolution.
3190
+ */
3191
+ preserveGioConfigOnRefs(schema) {
3192
+ return this.walkSchema(schema, schema);
3193
+ }
3194
+ walkSchema(node, root) {
3195
+ if (!isObject(node) || isArray(node)) {
3196
+ return node;
3197
+ }
3198
+ let result = { ...node };
3199
+ // If this node has a $ref alongside gioConfig, inline the resolved definition
3200
+ if (result.$ref && result.gioConfig) {
3201
+ const resolved = this.resolveRef(result.$ref, root);
3202
+ if (resolved) {
3203
+ const { $ref, ...rest } = result;
3204
+ result = { ...resolved, ...rest };
3205
+ }
3206
+ }
3207
+ // Recurse into properties
3208
+ if (result.properties) {
3209
+ const newProps = {};
3210
+ for (const [key, value] of Object.entries(result.properties)) {
3211
+ newProps[key] = this.walkSchema(value, root);
3212
+ }
3213
+ result = { ...result, properties: newProps };
3214
+ }
3215
+ // Recurse into items
3216
+ if (result.items) {
3217
+ if (isArray(result.items)) {
3218
+ result = { ...result, items: result.items.map(item => this.walkSchema(item, root)) };
3219
+ }
3220
+ else if (isObject(result.items)) {
3221
+ result = { ...result, items: this.walkSchema(result.items, root) };
3222
+ }
3223
+ }
3224
+ // Recurse into allOf / oneOf / anyOf
3225
+ for (const keyword of ['allOf', 'oneOf', 'anyOf']) {
3226
+ if (isArray(result[keyword])) {
3227
+ result = { ...result, [keyword]: result[keyword].map(s => this.walkSchema(s, root)) };
3228
+ }
3229
+ }
3230
+ return result;
3231
+ }
3232
+ resolveRef(ref, root) {
3233
+ const [, pointer] = ref.split('#/');
3234
+ if (!pointer) {
3235
+ return null;
3236
+ }
3237
+ return pointer
3238
+ .split('/')
3239
+ .reduce((acc, path) => (acc && acc[path]) ?? null, root);
3240
+ }
3185
3241
  uniqueValueMap(mappedField, mapSource) {
3186
3242
  let fieldNameWithErrors = undefined;
3187
3243
  if (mapSource.gioConfig?.uniqueItemProperties) {