Skip to content

Commit

Permalink
Merge pull request #94 from long-woo/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
long-woo authored Dec 10, 2024
2 parents 399a977 + b0597da commit e82ad72
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 19 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].0/mod.ts'
import { start } from 'jsr:@loongwoo/stc@^2.7.0'
// import { start } from 'https://deno.land/x/[email protected].1/mod.ts'
import { start } from 'jsr:@loongwoo/stc@^2.7.1'

// Defining plugins
const myPlugin: IPlugin = {
Expand Down
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.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",
Expand Down
24 changes: 13 additions & 11 deletions src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]}`;
}

// 方法名小驼峰
Expand Down Expand Up @@ -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 ?? {},
Expand Down Expand Up @@ -473,7 +474,7 @@ export const getApiPath = (
options?.tag,
);

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

if (pathMap.has(name)) {
Logs.error(
Expand All @@ -486,6 +487,7 @@ export const getApiPath = (

return;
}

pathMap.set(name, value);
});
});
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": "@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",
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/javascript/oxc.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand Down
1 change: 1 addition & 0 deletions src/swagger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export interface ISwaggerContentSchema {
export interface ISwaggerContent {
"application/json"?: ISwaggerContentSchema;
"application/octet-stream"?: ISwaggerContentSchema;
"text/plain": ISwaggerContentSchema;
}

interface ISwaggerMethodResponseStatus {
Expand Down
4 changes: 2 additions & 2 deletions test/swagger-4.test.ts
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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",
Expand Down

0 comments on commit e82ad72

Please sign in to comment.