next-openapi-gen 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -9,6 +9,7 @@
9
9
 
10
10
  ## Interfaces
11
11
 
12
+ - Scalar
12
13
  - Swagger
13
14
  - Redoc
14
15
  - Stoplight Elements
@@ -19,7 +20,7 @@
19
20
  - **Automatic OpenAPI Generation**: Generate OpenAPI 3.0 documentation from your Next.js routes, automatically parsing TypeScript types for parameters, request bodies and responses. Field comments in TypeScript types are reflected as descriptions in the OpenAPI schema.
20
21
  - **Complex TypeScript Types**: Use complex TypeScript types, such as `nested objects`, `arrays`, `enums` and `unions` (mapped to anyOf). This enables a more comprehensive representation of data structures directly in the OpenAPI schema.
21
22
  - **JSDoc-Based Documentation**: Document API routes with optional JSDoc comments, including tags like `@openapi`, `@auth`, `@desc`, `@params`, `@body`, and `@response` to easily define route metadata.
22
- - **Multiple UI Interfaces**: Choose between `Swagger UI`, `Redoc`, `Stoplight Elements` or `RapiDoc` to visualize your API documentation. Customize the interface to fit your preferences.
23
+ - **Multiple UI Interfaces**: Choose between `Scalar`, `Swagger UI`, `Redoc`, `Stoplight Elements` or `RapiDoc` to visualize your API documentation. Customize the interface to fit your preferences.
23
24
  - **Real-time Documentation**: As your API evolves, regenerate the OpenAPI documentation with a single command, ensuring your documentation is always up to date.
24
25
  - **Easy configuration**: Customize generator behavior using the `next.openapi.json` configuration file, allowing for quick adjustments without modifying the code.
25
26
 
@@ -33,20 +34,20 @@ yarn add next-openapi-gen
33
34
 
34
35
  ### Step 1: Initialize Configuration and Setup
35
36
 
36
- Run the following command to generate the `next.openapi.json` configuration file and automatically set up Swagger UI with `/api-docs` routes:
37
+ Run the following command to generate the `next.openapi.json` configuration file and automatically set up Scalar UI with `/api-docs` routes:
37
38
 
38
39
  ```bash
39
- npx next-openapi-gen init --ui swagger --docs-url api-docs
40
+ npx next-openapi-gen init --ui scalar --docs-url api-docs
40
41
  ```
41
42
 
42
43
  Parameters:
43
- - **ui**: `swagger` | `redoc` | `stoplight` | `rapidoc`
44
+ - **ui**: `scalar` | `swagger` | `redoc` | `stoplight` | `rapidoc`
44
45
  - **docs-url**: url on which api docs will be visible
45
46
 
46
47
  This command does the following:
47
48
 
48
49
  - Generates a `next.openapi.json` file, which stores the OpenAPI configuration for your project.
49
- - Installs Swagger UI to provide an API documentation interface.
50
+ - Installs Scalar UI to provide an API documentation interface.
50
51
  - Adds an `/api-docs` route in the Next.js app for visualizing the generated OpenAPI documentation.
51
52
 
52
53
  ### Step 2: Add JSDoc Comments to Your API Routes
@@ -57,7 +58,7 @@ Annotate your API routes using JSDoc comments. Here's an example:
57
58
  <table>
58
59
  <tr>
59
60
  <th>Login route</th>
60
- <th>Swagger</th>
61
+ <th>Scalar / Swagger</th>
61
62
  </tr>
62
63
  <tr>
63
64
  <td>
@@ -87,13 +88,14 @@ Annotate your API routes using JSDoc comments. Here's an example:
87
88
  ```
88
89
  </td>
89
90
  <td>
90
- <img width="340" alt="api-login" src="https://raw.githubusercontent.com/tazo90/next-openapi-gen/refs/heads/main/assets/api-login.png" alt-text="api-login"/>
91
+ <img width="340" alt="api-login-scalar" src="https://raw.githubusercontent.com/tazo90/next-openapi-gen/refs/heads/main/assets/api-login-scalar.png" alt-text="api-login"/>
92
+ <img width="340" alt="api-login-swagger" src="https://raw.githubusercontent.com/tazo90/next-openapi-gen/refs/heads/main/assets/api-login-swagger.png" alt-text="api-login-swagger"/>
91
93
  </td>
92
94
  </tr>
93
95
 
94
96
  <tr>
95
97
  <th>Users route</th>
96
- <th>Swagger</th>
98
+ <th>Scalar / Swagger</th>
97
99
  </tr>
98
100
  <tr>
99
101
  <td>
@@ -145,7 +147,8 @@ Annotate your API routes using JSDoc comments. Here's an example:
145
147
  ```
146
148
  </td>
147
149
  <td>
148
- <img width="340" alt="api-users" src="https://raw.githubusercontent.com/tazo90/next-openapi-gen/refs/heads/main/assets/api-users.png" alt-text="api-users"/>
150
+ <img width="340" alt="api-users-scalar" src="https://raw.githubusercontent.com/tazo90/next-openapi-gen/refs/heads/main/assets/api-users-scalar.png" alt-text="api-users-scalar"/>
151
+ <img width="340" alt="api-users-swagger" src="https://raw.githubusercontent.com/tazo90/next-openapi-gen/refs/heads/main/assets/api-users-swagger.png" alt-text="api-users-swagger"/>
149
152
  </td>
150
153
  </tr>
151
154
  </table>
@@ -159,11 +162,11 @@ Run the following command to generate the OpenAPI schema based on your API route
159
162
  npx next-openapi-gen generate
