@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
|
@@ -4,7 +4,7 @@ import { dirname as __pathDirname } from 'node:path';
|
|
|
4
4
|
const require = __createRequire(import.meta.url);
|
|
5
5
|
var __filename = __fileURLToPath(import.meta.url);
|
|
6
6
|
var __dirname = __pathDirname(__filename);
|
|
7
|
-
import{a as c}from"./
|
|
7
|
+
import{a as c}from"./GXILNSWK.js";import{h as s,l as a}from"./FLQQ3VRQ.js";import"./KFQC57GK.js";import{ca as t,ka as e,qa as i}from"./X22IMAJK.js";import"./6RTITFQA.js";import"./RFWIIJFG.js";async function y({argv:r,config:l,version:d}){let o=s(l,r.residency);try{let n=new a(d);r.verbose&&(e.info(`OAuth client initialized.
|
|
8
8
|
`),e.info(`Local credentials file path: ${n.credentialsFilePath}
|
|
9
9
|
`)),await n.login(o,c),e.output(t(`\u2705 Logged in
|
|
10
10
|
|
|
@@ -4,4 +4,4 @@ import { dirname as __pathDirname } from 'node:path';
|
|
|
4
4
|
const require = __createRequire(import.meta.url);
|
|
5
5
|
var __filename = __fileURLToPath(import.meta.url);
|
|
6
6
|
var __dirname = __pathDirname(__filename);
|
|
7
|
-
import{
|
|
7
|
+
import{qa as p}from"./X22IMAJK.js";import{spawn as l}from"node:child_process";import{existsSync as a}from"node:fs";import*as s from"node:path";var m=/[\\/](_npx|dlx)[\\/]/;function T(t,r){let o=`credential.${t}/.helper`,e=!m.test(process.argv[1]??"")&&d("redocly")?"redocly":`npx --yes @redocly/cli@${r}`;return[`${o}=`,`${o}=!REDOCLY_SUPPRESS_NOTIFICATIONS=true ${e} project git-credentials`]}async function x(t,{capture:r=!1}={}){return new Promise((o,i)=>{let e=l("git",t,{stdio:r?["ignore","pipe","ignore"]:"inherit",env:{...process.env,GIT_TERMINAL_PROMPT:"0"}}),c="";e.stdout?.on("data",n=>c+=n.toString()),e.on("error",n=>i(u(n))),e.on("close",n=>o({code:n??1,output:c.trim()}))})}function d(t){let r=process.platform==="win32"?[".cmd",".exe"]:[""];return(process.env.PATH??"").split(s.delimiter).some(o=>o&&r.some(i=>a(s.join(o,t+i))))}function u(t){return t.code==="ENOENT"?new p("git is not installed or not on PATH."):t}export{T as a,x as b};
|
|
@@ -4,7 +4,7 @@ import { dirname as __pathDirname } from 'node:path';
|
|
|
4
4
|
const require = __createRequire(import.meta.url);
|
|
5
5
|
var __filename = __fileURLToPath(import.meta.url);
|
|
6
6
|
var __dirname = __pathDirname(__filename);
|
|
7
|
-
import{
|
|
7
|
+
import{Q as D,R as h,S as O,W as C,ba as P,ca as j,d as E,da as S,e as x,ea as f,f as $,ia as b,k as l,ka as o,qa as a,u}from"./X22IMAJK.js";var y=["json","yaml","yml"];import*as i from"node:fs";import{basename as k,dirname as d,extname as g,join as T,resolve as m,relative as R}from"node:path";import*as p from"node:process";import{performance as F}from"perf_hooks";async function te(e,n){let r=!x(e)&&$(n.resolvedConfig.apis)?G(n):await W(e,n),c=r.filter(({path:s})=>!z(s));if(x(c)){for(let{path:s}of c)o.warn(`
|
|
8
8
|
${q(s)} ${P(`does not exist or is invalid.
|
|
9
9
|
|
|
10
10
|
`)}`);throw new a("Please provide a valid path.")}if(r.length===0)throw new a("No APIs were provided. Specify an API via the command argument or define one in your config.");return r}function w(e){return e.configPath?d(e.configPath):p.cwd()}function z(e){if(!e.trim())throw new a("Path cannot be empty.");return i.existsSync(e)||u(e)?e:void 0}function G(e){return Object.entries(e.resolvedConfig.apis||{}).map(([n,{root:t,output:r}])=>({path:u(t)?t:m(w(e),t),alias:n,output:r&&m(w(e),r)}))}function N(e,n){let t=w(e),r=e.resolvedConfig.apis?.[n];return r?{path:u(r.root)?r.root:m(t,r.root),alias:n,output:r.output&&m(t,r.output)}:{path:n,alias:Object.entries(e.resolvedConfig.apis||{}).find(([c,s])=>m(t,s.root)===m(n))?.[0]??void 0}}async function W(e,n){let{hasMagic:t,glob:r}=await import("./SJHPKWSD.js");return(await Promise.all(e.map(async c=>t(c)&&!u(c)?(await r(c,{cwd:w(n)})).map(I=>N(n,I)):N(n,c)))).flat()}function L(e){return p.env.NODE_ENV==="test"?"<test>ms":`${Math.ceil(F.now()-e)}ms`}function oe(e,n,t){let r=L(n);o.info(b(`
|
|
@@ -4,7 +4,7 @@ import { dirname as __pathDirname } from 'node:path';
|
|
|
4
4
|
const require = __createRequire(import.meta.url);
|
|
5
5
|
var __filename = __fileURLToPath(import.meta.url);
|
|
6
6
|
var __dirname = __pathDirname(__filename);
|
|
7
|
-
import{a as q}from"./
|
|
7
|
+
import{a as q}from"./GXILNSWK.js";import{A as _,h as H,l as B,v as z,x as K,y as V,z as Z}from"./FLQQ3VRQ.js";import"./KFQC57GK.js";import{b as J,d as M,e as Y,v as L}from"./YA5KTHFN.js";import{$ as v,X as N,ba as O,ca as A,da as j,ea as b,ga as y,ha as C,ia as R,k as h,ka as e,qa as w,ra as D,wa as S,za as g}from"./X22IMAJK.js";import"./6RTITFQA.js";import"./RFWIIJFG.js";import{dirname as le}from"node:path";function W(r,t,o,n){n&&e.info(C(v(`
|
|
8
8
|
\u2611\uFE0F Achieved Level: ${y(o)}
|
|
9
9
|
|
|
10
10
|
`))),e.output(`<?xml version="1.0" encoding="UTF-8"?>
|
|
@@ -4,7 +4,7 @@ import { dirname as __pathDirname } from 'node:path';
|
|
|
4
4
|
const require = __createRequire(import.meta.url);
|
|
5
5
|
var __filename = __fileURLToPath(import.meta.url);
|
|
6
6
|
var __dirname = __pathDirname(__filename);
|
|
7
|
-
import{
|
|
7
|
+
import{e as L}from"./TFPMT2XD.js";import{b as $,c as w,d as M,f as D,g as q,h as B,i as _,j as F,k as U}from"./4QC7OVHI.js";import{h as T,j as E}from"./BZTZIEWS.js";import{d as k,f as C,h as P,i as j,m as A}from"./ZXB5O6JQ.js";import{o as f,q as b,r as N,s as I,u as v}from"./A65OW7M7.js";import{join as x}from"node:path";var d="// Generated by @redocly/client-generator \u2014 do not edit by hand.\n// Source: OpenAPI description. Re-run `redocly generate-client` to update.";function S(e){return e.filter(t=>t.length>0).join(`
|
|
8
8
|
|
|
9
9
|
`)+`
|
|
10
10
|
`}function O(e){let t=["/**",` * ${j(`${e.title} (v${e.version})`)}`];if(e.description)for(let n of A(j(e.description)))t.push(` * ${n}`.replace(/ +$/,""));return t.push(" */"),t.join(`
|
|
@@ -4,7 +4,7 @@ import { dirname as __pathDirname } from 'node:path';
|
|
|
4
4
|
const require = __createRequire(import.meta.url);
|
|
5
5
|
var __filename = __fileURLToPath(import.meta.url);
|
|
6
6
|
var __dirname = __pathDirname(__filename);
|
|
7
|
-
import{c as f}from"./
|
|
7
|
+
import{c as f}from"./A65OW7M7.js";var u=/^[A-Za-z_$][A-Za-z0-9_$]*$/,o=f.typescript;function m(e){return u.test(e)}function E(e){return u.test(e)&&!o.has(e)}function p(e){let i=e.replace(/[^A-Za-z0-9_$]/g,"_");return(i===""||/^[0-9]/.test(i)||o.has(i))&&(i=`_${i}`),i}var l={"<":"\\u003C",">":"\\u003E","\u2028":"\\u2028","\u2029":"\\u2029"};function s(e){return JSON.stringify(e).replace(/[<>\u2028\u2029]/g,i=>l[i])}function L(e){return u.test(e)&&!o.has(e)?e:s(e)}function S(e,i){let n=p(e),r=n,t=2;for(;i.has(r);)r=`${n}_${t++}`;return i.add(r),r}var _=s;function c(e){if(typeof e=="string")return s(e);if(typeof e=="boolean"||e===null||typeof e=="number")return String(e);if(Array.isArray(e))return`[${e.map(c).join(", ")}]`;let i=Object.entries(e).map(([n,r])=>`${m(n)?n:s(n)}: ${c(r)}`);return i.length===0?"{}":`{ ${i.join(", ")} }`}function x(e){return e.replace(/\*\//g,"*\\/")}function y(e,i){let n=h(e,i);return n.length===0?void 0:n.join(`
|
|
8
8
|
`)}function h(e,i){let n=[];return e&&e.trim()&&n.push(...g($(e))),i&&n.push(...d(i)),n}function d(e){let i=[],n=(r,t)=>{t===void 0?i.push(`@${r}`):i.push(`@${r} ${t}`)};return e.minimum!==void 0&&n("minimum",e.minimum),e.maximum!==void 0&&n("maximum",e.maximum),e.exclusiveMinimum!==void 0&&n("exclusiveMinimum",e.exclusiveMinimum),e.exclusiveMaximum!==void 0&&n("exclusiveMaximum",e.exclusiveMaximum),e.minLength!==void 0&&n("minLength",e.minLength),e.maxLength!==void 0&&n("maxLength",e.maxLength),e.pattern!==void 0&&n("pattern",x(e.pattern)),e.minItems!==void 0&&n("minItems",e.minItems),e.maxItems!==void 0&&n("maxItems",e.maxItems),e.uniqueItems===!0&&n("uniqueItems"),e.format!==void 0&&n("format",e.format),e.deprecated===!0&&n("deprecated"),i}function g(e){let i=0,n=e.length;for(;i<n&&e[i]==="";)i++;for(;n>i&&e[n-1]==="";)n--;return e.slice(i,n)}function C(e){return e[0].toUpperCase()+e.slice(1)}function j(e){let i=e.split(/[-_]/).filter(n=>n.length>0).map((n,r)=>{let t=n.toLowerCase();return r===0?t:t.charAt(0).toUpperCase()+t.slice(1)}).join("");return p(i)}function $(e){return e.replace(/\r\n/g,`
|
|
9
9
|
`).split(`
|
|
10
10
|
`).map(i=>i.trimEnd())}export{m as a,E as b,p as c,s as d,L as e,S as f,_ as g,c as h,x as i,y as j,C as k,j as l,$ as m};
|
|
@@ -106,7 +106,7 @@ discriminated union on `kind`: `scalar`, `array`, `object`, `record`, `ref`,
|
|
|
106
106
|
| `isNullable(schema)` / `unwrapNullable(schema)` | Detect and strip `null` union members (`Optional[T]`, pointers, `Option<T>`). |
|
|
107
107
|
| `enumValues(schema)` | Values plus SCREAMING_SNAKE member-name suggestions. |
|
|
108
108
|
| `headerCoerceType(schema, model)` | Response-header coerce hint (`integer`/`number`/`boolean`/`string`) through refs, nullables, and allOf wrappers. |
|
|
109
|
-
| `casing` / `identifierFor(name, { style, reserved })` | camel/pascal/snake/screaming; keyword-safe identifiers (`RESERVED_WORDS.python/go/typescript` shipped).
|
|
109
|
+
| `casing` / `identifierFor(name, { style, reserved })` | camel/pascal/snake/screaming; keyword-safe identifiers (`RESERVED_WORDS.python/go/php/java/typescript` shipped). |
|
|
110
110
|
| `uniqueIdentifiers(names, { style, reserved, taken })` | The same, made unique among themselves and among names you already took — for a signature that takes one argument per parameter. |
|
|
111
111
|
| `Printer` | Indentation-aware text builder — no manual whitespace bookkeeping. |
|
|
112
112
|
| `docText(description)` | Description as trimmed lines for any comment syntax. |
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Ejected from @redocly/client-generator@0.
|
|
1
|
+
// Ejected from @redocly/client-generator@0.8.1 — the built-in "cli" generator.
|
|
2
2
|
// This file is yours: edit freely; the generated client stays machine-owned and is
|
|
3
3
|
// rebuilt by `redocly generate-client`. Newer generator versions merge in with
|
|
4
4
|
// `redocly eject-generator cli --update`.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Ejected from @redocly/client-generator@0.
|
|
1
|
+
// Ejected from @redocly/client-generator@0.8.1 — the built-in "cli" generator.
|
|
2
2
|
// This file is yours: edit freely; the generated client stays machine-owned and is
|
|
3
3
|
// rebuilt by `redocly generate-client`. Newer generator versions merge in with
|
|
4
4
|
// `redocly eject-generator cli --update`.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Ejected from @redocly/client-generator@0.
|
|
1
|
+
// Ejected from @redocly/client-generator@0.8.1 — the built-in "cli" generator.
|
|
2
2
|
// This file is yours: edit freely; the generated client stays machine-owned and is
|
|
3
3
|
// rebuilt by `redocly generate-client`. Newer generator versions merge in with
|
|
4
4
|
// `redocly eject-generator cli --update`.
|
|
@@ -86,5 +86,5 @@ export default {
|
|
|
86
86
|
docs: cliDocs,
|
|
87
87
|
requires: ["typescript","zod"],
|
|
88
88
|
errorModes: ["throw"],
|
|
89
|
-
requiresGenerator: '^0.
|
|
89
|
+
requiresGenerator: '^0.8.1',
|
|
90
90
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Ejected from @redocly/client-generator@0.
|
|
1
|
+
// Ejected from @redocly/client-generator@0.8.1 — the built-in "cli" generator.
|
|
2
2
|
// This file is yours: edit freely; the generated client stays machine-owned and is
|
|
3
3
|
// rebuilt by `redocly generate-client`. Newer generator versions merge in with
|
|
4
4
|
// `redocly eject-generator cli --update`.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Ejected from @redocly/client-generator@0.
|
|
1
|
+
// Ejected from @redocly/client-generator@0.8.1 — the built-in "go" generator.
|
|
2
2
|
// This file is yours: edit freely; the generated client stays machine-owned and is
|
|
3
3
|
// rebuilt by `redocly generate-client`. Newer generator versions merge in with
|
|
4
4
|
// `redocly eject-generator go --update`.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Ejected from @redocly/client-generator@0.
|
|
1
|
+
// Ejected from @redocly/client-generator@0.8.1 — the built-in "go" generator.
|
|
2
2
|
// This file is yours: edit freely; the generated client stays machine-owned and is
|
|
3
3
|
// rebuilt by `redocly generate-client`. Newer generator versions merge in with
|
|
4
4
|
// `redocly eject-generator go --update`.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Ejected from @redocly/client-generator@0.
|
|
1
|
+
// Ejected from @redocly/client-generator@0.8.1 — the built-in "go" generator.
|
|
2
2
|
// This file is yours: edit freely; the generated client stays machine-owned and is
|
|
3
3
|
// rebuilt by `redocly generate-client`. Newer generator versions merge in with
|
|
4
4
|
// `redocly eject-generator go --update`.
|
|
@@ -332,5 +332,5 @@ export default {
|
|
|
332
332
|
"argsStyle": "inputs follow the target language's own idiom",
|
|
333
333
|
"importExt": "the generated file has no relative imports"
|
|
334
334
|
},
|
|
335
|
-
requiresGenerator: '^0.
|
|
335
|
+
requiresGenerator: '^0.8.1',
|
|
336
336
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Ejected from @redocly/client-generator@0.
|
|
1
|
+
// Ejected from @redocly/client-generator@0.8.1 — the built-in "go" generator.
|
|
2
2
|
// This file is yours: edit freely; the generated client stays machine-owned and is
|
|
3
3
|
// rebuilt by `redocly generate-client`. Newer generator versions merge in with
|
|
4
4
|
// `redocly eject-generator go --update`.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Ejected from @redocly/client-generator@0.
|
|
1
|
+
// Ejected from @redocly/client-generator@0.8.1 — the built-in "go" generator.
|
|
2
2
|
// This file is yours: edit freely; the generated client stays machine-owned and is
|
|
3
3
|
// rebuilt by `redocly generate-client`. Newer generator versions merge in with
|
|
4
4
|
// `redocly eject-generator go --update`.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Ejected from @redocly/client-generator@0.
|
|
1
|
+
// Ejected from @redocly/client-generator@0.8.1 — the built-in "go" generator.
|
|
2
2
|
// This file is yours: edit freely; the generated client stays machine-owned and is
|
|
3
3
|
// rebuilt by `redocly generate-client`. Newer generator versions merge in with
|
|
4
4
|
// `redocly eject-generator go --update`.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Ejected from @redocly/client-generator@0.
|
|
1
|
+
// Ejected from @redocly/client-generator@0.8.1 — the built-in "go" generator.
|
|
2
2
|
// This file is yours: edit freely; the generated client stays machine-owned and is
|
|
3
3
|
// rebuilt by `redocly generate-client`. Newer generator versions merge in with
|
|
4
4
|
// `redocly eject-generator go --update`.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Ejected from @redocly/client-generator@0.
|
|
1
|
+
// Ejected from @redocly/client-generator@0.8.1 — the built-in "go" generator.
|
|
2
2
|
// This file is yours: edit freely; the generated client stays machine-owned and is
|
|
3
3
|
// rebuilt by `redocly generate-client`. Newer generator versions merge in with
|
|
4
4
|
// `redocly eject-generator go --update`.
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// Ejected from @redocly/client-generator@0.8.1 — the built-in "java" generator.
|
|
2
|
+
// This file is yours: edit freely; the generated client stays machine-owned and is
|
|
3
|
+
// rebuilt by `redocly generate-client`. Newer generator versions merge in with
|
|
4
|
+
// `redocly eject-generator java --update`.
|
|
5
|
+
// The `client` stage: the `Servers` helper class of one static method per
|
|
6
|
+
// declared server.
|
|
7
|
+
|
|
8
|
+
import {
|
|
9
|
+
type ApiModel,
|
|
10
|
+
identifierFor,
|
|
11
|
+
type ServerModel,
|
|
12
|
+
serverUrlParts,
|
|
13
|
+
} from '@redocly/client-generator';
|
|
14
|
+
import type { JavaPrinter } from '@redocly/client-generator/printers/java';
|
|
15
|
+
|
|
16
|
+
import { JAVA, javaString, memberName } from './naming.ts';
|
|
17
|
+
|
|
18
|
+
/** The server URL as a Java expression: literals concatenated with declared-variable args. */
|
|
19
|
+
function serverUrlExpression(server: ServerModel): string {
|
|
20
|
+
const parts = serverUrlParts(server).map((part) =>
|
|
21
|
+
part.kind === 'literal' ? javaString(part.value) : memberName(part.name)
|
|
22
|
+
);
|
|
23
|
+
return parts.join(' + ');
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** One static method per declared server; server variables become String arguments. */
|
|
27
|
+
export function writeServers(printer: JavaPrinter, model: ApiModel): void {
|
|
28
|
+
const servers = model.servers ?? [];
|
|
29
|
+
if (servers.length === 0) return;
|
|
30
|
+
const usedNames = new Set<string>();
|
|
31
|
+
printer.line("/** The declared servers; the description's defaults are in each method's doc. */");
|
|
32
|
+
printer.block(
|
|
33
|
+
'public static final class Servers {',
|
|
34
|
+
() => {
|
|
35
|
+
servers.forEach((server, index) => {
|
|
36
|
+
let name = identifierFor(server.description ?? `server${index + 1}`, {
|
|
37
|
+
style: 'camel',
|
|
38
|
+
reserved: JAVA,
|
|
39
|
+
});
|
|
40
|
+
if (usedNames.has(name)) name = `${name}${index + 1}`;
|
|
41
|
+
usedNames.add(name);
|
|
42
|
+
const params = server.variables.map((variable) => `String ${memberName(variable.name)}`);
|
|
43
|
+
// Java has no default arguments; the spec default lives in the doc comment.
|
|
44
|
+
const defaults = server.variables
|
|
45
|
+
.map(
|
|
46
|
+
(variable) => `${memberName(variable.name)} default: ${javaString(variable.default)}`
|
|
47
|
+
)
|
|
48
|
+
.join(', ');
|
|
49
|
+
if (index > 0) printer.blank();
|
|
50
|
+
printer.doc(
|
|
51
|
+
name,
|
|
52
|
+
`The ${javaString(server.description ?? server.url)} base URL${defaults === '' ? '.' : ` (${defaults}).`}`
|
|
53
|
+
);
|
|
54
|
+
printer.block(
|
|
55
|
+
`public static String ${name}(${params.join(', ')}) {`,
|
|
56
|
+
() => {
|
|
57
|
+
printer.line(`return ${serverUrlExpression(server)};`);
|
|
58
|
+
},
|
|
59
|
+
'}'
|
|
60
|
+
);
|
|
61
|
+
});
|
|
62
|
+
},
|
|
63
|
+
'}'
|
|
64
|
+
);
|
|
65
|
+
printer.blank();
|
|
66
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
// Ejected from @redocly/client-generator@0.8.1 — the built-in "java" generator.
|
|
2
|
+
// This file is yours: edit freely; the generated client stays machine-owned and is
|
|
3
|
+
// rebuilt by `redocly generate-client`. Newer generator versions merge in with
|
|
4
|
+
// `redocly eject-generator java --update`.
|
|
5
|
+
// The `descriptor` stage: the per-operation `Operation` literal — security
|
|
6
|
+
// OR-alternatives and the pagination spec — and the envelope-header coerce specs.
|
|
7
|
+
|
|
8
|
+
import {
|
|
9
|
+
type ApiModel,
|
|
10
|
+
headerCoerceType,
|
|
11
|
+
type NeutralPaginationRule,
|
|
12
|
+
type OperationModel,
|
|
13
|
+
securityRequirements,
|
|
14
|
+
uniqueIdentifiers,
|
|
15
|
+
} from '@redocly/client-generator';
|
|
16
|
+
|
|
17
|
+
import { JAVA, javaString } from './naming.ts';
|
|
18
|
+
|
|
19
|
+
/** `List.of(List.of(SecuritySpec…))` for the operation's security OR-alternatives. */
|
|
20
|
+
export function javaSecurityLiteral(op: OperationModel, model: ApiModel): string {
|
|
21
|
+
const alternatives = securityRequirements(op, model).map((alternative) => {
|
|
22
|
+
const specs = alternative.map((spec) =>
|
|
23
|
+
spec.kind === 'apiKey'
|
|
24
|
+
? `new SecuritySpec(${javaString(spec.scheme)}, "apiKey", ${javaString(spec.name)}, ${javaString(spec.in)})`
|
|
25
|
+
: `SecuritySpec.of(${javaString(spec.scheme)}, ${javaString(spec.kind)})`
|
|
26
|
+
);
|
|
27
|
+
return `List.of(${specs.join(', ')})`;
|
|
28
|
+
});
|
|
29
|
+
return `List.of(${alternatives.join(', ')})`;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** The neutral rule as a `new PaginationSpec(…)` literal, or `null` when the operation does not paginate. */
|
|
33
|
+
export function javaPaginationLiteral(rule: NeutralPaginationRule | undefined): string {
|
|
34
|
+
if (rule === undefined) return 'null';
|
|
35
|
+
const field = (value: string | undefined) => (value === undefined ? 'null' : javaString(value));
|
|
36
|
+
return `new PaginationSpec(${[
|
|
37
|
+
javaString(rule.style),
|
|
38
|
+
field(rule.param),
|
|
39
|
+
field(rule.nextCursor),
|
|
40
|
+
field(rule.hasMore),
|
|
41
|
+
field(rule.nextLink),
|
|
42
|
+
field(rule.limitParam),
|
|
43
|
+
field(rule.items),
|
|
44
|
+
].join(', ')})`;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* The operation as the runtime describes it, built where it is used: a table of every
|
|
49
|
+
* operation in one static initializer would exceed the JVM's method size on a large
|
|
50
|
+
* description, and the record is a trivial allocation.
|
|
51
|
+
*/
|
|
52
|
+
export function javaOperationLiteral(
|
|
53
|
+
op: OperationModel,
|
|
54
|
+
model: ApiModel,
|
|
55
|
+
rule: NeutralPaginationRule | undefined
|
|
56
|
+
): string {
|
|
57
|
+
return `new Operation(${javaString(op.specName ?? op.name)}, ${javaString(op.method.toUpperCase())}, ${javaString(op.path)}, ${javaSecurityLiteral(op, model)}, ${javaPaginationLiteral(rule)})`;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** Declared response headers as runtime coerce specs: `{wire name, camelCase key, type}`. */
|
|
61
|
+
export function envelopeHeaderSpecs(op: OperationModel, model: ApiModel): string {
|
|
62
|
+
const headers = op.successResponseHeaders ?? [];
|
|
63
|
+
const keys = uniqueIdentifiers(
|
|
64
|
+
headers.map((header) => header.name),
|
|
65
|
+
{ style: 'camel', reserved: JAVA }
|
|
66
|
+
);
|
|
67
|
+
const specs = headers.map((header, index) => {
|
|
68
|
+
const type = headerCoerceType(header.schema, model);
|
|
69
|
+
return `{${javaString(header.name)}, ${javaString(keys[index])}, ${javaString(type)}}`;
|
|
70
|
+
});
|
|
71
|
+
return `new String[][] {${specs.join(', ')}}`;
|
|
72
|
+
}
|
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
// Ejected from @redocly/client-generator@0.8.1 — the built-in "java" generator.
|
|
2
|
+
// This file is yours: edit freely; the generated client stays machine-owned and is
|
|
3
|
+
// rebuilt by `redocly generate-client`. Newer generator versions merge in with
|
|
4
|
+
// `redocly eject-generator java --update`.
|
|
5
|
+
// The built-in `java` generator — the fourth non-TypeScript library entry, authored
|
|
6
|
+
// with the language-neutral toolkit only (same dogfooding invariant as python/go/php,
|
|
7
|
+
// pinned by the guard test). Output is one Java >= 17 file over java.net.http: a public
|
|
8
|
+
// class named after the output stem that nests the records (with fromJson/toJson
|
|
9
|
+
// hydration), wire-backed enums, sealed union interfaces, the embedded runtime, and one
|
|
10
|
+
// typed method per operation. Exceptions are the error mode (`errorMode` does not apply).
|
|
11
|
+
|
|
12
|
+
import {
|
|
13
|
+
type CodeSample,
|
|
14
|
+
type Generator,
|
|
15
|
+
identifierFor,
|
|
16
|
+
jsonSuccessSchema,
|
|
17
|
+
type NeutralPaginationRule,
|
|
18
|
+
type OperationModel,
|
|
19
|
+
renderReferencePage,
|
|
20
|
+
type SampleContext,
|
|
21
|
+
sseResponse,
|
|
22
|
+
} from '@redocly/client-generator';
|
|
23
|
+
import { JavaPrinter } from '@redocly/client-generator/printers/java';
|
|
24
|
+
import { JAVA_RUNTIME_SOURCE } from '@redocly/client-generator/runtime-sources';
|
|
25
|
+
import { logger } from '@redocly/openapi-core';
|
|
26
|
+
|
|
27
|
+
import { writeServers } from './client.ts';
|
|
28
|
+
import { writeJavaModels } from './models.ts';
|
|
29
|
+
import {
|
|
30
|
+
JAVA,
|
|
31
|
+
javaClassName,
|
|
32
|
+
javaPackageName,
|
|
33
|
+
javaString,
|
|
34
|
+
methodIdents,
|
|
35
|
+
plainPackageName,
|
|
36
|
+
} from './naming.ts';
|
|
37
|
+
import { paramsClassName, writeJavaMethod, writeParamsClass } from './operations.ts';
|
|
38
|
+
import { writeJavaPaginationWrappers } from './pagination.ts';
|
|
39
|
+
import { javaType } from './types.ts';
|
|
40
|
+
|
|
41
|
+
export { renderJavaModels } from './models.ts';
|
|
42
|
+
export { javaType } from './types.ts';
|
|
43
|
+
|
|
44
|
+
/** The `import` lines of the runtime, which the generated file declares for both of them. */
|
|
45
|
+
function runtimeImports(): string[] {
|
|
46
|
+
return JAVA_RUNTIME_SOURCE.split('\n').filter((line) => line.startsWith('import '));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* The runtime's class body — everything between its class line and its closing brace, at
|
|
51
|
+
* the one-level indent the generated class also uses — for inline embedding.
|
|
52
|
+
*/
|
|
53
|
+
function runtimeBody(): string[] {
|
|
54
|
+
const lines = JAVA_RUNTIME_SOURCE.split('\n');
|
|
55
|
+
const start = lines.findIndex((line) => line.startsWith('abstract class Runtime {'));
|
|
56
|
+
const end = lines.lastIndexOf('}');
|
|
57
|
+
return lines
|
|
58
|
+
.slice(start + 1, end)
|
|
59
|
+
.map((line) => (line.startsWith(' ') ? line.slice(4) : line));
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** The whole generated file: package, imports, and the class nesting models, runtime, and methods. */
|
|
63
|
+
export const javaGenerator: Generator = ({ model, output, banner, emit, pagination }) => {
|
|
64
|
+
const printer = new JavaPrinter();
|
|
65
|
+
const dateType = emit.dateType ?? 'string';
|
|
66
|
+
const className = javaClassName(output.stem, model);
|
|
67
|
+
const packageName = javaPackageName(model.title);
|
|
68
|
+
// A package the reader cannot see in the title would surprise the code that imports it.
|
|
69
|
+
if (packageName !== plainPackageName(model.title)) {
|
|
70
|
+
logger.warn(
|
|
71
|
+
`generate-client: the API title ${JSON.stringify(model.title)} cannot be a Java package as is, so the java SDK uses package "${packageName}" — rename the API title in the description to choose another.\n`
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
const moduleRuntime = emit.runtime === 'module';
|
|
75
|
+
const runtimeClass = `${className}Runtime`;
|
|
76
|
+
const operations = model.services.flatMap((service) => service.operations);
|
|
77
|
+
const idents = methodIdents(model);
|
|
78
|
+
// Pagination arrives RESOLVED from the pipeline — one fit-verified answer per run.
|
|
79
|
+
const paginationRules = new Map<string, NeutralPaginationRule>();
|
|
80
|
+
for (const op of operations) {
|
|
81
|
+
const spec = pagination?.get(op.name)?.spec;
|
|
82
|
+
if (spec !== undefined) paginationRules.set(op.name, spec);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
printer.line(
|
|
86
|
+
`// Code generated by @redocly/client-generator (java) from ${javaString(model.title)} ${model.version}. DO NOT EDIT.`
|
|
87
|
+
);
|
|
88
|
+
printer.line(
|
|
89
|
+
'// Regenerate with `redocly generate-client`. Java >= 17, standard library only — zero dependencies.'
|
|
90
|
+
);
|
|
91
|
+
printer.blank();
|
|
92
|
+
printer.line(`package ${packageName};`);
|
|
93
|
+
printer.blank();
|
|
94
|
+
for (const line of runtimeImports()) printer.line(line);
|
|
95
|
+
printer.blank();
|
|
96
|
+
printer.doc(className, `Client for ${model.title} (${model.version}).`);
|
|
97
|
+
printer.block(
|
|
98
|
+
`public final class ${className}${moduleRuntime ? ` extends ${runtimeClass}` : ''} {`,
|
|
99
|
+
() => {
|
|
100
|
+
writeJavaModels(printer, model, dateType);
|
|
101
|
+
writeServers(printer, model);
|
|
102
|
+
if (!moduleRuntime) {
|
|
103
|
+
printer.line('// ─── Embedded runtime (@redocly/client-generator java runtime) ───');
|
|
104
|
+
for (const line of runtimeBody()) printer.line(line);
|
|
105
|
+
printer.blank();
|
|
106
|
+
}
|
|
107
|
+
for (const op of operations) {
|
|
108
|
+
writeParamsClass(printer, op, idents.get(op.name)!, model, dateType);
|
|
109
|
+
}
|
|
110
|
+
printer.line('private final Config config;');
|
|
111
|
+
printer.blank();
|
|
112
|
+
printer.block(
|
|
113
|
+
`public ${className}(Config config) {`,
|
|
114
|
+
() => {
|
|
115
|
+
printer.line('this.config = config;');
|
|
116
|
+
printer.block(
|
|
117
|
+
'if (config.serverUrl.isEmpty()) {',
|
|
118
|
+
() => {
|
|
119
|
+
printer.line(
|
|
120
|
+
`config.serverUrl = ${javaString(emit.serverUrl ?? model.serverUrl ?? '')};`
|
|
121
|
+
);
|
|
122
|
+
},
|
|
123
|
+
'}'
|
|
124
|
+
);
|
|
125
|
+
},
|
|
126
|
+
'}'
|
|
127
|
+
);
|
|
128
|
+
printer.blank();
|
|
129
|
+
printer.block(
|
|
130
|
+
`public ${className}() {`,
|
|
131
|
+
() => {
|
|
132
|
+
printer.line('this(new Config());');
|
|
133
|
+
},
|
|
134
|
+
'}'
|
|
135
|
+
);
|
|
136
|
+
printer.blank();
|
|
137
|
+
|
|
138
|
+
for (const op of operations) {
|
|
139
|
+
const ident = idents.get(op.name)!;
|
|
140
|
+
const rule = paginationRules.get(op.name);
|
|
141
|
+
writeJavaMethod(printer, op, ident, model, dateType, rule);
|
|
142
|
+
if (sseResponse(op) === undefined && (op.successResponseHeaders?.length ?? 0) > 0) {
|
|
143
|
+
writeJavaMethod(printer, op, ident, model, dateType, rule, true);
|
|
144
|
+
}
|
|
145
|
+
if (rule !== undefined) {
|
|
146
|
+
writeJavaPaginationWrappers(printer, op, ident, model, dateType, rule);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
},
|
|
150
|
+
'}'
|
|
151
|
+
);
|
|
152
|
+
|
|
153
|
+
const entry = {
|
|
154
|
+
path: output.path.replace(/[^\\/]+$/, `${className}.java`),
|
|
155
|
+
content: printer.toString(),
|
|
156
|
+
};
|
|
157
|
+
if (!moduleRuntime) return [entry];
|
|
158
|
+
// The runtime as a real file: the same source, as a public base class the client extends,
|
|
159
|
+
// so every runtime name resolves unqualified in both runtime modes.
|
|
160
|
+
const header = banner.map((line) => `// ${line}`).join('\n');
|
|
161
|
+
const runtimeSource = JAVA_RUNTIME_SOURCE.replace(
|
|
162
|
+
/^abstract class Runtime \{$/m,
|
|
163
|
+
`public abstract class ${runtimeClass} {`
|
|
164
|
+
);
|
|
165
|
+
return [
|
|
166
|
+
entry,
|
|
167
|
+
{
|
|
168
|
+
path: output.path.replace(/[^\\/]+$/, `${runtimeClass}.java`),
|
|
169
|
+
content: `${header}\npackage ${packageName};\n\n${runtimeSource
|
|
170
|
+
.replace(/^\/\/.*\n/gm, '')
|
|
171
|
+
.trimStart()
|
|
172
|
+
.trimEnd()}\n`,
|
|
173
|
+
},
|
|
174
|
+
];
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
/** One idiomatic Java call per operation — feeds `x-codeSamples` for docs. */
|
|
178
|
+
export function javaSample(op: OperationModel, ctx: SampleContext): CodeSample {
|
|
179
|
+
const dateType = ctx.emit.dateType ?? 'string';
|
|
180
|
+
const stem = ctx.outputPath.replace(/^.*[\\/]/, '').replace(/\.[^.]+$/, '');
|
|
181
|
+
const className = javaClassName(stem, ctx.model);
|
|
182
|
+
const ident = methodIdents(ctx.model).get(op.name) ?? identifierFor(op.name, { reserved: JAVA });
|
|
183
|
+
const args = [
|
|
184
|
+
...op.pathParams.map((param) =>
|
|
185
|
+
javaString(`<${identifierFor(param.name, { reserved: JAVA })}>`)
|
|
186
|
+
),
|
|
187
|
+
...(op.requestBody ? ['body'] : []),
|
|
188
|
+
...(paramsClassName(op, ident, ctx.model) === undefined
|
|
189
|
+
? []
|
|
190
|
+
: [`new ${className}.${paramsClassName(op, ident, ctx.model)}()`]),
|
|
191
|
+
];
|
|
192
|
+
const call = `client.${ident}(${args.join(', ')})`;
|
|
193
|
+
// The statement matches the return shape: a void method has no result, an SSE method is
|
|
194
|
+
// iterated, and a typed method binds its result.
|
|
195
|
+
const statement =
|
|
196
|
+
sseResponse(op) !== undefined
|
|
197
|
+
? `for (var event : ${call}) {\n System.out.println(event.data());\n}`
|
|
198
|
+
: jsonSuccessSchema(op) === undefined
|
|
199
|
+
? `${call};`
|
|
200
|
+
: `${javaType(jsonSuccessSchema(op)!, ctx.model, dateType)} result = ${call};`;
|
|
201
|
+
// The import names the package this run writes, so the snippet compiles as shown.
|
|
202
|
+
return {
|
|
203
|
+
lang: 'java',
|
|
204
|
+
label: 'Java SDK',
|
|
205
|
+
source: `import ${javaPackageName(ctx.model.title)}.${className};\n\n${className} client = new ${className}(new ${className}.Config());\n${statement}\n`,
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* The SDK's own reference page, written when `client.docs` is on. The call snippets come
|
|
211
|
+
* from `javaSample` — this generator's own hook — so the page can only ever show the syntax
|
|
212
|
+
* of the SDK beside it, and ejecting this generator takes the page with it.
|
|
213
|
+
*/
|
|
214
|
+
export const javaDocs: Generator = ({ model, output, emit, pagination }) => [
|
|
215
|
+
{
|
|
216
|
+
path: output.path.replace(/\.[^.\\/]+$/, '.java.md'),
|
|
217
|
+
content: renderReferencePage(model, {
|
|
218
|
+
title: `${model.title} Java SDK reference`,
|
|
219
|
+
frontmatter: emit.docsFrontmatter === true,
|
|
220
|
+
language: {
|
|
221
|
+
name: 'java',
|
|
222
|
+
label: 'Java',
|
|
223
|
+
fence: 'java',
|
|
224
|
+
requires: 'The SDK needs Java 17 or newer and the standard library only.',
|
|
225
|
+
},
|
|
226
|
+
sample: (op) => javaSample(op, { model, emit, outputPath: output.path }),
|
|
227
|
+
paginated: new Set(pagination?.keys() ?? []),
|
|
228
|
+
}),
|
|
229
|
+
},
|
|
230
|
+
];
|
|
231
|
+
|
|
232
|
+
export default {
|
|
233
|
+
name: 'java',
|
|
234
|
+
run: javaGenerator,
|
|
235
|
+
sample: javaSample,
|
|
236
|
+
docs: javaDocs,
|
|
237
|
+
errorModes: ["throw"],
|
|
238
|
+
notApplicable: {
|
|
239
|
+
"outputMode": "it always emits one self-contained file",
|
|
240
|
+
"runtime": "the runtime is always embedded in the generated file",
|
|
241
|
+
"argsStyle": "inputs follow the target language's own idiom",
|
|
242
|
+
"importExt": "the generated file has no relative imports"
|
|
243
|
+
},
|
|
244
|
+
requiresGenerator: '^0.8.1',
|
|
245
|
+
};
|