hono-openapi 0.4.1 → 0.4.3
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/arktype.d.cts +1 -1
- package/effect.d.cts +1 -1
- package/index.cjs +1 -1
- package/index.d.cts +1 -1
- package/index.js +1 -1
- package/package.json +1 -1
- package/src/helper.d.ts +2 -5
- package/typebox.d.cts +1 -1
- package/valibot.d.cts +1 -1
- package/zod.d.cts +1 -1
package/arktype.d.cts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from "./src/arktype
|
|
1
|
+
export * from "./src/arktype";
|
package/effect.d.cts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from "./src/effect
|
|
1
|
+
export * from "./src/effect";
|
package/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e=require("hono/http-exception"),t=require("./utils.cjs");const n=["GET","PUT","POST","DELETE","OPTIONS","HEAD","PATCH","TRACE"],s=e=>e.charAt(0).toUpperCase()+e.slice(1),o=(e,t)=>{let n=e;if("/"===t)return`${n}Index`;for(const e of t.split("/"))123===e.charCodeAt(0)?n+=`By${s(e.slice(1,-1))}`:n+=s(e);return n};function c({path:e,method:t,data:n,schema:s}){e=(e=>e.split("/").map((e=>{let t=e;return t.startsWith(":")&&(t=t.slice(1,t.length),t.endsWith("?")&&(t=t.slice(0,-1)),t=`{${t}}`),t})).join("/"))(e);const c=t.toLowerCase();s[e]={...s[e]?s[e]:{},[c]:{responses:{},...s[e]?.[c]??{},operationId:o(c,e),...n}}}function
|
|
1
|
+
"use strict";var e=require("hono/http-exception"),t=require("./utils.cjs");const n=["GET","PUT","POST","DELETE","OPTIONS","HEAD","PATCH","TRACE"],s=e=>e.charAt(0).toUpperCase()+e.slice(1),o=(e,t)=>{let n=e;if("/"===t)return`${n}Index`;for(const e of t.split("/"))123===e.charCodeAt(0)?n+=`By${s(e.slice(1,-1))}`:n+=s(e);return n};function c({path:e,method:t,data:n,schema:s}){e=(e=>e.split("/").map((e=>{let t=e;return t.startsWith(":")&&(t=t.slice(1,t.length),t.endsWith("?")&&(t=t.slice(0,-1)),t=`{${t}}`),t})).join("/"))(e);const c=t.toLowerCase();s[e]={...s[e]?s[e]:{},[c]:{responses:{},...s[e]?.[c]??{},operationId:o(c,e),...n}}}function a(e,{excludeStaticFile:t=!0,exclude:n=[]}){const s={},o=Array.isArray(n)?n:[n];for(const[n,c]of Object.entries(e))if(!(o.some((e=>"string"==typeof e?n===e:e.test(n)))||n.includes("*")||t&&n.includes("."))){for(const e of Object.keys(c)){const t=c[e];if(n.includes("{")){t.parameters||(t.parameters=[]);const e=n.split("/").filter((e=>e.startsWith("{")&&!t.parameters.find((t=>"path"===t.in&&t.name===e.slice(1,e.length-1)))));for(const n of e){const e=n.slice(1,n.length-1),s=t.parameters.findIndex((t=>"param"===t.in&&t.name===e));-1!==s?t.parameters[s].in="path":t.parameters.push({schema:{type:"string"},in:"path",name:e,required:!0})}}t.responses||(t.responses={200:{}})}s[n]=c}return s}async function i(e,{documentation:s={},excludeStaticFile:o=!0,exclude:i=[],excludeMethods:r=["OPTIONS"],excludeTags:p=[],defaultOptions:l}={documentation:{},excludeStaticFile:!0,exclude:[],excludeMethods:["OPTIONS"],excludeTags:[]},{version:d="3.1.0",components:m={}}={version:"3.1.0",components:{}},u){const h={version:d,components:m},f={};for(const s of e.routes){if(!(t.uniqueSymbol in s.handler))continue;if(r.includes(s.method))continue;if(!1===n.includes(s.method)&&"ALL"!==s.method)continue;const{resolver:e,metadata:o={}}=s.handler[t.uniqueSymbol],a=l?.[s.method],{docs:i,components:p}=await e({...h,...o},a);if(h.components={...h.components,...p??{}},"ALL"===s.method)for(const e of n)c({path:s.path,data:i,method:e,schema:f});else c({method:s.method,path:s.path,data:i,schema:f})}for(const e in f)for(const t in f[e]){const n=f[e][t]?.hide;n&&("boolean"==typeof n?n:u&&n(u))&&delete f[e][t]}return{openapi:h.version,...{...s,tags:s.tags?.filter((e=>!p?.includes(e?.name))),info:{title:"Hono Documentation",description:"Development documentation",version:"0.0.0",...s.info},paths:{...a(f,{excludeStaticFile:o,exclude:i}),...s.paths},components:{...s.components,schemas:{...h.components,...s.components?.schemas}}}}}exports.describeRoute=function(n){const{validateResponse:s,...o}=n;return Object.assign((async(t,o)=>{if(await o(),s&&n.responses){const s=t.res.status,o=t.res.headers.get("content-type");if(s&&o){const c=n.responses[s];if(c&&"content"in c&&c.content){const n=o.split(";")[0],s=c.content[n];if(s?.schema&&"validator"in s.schema)try{let e;const o=t.res.clone();if("application/json"===n?e=await o.json():"text/plain"===n&&(e=await o.text()),!e)throw new Error("No data to validate!");await s.schema.validator(e)}catch(t){throw new e.HTTPException(400,{message:"Response validation failed!",cause:t})}}}}}),{[t.uniqueSymbol]:{resolver:(e,t)=>async function(e,t,n={}){let s={};const o={...n,...t,responses:{...n?.responses,...t.responses}};for(const t of Object.keys(o.responses)){const n=o.responses[t];if(n&&"content"in n)for(const t of Object.keys(n.content??{})){const o=n.content?.[t];if(o&&(o.schema&&"builder"in o.schema)){const t=await o.schema.builder(e);o.schema=t.schema,t.components&&(s={...s,...t.components})}}}return{docs:o,components:s}}(e,o,t)}})},exports.generateSpecs=i,exports.openAPISpecs=function(e,t){const n={version:"3.1.0",components:{}};let s=null;return async o=>(s||(s=await i(e,t,n,o)),o.json(s))};
|
package/index.d.cts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from "./src/index
|
|
1
|
+
export * from "./src/index";
|
package/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{HTTPException as e}from"hono/http-exception";import{u as t}from"./utils.js";function n(n){const{validateResponse:s,...o}=n;return Object.assign((async(t,o)=>{if(await o(),s&&n.responses){const s=t.res.status,o=t.res.headers.get("content-type");if(s&&o){const c=n.responses[s];if(c&&"content"in c&&c.content){const n=o.split(";")[0],s=c.content[n];if(s?.schema&&"validator"in s.schema)try{let e;if("application/json"===n?e=await
|
|
1
|
+
import{HTTPException as e}from"hono/http-exception";import{u as t}from"./utils.js";function n(n){const{validateResponse:s,...o}=n;return Object.assign((async(t,o)=>{if(await o(),s&&n.responses){const s=t.res.status,o=t.res.headers.get("content-type");if(s&&o){const c=n.responses[s];if(c&&"content"in c&&c.content){const n=o.split(";")[0],s=c.content[n];if(s?.schema&&"validator"in s.schema)try{let e;const o=t.res.clone();if("application/json"===n?e=await o.json():"text/plain"===n&&(e=await o.text()),!e)throw new Error("No data to validate!");await s.schema.validator(e)}catch(t){throw new e(400,{message:"Response validation failed!",cause:t})}}}}}),{[t]:{resolver:(e,t)=>async function(e,t,n={}){let s={};const o={...n,...t,responses:{...n?.responses,...t.responses}};for(const t of Object.keys(o.responses)){const n=o.responses[t];if(n&&"content"in n)for(const t of Object.keys(n.content??{})){const o=n.content?.[t];if(o&&(o.schema&&"builder"in o.schema)){const t=await o.schema.builder(e);o.schema=t.schema,t.components&&(s={...s,...t.components})}}}return{docs:o,components:s}}(e,o,t)}})}const s=["GET","PUT","POST","DELETE","OPTIONS","HEAD","PATCH","TRACE"],o=e=>e.charAt(0).toUpperCase()+e.slice(1),c=(e,t)=>{let n=e;if("/"===t)return`${n}Index`;for(const e of t.split("/"))123===e.charCodeAt(0)?n+=`By${o(e.slice(1,-1))}`:n+=o(e);return n};function a({path:e,method:t,data:n,schema:s}){e=(e=>e.split("/").map((e=>{let t=e;return t.startsWith(":")&&(t=t.slice(1,t.length),t.endsWith("?")&&(t=t.slice(0,-1)),t=`{${t}}`),t})).join("/"))(e);const o=t.toLowerCase();s[e]={...s[e]?s[e]:{},[o]:{responses:{},...s[e]?.[o]??{},operationId:c(o,e),...n}}}function i(e,{excludeStaticFile:t=!0,exclude:n=[]}){const s={},o=Array.isArray(n)?n:[n];for(const[n,c]of Object.entries(e))if(!(o.some((e=>"string"==typeof e?n===e:e.test(n)))||n.includes("*")||t&&n.includes("."))){for(const e of Object.keys(c)){const t=c[e];if(n.includes("{")){t.parameters||(t.parameters=[]);const e=n.split("/").filter((e=>e.startsWith("{")&&!t.parameters.find((t=>"path"===t.in&&t.name===e.slice(1,e.length-1)))));for(const n of e){const e=n.slice(1,n.length-1),s=t.parameters.findIndex((t=>"param"===t.in&&t.name===e));-1!==s?t.parameters[s].in="path":t.parameters.push({schema:{type:"string"},in:"path",name:e,required:!0})}}t.responses||(t.responses={200:{}})}s[n]=c}return s}function r(e,t){const n={version:"3.1.0",components:{}};let s=null;return async o=>(s||(s=await p(e,t,n,o)),o.json(s))}async function p(e,{documentation:n={},excludeStaticFile:o=!0,exclude:c=[],excludeMethods:r=["OPTIONS"],excludeTags:p=[],defaultOptions:l}={documentation:{},excludeStaticFile:!0,exclude:[],excludeMethods:["OPTIONS"],excludeTags:[]},{version:d="3.1.0",components:m={}}={version:"3.1.0",components:{}},h){const f={version:d,components:m},u={};for(const n of e.routes){if(!(t in n.handler))continue;if(r.includes(n.method))continue;if(!1===s.includes(n.method)&&"ALL"!==n.method)continue;const{resolver:e,metadata:o={}}=n.handler[t],c=l?.[n.method],{docs:i,components:p}=await e({...f,...o},c);if(f.components={...f.components,...p??{}},"ALL"===n.method)for(const e of s)a({path:n.path,data:i,method:e,schema:u});else a({method:n.method,path:n.path,data:i,schema:u})}for(const e in u)for(const t in u[e]){const n=u[e][t]?.hide;n&&("boolean"==typeof n?n:h&&n(h))&&delete u[e][t]}return{openapi:f.version,...{...n,tags:n.tags?.filter((e=>!p?.includes(e?.name))),info:{title:"Hono Documentation",description:"Development documentation",version:"0.0.0",...n.info},paths:{...i(u,{excludeStaticFile:o,exclude:c}),...n.paths},components:{...n.components,schemas:{...f.components,...n.components?.schemas}}}}}export{n as describeRoute,p as generateSpecs,r as openAPISpecs};
|
package/package.json
CHANGED
package/src/helper.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { OpenAPIV3 } from "openapi-types";
|
|
2
|
-
import type { OpenAPIRoute } from "./types.js";
|
|
2
|
+
import type { OpenAPIRoute, OpenApiSpecsOptions } from "./types.js";
|
|
3
3
|
export declare const ALLOWED_METHODS: readonly ["GET", "PUT", "POST", "DELETE", "OPTIONS", "HEAD", "PATCH", "TRACE"];
|
|
4
4
|
export declare const toOpenAPIPath: (path: string) => string;
|
|
5
5
|
export declare const capitalize: (word: string) => string;
|
|
@@ -7,7 +7,4 @@ export declare const generateOperationId: (method: string, paths: string) => str
|
|
|
7
7
|
export declare function registerSchemaPath({ path, method: _method, data, schema, }: OpenAPIRoute & {
|
|
8
8
|
schema: Partial<OpenAPIV3.PathsObject>;
|
|
9
9
|
}): void;
|
|
10
|
-
export declare function filterPaths(paths: OpenAPIV3.PathsObject, { excludeStaticFile, exclude, }: {
|
|
11
|
-
excludeStaticFile: boolean;
|
|
12
|
-
exclude: (string | RegExp)[];
|
|
13
|
-
}): OpenAPIV3.PathsObject<{}, {}>;
|
|
10
|
+
export declare function filterPaths(paths: OpenAPIV3.PathsObject, { excludeStaticFile, exclude, }: Pick<OpenApiSpecsOptions, "excludeStaticFile" | "exclude">): OpenAPIV3.PathsObject<{}, {}>;
|
package/typebox.d.cts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from "./src/typebox
|
|
1
|
+
export * from "./src/typebox";
|
package/valibot.d.cts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from "./src/valibot
|
|
1
|
+
export * from "./src/valibot";
|
package/zod.d.cts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from "./src/zod
|
|
1
|
+
export * from "./src/zod";
|