Skip to content

Commit f60b36b

Browse files
committed
2.0.4 tRPC 11.0.0-rc.648 upgrade
1 parent 88ff9a1 commit f60b36b

File tree

4 files changed

+58
-21
lines changed

4 files changed

+58
-21
lines changed

README.md

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
## **[OpenAPI](https://swagger.io/specification/) support for [tRPC](https://trpc.io/)** 🧩
1313

14-
- tRPC 11 only 👈
14+
- tRPC ^11.0.0-rc.648 only 👈
1515
- Easy REST endpoints for your tRPC procedures.
1616
- Perfect for incremental adoption.
1717
- Supports all OpenAPI versions.
@@ -20,6 +20,7 @@ Note: This project is a fork of a fork, with full credit to the original authors
2020

2121
## Changelog
2222

23+
- 2.0.4 Upgrade to tRPC 11.0.0-rc.648
2324
- 2.0.3 Added support for array inputs for GET requests
2425

2526
## Usage
@@ -77,7 +78,7 @@ We currently support adapters for [`Express`](http://expressjs.com/), [`Next.js`
7778

7879
[`Fetch`](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API), [`Cloudflare Workers`](https://workers.cloudflare.com/) & more soon™, PRs are welcomed 🙌.
7980

80-
No support for AWS lambdas yet 😢
81+
No support for AWS lambdas
8182

8283
```typescript
8384
import http from 'http';
@@ -122,7 +123,7 @@ Please note:
122123

123124
## HTTP Requests
124125

125-
Procedures with a `GET`/`DELETE` method will accept inputs via URL `query parameters`. Procedures with a `POST`/`PATCH`/`PUT` method will accept inputs via the `request body` with a `application/json` or `application/x-www-form-urlencoded` content type.
126+
Procedures with a `GET`/`DELETE` method will accept inputs via URL `query parameters`. Procedures with a `POST`/`PATCH`/`PUT` method will accept inputs via the `request body` with a `application/json` content type.
126127

127128
### Path parameters
128129

@@ -267,7 +268,41 @@ app.use('/api', createOpenApiExpressMiddleware({ router: appRouter })); /* 👈
267268
app.listen(3000);
268269
```
269270

270-
#### With Next.js
271+
#### With Next.js app router
272+
273+
Please see [full example here](examples/with-nextjs-appdir).
274+
275+
```typescript
276+
// src/app/[...trpc]/route.ts
277+
import { appRouter } from '~/server/api/root';
278+
import { createContext } from '~/server/api/trpc';
279+
import { type NextRequest } from 'next/server';
280+
import { createOpenApiFetchHandler } from 'trpc-to-openapi';
281+
282+
export const dynamic = 'force-dynamic';
283+
284+
const handler = (req: NextRequest) => {
285+
// Handle incoming OpenAPI requests
286+
return createOpenApiFetchHandler({
287+
endpoint: '/',
288+
router: appRouter,
289+
createContext: () => createContext(req),
290+
req,
291+
});
292+
};
293+
294+
export {
295+
handler as GET,
296+
handler as POST,
297+
handler as PUT,
298+
handler as PATCH,
299+
handler as DELETE,
300+
handler as OPTIONS,
301+
handler as HEAD,
302+
};
303+
```
304+
305+
#### With Next.js pages router
271306

272307
Please see [full example here](examples/with-nextjs).
273308

package-lock.json

Lines changed: 17 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "trpc-to-openapi",
3-
"version": "2.0.3",
3+
"version": "2.0.4",
44
"description": "tRPC OpenAPI",
55
"author": "mcampa",
66
"private": false,

src/adapters/node-http/core.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ export const createOpenApiNodeHttpHandler = <
131131
if (zodSupportsCoerce && instanceofZodTypeObject(unwrappedSchema)) {
132132
if (!useBody) {
133133
for (const [key, shape] of Object.entries(unwrappedSchema.shape)) {
134-
if (shape instanceof ZodArray && typeof input[key] === 'string') {
134+
if (shape instanceof ZodArray && !Array.isArray(input[key])) {
135135
input[key] = [input[key]];
136136
}
137137
}

0 commit comments

Comments
 (0)