( schemaPart, schemaPath = "", path = [], inArray = null, segment = "#" )
| 329 | * @returns {number} added arguments |
| 330 | */ |
| 331 | const traverse = ( |
| 332 | schemaPart, |
| 333 | schemaPath = "", |
| 334 | path = [], |
| 335 | inArray = null, |
| 336 | segment = "#" |
| 337 | ) => { |
| 338 | while (schemaPart.$ref) { |
| 339 | segment = schemaPart.$ref; |
| 340 | schemaPart = getSchemaPart(schemaPart.$ref); |
| 341 | } |
| 342 | |
| 343 | const repetitions = path.filter(({ schema }) => schema === schemaPart); |
| 344 | if ( |
| 345 | repetitions.length >= 2 || |
| 346 | repetitions.some(({ path }) => path === schemaPath) |
| 347 | ) { |
| 348 | return 0; |
| 349 | } |
| 350 | |
| 351 | if (schemaPart.cli && schemaPart.cli.exclude) return 0; |
| 352 | |
| 353 | /** @type {PathItem[]} */ |
| 354 | const fullPath = [ |
| 355 | { schema: schemaPart, path: schemaPath, segment }, |
| 356 | ...path |
| 357 | ]; |
| 358 | |
| 359 | let addedArguments = 0; |
| 360 | |
| 361 | addedArguments += addFlag(fullPath, Boolean(inArray)); |
| 362 | |
| 363 | // Collect flags from both branches of a conditional schema. |
| 364 | const conditional = /** @type {JSONSchema7} */ (schemaPart); |
| 365 | if (conditional.if) { |
| 366 | for (const key of /** @type {const} */ (["if", "then", "else"])) { |
| 367 | const subSchema = conditional[key]; |
| 368 | if (subSchema && typeof subSchema === "object") { |
| 369 | addedArguments += traverse( |
| 370 | /** @type {Schema} */ |
| 371 | (subSchema), |
| 372 | schemaPath, |
| 373 | fullPath, |
| 374 | inArray, |
| 375 | `/${key}` |
| 376 | ); |
| 377 | } |
| 378 | } |
| 379 | } |
| 380 | |
| 381 | if (schemaPart.type === "object") { |
| 382 | if (schemaPart.properties) { |
| 383 | for (const property of Object.keys(schemaPart.properties)) { |
| 384 | addedArguments += traverse( |
| 385 | /** @type {Schema} */ |
| 386 | (schemaPart.properties[property]), |
| 387 | schemaPath ? `${schemaPath}.${property}` : property, |
| 388 | fullPath, |
no test coverage detected