-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathgenerateValidRootSchema.ts
More file actions
33 lines (32 loc) · 985 Bytes
/
generateValidRootSchema.ts
File metadata and controls
33 lines (32 loc) · 985 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import type * as Types from "./types";
export const generateValidRootSchema = (input: Types.OpenApi.Document): Types.OpenApi.Document => {
if (!input.paths) {
return input;
}
/** update undefined operation id */
for (const [path, methods] of Object.entries(input.paths || {})) {
const targets = {
get: methods.get,
put: methods.put,
post: methods.post,
delete: methods.delete,
options: methods.options,
head: methods.head,
patch: methods.patch,
trace: methods.trace,
} satisfies Record<string, Types.OpenApi.Operation | undefined>;
for (const [method, operation] of Object.entries(targets)) {
if (!operation) {
continue;
}
// skip reference object
if ("$ref" in operation) {
continue;
}
if (!operation.operationId) {
operation.operationId = `${method.toLowerCase()}${path.charAt(0).toUpperCase() + path.slice(1)}`;
}
}
}
return input;
};