Overview:
Next-swagger-doc is a tool designed to generate Swagger JSON API documentation from NextJS API routes. It simplifies the process of creating and organizing API documentation by reading JSDoc-annotated source code and converting it into an OpenAPI (Swagger) specification. By incorporating next-swagger-doc into your Next.js project, you can easily create a Swagger UI for viewing and interacting with your API documentation.
Features:
- Generate Swagger JSON API: Automatically generate Swagger documentation based on JSDoc-annotated source code in NextJS API routes.
- Built-in Swagger UI: Provides a user-friendly interface for viewing and interacting with the generated Swagger documentation.
- Support for Multiple Libraries: Compatible with various validation libraries such as Zod, Yup, Fastest-Validator, and Joi for enhanced functionality.
- CLI Support: Allows for generating Swagger files from the command line interface.
- Customizable Swagger Comments: Add Swagger comments to API routes for detailed metadata inclusion in the Swagger spec.
Installation:
To install next-swagger-doc with your Next.js project, follow these steps:
Create a Swagger Spec:
npx create-next-app@13
Create Swagger UI Component:
npm install swagger-ui-react
Create API Documentation Page:
touch app/api-doc/page.tsx
Add Swagger Comment to API Route:
// Example Swagger Comment
Navigate to localhost:3000/api-doc to view the Swagger UI.
Summary:
Next-swagger-doc simplifies the process of creating Swagger API documentation for NextJS projects by automatically generating a Swagger specification from JSDoc-annotated source code in API routes. With its built-in Swagger UI support and compatibility with various validation libraries, next-swagger-doc offers a convenient solution for organizing and visualizing API documentation. The tool’s CLI support and customizable Swagger comments further enhance its usability and flexibility for developers.