This repository was archived by the owner on Oct 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget-undocumented-endpoints.js
62 lines (49 loc) · 1.87 KB
/
get-undocumented-endpoints.js
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// This returns an array of request examples which do not currently have a GraphQL example.
// This could feasibly be used to autogenerate a list of requests which are currently not supported.
import fs from "fs";
import yaml from "js-yaml";
const pathToGraphQLExamples = "graphql-files/validated";
const pathToOASYAML = "../commercetools-api-reference/oas/api/openapi.yaml";
// Stores all potential endpoints
let endpoints = [];
// Stores the endpoints with no examples.
let endpointsWithNoExamples = [];
loadOASYaml(pathToOASYAML);
// Step 1: Load the OAS YAML file from API reference
function loadOASYaml(filePath) {
try {
const fileContents = fs.readFileSync(filePath, "utf8");
const oasDocument = yaml.load(fileContents);
// Step 2: Iterate through the OAS content
iterateOAS(oasDocument);
} catch (e) {
console.error(e);
}
}
// Step 2: Function to iterate through OAS content, putting all endpoint names in an array
function iterateOAS(oasDocument) {
// Example: Iterate over paths
if (oasDocument.paths) {
for (const path in oasDocument.paths) {
const methods = oasDocument.paths[path];
for (const method in methods) {
const operation = methods[method];
if (operation.operationId) {
//console.log(operation.operationId)
endpoints.push(operation.operationId + ".graphql");
}
}
}
}
checkIfEndpointDocumented();
}
function checkIfEndpointDocumented() {
endpoints.forEach((endpoint) => {
if (!fs.existsSync(`${pathToGraphQLExamples}/${endpoint}`)) {
endpointsWithNoExamples.push(endpoint.split(".graphql")[0]);
}
});
}
console.log(endpointsWithNoExamples);
// TODO: Use the content of endpointsWithNoExamples to autogenerate a Markdown list of unsupported GraphQL calls.
// This list could be included in the GraphQL docs, and updated whenever a new GraphQL example is added.