(directory = OPEN_API_RELEASES_DIR)
| 11 | // directory in `github/github` |
| 12 | // You can also specify getting specific versions of schemas. |
| 13 | export async function getSchemas(directory = OPEN_API_RELEASES_DIR) { |
| 14 | const openAPIConfigs = await readdir(directory) |
| 15 | const unpublished = [] |
| 16 | const deprecated = [] |
| 17 | const currentReleases = [] |
| 18 | |
| 19 | // The file content in the `github/github` repo is YAML before it is |
| 20 | // bundled into JSON. |
| 21 | for (const file of openAPIConfigs) { |
| 22 | const fileBaseName = path.basename(file, '.yaml') |
| 23 | const newFileName = `${fileBaseName}.deref.json` |
| 24 | const content = await readFile(path.join(directory, file), 'utf8') |
| 25 | const yamlContent = yaml.load(content) |
| 26 | |
| 27 | const isDeprecatedInDocs = !Object.keys(allVersions).find( |
| 28 | (version) => allVersions[version].openApiVersionName === fileBaseName |
| 29 | ) |
| 30 | if (!yamlContent.published) { |
| 31 | unpublished.push(newFileName) |
| 32 | } |
| 33 | // If it's deprecated, it must have been published at some point in the past |
| 34 | // This checks if the schema is deprecated in github/github and |
| 35 | // github/docs-internal. Sometimes deprecating in github/github lags |
| 36 | // behind deprecating in github/docs-internal a few days |
| 37 | if ( |
| 38 | (yamlContent.deprecated && yamlContent.published) || |
| 39 | (isDeprecatedInDocs && yamlContent.published) |
| 40 | ) { |
| 41 | deprecated.push(newFileName) |
| 42 | } |
| 43 | if (!yamlContent.deprecated && !isDeprecatedInDocs && yamlContent.published) { |
| 44 | currentReleases.push(newFileName) |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | return { currentReleases, unpublished, deprecated } |
| 49 | } |
| 50 | |
| 51 | export async function validateVersionsOptions(versions) { |
| 52 | const schemas = await getSchemas() |
no outgoing calls
no test coverage detected