首页 > 解决方案 > 对 fastify swagger 的标记支持

问题描述

您好 Fastify 专家,

我正在使用 fastify 和 fastify-swagger 从我的模式定义中创建 OAS-3 (3.0.3) API 规范。

我能够创建漂亮的 html,以便嵌入其中。

但是,当我使用标记(富文本,如 === 标题、--- 水平线等)时,它似乎没有承认它。

可能是我遗漏了一些东西或其他一些要添加以支持标记的 fastify 插件。

请帮帮我,如果可能的话。

    "fastify": "^3.20.1",
    "fastify-swagger": "^4.8.4",

谢谢, 普拉迪普

标签: swaggerfastify

解决方案


我可以使用markdown-it npm 包来完成它。

fasify-swagger支持GFM Syntax形式的标记。

const markdown = require('markdown-it')({
  html:         true,        // Enable HTML tags in source
  xhtmlOut:     true,        // Use '/' to close single tags (<br />).
});

const readMarkDown = () => {
  const markdownDir = './src/markdown';
  const introMDFile = `introduction.md`;
  const descriptionMDFileContent = fs.readFileSync(`${markdownDir}/${introMDFile}`, 'utf8');
  const descNoteMD = markdown.render(descriptionMDFileContent);
  return {descNoteMD};
}
const {descNoteMD} = readMarkDown();
console.log(descNoteMD);
   ...
const swaggerConfig = {
    swagger: {
      info: {
        title: 'My swagger',
        description: `My intro: ${descNoteMD}`,
        version: '2.0.0'
      },
       ....
}


推荐阅读