(context, location, addComma, objVar)
| 296 | } |
| 297 | |
| 298 | function buildExtraObjectPropertiesSerializer (context, location, addComma, objVar) { |
| 299 | const schema = location.schema |
| 300 | const propertiesKeys = Object.keys(schema.properties || {}) |
| 301 | |
| 302 | let code = ` |
| 303 | for (const key of Object.keys(${objVar})) { |
| 304 | if ( |
| 305 | ${propertiesKeys.length > 0 ? propertiesKeys.map(k => `key === ${JSON.stringify(k)}`).join(' || ') + ' ||' : ''} |
| 306 | ${objVar}[key] === undefined || |
| 307 | typeof ${objVar}[key] === 'function' || |
| 308 | typeof ${objVar}[key] === 'symbol' |
| 309 | ) continue |
| 310 | const value = ${objVar}[key] |
| 311 | ` |
| 312 | |
| 313 | const patternPropertiesLocation = location.getPropertyLocation('patternProperties') |
| 314 | const patternPropertiesSchema = patternPropertiesLocation.schema |
| 315 | |
| 316 | if (patternPropertiesSchema !== undefined) { |
| 317 | for (const propertyKey in patternPropertiesSchema) { |
| 318 | const propertyLocation = patternPropertiesLocation.getPropertyLocation(propertyKey) |
| 319 | |
| 320 | code += ` |
| 321 | if (/${propertyKey.replace(/\\*\//g, '\\/')}/.test(key)) { |
| 322 | ${addComma} |
| 323 | json += asString(key) + JSON_STR_COLONS |
| 324 | ${buildValue(context, propertyLocation, 'value')} |
| 325 | continue |
| 326 | } |
| 327 | ` |
| 328 | } |
| 329 | } |
| 330 | |
| 331 | const additionalPropertiesLocation = location.getPropertyLocation('additionalProperties') |
| 332 | const additionalPropertiesSchema = additionalPropertiesLocation.schema |
| 333 | |
| 334 | if (additionalPropertiesSchema !== undefined) { |
| 335 | if (additionalPropertiesSchema === true) { |
| 336 | code += ` |
| 337 | ${addComma} |
| 338 | json += asString(key) + JSON_STR_COLONS + JSON.stringify(value) |
| 339 | ` |
| 340 | } else { |
| 341 | const propertyLocation = location.getPropertyLocation('additionalProperties') |
| 342 | code += ` |
| 343 | ${addComma} |
| 344 | json += asString(key) + JSON_STR_COLONS |
| 345 | ${buildValue(context, propertyLocation, 'value')} |
| 346 | ` |
| 347 | } |
| 348 | } |
| 349 | |
| 350 | code += ` |
| 351 | } |
| 352 | ` |
| 353 | return code |
| 354 | } |
| 355 |
no test coverage detected
searching dependent graphs…