0

Hello Fastify experts,

I am using fastify and fastify-swagger for creating OAS-3 (3.0.3) API specification from my schema definition.

I am able to create nice html so embed into it.

However when I am using markup (rich text, like === heading, --- horizontal line etc.) it seems it does not acknowledging it.

May be I am missing something or some other fastify plugin to be added for markup support.

Please help me out, if it's possible.

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

Thanks, Pradip

Pradip
  • 509
  • 1
  • 5
  • 22

1 Answers1

0

I can able to get it done using the markdown-it npm package.

fasify-swagger does support markup of form 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'
      },
       ....
}

Pradip
  • 509
  • 1
  • 5
  • 22