Skip to content

Commit

Permalink
Merge pull request #1598 from ClickHouse/fix-cloud-api-docs-script
Browse files Browse the repository at this point in the history
Debug error in Cloud API docs script
  • Loading branch information
justindeguzman authored Oct 20, 2023
2 parents 86c999d + e609bb3 commit 6c0d30a
Showing 1 changed file with 48 additions and 43 deletions.
91 changes: 48 additions & 43 deletions clickhouseapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,55 +85,60 @@ function generateDocusaurusMarkdown(spec, groupedEndpoints, prefix) {
}

if (operation.responses) {
markdownContent += `\n### Response\n\n`;

markdownContent += `#### Response Schema\n\n`;

const rawSchema = operation.responses['200'].content["application/json"].schema
const result = rawSchema.properties.result
const schema = rawSchema.properties.result.type === 'array' ?
result.items['$ref'].split('/').pop() : result['$ref'].split('/').pop()

const bodyParamAttrs = spec.components.schemas[schema].properties
const bodyParams = Object.keys(bodyParamAttrs)
const sampleResponseObj = {}

markdownContent += `| Name | Type | Description |\n`
markdownContent += `| :--- | :--- | :---------- |\n`

for (const parameter of bodyParams) {
const paramType = bodyParamAttrs[parameter].format || bodyParamAttrs[parameter].type
markdownContent += `| ${parameter} | ${paramType || ''} | ${bodyParamAttrs[parameter].description || ''} | \n`

switch (paramType) {
case 'uuid':
sampleResponseObj[parameter] = 'uuid';
break;
case 'string':
sampleResponseObj[parameter] = 'string';
break;
case 'number':
sampleResponseObj[parameter] = 0;
break;
case 'array':
sampleResponseObj[parameter] = 'Array';
break;
case 'boolean':
sampleResponseObj[parameter] = 'boolean';
break;
case 'date-time':
sampleResponseObj[parameter] = 'date-time';
break;
case 'email':
sampleResponseObj[parameter] = 'email';
break;
if (result) {
markdownContent += `\n### Response\n\n`;

markdownContent += `#### Response Schema\n\n`;

const schema = rawSchema.properties.result.type === 'array' ?
result.items['$ref'].split('/').pop() : result['$ref'].split('/').pop()

const bodyParamAttrs = spec.components.schemas[schema].properties
const bodyParams = Object.keys(bodyParamAttrs)
const sampleResponseObj = {}

markdownContent += `| Name | Type | Description |\n`
markdownContent += `| :--- | :--- | :---------- |\n`

for (const parameter of bodyParams) {
const paramType = bodyParamAttrs[parameter].format || bodyParamAttrs[parameter].type
markdownContent += `| ${parameter} | ${paramType || ''} | ${bodyParamAttrs[parameter].description || ''} | \n`

switch (paramType) {
case 'uuid':
sampleResponseObj[parameter] = 'uuid';
break;
case 'string':
sampleResponseObj[parameter] = 'string';
break;
case 'number':
sampleResponseObj[parameter] = 0;
break;
case 'array':
sampleResponseObj[parameter] = 'Array';
break;
case 'boolean':
sampleResponseObj[parameter] = 'boolean';
break;
case 'date-time':
sampleResponseObj[parameter] = 'date-time';
break;
case 'email':
sampleResponseObj[parameter] = 'email';
break;
}
}

markdownContent += `\n#### Sample response\n\n`;
markdownContent += '```\n'
markdownContent += `${JSON.stringify(sampleResponseObj, 0, 2)}`
markdownContent += '\n```\n'
}

markdownContent += `\n#### Sample response\n\n`;
markdownContent += '```\n'
markdownContent += `${JSON.stringify(sampleResponseObj, 0, 2)}`
markdownContent += '\n```\n'

}
}
}
Expand Down

0 comments on commit 6c0d30a

Please sign in to comment.