160
163
  ```
161
164
 
162
- This command processes all your API routes, extracts the necessary information from JSDoc comments, and generates the OpenAPI schema, typically saved to a `swagger.json` file in the `public` folder.
165
+ This command processes all your API routes, extracts the necessary information from JSDoc comments, and generates the OpenAPI schema, typically saved to a `openapi.json` file in the `public` folder.
163
166
 
164
167
  ### Step 4: View API Documentation
165
168
 
166
- With the `/api-docs` route generated from the init command, you can now access your API documentation through Swagger UI by navigating to `http://localhost:3000/api-docs`.
169
+ With the `/api-docs` route generated from the init command, you can now access your API documentation through Scalar UI by navigating to `http://localhost:3000/api-docs`.
167
170
 
168
171
  ## JSDoc tags
169
172
 
@@ -181,8 +184,8 @@ The `next.openapi.json` file allows you to configure the behavior of the OpenAPI
181
184
  - **apiDir**: (default: `./src/app/api`) The directory where your API routes are stored.
182
185
  - **schemaDir**: (default: `./src`) The directory where your schema definitions are stored.
183
186
  - **docsUrl**: (default: `./api-docs`) Route where OpenAPI UI is available.
184
- - **ui**: (default: `swagger`) OpenAPI UI interface.
185
- - **outputFile**: (default: `./swagger.json`) The file where the generated OpenAPI specification will be saved in `public` folder.
187
+ - **ui**: (default: `scalar`) OpenAPI UI interface.
188
+ - **outputFile**: (default: `./openapi.json`) The file where the generated OpenAPI specification will be saved in `public` folder.
186
189
  - **includeOpenApiRoutes**: (default: `false`) When `true`, the generator will only include routes that have the `@openapi` tag in their JSDoc comments.
187
190
 
188
191
  ## Interface providers
@@ -190,7 +193,8 @@ The `next.openapi.json` file allows you to configure the behavior of the OpenAPI
190
193
  <div align="center">
191
194
  <table>
192
195
  <thead>
193
- <th>SwaggerUI</th>
196
+ <th>Scalar</th>
197
+ <th>Swagger</th>
194
198
  <th>Redoc</th>
195
199
  <th>Stoplight Elements</th>
196
200
  <th>RapiDoc</th>
@@ -5,6 +5,7 @@ import ora from "ora";
5
5
  import { exec } from "child_process";
6
6
  import util from "util";
7
7
  import openapiTemplate from "../openapi-template.js";
8
+ import { scalarDeps, ScalarUI } from "../components/scalar.js";
8
9
  import { swaggerDeps, SwaggerUI } from "../components/swagger.js";
9
10
  import { redocDeps, RedocUI } from "../components/redoc.js";
10
11
  import { stoplightDeps, StoplightUI } from "../components/stoplight.js";
@@ -33,8 +34,11 @@ const getPackageManager = async () => {
33
34
  return "npm";
34
35
  };
35
36
  function getDocsPage(ui, outputFile) {
36
- let DocsComponent = SwaggerUI;
37
- if (ui === "redoc") {
37
+ let DocsComponent = ScalarUI;
38
+ if (ui === "swagger") {
39
+ DocsComponent = SwaggerUI;
40
+ }
41
+ else if (ui === "redoc") {
38
42
  DocsComponent = RedocUI;
39
43
  }
40
44
  else if (ui === "stoplight") {
@@ -47,7 +51,10 @@ function getDocsPage(ui, outputFile) {
47
51
  }
48
52
  function getDocsPageDependencies(ui) {
49
53
  let deps = [];
50
- if (ui === "swagger") {
54
+ if (ui === "scalar") {
55
+ deps = scalarDeps;
56
+ }
57
+ else if (ui === "swagger") {
51
58
  deps = swaggerDeps;
52
59
  }
53
60
  else if (ui === "redoc") {
@@ -0,0 +1,20 @@
1
+ export const scalarDeps = ["@scalar/api-reference-react", "ajv"];
2
+ export function ScalarUI(outputFile) {
3
+ return `
4
+ "use client";
5
+
6
+ import { ApiReferenceReact } from "@scalar/api-reference-react";
7
+
8
+ import "@scalar/api-reference-react/style.css";
9
+
10
+ export default function ApiDocsPage() {
11
+ return (
12
+ <ApiReferenceReact
13
+ configuration={{
14
+ url: "/${outputFile}",
15
+ }}
16
+ />
17
+ );
18
+ }
19
+ `;
20
+ }
package/dist/index.js CHANGED
@@ -9,8 +9,8 @@ program
9
9
  .description("Super fast and easy way to generate OpenAPI documentation for Next.js");
10
10
  program
11
11
  .command("init")
12
- .addOption(new Option("-i, --ui <type>", "Specify the UI type, e.g., swagger")
13
- .choices(["swagger", "redoc", "stoplight", "rapidoc"])
12
+ .addOption(new Option("-i, --ui <type>", "Specify the UI type, e.g., scalar")
13
+ .choices(["scalar", "swagger", "redoc", "stoplight", "rapidoc"])
14
14
  .default("swagger"))
15
15
  .option("-u, --docs-url <url>", "Specify the docs URL", "api-docs")
16
16
  .description("Initialize a openapi specification")
@@ -23,7 +23,7 @@ export default {
23
23
  apiDir: "./src/app/api",
24
24
  schemaDir: "./src",
25
25
  docsUrl: "api-docs",
26
- ui: "swagger",
27
- outputFile: "swagger.json",
26
+ ui: "scalar",
27
+ outputFile: "openapi.json",
28
28
  includeOpenApiRoutes: false,
29
29
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-openapi-gen",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "Super fast and easy way to generate OpenAPI documentation automatically from API routes in NextJS.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -24,6 +24,7 @@
24
24
  "react",
25
25
  "nextjs",
26
26
  "openapi",
27
+ "scalar",
27
28
  "swagger",
28
29
  "docs",
29
30
  "api",