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

Commit

Permalink
refactor: remove legacy format conversion now that it's unused
Browse files Browse the repository at this point in the history
  • Loading branch information
Derek authored and gr2m committed Aug 14, 2019
1 parent 2a36efd commit 50acbf0
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 423 deletions.
32 changes: 32 additions & 0 deletions lib/get-openapi-doc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
module.exports = getDoc

const { resolve: pathResolve } = require('path')
const { readdirSync } = require('fs')

const PUBLIC_API = 'api.github.com'
const APIS = readdirSync(pathResolve(__dirname, '..', 'openapi'))

function getApi (rawApi) {
if (!rawApi) {
return PUBLIC_API
}
const api = !isNaN(rawApi) ? `ghe-${rawApi}` : rawApi
if (APIS.includes(api)) {
return api
}
throw new Error(`"${rawApi}" is not a valid API. Must be one of: "${APIS.join('", "')}".`)
}

function getDoc (rawApi) {
const api = getApi(rawApi)
const doc = require(`../openapi/${api}/index.json`)
for (const path of Object.keys(doc.paths)) {
for (const method of Object.keys(doc.paths[path])) {
const op = doc.paths[path][method]
if (doc.paths[path][method].$ref) {
doc.paths[path][method] = require(`../openapi/${api}/${op.$ref}`)
}
}
}
return doc
}
2 changes: 1 addition & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
const { getDoc: getOpenapiDoc } = require('./openapi')
const getOpenapiDoc = require('./get-openapi-doc')

module.exports = getOpenapiDoc
Loading

0 comments on commit 50acbf0

Please sign in to comment.