1
0
mirror of synced 2025-12-22 11:26:57 -05:00

Rest api versioning redo (#33011)

Co-authored-by: Rachael Sewell <rachmari@github.com>
Co-authored-by: Sarah Edwards <skedwards88@github.com>
Co-authored-by: Grace Park <gracepark@Graces-MacBook-Pro-2.local>
Co-authored-by: Sarah Schneider <sarahs@users.noreply.github.com>
Co-authored-by: Sarah Schneider <sarahs@github.com>
This commit is contained in:
Grace Park
2022-11-28 11:55:02 -08:00
committed by GitHub
parent f0baeed15b
commit e3f8f71c42
47 changed files with 2317573 additions and 11916 deletions

View File

@@ -11,7 +11,7 @@ import _ from 'lodash'
import frontmatter from '../../lib/read-frontmatter.js'
import getApplicableVersions from '../../lib/get-applicable-versions.js'
import { allVersions } from '../../lib/all-versions.js'
import { allVersions, getDocsVersion } from '../../lib/all-versions.js'
const contentFiles = []
@@ -28,7 +28,12 @@ export async function getDiffOpenAPIContentRest() {
const openAPISchemaCheck = await createOpenAPISchemasCheck()
// One off edge case for secret-scanning Docs-content issue 6637
delete openAPISchemaCheck['free-pro-team@latest']['secret-scanning']
const fptApiVersions = getOnlyApiVersions('free-pro-team@latest')
fptApiVersions.forEach((fptApiVersion) => {
delete openAPISchemaCheck[fptApiVersion]['secret-scanning']
})
// Get Differences between categories/subcategories from dereferenced schemas and the content/rest directory frontmatter versions
const differences = getDifferences(openAPISchemaCheck, checkContentDir)
const errorMessages = {}
@@ -36,13 +41,15 @@ export async function getDiffOpenAPIContentRest() {
if (Object.keys(differences).length > 0) {
for (const schemaName in differences) {
errorMessages[schemaName] = {}
for (const category of differences[schemaName]) {
differences[schemaName].forEach((category) => {
if (!errorMessages[schemaName]) errorMessages[schemaName] = category
errorMessages[schemaName][category] = {
contentDir: checkContentDir[schemaName][category],
openAPI: openAPISchemaCheck[schemaName][category],
}
}
})
}
}
@@ -51,31 +58,32 @@ export async function getDiffOpenAPIContentRest() {
async function createOpenAPISchemasCheck() {
const schemasPath = path.join(process.cwd(), 'lib/rest/static/decorated')
const openAPICheck = Object.keys(allVersions).reduce((acc, val) => {
return { ...acc, [val]: [] }
}, {})
const openAPICheck = createCheckObj()
const schemas = fs.readdirSync(schemasPath)
schemas.forEach((file) => {
const version = getVersion(file.replace('.json', ''))
const fileData = fs.readFileSync(path.join(schemasPath, file))
const fileSchema = JSON.parse(fileData.toString())
const categories = Object.keys(fileSchema).sort()
const version = getDocsVersion(file.split(/.json/)[0])
for (const category of categories) {
categories.forEach((category) => {
const subcategories = Object.keys(fileSchema[category])
openAPICheck[version][category] = subcategories.sort()
}
if (isApiVersioned(version)) {
getOnlyApiVersions(version).forEach(
(apiVersion) => (openAPICheck[apiVersion][category] = subcategories.sort())
)
} else {
openAPICheck[version][category] = subcategories.sort()
}
})
})
return openAPICheck
}
async function createCheckContentDirectory(contentFiles) {
const checkContent = Object.keys(allVersions).reduce((acc, val) => {
return { ...acc, [val]: [] }
}, {})
const checkContent = createCheckObj()
for (const filename of contentFiles) {
const { data } = frontmatter(await fs.promises.readFile(filename, 'utf8'))
@@ -84,26 +92,45 @@ async function createCheckContentDirectory(contentFiles) {
const subCategory = splitPath[splitPath.length - 1].replace('.md', '')
const category =
splitPath[splitPath.length - 2] === 'rest' ? subCategory : splitPath[splitPath.length - 2]
// All versions with appended calendar date versions if it exists
const allCompleteVersions = applicableVersions.flatMap((version) => {
return isApiVersioned(version)
? allVersions[version].apiVersions.map(
(apiVersion) => `${allVersions[version].version}.${apiVersion}`
)
: version
})
for (const version of applicableVersions) {
if (!checkContent[version][category]) {
checkContent[version][category] = [subCategory]
} else {
checkContent[version][category].push(subCategory)
}
allCompleteVersions.forEach((version) => {
!checkContent[version][category]
? (checkContent[version][category] = [subCategory])
: checkContent[version][category].push(subCategory)
checkContent[version][category].sort()
}
})
}
return checkContent
}
function getVersion(curVersion) {
for (const version in allVersions) {
if (Object.values(allVersions[version]).indexOf(curVersion) > -1) {
return version
}
}
function isApiVersioned(version) {
return allVersions[version] && allVersions[version].apiVersions.length > 0
}
function getOnlyApiVersions(version) {
return allVersions[version].apiVersions.map(
(apiVersion) => `${allVersions[version].version}.${apiVersion}`
)
}
function createCheckObj() {
const versions = {}
Object.keys(allVersions).forEach((version) => {
isApiVersioned(version)
? getOnlyApiVersions(version).forEach((apiVersion) => (versions[apiVersion] = {}))
: (versions[`${allVersions[version].version}`] = {})
})
return versions
}
function getDifferences(openAPISchemaCheck, contentCheck) {