UNPKG

@redpanda-data/docs-extensions-and-macros

Version:

Antora extensions and macros developed for Redpanda documentation.

68 lines (60 loc) 2.44 kB
const renderLeafField = require('./renderLeafField'); const renderObjectField = require('./renderObjectField'); // Component types that support the 'label' field const TYPES_WITH_LABEL = new Set(['inputs', 'outputs', 'processors']); /** * Builds either "Common" or "Advanced" YAML for one connector. * * - type = "input" or "output" (or whatever type) * - connectorName = such as "amqp_1" * - children = the array of field‐definitions (entry.config.children) * - includeAdvanced = if false → only fields where is_advanced !== true * if true → all fields (except deprecated) * * Structure produced: * * type: * label: "" (only for inputs, outputs, processors) * connectorName: * ...child fields (with comments for "no default") */ module.exports = function buildConfigYaml(type, connectorName, children, includeAdvanced) { const lines = []; // "type:" top‐level lines.push(`${type}:`); // Two‐space indent for "label" (only for types that support it) if (TYPES_WITH_LABEL.has(type)) { lines.push(` label: ""`); } // Count how many fields will be rendered to determine if we need {} const fieldsToRender = children.filter(field => { if (field.is_deprecated) return false; if (!includeAdvanced && field.is_advanced) return false; return true; }); // Two‐space indent for connectorName heading // If no fields will be rendered, use {} for valid YAML if (fieldsToRender.length === 0) { lines.push(` ${connectorName}: {}`); } else { lines.push(` ${connectorName}:`); } // Four‐space indent for children const baseIndent = 4; fieldsToRender.forEach(field => { // Check if this is an array-of-objects (e.g., client_certs[]) // These should render as empty arrays, not expanded object structures if (field.kind === 'array' && field.type === 'object' && Array.isArray(field.children)) { // Render as array leaf (e.g., "client_certs: []") lines.push(renderLeafField(field, baseIndent)); } else if (field.type === 'object' && Array.isArray(field.children)) { // Render nested object (plain object, not array) const nestedLines = renderObjectField(field, baseIndent); lines.push(...nestedLines); } else { // Render a scalar or array leaf lines.push(renderLeafField(field, baseIndent)); } }); return lines.join('\n'); }