Skip to content

Commit 6d6129d

Browse files
committed
refactor: 循环提前结束
1 parent 6b16ff6 commit 6d6129d

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

src/lib/document-to-meta.ts

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,17 @@ export const documentToMeta = (docs: OpenAPIV3.Document) => {
3030

3131
Object.entries(docs.paths).forEach(([uri, pathItem]) => {
3232
methods.forEach((method) => {
33-
if (pathItem?.[method]) {
34-
const methodItem = pathItem[method];
35-
metas[method].push({
36-
uri,
37-
key:
38-
methodItem.operationId ||
39-
snakeCase(`${method}_${uri.replaceAll(':', '_by_')}`),
40-
query: parseParameters(docs, pathItem, methodItem, 'query'),
41-
params: parseParameters(docs, pathItem, methodItem, 'path'),
42-
...parseRequestBody(docs, methodItem),
43-
...parseResponse(docs, methodItem),
44-
});
45-
}
33+
if (!pathItem || !pathItem[method]) return;
34+
const methodItem = pathItem[method]!;
35+
metas[method].push({
36+
uri,
37+
key:
38+
methodItem.operationId || snakeCase(`${method}_${uri.replaceAll(':', '_by_')}`),
39+
query: parseParameters(docs, pathItem, methodItem, 'query'),
40+
params: parseParameters(docs, pathItem, methodItem, 'path'),
41+
...parseRequestBody(docs, methodItem),
42+
...parseResponse(docs, methodItem),
43+
});
4644
});
4745
});
4846

0 commit comments

Comments
 (0)