Skip to content

Commit 6e6a975

Browse files
authored
fix: Fixed issues where some API debugging failed (#194)
* fix: 修复ROA类型API调试不成功的问题 * fix: 修复主题色适配问题 * fix: 修复POP验签失败的问题
1 parent 3401701 commit 6e6a975

File tree

5 files changed

+88
-86
lines changed

5 files changed

+88
-86
lines changed

media/src/components/APIPage/API.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ export const API: React.FC<APIProps> = (props) => {
263263
setIsVisible={setIsSearchVisible}
264264
mode={mode}
265265
></Searcher>
266-
<div className="bg-[var(--vscode-textBlockQuote-background)] pb-4" ref={contentRef}>
266+
<div className="bg-[var(--vscode-editorWidget-background)] pb-4" ref={contentRef}>
267267
<APIPageContext.Provider
268268
initialState={{
269269
apiMeta: selectedApi,

media/src/styles/Markdown.scss

+1-1
Original file line numberDiff line numberDiff line change
@@ -2556,7 +2556,7 @@ table .semix-markdown {
25562556
}
25572557
.semix-schema-table.semix-tree-table thead th {
25582558
background-color: $table-th-bg;
2559-
color: $primary-font-color;
2559+
color: $table-th-font-color;
25602560
}
25612561
.semix-schema-table {
25622562
.name {

media/src/styles/variable.scss

+2
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,5 @@ $disable-font-color: var(--vscode-editorHint-foreground);
3939
//链接颜色
4040
$primary-anchor-color: var(--vscode-editorLink-activeForeground);
4141
$hover-text-color: var(--vscode-editorHoverWidget-foreground);
42+
// 表格title字体
43+
$table-th-font-color: var(--vscode-badge-foreground);

src/openApiService/request/request.ts

+83-84
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,62 @@
1-
'use strict';
2-
const $Credential = require('@alicloud/credentials');
3-
const { default: Credential } = require('@alicloud/credentials');
4-
const FILTER_METHOD = ['HEAD', 'TRACE', 'OPTIONS', 'PATCH', 'CONNECT'];
5-
import {OpenAPIClient} from '../lib/client'
1+
"use strict";
2+
const $Credential = require("@alicloud/credentials");
3+
const { default: Credential } = require("@alicloud/credentials");
4+
const FILTER_METHOD = ["HEAD", "TRACE", "OPTIONS", "PATCH", "CONNECT"];
5+
import { OpenAPIClient } from "../lib/client";
66

77
function _bodyType(types) {
88
if (!types || types.length < 1) {
9-
return 'none';
9+
return "none";
1010
}
1111

1212
const type = types[0];
1313

14-
if (type === 'application/json') {
15-
return 'json';
14+
if (type === "application/json") {
15+
return "json";
1616
}
1717

18-
if (type === 'application/xml') {
19-
return 'xml';
18+
if (type === "application/xml") {
19+
return "xml";
2020
}
2121

22-
if (type === 'application/x-www-form-urlencoded') {
23-
return 'form';
22+
if (type === "application/x-www-form-urlencoded") {
23+
return "form";
2424
}
2525

26-
if (type === 'application/octet-stream') {
27-
return 'binary';
26+
if (type === "application/octet-stream") {
27+
return "binary";
2828
}
2929

30-
return 'none';
30+
return "none";
3131
}
3232

33-
function getMethod(method) {
33+
function getMethodByString(method) {
3434
let methodArray;
35-
if (method.includes('|')) {
36-
methodArray = method.split('|');
37-
} else if (method.includes(',')) {
38-
methodArray = method.split(',');
35+
if (method.includes("|")) {
36+
methodArray = method.split("|");
37+
} else if (method.includes(",")) {
38+
methodArray = method.split(",");
3939
} else {
4040
return method;
4141
}
42-
if (methodArray.includes('POST')) {
43-
return 'POST';
42+
if (methodArray.includes("POST")) {
43+
return "POST";
4444
}
45-
const vaildMethod = methodArray.filter(item => FILTER_METHOD.indexOf(item) <= -1);
45+
const vaildMethod = methodArray.filter((item) => FILTER_METHOD.indexOf(item) <= -1);
4646
if (vaildMethod.length > 0) {
4747
return vaildMethod[0];
48-
}
48+
}
4949
return methodArray[0];
50-
50+
}
51+
52+
function getMethod(methods: string[]) {
53+
const vaildMethod = methods?.filter((item) => FILTER_METHOD.indexOf(item?.toUpperCase()) <= -1);
54+
if (methods?.includes("post")) {
55+
return "POST";
56+
} else if (vaildMethod.length > 0) {
57+
return vaildMethod[0]?.toUpperCase();
58+
}
59+
return methods[0]?.toUpperCase();
5160
}
5261

5362
export class OpenAPIOptions {
@@ -86,47 +95,40 @@ export class OpenAPIOptions {
8695
}
8796

8897
export const request = async function (options: OpenAPIOptions) {
89-
let {
90-
endpoint,
91-
action,
92-
apiVersion,
93-
params,
94-
accessKeyId,
95-
accessKeySecret,
96-
productName,
97-
meta,
98-
bodyStyle,
99-
credential
100-
} = options;
101-
let method = meta?.method?.toUpperCase();
102-
let protocol = 'https';
103-
endpoint = endpoint ? endpoint.replace('http://', '').replace('https://', '') : `${productName.toLowerCase()}.cn-hangzhou.aliyuncs.com`;
104-
let pathname = '/';
105-
const schema = meta?.responses['200'] && meta?.responses['200'].schema;
98+
let { endpoint, action, apiVersion, params, accessKeyId, accessKeySecret, productName, meta, bodyStyle, credential } =
99+
options;
100+
// let method = meta?.method?.toUpperCase();
101+
let method = getMethod(meta?.methods);
102+
let protocol = "https";
103+
endpoint = endpoint
104+
? endpoint.replace("http://", "").replace("https://", "")
105+
: `${productName.toLowerCase()}.cn-hangzhou.aliyuncs.com`;
106+
let pathname = meta?.path?.length ? meta.path : "/";
107+
const schema = meta?.responses["200"] && meta?.responses["200"].schema;
106108
let requestType;
107-
if(meta?.consumes){
108-
requestType = _bodyType(meta?.consumes)
109-
}else{
110-
requestType = bodyStyle === 'json' ? 'json' : 'formData';
109+
if (meta?.consumes) {
110+
requestType = _bodyType(meta?.consumes);
111+
} else {
112+
requestType = bodyStyle === "json" ? "json" : "formData";
111113
}
112114
let responseType;
113-
115+
114116
if (!schema) {
115117
responseType = _bodyType(meta.apis[action] && meta.apis[action].produces);
116118
} else if (schema.xml) {
117-
responseType = 'xml';
118-
} else if (schema.type && schema.type !== 'object') {
119+
responseType = "xml";
120+
} else if (schema.type && schema.type !== "object") {
119121
responseType = schema.format || schema.type;
120-
} else if (meta?.ext?.produces){
122+
} else if (meta?.ext?.produces) {
121123
responseType = _bodyType(meta.ext.produces);
122-
}else {
123-
responseType = 'json';
124+
} else {
125+
responseType = "json";
124126
}
125127

126128
let request = {} as any;
127129
request.headers = {};
128-
if (productName === 'ROS' && params.RegionId) {
129-
request.headers['x-acs-region-id'] = params.RegionId;
130+
if (productName === "ROS" && params.RegionId) {
131+
request.headers["x-acs-region-id"] = params.RegionId;
130132
}
131133

132134
// const newParams = {};
@@ -136,90 +138,87 @@ export const request = async function (options: OpenAPIOptions) {
136138
// });
137139
// paramObject.params = newParams;
138140
const parameters = {};
139-
meta?.parameters?.map(param=>{
141+
meta?.parameters?.map((param) => {
140142
parameters[param.name] = param;
141-
})
143+
});
142144
// paramObject.params = params;
143145

144146
// eslint-disable-next-line guard-for-in
145147
for (let name in params) {
146148
let paramInfo = parameters[name];
147149
let value = params[name];
148150
if (paramInfo) {
149-
if (paramInfo.style
150-
&& paramInfo.style === 'json'
151-
&& typeof value !== 'string') {
151+
if (paramInfo.style && paramInfo.style === "json" && typeof value !== "string") {
152152
value = JSON.stringify(value);
153153
}
154-
if (paramInfo.style
155-
&& Array.isArray(value)) {
154+
if (paramInfo.style && Array.isArray(value)) {
156155
switch (paramInfo.style) {
157-
case 'simple':
158-
value = value.join(',');
156+
case "simple":
157+
value = value.join(",");
159158
break;
160-
case 'spaceDelimited':
161-
value = value.join(' ');
159+
case "spaceDelimited":
160+
value = value.join(" ");
162161
break;
163-
case 'pipeDelimited':
164-
value = value.join('|');
162+
case "pipeDelimited":
163+
value = value.join("|");
165164
break;
166165
}
167166
}
168167

169168
switch (paramInfo.in) {
170-
case 'path':
169+
case "path":
171170
// path:"/repos/{RepoNamespace}/{RepoName}/build/[BuildId]/cancel"
172-
if (pathname.indexOf('*') !== -1 && name === 'requestPath') {
171+
if (pathname.indexOf("*") !== -1 && name === "requestPath") {
173172
pathname = value;
174173
} else if (pathname.includes(name)) {
175174
pathname = pathname.replace(`{${name}}`, value);
176175
}
177176
break;
178-
case 'host':
177+
case "host":
179178
// endpoint 已经在前端处理过了
180179
// host 一般是 regionId
181180
break;
182-
case 'query':
181+
case "query":
183182
if (!request.query) {
184183
request.query = {};
185184
}
186185
request.query[name] = value;
187186
break;
188-
case 'body':
189-
case 'formData':
187+
case "body":
188+
case "formData":
190189
if (!request.body) {
191190
request.body = {};
192191
}
193-
if (bodyStyle === 'json') {
192+
if (bodyStyle === "json") {
194193
request.body = params[name];
195-
} else if (name === 'RequestBody' && paramInfo.type === 'RequestBody') {
194+
} else if (name === "RequestBody" && paramInfo.type === "RequestBody") {
196195
request.body = params[name];
197196
} else {
198197
request.body[name] = value;
199198
}
200-
if (paramInfo.type === 'Binary') {
199+
if (paramInfo.type === "Binary") {
201200
// TODO:上传文件
202201
// request.stream = await ossUtil.getStream(`tmpFile/${params[name]}`);
203202
}
204203
break;
205-
case 'header':
204+
case "header":
206205
request.headers[name] = value;
207206
break;
208207
}
209-
} else if (bodyStyle === 'json' && name === 'body' && params.body) {
208+
} else if (bodyStyle === "json" && name === "body" && params.body) {
210209
// 兼容 bodyStyle 为 json,且不传 body 层的情况
211210
// 兼容 bodyStyle 为 json,且不传 body 层的情况
212-
if (typeof params.body === 'string') {
211+
if (typeof params.body === "string") {
213212
request.body = JSON.parse(params.body);
214213
} else {
215214
request.body = params.body;
216215
}
217216
}
218217
}
219218
let _credential;
220-
if (credential && credential.type === 'bearer') {
219+
if (credential && credential.type === "bearer") {
221220
let credentialConfig = new $Credential.Config({
222-
type: 'bearer',
221+
type: "bearer",
223222
bearerToken: credential.token,
224223
});
225224
_credential = new Credential(credentialConfig);
@@ -231,7 +230,7 @@ export const request = async function (options: OpenAPIOptions) {
231230
credential: _credential,
232231
protocol: protocol,
233232
readTimeout: 50000,
234-
connectTimeout: 50000
233+
connectTimeout: 50000,
235234
});
236235
const data = {
237236
version: apiVersion,
@@ -240,7 +239,7 @@ export const request = async function (options: OpenAPIOptions) {
240239
action,
241240
reqBodyType: requestType,
242241
bodyType: responseType,
243-
authType: 'AK',
242+
authType: "AK",
244243
};
245244
return await client.doRequest(data, request, {});
246-
};
245+
};

src/plugins/parser.ts

+1
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ function parseAlicloudAPI(apiName: string, api: any, style = "RPC", meta: Simple
166166
title: (api as any).title || summary,
167167
name: apiName,
168168
method: methods?.[0],
169+
methods: methods,
169170
path,
170171
parameters: _.unionBy<PontSpec.Parameter>(newParameters, "name"),
171172
responses: parseResponses(responses, meta),

0 commit comments

Comments
 (0)