lib/export.js
function exportToJSONSchema(expSpecifications, baseSchemaURL, baseTypeURL, flat = false) {
  const namespaceResults = {};
  const endOfTypeURL = baseTypeURL[baseTypeURL.length - 1];
  if (endOfTypeURL !== '#' && endOfTypeURL !== '/') {
    baseTypeURL += '/';
  }
  for (const ns of expSpecifications.namespaces.all) {
    const lastLogger = logger;
    logger = logger.child({ shrId: ns.namespace});
    try {
      logger.debug('Exporting namespace.');
      if (flat) {
        const { schemaId, schema } = flatNamespaceToSchema(ns, expSpecifications.dataElements, baseSchemaURL, baseTypeURL);
        namespaceResults[schemaId] = schema;
      } else {
        const { schemaId, schema } = namespaceToSchema(ns, expSpecifications.dataElements, baseSchemaURL, baseTypeURL);
        namespaceResults[schemaId] = schema;
      }
      logger.debug('Finished exporting namespace.');
    } finally {
      logger = lastLogger;
    }
  }

  return namespaceResults;
}
function exportToJSONSchema(expSpecifications, baseSchemaURL, baseTypeURL, flat = false) {
  const namespaceResults = {};
  const endOfTypeURL = baseTypeURL[baseTypeURL.length - 1];
  if (endOfTypeURL !== '#' && endOfTypeURL !== '/') {
    baseTypeURL += '/';
  }
  for (const ns of expSpecifications.namespaces.all) {
    const lastLogger = logger;
    logger = logger.child({ shrId: ns.namespace});
    try {
      logger.debug('Exporting namespace.');
      if (flat) {
        const { schemaId, schema } = flatNamespaceToSchema(ns, expSpecifications.dataElements, baseSchemaURL, baseTypeURL);
        namespaceResults[schemaId] = schema;
      } else {
        const { schemaId, schema } = namespaceToSchema(ns, expSpecifications.dataElements, baseSchemaURL, baseTypeURL);
        namespaceResults[schemaId] = schema;
      }
      logger.debug('Finished exporting namespace.');
    } finally {
      logger = lastLogger;
    }
  }

  return namespaceResults;
}
Converts a group of specifications into JSON Schema.
@param {Specifications} expSpecifications - a fully expanded Specifications object.
@param {string} baseSchemaURL - the root URL for the schema identifier.
@param {string} baseTypeURL - the root URL for the EntryType field.
@param {boolean=} flat - if true then the generated schema will not be hierarchical. Defaults to false.
@return {Object.<string, Object>} A mapping of schema ids to JSON Schema definitions.