@omer-x/next-openapi-json-generator 0.1.0
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/LICENSE +21 -0
- package/README.md +195 -0
- package/dist/core/dir.d.ts +2 -0
- package/dist/core/next.d.ts +4 -0
- package/dist/core/route.d.ts +9 -0
- package/dist/core/schema.d.ts +3 -0
- package/dist/core/transpile.d.ts +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +1 -0
- package/package.json +61 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Omer Mecitoglu
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
# Next OpenAPI JSON Generator
|
|
2
|
+
|
|
3
|
+
[](https://badge.fury.io/js/%40omer-x%2Fnext-openapi-json-generator)
|
|
4
|
+
[](https://opensource.org/licenses/MIT)
|
|
5
|
+
|
|
6
|
+
## Overview
|
|
7
|
+
|
|
8
|
+
`Next OpenAPI JSON Generator` is an open-source Next.js plugin that extracts and generates OpenAPI JSON specifications from your route handlers defined using `@omer-x/next-openapi-route-handler`. It simplifies the process of generating and maintaining OpenAPI documentation by leveraging TypeScript and Zod schemas.
|
|
9
|
+
|
|
10
|
+
**Key Features:**
|
|
11
|
+
- **Automated OpenAPI Generation**: Automatically generates OpenAPI JSON specs from your route handlers.
|
|
12
|
+
- **TypeScript Integration**: Seamlessly integrates with TypeScript for strong type-checking.
|
|
13
|
+
- **Zod Schema Support**: Uses Zod schemas for validation and generates JSON schemas for OpenAPI.
|
|
14
|
+
- **Next.js Compatibility**: Works seamlessly with Next.js and integrates with other server-side libraries.
|
|
15
|
+
|
|
16
|
+
> **Note:** This package works in conjunction with [`Next OpenAPI Route Handler`](https://www.npmjs.com/package/@omer-x/next-openapi-route-handler) to extract the generated OpenAPI JSON.
|
|
17
|
+
|
|
18
|
+
## Requirements
|
|
19
|
+
|
|
20
|
+
To use `@omer-x/next-openapi-json-generator`, you'll need the following dependencies in your Next.js project:
|
|
21
|
+
|
|
22
|
+
- [TypeScript](https://www.typescriptlang.org/) >= v5
|
|
23
|
+
- [Next.js](https://nextjs.org/) >= v13
|
|
24
|
+
- [Zod](https://zod.dev/) >= v3
|
|
25
|
+
- [Next OpenAPI Route Handler](https://www.npmjs.com/package/@omer-x/next-openapi-route-handler)
|
|
26
|
+
|
|
27
|
+
## Installation
|
|
28
|
+
|
|
29
|
+
To install this package, along with its peer dependency, run:
|
|
30
|
+
|
|
31
|
+
```sh
|
|
32
|
+
npm install @omer-x/next-openapi-json-generator @omer-x/next-openapi-route-handler
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Usage
|
|
36
|
+
|
|
37
|
+
The `generateOpenApiSpec` function is used to extract and generate the OpenAPI JSON specification from your defined models. Here's a description of how to use it:
|
|
38
|
+
|
|
39
|
+
### Example
|
|
40
|
+
|
|
41
|
+
```typescript
|
|
42
|
+
import generateOpenApiSpec from "@omer-x/next-openapi-json-generator";
|
|
43
|
+
import { NewUserDTO, UserDTO, UserPatchDTO } from "../models/user";
|
|
44
|
+
|
|
45
|
+
const Page = async () => {
|
|
46
|
+
const spec = await generateOpenApiSpec({
|
|
47
|
+
UserDTO,
|
|
48
|
+
NewUserDTO,
|
|
49
|
+
UserPatchDTO,
|
|
50
|
+
});
|
|
51
|
+
return <ReactSwagger spec={spec} />;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export default Page;
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### Parameters
|
|
58
|
+
|
|
59
|
+
The `generateOpenApiSpec` function takes an object with the following properties:
|
|
60
|
+
|
|
61
|
+
| Property | Type | Description |
|
|
62
|
+
| ------------ | ------------------------------------------- | ---------------------------------------------------------------- |
|
|
63
|
+
| models | Record<string, [ZodType](https://zod.dev)> | An object where keys are model names and values are Zod schemas. |
|
|
64
|
+
|
|
65
|
+
### Result
|
|
66
|
+
|
|
67
|
+
The function returns a promise that resolves to an OpenAPI JSON specification.
|
|
68
|
+
|
|
69
|
+
```json
|
|
70
|
+
{
|
|
71
|
+
"openapi": "3.1.0",
|
|
72
|
+
"info": {
|
|
73
|
+
"title": "User Service",
|
|
74
|
+
"version": "1.0.0"
|
|
75
|
+
},
|
|
76
|
+
"paths": {
|
|
77
|
+
"/users": {
|
|
78
|
+
"get": {
|
|
79
|
+
...
|
|
80
|
+
},
|
|
81
|
+
"post": {
|
|
82
|
+
...
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
"/users/{id}": {
|
|
86
|
+
"get": {
|
|
87
|
+
"operationId": "getUser",
|
|
88
|
+
"summary": "Get a specific user by ID",
|
|
89
|
+
"description": "Retrieve details of a specific user by their ID",
|
|
90
|
+
"tags": [
|
|
91
|
+
"Users"
|
|
92
|
+
],
|
|
93
|
+
"parameters": [
|
|
94
|
+
{
|
|
95
|
+
"in": "path",
|
|
96
|
+
"name": "id",
|
|
97
|
+
"required": true,
|
|
98
|
+
"description": "ID of the user",
|
|
99
|
+
"schema": {
|
|
100
|
+
"type": "string",
|
|
101
|
+
"description": "ID of the user"
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
],
|
|
105
|
+
"responses": {
|
|
106
|
+
"200": {
|
|
107
|
+
"description": "User details retrieved successfully",
|
|
108
|
+
"content": {
|
|
109
|
+
"application/json": {
|
|
110
|
+
"schema": {
|
|
111
|
+
"$ref": "#/components/schemas/UserDTO"
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
},
|
|
116
|
+
"404": {
|
|
117
|
+
"description": "User not found"
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
},
|
|
121
|
+
"patch": {
|
|
122
|
+
...
|
|
123
|
+
},
|
|
124
|
+
"delete": {
|
|
125
|
+
...
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
},
|
|
129
|
+
"components": {
|
|
130
|
+
"schemas": {
|
|
131
|
+
"UserDTO": {
|
|
132
|
+
"type": "object",
|
|
133
|
+
"properties": {
|
|
134
|
+
"id": {
|
|
135
|
+
"type": "string",
|
|
136
|
+
"format": "uuid",
|
|
137
|
+
"description": "Unique identifier of the user"
|
|
138
|
+
},
|
|
139
|
+
"name": {
|
|
140
|
+
"type": "string",
|
|
141
|
+
"description": "Display name of the user"
|
|
142
|
+
},
|
|
143
|
+
"email": {
|
|
144
|
+
"type": "string",
|
|
145
|
+
"description": "Email address of the user"
|
|
146
|
+
},
|
|
147
|
+
"password": {
|
|
148
|
+
"type": "string",
|
|
149
|
+
"maxLength": 72,
|
|
150
|
+
"description": "Encrypted password of the user"
|
|
151
|
+
},
|
|
152
|
+
"createdAt": {
|
|
153
|
+
"type": "string",
|
|
154
|
+
"format": "date-time",
|
|
155
|
+
"description": "Creation date of the user"
|
|
156
|
+
},
|
|
157
|
+
"updatedAt": {
|
|
158
|
+
"type": "string",
|
|
159
|
+
"format": "date-time",
|
|
160
|
+
"description": "Modification date of the user"
|
|
161
|
+
}
|
|
162
|
+
},
|
|
163
|
+
"required": [
|
|
164
|
+
"id",
|
|
165
|
+
"name",
|
|
166
|
+
"email",
|
|
167
|
+
"password",
|
|
168
|
+
"createdAt",
|
|
169
|
+
"updatedAt"
|
|
170
|
+
],
|
|
171
|
+
"additionalProperties": false,
|
|
172
|
+
"description": "Represents the data of a user in the system."
|
|
173
|
+
},
|
|
174
|
+
"NewUserDTO": {
|
|
175
|
+
...
|
|
176
|
+
},
|
|
177
|
+
"UserPatchDTO": {
|
|
178
|
+
...
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
[An example can be found here](https://github.com/omermecitoglu/example-user-service)
|
|
186
|
+
|
|
187
|
+
## Screenshots
|
|
188
|
+
|
|
189
|
+
| <a href="https://i.imgur.com/ru3muBc.png" target="_blank"><img src="https://i.imgur.com/ru3muBc.png" alt="screenshot-1"></a> | <a href="https://i.imgur.com/utHaZ6X.png" target="_blank"><img src="https://i.imgur.com/utHaZ6X.png" alt="screenshot-2"></a> | <a href="https://i.imgur.com/2f24kPE.png" target="_blank"><img src="https://i.imgur.com/2f24kPE.png" alt="screenshot-3"></a> | <a href="https://i.imgur.com/z3KIJQ1.png" target="_blank"><img src="https://i.imgur.com/z3KIJQ1.png" alt="screenshot-4"></a> |
|
|
190
|
+
|:--------------:|:--------------:|:--------------:|:--------------:|
|
|
191
|
+
| <a href="https://i.imgur.com/IFKXOiX.png" target="_blank"><img src="https://i.imgur.com/IFKXOiX.png" alt="screenshot-5"></a> | <a href="https://i.imgur.com/xzVjAPq.png" target="_blank"><img src="https://i.imgur.com/xzVjAPq.png" alt="screenshot-6"></a> | <a href="https://i.imgur.com/HrWuHOR.png" target="_blank"><img src="https://i.imgur.com/HrWuHOR.png" alt="screenshot-7"></a> | |
|
|
192
|
+
|
|
193
|
+
## License
|
|
194
|
+
|
|
195
|
+
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { PathsObject } from "@omer-x/openapi-types/dist/paths";
|
|
2
|
+
type RouteRecord = {
|
|
3
|
+
method: string;
|
|
4
|
+
path: string;
|
|
5
|
+
apiData: object;
|
|
6
|
+
};
|
|
7
|
+
export declare function createRouteRecord(method: string, filePath: string, rootPath: string, apiData: unknown): RouteRecord;
|
|
8
|
+
export declare function bundlePaths(source: RouteRecord[]): PathsObject;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function transpile(rawCode: string): string;
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(()=>{"use strict";var __webpack_modules__={489:function(e,t,r){var n=this&&this.__awaiter||function(e,t,r,n){return new(r||(r=Promise))((function(o,a){function i(e){try{c(n.next(e))}catch(e){a(e)}}function u(e){try{c(n.throw(e))}catch(e){a(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(i,u)}c((n=n.apply(e,t||[])).next())}))},o=this&&this.__generator||function(e,t){var r,n,o,a,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return a={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function u(u){return function(c){return function(u){if(r)throw new TypeError("Generator is already executing.");for(;a&&(a=0,u[0]&&(i=0)),i;)try{if(r=1,n&&(o=2&u[0]?n.return:u[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,u[1])).done)return o;switch(n=0,o&&(u=[2&u[0],o.value]),u[0]){case 0:case 1:o=u;break;case 4:return i.label++,{value:u[1],done:!1};case 5:i.label++,n=u[1],u=[0];continue;case 7:u=i.ops.pop(),i.trys.pop();continue;default:if(!(o=i.trys,(o=o.length>0&&o[o.length-1])||6!==u[0]&&2!==u[0])){i=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]<o[3])){i.label=u[1];break}if(6===u[0]&&i.label<o[1]){i.label=o[1],o=u;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(u);break}o[2]&&i.ops.pop(),i.trys.pop();continue}u=t.call(e,i)}catch(e){u=[6,e],n=0}finally{r=o=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,c])}}},a=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.getDirectoryItems=t.directoryExists=void 0;var i=r(896),u=a(r(943)),c=a(r(760));t.directoryExists=function(e){return n(this,void 0,void 0,(function(){return o(this,(function(t){switch(t.label){case 0:return t.trys.push([0,2,,3]),[4,u.default.access(e,i.constants.F_OK)];case 1:return t.sent(),[2,!0];case 2:return t.sent(),[2,!1];case 3:return[2]}}))}))},t.getDirectoryItems=function e(t,r){return n(this,void 0,void 0,(function(){var n,a,i,s,l,p,f;return o(this,(function(o){switch(o.label){case 0:return n=[],[4,u.default.readdir(t)];case 1:a=o.sent(),i=0,s=a,o.label=2;case 2:return i<s.length?(l=s[i],p=c.default.resolve(t,l),[4,u.default.stat(p)]):[3,7];case 3:return o.sent().isDirectory()?[4,e(p,r)]:[3,5];case 4:return f=o.sent(),n.push.apply(n,f),[3,6];case 5:l===r&&n.push(p),o.label=6;case 6:return i++,[3,2];case 7:return[2,n]}}))}))}},37:function(__unused_webpack_module,exports,__webpack_require__){var __awaiter=this&&this.__awaiter||function(e,t,r,n){return new(r||(r=Promise))((function(o,a){function i(e){try{c(n.next(e))}catch(e){a(e)}}function u(e){try{c(n.throw(e))}catch(e){a(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(i,u)}c((n=n.apply(e,t||[])).next())}))},__generator=this&&this.__generator||function(e,t){var r,n,o,a,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return a={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function u(u){return function(c){return function(u){if(r)throw new TypeError("Generator is already executing.");for(;a&&(a=0,u[0]&&(i=0)),i;)try{if(r=1,n&&(o=2&u[0]?n.return:u[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,u[1])).done)return o;switch(n=0,o&&(u=[2&u[0],o.value]),u[0]){case 0:case 1:o=u;break;case 4:return i.label++,{value:u[1],done:!1};case 5:i.label++,n=u[1],u=[0];continue;case 7:u=i.ops.pop(),i.trys.pop();continue;default:if(!(o=i.trys,(o=o.length>0&&o[o.length-1])||6!==u[0]&&2!==u[0])){i=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]<o[3])){i.label=u[1];break}if(6===u[0]&&i.label<o[1]){i.label=o[1],o=u;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(u);break}o[2]&&i.ops.pop(),i.trys.pop();continue}u=t.call(e,i)}catch(e){u=[6,e],n=0}finally{r=o=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,c])}}},__importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.getRouteExports=exports.findAppFolderPath=void 0;var promises_1=__importDefault(__webpack_require__(455)),node_path_1=__importDefault(__webpack_require__(760)),dir_1=__webpack_require__(489),transpile_1=__webpack_require__(380);function findAppFolderPath(){return __awaiter(this,void 0,void 0,(function(){var e,t;return __generator(this,(function(r){switch(r.label){case 0:return e=node_path_1.default.resolve(process.cwd(),"src","app"),[4,(0,dir_1.directoryExists)(e)];case 1:return r.sent()?[2,e]:(t=node_path_1.default.resolve(process.cwd(),"app"),[4,(0,dir_1.directoryExists)(t)]);case 2:return r.sent()?[2,t]:[2,null]}}))}))}function advancedEval(code){try{return eval(code)}catch(e){if(e instanceof ReferenceError){var refName=e.message.replace("is not defined","").trim();return advancedEval(code.replace(new RegExp("\\b".concat(refName,"\\b"),"g"),'"'.concat(refName,'"')))}throw e}}function getRouteExports(e){return __awaiter(this,void 0,void 0,(function(){var t;return __generator(this,(function(r){switch(r.label){case 0:return[4,promises_1.default.readFile(e,"utf-8")];case 1:return t=r.sent(),[2,advancedEval((0,transpile_1.transpile)(t))]}}))}))}exports.findAppFolderPath=findAppFolderPath,exports.getRouteExports=getRouteExports},683:function(e,t){var r=this&&this.__assign||function(){return r=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},r.apply(this,arguments)};function n(e,t){return e.replace(t,"").replace("[","{").replace("]","}").replace("/route.ts","")}Object.defineProperty(t,"__esModule",{value:!0}),t.bundlePaths=t.createRouteRecord=void 0,t.createRouteRecord=function(e,t,r,o){return{method:e.toLocaleLowerCase(),path:n(t,r),apiData:o}},t.bundlePaths=function(e){return e.sort((function(e,t){return e.path.localeCompare(t.path)})),e.reduce((function(e,t){var n,o;return r(r({},e),((n={})[t.path]=r(r({},e[t.path]),((o={})[t.method]=r({},t.apiData),o)),n))}),{})}},363:function(e,t,r){var n=this&&this.__assign||function(){return n=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},n.apply(this,arguments)},o=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.bundleSchemas=void 0;var a=o(r(106));t.bundleSchemas=function(e){return Object.keys(e).reduce((function(t,r){var o;return n(n({},t),((o={})[r]=(0,a.default)(e[r],{target:"openApi3"}),o))}),{})}},380:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.transpile=void 0;var n=r(899);t.transpile=function(e){var t=["import createRoute from '@omer-x/next-openapi-route-handler'","import z from 'zod';",function(e){var t=["GET","POST","PUT","PATCH","DELETE"],r=t.map((function(e){return"exports.".concat(e," = void 0;\n")})),n="module.exports = { ".concat(t.map((function(e){return"".concat(e,": exports.").concat(e)})).join(", ")," }");return"".concat(r,"\n").concat(e,"\n").concat(n)}(function(e){return e.replace(/^import\s.+\sfrom\s.+;$/gm,"").trim()}(e))];return(0,n.transpile)(t.join("\n"))}},156:function(e,t,r){var n=this&&this.__awaiter||function(e,t,r,n){return new(r||(r=Promise))((function(o,a){function i(e){try{c(n.next(e))}catch(e){a(e)}}function u(e){try{c(n.throw(e))}catch(e){a(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(i,u)}c((n=n.apply(e,t||[])).next())}))},o=this&&this.__generator||function(e,t){var r,n,o,a,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return a={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function u(u){return function(c){return function(u){if(r)throw new TypeError("Generator is already executing.");for(;a&&(a=0,u[0]&&(i=0)),i;)try{if(r=1,n&&(o=2&u[0]?n.return:u[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,u[1])).done)return o;switch(n=0,o&&(u=[2&u[0],o.value]),u[0]){case 0:case 1:o=u;break;case 4:return i.label++,{value:u[1],done:!1};case 5:i.label++,n=u[1],u=[0];continue;case 7:u=i.ops.pop(),i.trys.pop();continue;default:if(!(o=i.trys,(o=o.length>0&&o[o.length-1])||6!==u[0]&&2!==u[0])){i=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]<o[3])){i.label=u[1];break}if(6===u[0]&&i.label<o[1]){i.label=o[1],o=u;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(u);break}o[2]&&i.ops.pop(),i.trys.pop();continue}u=t.call(e,i)}catch(e){u=[6,e],n=0}finally{r=o=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,c])}}},a=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});var i=a(r(386)),u=r(489),c=r(37),s=r(683),l=r(363);t.default=function(e){return n(this,void 0,void 0,(function(){var t,r,n,a,p,f,_,d,h,b,v,y,w;return o(this,(function(o){switch(o.label){case 0:return[4,(0,c.findAppFolderPath)()];case 1:if(!(t=o.sent()))throw new Error("This is not a Next.js application!");return[4,(0,u.getDirectoryItems)(t,"route.ts")];case 2:r=o.sent(),n=[],a=0,p=r,o.label=3;case 3:return a<p.length?(f=p[a],[4,(0,c.getRouteExports)(f)]):[3,6];case 4:for(_=o.sent(),d=0,h=Object.entries(_);d<h.length;d++)b=h[d],v=b[0],(y=b[1])&&y.apiData&&n.push((0,s.createRouteRecord)(v.toLocaleLowerCase(),f,t,y.apiData));o.label=5;case 5:return a++,[3,3];case 6:return[2,{openapi:"3.1.0",info:{title:(w=(0,i.default)()).serviceName,version:w.version},paths:(0,s.bundlePaths)(n),components:{schemas:(0,l.bundleSchemas)(e)},tags:[]}]}}))}))}},899:e=>{e.exports=require("typescript")},106:e=>{e.exports=require("zod-to-json-schema")},896:e=>{e.exports=require("fs")},943:e=>{e.exports=require("fs/promises")},455:e=>{e.exports=require("node:fs/promises")},760:e=>{e.exports=require("node:path")},386:(e,t,r)=>{r.r(t),r.d(t,{default:()=>i});const n=require("node:fs");var o=r(760);function a(e){const t=e.match(/^@([^/]+)\//);return t?`@${t[1]}`:null}function i(){const e=o.resolve(process.cwd(),"package.json"),t=n.readFileSync(e,"utf-8"),r=JSON.parse(t),i=r.name,u=function(e){return e.split("/").pop()??null}(i)??"unknown-package";return{scope:a(i),packageName:i,moduleName:u,serviceName:(c=u.replace(/-/g," "),c.split(" ").map((e=>e.charAt(0).toUpperCase()+e.slice(1))).join(" ")),version:r.version};var c}}},__webpack_module_cache__={};function __webpack_require__(e){var t=__webpack_module_cache__[e];if(void 0!==t)return t.exports;var r=__webpack_module_cache__[e]={exports:{}};return __webpack_modules__[e].call(r.exports,r,r.exports,__webpack_require__),r.exports}__webpack_require__.d=(e,t)=>{for(var r in t)__webpack_require__.o(t,r)&&!__webpack_require__.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},__webpack_require__.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),__webpack_require__.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var __webpack_exports__=__webpack_require__(156);module.exports=__webpack_exports__})();
|
package/package.json
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@omer-x/next-openapi-json-generator",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "a Next.js plugin to generate OpenAPI documentation from route handlers",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"next.js",
|
|
7
|
+
"swagger",
|
|
8
|
+
"openapi",
|
|
9
|
+
"swagger.json",
|
|
10
|
+
"openapi.json",
|
|
11
|
+
"generator"
|
|
12
|
+
],
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "git+https://github.com/omermecitoglu/next-openapi-json-generator.git"
|
|
16
|
+
},
|
|
17
|
+
"bugs": {
|
|
18
|
+
"url": "https://github.com/omermecitoglu/next-openapi-json-generator/issues"
|
|
19
|
+
},
|
|
20
|
+
"homepage": "https://github.com/omermecitoglu/next-openapi-json-generator#readme",
|
|
21
|
+
"private": false,
|
|
22
|
+
"publishConfig": {
|
|
23
|
+
"access": "public"
|
|
24
|
+
},
|
|
25
|
+
"author": {
|
|
26
|
+
"name": "Omer Mecitoglu",
|
|
27
|
+
"email": "omer.mecitoglu@gmail.com",
|
|
28
|
+
"url": "https://omermecitoglu.github.io"
|
|
29
|
+
},
|
|
30
|
+
"license": "MIT",
|
|
31
|
+
"main": "dist/index.js",
|
|
32
|
+
"types": "dist/index.d.ts",
|
|
33
|
+
"files": [
|
|
34
|
+
"dist/"
|
|
35
|
+
],
|
|
36
|
+
"scripts": {
|
|
37
|
+
"prebuild": "ts-unused-exports tsconfig.json --excludePathsFromReport='src/index'",
|
|
38
|
+
"build": "webpack build --progress --mode=production",
|
|
39
|
+
"dev": "webpack build --progress --mode=development --watch"
|
|
40
|
+
},
|
|
41
|
+
"dependencies": {
|
|
42
|
+
"@omer-x/package-metadata": "^0.1.0",
|
|
43
|
+
"typescript": "^5.4.5",
|
|
44
|
+
"zod-to-json-schema": "^3.23.0"
|
|
45
|
+
},
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"@omer-x/eslint-config": "^1.0.7",
|
|
48
|
+
"@omer-x/openapi-types": "^0.1.0",
|
|
49
|
+
"@types/node": "^20.13.0",
|
|
50
|
+
"clean-webpack-plugin": "^4.0.0",
|
|
51
|
+
"eslint": "^8.57.0",
|
|
52
|
+
"ts-loader": "^9.5.1",
|
|
53
|
+
"ts-unused-exports": "^10.1.0",
|
|
54
|
+
"webpack": "^5.91.0",
|
|
55
|
+
"webpack-cli": "^5.1.4",
|
|
56
|
+
"zod": "^3.23.8"
|
|
57
|
+
},
|
|
58
|
+
"peerDependencies": {
|
|
59
|
+
"@omer-x/next-openapi-route-handler": "^0.1.0"
|
|
60
|
+
}
|
|
61
|
+
}
|