MCPcopy Index your code
hub / github.com/rapi-doc/RapiDoc / json2xml

Function json2xml

src/utils/schema-utils.js:390–416  ·  view source on GitHub ↗
(obj, level = 1)

Source from the content-addressed store, hash-verified

388 </root>
389*/
390export function json2xml(obj, level = 1) {
391 const indent = ' '.repeat(level);
392 let xmlText = '';
393 if (level === 1 && typeof obj !== 'object') {
394 return `\n${indent}${obj.toString()}`;
395 }
396 for (const prop in obj) {
397 const tagNameOrProp = (obj[prop]['::XML_TAG'] || prop);
398 let tagName = '';
399 if (Array.isArray(obj[prop])) {
400 tagName = tagNameOrProp[0]['::XML_TAG'] || `${prop}`;
401 } else {
402 tagName = tagNameOrProp;
403 }
404 if (prop.startsWith('::')) {
405 continue;
406 }
407 if (Array.isArray(obj[prop])) {
408 xmlText = `${xmlText}\n${indent}<${tagName}>${json2xml(obj[prop], level + 1)}\n${indent}</${tagName}>`;
409 } else if (typeof obj[prop] === 'object') {
410 xmlText = `${xmlText}\n${indent}<${tagName}>${json2xml(obj[prop], level + 1)}\n${indent}</${tagName}>`;
411 } else {
412 xmlText = `${xmlText}\n${indent}<${tagName}>${obj[prop].toString()}</${tagName}>`;
413 }
414 }
415 return xmlText;
416}
417
418function addSchemaInfoToExample(schema, obj) {
419 if (typeof obj !== 'object' || obj === null) {

Callers 2

buildFetchURLMethod · 0.90
generateExampleFunction · 0.70

Calls 1

toStringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…