Skip to content
This repository has been archived by the owner on Jul 27, 2020. It is now read-only.

Commit

Permalink
fix: workaround for udpate-a-gist content definition (#723)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gem Xli committed May 17, 2020
1 parent 470386f commit a9c1aaa
Show file tree
Hide file tree
Showing 41 changed files with 606 additions and 1,025 deletions.
191 changes: 191 additions & 0 deletions lib/endpoint/overrides/workarounds.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ function workarounds(state) {
});
}

gistWorkarounds(route);

if (
/repos\/get-(apps|teams|users)-with-access-to-protected-branch/.test(
route.operation.operationId
Expand Down Expand Up @@ -147,3 +149,192 @@ function workarounds(state) {
}
});
}

function gistWorkarounds(route) {
const { operation } = route;
const restPattern = route.method + " " + route.path;

// Allows you to update or delete a gist file and rename gist files.
// Files from the previous version of the gist that aren't explicitly
// changed during an edit are unchanged.
// see https://developer.github.com/v3/gists/#update-a-gist
if (restPattern === "PATCH /gists/:gist_id") {
operation.requestBody.content[
"application/json"
].schema.properties.files = {
type: "object",
description: "The filenames and content that make up this gist.",
additionalProperties: {
type: "object",
properties: {
content: {
type: "string",
description: "The updated content of the file.",
},
filename: {
type: "string",
description:
"The new name for this file. To delete a file, set the value of the filename to `null`.",
},
},
},
};
}

// see https://developer.github.com/v3/gists/#get-a-gist
if (restPattern === "GET /gists/:gist_id") {
operation.responses[200].content[
"application/json"
].schema.properties.files = {
type: "object",
additionalProperties: {
type: "object",
properties: {
filename: { type: "string" },
type: { type: "string" },
language: { type: "string" },
raw_url: { type: "string" },
size: { type: "number" },
truncated: { type: "boolean" },
content: { type: "string" },
},
},
};
}

// Allows you to add a new gist with one or more files.
// see https://developer.github.com/v3/gists/#create-a-gist
if (restPattern === "POST /gists") {
operation.requestBody.content[
"application/json"
].schema.properties.files = {
type: "object",
description:
"The filenames and content of each file in the gist. The keys in the `files` object represent the filename and have the type `string`.",
additionalProperties: {
type: "object",
properties: {
content: {
type: "string",
description: "The content of the file.",
},
},
},
};

operation.responses[201].content[
"application/json"
].schema.properties.files = {
type: "object",
additionalProperties: {
type: "object",
properties: {
filename: { type: "string" },
type: { type: "string" },
language: { type: "string" },
raw_url: { type: "string" },
size: { type: "number" },
truncated: { type: "boolean" },
content: { type: "string" },
},
},
};
}

// see https://developer.github.com/v3/gists/#get-a-specific-revision-of-a-gist
if (restPattern === "GET /gists/:gist_id/:sha") {
operation.responses[200].content[
"application/json"
].schema.properties.files = {
type: "object",
additionalProperties: {
type: "object",
properties: {
filename: { type: "string" },
type: { type: "string" },
language: { type: "string" },
raw_url: { type: "string" },
size: { type: "number" },
truncated: { type: "boolean" },
content: { type: "string" },
},
},
};
}

// see https://developer.github.com/v3/gists/#list-gists-for-the-authenticated-user
if (restPattern === "GET /gists") {
operation.responses[200].content[
"application/json"
].schema.items.properties.files = {
type: "object",
additionalProperties: {
type: "object",
properties: {
filename: { type: "string" },
type: { type: "string" },
language: { type: "string" },
raw_url: { type: "string" },
size: { type: "number" },
},
},
};
}

// see https://developer.github.com/v3/gists/#list-public-gists
if (restPattern === "GET /gists/public") {
operation.responses[200].content[
"application/json"
].schema.items.properties.files = {
type: "object",
additionalProperties: {
type: "object",
properties: {
filename: { type: "string" },
type: { type: "string" },
language: { type: "string" },
raw_url: { type: "string" },
size: { type: "number" },
},
},
};
}

// see https://developer.github.com/v3/gists/#list-starred-gists
if (restPattern === "GET /gists/starred") {
operation.responses[200].content[
"application/json"
].schema.items.properties.files = {
type: "object",
additionalProperties: {
type: "object",
properties: {
filename: { type: "string" },
type: { type: "string" },
language: { type: "string" },
raw_url: { type: "string" },
size: { type: "number" },
},
},
};
}

// see https://developer.github.com/v3/gists/#list-gists-for-a-user
if (restPattern === "GET /users/:username/gists") {
operation.responses[200].content[
"application/json"
].schema.items.properties.files = {
type: "object",
additionalProperties: {
type: "object",
properties: {
filename: { type: "string" },
type: { type: "string" },
language: { type: "string" },
raw_url: { type: "string" },
size: { type: "number" },
},
},
};
}
}
81 changes: 20 additions & 61 deletions openapi/api.github.com/operations/gists/create.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,54 +36,16 @@
"html_url": { "type": "string" },
"files": {
"type": "object",
"properties": {
"hello_world.rb": {
"type": "object",
"properties": {
"filename": { "type": "string" },
"type": { "type": "string" },
"language": { "type": "string" },
"raw_url": { "type": "string" },
"size": { "type": "number" },
"truncated": { "type": "boolean" },
"content": { "type": "string" }
}
},
"hello_world.py": {
"type": "object",
"properties": {
"filename": { "type": "string" },
"type": { "type": "string" },
"language": { "type": "string" },
"raw_url": { "type": "string" },
"size": { "type": "number" },
"truncated": { "type": "boolean" },
"content": { "type": "string" }
}
},
"hello_world_ruby.txt": {
"type": "object",
"properties": {
"filename": { "type": "string" },
"type": { "type": "string" },
"language": { "type": "string" },
"raw_url": { "type": "string" },
"size": { "type": "number" },
"truncated": { "type": "boolean" },
"content": { "type": "string" }
}
},
"hello_world_python.txt": {
"type": "object",
"properties": {
"filename": { "type": "string" },
"type": { "type": "string" },
"language": { "type": "string" },
"raw_url": { "type": "string" },
"size": { "type": "number" },
"truncated": { "type": "boolean" },
"content": { "type": "string" }
}
"additionalProperties": {
"type": "object",
"properties": {
"filename": { "type": "string" },
"type": { "type": "string" },
"language": { "type": "string" },
"raw_url": { "type": "string" },
"size": { "type": "number" },
"truncated": { "type": "boolean" },
"content": { "type": "string" }
}
}
},
Expand Down Expand Up @@ -346,16 +308,10 @@
"x-code-samples": [
{
"lang": "Shell",
"source": "curl \\\n -XPOST \\\n -H\"Accept: application/vnd.github.v3+json\" \\\n https://api.github.com/gists \\\n -d '{\"files\":{\"content\":\"content\"}}'"
},
{
"lang": "JS",
"source": "octokit.gists.create({\n files: {\n content: 'content'\n }\n})"
"source": "curl \\\n -XPOST \\\n -H\"Accept: application/vnd.github.v3+json\" \\\n https://api.github.com/gists \\\n -d '{\"files\":{}}'"
},
{
"lang": "Ruby",
"source": "octokit.create(\n {\n content: 'content'\n }\n)"
}
{ "lang": "JS", "source": "octokit.gists.create({\n files: {}\n})" },
{ "lang": "Ruby", "source": "octokit.create(\n {}\n)" }
],
"x-github": {
"legacy": false,
Expand All @@ -373,10 +329,13 @@
"files": {
"type": "object",
"description": "The filenames and content of each file in the gist. The keys in the `files` object represent the filename and have the type `string`.",
"properties": {
"content": {
"type": "string",
"description": "The content of the file."
"additionalProperties": {
"type": "object",
"properties": {
"content": {
"type": "string",
"description": "The content of the file."
}
}
}
},
Expand Down
58 changes: 10 additions & 48 deletions openapi/api.github.com/operations/gists/get-revision.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,54 +48,16 @@
"html_url": { "type": "string" },
"files": {
"type": "object",
"properties": {
"hello_world.rb": {
"type": "object",
"properties": {
"filename": { "type": "string" },
"type": { "type": "string" },
"language": { "type": "string" },
"raw_url": { "type": "string" },
"size": { "type": "number" },
"truncated": { "type": "boolean" },
"content": { "type": "string" }
}
},
"hello_world.py": {
"type": "object",
"properties": {
"filename": { "type": "string" },
"type": { "type": "string" },
"language": { "type": "string" },
"raw_url": { "type": "string" },
"size": { "type": "number" },
"truncated": { "type": "boolean" },
"content": { "type": "string" }
}
},
"hello_world_ruby.txt": {
"type": "object",
"properties": {
"filename": { "type": "string" },
"type": { "type": "string" },
"language": { "type": "string" },
"raw_url": { "type": "string" },
"size": { "type": "number" },
"truncated": { "type": "boolean" },
"content": { "type": "string" }
}
},
"hello_world_python.txt": {
"type": "object",
"properties": {
"filename": { "type": "string" },
"type": { "type": "string" },
"language": { "type": "string" },
"raw_url": { "type": "string" },
"size": { "type": "number" },
"truncated": { "type": "boolean" },
"content": { "type": "string" }
}
"additionalProperties": {
"type": "object",
"properties": {
"filename": { "type": "string" },
"type": { "type": "string" },
"language": { "type": "string" },
"raw_url": { "type": "string" },
"size": { "type": "number" },
"truncated": { "type": "boolean" },
"content": { "type": "string" }
}
}
},
Expand Down
Loading

0 comments on commit a9c1aaa

Please sign in to comment.