diff --git a/bin/generate-example-metadata.mjs b/bin/generate-example-metadata.mjs index 7ee9421..035f239 100755 --- a/bin/generate-example-metadata.mjs +++ b/bin/generate-example-metadata.mjs @@ -8,13 +8,17 @@ process.exit(errorNumber); } +const json2dotNotationLitteral = (j) => JSON.stringify(j) + .replace(/^"|"$/g, "") + .replace(/\\"/g, '"'); + const json2dotNotation = ( json, prefix = "post.responses.default.content.application/json.example." ) => { const flattened = flatten(json); const str = Object.keys(flattened) - .map(key => prefix + key + ": " + JSON.stringify(flattened[key])) + .map(key => `${prefix + key}: ${json2dotNotationLitteral(flattened[key])}`) .join("\n"); return str; };