Skip to content

Commit

Permalink
feat: replace @octokit/routes with latest OpenAPI spec via `@octoki…
Browse files Browse the repository at this point in the history
…t/openapi` (#58)
  • Loading branch information
gr2m authored Jan 7, 2021
1 parent e795c9b commit 6620c5f
Show file tree
Hide file tree
Showing 6 changed files with 308,078 additions and 118,130 deletions.
27 changes: 1 addition & 26 deletions api/_lib/parse-operation.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ function parseOperation({ method, url }, operation) {
const headerParameters = operation.parameters.filter(
param => param.in === "header"
);
const acceptHeader = headerParameters.find(param => param.name === "accept");
const headers = headerParameters
.filter(param => param.name !== "accept")
.map(toHeader);
Expand Down Expand Up @@ -149,41 +148,17 @@ function parseOperation({ method, url }, operation) {
}

const endpoint = {
id,
scope,
name: operation.summary,
description: operation.description,
method: method.toUpperCase(),
url,
parameters,
headers,
documentationUrl: operation.externalDocs.url,
isDeprecated: !!operation.deprecated,
isLegacy: operation["x-github"].legacy,
isEnabledForApps: operation["x-github"].enabledForApps,
isGithubCloudOnly: operation["x-github"].githubCloudOnly,
triggersNotification: operation["x-github"].triggersNotification,
previews: operation["x-github"].previews,
responses,
changes: operation["x-changes"].map(change => {
const type = change.type.toUpperCase();
const before = toParamter(type, change.before);
const after = toParamter(type, change.after);

return {
type,
date: change.date,
note: change.note,
before,
after
};
})
responses
};

if (acceptHeader.required) {
endpoint.headers.unshift(toHeader(acceptHeader));
}

return endpoint;
}

Expand Down
15 changes: 12 additions & 3 deletions api/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,20 @@ module.exports = async (request, response) => {
const operation = OPENAPI_PATHS[endpointPath][method.toLowerCase()];
if (!operation) continue;

results.push([method, endpointPath, operation]);
results.push([method, endpointPath, toSearchData(operation)]);
continue;
}

for (const [method, operation] of Object.entries(
OPENAPI_PATHS[endpointPath]
)) {
if (path) {
results.push([method.toUpperCase(), endpointPath, operation]);
results.push([method.toUpperCase(), endpointPath, toSearchData(operation)]);
continue;
}

if (queryRegex.test(operation.summary)) {
results.push([method.toUpperCase(), endpointPath, operation]);
results.push([method.toUpperCase(), endpointPath, toSearchData(operation)]);
}
}
}
Expand Down Expand Up @@ -88,3 +88,12 @@ function toMethodAndPath(query) {

return {};
}

/**
* only return data that is actually needed for search results
*/
function toSearchData(operation) {
return {
summary: operation.summary
}
}
11 changes: 5 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
"node": "12.x"
},
"dependencies": {
"@octokit/openapi": "^2.2.1",
"@octokit/request": "^5.3.2",
"markdown-it": "^10.0.0"
},
"devDependencies": {
"@octokit/routes": "29.0.0",
"cypress": "^4.7.0",
"semantic-release": "^17.2.3",
"vercel": "^20.1.1"
Expand Down
Loading

1 comment on commit 6620c5f

@vercel
Copy link

@vercel vercel bot commented on 6620c5f Jan 7, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.