Skip to content

Commit f529387

Browse files
authored
feat: improve escape hatches (#326)
- improves the escape hatches to support skipping response processing by returning the `SkipResponse` symbol, allowing the method handler implementations to directly send responses. This allows for scenarios like returning binary data that isn't currently supported by the code generation - refactors the e2e tests in anticipation of multiple server implementations, and adds a few tests - adds documentation around the included escape hatches
1 parent eaf41af commit f529387

File tree

31 files changed

+16094
-2397
lines changed

31 files changed

+16094
-2397
lines changed

e2e/openapi.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ info:
55
tags:
66
- name: request headers
77
- name: validation
8+
- name: escape hatches
89
servers:
910
- url: '{protocol}://{host}:{port}'
1011
variables:
@@ -91,6 +92,24 @@ paths:
9192
application/json:
9293
schema:
9394
$ref: '#/components/schemas/Enumerations'
95+
/responses/500:
96+
get:
97+
tags:
98+
- validation
99+
responses:
100+
500:
101+
description: Internal Server Error
102+
/escape-hatches/plain-text:
103+
get:
104+
tags:
105+
- escape hatches
106+
responses:
107+
200:
108+
description: 'ok'
109+
content:
110+
text/plain:
111+
schema:
112+
type: string
94113
/responses/empty:
95114
get:
96115
tags:

e2e/scripts/generate.sh

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
#!/usr/bin/env bash
22

3-
echo $PWD
3+
set -e
4+
5+
SCHEMA_BUILDER=zod
46

57
yarn openapi-code-generator \
68
--input ./openapi.yaml \
7-
--output ./src/generated \
9+
--output ./src/generated/server/koa \
810
--template typescript-koa \
9-
--schema-builder zod \
11+
--schema-builder "$SCHEMA_BUILDER" \
1012
--extract-inline-schemas \
1113
--grouping-strategy first-tag
1214

1315
yarn openapi-code-generator \
1416
--input ./openapi.yaml \
1517
--output ./src/generated/client/fetch \
1618
--template typescript-fetch \
17-
--schema-builder zod \
19+
--schema-builder "$SCHEMA_BUILDER" \
1820
--extract-inline-schemas \
1921
--enable-runtime-response-validation \
2022
--override-specification-title "E2E Test Client"
@@ -23,7 +25,7 @@ yarn openapi-code-generator \
2325
--input ./openapi.yaml \
2426
--output ./src/generated/client/axios \
2527
--template typescript-axios \
26-
--schema-builder zod \
28+
--schema-builder "$SCHEMA_BUILDER" \
2729
--extract-inline-schemas \
2830
--enable-runtime-response-validation \
2931
--override-specification-title "E2E Test Client"

e2e/src/generated/client/axios/client.ts

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

e2e/src/generated/client/fetch/client.ts

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

e2e/src/generated/server/koa/routes/escape-hatches.ts

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

e2e/src/generated/routes/request-headers.ts renamed to e2e/src/generated/server/koa/routes/request-headers.ts

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

0 commit comments

Comments
 (0)