This commit is contained in:
seb
2026-07-31 20:10:14 +02:00
parent 6074aa7304
commit c77337507f
7 changed files with 372 additions and 5 deletions

View File

@@ -103,6 +103,38 @@ function contentSchema(content) {
return json?.schema ?? null;
}
function renderRequestBody(requestBody) {
if (!requestBody?.content) return null;
const lines = [];
const types = Object.keys(requestBody.content);
const jsonSchema = contentSchema(requestBody.content);
if (jsonSchema) {
lines.push('## Body (JSON)');
lines.push('');
lines.push(formatSchema(jsonSchema, spec.components));
lines.push('');
return lines;
}
lines.push('## Body');
lines.push('');
for (const type of types) {
const schema = requestBody.content[type]?.schema;
if (schema?.format === 'binary') {
lines.push(`Raw binary (\`${type}\`).`);
} else {
lines.push(`\`${type}\``);
if (schema) {
lines.push('');
lines.push(formatSchema(schema, spec.components));
}
}
lines.push('');
}
return lines;
}
function docsFileFor(apiPath, method) {
const custom = spec.paths[apiPath]?.[method]?.['x-markdown'];
if (custom) return custom;
@@ -172,11 +204,8 @@ function renderOperation(apiPath, method, operation) {
}
if (operation.requestBody) {
const schema = contentSchema(operation.requestBody.content);
lines.push('## Body (JSON)');
lines.push('');
lines.push(formatSchema(schema, spec.components));
lines.push('');
const bodyLines = renderRequestBody(operation.requestBody);
if (bodyLines) lines.push(...bodyLines);
}
const responses = operation.responses || {};