Skip to content

Commit 1bb2116

Browse files
committed
feat: support returning a raw Response
1 parent 732d26b commit 1bb2116

File tree

6 files changed

+106
-48
lines changed

6 files changed

+106
-48
lines changed

integration-tests/typescript-nextjs/src/generated/todo-lists.yaml/attachments/route.ts

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

integration-tests/typescript-nextjs/src/generated/todo-lists.yaml/list/[listId]/items/route.ts

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

integration-tests/typescript-nextjs/src/generated/todo-lists.yaml/list/[listId]/route.ts

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

integration-tests/typescript-nextjs/src/generated/todo-lists.yaml/list/route.ts

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

packages/openapi-code-generator/src/typescript/server/typescript-nextjs/typescript-nextjs-router-builder.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -145,14 +145,18 @@ try {
145145
146146
const responder = ${responder.implementation}
147147
148-
const {
149-
status,
150-
body,
151-
} = await implementation(${[params.hasParams ? "input" : undefined, "responder", "request"].filter(isDefined).join(",")})
152-
.then(it => it.unpack())
148+
const res = await implementation(${[params.hasParams ? "input" : undefined, "responder", "request"].filter(isDefined).join(",")})
149+
.then(it => {
150+
if(it instanceof Response) {
151+
return it
152+
}
153+
const {status, body} = it.unpack()
154+
155+
return body !== undefined ? Response.json(body, {status}) : new Response(undefined, {status})
156+
})
153157
.catch(err => { throw OpenAPIRuntimeError.HandlerError(err) })
154158
155-
return body !== undefined ? Response.json(body, {status}) : new Response(undefined, {status})
159+
return res
156160
} catch (err) {
157161
return await onError(err)
158162
}

packages/typescript-nextjs-runtime/src/server.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ export type Response<Status extends StatusCode, Type> = {
2929
body: Type
3030
}
3131

32-
export const SkipResponse = Symbol("skip response processing")
33-
3432
export class OpenAPIRuntimeResponse<Type> {
3533
private _body?: Type
3634

0 commit comments

Comments
 (0)