-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfilter-deprecated-params.js
More file actions
44 lines (38 loc) · 1.4 KB
/
filter-deprecated-params.js
File metadata and controls
44 lines (38 loc) · 1.4 KB
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
34
35
36
37
38
39
40
41
42
43
44
const fs = require("fs");
const yaml = require("yaml");
// Load the input file
const inputFile = "openapi.yaml";
const outputFile = "openapi.filtered.yaml";
try {
const fileContent = fs.readFileSync(inputFile, "utf8");
const openapi = yaml.parse(fileContent);
// Function to filter out deprecated parameters
const removeDeprecatedParams = (parameters) =>
parameters.filter((param) => !param.deprecated);
// Iterate through paths and methods to filter parameters
Object.entries(openapi.paths).forEach(([path, methods]) => {
Object.entries(methods).forEach(([method, details]) => {
if (details.parameters) {
details.parameters = removeDeprecatedParams(details.parameters);
}
});
});
// Wrap string parameter examples in JS-style double quotes so the
// openapi-generator-cli renders them as valid JS string literals.
if (openapi.components?.parameters) {
Object.values(openapi.components.parameters).forEach((param) => {
if (
param.schema?.type === "string" &&
param.example !== undefined &&
!String(param.example).startsWith('"')
) {
param.example = `"${param.example}"`;
}
});
}
// Save the updated content to a new file
fs.writeFileSync(outputFile, yaml.stringify(openapi), "utf8");
console.log(`Filtered file written to ${outputFile}`);
} catch (err) {
console.error("Error processing the file:", err);
}