chore(medusa-oas-cli,oas-github-ci): remove v2 option + generate v2 by default (#7304)

* chore(medusa-oas-cli,oas-github-ci): remove v2 option + generate v2 by default

* fixes to changeset

* fix public url path
This commit is contained in:
Shahed Nasser
2024-05-13 17:01:38 +03:00
committed by GitHub
parent 63623422fe
commit 8b2429d24f
10 changed files with 111 additions and 926 deletions

View File

@@ -18,14 +18,6 @@ import { isFile } from "./utils/fs-utils"
const medusaPackagePath = path.dirname(
require.resolve("@medusajs/medusa/package.json")
)
// Types package directory
const medusaTypesPath = path.dirname(
require.resolve("@medusajs/types/package.json")
)
// Utils package directory
const medusaUtilsPath = path.dirname(
require.resolve("@medusajs/utils/package.json")
)
const basePath = path.resolve(__dirname, "../")
/**
@@ -53,10 +45,6 @@ export const commandOptions: Option[] = [
"Custom base OAS file to use for swagger-inline."
),
new Option("-F, --force", "Ignore OAS validation and output OAS files."),
new Option(
"--v2",
"Generate OAS files for V2 endpoints. This loads OAS from www/utils/generated/oas-output/operations directory"
),
new Option(
"--local",
"Generate OAS from local files rather than public OAS. This is useful for generating references in the Medusa monorepo."
@@ -117,11 +105,11 @@ export async function execute(cliParams: OptionValues) {
console.log(`🟣 Generating OAS - ${apiType}`)
if (apiType === "combined") {
const adminOAS = !local ? await getPublicOas("admin", v2) : await getOASFromCodebase("admin", v2)
const storeOAS = !local ? await getPublicOas("store", v2) : await getOASFromCodebase("store", v2)
const adminOAS = !local ? await getPublicOas("admin") : await getOASFromCodebase("admin")
const storeOAS = !local ? await getPublicOas("store") : await getOASFromCodebase("store")
oas = await combineOAS(adminOAS, storeOAS)
} else {
oas = !local ? await getPublicOas(apiType, v2) : await getOASFromCodebase(apiType, v2)
oas = !local ? await getPublicOas(apiType) : await getOASFromCodebase(apiType)
}
if (additionalPaths.length || baseFile) {
@@ -146,36 +134,24 @@ export async function execute(cliParams: OptionValues) {
* Methods
*/
async function getOASFromCodebase(
apiType: ApiType,
v2?: boolean
apiType: ApiType
): Promise<OpenAPIObject> {
/**
* OAS output directory
*
* @privateRemark
* This should be the only directory OAS is loaded from for Medusa V2.
* For now, we only use it if the --v2 flag it passed to the CLI tool.
*/
const oasOutputPath = path.resolve(
__dirname, "..", "..", "..", "..", "..", "www", "utils", "generated", "oas-output"
)
const gen = await swaggerInline(
v2 ? [
[
path.resolve(oasOutputPath, "operations", apiType),
path.resolve(oasOutputPath, "schemas"),
// We currently load error schemas from here. If we change
// that in the future, we should change the path.
path.resolve(medusaPackagePath, "dist", "utils/middlewares"),
] : [
path.resolve(medusaTypesPath, "dist"),
path.resolve(medusaUtilsPath, "dist"),
path.resolve(medusaPackagePath, "dist", "models"),
path.resolve(medusaPackagePath, "dist", "types"),
path.resolve(medusaPackagePath, "dist", "api/middlewares"),
path.resolve(medusaPackagePath, "dist", `api/routes/${apiType}`),
],
{
base: path.resolve(oasOutputPath, v2 ? "base-v2" : "base", `${apiType}.oas.base.yaml`),
base: path.resolve(oasOutputPath, "base", `${apiType}.oas.base.yaml`),
format: ".json",
}
)
@@ -184,9 +160,8 @@ async function getOASFromCodebase(
async function getPublicOas(
apiType: ApiType,
v2?: boolean
) {
const url = `https://docs.medusajs.com/api/download/${apiType}?version=${v2 ? "2" : "1"}`
const url = `https://docs.medusajs.com/v2/api/download/${apiType}`
return await OpenAPIParser.parse(url) as OpenAPIObject
}

View File

@@ -7,11 +7,9 @@ const execa = require("execa")
const isDryRun = process.argv.indexOf("--dry-run") !== -1
const withFullFile = process.argv.indexOf("--with-full-file") !== -1
const v2 = process.argv.indexOf("--v2") !== -1
const basePath = path.resolve(__dirname, `../`)
const repoRootPath = path.resolve(basePath, `../../../../`)
const docsApiPath = v2 ? path.resolve(repoRootPath, "www/apps/api-reference/specs-v2") :
path.resolve(repoRootPath, "www/apps/api-reference/specs")
const docsApiPath = path.resolve(repoRootPath, "www/apps/api-reference/specs")
const run = async () => {
const oasOutDir = isDryRun ? await getTmpDirectory() : docsApiPath
@@ -25,9 +23,6 @@ const run = async () => {
const generateOASSource = async (outDir, apiType) => {
const commandParams = ["oas", `--type=${apiType}`, `--out-dir=${outDir}`, "--local"]
if (v2) {
commandParams.push(`--v2`)
}
const { all: logs } = await execa(
"medusa-oas",
commandParams,