Skip to content

Commit

Permalink
add type and enum to object definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
TheJuanAndOnly99 committed Feb 13, 2024
1 parent 6dc4331 commit 814fd93
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions schema2Markdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function processProperty(propertyName, propertyDetails, schemaExamples) {
}

if (propertyDetails.type) {
markdownContent += `**Type**: ${propertyDetails.type}\n\n`;
markdownContent += renderType(propertyDetails.type);
} else {
const contextRef = propertyDetails.properties?.context?.$ref || propertyDetails.$ref;

Expand All @@ -27,7 +27,7 @@ function processProperty(propertyName, propertyDetails, schemaExamples) {
}

if (propertyDetails.enum) {
markdownContent += `Possible values: ${propertyDetails.enum.join(', ')}\n\n`;
markdownContent += renderEnum(propertyDetails.enum);
}

if (propertyDetails.allOf) {
Expand All @@ -47,6 +47,14 @@ function processProperty(propertyName, propertyDetails, schemaExamples) {
return markdownContent;
}

function renderType(ref) {
return `**Type**: ${ref}\n\n`;
}

function renderEnum(ref) {
return `**Possible values**: ${ref.join(', ')}\n\n`;
}

function renderRef(contextRef) {
const filePath = contextRef.split('#')[0]; // ../api/api.schema.json
const objectType = filePath.split('/').pop().split('.')[0]; // api
Expand Down Expand Up @@ -99,6 +107,13 @@ function generateObjectMD(schema, title, schemaFolderName, version) {
markdownContent += `${escape(schema.description)}\n\n`;
}

if (schema.type) {
markdownContent += renderType(schema.type);
}
if (schema.enum) {
markdownContent += renderEnum(schema.enum);
}

console.log('hasAllOf/hasProperties', hasAllOf(schema.allOf), hasProperties(schema));
if (hasAllOf(schema.allOf) || hasProperties(schema)) {
// Extract properties, required fields, and $ref from the first allOf object
Expand Down

0 comments on commit 814fd93

Please sign in to comment.