Spaces:
Running
Running
| import{r as s,j as e}from"./react-B-lWpQRQ.js";import{J as N}from"./jszip-C9LaxYWv.js";import{u as v,Y as w,L as S,M as P,aW as C}from"./index-DyMS-nC-.js";import"./@google-xfXoiafW.js";import"./@braintree-DY5JYOZd.js";import"./react-dom-CU2yWD-Y.js";import"./scheduler-DYLXRpC5.js";import"./idb-Dob3nYDb.js";import"./axe-core-CA05Kxsw.js";import"./marked-CesSW9Du.js";import"./@mermaid-js-Ce0__7Tp.js";import"./langium-B_PGe6V2.js";import"./vscode-jsonrpc-2tvYB2ki.js";import"./chevrotain-D5DQZOif.js";import"./@chevrotain-DMYZVohV.js";import"./lodash-es-CKTcnrxn.js";import"./chevrotain-allstar-eFSt8-qu.js";import"./vscode-languageserver-types-NoPvPymt.js";import"./vscode-languageserver-textdocument-CKBVUiR3.js";import"./vscode-uri-CoxP0whD.js";const A=`{ | |
| "openapi": "3.0.0", | |
| "info": { "title": "Simple API", "version": "1.0.0" }, | |
| "paths": { | |
| "/users": { | |
| "get": { | |
| "summary": "Get all users", | |
| "responses": { "200": { "description": "A list of users" } } | |
| } | |
| } | |
| } | |
| }`,$=()=>{const[i,g]=s.useState(A),[m,j]=s.useState("TypeScript/Fetch"),[d,p]=s.useState(!1),[x,o]=s.useState(""),[n,h]=s.useState([]),[r,c]=s.useState(null),{addNotification:u}=v(),b=async()=>{if(!i.trim()){o("Please provide a schema.");return}p(!0),o(""),h([]),c(null);try{const t=await C(i,m);h(t),t.length>0&&c(t[0]),u("API client generated!","success")}catch(t){const l=t instanceof Error?t.message:"An unknown error occurred";o(l),u(l,"error")}finally{p(!1)}},y=async()=>{if(n.length===0)return;const t=new N;n.forEach(f=>{t.file(f.filePath,f.content)});const l=await t.generateAsync({type:"blob"}),a=document.createElement("a");a.href=URL.createObjectURL(l),a.download="api-client.zip",document.body.appendChild(a),a.click(),document.body.removeChild(a)};return e.jsxs("div",{className:"h-full flex flex-col p-4 sm:p-6 lg:p-8 text-text-primary",children:[e.jsxs("header",{className:"mb-6",children:[e.jsxs("h1",{className:"text-3xl font-bold flex items-center",children:[e.jsx(w,{}),e.jsx("span",{className:"ml-3",children:"API Client Generator"})]}),e.jsx("p",{className:"text-text-secondary mt-1",children:"Generate a typed client library from an OpenAPI or GraphQL schema."})]}),e.jsxs("div",{className:"flex-grow grid grid-cols-1 lg:grid-cols-2 gap-6 min-h-0",children:[e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"flex flex-col flex-1 min-h-0",children:[e.jsx("label",{className:"text-sm font-medium mb-2",children:"OpenAPI / GraphQL Schema"}),e.jsx("textarea",{value:i,onChange:t=>g(t.target.value),className:"flex-grow p-2 bg-surface border rounded font-mono text-xs"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium",children:"Target Language & Library"}),e.jsxs("select",{value:m,onChange:t=>j(t.target.value),className:"w-full mt-1 p-2 bg-surface border rounded",children:[e.jsx("option",{children:"TypeScript/Fetch"}),e.jsx("option",{children:"Python/requests"})]})]}),e.jsx("button",{onClick:b,disabled:d,className:"btn-primary w-full py-3",children:d?e.jsx(S,{}):"Generate Client"}),x&&e.jsx("p",{className:"text-red-500 text-xs text-center",children:x})]}),e.jsxs("div",{className:"flex flex-col min-h-0",children:[e.jsxs("div",{className:"flex justify-between items-center mb-2",children:[e.jsx("label",{className:"text-sm font-medium",children:"Generated Files"}),n.length>0&&e.jsx("button",{onClick:y,className:"btn-primary px-3 py-1 text-sm",children:"Download as ZIP"})]}),e.jsxs("div",{className:"flex-grow grid grid-cols-3 gap-2 min-h-0 bg-background border rounded-lg p-2",children:[e.jsx("div",{className:"col-span-1 overflow-y-auto",children:n.map(t=>e.jsx("div",{onClick:()=>c(t),className:`p-2 text-sm rounded cursor-pointer ${(r==null?void 0:r.filePath)===t.filePath?"bg-primary/10 text-primary":""}`,children:t.filePath},t.filePath))}),e.jsx("div",{className:"col-span-2 bg-surface rounded overflow-y-auto",children:r&&e.jsx(P,{content:"```\n"+r.content+"\n```"})})]})]})]})]})};export{$ as ApiClientGenerator}; | |
| //# sourceMappingURL=ApiClientGenerator-CKm58gQ7.js.map | |