Skip to content

Commit

Permalink
Merge pull request #98 from long-woo/dev
Browse files Browse the repository at this point in the history
fix(ts): 修复缺失参数问题
  • Loading branch information
long-woo authored Jan 7, 2025
2 parents 12f218e + e54862c commit c73f301
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 14 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ Create a `myPlugin.ts` file:

```ts
// 引用模块
// import { start } from 'https://deno.land/x/[email protected].3/mod.ts'
import { start } from 'jsr:@lonu/stc@^2.8.0'
// import { start } from 'https://deno.land/x/[email protected].1/mod.ts'
import { start } from 'jsr:@lonu/stc@^2.8.1'

// Defining plugins
const myPlugin: IPlugin = {
Expand Down
6 changes: 3 additions & 3 deletions deno.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/npm/pkg.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
11 changes: 4 additions & 7 deletions src/plugins/typescript/template/actionMethod.eta
Original file line number Diff line number Diff line change
Expand Up @@ -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 %>

Expand All @@ -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 { %>{
Expand All @@ -36,4 +33,4 @@ export const <%= it.methodName %> = (<% it.params.forEach((param, index) => { %>
<% } %><% if (index < it.params.length - 1) { %>, <% } %>

<% }) %>
}<% } %>, config)
}<% } else { %>undefined<% } %>, config)
2 changes: 1 addition & 1 deletion src/plugins/typescript/template/index.ts
Original file line number Diff line number Diff line change
@@ -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"}
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"}

0 comments on commit c73f301

Please sign in to comment.