feat(medusa-oas-cli,oas-github-ci): new options + added download of OAS in api reference (#5453)
This commit is contained in:
1 parent
03959c3e3a
commit
c1b97050ab
9 files changed
+50130
-6
No files matched your search
@@ -59,6 +59,10 @@ export const commandOptions: Option[] = [
|
||||
"--html",
|
||||
"Generate a static HTML using Redocly's build-docs command."
|
||||
),
|
||||
new Option(
|
||||
"--main-file-name <mainFileName>",
|
||||
"The name of the main YAML file."
|
||||
).default("openapi.yaml")
|
||||
]
|
||||
|
||||
export function getCommand(): Command {
|
||||
@@ -95,7 +99,6 @@ export async function execute(cliParams: OptionValues): Promise<void> {
|
||||
throw new Error(`--config must be a file - ${configFileCustom}`)
|
||||
}
|
||||
if (![".json", ".yaml"].includes(path.extname(configFileCustom))) {
|
||||
console.log(path.extname(configFileCustom))
|
||||
throw new Error(
|
||||
`--config file must be of type .json or .yaml - ${configFileCustom}`
|
||||
)
|
||||
@@ -110,7 +113,7 @@ export async function execute(cliParams: OptionValues): Promise<void> {
|
||||
const tmpDir = await getTmpDirectory()
|
||||
const configTmpFile = path.resolve(tmpDir, "redocly-config.yaml")
|
||||
/** matches naming convention from `redocly split` */
|
||||
const finalOASFile = path.resolve(outDir, "openapi.yaml")
|
||||
const finalOASFile = cliParams.mainFileName
|
||||
|
||||
await createTmpConfig(configFileDefault, configTmpFile)
|
||||
if (configFileCustom) {
|
||||
@@ -143,7 +146,7 @@ export async function execute(cliParams: OptionValues): Promise<void> {
|
||||
if (shouldSplit) {
|
||||
await generateReference(srcFileSanitized, outDir)
|
||||
} else {
|
||||
await jsonFileToYamlFile(srcFileSanitized, finalOASFile)
|
||||
await jsonFileToYamlFile(srcFileSanitized, path.join(outDir, finalOASFile))
|
||||
}
|
||||
if (shouldBuildHTML) {
|
||||
const outHTMLFile = path.resolve(outDir, "index.html")
|
||||
|
||||
@@ -6,6 +6,7 @@ const path = require("path")
|
||||
const execa = require("execa")
|
||||
|
||||
const isDryRun = process.argv.indexOf("--dry-run") !== -1
|
||||
const withFullFile = process.argv.indexOf("--with-full-file") !== -1
|
||||
const basePath = path.resolve(__dirname, `../`)
|
||||
const repoRootPath = path.resolve(basePath, `../../../`)
|
||||
const docsApiPath = path.resolve(repoRootPath, "www/apps/api-reference/specs")
|
||||
@@ -30,7 +31,7 @@ const generateOASSource = async (outDir, apiType) => {
|
||||
}
|
||||
|
||||
const generateDocs = async (srcFile, outDir, isDryRun) => {
|
||||
const params = [
|
||||
let params = [
|
||||
"docs",
|
||||
`--src-file=${srcFile}`,
|
||||
`--out-dir=${outDir}`,
|
||||
@@ -40,6 +41,21 @@ const generateDocs = async (srcFile, outDir, isDryRun) => {
|
||||
if (isDryRun) {
|
||||
params.push("--dry-run")
|
||||
}
|
||||
await runMedusaOasCommand(params)
|
||||
if (withFullFile && !isDryRun) {
|
||||
console.log("Generating full file...")
|
||||
params = [
|
||||
"docs",
|
||||
`--src-file=${srcFile}`,
|
||||
`--out-dir=${outDir}`,
|
||||
`--main-file-name=openapi.full.yaml`
|
||||
]
|
||||
await runMedusaOasCommand(params)
|
||||
console.log("Finished generating full file.")
|
||||
}
|
||||
}
|
||||
|
||||
const runMedusaOasCommand = async (params) => {
|
||||
const { all: logs } = await execa("medusa-oas", params, {
|
||||
cwd: basePath,
|
||||
all: true,
|
||||
|
||||
Reference in new issue
Block a user