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

Commit

Permalink
fix: schemas for the remaining gists endpoints (#727)
Browse files Browse the repository at this point in the history
  • Loading branch information
RomanHotsiy authored May 18, 2020
1 parent 52fce52 commit 712e34f
Show file tree
Hide file tree
Showing 11 changed files with 137 additions and 387 deletions.
144 changes: 47 additions & 97 deletions lib/endpoint/overrides/workarounds.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,36 @@ function gistWorkarounds(route) {
const { operation } = route;
const restPattern = route.method + " " + route.path;

const gistFiles = {
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" },
},
},
};

const gistBaseFiles = {
type: "object",
additionalProperties: {
type: "object",
properties: {
filename: { type: "string" },
type: { type: "string" },
language: { type: "string" },
raw_url: { type: "string" },
size: { type: "number" },
},
},
};

// 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.
Expand All @@ -179,27 +209,17 @@ function gistWorkarounds(route) {
},
},
};

operation.responses[200].content[
"application/json"
].schema.properties.files = gistFiles;
}

// 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" },
},
},
};
].schema.properties.files = gistFiles;
}

// Allows you to add a new gist with one or more files.
Expand All @@ -224,117 +244,47 @@ function gistWorkarounds(route) {

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" },
},
},
};
].schema.properties.files = gistFiles;
}

// 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" },
},
},
};
].schema.properties.files = gistFiles;
}

// 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" },
},
},
};
].schema.items.properties.files = gistBaseFiles;
}

// 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" },
},
},
};
].schema.items.properties.files = gistBaseFiles;
}

// 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" },
},
},
};
].schema.items.properties.files = gistBaseFiles;
}

// 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" },
},
},
};
].schema.items.properties.files = gistBaseFiles;
}

if (restPattern === "POST /gists/:gist_id/forks") {
operation.responses[201].content[
"application/json"
].schema.properties.files = gistBaseFiles;
}
}
18 changes: 8 additions & 10 deletions openapi/api.github.com/operations/gists/fork.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,14 @@
"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" }
}
"additionalProperties": {
"type": "object",
"properties": {
"filename": { "type": "string" },
"type": { "type": "string" },
"language": { "type": "string" },
"raw_url": { "type": "string" },
"size": { "type": "number" }
}
}
},
Expand Down
58 changes: 10 additions & 48 deletions openapi/api.github.com/operations/gists/update.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,54 +42,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.md": {
"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" }
}
},
"new_file.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
18 changes: 8 additions & 10 deletions openapi/ghe-2.17/operations/gists/fork.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,14 @@
"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" }
}
"additionalProperties": {
"type": "object",
"properties": {
"filename": { "type": "string" },
"type": { "type": "string" },
"language": { "type": "string" },
"raw_url": { "type": "string" },
"size": { "type": "number" }
}
}
},
Expand Down
58 changes: 10 additions & 48 deletions openapi/ghe-2.17/operations/gists/update.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,54 +42,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.md": {
"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" }
}
},
"new_file.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 712e34f

Please sign in to comment.