Skip to content

feat: replace widdershin with redocly #19141

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions scripts/apidocgen/concat-markdown.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/usr/bin/env node

const fs = require('fs');
const path = require('path');

if (process.argv.length < 4) {
console.error('Usage: node concat-markdown.js <input-dir> <output-file>');
process.exit(1);
}

const inputDir = process.argv[2];
const outputFile = process.argv[3];

try {
let combinedMarkdown = '';

// Read the main README.md first
const readmePath = path.join(inputDir, 'README.md');
if (fs.existsSync(readmePath)) {
const readmeContent = fs.readFileSync(readmePath, 'utf8');
combinedMarkdown += '<!-- APIDOCGEN: BEGIN SECTION -->\n';
combinedMarkdown += readmeContent;
combinedMarkdown += '\n\n';
}

// Read all API files from the Apis directory
const apisDir = path.join(inputDir, 'Apis');
if (fs.existsSync(apisDir)) {
const apiFiles = fs.readdirSync(apisDir)
.filter(file => file.endsWith('.md'))
.sort(); // Sort alphabetically for consistent output

for (const apiFile of apiFiles) {
const apiPath = path.join(apisDir, apiFile);
const apiContent = fs.readFileSync(apiPath, 'utf8');

// Add section marker for postprocessor
combinedMarkdown += '<!-- APIDOCGEN: BEGIN SECTION -->\n';
combinedMarkdown += apiContent;
combinedMarkdown += '\n\n';
}
}

// Write the combined markdown file
fs.writeFileSync(outputFile, combinedMarkdown);

console.log(`Successfully combined markdown files into ${outputFile}`);
console.log(`Total size: ${Math.round(combinedMarkdown.length / 1024)}KB`);

} catch (error) {
console.error('Error:', error.message);
process.exit(1);
}
37 changes: 22 additions & 15 deletions scripts/apidocgen/generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,32 @@ log "Use temporary file: ${API_MD_TMP_FILE}"

pushd "${PROJECT_ROOT}"
go run github.com/swaggo/swag/cmd/swag@v1.8.9 init \
--generalInfo="coderd.go" \
--dir="./coderd,./codersdk,./enterprise/coderd,./enterprise/wsproxy/wsproxysdk" \
--output="./coderd/apidoc" \
--outputTypes="go,json" \
--parseDependency=true
--generalInfo="coderd.go" \
--dir="./coderd,./codersdk,./enterprise/coderd,./enterprise/wsproxy/wsproxysdk" \
--output="./coderd/apidoc" \
--outputTypes="go,json" \
--parseDependency=true
popd

pushd "${APIDOCGEN_DIR}"

# Make sure that widdershins is installed correctly.
pnpm exec -- widdershins --version
# Render the Markdown file.
pnpm exec -- widdershins \
--user_templates "./markdown-template" \
--search false \
--omitHeader true \
--language_tabs "shell:curl" \
--summary "../../coderd/apidoc/swagger.json" \
--outfile "${API_MD_TMP_FILE}"
# Make sure that OpenAPI Generator is installed correctly.
pnpm exec -- openapi-generator-cli version

# Generate markdown documentation using OpenAPI Generator
log "Generating markdown documentation with OpenAPI Generator..."
OUTPUT_TMP_DIR=$(mktemp -d /tmp/coder-apidoc-openapi.XXXXXX)
pnpm exec -- openapi-generator-cli generate \
-i "../../coderd/apidoc/swagger.json" \
-g markdown \
-o "${OUTPUT_TMP_DIR}"

# Combine all markdown files into a single file
log "Combining markdown files..."
node concat-markdown.js "${OUTPUT_TMP_DIR}" "${API_MD_TMP_FILE}"

# Clean up temporary directory
rm -rf "${OUTPUT_TMP_DIR}"
# Perform the postprocessing
go run postprocess/main.go -in-md-file-single "${API_MD_TMP_FILE}"
popd
7 changes: 7 additions & 0 deletions scripts/apidocgen/openapitools.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"$schema": "./node_modules/@openapitools/openapi-generator-cli/config.schema.json",
"spaces": 2,
"generator-cli": {
"version": "7.14.0"
}
}
2 changes: 1 addition & 1 deletion scripts/apidocgen/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"dependencies": {
"widdershins": "^4.0.1"
"@openapitools/openapi-generator-cli": "^2.15.0"
},
"resolutions": {
"semver": "7.5.3",
Expand Down
Loading
Loading