How to use odata-csdl - 2 common examples

To help you get started, we’ve selected a few odata-csdl examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github SAP / odata-vocabularies / lib / transform.js View on Github external
fs.readdirSync(vocabFolder).filter(fn => fn.endsWith('.xml')).forEach(xmlfile => {
    const vocab = xmlfile.substring(0, xmlfile.lastIndexOf('.'));
    console.log(xmlfile);

    const xml = fs.readFileSync(vocabFolder + xmlfile, 'utf8');

    const jsonWithLineNumbers = csdl.xml2json(xml, true);
    const markdown = lib.csdl2markdown(xmlfile, jsonWithLineNumbers);
    fs.writeFileSync(vocabFolder + vocab + '.md', markdown.join('\n'));

    const json = csdl.xml2json(xml, false);
    // swap URLs of latest-version and alternate links
    const links = json['com.sap.vocabularies.' + vocab + '.v1']['@Core.Links'];
    const latestVersion = links.findIndex(l => l.rel == 'latest-version');
    const alternate = links.findIndex(l => l.rel == 'alternate');
    if (latestVersion != -1 && alternate != -1) {
        links[latestVersion].rel = 'alternate';
        links[alternate].rel = 'latest-version';
    }
    fs.writeFileSync(vocabFolder + vocab + '.json', JSON.stringify(json, null, 4));
});
github SAP / odata-vocabularies / lib / transform.js View on Github external
fs.readdirSync(vocabFolder).filter(fn => fn.endsWith('.xml')).forEach(xmlfile => {
    const vocab = xmlfile.substring(0, xmlfile.lastIndexOf('.'));
    console.log(xmlfile);

    const xml = fs.readFileSync(vocabFolder + xmlfile, 'utf8');

    const jsonWithLineNumbers = csdl.xml2json(xml, true);
    const markdown = lib.csdl2markdown(xmlfile, jsonWithLineNumbers);
    fs.writeFileSync(vocabFolder + vocab + '.md', markdown.join('\n'));

    const json = csdl.xml2json(xml, false);
    // swap URLs of latest-version and alternate links
    const links = json['com.sap.vocabularies.' + vocab + '.v1']['@Core.Links'];
    const latestVersion = links.findIndex(l => l.rel == 'latest-version');
    const alternate = links.findIndex(l => l.rel == 'alternate');
    if (latestVersion != -1 && alternate != -1) {
        links[latestVersion].rel = 'alternate';
        links[alternate].rel = 'latest-version';
    }
    fs.writeFileSync(vocabFolder + vocab + '.json', JSON.stringify(json, null, 4));
});

odata-csdl

Convert CSDL XML to CSDL JSON

SEE LICENSE IN LICENSE.md
Latest version published 2 months ago

Package Health Score

73 / 100
Full package analysis

Popular odata-csdl functions