(context, location, input)
| 551 | } |
| 552 | |
| 553 | function buildObject (context, location, input) { |
| 554 | const schema = location.schema |
| 555 | |
| 556 | if (context.functionsNamesBySchema.has(schema)) { |
| 557 | const funcName = context.functionsNamesBySchema.get(schema) |
| 558 | return `json += ${funcName}(${input})` |
| 559 | } |
| 560 | |
| 561 | const nullable = schema.nullable === true |
| 562 | |
| 563 | const schemaId = location.schemaId || '' |
| 564 | const jsonPointer = location.jsonPointer || '' |
| 565 | const fullPath = `${schemaId}#${jsonPointer}` |
| 566 | |
| 567 | if (context.recursivePaths.has(fullPath) || context.buildingSet.has(schema) || schemaId !== '') { |
| 568 | const functionName = generateFuncName(context) |
| 569 | context.functionsNamesBySchema.set(schema, functionName) |
| 570 | |
| 571 | const schemaRef = getSafeSchemaRef(context, location) |
| 572 | |
| 573 | const functionCode = ` |
| 574 | // ${schemaRef} |
| 575 | function ${functionName} (input) { |
| 576 | const obj = ${toJSON('input')} |
| 577 | if (obj === null) return ${nullable ? 'JSON_STR_NULL' : 'JSON_STR_EMPTY_OBJECT'} |
| 578 | let json = '' |
| 579 | |
| 580 | ${buildInnerObject(context, location, 'obj')} |
| 581 | return json |
| 582 | } |
| 583 | ` |
| 584 | |
| 585 | context.functions.push(functionCode) |
| 586 | return `json += ${functionName}(${input})` |
| 587 | } |
| 588 | |
| 589 | context.buildingSet.add(schema) |
| 590 | const objVar = `obj_${context.uid++}` |
| 591 | const code = ` |
| 592 | const ${objVar} = ${toJSON(input)} |
| 593 | if (${objVar} === null) { |
| 594 | json += ${nullable ? 'JSON_STR_NULL' : 'JSON_STR_EMPTY_OBJECT'} |
| 595 | } else { |
| 596 | ${buildInnerObject(context, location, objVar)} |
| 597 | } |
| 598 | ` |
| 599 | context.buildingSet.delete(schema) |
| 600 | return code |
| 601 | } |
| 602 | |
| 603 | function buildArray (context, location, input) { |
| 604 | const schema = location.schema |
no test coverage detected
searching dependent graphs…