u
This commit is contained in:
@@ -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 || {};
|
||||
|
||||
Reference in New Issue
Block a user