You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-**Integration with Next.js**: Works seamlessly with Next.js App Directory features.
15
15
-**Customizable**: Compatible with existing Next.js projects and fully customizable to suit your needs.
16
16
17
-
> **Note:** This package has a peer dependency on [`Next OpenAPI.json Generator`](https://www.npmjs.com/package/@omer-x/next-openapi-json-generator) for extracting the generated OpenAPI JSON.
17
+
> **Note:** This package has a peer dependency on [`Next OpenAPI JSON Generator`](https://www.npmjs.com/package/@omer-x/next-openapi-json-generator) for extracting the generated OpenAPI JSON.
18
18
19
19
## Requirements
20
20
21
21
To use `@omer-x/next-openapi-route-handler`, you'll need the following dependencies in your Next.js project:
The `createRoute` function is used to define route handlers in a type-safe and self-documenting way. Below is a description of each property of the input parameter:
| operationId |`string`| Unique identifier for the operation. |
43
-
| method |`HttpMethod`| HTTP method for the route (e.g., GET, POST, PUT, PATCH, DELETE). |
44
-
| summary |`string`| Short summary of the operation. |
45
-
| description |`string`| Detailed description of the operation. |
46
-
| tags |`string[]`| Tags for categorizing the operation. |
47
-
| pathParams |`ZodType`| Zod schema for validating path parameters. |
48
-
| queryParams |`ZodType`| Zod schema for validating query parameters. |
49
-
| requestBody |`ZodType`| Zod schema for the request body (required for POST/PUT/PATCH). |
50
-
| action |`({ pathParams, queryParams, body }) => Promise<Response>`| Function handling the request, receiving pathParams, queryParams, and requestBody. |
51
-
| responses |`Record<string, ResponseDefinition>`| Object defining possible responses, each with a description and optional content schema. |
| operationId |`string`| Unique identifier for the operation. |
42
+
| method |`string`| HTTP method for the route (e.g., `GET`, `POST`, `PUT`, `PATCH`, `DELETE`). |
43
+
| summary |`string`| Short summary of the operation. |
44
+
| description |`string`| Detailed description of the operation. |
45
+
| tags |`string[]`| Tags for categorizing the operation. |
46
+
| pathParams |[ZodType](https://zod.dev)|`(Optional)` Zod schema for validating path parameters. |
47
+
| queryParams |[ZodType](https://zod.dev)|`(Optional)` Zod schema for validating query parameters. |
48
+
| requestBody |[ZodType](https://zod.dev)| Zod schema for the request body (required for `POST`, `PUT`, `PATCH`). |
49
+
| action | (source: [ActionSource](#action-source)) => Promise<[Response](https://developer.mozilla.org/en-US/docs/Web/API/Response)> | Function handling the request, receiving pathParams, queryParams, and requestBody. |
50
+
| responses | Record<`number`, [ResponseDefinition](#response-definition)> | Object defining possible responses, each with a description and optional content schema. |
@@ -192,64 +150,78 @@ This will generate an OpenAPI JSON like this:
192
150
}
193
151
},
194
152
"patch": {
195
-
"operationId": "updateUser",
196
-
"summary": "Update a specific user by ID",
197
-
"description": "Update the details of an existing user identified by their unique ID",
198
-
"tags": ["Users"],
199
-
"parameters": [
200
-
{
201
-
"in": "path",
202
-
"name": "id",
203
-
"required": true,
204
-
"description": "ID of the user",
205
-
"schema": {
206
-
"type": "string"
207
-
}
208
-
}
209
-
],
210
-
"responses": {
211
-
"200": {
212
-
"description": "User updated successfully"
213
-
},
214
-
"404": {
215
-
"description": "User not found"
216
-
},
217
-
"409": {
218
-
"description": "Email already exists"
219
-
}
220
-
}
153
+
...
221
154
},
222
155
"delete": {
223
-
"operationId": "deleteUser",
224
-
"summary": "Delete a specific user by ID",
225
-
"description": "Remove a user from the system by their unique ID",
226
-
"tags": ["Users"],
227
-
"parameters": [
228
-
{
229
-
"in": "path",
230
-
"name": "id",
231
-
"required": true,
232
-
"description": "ID of the user",
233
-
"schema": {
234
-
"type": "string"
235
-
}
236
-
}
237
-
],
238
-
"responses": {
239
-
"204": {
240
-
"description": "User deleted successfully"
156
+
...
157
+
}
158
+
}
159
+
},
160
+
"components": {
161
+
"schemas": {
162
+
"UserDTO": {
163
+
"type": "object",
164
+
"properties": {
165
+
"id": {
166
+
"type": "string",
167
+
"format": "uuid",
168
+
"description": "Unique identifier of the user"
241
169
},
242
-
"404": {
243
-
"description": "User not found"
170
+
"name": {
171
+
"type": "string",
172
+
"description": "Display name of the user"
173
+
},
174
+
"email": {
175
+
"type": "string",
176
+
"description": "Email address of the user"
177
+
},
178
+
"password": {
179
+
"type": "string",
180
+
"maxLength": 72,
181
+
"description": "Encrypted password of the user"
182
+
},
183
+
"createdAt": {
184
+
"type": "string",
185
+
"format": "date-time",
186
+
"description": "Creation date of the user"
187
+
},
188
+
"updatedAt": {
189
+
"type": "string",
190
+
"format": "date-time",
191
+
"description": "Modification date of the user"
244
192
}
245
-
}
193
+
},
194
+
"required": [
195
+
"id",
196
+
"name",
197
+
"email",
198
+
"password",
199
+
"createdAt",
200
+
"updatedAt"
201
+
],
202
+
"additionalProperties": false,
203
+
"description": "Represents the data of a user in the system."
204
+
},
205
+
"NewUserDTO": {
206
+
...
207
+
},
208
+
"UserPatchDTO": {
209
+
...
246
210
}
247
211
}
248
212
}
249
213
}
250
214
```
251
215
252
-
> **Important:** This package cannot extract the OpenAPI JSON by itself. Use [Next OpenAPI.json Generator](https://www.npmjs.com/package/@omer-x/next-openapi-json-generator) to extract the generated data as JSON.
216
+
> **Important:** This package cannot extract the OpenAPI JSON by itself. Use [Next OpenAPI JSON Generator](https://www.npmjs.com/package/@omer-x/next-openapi-json-generator) to extract the generated data as JSON.
217
+
218
+
[An example can be found here](https://github.com/omermecitoglu/example-user-service)
0 commit comments