swagger - 对 fastify swagger 的标记支持
问题描述
您好 Fastify 专家,
我正在使用 fastify 和 fastify-swagger 从我的模式定义中创建 OAS-3 (3.0.3) API 规范。
我能够创建漂亮的 html,以便嵌入其中。
但是,当我使用标记(富文本,如 === 标题、--- 水平线等)时,它似乎没有承认它。
可能是我遗漏了一些东西或其他一些要添加以支持标记的 fastify 插件。
请帮帮我,如果可能的话。
"fastify": "^3.20.1",
"fastify-swagger": "^4.8.4",
谢谢, 普拉迪普
解决方案
我可以使用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'
},
....
}
推荐阅读
- python - 逻辑错了吗?计算用于支付首期付款的工资百分比
- c# - System.Net.Http.HttpClient如何选择认证类型?
- java - 如何在不下载的情况下获取 S3 上 csv 文件的行数?
- apache-camel - Camel 3.0-M2 在类中缺少方法adviceWith:RouteDefinition
- c# - 如何编组 unsigned short (c++) -> ushort (c#) 数组或读取本机数组以创建 BitmapSource?
- javascript - 如何在 htaccess 中将我的 /old/folder 重定向到 /newfolder
- c# - How to load Emoji icons using this library TheArtOfDev.HtmlRenderer.PdfSharp.PdfGenerator when converting HTML to PDF in c#?
- angular - 编写 Angular 原理图模板时,“小写”的辅助函数是什么?
- google-sheets - 提供值以获取“EMPTY”或“BLANK”单元格
- .htaccess - forbid every request to a domain