openapi-sync 4.0.1 → 5.0.0
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 +225 -8
- package/bin/cli.js +105 -12
- package/dist/chunk-PUWCZVB7.mjs +1 -0
- package/dist/index.d.mts +409 -12
- package/dist/index.d.ts +409 -12
- package/dist/index.js +775 -70
- package/dist/index.mjs +764 -70
- package/dist/interactive-init-4LMPMPGI.mjs +12 -0
- package/package.json +16 -3
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import {d}from'./chunk-PUWCZVB7.mjs';import y from'prompts';import l from'fs';import r from'path';var i=process.env.NODE_ENV==="test"||process.env.JEST_WORKER_ID!==void 0;function v(){return d(this,null,function*(){try{let e=yield y([{type:"select",name:"configFormat",message:"What configuration format would you like to use?",choices:[{title:"TypeScript (openapi.sync.ts)",value:"typescript"},{title:"JSON (openapi.sync.json)",value:"json"},{title:"JavaScript (openapi.sync.js)",value:"javascript"}],initial:0},{type:"select",name:"apiSource",message:"Where is your OpenAPI specification?",choices:[{title:"URL (e.g., https://api.example.com/openapi.json)",value:"url"},{title:"Local file",value:"file"}],initial:0},{type:t=>t==="url"?"text":null,name:"apiUrl",message:"Enter the OpenAPI specification URL:",validate:t=>t.startsWith("http://")||t.startsWith("https://")?!0:"Please enter a valid URL starting with http:// or https://"},{type:(t,a)=>a.apiSource==="file"?"text":null,name:"apiFile",message:"Enter the path to your OpenAPI file:",validate:t=>t.trim()!==""?!0:"Please enter a valid file path"},{type:"text",name:"apiName",message:"What would you like to name this API?",initial:"myapi",validate:t=>/^[a-zA-Z0-9_-]+$/.test(t)?!0:"API name must contain only letters, numbers, hyphens, and underscores"},{type:"text",name:"outputFolder",message:"Where should generated files be saved?",initial:"./src/api",validate:t=>{if(!t||t.trim()==="")return "Output folder cannot be empty";let a=r.normalize(t);if(a==="/"||a==="C:\\"||a==="\\")return "Cannot use filesystem root directory. Please use a project subfolder like './src/api'";if(r.isAbsolute(t)){let g=process.cwd();if(!t.startsWith(g))return "\u26A0\uFE0F Warning: Using absolute path outside project directory. Recommended: use relative path like './src/api'"}return !0}},{type:"confirm",name:"enableFolderSplit",message:"Organize generated code into folders by OpenAPI tags?",initial:!1},{type:"confirm",name:"generateClient",message:"Generate API client code?",initial:!0},{type:t=>t?"select":null,name:"clientType",message:"Which client type would you like?",choices:[{title:"React Query (Recommended for React)",value:"react-query"},{title:"RTK Query (Redux Toolkit)",value:"rtk-query"},{title:"SWR",value:"swr"},{title:"Fetch API",value:"fetch"},{title:"Axios",value:"axios"}],initial:0},{type:"confirm",name:"enableValidation",message:"Enable runtime validation schemas?",initial:!0},{type:t=>t?"select":null,name:"validationLibrary",message:"Which validation library?",choices:[{title:"Zod (Recommended)",value:"zod"},{title:"Yup",value:"yup"},{title:"Joi",value:"joi"}],initial:0},{type:"confirm",name:"enableCustomCode",message:"Enable custom code preservation?",initial:!0},{type:"confirm",name:"typesUseOperationId",message:"Use operationId from OpenAPI spec for type names?",initial:!0},{type:"text",name:"typesPrefix",message:"Prefix for TypeScript interface names (leave empty for none):",initial:"I"},{type:"confirm",name:"excludeEndpointsByTags",message:"Exclude endpoints by tags (e.g., deprecated, internal)?",initial:!1},{type:t=>t?"text":null,name:"excludeTags",message:"Enter tags to exclude (comma-separated):",initial:"deprecated,internal"},{type:"confirm",name:"showCurlInDocs",message:"Include cURL examples in generated documentation?",initial:!0},{type:"number",name:"refetchInterval",message:"Refetch interval in milliseconds (0 to disable auto-refresh):",initial:5e3,min:0},{type:"confirm",name:"runSync",message:"Run initial sync after setup?",initial:!0}],{onCancel:()=>{throw i||process.exit(0),new Error("Setup cancelled")}}),n={refetchInterval:e.refetchInterval||void 0,folder:e.outputFolder,api:{[e.apiName]:e.apiUrl||e.apiFile}};e.enableFolderSplit&&(n.folderSplit={byTags:!0}),n.types={name:{prefix:e.typesPrefix||"",useOperationId:e.typesUseOperationId}},n.endpoints={name:{useOperationId:e.typesUseOperationId},doc:{showCurl:e.showCurlInDocs}},e.excludeEndpointsByTags&&e.excludeTags&&(n.endpoints.exclude={tags:e.excludeTags.split(",").map(t=>t.trim())}),e.generateClient&&e.clientType&&(n.clientGeneration={enabled:!0,type:e.clientType,outputDir:r.join(e.outputFolder,e.apiName,"client")},e.clientType==="react-query"?n.clientGeneration.reactQuery={version:5,mutations:!0}:e.clientType==="swr"&&(n.clientGeneration.swr={mutations:!0})),e.enableValidation&&e.validationLibrary&&(n.validations={library:e.validationLibrary}),e.enableCustomCode&&(n.customCode={enabled:!0,position:"bottom"});let s,o;e.configFormat==="json"?(o="openapi.sync.json",s=JSON.stringify(n,null,2)):e.configFormat==="typescript"?(o="openapi.sync.ts",s=`import { IConfig } from "openapi-sync";
|
|
2
|
+
|
|
3
|
+
const config: IConfig = ${JSON.stringify(n,null,2)};
|
|
4
|
+
|
|
5
|
+
export default config;
|
|
6
|
+
`):(o="openapi.sync.js",s=`module.exports = ${JSON.stringify(n,null,2)};
|
|
7
|
+
`);let p=r.join(process.cwd(),o);if(l.existsSync(p)&&!(yield y({type:"confirm",name:"value",message:`${o} already exists. Overwrite?`,initial:!1})).value)throw i||process.exit(0),new Error("Configuration file not created");l.writeFileSync(p,s,"utf-8"),i||`${o}`;let u=r.isAbsolute(e.outputFolder)?e.outputFolder:r.join(process.cwd(),e.outputFolder);if(!l.existsSync(u))try{l.mkdirSync(u,{recursive:!0}),i||`${e.outputFolder}`;}catch(t){i||`${t.message}`;}let c=r.join(process.cwd(),".gitignore");if(l.existsSync(c)&&(l.readFileSync(c,"utf-8").includes(e.outputFolder)||l.appendFileSync(c,`
|
|
8
|
+
# OpenAPI Sync generated files
|
|
9
|
+
${e.outputFolder}
|
|
10
|
+
`)),i||(`${o}`,e.generateClient&&e.clientType&&(e.clientType==="axios"||e.clientType==="react-query"||e.clientType==="swr"||e.clientType),e.enableValidation&&e.validationLibrary&&(e.generateClient,`${e.validationLibrary}`)),e.runSync&&!i)try{let{Init:t,GenerateClient:a}=yield import('./index.mjs');yield t({refetchInterval:e.refetchInterval}),e.generateClient&&e.clientType&&(yield a({type:e.clientType,apiName:e.apiName}));}catch(t){console.error(`
|
|
11
|
+
\u274C Error during sync:`,t.message),t.stack&&process.env.DEBUG&&console.error(t.stack);}else i||(e.generateClient||e.enableValidation,e.generateClient&&e.clientType&&(e.generateClient||e.enableValidation,`${e.clientType}`));i||(`${e.outputFolder}${e.apiName}`,e.generateClient&&`${e.outputFolder}${e.apiName}`,e.generateClient&&e.clientType&&`${e.clientType}`);}catch(e){throw i||(console.error(`
|
|
12
|
+
\u274C Error during setup:`,e.message),process.exit(1)),e}})}export{v as interactiveInit};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "openapi-sync",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "A powerful developer tool that automates API documentation synchronization with your codebase using OpenAPI specifications. Generates TypeScript types, endpoint definitions, runtime validation schemas (Zod, Yup, Joi), and comprehensive documentation",
|
|
3
|
+
"version": "5.0.0",
|
|
4
|
+
"description": "A powerful developer tool that automates API documentation synchronization with your codebase using OpenAPI specifications. Generates TypeScript types, fully-typed API clients (Fetch, Axios, React Query, SWR, RTK Query), endpoint definitions, runtime validation schemas (Zod, Yup, Joi), and comprehensive documentation with enterprise-grade reliability",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"bin": {
|
|
@@ -25,7 +25,18 @@
|
|
|
25
25
|
"codegen",
|
|
26
26
|
"generation",
|
|
27
27
|
"generator",
|
|
28
|
-
"generate types"
|
|
28
|
+
"generate types",
|
|
29
|
+
"api client",
|
|
30
|
+
"fetch",
|
|
31
|
+
"axios",
|
|
32
|
+
"react-query",
|
|
33
|
+
"tanstack query",
|
|
34
|
+
"swr",
|
|
35
|
+
"rtk-query",
|
|
36
|
+
"redux toolkit",
|
|
37
|
+
"type-safe",
|
|
38
|
+
"hooks",
|
|
39
|
+
"client generation"
|
|
29
40
|
],
|
|
30
41
|
"files": [
|
|
31
42
|
"bin",
|
|
@@ -56,6 +67,7 @@
|
|
|
56
67
|
"author": "P-Technologies",
|
|
57
68
|
"license": "ISC",
|
|
58
69
|
"devDependencies": {
|
|
70
|
+
"@types/prompts": "^2.4.9",
|
|
59
71
|
"@types/jest": "^30.0.0",
|
|
60
72
|
"@types/js-yaml": "^4.0.9",
|
|
61
73
|
"@types/lodash": "^4.17.7",
|
|
@@ -77,6 +89,7 @@
|
|
|
77
89
|
"js-yaml": "^4.1.0",
|
|
78
90
|
"lodash.get": "^4.4.2",
|
|
79
91
|
"lodash.isequal": "^4.5.0",
|
|
92
|
+
"prompts": "^2.4.2",
|
|
80
93
|
"yargs": "^17.7.2"
|
|
81
94
|
}
|
|
82
95
|
}
|