swagger-typescript-api 13.0.22 → 13.0.23
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/dist/{chunk-M2JPSLFC.js → chunk-7R2HP255.js} +3 -3
- package/dist/{chunk-M2JPSLFC.js.map → chunk-7R2HP255.js.map} +1 -1
- package/dist/{chunk-KMLLDZJ4.cjs → chunk-B7E4I4GW.cjs} +6 -6
- package/dist/{chunk-KMLLDZJ4.cjs.map → chunk-B7E4I4GW.cjs.map} +1 -1
- package/dist/cli.cjs +15 -14
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +14 -13
- package/dist/cli.js.map +1 -1
- package/dist/lib.cjs +4 -4
- package/dist/lib.js +1 -1
- package/package.json +1 -1
|
@@ -14,7 +14,7 @@ import * as Nt from 'eta';
|
|
|
14
14
|
import * as N from 'node:fs';
|
|
15
15
|
|
|
16
16
|
var Dt=Object.defineProperty;var _t=(p,e)=>{for(var t in e)Dt(p,t,{get:e[t],enumerable:!0});};var Z=class{config;constructor({config:e}){this.config=e;}removeUnusedImports=e=>{let t="file.ts",s=new Ue(t,e),a=d.createLanguageService(s).organizeImports({type:"file",fileName:t},{newLineCharacter:d.sys.newLine})[0];return a?.textChanges.length?a.textChanges.reduceRight((i,{span:n,newText:o})=>`${i.slice(0,n.start)}${o}${i.slice(n.start+n.length)}`,e):e};prettierFormat=async e=>await rt.format(e,this.config.prettierOptions);formatCode=async(e,{removeUnusedImports:t=!0,prettierFormat:s=!0}={})=>(t&&(e=this.removeUnusedImports(e)),s&&(e=await this.prettierFormat(e)),e)},Ue=class{constructor(e,t){let s=d.findConfigFile(e,d.sys.fileExists);Object.assign(this,{fileName:e,content:t,compilerOptions:s?d.convertCompilerOptionsFromJson(d.readConfigFile(s,d.sys.readFile).config.compilerOptions).options:d.getDefaultCompilerOptions()});}getNewLine(){return "newLine"in d.sys?d.sys.newLine:`
|
|
17
|
-
`}getScriptFileNames(){return [this.fileName]}getCompilationSettings(){return this.compilerOptions}getDefaultLibFileName(){return d.getDefaultLibFileName(this.getCompilationSettings())}getCurrentDirectory(){return process.cwd()}getScriptVersion(){return d.version}getScriptSnapshot(){return d.ScriptSnapshot.fromString(this.content)}readFile(e,t){return e===this.fileName?this.content:d.sys.readFile(e,t)}fileExists(e){return d.sys.fileExists(e)}};var b=class{reservedNames=[];getFallbackName=null;config;constructor(e,t,s){this.config=e,this.getFallbackName=s,this.reserve(t);}reserve(e){let t=u.uniq(u.compact(e));for(let s of t)this.reservedNames.indexOf(s)===-1&&this.reservedNames.push(s);}unreserve(e){this.reservedNames.filter(t=>!e.some(s=>s===t));}isReserved(e){return this.reservedNames.some(t=>t===e)}resolve(e,t,s,r=!0){if(typeof t=="function"){let a=null;for(;a===null;){let i=t(e,s);if(i===void 0)return consola.warn("unable to resolve name. current reserved names: ",this.reservedNames),null;(!r||!this.isReserved(i))&&(a=i);}return r&&this.reserve([a]),a}if(Array.isArray(e)){let a=null,i=u.uniq(u.compact(e));for(let n of i)!a&&(!r||!this.isReserved(n))&&(a=n);return a?(r&&this.reserve([a]),a):(consola.debug("trying to resolve name with using fallback name generator using variants",e),this.resolve(e,this.getFallbackName,s))}return consola.debug("problem with reserving names. current reserved names: ",this.reservedNames),null}};var Kt=(p=0,e=1)=>Math.random()*(e-p)+p,at=(p=0,e=1)=>p===e?p:Math.round(Kt(p,e));var te=class extends b{counter=1;fallbackNameCounter=1;countersByVariant=new Map;constructor(e,t){super(e,t,s=>{let r=s[at(0,s.length-1)];if(r){this.countersByVariant.has(r)||this.countersByVariant.set(r,0);let i=this.countersByVariant.get(r)+1;this.countersByVariant.set(r,i);let n=`${r}${i}`;return consola.debug("generated dirty resolved type name for component - ",n),n}let a=`${this.config.componentTypeNameResolver}${this.fallbackNameCounter++}`;return consola.debug("generated fallback type name for component - ",a),a});}};var re={};_t(re,{DEFAULT_BODY_ARG_NAME:()=>ke,FILE_PREFIX:()=>Ut,HTTP_CLIENT:()=>L,PRETTIER_OPTIONS:()=>se,PROJECT_VERSION:()=>G,RESERVED_BODY_ARG_NAMES:()=>We,RESERVED_HEADER_ARG_NAMES:()=>Ve,RESERVED_PATH_ARG_NAMES:()=>Be,RESERVED_QUERY_ARG_NAMES:()=>Le,RESERVED_REQ_PARAMS_ARG_NAMES:()=>jt,SCHEMA_TYPES:()=>l});var ot={name:"swagger-typescript-api",version:"13.0.
|
|
17
|
+
`}getScriptFileNames(){return [this.fileName]}getCompilationSettings(){return this.compilerOptions}getDefaultLibFileName(){return d.getDefaultLibFileName(this.getCompilationSettings())}getCurrentDirectory(){return process.cwd()}getScriptVersion(){return d.version}getScriptSnapshot(){return d.ScriptSnapshot.fromString(this.content)}readFile(e,t){return e===this.fileName?this.content:d.sys.readFile(e,t)}fileExists(e){return d.sys.fileExists(e)}};var b=class{reservedNames=[];getFallbackName=null;config;constructor(e,t,s){this.config=e,this.getFallbackName=s,this.reserve(t);}reserve(e){let t=u.uniq(u.compact(e));for(let s of t)this.reservedNames.indexOf(s)===-1&&this.reservedNames.push(s);}unreserve(e){this.reservedNames.filter(t=>!e.some(s=>s===t));}isReserved(e){return this.reservedNames.some(t=>t===e)}resolve(e,t,s,r=!0){if(typeof t=="function"){let a=null;for(;a===null;){let i=t(e,s);if(i===void 0)return consola.warn("unable to resolve name. current reserved names: ",this.reservedNames),null;(!r||!this.isReserved(i))&&(a=i);}return r&&this.reserve([a]),a}if(Array.isArray(e)){let a=null,i=u.uniq(u.compact(e));for(let n of i)!a&&(!r||!this.isReserved(n))&&(a=n);return a?(r&&this.reserve([a]),a):(consola.debug("trying to resolve name with using fallback name generator using variants",e),this.resolve(e,this.getFallbackName,s))}return consola.debug("problem with reserving names. current reserved names: ",this.reservedNames),null}};var Kt=(p=0,e=1)=>Math.random()*(e-p)+p,at=(p=0,e=1)=>p===e?p:Math.round(Kt(p,e));var te=class extends b{counter=1;fallbackNameCounter=1;countersByVariant=new Map;constructor(e,t){super(e,t,s=>{let r=s[at(0,s.length-1)];if(r){this.countersByVariant.has(r)||this.countersByVariant.set(r,0);let i=this.countersByVariant.get(r)+1;this.countersByVariant.set(r,i);let n=`${r}${i}`;return consola.debug("generated dirty resolved type name for component - ",n),n}let a=`${this.config.componentTypeNameResolver}${this.fallbackNameCounter++}`;return consola.debug("generated fallback type name for component - ",a),a});}};var re={};_t(re,{DEFAULT_BODY_ARG_NAME:()=>ke,FILE_PREFIX:()=>Ut,HTTP_CLIENT:()=>L,PRETTIER_OPTIONS:()=>se,PROJECT_VERSION:()=>G,RESERVED_BODY_ARG_NAMES:()=>We,RESERVED_HEADER_ARG_NAMES:()=>Ve,RESERVED_PATH_ARG_NAMES:()=>Be,RESERVED_QUERY_ARG_NAMES:()=>Le,RESERVED_REQ_PARAMS_ARG_NAMES:()=>jt,SCHEMA_TYPES:()=>l});var ot={name:"swagger-typescript-api",version:"13.0.23",description:"Generate the API client for Fetch or Axios from an OpenAPI Specification",homepage:"https://github.com/acacode/swagger-typescript-api",bugs:"https://github.com/acacode/swagger-typescript-api/issues",repository:"github:acacode/swagger-typescript-api",license:"MIT",author:"Sergey Volkov <js2me@outlook.com>",contributors:["Sora Morimoto <sora@morimoto.io>"],type:"module",exports:{".":{import:{types:"./dist/types.d.ts",default:"./dist/lib.js"},require:{types:"./dist/types.d.cts",default:"./dist/lib.cjs"}}},main:"./dist/lib.cjs",module:"./dist/lib.js",types:"./dist/types.d.cts",bin:{sta:"./dist/cli.js","swagger-typescript-api":"./dist/cli.js"},files:["dist","templates"],scripts:{build:"tsup","cli:help":"node index.js -h","cli:json":"node index.js -r -d -p ./swagger-test-cli.json -n swagger-test-cli.ts","cli:yaml":"node index.js -r -d -p ./swagger-test-cli.yaml -n swagger-test-cli.ts",format:"biome format --write .","format:check":"biome format .",lint:"biome check",prepack:"tsup",test:"vitest run"},dependencies:{"@types/swagger-schema-official":"^2.0.25",consola:"^3.2.3",cosmiconfig:"^9.0.0",didyoumean:"^1.2.2",eta:"^2.2.0","js-yaml":"^4.1.0",lodash:"^4.17.21",nanoid:"^3.3.7",prettier:"~3.3.3","swagger-schema-official":"2.0.0-bab6bed",swagger2openapi:"^7.0.8",typescript:"~5.5.4"},devDependencies:{"@biomejs/biome":"1.8.3","@tsconfig/node18":"18.2.4","@tsconfig/strictest":"2.0.5","@types/didyoumean":"1.2.2","@types/js-yaml":"4.0.9","@types/lodash":"4.17.7","@types/node":"22.5.0","@types/swagger2openapi":"7.0.4",axios:"1.7.5",shx:"0.3.4",tsup:"8.2.4",vitest:"2.0.5"},packageManager:"yarn@4.4.1",engines:{node:">=18.0.0"},publishConfig:{access:"public",registry:"https://registry.npmjs.org"}};var ke="data",Ut=`/* eslint-disable */
|
|
18
18
|
/* tslint:disable */
|
|
19
19
|
/*
|
|
20
20
|
* ---------------------------------------------------------------
|
|
@@ -54,5 +54,5 @@ ${e}
|
|
|
54
54
|
`))};createOutputFileInfo=async(e,t,s)=>{let r=this.fileSystem.cropExtension(t),a=d.Extension.Ts;return e.translateToJavaScript?(consola.debug("using js translator for",r),await this.javascriptTranslator.translate({fileName:r,fileExtension:a,fileContent:s})):e.customTranslator?(consola.debug("using custom translator for",r),await e.customTranslator.translate({fileName:r,fileExtension:a,fileContent:s})):(consola.debug("generating output for",`${r}${a}`),[{fileName:r,fileExtension:a,fileContent:await this.codeFormatter.formatCode(s)}])};createApiConfig=e=>{let{info:t,servers:s,host:r,basePath:a,externalDocs:i,tags:n}=e,o=s?.[0]||{url:""},{title:c="No title",version:m}=t||{},{url:h}=o;return {info:t||{},servers:s||[],basePath:a,host:r,externalDocs:u.merge({url:"",description:""},i),tags:u.compact(n),baseUrl:h,title:c,version:m}};injectClassInstance=(e,t)=>{this[e]=t;for(let s of Zt)s!==e&&e in this[s]&&(this[s][e]=t);}};var De=class{cleanOutput=!1;output=void 0;httpClientType=L.FETCH;modular=!1;silent=!1;version=G;rewrite=!1;constructor(e){this.update(e);}update=e=>{U(this,e);}};var ts=F__default.dirname(St__default.fileURLToPath(import.meta.url)),_e=class{config;fileSystem;rootDir=F__default.resolve(ts,"../../../");paths={baseTemplates:"templates/base",httpClientTemplates:"templates/base/http-clients",moduleApiTemplates:"templates/modular",defaultApiTemplates:"templates/default"};importTemplatePrefixes=["@base","@modular","@default"];constructor(e){this.config=new De(e),this.fileSystem=new W(this);}async start(){consola.info('start generating source templates ".ejs" for code generator');let e=this.getTemplates();if(this.config.output){consola.info("preparing output directory for source templates");let t=F__default.resolve(process.cwd(),this.config.output);this.fileSystem.pathIsExist(t)?this.config.cleanOutput&&this.fileSystem.cleanDir(t):this.fileSystem.createDir(t);for(let s of e){let r=this.fileSystem.cropExtension(s.name),a=F__default.resolve(t,`${r}.ejs`),i=F__default.resolve(t,`${r}.eta`),n=this.fileSystem.pathIsExist(a),o=this.fileSystem.pathIsExist(i);!n&&!o?this.fileSystem.createFile({path:t,fileName:s.name,content:s.content,withPrefix:!1}):this.config.rewrite&&(n?this.fileSystem.createFile({path:t,fileName:`${r}.ejs`,content:s.content,withPrefix:!1}):o&&this.fileSystem.createFile({path:t,fileName:`${r}.eta`,content:s.content,withPrefix:!1}));}consola.success(`source templates has been successfully created in "${t}"`);}return {files:e,configuration:this.config,createFile:this.fileSystem.createFile}}getTemplates=()=>{let e=[],t=this.getTemplateNamesFromDir(this.paths.baseTemplates),s=this.getTemplateNamesFromDir(this.paths.httpClientTemplates),r=this.config.modular?this.paths.moduleApiTemplates:this.paths.defaultApiTemplates,a=this.getTemplateNamesFromDir(r),i=s.find(o=>o.startsWith(`${this.config.httpClientType}-`)),n="";i&&(n=this.fixTemplateContent(this.getTemplateContent(`${this.paths.httpClientTemplates}/${i}`)));for(let o of t){let c=o==="http-client.ejs"&&n||this.fixTemplateContent(this.getTemplateContent(`${this.paths.baseTemplates}/${o}`));e.push({name:o,content:c});}for(let o of a)e.push({name:o,content:this.fixTemplateContent(this.getTemplateContent(`${r}/${o}`))});return e};fixTemplateContent=e=>{let t=new RegExp(`includeFile\\("(${this.importTemplatePrefixes.map(a=>`(${a})`).join("|")})/`,"g"),s=new RegExp(`includeFile\\(\`(${this.importTemplatePrefixes.map(a=>`(${a})`).join("|")})/`,"g"),r=new RegExp(`includeFile\\('(${this.importTemplatePrefixes.map(a=>`(${a})`).join("|")})/`,"g");return e.replace(t,'includeFile("./').replace(s,"includeFile(`./").replace(r,"includeFile('./")};getTemplateNamesFromDir=e=>this.fileSystem.readDir(F__default.resolve(this.rootDir,e)).filter(t=>t.endsWith(".ejs"));getTemplateContent=e=>this.fileSystem.getFileContent(F__default.resolve(this.rootDir,e))};async function ss(p){return await new _e(p).start()}async function za({name:p,prettier:e,...t}){return t.debug&&(consola.level=Number.MAX_SAFE_INTEGER),await new ve({...t,fileName:p,prettierOptions:e}).start()}
|
|
55
55
|
|
|
56
56
|
export { ot as a, L as b, re as c, ae as d, De as e, ss as f, za as g };
|
|
57
|
-
//# sourceMappingURL=chunk-
|
|
58
|
-
//# sourceMappingURL=chunk-
|
|
57
|
+
//# sourceMappingURL=chunk-7R2HP255.js.map
|
|
58
|
+
//# sourceMappingURL=chunk-7R2HP255.js.map
|