From e0a202a4d1b66afaa85bb24bb0cdb8520b23e8ea Mon Sep 17 00:00:00 2001 From: lonu Date: Tue, 10 Dec 2024 11:53:11 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=96=B9=E6=B3=95?= =?UTF-8?q?=E5=90=8D=E9=87=8D=E5=A4=8D=E9=97=AE=E9=A2=98=EF=BC=8C=E5=93=8D?= =?UTF-8?q?=E5=BA=94=E8=A7=A3=E6=9E=90=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/core.ts | 24 +++++++++++++----------- src/swagger.ts | 1 + 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/core.ts b/src/core.ts index df00791..6d0a497 100644 --- a/src/core.ts +++ b/src/core.ts @@ -218,20 +218,20 @@ const getMethodName = ( conjunction: string, index: number = -1, ) => { - const _url = url.split("/"); - // 获取URL路径Query方法名称(取第一个Params) - let _query = url.split("?")?.[1]?.split("&") - .shift()?.replace(/[,=]/g, "_"); - // 添加_分割标记 - _query = _query ? `_${_query}` : ""; - let _name = _url.slice(index).join("_")?.split("?")[0] as string; + let _url = url; + if (url.indexOf("?") > -1) { + _url = url.substring(0, url.indexOf("?")); + } + + const _urls = _url.split("/"); + let _name = _urls.slice(index).join("_"); if (!_name) return _name; - const regExp = /^{(\w+)}$/; + const regExp = /[\\{|:](\w+)[\\}]/; if (regExp.test(_name)) { // 动态路径添加连接字符 - _name = `${_url.pop()}_${conjunction}_${_name.match(regExp)![1]}`; + _name = `${conjunction}_${_name.match(regExp)![1]}`; } // 方法名小驼峰 @@ -386,7 +386,8 @@ const getPathVirtualProperty = ( // 响应 const _resSchema = pathMethod.responses[200]?.schema ?? - pathMethod.responses[200]?.content?.["application/json"]?.schema; + pathMethod.responses[200]?.content?.["application/json"]?.schema ?? + pathMethod.responses[200]?.content?.["text/plain"]?.schema; const _properties = getProperties( _resSchema?.properties ?? _resSchema?.items?.properties ?? {}, @@ -473,7 +474,7 @@ export const getApiPath = ( options?.tag, ); - name = `${value.tag}@${name}`; + name = `${url}@${name}`; if (pathMap.has(name)) { Logs.error( @@ -486,6 +487,7 @@ export const getApiPath = ( return; } + pathMap.set(name, value); }); }); diff --git a/src/swagger.ts b/src/swagger.ts index 81a9acd..db066ac 100644 --- a/src/swagger.ts +++ b/src/swagger.ts @@ -56,6 +56,7 @@ export interface ISwaggerContentSchema { export interface ISwaggerContent { "application/json"?: ISwaggerContentSchema; "application/octet-stream"?: ISwaggerContentSchema; + "text/plain": ISwaggerContentSchema; } interface ISwaggerMethodResponseStatus { From b0597da9c6d3c2839f1cf3a3d5034172f9e4caf6 Mon Sep 17 00:00:00 2001 From: lonu Date: Tue, 10 Dec 2024 14:11:51 +0800 Subject: [PATCH 2/2] release: v2.7.1 --- README.md | 4 ++-- deno.json | 4 ++-- src/npm/pkg.json | 2 +- src/plugins/javascript/oxc.ts | 2 +- test/swagger-4.test.ts | 4 ++-- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 8c07627..c05d6b8 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.0/mod.ts' -import { start } from 'jsr:@loongwoo/stc@^2.7.0' +// import { start } from 'https://deno.land/x/stc@2.7.1/mod.ts' +import { start } from 'jsr:@loongwoo/stc@^2.7.1' // Defining plugins const myPlugin: IPlugin = { diff --git a/deno.json b/deno.json index 216545a..7cfb41e 100644 --- a/deno.json +++ b/deno.json @@ -1,12 +1,12 @@ { "name": "@loongwoo/stc", - "version": "2.7.0", + "version": "2.7.1", "exports": "./mod.ts", "tasks": { "pack": "deno run -A src/pack.ts", "dev": "deno task pack && deno run -A --watch=src src/main.ts --url='https://petstore3.swagger.io/api/v3/openapi.json' --lang=ts", "serve": "deno run -A --watch=src src/service.ts", - "version": "echo '2.7.0' > release/version", + "version": "echo '2.7.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 7eb686f..59e2216 100644 --- a/src/npm/pkg.json +++ b/src/npm/pkg.json @@ -1,6 +1,6 @@ { "name": "@loongwoo/stc", - "version": "2.7.0", + "version": "2.7.1", "description": "A tool for converting OpenApi/Swagger/Apifox into code.", "type": "module", "module": "esm/mod.js", diff --git a/src/plugins/javascript/oxc.ts b/src/plugins/javascript/oxc.ts index 4d584af..9959025 100644 --- a/src/plugins/javascript/oxc.ts +++ b/src/plugins/javascript/oxc.ts @@ -1,4 +1,4 @@ -import oxc from "npm:oxc-transform@^0.30.5"; +import oxc from "npm:oxc-transform@^0.39"; import Logs from "../../console.ts"; diff --git a/test/swagger-4.test.ts b/test/swagger-4.test.ts index d3e522c..9e49ab1 100644 --- a/test/swagger-4.test.ts +++ b/test/swagger-4.test.ts @@ -1,7 +1,7 @@ // https://petstore3.swagger.io/api/v3/openapi.json import { assertEquals } from "@std/assert"; -Deno.test("测试 解决动态路径生成方法被覆盖的问题", async () => { +Deno.test("解决动态路径生成方法被覆盖的问题", async () => { const command = new Deno.Command("deno", { args: [ "run", @@ -17,7 +17,7 @@ Deno.test("测试 解决动态路径生成方法被覆盖的问题", async () => assertEquals(0, code); }); -Deno.test("测试 支持URL路径Query参数解析", async () => { +Deno.test("支持URL路径Query参数解析", async () => { const command = new Deno.Command("deno", { args: [ "run",