Skip to content

Commit

Permalink
fix: Documentation generation
Browse files Browse the repository at this point in the history
  • Loading branch information
ksentak committed Oct 18, 2024
1 parent b43349b commit f412c1b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
2 changes: 2 additions & 0 deletions languages/markdown/templates/schemas/default.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ ${schema.description}
${schema.shape}
```

Additional properties: ${schema.additionalProperties}

See also: ${schema.seeAlso}

---
10 changes: 10 additions & 0 deletions src/macrofier/engine.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -930,6 +930,10 @@ function generateSchemas(json, templates, options) {
else {
content = content.replace(/\$\{if\.description\}(.*?)\{end\.if\.description\}/gms, '$1')
}

// Schema title is requuired for proper documentation generation
if (!schema.title) schema.title = name

const schemaShape = types.getSchemaShape(schema, json, { templateDir: state.typeTemplateDir, destination: state.destination, section: options.section, primitive: config.primitives ? Object.keys(config.primitives).length > 0 : false })

content = content
Expand All @@ -941,6 +945,12 @@ function generateSchemas(json, templates, options) {
content = content.replace(/\$\{schema.example\}/, schema.examples.map(ex => JSON.stringify(ex, null, ' ')).join('\n\n'))
}

if (schema.additionalProperties) {
content = content.replace(/\$\{schema.additionalProperties\}/, JSON.stringify(schema.additionalProperties, null, ' '))
} else {
content = content.replace(/.*\$\{schema.additionalProperties\}/, '')
}

let seeAlso = getRelatedSchemaLinks(schema, json, templates, options)
if (seeAlso) {
content = content.replace(/\$\{schema.seeAlso\}/, '\n\n' + seeAlso)
Expand Down
2 changes: 0 additions & 2 deletions src/macrofier/types.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -664,9 +664,7 @@ function getSchemaShape(schema = {}, module = {}, { templateDir = 'types', paren
else if (schema.type) {
const shape = insertPrimitiveMacros(getTemplate(path.join(templateDir, 'primitive' + suffix)), schema, module, theTitle, templateDir)
result = result.replace(/\$\{shape\}/g, shape)
if (level > 0 || primitive) {
return insertSchemaMacros(result, schema, module, { name: theTitle, parent, property, required, templateDir })
}
}

return ''
Expand Down

0 comments on commit f412c1b

Please sign in to comment.