MCPcopy Index your code
hub / github.com/github/docs / createStaticRestFiles

Function createStaticRestFiles

src/rest/scripts/utils/decorator.js:69–156  ·  view source on GitHub ↗
(restOperations)

Source from the content-addressed store, hash-verified

67}
68
69async function createStaticRestFiles(restOperations) {
70 const operationsEnabledForGitHubApps = {}
71 const clientSideRedirects = await getCategoryOverrideRedirects()
72 for (const schemaName in restOperations) {
73 const operations = restOperations[schemaName]
74 await addRestClientSideRedirects(operations, clientSideRedirects)
75
76 const categories = [...new Set(operations.map((operation) => operation.category))].sort()
77
78 // Orders the operations by their category and subcategories.
79 // All operations must have a category, but operations don't need
80 // a subcategory. When no subcategory is present, the subcategory
81 // property is an empty string ('').
82 /*
83 Example:
84 {
85 [category]: {
86 '': {
87 "description": "",
88 "operations": []
89 },
90 [subcategory sorted alphabetically]: {
91 "description": "",
92 "operations": []
93 }
94 }
95 }
96 */
97 const operationsByCategory = {}
98 categories.forEach((category) => {
99 operationsByCategory[category] = {}
100 const categoryOperations = operations.filter((operation) => operation.category === category)
101 categoryOperations
102 .filter((operation) => !operation.subcategory)
103 .map((operation) => (operation.subcategory = operation.category))
104
105 const subcategories = [
106 ...new Set(categoryOperations.map((operation) => operation.subcategory)),
107 ].sort()
108 // the first item should be the item that has no subcategory
109 // e.g., when the subcategory = category
110 const firstItemIndex = subcategories.indexOf(category)
111 if (firstItemIndex > -1) {
112 const firstItem = subcategories.splice(firstItemIndex, 1)[0]
113 subcategories.unshift(firstItem)
114 }
115
116 subcategories.forEach((subcategory) => {
117 operationsByCategory[category][subcategory] = {}
118
119 const subcategoryOperations = categoryOperations.filter(
120 (operation) => operation.subcategory === subcategory
121 )
122
123 operationsByCategory[category][subcategory] = subcategoryOperations
124 })
125 })
126

Callers 1

decorateFunction · 0.85

Calls 2

Tested by

no test coverage detected