MCPcopy Create free account
hub / github.com/eclipsesource/jsonforms / extractDefaults

Function extractDefaults

packages/core/src/mappers/renderer.ts:261–292  ·  view source on GitHub ↗
(schema: JsonSchema, rootSchema: JsonSchema)

Source from the content-addressed store, hash-verified

259 * @returns {any}
260 */
261export const extractDefaults = (schema: JsonSchema, rootSchema: JsonSchema) => {
262 if (hasType(schema, 'object') && schema.default === undefined) {
263 const result: { [key: string]: any } = {};
264 for (const key in schema.properties) {
265 const property = schema.properties[key];
266 const resolvedProperty = property.$ref
267 ? Resolve.schema(rootSchema, property.$ref, rootSchema)
268 : property;
269 if (resolvedProperty && resolvedProperty.default !== undefined) {
270 result[key] = cloneDeep(resolvedProperty.default);
271 }
272 }
273 // there could be more properties in allOf schemas
274 if (schema.allOf && Array.isArray(schema.allOf)) {
275 schema.allOf.forEach((allOfSchema) => {
276 if (allOfSchema && allOfSchema.properties) {
277 for (const key in allOfSchema.properties) {
278 const property = allOfSchema.properties[key];
279 const resolvedProperty = property.$ref
280 ? Resolve.schema(rootSchema, property.$ref, rootSchema)
281 : property;
282 if (resolvedProperty && resolvedProperty.default !== undefined) {
283 result[key] = cloneDeep(resolvedProperty.default);
284 }
285 }
286 }
287 });
288 }
289 return result;
290 }
291 return cloneDeep(schema.default);
292};
293
294/**
295 * Whether an element's description should be hidden.

Callers 1

doCreateDefaultValueFunction · 0.85

Calls 1

hasTypeFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…