feat: 添加接口生成的测试
parent
84685a7f19
commit
399ee75183
|
|
@ -0,0 +1,40 @@
|
||||||
|
version: '3'
|
||||||
|
|
||||||
|
services:
|
||||||
|
server:
|
||||||
|
image: git.dev.juetan.cn/juetan/server:latest
|
||||||
|
networks:
|
||||||
|
- public
|
||||||
|
deploy:
|
||||||
|
mode: replicated
|
||||||
|
replicas: 1
|
||||||
|
placement:
|
||||||
|
constraints: [node.role == manager]
|
||||||
|
labels:
|
||||||
|
- traefik.enable=true
|
||||||
|
- traefik.http.routers.nest.rule=Host(`nest.dev.juetan.cn`) && PathPrefix(`/api`, `/upload`)
|
||||||
|
- traefik.http.routers.nest.entrypoints=websecure
|
||||||
|
- traefik.http.routers.nest.tls=true
|
||||||
|
- traefik.http.routers.nest.tls.certresolver=acmer
|
||||||
|
- traefik.http.services.nest1.loadbalancer.server.port=3030
|
||||||
|
|
||||||
|
web:
|
||||||
|
image: git.dev.juetan.cn/juetan/web:latest
|
||||||
|
networks:
|
||||||
|
- public
|
||||||
|
deploy:
|
||||||
|
mode: replicated
|
||||||
|
replicas: 1
|
||||||
|
placement:
|
||||||
|
constraints: [node.role == manager]
|
||||||
|
labels:
|
||||||
|
- traefik.enable=true
|
||||||
|
- traefik.http.routers.vue.rule=Host(`nest.dev.juetan.cn`)
|
||||||
|
- traefik.http.routers.vue.entrypoints=websecure
|
||||||
|
- traefik.http.routers.vue.tls=true
|
||||||
|
- traefik.http.routers.vue.tls.certresolver=acmer
|
||||||
|
- traefik.http.services.vue1.loadbalancer.server.port=80
|
||||||
|
|
||||||
|
networks:
|
||||||
|
public:
|
||||||
|
external: true
|
||||||
|
|
@ -1,2 +1 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" style="margin: auto; background: rgb(255, 255, 255); display: block; shape-rendering: auto;" width="200px" height="200px" viewBox="0 0 100 100" preserveAspectRatio="xMidYMid"><g transform="translate(50 50)"><g><animateTransform attributeName="transform" type="rotate" values="0;45" keyTimes="0;1" dur="0.2s" repeatCount="indefinite"></animateTransform><path d="M29.491524206117255 -5.5 L37.491524206117255 -5.5 L37.491524206117255 5.5 L29.491524206117255 5.5 A30 30 0 0 1 24.742744050198738 16.964569457146712 L24.742744050198738 16.964569457146712 L30.399598299691117 22.621423706639092 L22.621423706639096 30.399598299691114 L16.964569457146716 24.742744050198734 A30 30 0 0 1 5.5 29.491524206117255 L5.5 29.491524206117255 L5.5 37.491524206117255 L-5.499999999999997 37.491524206117255 L-5.499999999999997 29.491524206117255 A30 30 0 0 1 -16.964569457146705 24.742744050198738 L-16.964569457146705 24.742744050198738 L-22.621423706639085 30.399598299691117 L-30.399598299691117 22.621423706639092 L-24.742744050198738 16.964569457146712 A30 30 0 0 1 -29.491524206117255 5.500000000000009 L-29.491524206117255 5.500000000000009 L-37.491524206117255 5.50000000000001 L-37.491524206117255 -5.500000000000001 L-29.491524206117255 -5.500000000000002 A30 30 0 0 1 -24.742744050198738 -16.964569457146705 L-24.742744050198738 -16.964569457146705 L-30.399598299691117 -22.621423706639085 L-22.621423706639092 -30.399598299691117 L-16.964569457146712 -24.742744050198738 A30 30 0 0 1 -5.500000000000011 -29.491524206117255 L-5.500000000000011 -29.491524206117255 L-5.500000000000012 -37.491524206117255 L5.499999999999998 -37.491524206117255 L5.5 -29.491524206117255 A30 30 0 0 1 16.964569457146702 -24.74274405019874 L16.964569457146702 -24.74274405019874 L22.62142370663908 -30.39959829969112 L30.399598299691117 -22.6214237066391 L24.742744050198738 -16.964569457146716 A30 30 0 0 1 29.491524206117255 -5.500000000000013 M0 -20A20 20 0 1 0 0 20 A20 20 0 1 0 0 -20" fill="#09f"></path></g></g></svg>
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" style="margin: auto; background: rgb(255, 255, 255); display: block; shape-rendering: auto;" width="200px" height="200px" viewBox="0 0 100 100" preserveAspectRatio="xMidYMid"><g transform="translate(50 50)"><g><animateTransform attributeName="transform" type="rotate" values="0;45" keyTimes="0;1" dur="0.2s" repeatCount="indefinite"></animateTransform><path d="M29.491524206117255 -5.5 L37.491524206117255 -5.5 L37.491524206117255 5.5 L29.491524206117255 5.5 A30 30 0 0 1 24.742744050198738 16.964569457146712 L24.742744050198738 16.964569457146712 L30.399598299691117 22.621423706639092 L22.621423706639096 30.399598299691114 L16.964569457146716 24.742744050198734 A30 30 0 0 1 5.5 29.491524206117255 L5.5 29.491524206117255 L5.5 37.491524206117255 L-5.499999999999997 37.491524206117255 L-5.499999999999997 29.491524206117255 A30 30 0 0 1 -16.964569457146705 24.742744050198738 L-16.964569457146705 24.742744050198738 L-22.621423706639085 30.399598299691117 L-30.399598299691117 22.621423706639092 L-24.742744050198738 16.964569457146712 A30 30 0 0 1 -29.491524206117255 5.500000000000009 L-29.491524206117255 5.500000000000009 L-37.491524206117255 5.50000000000001 L-37.491524206117255 -5.500000000000001 L-29.491524206117255 -5.500000000000002 A30 30 0 0 1 -24.742744050198738 -16.964569457146705 L-24.742744050198738 -16.964569457146705 L-30.399598299691117 -22.621423706639085 L-22.621423706639092 -30.399598299691117 L-16.964569457146712 -24.742744050198738 A30 30 0 0 1 -5.500000000000011 -29.491524206117255 L-5.500000000000011 -29.491524206117255 L-5.500000000000012 -37.491524206117255 L5.499999999999998 -37.491524206117255 L5.5 -29.491524206117255 A30 30 0 0 1 16.964569457146702 -24.74274405019874 L16.964569457146702 -24.74274405019874 L22.62142370663908 -30.39959829969112 L30.399598299691117 -22.6214237066391 L24.742744050198738 -16.964569457146716 A30 30 0 0 1 29.491524206117255 -5.500000000000013 M0 -20A20 20 0 1 0 0 20 A20 20 0 1 0 0 -20" fill="#09f"></path></g></g></svg>
|
|
||||||
|
|
|
||||||
|
Before Width: | Height: | Size: 2.1 KiB After Width: | Height: | Size: 2.1 KiB |
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1,75 @@
|
||||||
|
import fs from 'fs'
|
||||||
|
import doc from './openapi1.json';
|
||||||
|
|
||||||
|
interface Param {
|
||||||
|
name: string;
|
||||||
|
required: boolean;
|
||||||
|
description: string;
|
||||||
|
example: string;
|
||||||
|
schema: {
|
||||||
|
type: string;
|
||||||
|
[key: string]: any;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
interface JsonParam {
|
||||||
|
name: string;
|
||||||
|
type: string;
|
||||||
|
required: boolean;
|
||||||
|
description: string;
|
||||||
|
example: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
const run = () => {
|
||||||
|
const { paths } = doc
|
||||||
|
const routes: any[] = []
|
||||||
|
for(const [path, obj] of Object.entries(paths)) {
|
||||||
|
for(const [method, obj1] of Object.entries(obj)) {
|
||||||
|
const { tags, summary, operationId, description, parameters, requestBody, responses } = obj1
|
||||||
|
|
||||||
|
const { content = {} } = requestBody || {}
|
||||||
|
const { schema = {} } = content['application/json'] || {}
|
||||||
|
const { properties = {}, required: requireds = [] } = schema
|
||||||
|
const bodyParams = {}
|
||||||
|
for(const [id, obj2 = {}] of Object.entries(properties)) {
|
||||||
|
const { type, description, example } = obj2 as any;
|
||||||
|
const required = requireds.includes(id)
|
||||||
|
const param: JsonParam = {
|
||||||
|
...(obj2 as any),
|
||||||
|
name: id,
|
||||||
|
type,
|
||||||
|
required,
|
||||||
|
description,
|
||||||
|
example,
|
||||||
|
}
|
||||||
|
bodyParams[id] = param
|
||||||
|
}
|
||||||
|
|
||||||
|
const { content: content1 = {} } = responses['200'] || {}
|
||||||
|
const { schema: schema1 = {} } = content1['application/json'] || {}
|
||||||
|
let resBody = {}
|
||||||
|
if(schema1.type === 'object') {
|
||||||
|
resBody = schema1.properties?.data;
|
||||||
|
}
|
||||||
|
|
||||||
|
const pathParams = parameters.filter((i: any) => i.in === 'path')
|
||||||
|
const queryParams = parameters.filter((i: any) => i.in === 'query')
|
||||||
|
const route = {
|
||||||
|
method,
|
||||||
|
path,
|
||||||
|
tag: tags?.[0],
|
||||||
|
summary,
|
||||||
|
operationId,
|
||||||
|
description,
|
||||||
|
pathParams,
|
||||||
|
queryParams,
|
||||||
|
bodyParams,
|
||||||
|
resBody,
|
||||||
|
}
|
||||||
|
routes.push(route)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fs.writeFileSync('12.json', JSON.stringify(routes, null, 2));
|
||||||
|
}
|
||||||
|
|
||||||
|
run();
|
||||||
|
|
@ -8,9 +8,9 @@ const env = loadEnv("development", process.cwd());
|
||||||
|
|
||||||
const run = async () => {
|
const run = async () => {
|
||||||
const output = await generateApi({
|
const output = await generateApi({
|
||||||
url: env.VITE_OPENAPI,
|
url: "http://localhost:3030/openapi.json",
|
||||||
templates: path.resolve(__dirname, "./template"),
|
templates: path.resolve(__dirname, "./template"),
|
||||||
output: path.resolve(process.cwd(), "src/api/service"),
|
// output: path.resolve(process.cwd(), "src/api/service"),
|
||||||
name: "Api.ts",
|
name: "Api.ts",
|
||||||
singleHttpClient: false,
|
singleHttpClient: false,
|
||||||
httpClientType: "axios",
|
httpClientType: "axios",
|
||||||
|
|
@ -28,6 +28,7 @@ const run = async () => {
|
||||||
parser: "typescript",
|
parser: "typescript",
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
debugger;
|
||||||
return output;
|
return output;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1,11 @@
|
||||||
|
import parser from '@apidevtools/swagger-parser'
|
||||||
|
import apiJson from './openapi.json'
|
||||||
|
import fs from 'fs'
|
||||||
|
|
||||||
|
const run = async () => {
|
||||||
|
const api = await parser.validate(apiJson as any)
|
||||||
|
console.log(api);
|
||||||
|
fs.writeFileSync('./openapi1.json', JSON.stringify(api, null, 2))
|
||||||
|
}
|
||||||
|
|
||||||
|
run()
|
||||||
|
|
@ -8,7 +8,7 @@
|
||||||
},
|
},
|
||||||
"include": [
|
"include": [
|
||||||
"vite.config.ts",
|
"vite.config.ts",
|
||||||
"scripts/vite/**/*",
|
"scripts/vite/**/*.ts",
|
||||||
"scripts/vite/icon-file.json",
|
"scripts/vite/icon-file.json",
|
||||||
"package.json",
|
"package.json",
|
||||||
"src/types/env.d.ts"
|
"src/types/env.d.ts"
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue