Skip to content

Commit

Permalink
remove use of require, remove hardcoded versions, check for multiple …
Browse files Browse the repository at this point in the history
…examples, refactor context ref split
  • Loading branch information
TheJuanAndOnly99 committed Mar 7, 2024
1 parent 6060696 commit 6bf17da
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions schema2Markdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,14 @@ function processProperty(propertyName, propertyDetails, schemaExamples) {
}

if (schemaExamples) {
const example = schemaExamples[0];

if (typeof example[propertyName] === 'object') {
markdownContent += `**Example Value**: \n\`\`\`json\n${JSON.stringify(example[propertyName], null, 2)}\n\`\`\`\n\n`;
} else if (example[propertyName]) {
markdownContent += `**Example Value**: \`'${example[propertyName]}'\`\n\n`;
}
schemaExamples.forEach((example) => {
markdownContent += `**Example Value**: \n`;
if (typeof example[propertyName] === 'object') {
markdownContent += `\`\`\`json\n${JSON.stringify(example[propertyName], null, 2)}\n\`\`\`\n\n`;
} else if (example[propertyName]) {
markdownContent += `\`${example[propertyName]}\`\n\n`;
}
});
}
}
return markdownContent;
Expand All @@ -57,7 +58,7 @@ function renderEnum(ref) {
}

function renderRef(contextRef) {
const filePath = contextRef.split('#')[0]; // ../api/api.schema.json
const [filePath, objectPath] = contextRef.split('#'); // ../api/api.schema.json, /definitions/AppIdentifier
const objectType = filePath.split('/').pop().split('.')[0]; // api

// FROM ../api/api.schema.json#/definitions/AppIdentifier
Expand All @@ -66,7 +67,6 @@ function renderRef(contextRef) {
// FROM timerange.schema.json#
// TO timerange/schemas/timerange

const objectPath = contextRef.split('#')[1]; // /definitions/AppIdentifier
let objectName = objectType;
if (objectPath) {
objectName = objectPath.split('/').pop(); // AppIdentifier
Expand Down Expand Up @@ -215,11 +215,11 @@ function parseSchemaFolder(schemaFolderName, version) {

function main() {

const versions = ["1.0", "1.1", "1.2", "2.0", "2.1"];
const versions = fse.readdirSync('./website/versioned_docs').map(version => version.split('-')[1]);

versions.forEach(version => {

let sidebarObject = require(`./website/versioned_sidebars/version-${version}-sidebars.json`)
let sidebarObject = fse.readJsonSync(`./website/versioned_sidebars/version-${version}-sidebars.json`)

let sidebarContextObject = {
"type": "category",
Expand Down

0 comments on commit 6bf17da

Please sign in to comment.