Skip to content

Commit

Permalink
Merge pull request #95 from long-woo/dev
Browse files Browse the repository at this point in the history
release: v2.7.2
  • Loading branch information
long-woo authored Dec 13, 2024
2 parents e82ad72 + 0d8f99c commit 002a7ce
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 14 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ STC (Swagger Transform Code) is a tool for converting OpenApi/Swagger/Apifox int
[![JSR](https://jsr.io/badges/@loongwoo/stc)](https://jsr.io/@loongwoo/stc)
![NPM Version](https://img.shields.io/npm/v/%40loongwoo%2Fstc)

> New scope enabled since 2.8.0 **@lonu**
<div align="center">
<img src="resources/20240422-151653.gif" alt="stc" />
</div>
Expand Down Expand Up @@ -153,8 +155,8 @@ Create a `myPlugin.ts` file:

```ts
// 引用模块
// import { start } from 'https://deno.land/x/stc@2.7.1/mod.ts'
import { start } from 'jsr:@loongwoo/stc@^2.7.1'
// import { start } from 'https://deno.land/x/stc@2.7.2/mod.ts'
import { start } from 'jsr:@loongwoo/stc@^2.7.2'

// Defining plugins
const myPlugin: IPlugin = {
Expand Down
1 change: 1 addition & 0 deletions cover.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions deno.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "@loongwoo/stc",
"version": "2.7.1",
"version": "2.7.2",
"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.1' > release/version",
"version": "echo '2.7.2' > 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
29 changes: 25 additions & 4 deletions src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,10 +228,31 @@ const getMethodName = (

if (!_name) return _name;

const regExp = /[\\{|:](\w+)[\\}]/;
if (regExp.test(_name)) {
const regExp = /[\\{|:](\w+)[\\}]/g;
const regReplace = /[\\{|:\\}]/g
if (regExp.test(_url)) {
// 取最后一个动态路径
const _lastName = _url.match(regExp)?.pop()?.replace(regReplace, "");

// 若 _name 中存在动态路径,判断是否与 _lastName 重复
if (regExp.test(_name)) {
const _namePath = _name.match(regExp)?.reduce<string[]>((prev, current) => {
const _n = current.replace(regReplace, "")

// 移除与 _lastName 重复的
if (_n !== _lastName) {
prev.push(_n)
}
return prev
}, []).join('_') ?? ''

if (_namePath) {
_name = `${conjunction}_${_namePath}`
}
}

// 动态路径添加连接字符
_name = `${conjunction}_${_name.match(regExp)![1]}`;
_name = `${_name}_${conjunction}_${_lastName}`;
}

// 方法名小驼峰
Expand Down Expand Up @@ -474,7 +495,7 @@ export const getApiPath = (
options?.tag,
);

name = `${url}@${name}`;
name = `${value.tag}@${name}`;

if (pathMap.has(name)) {
Logs.error(
Expand Down
4 changes: 2 additions & 2 deletions src/i18n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
"parserTypeError": "The {{type}} type could not be resolved."
},
"path": {
"notName": "{{url}} {{method}} cannot get the method name, so it will be ignored.",
"duplicate": "{{url}} {{method}} has the same method name {{name}}, you can set the `--actionIndex` option."
"notName": "{{url}} [{{method}}] cannot get the method name, so it will be ignored.",
"duplicate": "{{url}} [{{method}}] has the same method name {{name}}, you can set the `--actionIndex` option."
},
"app": {
"apiJsonFileError": "API file parsing failed. Reason: {{error}}",
Expand Down
4 changes: 2 additions & 2 deletions src/i18n/locales/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
"parserTypeError": "{{type}} 类型无法解析。"
},
"path": {
"notName": "{{url}} {{method}} 无法获取方法名称,故忽略。",
"duplicate": "{{url}} {{method}} 的 {{name}} 方法名重复,可设置 `--actionIndex` 选项。"
"notName": "{{url}} {{method}} 无法获取方法名称,故忽略。",
"duplicate": "{{url}} {{method}} 的 {{name}} 方法名重复,可设置 `--actionIndex` 选项。"
},
"app": {
"apiJsonFileError": "API 文件解析失败。原因:{{error}}",
Expand Down
4 changes: 2 additions & 2 deletions src/npm/pkg.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@loongwoo/stc",
"version": "2.7.1",
"version": "2.7.2",
"description": "A tool for converting OpenApi/Swagger/Apifox into code.",
"type": "module",
"module": "esm/mod.js",
Expand All @@ -18,7 +18,7 @@
"apifox",
"stc"
],
"author": "loong.woo",
"author": "lonu",
"license": "MIT",
"bugs": {
"url": "https://github.com/long-woo/stc/issues"
Expand Down

0 comments on commit 002a7ce

Please sign in to comment.