(schema: JsonSchema, rootSchema: JsonSchema)
| 259 | * @returns {any} |
| 260 | */ |
| 261 | export 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. |
no test coverage detected
searching dependent graphs…