Skip to content

Commit

Permalink
fix: fix get baseURL
Browse files Browse the repository at this point in the history
  • Loading branch information
rookie-luochao committed Apr 20, 2024
1 parent 09d7cb5 commit da0d9e4
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README-zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
</head>
<body>
<div id="openapi-ui-container" spec-url="https://petstore3.swagger.io/api/v3/openapi.json"></div>
<script src="https://cdn.jsdelivr.net/npm/openapi-ui-dist@2.0.0/lib/openapi-ui.umd.js"></script>
<script src="https://cdn.jsdelivr.net/npm/openapi-ui-dist@latest/lib/openapi-ui.umd.js"></script>
</body>
</html>
```
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ OpenAPI/Swagger UI document, quickly generate mock params and call api, also sim
</head>
<body>
<div id="openapi-ui-container" spec-url="https://petstore3.swagger.io/api/v3/openapi.json"></div>
<script src="https://cdn.jsdelivr.net/npm/openapi-ui-dist@2.0.0/lib/openapi-ui.umd.js"></script>
<script src="https://cdn.jsdelivr.net/npm/openapi-ui-dist@latest/lib/openapi-ui.umd.js"></script>
</body>
</html>
```
Expand Down
2 changes: 1 addition & 1 deletion src/components/head/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export function Head() {
}, []);

async function refetchOpenapiInfo(url: string, isCallBySearchInput?: boolean) {
const res = await request(Object.assign({ url: url }));
const res = await request({ url: url });

if (res?.status >= 200 && res?.status < 300) {
const openapi = await parseSwaggerOrOpenapi(res.data);
Expand Down
2 changes: 1 addition & 1 deletion src/components/package-config/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export function InitPackageConfig() {
}, []);

async function fetchOpenapiInfo(url: string) {
const res = await request(Object.assign({ url: url }));
const res = await request({ url: url });

if (res?.status >= 200 && res?.status < 300) {
const openapi = await parseSwaggerOrOpenapi(res.data);
Expand Down
9 changes: 7 additions & 2 deletions src/openapi/util.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { keys, map, replace } from "lodash-es";
import { urlRegex } from "../core/regex";
import { dsc } from "../core/style/defaultStyleConfig";
import { IMethodType, IRequestBody, MethodType } from "./type";

Expand Down Expand Up @@ -80,8 +81,12 @@ export function getAxiosBasePathByUrl(url: string) {
return "//serviceURL";
}

const tmpStrs = url.split("//");
const basePath = `${tmpStrs[0]}//${tmpStrs[1].split("/")[0]}`;
let basePath = "";

if (urlRegex.test(url)) {
const tmpStrs = url.split("//");
basePath = `${tmpStrs[0]}//${tmpStrs[1].split("/")[0]}`;
}

return basePath;
}
Expand Down

0 comments on commit da0d9e4

Please sign in to comment.