Skip to content

Commit 2868dc4

Browse files
simplify
1 parent d63dab9 commit 2868dc4

File tree

1 file changed

+17
-20
lines changed

1 file changed

+17
-20
lines changed

packages/oats/src/util.ts

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -31,26 +31,23 @@ export function filterEndpointsInSpec(
3131
{ paths: specPaths, ...restSpec }: oas.OpenAPIObject,
3232
includeEndpoint: IncludeEndpointFilter
3333
): oas.OpenAPIObject {
34-
const filteredPathEntries = Object.entries(specPaths).flatMap(
35-
([path, pathObject]: [string, oas.PathItemObject]) => {
36-
const filteredPathObject: oas.PathItemObject = Object.fromEntries(
37-
Object.entries(pathObject).filter(
38-
([key]) =>
39-
!server.supportedMethods.includes(key as server.Methods) ||
40-
includeEndpoint(path, key.toUpperCase() as Uppercase<server.Methods>)
41-
)
42-
);
43-
const hasMethods = server.supportedMethods.some(method => filteredPathObject[method]);
44-
45-
if (!hasMethods) {
46-
return [];
47-
}
48-
return [[path, filteredPathObject]] as const;
49-
}
50-
);
51-
const filteredPaths = Object.fromEntries(filteredPathEntries);
52-
53-
return { ...restSpec, paths: filteredPaths };
34+
return {
35+
...restSpec,
36+
paths: Object.fromEntries(
37+
Object.entries(specPaths)
38+
.map(([path, pathObject]): [string, oas.PathItemObject] => [
39+
path,
40+
Object.fromEntries(
41+
Object.entries(pathObject).filter(
42+
([key]) =>
43+
!server.supportedMethods.includes(key as server.Methods) ||
44+
includeEndpoint(path, key.toUpperCase() as Uppercase<server.Methods>)
45+
)
46+
)
47+
])
48+
.filter(([, pathObject]) => server.supportedMethods.some(method => pathObject[method]))
49+
)
50+
};
5451
}
5552

5653
export function isReferenceObject(schema: any): schema is oas.ReferenceObject {

0 commit comments

Comments
 (0)