typespec-hono 0.13.0 → 0.14.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/dist/src/app.js +14 -7
- package/package.json +2 -2
package/dist/src/app.js
CHANGED
|
@@ -207,14 +207,19 @@ function inputTypeOf(entry) {
|
|
|
207
207
|
* query parameter of that name.
|
|
208
208
|
*/
|
|
209
209
|
const bodyProperty = entry.route.bodyProperty;
|
|
210
|
+
/**
|
|
211
|
+
* **The body validator is found by its SCHEMA, never by its target.** A JSON body validates under
|
|
212
|
+
* `"json"` and a form body under `"form"`, so keying on the JSON target silently missed every
|
|
213
|
+
* form - measured on a clean install, `@header contentType: "application/x-www-form-urlencoded"`
|
|
214
|
+
* with a `Record` body still emitted the intersection and still did not compile. The schema
|
|
215
|
+
* identifier is the same fact whichever parser reads it.
|
|
216
|
+
*/
|
|
217
|
+
const bodyName = entry.names.body;
|
|
210
218
|
const parts = entry.validators
|
|
211
|
-
.filter(([
|
|
219
|
+
.filter(([, name]) => bodyProperty === undefined || name !== bodyName)
|
|
212
220
|
.map(([, name]) => `z.infer<typeof ${name}>`);
|
|
213
|
-
if (bodyProperty !== undefined) {
|
|
214
|
-
|
|
215
|
-
if (bodySchema !== undefined) {
|
|
216
|
-
parts.push(`{ ${objectKey(bodyProperty)}: z.infer<typeof ${bodySchema}> }`);
|
|
217
|
-
}
|
|
221
|
+
if (bodyProperty !== undefined && bodyName !== undefined) {
|
|
222
|
+
parts.push(`{ ${objectKey(bodyProperty)}: z.infer<typeof ${bodyName}> }`);
|
|
218
223
|
}
|
|
219
224
|
if (entry.route.rawBodyProperty !== undefined) {
|
|
220
225
|
const reader = rawBodyReaderFor(entry.route.requestContentTypes);
|
|
@@ -539,12 +544,14 @@ securityFor) {
|
|
|
539
544
|
}
|
|
540
545
|
// A dispatched body is in `validators` under the body target like any other, so there is
|
|
541
546
|
// nothing extra to spread: `byContentType` published it there whichever parser ran.
|
|
547
|
+
// Same rule as `inputTypeOf`: the body is identified by its schema, not by its target.
|
|
548
|
+
const bodyTarget = validators.find(([, name]) => name === entry.names.body)?.[0];
|
|
542
549
|
const pieces = validators.map(([target]) =>
|
|
543
550
|
/**
|
|
544
551
|
* A named body is assigned rather than spread, matching the input type above and the
|
|
545
552
|
* document, which states the parameters and the body as separate things.
|
|
546
553
|
*/
|
|
547
|
-
route.bodyProperty !== undefined && target ===
|
|
554
|
+
route.bodyProperty !== undefined && target === bodyTarget
|
|
548
555
|
? `${objectKey(route.bodyProperty)}: c.req.valid(${JSON.stringify(target)})`
|
|
549
556
|
: `...c.req.valid(${JSON.stringify(target)})`);
|
|
550
557
|
if (route.rawBodyProperty !== undefined) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "typespec-hono",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.0",
|
|
4
4
|
"description": "TypeSpec emitter: generate a Hono server, and the Zod validators it enforces, from an HTTP service definition, agreeing with the OpenAPI document @typespec/openapi3 publishes from the same source.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cloudflare-workers",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"provenance": true
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"typespec-http-zod": "^0.
|
|
47
|
+
"typespec-http-zod": "^0.16.0"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
50
|
"@hono/zod-openapi": "^1.4.0",
|