Skip to content

Commit

Permalink
build(update-endpoints): add octokit.repos.uploadReleaseAsset() wor…
Browse files Browse the repository at this point in the history
…karounds for types generation
  • Loading branch information
gr2m committed Jan 31, 2020
1 parent 7982cb4 commit d66ddfb
Showing 1 changed file with 30 additions and 13 deletions.
43 changes: 30 additions & 13 deletions scripts/update-endpoints/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -337,17 +337,16 @@ async function getRoutes() {
method: endpoint.method,
url,
description: endpoint.description,
headers: endpoint.headers.reduce((result, header) => {
if (!result) {
result = {};
}
result[header.name] = header.value;
return result;
}, undefined),
deprecated: newRoutes[scope][idName]
? newRoutes[scope][idName].deprecated
: undefined,
params: endpoint.parameters.reduce((result, param) => {
// "origin" is a URL parameter only relevant for octokit.repos.uploadReleaseAsset()
// We remove it and set a default for `baseUrl`, which is a special default parameter
if (param.name === "origin") {
return result;
}

result[param.name] = {
type: param.type,
description:
Expand Down Expand Up @@ -398,14 +397,32 @@ async function getRoutes() {
: undefined
};

const previewHeaders = endpoint.previews
.map(preview => `application/vnd.github.${preview.name}-preview+json`)
.join(",");
// add required headers as parameters
const requiredHeaders = endpoint.headers.filter(header => {
// if value is set, we pass the header with its expected value automatically
if (header.value) {
return false;
}

if (previewHeaders) {
newRoutes[scope][idName].headers = {
accept: previewHeaders
return header.required;
});

if (requiredHeaders.length) {
newRoutes[scope][idName].params.headers = {
type: "object",
required: true
};
for (const header of requiredHeaders) {
// Content-Length header is set automatically
if (header.name === "content-length") {
continue;
}

newRoutes[scope][idName].params[`headers.${header.name}`] = {
type: "string",
required: true
};
}
}

if (endpoint.renamed) {
Expand Down

0 comments on commit d66ddfb

Please sign in to comment.