api-render-ui 1.1.2 → 1.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -20,7 +20,7 @@ export class ApiRenderer {
20
20
  this.container = null;
21
21
  }
22
22
 
23
- render(apiSpec: OpenAPIV3CustomDoc, renderUnit: boolean = false) {
23
+ render(apiSpec: OpenAPIV3CustomDoc, currentServer?: any, serviceName?: string, renderUnit: boolean = false) {
24
24
 
25
25
  const appendInlineStyle = (text: string) => {
26
26
  if (!ApiRenderer.globalStyleInjected) {
@@ -49,7 +49,7 @@ export class ApiRenderer {
49
49
  if ((apiSpec["openapi"] && apiSpec["openapi"].startsWith("3."))
50
50
  || (apiSpec["swagger"] && apiSpec["swagger"].startsWith("2."))) {
51
51
  const countApi = countOpenAPI(apiSpec);
52
- const apiOperatorList = parseOpenAPI(apiSpec);
52
+ const apiOperatorList = parseOpenApiSpec(apiSpec, currentServer, serviceName);
53
53
  // console.log('解析结果:', apiOperatorList);
54
54
  if (countApi == 1 && renderUnit) {
55
55
  // If the count of api <=1, create the api unit only.
@@ -1521,7 +1521,7 @@ function isHttpMethod(method: string): method is HttpMethod {
1521
1521
  }
1522
1522
 
1523
1523
  // 解析OpenAPI规范并构建API操作列表
1524
- function parseOpenAPI(openapiSpec: OpenAPIV3CustomDoc) {
1524
+ function parseOpenApiSpec(openapiSpec: OpenAPIV3CustomDoc, currentServer?: any, serviceName?: string) {
1525
1525
  const apiOperatorList: any = [];
1526
1526
 
1527
1527
  const pathEntries: [string, OpenAPIV3.PathItemObject | undefined][] = [];
@@ -1549,9 +1549,16 @@ function parseOpenAPI(openapiSpec: OpenAPIV3CustomDoc) {
1549
1549
  // 遍历路径下的所有方法
1550
1550
  pathItemEntries.forEach(([method, operation]) => {
1551
1551
  // 初始化当前API操作对象
1552
+ let url = path
1553
+ if (currentServer) {
1554
+ url = currentServer.value + "/api/" + serviceName + "/v1" + path;
1555
+ } else if (openapiSpec.servers && openapiSpec.servers.length > 0) {
1556
+ url = openapiSpec.servers[0].url + path;
1557
+ }
1558
+
1552
1559
  const apiOperator: any = {
1553
1560
  method: method.toUpperCase(),
1554
- url: path,
1561
+ url: url,
1555
1562
  rawApiInfo: operation,
1556
1563
  requestBody: null,
1557
1564
  response: {},