@hono/zod-openapi
Advanced tools
Comparing version 0.15.1 to 0.15.2
@@ -102,9 +102,27 @@ "use strict"; | ||
} | ||
if (/^application\/([a-z-\.]+\+)?json/.test(mediaType)) { | ||
if (isJSONContentType(mediaType)) { | ||
const validator = (0, import_zod_validator.zValidator)("json", schema, hook); | ||
validators.push(validator); | ||
const mw = async (c, next) => { | ||
if (c.req.header("content-type")) { | ||
if (isJSONContentType(c.req.header("content-type"))) { | ||
return await validator(c, next); | ||
} | ||
} | ||
c.req.addValidatedData("json", {}); | ||
await next(); | ||
}; | ||
validators.push(mw); | ||
} | ||
if (mediaType.startsWith("multipart/form-data") || mediaType.startsWith("application/x-www-form-urlencoded")) { | ||
if (isFormContentType(mediaType)) { | ||
const validator = (0, import_zod_validator.zValidator)("form", schema, hook); | ||
validators.push(validator); | ||
const mw = async (c, next) => { | ||
if (c.req.header("content-type")) { | ||
if (isFormContentType(c.req.header("content-type"))) { | ||
return await validator(c, next); | ||
} | ||
} | ||
c.req.addValidatedData("form", {}); | ||
await next(); | ||
}; | ||
validators.push(mw); | ||
} | ||
@@ -214,2 +232,8 @@ } | ||
} | ||
function isJSONContentType(contentType) { | ||
return /^application\/([a-z-\.]+\+)?json/.test(contentType); | ||
} | ||
function isFormContentType(contentType) { | ||
return contentType.startsWith("multipart/form-data") || contentType.startsWith("application/x-www-form-urlencoded"); | ||
} | ||
// Annotate the CommonJS export names for ESM import in node: | ||
@@ -216,0 +240,0 @@ 0 && (module.exports = { |
{ | ||
"name": "@hono/zod-openapi", | ||
"version": "0.15.1", | ||
"version": "0.15.2", | ||
"description": "A wrapper class of Hono which supports OpenAPI.", | ||
@@ -45,3 +45,3 @@ "main": "dist/index.js", | ||
"@cloudflare/workers-types": "^4.20240117.0", | ||
"hono": "^4.3.6", | ||
"hono": "^4.5.4", | ||
"jest": "^29.7.0", | ||
@@ -48,0 +48,0 @@ "tsup": "^8.0.1", |
@@ -272,3 +272,3 @@ # Zod OpenAPI Hono | ||
import { prettyJSON } from 'hono/pretty-json' | ||
import { cache } from 'honoc/cache' | ||
import { cache } from 'hono/cache' | ||
@@ -275,0 +275,0 @@ app.use(route.getRoutingPath(), prettyJSON(), cache({ cacheName: 'my-cache' })) |
Sorry, the diff of this file is not supported yet
45984
630