Surnet/swagger-jsdoc

Is it possible to generate a swagger.json file?

ronaldl29 opened this issue · 3 comments

I am loading my *.routes.api.js files like this:


const swaggerJsdoc = require('swagger-jsdoc');

const options = {
  definition: {
    openapi: '3.0.0',
    info: {
      title: 'Hello World',
      version: '1.0.0',
    },
  },
  apis: ['./src/routes*.js'], // files containing annotations as above
};

const openapiSpecification = swaggerJsdoc(options);

I would like to export this to a swagger.json file. Is it possible with this package?

Check this out.

$ npx swagger-jsdoc     
Usage: swagger-jsdoc [options] <path ...>

Options:
  -V, --version                            output the version number
  -d, --definition <swaggerDefinition.js>  Input swagger definition.
  -o, --output [swaggerSpec.json]          Output swagger specification.
  -h, --help                               display help for command
# $ npx swagger-jsdoc -d <<definition-file>> -o swagger.json <<your-api-entry-point>>
$ npx swagger-jsdoc -d swagger.js -o swagger.json index.js

while running it can be done like this:

import { writeFile } from 'fs/promises';

writeFile('swagger.json', JSON.stringify(openapiSpecification, null, 2), 'utf-8');
stale commented

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.