@redocly/cli 2.71.2 → 2.72.1
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/README.md +1 -1
- package/THIRD_PARTY_NOTICES +29 -7
- package/lib/chunks/{EHJ3FMW6.js → 2AW4F6ZZ.js} +1 -1
- package/lib/chunks/{3EQNI6CT.js → 2MF3MKAD.js} +1 -1
- package/lib/chunks/{UYZXI3NO.js → 2X2KHSF3.js} +1 -1
- package/lib/chunks/{YF4FMOTE.js → 3FA5W77S.js} +1 -1
- package/lib/chunks/{VPTYPV6P.js → 3FVHXIZN.js} +1 -1
- package/lib/chunks/{P5T6BIKW.js → 3N53VPSU.js} +1 -1
- package/lib/chunks/{KLGUZBJO.js → 3N73A66H.js} +1 -1
- package/lib/chunks/{JO76DPXR.js → 3WOXO2JS.js} +1 -1
- package/lib/chunks/{ORWIUECT.js → 4A5R4H5W.js} +1 -1
- package/lib/chunks/{NXREEI2S.js → 4LTPQZBP.js} +1 -1
- package/lib/chunks/{L325HIGK.js → 4QC7OVHI.js} +1 -1
- package/lib/chunks/{FDKY4PGX.js → 542GVIYM.js} +1 -1
- package/lib/chunks/5JF6EUWW.js +9 -0
- package/lib/chunks/{6X42UQ3O.js → 5MZU5MHZ.js} +1 -1
- package/lib/chunks/{DZT5NLUB.js → 5UPBGRBZ.js} +1 -1
- package/lib/chunks/{WO6IIVA3.js → 6LZX65VY.js} +8 -8
- package/lib/chunks/{NEWT5A6S.js → 6RTITFQA.js} +1 -1
- package/lib/chunks/{IQLQH23V.js → 6Y6B2SKE.js} +1 -1
- package/lib/chunks/765BYRQR.js +7 -0
- package/lib/chunks/{2TG3DP4I.js → 7NZS5HXU.js} +1 -1
- package/lib/chunks/{5CR6AOLY.js → A65OW7M7.js} +3 -3
- package/lib/chunks/ARUYNQHA.js +7 -0
- package/lib/chunks/BJ6Z66KZ.js +7 -0
- package/lib/chunks/{T77BOGYV.js → BWGBTYNU.js} +1 -1
- package/lib/chunks/{DM4EUYBB.js → BZTZIEWS.js} +2 -2
- package/lib/chunks/{4S6LRPCX.js → CBFNHKDJ.js} +1 -1
- package/lib/chunks/{OFIQ2EST.js → CYCPHJNX.js} +33 -33
- package/lib/chunks/DSBDKSRR.js +53 -0
- package/lib/chunks/E2CEKR6N.js +22 -0
- package/lib/chunks/{HRZLSSOF.js → EMWHLZB6.js} +1 -1
- package/lib/chunks/{DWXDCKZ7.js → ENIFTFYK.js} +1 -1
- package/lib/chunks/{BIS2ZFGS.js → ETJMQLWJ.js} +1 -1
- package/lib/chunks/{ADACRYTN.js → EU5WR2O3.js} +1 -1
- package/lib/chunks/{FAFMGLT6.js → FLQQ3VRQ.js} +1 -1
- package/lib/chunks/{BPJTNQBC.js → FZZACVYL.js} +1 -1
- package/lib/chunks/{N4GCIKY4.js → G7A4OE2M.js} +1 -1
- package/lib/chunks/{HP7UD4BA.js → GCAL2PYM.js} +1 -1
- package/lib/chunks/{MJ2NI6MR.js → GGHLD27S.js} +1 -1
- package/lib/chunks/{U4MI7HDM.js → GMPHU6KM.js} +1 -1
- package/lib/chunks/{HTFKP5HH.js → GWBLS542.js} +1 -1
- package/lib/chunks/{U2F3JOT2.js → GXILNSWK.js} +1 -1
- package/lib/chunks/{5AVTCY6F.js → HM7M6465.js} +1 -1
- package/lib/chunks/{5HPO77VR.js → I2JZXLJ6.js} +2 -2
- package/lib/chunks/I3YF3GEY.js +13 -0
- package/lib/chunks/{YWRFPTTI.js → IIQW437Z.js} +1 -1
- package/lib/chunks/{4H3DPQDW.js → IM4YIUUN.js} +1 -1
- package/lib/chunks/{LET2MPMU.js → JDMRVD45.js} +1 -1
- package/lib/chunks/{XVS7B4RZ.js → KIFXQTTL.js} +1 -1
- package/lib/chunks/{UVKUPD4U.js → L4VSY42B.js} +1 -1
- package/lib/chunks/LH3ONQEX.js +17 -0
- package/lib/chunks/{SSEMMWPY.js → LUNR7GV4.js} +1 -1
- package/lib/chunks/{LY6BDOEF.js → LY5MGNMA.js} +1 -1
- package/lib/chunks/{XQEXWC5L.js → MAACTVYP.js} +1 -1
- package/lib/chunks/{GFSMOHUE.js → MTKICX4T.js} +1 -1
- package/lib/chunks/{ZXOX7NF2.js → NMAWU5S4.js} +1 -1
- package/lib/chunks/{I4TK6NG7.js → PJHQKG7X.js} +1 -1
- package/lib/chunks/PTBPNZRZ.js +7 -0
- package/lib/chunks/{CZX7WE2R.js → PUZ5QSL3.js} +1 -1
- package/lib/chunks/{JRVXIEVC.js → PW2XFZOB.js} +1 -1
- package/lib/chunks/{TH44RKLO.js → QAT3DPT3.js} +1 -1
- package/lib/chunks/{QXXAC25O.js → R67IVFZH.js} +1 -1
- package/lib/chunks/RA4FAJM3.js +59 -0
- package/lib/chunks/{AZ5LIJEO.js → RF5LL2UZ.js} +1 -1
- package/lib/chunks/{JOUEVI3E.js → RQPH22PV.js} +1 -1
- package/lib/chunks/S3B562IT.js +7 -0
- package/lib/chunks/{3FR3456Q.js → S43EG4DB.js} +1 -1
- package/lib/chunks/{CER2D6ZD.js → S7VIXBKD.js} +7 -7
- package/lib/chunks/{VJZDR6KS.js → TFPMT2XD.js} +1529 -4
- package/lib/chunks/{AXGFQS75.js → U56BQ2BR.js} +2 -2
- package/lib/chunks/{KJNBOXDI.js → UOTHMCTM.js} +3 -3
- package/lib/chunks/{CR5TYFBN.js → VHZJNDWE.js} +2 -2
- package/lib/chunks/{BOTTA3HA.js → VOYPXV3Z.js} +1 -1
- package/lib/chunks/{UTEOWLD5.js → VS4MTPCM.js} +1 -1
- package/lib/chunks/{QTSECOQB.js → WEPGHS5R.js} +2 -2
- package/lib/chunks/{LKNL5LEV.js → WRKMMY3F.js} +1 -1
- package/lib/chunks/{7JS7JGWP.js → WTJ3S4D7.js} +1 -1
- package/lib/chunks/X22IMAJK.js +199 -0
- package/lib/chunks/{W7TN2XCW.js → X3FFOCXC.js} +1 -1
- package/lib/chunks/{CRJEY7P3.js → XTI7EXWX.js} +1 -1
- package/lib/chunks/{BH4FA7AH.js → YA5KTHFN.js} +1 -1
- package/lib/chunks/{Z6GFQV2Y.js → YA6D5EUI.js} +1 -1
- package/lib/chunks/{HMYFTLS7.js → ZFET6WME.js} +1 -1
- package/lib/chunks/{R32HBYOH.js → ZXB5O6JQ.js} +1 -1
- package/lib/eject-assets/AGENTS.md +1 -1
- package/lib/eject-assets/generators/cli/docs.ts +1 -1
- package/lib/eject-assets/generators/cli/engine-source.ts +1 -1
- package/lib/eject-assets/generators/cli/index.ts +2 -2
- package/lib/eject-assets/generators/cli/render.ts +1 -1
- package/lib/eject-assets/generators/go/client.ts +1 -1
- package/lib/eject-assets/generators/go/descriptor.ts +1 -1
- package/lib/eject-assets/generators/go/index.ts +2 -2
- package/lib/eject-assets/generators/go/models.ts +1 -1
- package/lib/eject-assets/generators/go/naming.ts +1 -1
- package/lib/eject-assets/generators/go/operations.ts +1 -1
- package/lib/eject-assets/generators/go/pagination.ts +1 -1
- package/lib/eject-assets/generators/go/types.ts +1 -1
- package/lib/eject-assets/generators/java/client.ts +66 -0
- package/lib/eject-assets/generators/java/descriptor.ts +72 -0
- package/lib/eject-assets/generators/java/index.ts +245 -0
- package/lib/eject-assets/generators/java/models.ts +362 -0
- package/lib/eject-assets/generators/java/naming.ts +135 -0
- package/lib/eject-assets/generators/java/operations.ts +300 -0
- package/lib/eject-assets/generators/java/pagination.ts +94 -0
- package/lib/eject-assets/generators/java/types.ts +103 -0
- package/lib/eject-assets/generators/mock/faker.ts +1 -1
- package/lib/eject-assets/generators/mock/index.ts +2 -2
- package/lib/eject-assets/generators/mock/render.ts +1 -1
- package/lib/eject-assets/generators/mock/sample.ts +1 -1
- package/lib/eject-assets/generators/mock/values.ts +1 -1
- package/lib/eject-assets/generators/php/client.ts +1 -1
- package/lib/eject-assets/generators/php/descriptor.ts +1 -1
- package/lib/eject-assets/generators/php/index.ts +2 -2
- package/lib/eject-assets/generators/php/models.ts +1 -1
- package/lib/eject-assets/generators/php/naming.ts +1 -1
- package/lib/eject-assets/generators/php/operations.ts +1 -1
- package/lib/eject-assets/generators/php/pagination.ts +1 -1
- package/lib/eject-assets/generators/php/types.ts +1 -1
- package/lib/eject-assets/generators/python/client.ts +1 -1
- package/lib/eject-assets/generators/python/descriptor.ts +1 -1
- package/lib/eject-assets/generators/python/index.ts +2 -2
- package/lib/eject-assets/generators/python/models.ts +1 -1
- package/lib/eject-assets/generators/python/naming.ts +1 -1
- package/lib/eject-assets/generators/python/operations.ts +1 -1
- package/lib/eject-assets/generators/python/pagination.ts +1 -1
- package/lib/eject-assets/generators/python/types.ts +1 -1
- package/lib/eject-assets/generators/swr/index.ts +2 -2
- package/lib/eject-assets/generators/swr/render.ts +1 -1
- package/lib/eject-assets/generators/tanstack-query/index.ts +2 -2
- package/lib/eject-assets/generators/tanstack-query/render.ts +1 -1
- package/lib/eject-assets/generators/transformers/index.ts +2 -2
- package/lib/eject-assets/generators/transformers/render.ts +1 -1
- package/lib/eject-assets/generators/typescript/banner.ts +1 -1
- package/lib/eject-assets/generators/typescript/client.ts +1 -1
- package/lib/eject-assets/generators/typescript/descriptor.ts +1 -1
- package/lib/eject-assets/generators/typescript/index.ts +2 -2
- package/lib/eject-assets/generators/typescript/inline-runtime.ts +1 -1
- package/lib/eject-assets/generators/typescript/operation-signature.ts +1 -1
- package/lib/eject-assets/generators/typescript/operation-types.ts +1 -1
- package/lib/eject-assets/generators/typescript/operations.ts +1 -1
- package/lib/eject-assets/generators/typescript/response-headers.ts +1 -1
- package/lib/eject-assets/generators/typescript/type-guards.ts +1 -1
- package/lib/eject-assets/generators/typescript/types.ts +1 -1
- package/lib/eject-assets/generators/zod/index.ts +2 -2
- package/lib/eject-assets/generators/zod/schemas.ts +1 -1
- package/lib/eject-assets/skills/client-generators/SKILL.md +1 -1
- package/lib/eject-assets/skills/java-generator/SKILL.md +161 -0
- package/lib/index.js +91 -90
- package/lib/skills/redocly-cli/SKILL.md +3 -1
- package/package.json +1 -1
- package/lib/chunks/2ZEKFWJQ.js +0 -13
- package/lib/chunks/3VOQMXIZ.js +0 -7
- package/lib/chunks/7GADNOVY.js +0 -9
- package/lib/chunks/FRQHCFKP.js +0 -199
- package/lib/chunks/J2EPFEBO.js +0 -17
- package/lib/chunks/JZATGVUO.js +0 -53
- package/lib/chunks/KNMNSDHR.js +0 -7
- package/lib/chunks/U5DIFWGH.js +0 -7
package/lib/chunks/J2EPFEBO.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { createRequire as __createRequire } from 'node:module';
|
|
2
|
-
import { fileURLToPath as __fileURLToPath } from 'node:url';
|
|
3
|
-
import { dirname as __pathDirname } from 'node:path';
|
|
4
|
-
const require = __createRequire(import.meta.url);
|
|
5
|
-
var __filename = __fileURLToPath(import.meta.url);
|
|
6
|
-
var __dirname = __pathDirname(__filename);
|
|
7
|
-
import{a as A}from"./3EQNI6CT.js";import{a as F,b as O,c as k,d as g}from"./WO6IIVA3.js";import{c as d,d as M}from"./N4GCIKY4.js";import{W as y,Y as C,Z as R,_ as $,ba as S,fa as s,la as l,ma as b}from"./FRQHCFKP.js";import"./NEWT5A6S.js";import"./RFWIIJFG.js";import{mkdir as z,writeFile as J}from"node:fs/promises";import V from"node:path";var E=20;function D(e){return e.total===0?void 0:Math.floor(e.covered/e.total*100)}function H(e){return e===void 0?"n/a":`${e}%`}function B(e,o){let t=e===void 0?0:Math.floor(e/100*E),r=`${"\u2588".repeat(t)}${"\u2591".repeat(E-t)}`;return!o||e===void 0?r:e>=80?R(r):e>=50?$(r):C(r)}function I(e,o){let t=[["operations",e.totals.operations],["parameters",e.totals.parameters],["schema properties",e.totals.properties],["response codes",e.totals.responses]],r=Math.max(...t.map(([,i])=>`${i.covered}/${i.total}`.length)),n="API coverage",a=[o?y(S(n)):n];for(let[i,c]of t){let f=D(c);a.push(` ${i.padEnd(18)} ${B(f,o)} ${H(f).padStart(5)} ${`${c.covered}/${c.total}`.padStart(r+3)}`)}return`${a.join(`
|
|
8
|
-
`)}
|
|
9
|
-
`}function T(e,o){let t={version:1,meta:{...o,exchanges:e.exchanges},totals:e.totals,operations:e.operations};return`${JSON.stringify(t,null,2)}
|
|
10
|
-
`}async function P(e){let o=await M(e.trafficPath);if(o.length===0)throw new Error("No traffic files found in the provided traffic path.");let t=O.create({openApiIndex:e.openApiIndex,matchMode:e.matchMode,ignoreCookies:e.ignoreCookies,ignoreHeaders:e.ignoreHeaders,previewFindingsLimit:e.previewFindingsLimit,activeRules:e.activeRules,server:e.server,minSeverity:e.minSeverity,coverage:e.coverage}),r=0,n=0;for(let a of o){let i=await A(a,e.format);if(!i){s.warn(`Skipping traffic file with unrecognized format: ${a}
|
|
11
|
-
`);continue}r+=1;for await(let c of i.parse(a))await t.process({...c,index:n}),n+=1}if(r===0)throw new Error("No supported traffic files found. In auto mode, files must match built-in traffic parser signatures.");if(n===0)throw new Error("No HTTP exchanges were parsed from the provided traffic files.");return t.finalize()}var L=!!process.stdout.isTTY&&process.env.NO_COLOR===void 0;function W(e){let o=new Set;for(let t of e.operationsByMethod.values())for(let r of t)for(let n of r.servers)o.add(n.rawUrl);return Array.from(o).sort()}function _(e,o,t){let r=e.totalExchanges-e.skippedExchanges;if(r===0&&e.skippedExchanges>0){s.warn(`All ${e.skippedExchanges} exchange(s) were outside the --server "${t}" and were skipped. Check that the server matches the traffic URLs.
|
|
12
|
-
`);return}if(e.documentedExchanges>0||r===0)return;let n=W(o),a=t?`Check that the --server "${t}" matches the traffic URLs and that the description paths align with the remainder.`:e.hostCompatibleExchanges===r?`The traffic hosts are compatible with the description servers (${n.join(", ")}), so the endpoints are likely undocumented; if they should be documented, check that the description base paths and paths align with the traffic URLs, or use --server to declare the server the traffic was captured against.`:`Check that the traffic host and base path match the description servers (${n.join(", ")}), or use --server to declare the server the traffic was captured against.`;s.warn(`None of the ${r} validated exchange(s) matched a documented operation. ${a}
|
|
13
|
-
`)}async function j(e,o){let t=d(e);await z(V.dirname(t),{recursive:!0}),await J(t,o,"utf8")}async function fe({argv:e,config:o}){let t=d(e.traffic),r=e["traffic-format"],n=e.rules?g(e.rules):void 0,a=e["ignore-headers"]?g(e["ignore-headers"]):void 0,i=e.server;if(i&&e["match-mode"])throw new l("The --server and --match-mode options are mutually exclusive: --match-mode controls how requests are located via the description servers, while --server replaces the description servers with the one the traffic was captured against.");let c=e["match-mode"]??"strict-host",f=d(e.api),u=await k(f,o);if(u.loadedOperations===0)throw new l(`No OpenAPI operations were loaded from: ${f}`);let p=e["coverage-output"],{runId:N,summary:m,findings:U,coverage:h}=await P({trafficPath:t,format:r,matchMode:c,ignoreCookies:e["ignore-cookies"],ignoreHeaders:a,previewFindingsLimit:e["max-findings"],activeRules:n,openApiIndex:u,server:i,minSeverity:e["min-severity"],coverage:e.coverage||p!==void 0});_(m,u,i);let v=F({runId:N,summary:m,findings:U,meta:{specSource:f,trafficPath:t,format:r,matchMode:c,server:i}},{format:e["report-format"],color:L&&e["report-format"]==="pretty"&&!e.output,maxFindings:e["max-findings"]});e.output?(await j(e.output,v),s.info(`Drift report written to: ${d(e.output)}
|
|
14
|
-
`)):s.output(v);let w=e["report-format"]!=="pretty"&&!e.output;if(e.coverage&&h){let x=I(h,L&&!w);w?s.info(`
|
|
15
|
-
${x}`):s.output(`
|
|
16
|
-
${x}`)}if(p&&h&&(await j(p,T(h,{spec:f,traffic:t,matchMode:c,server:i})),s.info(`Coverage report written to: ${d(p)}
|
|
17
|
-
`)),m.findingsBySeverity.error>0)throw new b("Drift detected.")}export{fe as handleDrift};
|
package/lib/chunks/JZATGVUO.js
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { createRequire as __createRequire } from 'node:module';
|
|
2
|
-
import { fileURLToPath as __fileURLToPath } from 'node:url';
|
|
3
|
-
import { dirname as __pathDirname } from 'node:path';
|
|
4
|
-
const require = __createRequire(import.meta.url);
|
|
5
|
-
var __filename = __fileURLToPath(import.meta.url);
|
|
6
|
-
var __dirname = __pathDirname(__filename);
|
|
7
|
-
import{a as ae,b as W,c as ce,d as pe}from"./2ZEKFWJQ.js";import{a as V}from"./3EQNI6CT.js";import{c as I,d as N,e as fe,h as G,j as _,k as ue,v as B,w as H}from"./N4GCIKY4.js";import{a as ie}from"./64G5RPLP.js";import"./XQEXWC5L.js";import{L as oe,M as v,c as y,fa as S,k as O,la as J,qa as se}from"./FRQHCFKP.js";import"./NEWT5A6S.js";import"./RFWIIJFG.js";import{mkdir as At,writeFile as jt}from"node:fs/promises";import kt from"node:path";var Ve=/^[a-zA-Z][a-zA-Z0-9]*(?:[_\-.][a-zA-Z0-9]+)*$/,Be=/^[0-9a-f-]{8,}$/i,He=[["uuid",/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i],["date-time",/^\d{4}-\d{2}-\d{2}[Tt]\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:[Zz]|[+-]\d{2}:\d{2})$/],["date",/^\d{4}-\d{2}-\d{2}$/],["email",/^[^\s@]+@[^\s@]+\.[^\s@]+$/],["uri",/^https?:\/\/\S+$/],["ipv4",/^(?:(?:25[0-5]|2[0-4]\d|1?\d?\d)\.){3}(?:25[0-5]|2[0-4]\d|1?\d?\d)$/]],x=new WeakMap;function z(e){return{formats:He.filter(([,t])=>t.test(e)).map(([t])=>t),values:[e],count:1,overflow:!1}}function q(e,t){if(!e)return t;if(!t)return e;let n={formats:e.formats.filter(r=>t.formats.includes(r)),values:[],count:e.count+t.count,overflow:e.overflow||t.overflow};if(!n.overflow){let r=[...e.values];for(let s of t.values)r.includes(s)||r.push(s);r.length>10?n.overflow=!0:n.values=r}return n}function D(e,t){x.set(e,t)}function U(e){return x.get(e)}function F(e,t){let n=x.get(e);n&&x.set(t,n)}function ze(e){return e.length<=30&&!Be.test(e)&&Ve.test(e)}function X(e,t){return e.formats.length>0?{format:e.formats[0]}:t&&!e.overflow&&e.count>=4&&e.values.length>0&&e.values.length<=5&&e.values.length*2<=e.count&&e.values.every(ze)?{enum:[...e.values].sort()}:{}}function $(e){let t=x.get(e);if(t){let n=typeof e.type=="string"?[e.type]:e.type??[];n.includes("string")&&Object.assign(e,X(t,n.length===1))}for(let n of Object.values(e.properties??{}))$(n);e.additionalProperties&&$(e.additionalProperties),e.items&&$(e.items);for(let n of e.oneOf??[])$(n)}function me(e){for(let t of Object.values(e.paths))for(let n of Object.values(t)){for(let r of Object.values(n.requestBody?.content??{}))$(r.schema);for(let r of Object.values(n.responses))for(let s of Object.values(r.content??{}))$(s.schema)}for(let t of Object.values(e.components?.schemas??{}))$(t);return e}var be=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i,Y=/^\d+$/,De=/^[0-9a-hjkmnp-tv-z]{26}$/i,Ue=/^[a-z][a-z0-9]*_(?=[0-9a-z]*\d)[0-9a-z]{10,}$/i,Fe=/^[a-z](?=[a-z0-9]*\d)[a-z0-9]{23,24}$/,Q=new Set(ie),Le=new Set(["get","head"]),de="application/x-www-form-urlencoded",le="multipart/form-data";function Ye(e){return e?Y.test(e)||be.test(e)||De.test(e)||Ue.test(e)||Fe.test(e)?!0:/^[0-9a-f]{16,}$/i.test(e):!1}function ee(e){let t=e.split("/"),n=[],r=new Set;return{template:t.map((o,a)=>{if(!Ye(o))return o;let i=t[a-1],c=i?`${O(i,1)}Id`:"id",p=1;for(;r.has(c);)p+=1,c=i?`${O(i,1)}Id${p}`:`id${p}`;return r.add(c),n.push({name:c,value:o}),`{${c}}`}).join("/")||"/",params:n}}function T(e){if(e===null)return{type:"null"};if(Array.isArray(e)){if(e.length===0)return{type:"array"};let t=e.slice(0,20).map(T);return{type:"array",items:E(t)}}switch(typeof e){case"string":{let t={type:"string"};return D(t,z(e)),t}case"boolean":return{type:"boolean"};case"number":return Number.isInteger(e)?{type:"integer"}:{type:"number"};case"object":{let t=Object.entries(e);if(t.length>0&&(t.every(([a])=>Y.test(a))||t.every(([a])=>be.test(a))))return{type:"object",additionalProperties:E(t.map(([,a])=>T(a)))};let n={},r=[];for(let[o,a]of t)n[o]=T(a),r.push(o);let s={type:"object",properties:n};return r.length>0&&(s.required=r),s}default:return{}}}function E(e){if(e.length===0)return{};let[t,...n]=e,r=t;for(let s of n)r=L(r,s);return r}function he(e){return Object.keys(e).length===0}function A(e){return e.additionalProperties?"map":e.type==="object"?"object":e.type==="array"?"array":"scalar"}function Z(e){return e.oneOf?e.oneOf.flatMap(Z):Array.isArray(e.type)?e.type.map(t=>{if(t==="object"){let r={type:"object"};return e.properties&&(r.properties=e.properties),e.required&&(r.required=e.required),e.additionalProperties&&(r.additionalProperties=e.additionalProperties),r}if(t==="array")return e.items?{type:"array",items:e.items}:{type:"array"};let n={type:t};return t==="string"&&F(e,n),n}):[e]}var Ke=.5,We=3;function Oe(e,t){let n=Object.keys(e.properties??{}),r=Object.keys(t.properties??{});if(n.length===0||r.length===0)return 1;let s=new Set(r),o=n.filter(a=>s.has(a)).length;return o/(n.length+r.length-o)}function Xe(e,t){let n=A(e);if(n!==A(t))return!1;switch(n){case"scalar":return e.type===t.type||e.type==="integer"&&t.type==="number"||e.type==="number"&&t.type==="integer";case"object":return Oe(e,t)>=Ke;default:return!0}}function ve(e,t){switch(A(e)){case"scalar":{if(e.type!==t.type)return{type:"number"};if(e.type==="string"){let n=q(U(e),U(t));if(n){let r={type:"string"};return D(r,n),r}}return e}case"map":return{type:"object",additionalProperties:L(e.additionalProperties??{},t.additionalProperties??{})};case"object":{let n={...e.properties??{}};for(let[a,i]of Object.entries(t.properties??{}))n[a]=n[a]?L(n[a],i):i;let r=new Set(t.required??[]),s=(e.required??[]).filter(a=>r.has(a)),o={type:"object",properties:n};return s.length>0&&(o.required=s),o}case"array":{if(!e.items||!t.items){let n=e.items??t.items;return n?{type:"array",items:n}:{type:"array"}}return{type:"array",items:L(e.items,t.items)}}}}function Ze(e){let t=[...e],n=()=>t.filter(r=>A(r)==="object").length;for(;n()>We;){let r=-1,s=-1,o=-1;for(let a=0;a<t.length;a++)if(A(t[a])==="object")for(let i=a+1;i<t.length;i++){if(A(t[i])!=="object")continue;let c=Oe(t[a],t[i]);c>o&&(o=c,r=a,s=i)}t[r]=ve(t[r],t[s]),t.splice(s,1)}return t}var Qe=["boolean","integer","number","string","null"];function et(e){if(e.length===1)return e[0];let t=[],n=new Set,r;for(let i of e)A(i)==="scalar"&&typeof i.type=="string"?(n.add(i.type),i.type==="string"&&(r=q(r,U(i)))):t.push(i);let s=Qe.filter(i=>n.has(i)),o=i=>{let c={type:i};return(typeof i=="string"?i==="string":i.includes("string"))&&r&&D(c,r),c};if(t.length===0)return s.length===1?o(s[0]):o(s);if(t.length===1&&s.length===1&&s[0]==="null"&&typeof t[0].type=="string")return{...t[0],type:[t[0].type,"null"]};let a=[...t];return s.length===1?a.push(o(s[0])):s.length>1&&a.push(o(s)),{oneOf:a}}function L(e,t){if(he(e)||he(t))return{};let n=Z(e);for(let r of Z(t)){let s=n.findIndex(o=>Xe(o,r));s===-1?n.push(r):n[s]=ve(n[s],r)}return et(Ze(n))}function tt(e){if(!e)return;let t=e.trim();if(!(!t.startsWith("{")&&!t.startsWith("[")))try{return JSON.parse(t)}catch{return}}function nt(e,t){let n=t?.match(/boundary="?([^";,]+)"?/i)?.[1];if(!n)return;let r={};for(let s of e.split(`--${n}`)){let o=s.match(/^\r?\n([\s\S]*?)\r?\n\r?\n([\s\S]*)\r?\n$/);if(!o)continue;let[,a,i]=o,c=a.match(/\bname="([^"]*)"/i)?.[1];c!==void 0&&(r[c]=/\bfilename="/i.test(a)?{type:"string",format:"binary"}:T(i))}if(Object.keys(r).length!==0)return{type:"object",properties:r,required:Object.keys(r)}}function ge(e){let t=_(e.contentType);if(e.bodyJson!==void 0)return{mime:ue(t)?t:"application/json",schema:T(e.bodyJson)};if(t===de&&e.bodyText){let r={};for(let[s,o]of new URLSearchParams(e.bodyText))r[s]=o;return Object.keys(r).length===0?void 0:{mime:de,schema:T(r)}}if(t===le&&e.bodyText){let r=nt(e.bodyText,e.contentType);return r?{mime:le,schema:r}:void 0}let n=tt(e.bodyText);if(n!==void 0)return{mime:"application/json",schema:T(n)}}function ye(e,t,n){let r=e.get(t);e.set(t,r?E([r,n]):n)}async function we(e){let t=await N(e.trafficPath);if(t.length===0)throw new Error("No traffic files found in the provided traffic path.");let n=B(e.server),r=new Map,s=new Set,o=0,a=0,i=p=>{let f=p.request.method.toLowerCase();if(!Q.has(f))return;let u=p.request.path||"/";if(n){let d=H(p.request,n);if(d===void 0)return;u=d}if(f==="query"&&e.openapiVersion==="3.1"){a+=1;return}!n&&p.request.host&&!fe(p.request.host)&&s.add(`${p.request.protocol}//${p.request.host}`);let{template:m,params:k}=ee(G(u)),P=`${f} ${m}`,l=r.get(P);l||(l={method:f,template:m,pathParams:new Map,queryParams:new Map,requestBodies:new Map,responses:new Map},r.set(P,l));for(let{name:d,value:g}of k){let h=l.pathParams.get(d);l.pathParams.set(d,{numeric:(h?.numeric??!0)&&Y.test(g),observations:q(h?.observations,z(g))})}for(let d of new Set(p.request.query.keys())){let g=p.request.query.getAll(d),h=l.queryParams.get(d),C=g.length>0&&g.every(R=>Y.test(R)),b=h?.observations;for(let R of g)b=q(b,z(R));l.queryParams.set(d,{numeric:(h?.numeric??!0)&&C,observations:b})}if(!Le.has(f)){let d=ge(p.request);d&&ye(l.requestBodies,d.mime,d.schema)}if(p.response&&p.response.status>=100){let d=String(p.response.status),g=l.responses.get(d);g||(g={bodies:new Map},l.responses.set(d,g)),g.statusText??=p.response.statusText||void 0;let h=ge(p.response);h&&ye(g.bodies,h.mime,h.schema)}};for(let p of t){let f=await V(p,e.format);if(!f){S.warn(`Skipping traffic file with unrecognized format: ${p}
|
|
8
|
-
`);continue}o+=1;for await(let u of f.parse(p))i(u)}if(o===0)throw new J("No supported traffic files found to generate an OpenAPI description from.");if(r.size===0&&a>0)throw new J("All observed HTTP exchanges use the QUERY method, which OpenAPI 3.1 does not support. Use --openapi-version 3.2 to include them.");if(r.size===0)throw new J(n?`No HTTP exchanges in the traffic matched the server "${n}".`:"No HTTP exchanges were observed in the traffic. Cannot generate an OpenAPI description.");let c=n?[n]:Array.from(s).sort();return rt(r,e.openapiVersion,e.title??"Generated API",c)}function Pe(e){return Object.values(e.paths).reduce((t,n)=>t+Object.keys(n).length,0)}function Se(e,t){if(e.numeric)return{type:"integer"};let n={type:"string"};return e.observations&&Object.assign(n,X(e.observations,t)),n}function rt(e,t,n,r){let s={};for(let o of e.values()){let a=s[o.template]??={},i=[...Array.from(o.pathParams).map(([p,f])=>({name:p,in:"path",required:!0,schema:Se(f,!1)})),...Array.from(o.queryParams).map(([p,f])=>({name:p,in:"query",required:!1,schema:Se(f,!0)}))],c={operationId:ot(o.method,o.template),responses:{}};if(i.length>0&&(c.parameters=i),o.requestBodies.size>0){let p={};for(let[f,u]of o.requestBodies)p[f]={schema:u};c.requestBody={content:p}}if(o.responses.size===0)c.responses.default={description:"Observed response"};else for(let[p,f]of o.responses){let u={description:f.statusText||"Observed response"};if(f.bodies.size>0){let m={};for(let[k,P]of f.bodies)m[k]={schema:P};u.content=m}c.responses[p]=u}a[o.method]=c}return{openapi:`${t}.0`,info:{title:n,version:"1.0.0"},...r.length>0?{servers:r.map(o=>({url:o}))}:{},paths:s}}function ot(e,t){let n=t.split("/").filter(Boolean).map(r=>r.replace(/[{}]/g,"")).join("-");return`${e}-${n||"root"}`}function K(e,t){return`${e.toUpperCase()} ${t}`}function $e(e,t){let n;if(e.bodyJson!==void 0)try{n=JSON.stringify(e.bodyJson)}catch{n=void 0}if(n??=e.bodyText,!n)return;let r=n.trim();if(r)return r.length>t?`${r.slice(0,t)}\u2026[truncated]`:r}function Te(e){if(!e)return"";let t=e.bodyJson;return t===void 0?e.bodyText?_(e.contentType)||"text":"":t===null?"null":Array.isArray(t)?`array<${t.length>0?Ae(t[0]):""}>`:Ae(t)}function Ae(e){return y(e)?Object.keys(e).sort().join(","):e===null?"null":typeof e}async function je(e){let t=e.perGroup??2,n=e.perOperation??4,r=e.maxBodyChars??2e3,s=B(e.server),o=await N(e.trafficPath),a=new Map;for(let c of o){let p=await V(c,e.format);if(p)for await(let f of p.parse(c)){let u=f.request.method.toUpperCase();if(!Q.has(u.toLowerCase()))continue;let m=f.request.path||"/";if(s){let R=H(f.request,s);if(R===void 0)continue;m=R}let k=G(m),{template:P}=ee(k),l=f.response&&f.response.status>=100?f.response:void 0,d=l?.status,g=`${Te(f.request)}\u2192${Te(l)}`,h=a.get(K(u,P));h||(h=new Map,a.set(K(u,P),h));let C=`${d??""} ${g}`,b=h.get(C);b||(b=[],h.set(C,b)),!(b.length>=t)&&b.push({method:u,path:k,query:f.request.query.toString(),status:d,requestContentType:f.request.contentType,requestBody:$e(f.request,r),responseContentType:l?.contentType,responseBody:l?$e(l,r):void 0})}}let i=new Map;for(let[c,p]of a){let f=[];for(let u=0;u<t&&f.length<n;u++)for(let m of p.values()){if(f.length>=n)break;m[u]&&f.push(m[u])}i.set(c,f)}return i}var st=e=>`You are an expert API designer. You are given one operation from an OpenAPI ${e} description that was inferred mechanically from recorded HTTP traffic, the component schemas it references, and a sample of the real recorded HTTP exchanges for that operation. The inferred description is only a hypothesis: types are coarse, every observed property is marked required, and descriptions are missing. Alternative body shapes observed in the traffic appear as "oneOf" variants or type unions. Common string formats (uuid, date-time, date, email, uri, ipv4) and small closed enums are detected conservatively from the observed values.
|
|
9
|
-
|
|
10
|
-
Refine the operation into the most accurate OpenAPI ${e} definition you can justify from the evidence, while staying conservative:
|
|
11
|
-
- Keep the path template and the HTTP method exactly as given. Do not rename path parameters, do not move parameters to the path item level, and keep every response status code. The result is programmatically checked and rejected otherwise.
|
|
12
|
-
- Keep the operationId unless it is clearly wrong.
|
|
13
|
-
- Narrow property types where the samples clearly support it (formats such as date-time, uuid, email, uri; integer vs number; enums when a field only ever takes a small fixed set of values). Verify the formats and enums already detected against the samples; correct or extend them where justified. The detected formats and enums were derived from the full recorded traffic while you see only a subset of it, so never remove a detected format or enum value merely because the samples do not show it \u2014 correct one only when a sample contradicts it.
|
|
14
|
-
- Relax "required" for properties that are plausibly optional (e.g. absent in some samples, or clearly nullable). Express nullable values as type unions such as ["string", "null"].
|
|
15
|
-
- When a request or response body has alternative shapes \u2014 the baseline shows "oneOf" variants, or the samples show clearly different payloads \u2014 model them explicitly with "oneOf". Name each variant in components/schemas, and add a "discriminator" when a property (such as "type" or "kind") selects the variant.
|
|
16
|
-
- Factor structure shared between variants or schemas with "allOf": extract the common base into components/schemas and compose each variant as "allOf" of the base plus its specific properties.
|
|
17
|
-
- Keep the $ref references to the component schemas you were given. You may refine the definition of a referenced component when the samples justify it, and you may add new components, but never rename an existing component and never reuse a reserved component name listed in the input.
|
|
18
|
-
- Add concise, useful "summary" and "description" fields to the operation, its parameters and important schema properties.
|
|
19
|
-
- Add example values drawn from the real samples where helpful, but never copy values that look like secrets or personal data (tokens, API keys, passwords, session identifiers, email addresses, personal names); use clearly fictional placeholder values instead.
|
|
20
|
-
|
|
21
|
-
Output ONLY a YAML document with this exact top-level structure:
|
|
22
|
-
|
|
23
|
-
paths:
|
|
24
|
-
<the path template exactly as given>:
|
|
25
|
-
<the method>:
|
|
26
|
-
...the refined operation...
|
|
27
|
-
components:
|
|
28
|
-
schemas:
|
|
29
|
-
...only the component schemas you changed or added; omit "components" entirely when there are none...
|
|
30
|
-
|
|
31
|
-
Do not wrap the output in Markdown code fences. Do not add any commentary before or after the document.`;function it(e){return e.length===0?"(no sample exchanges were captured)":e.map((t,n)=>{let r=[],s=t.query?`?${t.query}`:"";return r.push(`### Exchange ${n+1}`),r.push(`${t.method} ${t.path}${s}`),t.requestContentType&&r.push(`Request Content-Type: ${t.requestContentType}`),t.requestBody&&r.push(`Request body: ${t.requestBody}`),t.status!==void 0&&r.push(`Response status: ${t.status}`),t.responseContentType&&r.push(`Response Content-Type: ${t.responseContentType}`),t.responseBody&&r.push(`Response body: ${t.responseBody}`),r.join(`
|
|
32
|
-
`)}).join(`
|
|
33
|
-
|
|
34
|
-
`)}function ke(e){let t=[];return t.push(`# Operation to refine (inferred from traffic)
|
|
35
|
-
|
|
36
|
-
\`\`\`yaml
|
|
37
|
-
${v({paths:{[e.path]:{[e.method]:e.operation}}})}\`\`\``),Object.keys(e.components).length>0&&t.push(`# Component schemas referenced by this operation (current definitions)
|
|
38
|
-
|
|
39
|
-
\`\`\`yaml
|
|
40
|
-
${v({components:{schemas:e.components}})}\`\`\``),e.reservedComponentNames.length>0&&t.push(`# Reserved component names (used elsewhere in the description; do not redefine or reuse them)
|
|
41
|
-
|
|
42
|
-
${e.reservedComponentNames.join(", ")}`),t.push(`# Recorded HTTP exchanges for this operation
|
|
43
|
-
|
|
44
|
-
${it(e.samples)}`),t.push(`Refine ${e.method.toUpperCase()} ${e.path} as instructed and output only the YAML document.`),{system:st(e.openapiVersion),user:t.join(`
|
|
45
|
-
|
|
46
|
-
`)}}var Re=/^#\/components\/schemas\/(.+)$/;function te(e,t){if(Array.isArray(e)){for(let n of e)te(n,t);return}if(y(e)){if(typeof e.$ref=="string"){let n=e.$ref.match(Re);n&&t.add(n[1])}if(y(e.discriminator)&&y(e.discriminator.mapping)){for(let n of Object.values(e.discriminator.mapping))if(typeof n=="string"){let r=n.match(Re);t.add(r?r[1]:n)}}for(let n of Object.values(e))te(n,t)}}function Je(e,t){let n=new Set,r=[e];for(;r.length>0;){let s=new Set;te(r.pop(),s);for(let o of s)!n.has(o)&&o in t&&(n.add(o),r.push(t[o]))}return n}function at(e){let t=e.components?.schemas;if(!t)return;let n=Je(e.paths,t);for(let r of Object.keys(t))n.has(r)||delete t[r];Object.keys(t).length===0&&delete e.components}function ct(e,t,n){let r=ae(e),s;try{s=oe(r)}catch(f){throw new Error(`the provider did not return valid YAML: ${f instanceof Error?f.message:String(f)}`)}if(!y(s))throw new Error('the response is not a YAML document with a "paths" object');let o=s.paths;if(!y(o))throw new Error('the response is not a YAML document with a "paths" object');let a=o[t];if(!y(a))throw new Error(`the response does not keep the path template "${t}"`);let i=a[n];if(!y(i))throw new Error(`the response does not contain the ${n.toUpperCase()} operation`);let c=s.components,p=y(c)?c.schemas:void 0;return{operation:i,components:y(p)?p:{}}}function pt(e,t){let n=y(t.responses)?t.responses:{};return Object.keys(e.responses).filter(r=>!(r in n))}async function ft(e){let t=e.document.components?.schemas??{},n=Je(e.operation,t),r={};for(let m of n)r[m]=t[m];let s=Object.keys(t).filter(m=>!n.has(m)),{system:o,user:a}=ke({openapiVersion:e.document.openapi,path:e.path,method:e.method,operation:e.operation,components:r,reservedComponentNames:s,samples:e.samples}),{text:i}=await ce(e.provider,{system:o,user:a,model:e.model}),c=ct(i,e.path,e.method),p=pt(e.operation,c.operation);if(p.length>0)throw new Error(`the response dropped observed response status(es): ${p.join(", ")}`);if(typeof c.operation.operationId!="string")throw new Error("the response dropped the operationId");let f=Object.keys(c.components).filter(m=>s.includes(m));if(f.length>0)throw new Error(`the response redefines reserved component(s): ${f.join(", ")}`);let u={openapi:e.document.openapi,info:e.document.info,paths:{[e.path]:{[e.method]:c.operation}},components:{schemas:{...t,...c.components}}};return await W(v(u),e.config),c}function ut(e,t,n,r){e.paths[t][n]=r.operation,Object.keys(r.components).length>0&&(e.components??={schemas:{}},Object.assign(e.components.schemas,r.components))}async function Ee(e){let t=structuredClone(e.baseline),n=await se({extends:["spec"]}),r=[];for(let[i,c]of Object.entries(e.baseline.paths))for(let[p,f]of Object.entries(c))r.push({path:i,method:p,operation:f});let o=(await pe({items:r,concurrency:e.concurrency??1,action:"Refining",successNote:"refined",failureNote:"kept the baseline",label:({path:i,method:c})=>`${c.toUpperCase()} ${i}`,run:async({path:i,method:c,operation:p})=>{let f=await ft({provider:e.provider,model:e.model,document:t,path:i,method:c,operation:p,samples:e.samplesByOperation.get(K(c,i))??[],config:n});return ut(t,i,c,f),f}})).filter(i=>i!==null).length;if(o===0)throw new Error(`the ${e.provider} provider did not produce a usable refinement for any operation`);at(t);let a=v(t);return await W(a,n),{yaml:a,document:t,refined:o,total:r.length}}var mt=2,dt=2,lt=.75,ht=2,Me=new Set(["integer","number"]),xe=new WeakMap;function w(e){let t=xe.get(e);if(t!==void 0)return t;let n;if(e.$ref!==void 0)n=`ref(${e.$ref})`;else if(e.oneOf)n=`oneOf(${e.oneOf.map(w).sort().join("|")})`;else{let s=[`type=${(Array.isArray(e.type)?[...e.type].sort().join(","):e.type)??""}`];if(e.properties){let o=Object.entries(e.properties).map(([a,i])=>`${JSON.stringify(a)}:${w(i)}`).sort().join(",");s.push(`props{${o}}`)}e.additionalProperties&&s.push(`values(${w(e.additionalProperties)})`),e.items&&s.push(`items(${w(e.items)})`),n=s.join(";")}return xe.set(e,n),n}function gt(e){return e.$ref===void 0&&e.type==="object"&&e.oneOf===void 0&&e.additionalProperties===void 0&&Object.keys(e.properties??{}).length>=mt}function qe(e,t){for(let n of t)e.set(n,(e.get(n)??0)+1)}function M(e,t,n){if(e.oneOf){e.oneOf.forEach((o,a)=>M(o,{...t,path:`${t.path}/oneOf/${a}`,fallbackHints:[]},n));return}let r=t.container,s=`${t.path}/`;if(gt(e)){let o=w(e),a=n.get(o);a||(a={keys:[o],schemas:[],merged:{},contexts:new Set,primaryVotes:new Map,fallbackVotes:new Map},n.set(o,a)),a.schemas.push(e),a.contexts.add(`${t.container}#${t.path}`),qe(a.primaryVotes,t.primaryHints),qe(a.fallbackVotes,t.fallbackHints),r=o,s=""}for(let[o,a]of Object.entries(e.properties??{}))M(a,{container:r,path:`${s}${o}`,primaryHints:[o],fallbackHints:[]},n);e.additionalProperties&&M(e.additionalProperties,{container:r,path:`${s}additionalProperties`,primaryHints:t.primaryHints.map(o=>O(o,1)),fallbackHints:t.fallbackHints.map(o=>O(o,1))},n),e.items&&M(e.items,{container:r,path:`${s}items`,primaryHints:t.primaryHints.map(o=>O(o,1)),fallbackHints:t.fallbackHints.map(o=>O(o,1))},n)}function yt(e){return e.split("/").filter(n=>n&&!n.startsWith("{")).at(-1)}function St(e){let t=new Map;for(let[n,r]of Object.entries(e.paths)){let s=yt(n),o=s?O(s,1):void 0;for(let[a,i]of Object.entries(r)){for(let[c,p]of Object.entries(i.requestBody?.content??{}))M(p.schema,{container:`request ${a} ${n} ${c}`,path:"",primaryHints:o?[o]:[],fallbackHints:o?[`${o} request`]:[]},t);for(let[c,p]of Object.entries(i.responses)){let f=Number(c)>=400;for(let[u,m]of Object.entries(p.content??{}))M(m.schema,{container:`response ${a} ${n} ${c} ${u}`,path:"",primaryHints:f?["error"]:o?[o]:[],fallbackHints:f?o?[`${o} error`]:[]:o?[`${o} response`]:[]},t)}}}return t}function Ce(e){return Object.keys(e.properties??{})}function bt(e,t){let n=Ce(e),r=new Set(Ce(t)),s=n.filter(a=>r.has(a)).length,o=n.length+r.size-s;return o===0?0:s/o}function Ie(e){if(e.$ref!==void 0||e.properties||e.additionalProperties||e.items||e.oneOf)return;let t=typeof e.type=="string"?[e.type]:e.type;if(!(!t||t.some(n=>n==="object"||n==="array")))return t}function ne(e){return Object.keys(e).length===0}function Ge(e,t){if(w(e)===w(t)||ne(e)||ne(t))return!0;let n=Ie(e),r=Ie(t);if(n&&r){let o=new Set(n.filter(i=>i!=="null")),a=new Set(r.filter(i=>i!=="null"));return o.size===a.size&&[...o].every(i=>a.has(i))?!0:[...o].every(i=>Me.has(i))&&[...a].every(i=>Me.has(i))}let s=o=>o.type==="array"||o.items!==void 0;return s(e)&&s(t)?!e.items||!t.items||Ge(e.items,t.items):!1}function Ot(e,t){let n=t.merged.properties??{};return Object.entries(e.merged.properties??{}).every(([r,s])=>!(r in n)||Ge(s,n[r]))}function vt(e){let t=[...e];for(;t.length>1;){let n=-1,r=-1,s=0;for(let i=0;i<t.length;i++)for(let c=i+1;c<t.length;c++){let p=bt(t[i].merged,t[c].merged);p>=lt&&p>s&&Ot(t[i],t[c])&&(s=p,n=i,r=c)}if(n===-1)break;let o=t[n],a=t[r];o.keys.push(...a.keys),o.schemas.push(...a.schemas),o.merged=E([o.merged,a.merged]);for(let i of a.contexts)o.contexts.add(i);for(let[i,c]of a.primaryVotes)o.primaryVotes.set(i,(o.primaryVotes.get(i)??0)+c);for(let[i,c]of a.fallbackVotes)o.fallbackVotes.set(i,(o.fallbackVotes.get(i)??0)+c);t.splice(r,1)}return t}function re(e,t){return e<t?-1:e>t?1:0}function wt(e){return e.split(/[^a-zA-Z0-9]+/).filter(Boolean).map(t=>t[0].toUpperCase()+t.slice(1)).join("")}function Ne(e){return[...e.entries()].sort(([t,n],[r,s])=>s-n||re(t,r)).map(([t])=>t)}function Pt(e){let t=[...e].sort((r,s)=>s.contexts.size-r.contexts.size||s.schemas.length-r.schemas.length||re(r.keys[0],s.keys[0])),n=new Set;return t.map(r=>{let s=[...Ne(r.primaryVotes),...Ne(r.fallbackVotes)].map(wt).filter(a=>a.length>0);s.length===0&&s.push("Schema");let o=s.find(a=>!n.has(a));for(let a=2;o===void 0;a++){let i=`${s[0]}${a}`;n.has(i)||(o=i)}return n.add(o),{group:r,name:o}})}function j(e,t,n=!1){if(!n){let s=t.get(w(e));if(s!==void 0)return{$ref:`#/components/schemas/${s}`}}let r={...e};return F(e,r),e.properties&&(r.properties=Object.fromEntries(Object.entries(e.properties).map(([s,o])=>[s,j(o,t)]))),e.additionalProperties&&(r.additionalProperties=j(e.additionalProperties,t)),e.items&&(r.items=j(e.items,t)),e.oneOf&&(r.oneOf=e.oneOf.map(s=>j(s,t))),r}function $t(e){let t=Object.values(e.properties??{}),n=t.filter(r=>r.type==="array"&&(!r.items||ne(r.items)));return n.length>0&&t.length-n.length<=ht}function Tt(e){let t=0,n=0;for(let r of e.primaryVotes.values())t+=r,n=Math.max(n,r);return n*2>t}function _e(e){let t=St(e);for(let i of t.values())i.merged=E(i.schemas);let r=vt([...t.values()]).filter(i=>i.contexts.size>=dt&&(Tt(i)||!i.schemas.some($t)));if(r.length===0)return e;let s=Pt(r),o=new Map;for(let{group:i,name:c}of s)for(let p of i.keys)o.set(p,c);let a={};for(let{group:i,name:c}of[...s].sort((p,f)=>re(p.name,f.name)))a[c]=j(i.merged,o,!0);for(let i of Object.values(e.paths))for(let c of Object.values(i)){for(let p of Object.values(c.requestBody?.content??{}))p.schema=j(p.schema,o);for(let p of Object.values(c.responses))for(let f of Object.values(p.content??{}))f.schema=j(f.schema,o)}return e.components={schemas:a},e}async function Rt(e,t){let n=I(e);await At(kt.dirname(n),{recursive:!0}),await jt(n,t,"utf8")}function Jt(e){let t=Math.round(e/1e3),n=Math.floor(t/60),r=t%60;return n>0?`${n}m ${r}s`:`${r}s`}async function gn({argv:e}){if(e.type!=="openapi")throw new J(`Unsupported spec type "${e.type}". Only "openapi" is supported.`);let t=Date.now(),n=I(e.traffic),r=e["traffic-format"],s=me(_e(await we({trafficPath:n,format:r,openapiVersion:e["openapi-version"],title:e.title,server:e.server})));S.info(`Inferred a baseline OpenAPI description from traffic: ${Pe(s)} operation(s).
|
|
47
|
-
`);let o=v(s);if(e["with-ai"]){let a=e["ai-provider"];S.info(`Refining the description with AI provider "${a}"...
|
|
48
|
-
`),S.warn(`Note: --with-ai sends samples of the recorded traffic (URLs, query strings, request and response bodies) to the selected AI provider. Make sure the traffic contains no secrets or personal data you are not allowed to share.
|
|
49
|
-
`);let i=await je({trafficPath:n,format:r,server:e.server});try{let c=await Ee({provider:a,model:e["ai-model"],baseline:s,samplesByOperation:i,concurrency:e["ai-concurrency"]});o=c.yaml,S.info(`AI refinement complete: ${c.refined} of ${c.total} operation(s) refined (${a}).
|
|
50
|
-
`)}catch(c){S.warn(`AI refinement failed, falling back to the baseline description: ${c instanceof Error?c.message:String(c)}
|
|
51
|
-
`)}}e.output?(await Rt(e.output,o),S.info(`Written to: ${I(e.output)}
|
|
52
|
-
`)):S.output(o),S.info(`Done in ${Jt(Date.now()-t)}.
|
|
53
|
-
`)}export{gn as handleGenerateSpec};
|
package/lib/chunks/KNMNSDHR.js
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { createRequire as __createRequire } from 'node:module';
|
|
2
|
-
import { fileURLToPath as __fileURLToPath } from 'node:url';
|
|
3
|
-
import { dirname as __pathDirname } from 'node:path';
|
|
4
|
-
const require = __createRequire(import.meta.url);
|
|
5
|
-
var __filename = __fileURLToPath(import.meta.url);
|
|
6
|
-
var __dirname = __pathDirname(__filename);
|
|
7
|
-
import{a as l}from"./DZT5NLUB.js";import{a as R,b as u,c as f,d}from"./I4TK6NG7.js";import{d as y,e as G,f as x}from"./4S6LRPCX.js";import{c as g,d as S,e as h}from"./MJ2NI6MR.js";import{c as k,d as v,e as b}from"./6X42UQ3O.js";import{a as D,b as E,c as q,d as z}from"./CER2D6ZD.js";import{a as o}from"./HRZLSSOF.js";import{a,b as p,c as s}from"./HMYFTLS7.js";import"./VJZDR6KS.js";import{a as m}from"./EHJ3FMW6.js";import{a as i}from"./T77BOGYV.js";import{a as c}from"./JOUEVI3E.js";import"./5AVTCY6F.js";import{a as I,d as M,e as N}from"./L325HIGK.js";import{e as T,h as j,k as w}from"./R32HBYOH.js";import{a as rr,b as er,c as tr,d as or,e as nr,f as ar,g as pr,h as sr,i as mr,j as ir,k as cr}from"./DM4EUYBB.js";import{a as _,b as B,c as F,d as J,e as Q,f as H,g as K,h as P,i as V,j as W,k as X,l as Y,m as Z,n as $}from"./5CR6AOLY.js";import{a as U}from"./WZXA5XPB.js";import"./FRQHCFKP.js";import"./NEWT5A6S.js";import"./RFWIIJFG.js";var A={typescript:{run:a,sample:s,docs:p},zod:{run:m},transformers:{run:i},"tanstack-query":{run:o("react")},"tanstack-query-vue":{run:o("vue")},"tanstack-query-svelte":{run:o("svelte")},"tanstack-query-solid":{run:o("solid")},swr:{run:c},mock:{run:l},cli:{run:u,sample:d,docs:f},python:{run:y,sample:G,docs:x},go:{run:g,sample:S,docs:h},php:{run:k,sample:v,docs:b}},L=Object.fromEntries(Object.entries(D).map(([e,{load:r,...t}])=>[e,{...t,...A[e]}]));function n(){return new Map(Object.entries(L))}function C(e,r,t=n(),O){E(e,r,t,O)}function Er(e,r){let t=r.registry??n();return C(r.generators,r.emit,t,r.outputMode),q(e,{...r,registry:t})}export{cr as AUTHORING_HELPER_NAMES,U as NotSupportedError,_ as Printer,F as RESERVED_WORDS,B as casing,j as codeLiteral,Er as collectGeneratedFiles,H as deref,P as discriminatorCases,Y as docText,X as enumValues,K as flattenAllOf,z as generateClient,$ as headerCoerceType,J as identifierFor,ar as isBinaryContentType,or as isMultipartBody,V as isNullable,nr as isUntypedMultipartBody,er as jsonSuccessSchema,I as operationSignature,mr as paginationItemSchema,rr as paginationRuleFor,w as pascalCase,R as renderComposedCliEntry,ir as renderReferencePage,T as safeIdent,Z as schemaAtPointer,sr as securityRequirements,pr as serverUrlParts,tr as sseResponse,M as tsJsdoc,N as tsType,Q as uniqueIdentifiers,W as unwrapNullable};
|
package/lib/chunks/U5DIFWGH.js
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { createRequire as __createRequire } from 'node:module';
|
|
2
|
-
import { fileURLToPath as __fileURLToPath } from 'node:url';
|
|
3
|
-
import { dirname as __pathDirname } from 'node:path';
|
|
4
|
-
const require = __createRequire(import.meta.url);
|
|
5
|
-
var __filename = __fileURLToPath(import.meta.url);
|
|
6
|
-
var __dirname = __pathDirname(__filename);
|
|
7
|
-
var l={},c=new Set(["typescript","zod","tanstack-query","tanstack-query-vue","tanstack-query-svelte","tanstack-query-solid","swr","transformers","mock","cli","python","go","php"]),s=/import\s*(?:type\s*)?\{([^}]*)\}\s*from\s*['"]@redocly\/client-generator(?:\/generate)?['"]/g;function _(e,t){let o=new Set(t),r=new Set;for(let i of e.matchAll(s))for(let a of i[1].split(",")){let n=a.trim().replace(/^type\s+/,"").split(/\s+as\s+/)[0].trim();o.has(n)&&r.add(n)}return[...r]}var g=/^\/\/ Ejected from @redocly\/client-generator@([\w.-]+) — the built-in "([a-z-]+)" generator\./;function u(e){let t=e.match(g);if(!(!t||!c.has(t[2])))return{name:t[2],version:t[1]}}function p(e){return e.includes("Invalid pagination configuration")?"pagination":e.includes("Could not load generator")?"generator-load":/^Generator "[^"]+" failed:/.test(e)?"generator-run":e.includes("Unknown generator")||e.includes("does not support")?"not-supported":"other"}var d={};export{l as a,c as b,_ as c,u as d,p as e,d as f};
|