diff --git a/README.md b/README.md index 991c7b5..7539f0a 100644 --- a/README.md +++ b/README.md @@ -153,8 +153,8 @@ Create a `myPlugin.ts` file: ```ts // 引用模块 -// import { start } from 'https://deno.land/x/stc@2.7.3/mod.ts' -import { start } from 'jsr:@lonu/stc@^2.8.0' +// import { start } from 'https://deno.land/x/stc@2.7.1/mod.ts' +import { start } from 'jsr:@lonu/stc@^2.8.1' // Defining plugins const myPlugin: IPlugin = { diff --git a/deno.json b/deno.json index ba7d0b8..dd172ed 100644 --- a/deno.json +++ b/deno.json @@ -1,12 +1,12 @@ { "name": "@lonu/stc", - "version": "2.8.0", + "version": "2.8.1", "exports": "./mod.ts", "tasks": { "pack": "deno run -A src/pack.ts", - "dev": "deno run -A --watch=src src/main.ts --url='https://petstore3.swagger.io/api/v3/openapi.json'", + "dev": "deno task pack && deno run -A --watch=src src/main.ts --url='https://petstore3.swagger.io/api/v3/openapi.json'", "serve": "deno run -A --watch=src src/service.ts", - "version": "echo '2.8.0' > release/version", + "version": "echo '2.8.1' > release/version", "build:npm": "deno run -A src/npm/build.ts", "build:mac": "deno compile -A --target x86_64-apple-darwin --output release/stc src/main.ts", "build:mac-m": "deno compile -A --target aarch64-apple-darwin --output release/stc-m src/main.ts", diff --git a/src/npm/pkg.json b/src/npm/pkg.json index e9e1670..cb7e61e 100644 --- a/src/npm/pkg.json +++ b/src/npm/pkg.json @@ -1,6 +1,6 @@ { "name": "@lonu/stc", - "version": "2.8.0", + "version": "2.8.1", "description": "A tool for converting OpenApi/Swagger/Apifox into code.", "type": "module", "module": "esm/mod.js", diff --git a/src/plugins/typescript/template/actionMethod.eta b/src/plugins/typescript/template/actionMethod.eta index 14087c8..10e3e0e 100644 --- a/src/plugins/typescript/template/actionMethod.eta +++ b/src/plugins/typescript/template/actionMethod.eta @@ -4,17 +4,14 @@ * <%~ it.summary %> <% } %> <% if (it.summary !== it.description) { %> -<% if (it.summary && it.description) { %> - - * -<% } %> <% if (it.description) { %> + * @description <%~ it.description %> <% } %> <% } %> -<% if (it.params.length) { %> * +<% if (it.params.length) { %> <% it.params.forEach(param => { %> * @param {<%~ param.type %>} <% if (!param.required) { %>[<% } %><%= param.name %><% if (!param.required) { %>]<% } %> - <%~ param.description || param.type %> @@ -26,7 +23,7 @@ <% /* API 方法 */ %> export const <%= it.methodName %> = (<% it.params.forEach((param, index) => { %> <%= param.name %><% if (!param.required) { %>?<% } %>: <%~ param.type %><% if (index < it.params.length - 1) { %>, <% } %> -<% }) %><% if (it.params.length) { %>, <% } %>config?: ApiClientConfig['config']): Promise<<%~ it.responseType %>> => fetchRuntime<<%~ it.responseType %>>('<%= it.url %>', '<%= it.method.toUpperCase() %>'<% if (it.params.length) { %>, { +<% }) %><% if (it.params.length) { %>, <% } %>config?: ApiClientConfig['config']): Promise<<%~ it.responseType %>> => fetchRuntime<<%~ it.responseType %>>('<%= it.url %>', '<%= it.method.toUpperCase() %>', <% if (it.params.length) { %>{ <% it.params.forEach((param, index) => { %> <%= param.category %><% if (param.category === param.name) { %> <% } else { %>: <% if (param.category === 'body') { %><%= param.name %><% } else { %>{ @@ -36,4 +33,4 @@ export const <%= it.methodName %> = (<% it.params.forEach((param, index) => { %> <% } %><% if (index < it.params.length - 1) { %>, <% } %> <% }) %> -}<% } %>, config) +}<% } else { %>undefined<% } %>, config) diff --git a/src/plugins/typescript/template/index.ts b/src/plugins/typescript/template/index.ts index 277caf0..f86533b 100644 --- a/src/plugins/typescript/template/index.ts +++ b/src/plugins/typescript/template/index.ts @@ -1,2 +1,2 @@ // this file is auto generated. -export default {"actionImport":"import type { ApiClientConfig } from '<%= it.importPath %>shared/apiClientBase'\nimport { fetchRuntime } from '<%= it.importPath %>shared/fetchRuntime'\n<% if (it.imports.length) { %>\nimport type { <%= it.imports.join(', ') %> } from '<%= it.importPath %><%= it.typeFileName %>'\n<% } %>","actionMethod":"<% /* API 方法注释 */ %>\n/**\n<% if (it.summary) { %>\n * <%~ it.summary %>\n<% } %>\n<% if (it.summary !== it.description) { %>\n<% if (it.summary && it.description) { %>\n\n *\n<% } %>\n<% if (it.description) { %>\n * @description <%~ it.description %>\n<% } %>\n<% } %>\n<% if (it.params.length) { %>\n\n *\n<% it.params.forEach(param => { %>\n * @param {<%~ param.type %>} <% if (!param.required) { %>[<% } %><%= param.name %><% if (!param.required) { %>]<% } %> - <%~ param.description || param.type %>\n\n<% }) %>\n<% } %>\n * @param {ApiClientConfig['config']} [config] - ApiClientConfig['config']\n * @returns {Promise<<%~ it.responseType %>>} Promise<<%~ it.responseType %>>\n */\n<% /* API 方法 */ %>\nexport const <%= it.methodName %> = (<% it.params.forEach((param, index) => { %>\n<%= param.name %><% if (!param.required) { %>?<% } %>: <%~ param.type %><% if (index < it.params.length - 1) { %>, <% } %>\n<% }) %><% if (it.params.length) { %>, <% } %>config?: ApiClientConfig['config']): Promise<<%~ it.responseType %>> => fetchRuntime<<%~ it.responseType %>>('<%= it.url %>', '<%= it.method.toUpperCase() %>'<% if (it.params.length) { %>, {\n<% it.params.forEach((param, index) => { %>\n <%= param.category %><% if (param.category === param.name) { %>\n<% } else { %>: <% if (param.category === 'body') { %><%= param.name %><% } else { %>{\n\t\t<%= param.name %>\n\n\t}<% } %>\n<% } %><% if (index < it.params.length - 1) { %>, <% } %>\n\n<% }) %>\n}<% } %>, config)\n","definitionBody":"<% if (it.propCommit) { %>\n /**\n * <%~ it.propCommit %>\n\n */\n<% } %>\n <%= it.prop.name %><% if (!it.prop.required) { %>?<% } %>: <%~ it.propType %>;","definitionFooter":"}\n// #endregion\n","definitionHeader":"// #region <%= it.defName %>\n\nexport interface <%= it.defName %> {","enum":"<% \n const option = it.data.map(item => { \n const val = it.convertValue(item)\n\n return typeof val === 'number' ? val : `'${val}'`\n })\n%>\n// #region <%= it.name %>\n\nexport type <%= it.name %> = <%~ option.join(\" | \") %>;\n// #endregion\n"} \ No newline at end of file +export default {"actionImport":"import type { ApiClientConfig } from '<%= it.importPath %>shared/apiClientBase'\nimport { fetchRuntime } from '<%= it.importPath %>shared/fetchRuntime'\n<% if (it.imports.length) { %>\nimport type { <%= it.imports.join(', ') %> } from '<%= it.importPath %><%= it.typeFileName %>'\n<% } %>","actionMethod":"<% /* API 方法注释 */ %>\n/**\n<% if (it.summary) { %>\n * <%~ it.summary %>\n<% } %>\n<% if (it.summary !== it.description) { %>\n<% if (it.description) { %>\n\n * @description <%~ it.description %>\n<% } %>\n<% } %>\n\n *\n<% if (it.params.length) { %>\n<% it.params.forEach(param => { %>\n * @param {<%~ param.type %>} <% if (!param.required) { %>[<% } %><%= param.name %><% if (!param.required) { %>]<% } %> - <%~ param.description || param.type %>\n\n<% }) %>\n<% } %>\n * @param {ApiClientConfig['config']} [config] - ApiClientConfig['config']\n * @returns {Promise<<%~ it.responseType %>>} Promise<<%~ it.responseType %>>\n */\n<% /* API 方法 */ %>\nexport const <%= it.methodName %> = (<% it.params.forEach((param, index) => { %>\n<%= param.name %><% if (!param.required) { %>?<% } %>: <%~ param.type %><% if (index < it.params.length - 1) { %>, <% } %>\n<% }) %><% if (it.params.length) { %>, <% } %>config?: ApiClientConfig['config']): Promise<<%~ it.responseType %>> => fetchRuntime<<%~ it.responseType %>>('<%= it.url %>', '<%= it.method.toUpperCase() %>', <% if (it.params.length) { %>{\n<% it.params.forEach((param, index) => { %>\n <%= param.category %><% if (param.category === param.name) { %>\n<% } else { %>: <% if (param.category === 'body') { %><%= param.name %><% } else { %>{\n\t\t<%= param.name %>\n\n\t}<% } %>\n<% } %><% if (index < it.params.length - 1) { %>, <% } %>\n\n<% }) %>\n}<% } else { %>undefined<% } %>, config)\n","definitionBody":"<% if (it.propCommit) { %>\n /**\n * <%~ it.propCommit %>\n\n */\n<% } %>\n <%= it.prop.name %><% if (!it.prop.required) { %>?<% } %>: <%~ it.propType %>;","definitionFooter":"}\n// #endregion\n","definitionHeader":"// #region <%= it.defName %>\n\nexport interface <%= it.defName %> {","enum":"<% \n const option = it.data.map(item => { \n const val = it.convertValue(item)\n\n return typeof val === 'number' ? val : `'${val}'`\n })\n%>\n// #region <%= it.name %>\n\nexport type <%= it.name %> = <%~ option.join(\" | \") %>;\n// #endregion\n"} \ No newline at end of file